Create nested parent directories as needed
Allows the user to create or copy a nested node in a single step with ma or mc, recursively creating nested parent directories if needed, and without throwing any errors if they already exist. [Finishes #163, #34]
This commit is contained in:
parent
b0bb781fc7
commit
eacd5d72ec
@ -141,6 +141,7 @@ function! s:Path.Create(fullpath)
|
|||||||
|
|
||||||
"assume its a file and create
|
"assume its a file and create
|
||||||
else
|
else
|
||||||
|
call s:Path.createParentDirectories(a:fullpath)
|
||||||
call writefile([], a:fullpath)
|
call writefile([], a:fullpath)
|
||||||
endif
|
endif
|
||||||
catch
|
catch
|
||||||
@ -161,6 +162,8 @@ function! s:Path.copy(dest)
|
|||||||
throw "NERDTree.CopyingNotSupportedError: Copying is not supported on this OS"
|
throw "NERDTree.CopyingNotSupportedError: Copying is not supported on this OS"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
call s:Path.createParentDirectories(a:dest)
|
||||||
|
|
||||||
let dest = s:Path.WinToUnixPath(a:dest)
|
let dest = s:Path.WinToUnixPath(a:dest)
|
||||||
|
|
||||||
let cmd = g:NERDTreeCopyCmd . " " . escape(self.str(), nerdtree#escChars()) . " " . escape(dest, nerdtree#escChars())
|
let cmd = g:NERDTreeCopyCmd . " " . escape(self.str(), nerdtree#escChars()) . " " . escape(dest, nerdtree#escChars())
|
||||||
@ -197,6 +200,20 @@ function! s:Path.copyingWillOverwrite(dest)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"FUNCTION: Path.createParentDirectories(path) {{{1
|
||||||
|
"
|
||||||
|
"create parent directories for this path if needed
|
||||||
|
"without throwing any errors is those directories already exist
|
||||||
|
"
|
||||||
|
"Args:
|
||||||
|
"path: full path of the node whose parent directories may need to be created
|
||||||
|
function! s:Path.createParentDirectories(path)
|
||||||
|
let dir_path = fnamemodify(a:path, ':h')
|
||||||
|
if !isdirectory(dir_path)
|
||||||
|
call mkdir(dir_path, 'p')
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
"FUNCTION: Path.delete() {{{1
|
"FUNCTION: Path.delete() {{{1
|
||||||
"
|
"
|
||||||
"Deletes the file represented by this path.
|
"Deletes the file represented by this path.
|
||||||
|
@ -114,7 +114,10 @@ function! NERDTreeAddNode()
|
|||||||
let parentNode = b:NERDTreeRoot.findNode(newPath.getParent())
|
let parentNode = b:NERDTreeRoot.findNode(newPath.getParent())
|
||||||
|
|
||||||
let newTreeNode = g:NERDTreeFileNode.New(newPath)
|
let newTreeNode = g:NERDTreeFileNode.New(newPath)
|
||||||
if parentNode.isOpen || !empty(parentNode.children)
|
if empty(parentNode)
|
||||||
|
call b:NERDTreeRoot.refresh()
|
||||||
|
call nerdtree#renderView()
|
||||||
|
elseif parentNode.isOpen || !empty(parentNode.children)
|
||||||
call parentNode.addChild(newTreeNode, 1)
|
call parentNode.addChild(newTreeNode, 1)
|
||||||
call NERDTreeRender()
|
call NERDTreeRender()
|
||||||
call newTreeNode.putCursorHere(1, 0)
|
call newTreeNode.putCursorHere(1, 0)
|
||||||
@ -224,7 +227,10 @@ function! NERDTreeCopyNode()
|
|||||||
if confirmed
|
if confirmed
|
||||||
try
|
try
|
||||||
let newNode = currentNode.copy(newNodePath)
|
let newNode = currentNode.copy(newNodePath)
|
||||||
if !empty(newNode)
|
if empty(newNode)
|
||||||
|
call b:NERDTreeRoot.refresh()
|
||||||
|
call nerdtree#renderView()
|
||||||
|
else
|
||||||
call NERDTreeRender()
|
call NERDTreeRender()
|
||||||
call newNode.putCursorHere(0, 0)
|
call newNode.putCursorHere(0, 0)
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user