mirror of
https://github.com/purocean/yn.git
synced 2026-10-12 23:31:39 +08:00
插件增加文件树菜单注册
This commit is contained in:
@@ -42,6 +42,7 @@ import Extensions from '../useful/extensions'
|
||||
import { triggerHook } from '../useful/plugin'
|
||||
import { Components } from '../types'
|
||||
import SvgIcon from './SvgIcon.vue'
|
||||
import { registerContextMenu, getContextMenuItems } from '../useful/plugin/tree'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'tree-node',
|
||||
@@ -231,6 +232,10 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function showContextMenu (item: any) {
|
||||
contextMenu.show(getContextMenuItems(item))
|
||||
}
|
||||
|
||||
function buildContextMenu (item: any) {
|
||||
const menu: Components.ContextMenu.Item[] = [
|
||||
{ id: 'delete', label: '删除', onClick: () => deleteFile() },
|
||||
{ id: 'rename', label: '重命名 / 移动', onClick: () => renameFile() },
|
||||
@@ -240,11 +245,11 @@ export default defineComponent({
|
||||
]
|
||||
|
||||
if (item.type === 'dir') {
|
||||
contextMenu.show([
|
||||
return [
|
||||
{ id: 'create', label: '创建新文件', onClick: () => createFile() },
|
||||
...menu,
|
||||
{ id: 'openInTerminal', label: '在终端中打开', onClick: () => revealInXterminal() }
|
||||
])
|
||||
]
|
||||
} else {
|
||||
// markdown 文件可以被标记
|
||||
if (props.item.path.endsWith('.md')) {
|
||||
@@ -257,17 +262,19 @@ export default defineComponent({
|
||||
additional.push({ id: 'duplicate', label: '重复文件', onClick: () => duplicateFile() })
|
||||
}
|
||||
|
||||
contextMenu.show([
|
||||
return [
|
||||
...additional,
|
||||
...menu,
|
||||
{ id: 'create', label: '当前目录创建新文件', onClick: () => createFile() }
|
||||
])
|
||||
]
|
||||
} else {
|
||||
contextMenu.show(menu)
|
||||
return menu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerContextMenu((_, item) => buildContextMenu(item))
|
||||
|
||||
const currentRepoName = computed(() => currentRepo.value?.name ?? '/')
|
||||
|
||||
const selected = computed(() => {
|
||||
|
||||
@@ -50,6 +50,7 @@ const ctx = {
|
||||
|
||||
return false
|
||||
},
|
||||
tree: tree.ctx,
|
||||
markdown: markdown.ctx,
|
||||
statusBar: statusBar.ctx
|
||||
}
|
||||
|
||||
@@ -1 +1,21 @@
|
||||
import { Components } from '@/types'
|
||||
|
||||
export type HookType = 'ON_TREE_NODE_SELECT'
|
||||
|
||||
type MenuItem = Components.ContextMenu.Item
|
||||
|
||||
type BuildContextMenu = (items: MenuItem[], node: any) => MenuItem[]
|
||||
|
||||
const contextMenuFunList: BuildContextMenu[] = []
|
||||
|
||||
export const registerContextMenu = (fun: BuildContextMenu) => {
|
||||
contextMenuFunList.push(fun)
|
||||
}
|
||||
|
||||
export const getContextMenuItems = (node: any) => {
|
||||
return contextMenuFunList.reduce((items, fun) => fun(items, node), [] as MenuItem[])
|
||||
}
|
||||
|
||||
export const ctx = {
|
||||
registerContextMenu
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user