2009-07-19 01:21:57 -04:00
|
|
|
" ============================================================================
|
2009-08-21 09:54:28 -04:00
|
|
|
" File: fs_menu.vim
|
2009-07-19 01:21:57 -04:00
|
|
|
" Description: plugin for the NERD Tree that provides a file system menu
|
2009-10-08 21:46:40 -04:00
|
|
|
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
|
2009-07-19 01:21:57 -04:00
|
|
|
" 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_fs_menu")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_nerdtree_fs_menu = 1
|
|
|
|
|
2009-07-21 03:26:48 -04:00
|
|
|
call NERDTreeAddMenuItem({'text': '(a)dd a childnode', 'shortcut': 'a', 'callback': 'NERDTreeAddNode'})
|
2011-02-07 23:16:30 -05:00
|
|
|
call NERDTreeAddMenuItem({'text': '(m)ove the current node', 'shortcut': 'm', 'callback': 'NERDTreeMoveNode'})
|
|
|
|
call NERDTreeAddMenuItem({'text': '(d)elete the current node', 'shortcut': 'd', 'callback': 'NERDTreeDeleteNode'})
|
2009-07-19 01:34:28 -04:00
|
|
|
if g:NERDTreePath.CopyingSupported()
|
2009-07-21 03:26:48 -04:00
|
|
|
call NERDTreeAddMenuItem({'text': '(c)copy the current node', 'shortcut': 'c', 'callback': 'NERDTreeCopyNode'})
|
2009-07-19 01:34:28 -04:00
|
|
|
endif
|
2009-07-19 01:21:57 -04:00
|
|
|
|
|
|
|
"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: s:promptToDelBuffer(bufnum, msg){{{1
|
|
|
|
"prints out the given msg and, if the user responds by pushing 'y' then the
|
|
|
|
"buffer with the given bufnum is deleted
|
|
|
|
"
|
|
|
|
"Args:
|
|
|
|
"bufnum: the buffer that may be deleted
|
|
|
|
"msg: a message that will be echoed to the user asking them if they wish to
|
|
|
|
" del the buffer
|
|
|
|
function! s:promptToDelBuffer(bufnum, msg)
|
|
|
|
echo a:msg
|
|
|
|
if nr2char(getchar()) ==# 'y'
|
|
|
|
exec "silent bdelete! " . a:bufnum
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2009-07-19 01:34:28 -04:00
|
|
|
"FUNCTION: NERDTreeAddNode(){{{1
|
|
|
|
function! NERDTreeAddNode()
|
2009-07-19 01:21:57 -04:00
|
|
|
let curDirNode = g:NERDTreeDirNode.GetSelected()
|
|
|
|
|
|
|
|
let newNodeName = input("Add a childnode\n".
|
|
|
|
\ "==========================================================\n".
|
|
|
|
\ "Enter the dir/file name to be created. Dirs end with a '/'\n" .
|
2011-07-04 08:56:39 -04:00
|
|
|
\ "", curDirNode.path.str() . g:NERDTreePath.Slash(), "file")
|
2009-07-19 01:21:57 -04:00
|
|
|
|
|
|
|
if newNodeName ==# ''
|
|
|
|
call s:echo("Node Creation Aborted.")
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
try
|
|
|
|
let newPath = g:NERDTreePath.Create(newNodeName)
|
2009-08-18 10:06:11 -04:00
|
|
|
let parentNode = b:NERDTreeRoot.findNode(newPath.getParent())
|
2009-07-19 01:21:57 -04:00
|
|
|
|
|
|
|
let newTreeNode = g:NERDTreeFileNode.New(newPath)
|
|
|
|
if parentNode.isOpen || !empty(parentNode.children)
|
|
|
|
call parentNode.addChild(newTreeNode, 1)
|
|
|
|
call NERDTreeRender()
|
|
|
|
call newTreeNode.putCursorHere(1, 0)
|
|
|
|
endif
|
|
|
|
catch /^NERDTree/
|
|
|
|
call s:echoWarning("Node Not Created.")
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2009-07-19 01:34:28 -04:00
|
|
|
"FUNCTION: NERDTreeMoveNode(){{{1
|
|
|
|
function! NERDTreeMoveNode()
|
2009-07-19 01:21:57 -04:00
|
|
|
let curNode = g:NERDTreeFileNode.GetSelected()
|
|
|
|
let newNodePath = input("Rename the current node\n" .
|
|
|
|
\ "==========================================================\n" .
|
|
|
|
\ "Enter the new path for the node: \n" .
|
2011-07-04 08:56:39 -04:00
|
|
|
\ "", curNode.path.str(), "file")
|
2009-07-19 01:21:57 -04:00
|
|
|
|
|
|
|
if newNodePath ==# ''
|
|
|
|
call s:echo("Node Renaming Aborted.")
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
try
|
2009-08-23 07:56:33 -04:00
|
|
|
let bufnum = bufnr(curNode.path.str())
|
2009-07-19 01:21:57 -04:00
|
|
|
|
|
|
|
call curNode.rename(newNodePath)
|
|
|
|
call NERDTreeRender()
|
|
|
|
|
|
|
|
"if the node is open in a buffer, ask the user if they want to
|
|
|
|
"close that buffer
|
|
|
|
if bufnum != -1
|
|
|
|
let prompt = "\nNode renamed.\n\nThe old file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
|
|
|
|
call s:promptToDelBuffer(bufnum, prompt)
|
|
|
|
endif
|
|
|
|
|
|
|
|
call curNode.putCursorHere(1, 0)
|
|
|
|
|
|
|
|
redraw
|
|
|
|
catch /^NERDTree/
|
|
|
|
call s:echoWarning("Node Not Renamed.")
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2009-07-19 01:34:28 -04:00
|
|
|
" FUNCTION: NERDTreeDeleteNode() {{{1
|
|
|
|
function! NERDTreeDeleteNode()
|
2009-07-19 01:21:57 -04:00
|
|
|
let currentNode = g:NERDTreeFileNode.GetSelected()
|
|
|
|
let confirmed = 0
|
|
|
|
|
|
|
|
if currentNode.path.isDirectory
|
|
|
|
let choice =input("Delete the current node\n" .
|
|
|
|
\ "==========================================================\n" .
|
|
|
|
\ "STOP! To delete this entire directory, type 'yes'\n" .
|
2009-09-05 06:29:11 -04:00
|
|
|
\ "" . currentNode.path.str() . ": ")
|
2009-07-19 01:21:57 -04:00
|
|
|
let confirmed = choice ==# 'yes'
|
|
|
|
else
|
|
|
|
echo "Delete the current node\n" .
|
|
|
|
\ "==========================================================\n".
|
|
|
|
\ "Are you sure you wish to delete the node:\n" .
|
2009-09-05 06:29:11 -04:00
|
|
|
\ "" . currentNode.path.str() . " (yN):"
|
2009-07-19 01:21:57 -04:00
|
|
|
let choice = nr2char(getchar())
|
|
|
|
let confirmed = choice ==# 'y'
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
if confirmed
|
|
|
|
try
|
|
|
|
call currentNode.delete()
|
|
|
|
call NERDTreeRender()
|
|
|
|
|
|
|
|
"if the node is open in a buffer, ask the user if they want to
|
|
|
|
"close that buffer
|
2009-08-23 07:56:33 -04:00
|
|
|
let bufnum = bufnr(currentNode.path.str())
|
2009-07-19 01:21:57 -04:00
|
|
|
if buflisted(bufnum)
|
|
|
|
let prompt = "\nNode deleted.\n\nThe file is open in buffer ". bufnum . (bufwinnr(bufnum) ==# -1 ? " (hidden)" : "") .". Delete this buffer? (yN)"
|
|
|
|
call s:promptToDelBuffer(bufnum, prompt)
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw
|
|
|
|
catch /^NERDTree/
|
|
|
|
call s:echoWarning("Could not remove node")
|
|
|
|
endtry
|
|
|
|
else
|
|
|
|
call s:echo("delete aborted")
|
|
|
|
endif
|
|
|
|
|
|
|
|
endfunction
|
|
|
|
|
2009-07-19 01:34:28 -04:00
|
|
|
" FUNCTION: NERDTreeCopyNode() {{{1
|
|
|
|
function! NERDTreeCopyNode()
|
2009-07-19 01:21:57 -04:00
|
|
|
let currentNode = g:NERDTreeFileNode.GetSelected()
|
|
|
|
let newNodePath = input("Copy the current node\n" .
|
|
|
|
\ "==========================================================\n" .
|
|
|
|
\ "Enter the new path to copy the node to: \n" .
|
2011-07-04 08:56:39 -04:00
|
|
|
\ "", currentNode.path.str(), "file")
|
2009-07-19 01:21:57 -04:00
|
|
|
|
|
|
|
if newNodePath != ""
|
|
|
|
"strip trailing slash
|
|
|
|
let newNodePath = substitute(newNodePath, '\/$', '', '')
|
|
|
|
|
|
|
|
let confirmed = 1
|
|
|
|
if currentNode.path.copyingWillOverwrite(newNodePath)
|
|
|
|
call s:echo("Warning: copying may overwrite files! Continue? (yN)")
|
|
|
|
let choice = nr2char(getchar())
|
|
|
|
let confirmed = choice ==# 'y'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if confirmed
|
|
|
|
try
|
|
|
|
let newNode = currentNode.copy(newNodePath)
|
2011-07-09 02:44:03 -04:00
|
|
|
if !empty(newNode)
|
|
|
|
call NERDTreeRender()
|
|
|
|
call newNode.putCursorHere(0, 0)
|
|
|
|
endif
|
2009-07-19 01:21:57 -04:00
|
|
|
catch /^NERDTree/
|
|
|
|
call s:echoWarning("Could not copy node")
|
|
|
|
endtry
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
call s:echo("Copy aborted.")
|
|
|
|
endif
|
|
|
|
redraw
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|