mirror of
https://github.com/preservim/nerdtree.git
synced 2024-10-19 06:00:39 +03:00
C++ create header/class menu option.
This commit is contained in:
parent
fc0d21cbbc
commit
f0287df9c7
66
nerdtree_plugin/cxx_class_menu.vim
Normal file
66
nerdtree_plugin/cxx_class_menu.vim
Normal file
@ -0,0 +1,66 @@
|
||||
" ============================================================================
|
||||
" File: fs_menu.vim
|
||||
" Description: plugin for the NERD Tree that provides a file system menu
|
||||
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
|
||||
" Last Change: 17 July, 2009
|
||||
" License: This program is free software. It comes without any warranty,
|
||||
" to the extent permitted by applicable law. You can redistribute
|
||||
" it and/or modify it under the terms of the Do What The Fuck You
|
||||
" Want To Public License, Version 2, as published by Sam Hocevar.
|
||||
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
"
|
||||
" ============================================================================
|
||||
if exists("g:loaded_nerdtree_cxx_class_menu")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_nerdtree_cxx_class_menu = 1
|
||||
|
||||
|
||||
call NERDTreeAddMenuItem({'text': 'create C++ header/class (p)air', 'shortcut': 'p', 'callback': 'NERDTreeAddCxxClass'})
|
||||
|
||||
"FUNCTION: s:echo(msg){{{1
|
||||
function! s:echo(msg)
|
||||
redraw
|
||||
echomsg "NERDTree: " . a:msg
|
||||
endfunction
|
||||
|
||||
"FUNCTION: s:echoWarning(msg){{{1
|
||||
function! s:echoWarning(msg)
|
||||
echohl warningmsg
|
||||
call s:echo(a:msg)
|
||||
echohl normal
|
||||
endfunction
|
||||
|
||||
"FUNCTION: NERDTreeAddNode(){{{1
|
||||
function! NERDTreeAddCxxClass()
|
||||
let curDirNode = g:NERDTreeDirNode.GetSelected()
|
||||
|
||||
let newNodeName = input("Create a C++ class\n".
|
||||
\ "==========================================================\n".
|
||||
\ "Create a new C++ .h/.cpp file pair with the given name\n" .
|
||||
\ "", "", "file")
|
||||
|
||||
if newNodeName ==# ''
|
||||
call s:echo("Node Creation Aborted.")
|
||||
return
|
||||
endif
|
||||
|
||||
try
|
||||
let newPathPrefix = curDirNode.path.str() . g:NERDTreePath.Slash() . newNodeName
|
||||
let newPathH = g:NERDTreePath.Create(newPathPrefix . ".h")
|
||||
let newPathCpp = g:NERDTreePath.Create(newPathPrefix . ".cpp")
|
||||
let parentNode = b:NERDTreeRoot.findNode(newPathH.getParent())
|
||||
|
||||
let newTreeNodeH = g:NERDTreeFileNode.New(newPathH)
|
||||
let newTreeNodeCpp = g:NERDTreeFileNode.New(newPathCpp)
|
||||
if parentNode.isOpen || !empty(parentNode.children)
|
||||
call parentNode.addChild(newTreeNodeH, 1)
|
||||
call parentNode.addChild(newTreeNodeCpp, 1)
|
||||
call NERDTreeRender()
|
||||
call newTreeNodeH.putCursorHere(1, 0)
|
||||
endif
|
||||
catch /^NERDTree/
|
||||
call s:echoWarning("Node Not Created.")
|
||||
endtry
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue
Block a user