Skip to content

Commit

Permalink
feat(tree): add add item to context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Aug 22, 2023
1 parent aaa8c47 commit a96ebe2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/renderer/plugins/file-tree-context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,29 @@ export default {
}
}

function addItem (node: Doc) {
const input = window.document.createElement('input')
input.type = 'file'
input.multiple = true
input.onchange = async () => {
for (let i = 0; i < input.files!.length; i++) {
const file = input.files![i]
const fileBase64Url = await ctx.utils.fileToBase64URL(file)
const filePath = ctx.utils.path.resolve(node.path, file.name)
await ctx.api.upload(node.repo, fileBase64Url, filePath)
}

ctx.tree.refreshTree()
}
input.click()
}

function getItems (node: Doc, position: 'tabs' | 'tree'): Components.ContextMenu.Item[] {
const t = ctx.i18n.t
const isMarkdown = ctx.doc.isMarkdownFile(node)

const disableItems = ctx.args.FLAG_READONLY
? ['duplicate', 'duplicate', 'create-dir', 'create-doc', 'create-in-cd', 'rename', 'delete', 'open-in-terminal']
? ['add-item', 'duplicate', 'duplicate', 'create-dir', 'create-doc', 'create-in-cd', 'rename', 'delete', 'open-in-terminal']
: []

if (position === 'tabs') {
Expand All @@ -31,7 +48,8 @@ export default {
] : []),
...(node.type === 'dir' ? [
{ id: 'create-doc', label: t('tree.context-menu.create-doc'), onClick: () => ctx.doc.createDoc({ repo: node.repo }, node) },
{ id: 'create-dir', label: t('tree.context-menu.create-dir'), onClick: () => ctx.doc.createDir({ repo: node.repo }, node) }
{ id: 'create-dir', label: t('tree.context-menu.create-dir'), onClick: () => ctx.doc.createDir({ repo: node.repo }, node) },
{ id: 'add-item', label: t('tree.context-menu.add-item'), onClick: () => addItem(node) },
] : []),
...(node.path !== '/' ? [
{ id: 'rename', label: t('tree.context-menu.rename'), onClick: () => ctx.doc.moveDoc(node) },
Expand Down
1 change: 1 addition & 0 deletions src/share/i18n/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ const data = {
'duplicate': 'Duplicate',
'create-doc': 'New File',
'create-dir': 'New Folder',
'add-item': 'Add Item',
'rename': 'Rename / Move',
'delete': 'Delete',
'open-in-os': 'Open in OS',
Expand Down
1 change: 1 addition & 0 deletions src/share/i18n/languages/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ const data: BaseLanguage = {
'duplicate': '重复文件',
'create-doc': '创建文件',
'create-dir': '创建文件夹',
'add-item': '添加文件',
'rename': '重命名 / 移动',
'delete': '删除',
'open-in-os': '在系统中打开',
Expand Down

1 comment on commit a96ebe2

@vercel
Copy link

@vercel vercel bot commented on a96ebe2 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.