make the git menu work and put it under a submenu

This commit is contained in:
marty 2009-08-19 02:05:36 +12:00
parent e93bf0632b
commit 891f0ed3a2

View File

@ -21,12 +21,41 @@ if exists("g:loaded_nerdtree_git_menu")
endif
let g:loaded_nerdtree_git_menu = 1
call NERDTreeAddMenuItem({
call NERDTreeAddMenuSeparator({'isActiveCallback': 'NERDTreeGitMenuEnabled'})
let s:menu = NERDTreeAddMenuItem({
\ 'text': '(g)it menu',
\ 'shortcut': 'g',
\ 'isActiveCallback': 'NERDTreeGitMenuEnabled',
\ 'callback': 'NERDTreeGitMenu' })
call NERDTreeAddMenuItem({
\ 'text': 'git (a)dd',
\ 'shortcut': 'a',
\ 'isActiveCallback': 'NERDTreeGitMenuEnabled',
\ 'callback': 'NERDTreeGitAdd',
\ 'parent': s:menu })
call NERDTreeAddMenuItem({
\ 'text': 'git (c)heckout',
\ 'shortcut': 'c',
\ 'isActiveCallback': 'NERDTreeGitMenuEnabled',
\ 'callback': 'NERDTreeGitCheckout',
\ 'parent': s:menu })
call NERDTreeAddMenuItem({
\ 'text': 'git (m)v',
\ 'shortcut': 'm',
\ 'isActiveCallback': 'NERDTreeGitMenuEnabled',
\ 'callback': 'NERDTreeGitMove',
\ 'parent': s:menu })
call NERDTreeAddMenuItem({
\ 'text': 'git (r)m',
\ 'shortcut': 'r',
\ 'isActiveCallback': 'NERDTreeGitMenuEnabled',
\ 'callback': 'NERDTreeGitRemove',
\ 'parent': s:menu })
function! NERDTreeGitMenuEnabled()
return isdirectory(s:GitRepoPath())
endfunction
@ -35,37 +64,29 @@ function! s:GitRepoPath()
return b:NERDTreeRoot.path.str(0) . ".git"
endfunction
function! NERDTreeGitMenu()
function! NERDTreeGitMove()
let node = g:NERDTreeFileNode.GetSelected()
let path = node.path
let parent = path.getParent()
let p = path.strForOS(1)
call s:promptCommand('mv ', p . ' ' . p, 'file')
endfunction
let prompt = "NERDTree Git Menu\n" .
\ "==========================================================\n".
\ "Select the desired operation: \n" .
\ " (a) - git add\n".
\ " (c) - git checkout\n".
\ " (m) - git mv\n".
\ " (r) - git rm\n"
function! NERDTreeGitAdd()
let node = g:NERDTreeFileNode.GetSelected()
let path = node.path
call s:promptCommand('add ', path.strForOS(1), 'file')
endfunction
echo prompt
function! NERDTreeGitRemove()
let node = g:NERDTreeFileNode.GetSelected()
let path = node.path
call s:promptCommand('rm ', path.strForOS(1), 'file')
endfunction
let choice = nr2char(getchar())
if choice ==# "a"
call s:promptCommand('add ', path.strForOS(1), 'file')
elseif choice ==# "c"
call s:promptCommand('checkout ', path.strForOS(1), 'file')
elseif choice ==# "m"
let p = path.strForOS(1)
call s:promptCommand('mv ', p . ' ' . p, 'file')
elseif choice ==# "r"
call s:promptCommand('rm ', path.strForOS(1), 'file')
endif
call node.parent.refresh()
call NERDTreeRender()
function! NERDTreeGitCheckout()
let node = g:NERDTreeFileNode.GetSelected()
let path = node.path
call s:promptCommand('checkout ', path.strForOS(1), 'file')
endfunction
function! s:promptCommand(sub_command, cmd_tail_default, complete)
@ -73,11 +94,16 @@ function! s:promptCommand(sub_command, cmd_tail_default, complete)
let extra_options .= ' --work-tree=' . b:NERDTreeRoot.path.str(0) . ' '
let base = "git" . extra_options . a:sub_command
let node = g:NERDTreeFileNode.GetSelected()
let cmd_tail = input(":!" . base, a:cmd_tail_default, a:complete)
if cmd_tail != ''
let output = system(base . cmd_tail)
redraw!
if v:shell_error != 0
if v:shell_error == 0
call node.parent.refresh()
call NERDTreeRender()
else
echo output
endif
else