" perforcemenu.vim: Create a menu for perforce plugin. " Author: Hari Krishna (hari_vim at yahoo dot com) " Last Change: 28-Aug-2006 @ 22:50 " Created: 07-Nov-2003 " Requires: Vim-6.2, perforce.vim(4.0) " Version: 2.1.0 " Licence: This program is free software; you can redistribute it and/or " modify it under the terms of the GNU General Public License. " See http://www.gnu.org/copyleft/gpl.txt if !exists("loaded_perforce") runtime plugin/perforce.vim endif if !exists("loaded_perforce") || loaded_perforce < 400 echomsg "perforcemenu: You need a newer version of perforce.vim plugin" finish endif " Make sure line-continuations won't cause any problem. This will be restored " at the end let s:save_cpo = &cpo set cpo&vim function! s:Get(setting, ...) if exists('g:p4'.a:setting) return g:p4{a:setting} endif if exists('*perforce#PFCall') let val = perforce#PFCall('s:_', a:setting) if val == '' && a:0 > 0 let val = a:1 endif return val endif return 0 endfunction function! s:PFExecCmd(cmd) " {{{ if exists(':'.a:cmd) == 2 exec a:cmd else call perforce#PFCall("s:EchoMessage", 'The command: ' . a:cmd . \ ' is not defined for this buffer.', 'WarningMsg') endif endfunction command! -nargs=1 PFExecCmd :call PFExecCmd() " }}} let s:loaded_perforcemenu = 1 " CreateMenu {{{ if s:Get('EnableMenu') || s:Get('EnablePopupMenu') " [-2f] function! s:CreateMenu(sub, expanded) if ! a:expanded let fileGroup = '.' else let fileGroup = '.&File.' endif exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '&Add :PAdd' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . 'S&ync :PSync' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '&Edit :PEdit' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '-Sep1- :' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . \ '&Delete :PDelete' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '&Revert :PRevert' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '-Sep2- :' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . 'Loc&k :PLock' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . \ 'U&nlock :PUnlock' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '-Sep3- :' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '&Diff :PDiff' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . 'Diff&2 :PDiff2' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . \ 'Revision\ &History :PFilelog' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . 'Propert&ies ' . \ ':PFstat -C' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '&Print :PPrint' exec 'amenu ' . a:sub . '&Perforce' . fileGroup . '-Sep4- :' if a:expanded exec 'amenu ' . a:sub . '&Perforce.&File.' . \ 'Resol&ve.Accept\ &Their\ Changesresolve\ -at ' . \ ':PResolve -at' exec 'amenu ' . a:sub . '&Perforce.&File.' . \ 'Resol&ve.Accept\ &Your\ Changesresolve\ -ay :PResolve -ay' exec 'amenu ' . a:sub . '&Perforce.&File.' . \ 'Resol&ve.&Automatic\ Resolveresolve\ -am :PResolve -am' exec 'amenu ' . a:sub . '&Perforce.&File.' . \ 'Resol&ve.&Safe\ Resolveresolve\ -as :PResolve -as' exec 'amenu ' . a:sub . '&Perforce.&File.' . \ 'Resol&ve.&Force\ Resolveresolve\ -af :PResolve -af' exec 'amenu ' . a:sub . '&Perforce.&File.' . \ 'Resol&ve.S&how\ Integrationsresolve\ -n :PResolve -n' exec 'amenu ' . a:sub . '&Perforce.&File.-Sep5- :' exec 'amenu ' . a:sub . '&Perforce.&File.Sa&ve\ Current\ Spec ' . \':PFExecCmd W' exec 'amenu ' . a:sub . '&Perforce.&File.Save\ and\ &Quit\ ' . \'Current\ Spec :PFExecCmd WQ' endif if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.&Opened\ Files :POpened' exec 'amenu ' . a:sub . '&Perforce.&Refresh\ Active\ Pane ' . \ ':PRefreshActivePane' exec 'amenu ' . a:sub . '&Perforce.-Sep6- :' else exec 'amenu ' . a:sub . \ '&Perforce.&View.&BranchSpecs :PBranches' exec 'amenu ' . a:sub . '&Perforce.&View.&Changelist.' . \ '&Pending\ Changelists :PChanges -s pending' exec 'amenu ' . a:sub . '&Perforce.&View.&Changelist.' . \ '&Submitted\ Changelists :PChanges -s submitted' exec 'amenu ' . a:sub . \ '&Perforce.&View.Cl&ientSpecs :PClients' exec 'amenu ' . a:sub . '&Perforce.&View.&Jobs :PJobs' exec 'amenu ' . a:sub . '&Perforce.&View.&Labels :PLabels' exec 'amenu ' . a:sub . '&Perforce.&View.&Users :PUsers' exec 'amenu ' . a:sub . '&Perforce.&View.&Depots :PDepots' exec 'amenu ' . a:sub . '&Perforce.&View.&Opened\ Files :POpened' exec 'amenu ' . a:sub . '&Perforce.&View.&Refresh\ Active\ Pane ' . \ ':PRefreshActivePane' endif if a:expanded exec 'amenu ' . a:sub . '&Perforce.&Settings.' . \ '&Switch\ Port\ Client\ User '. \ ':call perforce#PFCall("s:SwitchPortClientUser")' let p4Presets = split(perforce#PFGet('s:p4Presets'), ',') if len(p4Presets) > 0 let index = 0 while index < len(p4Presets) exec 'amenu ' a:sub.'&Perforce.&Settings.&'.index.'\ ' \ .escape(p4Presets[index], ' .') ':PFSwitch' index.'' let index = index + 1 endwhile endif endif if ! a:expanded exec 'amenu ' . a:sub . \ '&Perforce.New\ &Submission\ Template :PSubmit' else exec 'amenu ' . a:sub . '&Perforce.&Changelist.&New :PChange' exec 'amenu ' . a:sub . '&Perforce.&Changelist.' . \ '&Edit\ Current\ Changelist :PFExecCmd PItemOpen' exec 'amenu ' . a:sub . '&Perforce.&Changelist.' . \ 'Descri&be\ Current\ Changelist :PFExecCmd PItemDescribe' exec 'amenu ' . a:sub . '&Perforce.&Changelist.' . \ '&Delete\ Current\ Changelist :PFExecCmd PItemDelete' exec 'amenu ' . a:sub . '&Perforce.&Changelist.' . \ 'New\ &Submission\ Template :PSubmit' exec 'amenu ' . a:sub . '&Perforce.&Changelist.-Sep- :' exec 'amenu ' . a:sub . '&Perforce.&Changelist.' . \ 'View\ &Pending\ Changelists :PChanges -s pending' exec 'amenu ' . a:sub . '&Perforce.&Changelist.' . \ '&View\ Submitted\ Changelists :PChanges -s submitted' endif if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.&Branch :PBranch' else exec 'amenu ' . a:sub . '&Perforce.&Branch.&New :PBranch' exec 'amenu ' . a:sub . '&Perforce.&Branch.' . \ '&Edit\ Current\ BranchSpec :PFExecCmd PItemOpen' exec 'amenu ' . a:sub . '&Perforce.&Branch.' . \ 'Descri&be\ Current\ BranchSpec :PFExecCmd PItemDescribe' exec 'amenu ' . a:sub . '&Perforce.&Branch.' . \ '&Delete\ Current\ BranchSpec :PFExecCmd PItemDelete' exec 'amenu ' . a:sub . '&Perforce.&Branch.-Sep- :' exec 'amenu ' . a:sub . \ '&Perforce.&Branch.&View\ BranchSpecs :PBranches' endif if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.&Label :PLabel' else exec 'amenu ' . a:sub . '&Perforce.&Label.&New :PLabel' exec 'amenu ' . a:sub . '&Perforce.&Label.' . \ '&Edit\ Current\ LabelSpec :PFExecCmd PItemOpen' exec 'amenu ' . a:sub . '&Perforce.&Label.' . \ 'Descri&be\ Current\ LabelSpec :PFExecCmd PItemDescribe' exec 'amenu ' . a:sub . '&Perforce.&Label.' . \ '&Delete\ Current\ LabelSpec :PFExecCmd PItemDelete' exec 'amenu ' . a:sub . '&Perforce.&Label.-Sep1- :' exec 'amenu ' . a:sub . '&Perforce.&Label.' . \ '&Sync\ Client\ ' . s:Get('Client') . '\ to\ Current\ Label ' . \ ':PFExecCmd PLabelsSyncClient' exec 'amenu ' . a:sub . '&Perforce.&Label.' . \ '&Replace\ Files\ in\ Current\ Label\ with\ Client\ ' . \ s:Get('Client') . '\ files ' . ':PFExecCmd PLabelsSyncLabel' exec 'amenu ' . a:sub . '&Perforce.&Label.-Sep2- :' exec 'amenu ' . a:sub . \ '&Perforce.&Label.&View\ Labels :PLabels' endif if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.Cl&ient :PClient' else exec 'amenu ' . a:sub . \ '&Perforce.Cl&ient.&New :PClient +P' exec 'amenu ' . a:sub . '&Perforce.Cl&ient.' . \ '&Edit\ Current\ ClientSpec :PFExecCmd PItemOpen' exec 'amenu ' . a:sub . '&Perforce.Cl&ient.' . \ 'Descri&be\ Current\ ClientSpec :PFExecCmd PItemDescribe' exec 'amenu ' . a:sub . '&Perforce.Cl&ient.' . \ '&Delete\ Current\ ClientSpec :PFExecCmd PItemDelete' exec 'amenu ' . a:sub . '&Perforce.' . \ 'Cl&ient.&Edit\ ' . escape(s:Get('Client', 'Current Client'), ' ') . \ ' :PClient' exec 'amenu ' . a:sub . '&Perforce.Cl&ient.-Sep- :' exec 'amenu ' . a:sub . '&Perforce.Cl&ient.&Switch\ to\ Current' . \ '\ Client :exec "PFSwitch ' . s:Get('Port') . \ ' " . perforce#PFCall("s:GetCurrentItem")' exec 'amenu ' . a:sub . \ '&Perforce.Cl&ient.&View\ ClientSpecs :PClients' endif if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.&User :PUser' else exec 'amenu ' . a:sub . \ '&Perforce.&User.&New :PUser +P' exec 'amenu ' . a:sub . '&Perforce.&User.' . \ '&Edit\ Current\ UserSpec :PFExecCmd PItemOpen' exec 'amenu ' . a:sub . '&Perforce.&User.' . \ 'Descri&be\ Current\ UserSpec :PFExecCmd PItemDescribe' exec 'amenu ' . a:sub . '&Perforce.&User.' . \ '&Delete\ Current\ UserSpec :PFExecCmd PItemDelete' exec 'amenu ' . a:sub . \ '&Perforce.&User.&Edit\ ' . \ escape(s:Get('User', 'Current User'), ' ') . ' :PUser' exec 'amenu ' . a:sub . '&Perforce.&User.-Sep- :' exec 'amenu ' . a:sub . '&Perforce.&User.&Switch\ to\ Current' . \ '\ User :exec "PFSwitch ' . s:Get('Port') . ' ' . \ s:Get('Client') . ' " . perforce#PFCall("s:GetCurrentItem")' exec 'amenu ' . a:sub . \ '&Perforce.&User.&View\ Users :PUsers' endif if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.&Job :PJob' else exec 'amenu ' . a:sub . '&Perforce.&Job.&New :PJob' exec 'amenu ' . a:sub . '&Perforce.&Job.' . \ '&Edit\ Current\ JobSpec :PFExecCmd PItemOpen' exec 'amenu ' . a:sub . '&Perforce.&Job.' . \ 'Descri&be\ Current\ JobSpec :PFExecCmd PItemDescribe' exec 'amenu ' . a:sub . '&Perforce.&Job.' . \ '&Delete\ Current\ JobSpec :PFExecCmd PItemDelete' exec 'amenu ' . a:sub . '&Perforce.&Job.-Sep1- :' exec 'amenu ' . a:sub . '&Perforce.&Job.&Edit\ Job&Spec ' . \ ':PJobspec' exec 'amenu ' . a:sub . '&Perforce.&Job.-Sep2- :' exec 'amenu ' . a:sub . '&Perforce.&Job.&View\ Jobs :PJobs' endif if a:expanded exec 'amenu ' . a:sub . '&Perforce.&Depot.&New :PDepot' exec 'amenu ' . a:sub . '&Perforce.&Depot.' . \ '&Edit\ Current\ DepotSpec :PFExecCmd PItemOpen' exec 'amenu ' . a:sub . '&Perforce.&Depot.' . \ 'Descri&be\ Current\ DepotSpec :PFExecCmd PItemDescribe' exec 'amenu ' . a:sub . '&Perforce.&Depot.' . \ '&Delete\ Current\ DepotSpec :PFExecCmd PItemDelete' exec 'amenu ' . a:sub . '&Perforce.&Depot.-Sep- :' exec 'amenu ' . a:sub . \ '&Perforce.&Depot.&View\ Depots :PDepots' endif if ! a:expanded exec 'amenu ' . a:sub . \ '&Perforce.Open\ Current\ File\ From\ A¬her\ Branch :E' else exec 'amenu ' . a:sub . \ '&Perforce.&Tools.Open\ Current\ File\ From\ A¬her\ Branch ' . \ ':E' endif if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.-Sep7- :' exec 'amenu ' . a:sub . '&Perforce.Sa&ve\ Current\ Spec ' . \':PFExecCmd W' exec 'amenu ' . a:sub . '&Perforce.Save\ and\ &Quit\ ' . \'Current\ Spec :PFExecCmd WQ' endif exec 'amenu ' . a:sub . '&Perforce.-Sep8- :' exec 'amenu ' . a:sub . '&Perforce.Re-Initial&ze :PFInitialize' if ! a:expanded exec 'amenu ' . a:sub . '&Perforce.&Help :PHelp' else exec 'amenu ' . a:sub . '&Perforce.&Help.&General :PHelp' exec 'amenu ' . a:sub . '&Perforce.&Help.&Simple :PHelp simple' exec 'amenu ' . a:sub . \ '&Perforce.&Help.&Commands :PHelp commands' exec 'amenu ' . a:sub . \ '&Perforce.&Help.&Environment :PHelp environment' exec 'amenu ' . a:sub . \ '&Perforce.&Help.&Filetypes :PHelp filetypes' exec 'amenu ' . a:sub . '&Perforce.&Help.&Jobview :PHelp jobview' exec 'amenu ' . a:sub . \ '&Perforce.&Help.&Revisions :PHelp revisions' exec 'amenu ' . a:sub . '&Perforce.&Help.&Usage :PHelp usage' exec 'amenu ' . a:sub . '&Perforce.&Help.&Views :PHelp views' endif endfunction endif " }}} " " Add menu entries if user wants. " silent! unmenu Perforce silent! unmenu! Perforce if s:Get('EnableMenu') call s:CreateMenu('', s:Get('UseExpandedMenu')) endif silent! unmenu PopUp.Perforce silent! unmenu! PopUp.Perforce if s:Get('EnablePopupMenu') call s:CreateMenu('PopUp.', s:Get('UseExpandedPopupMenu')) endif " We no longer need this. silent! delf s:CreateMenu silent! delf s:Get let v:errmsg = '' " Make sure line-continuations won't cause any problem. This will be restored " at the end let s:save_cpo = &cpo set cpo&vim " vim6:fdm=marker et sw=2