fix some bugs when dealing with invalid bookmarks

This commit is contained in:
Martin Grenfell 2008-07-02 21:15:28 +12:00
parent a0573c51b1
commit f5a20e5379

View File

@ -211,15 +211,15 @@ function! s:oBookmark.CacheBookmarks() dict
try try
let bookmark = s:oBookmark.New(name, s:oPath.New(path)) let bookmark = s:oBookmark.New(name, s:oPath.New(path))
call add(bookmarks, bookmark)
catch /NERDTree.Path.InvalidArguments/ catch /NERDTree.Path.InvalidArguments/
let invalidBookmarksFound += 1 let invalidBookmarksFound += 1
endtry endtry
call add(bookmarks, bookmark)
endfor endfor
let g:NERDTreeBookmarks = bookmarks let g:NERDTreeBookmarks = bookmarks
if invalidBookmarksFound if invalidBookmarksFound
call s:Echo(invalidBookmarksFound . " invalid bookmarks were read and discarded") call s:Echo(invalidBookmarksFound . " invalid bookmarks were read and discarded")
call s:WriteBookmarks() call s:oBookmark.Write()
endif endif
endif endif
endfunction endfunction
@ -278,7 +278,7 @@ endfunction
" Create a new bookmark object with the given name and path object " Create a new bookmark object with the given name and path object
function! s:oBookmark.New(name, path) dict function! s:oBookmark.New(name, path) dict
if a:name !~ '^[0-9a-zA-Z_]*$' if a:name !~ '^[0-9a-zA-Z_]*$'
throw "NERDTree.IllegalBookmarkName illegal name:" a:name throw "NERDTree.IllegalBookmarkName illegal name:" . a:name
endif endif
let newBookmark = copy(self) let newBookmark = copy(self)
@ -2797,8 +2797,12 @@ endfunction
function! s:BookmarkNode(name) function! s:BookmarkNode(name)
let currentNode = s:GetSelectedNode() let currentNode = s:GetSelectedNode()
if currentNode != {} if currentNode != {}
call currentNode.Bookmark(a:name) try
call s:RenderView() call currentNode.Bookmark(a:name)
call s:RenderView()
catch /NERDTree.IllegalBookmarkName/
call s:Echo("bookmark names must be made up of alpha numeric characters and underscores")
endtry
else else
call s:Echo("select a node first") call s:Echo("select a node first")
endif endif