From b936475564a915140a33c17b6cd8319864d1193f Mon Sep 17 00:00:00 2001 From: Bob Hiestand Date: Thu, 2 Sep 2010 14:47:40 -0500 Subject: [PATCH] Factored menu addition into a single function and shared with extensions. --- plugin/vcscommand.vim | 68 ++++++++++++++++++++++++++++++++++----------------- plugin/vcscvs.vim | 25 +++++++++++-------- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/plugin/vcscommand.vim b/plugin/vcscommand.vim index db154ae..6fbb2e5 100644 --- a/plugin/vcscommand.vim +++ b/plugin/vcscommand.vim @@ -231,7 +231,7 @@ " shortcuts. " " VCSCommandMenuRoot -" This variable, if set, overrides the default menu root 'Plugin' +" This variable, if set, overrides the default menu root 'Plugin.VCS' " " VCSCommandMenuPriority " This variable, if set, overrides the default menu priority '' (empty) @@ -366,7 +366,7 @@ function! s:ReportError(error) echohl WarningMsg|echomsg 'VCSCommand: ' . a:error|echohl None endfunction -" Function s:VCSCommandUtility.system(...) {{{2 +" Function: s:VCSCommandUtility.system(...) {{{2 " Replacement for system() function. This version protects the quoting in the " command line on Windows systems. @@ -384,6 +384,23 @@ function! s:VCSCommandUtility.system(...) endtry endfunction +" Function: s:VCSCommandUtility.addMenuItem(shortcut, command) {{{2 +" Adds the given menu item. + +function! s:VCSCommandUtility.addMenuItem(shortcut, command) + if s:menuEnabled + exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.'.a:shortcut.' '.a:command + endif +endfunction + +" Function: s:ClearMenu() {{{2 +" Removes all VCSCommand menu items +function! s:ClearMenu() + if s:menuEnabled + execute 'aunmenu' s:menuRoot + endif +endfunction + " Function: s:CreateMapping(shortcut, expansion, display) {{{2 " Creates the given mapping by prepending the contents of " 'VCSCommandMapPrefix' (by default 'c') to the given shortcut and @@ -1289,7 +1306,7 @@ com! VCSCommandDisableBufferSetup call VCSCommandDisableBufferSetup() com! VCSCommandEnableBufferSetup call VCSCommandEnableBufferSetup() " Allow reloading VCSCommand.vim -com! VCSReload let savedPlugins = s:plugins|let s:plugins = {}|execute 'aunmenu '.VCSCommandGetOption('VCSCommandMenuRoot', '&Plugin').'.VCS' |unlet! g:loaded_VCSCommand|runtime plugin/vcscommand.vim|for plugin in values(savedPlugins)|execute 'source' plugin[0]|endfor|unlet savedPlugins +com! VCSReload let savedPlugins = s:plugins|let s:plugins = {}|call s:ClearMenu()|unlet! g:loaded_VCSCommand|runtime plugin/vcscommand.vim|for plugin in values(savedPlugins)|execute 'source' plugin[0]|endfor|unlet savedPlugins " Section: Plugin command mappings {{{1 nnoremap VCSAdd :VCSAdd @@ -1333,29 +1350,36 @@ let s:defaultMappings = [ \] if !VCSCommandGetOption('VCSCommandDisableMappings', 0) - for [shortcut, vcsFunction] in VCSCommandGetOption('VCSCommandMappings', s:defaultMappings) - call s:CreateMapping(shortcut, '' . vcsFunction, '''' . vcsFunction . '''') + for [s:shortcut, s:vcsFunction] in VCSCommandGetOption('VCSCommandMappings', s:defaultMappings) + call s:CreateMapping(s:shortcut, '' . s:vcsFunction, '''' . s:vcsFunction . '''') endfor + unlet s:shortcut s:vcsFunction endif +unlet s:defaultMappings " Section: Menu items {{{1 -if !VCSCommandGetOption('VCSCommandDisableMenu', 0) - let s:menuRoot = VCSCommandGetOption('VCSCommandMenuRoot', '&Plugin') - let s:menuPriority = VCSCommandGetOption('VCSCommandMenuPriority', '') - - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Add VCSAdd' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.A&nnotate VCSAnnotate' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Commit VCSCommit' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.Delete VCSDelete' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Diff VCSDiff' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Info VCSInfo' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Log VCSLog' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.Revert VCSRevert' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Review VCSReview' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Status VCSStatus' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&Update VCSUpdate' - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.VCS.&VimDiff VCSVimDiff' -endif + +let s:menuEnabled = !VCSCommandGetOption('VCSCommandDisableMenu', 0) +let s:menuRoot = VCSCommandGetOption('VCSCommandMenuRoot', '&Plugin.VCS') +let s:menuPriority = VCSCommandGetOption('VCSCommandMenuPriority', '') + +for [s:shortcut, s:command] in [ + \['&Add', 'VCSAdd'], + \['A&nnotate', 'VCSAnnotate'], + \['&Commit', 'VCSCommit'], + \['Delete', 'VCSDelete'], + \['&Diff', 'VCSDiff'], + \['&Info', 'VCSInfo'], + \['&Log', 'VCSLog'], + \['Revert', 'VCSRevert'], + \['&Review', 'VCSReview'], + \['&Status', 'VCSStatus'], + \['&Update', 'VCSUpdate'], + \['&VimDiff', 'VCSVimDiff'] + \] + call s:VCSCommandUtility.addMenuItem(s:shortcut, s:command) +endfor +unlet s:shortcut s:command " Section: Autocommands to restore vimdiff state {{{1 augroup VimDiffRestore diff --git a/plugin/vcscvs.vim b/plugin/vcscvs.vim index e29da46..73d6a7f 100644 --- a/plugin/vcscvs.vim +++ b/plugin/vcscvs.vim @@ -428,17 +428,22 @@ for [pluginName, commandText, shortCut] in mappingInfo endif endfor -" Section: Menu items {{{1 -amenu &Plugin.VCS.CVS.&Edit CVSEdit -amenu &Plugin.VCS.CVS.Ed&itors CVSEditors -amenu &Plugin.VCS.CVS.Unedi&t CVSUnedit -amenu &Plugin.VCS.CVS.&Watchers CVSWatchers -amenu &Plugin.VCS.CVS.WatchAdd CVSWatchAdd -amenu &Plugin.VCS.CVS.WatchOn CVSWatchOn -amenu &Plugin.VCS.CVS.WatchOff CVSWatchOff -amenu &Plugin.VCS.CVS.WatchRemove CVSWatchRemove - " Section: Plugin Registration {{{1 let s:VCSCommandUtility = VCSCommandRegisterModule('CVS', expand(''), s:cvsFunctions, s:cvsExtensionMappings) +" Section: Menu items {{{1 +for [s:shortcut, s:command] in [ + \['CVS.&Edit', 'CVSEdit'], + \['CVS.Ed&itors', 'CVSEditors'], + \['CVS.Unedi&t', 'CVSUnedit'], + \['CVS.&Watchers', 'CVSWatchers'], + \['CVS.WatchAdd', 'CVSWatchAdd'], + \['CVS.WatchOn', 'CVSWatchOn'], + \['CVS.WatchOff', 'CVSWatchOff'], + \['CVS.WatchRemove', 'CVSWatchRemove'] + \] + call s:VCSCommandUtility.addMenuItem(s:shortcut, s:command) +endfor +unlet s:shortcut s:command + let &cpo = s:save_cpo -- 2.11.4.GIT