mirror of
https://github.com/preservim/nerdtree.git
synced 2025-11-09 11:53:48 -05:00
make the menu api more awesome
This commit is contained in:
@@ -688,7 +688,6 @@ function! s:MenuItem.Create(options)
|
|||||||
|
|
||||||
let newMenuItem.text = a:options['text']
|
let newMenuItem.text = a:options['text']
|
||||||
let newMenuItem.shortcut = a:options['shortcut']
|
let newMenuItem.shortcut = a:options['shortcut']
|
||||||
let newMenuItem.callback = a:options['callback']
|
|
||||||
let newMenuItem.children = []
|
let newMenuItem.children = []
|
||||||
|
|
||||||
let newMenuItem.isActiveCallback = -1
|
let newMenuItem.isActiveCallback = -1
|
||||||
@@ -696,6 +695,11 @@ function! s:MenuItem.Create(options)
|
|||||||
let newMenuItem.isActiveCallback = a:options['isActiveCallback']
|
let newMenuItem.isActiveCallback = a:options['isActiveCallback']
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let newMenuItem.callback = -1
|
||||||
|
if has_key(a:options, 'callback')
|
||||||
|
let newMenuItem.callback = a:options['callback']
|
||||||
|
endif
|
||||||
|
|
||||||
if has_key(a:options, 'parent')
|
if has_key(a:options, 'parent')
|
||||||
call add(a:options['parent'].children, newMenuItem)
|
call add(a:options['parent'].children, newMenuItem)
|
||||||
else
|
else
|
||||||
@@ -716,6 +720,15 @@ function! s:MenuItem.CreateSeparator(options)
|
|||||||
return s:MenuItem.Create(options)
|
return s:MenuItem.Create(options)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: MenuItem.CreateSubmenu(options) {{{3
|
||||||
|
"make a new submenu and add it to global list
|
||||||
|
function! s:MenuItem.CreateSubmenu(options)
|
||||||
|
let standard_options = { 'callback': -1 }
|
||||||
|
let options = extend(a:options, standard_options, "force")
|
||||||
|
|
||||||
|
return s:MenuItem.Create(options)
|
||||||
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: MenuItem.enabled() {{{3
|
"FUNCTION: MenuItem.enabled() {{{3
|
||||||
"return 1 if this menu item should be displayed
|
"return 1 if this menu item should be displayed
|
||||||
"
|
"
|
||||||
@@ -746,7 +759,13 @@ endfunction
|
|||||||
"FUNCTION: MenuItem.isSeparator() {{{3
|
"FUNCTION: MenuItem.isSeparator() {{{3
|
||||||
"return 1 if this menuitem is a separator
|
"return 1 if this menuitem is a separator
|
||||||
function! s:MenuItem.isSeparator()
|
function! s:MenuItem.isSeparator()
|
||||||
return self.callback == -1
|
return self.callback == -1 && self.children == []
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: MenuItem.isSubmenu() {{{3
|
||||||
|
"return 1 if this menuitem is a submenu
|
||||||
|
function! s:MenuItem.isSubmenu()
|
||||||
|
return self.callback == -1 && !empty(self.children)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"CLASS: TreeFileNode {{{2
|
"CLASS: TreeFileNode {{{2
|
||||||
@@ -2594,12 +2613,16 @@ let g:NERDTreeFileNode = s:TreeFileNode
|
|||||||
let g:NERDTreeBookmark = s:Bookmark
|
let g:NERDTreeBookmark = s:Bookmark
|
||||||
|
|
||||||
function! NERDTreeAddMenuItem(options)
|
function! NERDTreeAddMenuItem(options)
|
||||||
return s:MenuItem.Create(a:options)
|
call s:MenuItem.Create(a:options)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! NERDTreeAddMenuSeparator(...)
|
function! NERDTreeAddMenuSeparator(...)
|
||||||
let opts = a:0 ? a:1 : {}
|
let opts = a:0 ? a:1 : {}
|
||||||
return s:MenuItem.CreateSeparator(opts)
|
call s:MenuItem.CreateSeparator(opts)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! NERDTreeAddSubmenu(options)
|
||||||
|
return s:MenuItem.Create(a:options)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! NERDTreeAddKeyMap(options)
|
function! NERDTreeAddKeyMap(options)
|
||||||
|
|||||||
Reference in New Issue
Block a user