From 83d108894ee9a7e0a291a1197fede2a39dec5005 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sat, 14 Nov 2015 17:35:07 +0000 Subject: [PATCH] move a bunch of `b:NERDTree.*` vars into the b:NERDTree.ui obj --- autoload/nerdtree/ui_glue.vim | 4 +-- lib/nerdtree/creator.vim | 12 ------- lib/nerdtree/nerdtree.vim | 3 +- lib/nerdtree/path.vim | 6 ++-- lib/nerdtree/ui.vim | 63 +++++++++++++++++++++++++++++------ 5 files changed, 58 insertions(+), 30 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 3bd74ce..965b259 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -241,7 +241,7 @@ endfunction " FUNCTION: s:displayHelp() {{{1 " toggles the help display function! s:displayHelp() - let b:treeShowHelp = b:treeShowHelp ? 0 : 1 + call b:NERDTree.ui.toggleHelp() call b:NERDTree.render() call b:NERDTree.ui.centerView() endfunction @@ -280,7 +280,7 @@ function! s:findAndRevealPath() else call g:NERDTree.CursorToTreeWin() endif - let b:NERDTreeShowHidden = g:NERDTreeShowHidden + call b:NERDTree.setShowHidden(g:NERDTreeShowHidden) call s:chRoot(g:NERDTreeDirNode.New(p.getParent())) else if !g:NERDTree.IsOpen() diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim index 7289d3f..87d1b1b 100644 --- a/lib/nerdtree/creator.vim +++ b/lib/nerdtree/creator.vim @@ -67,12 +67,6 @@ function! s:Creator.createTabTree(name) call self._createTreeWin() call self._createNERDTree(path, "tab") - let b:treeShowHelp = 0 - let b:NERDTreeIgnoreEnabled = 1 - let b:NERDTreeShowFiles = g:NERDTreeShowFiles - let b:NERDTreeShowHidden = g:NERDTreeShowHidden - let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks - call b:NERDTree.render() call b:NERDTreeRoot.putCursorHere(0, 0) @@ -285,12 +279,6 @@ function! s:Creator._setCommonBufOptions() endif call self._setupStatusline() - - let b:treeShowHelp = 0 - let b:NERDTreeIgnoreEnabled = 1 - let b:NERDTreeShowFiles = g:NERDTreeShowFiles - let b:NERDTreeShowHidden = g:NERDTreeShowHidden - let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks call self._bindMappings() setlocal filetype=nerdtree endfunction diff --git a/lib/nerdtree/nerdtree.vim b/lib/nerdtree/nerdtree.vim index db55cb9..938c5f8 100644 --- a/lib/nerdtree/nerdtree.vim +++ b/lib/nerdtree/nerdtree.vim @@ -43,7 +43,7 @@ endfunction "FUNCTION: s:NERDTree.CursorToBookmarkTable(){{{1 "Places the cursor at the top of the bookmarks table function! s:NERDTree.CursorToBookmarkTable() - if !b:NERDTreeShowBookmarks + if !b:NERDTree.ui.getShowBookmarks() throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active" endif @@ -128,7 +128,6 @@ function! s:NERDTree.New(path, type) let newObj.ui = g:NERDTreeUI.New(newObj) let newObj.root = g:NERDTreeDirNode.New(a:path) let newObj._type = a:type - return newObj endfunction diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim index 2af07dd..4a2314e 100644 --- a/lib/nerdtree/path.vim +++ b/lib/nerdtree/path.vim @@ -410,7 +410,7 @@ endfunction "returns true if this path should be ignored function! s:Path.ignore() "filter out the user specified paths to ignore - if b:NERDTreeIgnoreEnabled + if b:NERDTree.ui.isIgnoreFilterEnabled() for i in g:NERDTreeIgnore if self._ignorePatternMatches(i) return 1 @@ -425,11 +425,11 @@ function! s:Path.ignore() endif "dont show hidden files unless instructed to - if b:NERDTreeShowHidden ==# 0 && self.isUnixHiddenFile() + if !b:NERDTree.ui.getShowHidden() && self.isUnixHiddenFile() return 1 endif - if b:NERDTreeShowFiles ==# 0 && self.isDirectory ==# 0 + if b:NERDTree.ui.getShowFiles() ==# 0 && self.isDirectory ==# 0 return 1 endif diff --git a/lib/nerdtree/ui.vim b/lib/nerdtree/ui.vim index 8e18805..bacbf63 100644 --- a/lib/nerdtree/ui.vim +++ b/lib/nerdtree/ui.vim @@ -21,7 +21,7 @@ endfunction "prints out the quick help function! s:UI._dumpHelp() let old_h = @h - if b:treeShowHelp ==# 1 + if self.getShowHelp() let @h= "\" NERD tree (" . nerdtree#version() . ") quickhelp~\n" let @h=@h."\" ============================\n" let @h=@h."\" File node mappings~\n" @@ -87,10 +87,10 @@ function! s:UI._dumpHelp() let @h=@h."\"\n\" ----------------------------\n" let @h=@h."\" Tree filtering mappings~\n" - let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (b:NERDTreeShowHidden ? "on" : "off") . ")\n" - let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (b:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n" - let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (b:NERDTreeShowFiles ? "on" : "off") . ")\n" - let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (b:NERDTreeShowBookmarks ? "on" : "off") . ")\n" + let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (self.getShowHidden() ? "on" : "off") . ")\n" + let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (self.isIgnoreFilterEnabled() ? "on" : "off") . ")\n" + let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (self.getShowFiles() ? "on" : "off") . ")\n" + let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (self.getShowBookmarks() ? "on" : "off") . ")\n" "add quickhelp entries for each custom key map let @h=@h."\"\n\" ----------------------------\n" @@ -129,6 +129,12 @@ endfunction function! s:UI.New(nerdtree) let newObj = copy(self) let newObj.nerdtree = a:nerdtree + let newObj._showHelp = 0 + let newObj._ignoreEnabled = 1 + let newObj._showFiles = g:NERDTreeShowFiles + let newObj._showHidden = g:NERDTreeShowHidden + let newObj._showBookmarks = g:NERDTreeShowBookmarks + return newObj endfunction @@ -259,6 +265,26 @@ function! s:UI.getRootLineNum() return rootLine endfunction +"FUNCTION: s:UI.getShowBookmarks() {{{1 +function! s:UI.getShowBookmarks() + return self._showBookmarks +endfunction + +"FUNCTION: s:UI.getShowFiles() {{{1 +function! s:UI.getShowFiles() + return self._showFiles +endfunction + +"FUNCTION: s:UI.getShowHelp() {{{1 +function! s:UI.getShowHelp() + return self._showHelp +endfunction + +"FUNCTION: s:UI.getShowHidden() {{{1 +function! s:UI.getShowHidden() + return self._showHidden +endfunction + "FUNCTION: s:UI._indentLevelFor(line) {{{1 function! s:UI._indentLevelFor(line) let level = match(a:line, '[^ \-+~'.g:NERDTreeDirArrowExpandable.g:NERDTreeDirArrowCollapsible.'`|]') / s:UI.IndentWid() @@ -275,6 +301,11 @@ function! s:UI.IndentWid() return 2 endfunction +"FUNCTION: s:UI.isIgnoreFilterEnabled() {{{1 +function! s:UI.isIgnoreFilterEnabled() + return self._ignoreEnabled == 1 +endfunction + "FUNCTION: s:UI.MarkupReg() {{{1 function! s:UI.MarkupReg() if g:NERDTreeDirArrows @@ -334,6 +365,11 @@ function! s:UI.saveScreenState() call nerdtree#exec(win . "wincmd w") endfunction +"FUNCTION: s:UI.setShowHidden(val) {{{1 +function! s:UI.setShowHidden(val) + let self._showHidden = a:val +endfunction + "FUNCTION: s:UI._stripMarkup(line, removeLeadingSpaces){{{1 "returns the given line with all the tree parts stripped off " @@ -395,7 +431,7 @@ function! s:UI.render() call cursor(line(".")+1, col(".")) endif - if b:NERDTreeShowBookmarks + if self.getShowBookmarks() call self._renderBookmarks() endif @@ -450,10 +486,15 @@ function! s:UI.renderViewSavingPosition() endif endfunction +"FUNCTION: s:UI.toggleHelp() {{{1 +function! s:UI.toggleHelp() + let self._showHelp = !self._showHelp +endfunction + " FUNCTION: s:UI.toggleIgnoreFilter() {{{1 " toggles the use of the NERDTreeIgnore option function! s:UI.toggleIgnoreFilter() - let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled + let self._ignoreEnabled = !self._ignoreEnabled call b:NERDTree.ui.renderViewSavingPosition() call b:NERDTree.ui.centerView() endfunction @@ -461,8 +502,8 @@ endfunction " FUNCTION: s:UI.toggleShowBookmarks() {{{1 " toggles the display of bookmarks function! s:UI.toggleShowBookmarks() - let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks - if b:NERDTreeShowBookmarks + let self._showBookmarks = !self._showBookmarks + if self.getShowBookmarks() call b:NERDTree.render() call g:NERDTree.CursorToBookmarkTable() else @@ -474,7 +515,7 @@ endfunction " FUNCTION: s:UI.toggleShowFiles() {{{1 " toggles the display of hidden files function! s:UI.toggleShowFiles() - let b:NERDTreeShowFiles = !b:NERDTreeShowFiles + let self._showFiles = !self._showFiles call b:NERDTree.ui.renderViewSavingPosition() call b:NERDTree.ui.centerView() endfunction @@ -482,7 +523,7 @@ endfunction " FUNCTION: s:UI.toggleShowHidden() {{{1 " toggles the display of hidden files function! s:UI.toggleShowHidden() - let b:NERDTreeShowHidden = !b:NERDTreeShowHidden + let self._showHidden = !self._showHidden call b:NERDTree.ui.renderViewSavingPosition() call self.centerView() endfunction