From 1e0d1cbc8f4975bc169dc3e900c14152c03d058c Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Wed, 9 Jul 2014 09:25:25 +0100 Subject: [PATCH] move some more view code into the UI class --- autoload/nerdtree.vim | 14 ------- autoload/nerdtree/ui_glue.vim | 44 +++++----------------- lib/nerdtree/ui.vim | 70 +++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 48 deletions(-) diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim index f5becc5..64ac5dd 100644 --- a/autoload/nerdtree.vim +++ b/autoload/nerdtree.vim @@ -126,20 +126,6 @@ endfunction " SECTION: View Functions {{{1 "============================================================ " -"FUNCTION: nerdtree#centerView() {{{2 -"centers the nerd tree window around the cursor (provided the nerd tree -"options permit) -function! nerdtree#centerView() - if g:NERDTreeAutoCenter - let current_line = winline() - let lines_to_top = current_line - let lines_to_bottom = winheight(nerdtree#getTreeWinNum()) - current_line - if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold - normal! zz - endif - endif -endfunction - " FUNCTION: nerdtree#chRoot(node) {{{2 " changes the current root to the selected one function! nerdtree#chRoot(node) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 0209472..6058350 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -243,7 +243,7 @@ endfunction function! s:displayHelp() let b:treeShowHelp = b:treeShowHelp ? 0 : 1 call b:NERDTree.render() - call nerdtree#centerView() + call b:NERDTree.ui.centerView() endfunction " FUNCTION: s:findAndRevealPath() {{{1 @@ -372,7 +372,7 @@ function! s:jumpToChild(currentNode, direction) call targetNode.putCursorHere(1, 0) - call nerdtree#centerView() + call b:NERDTree.ui.centerView() endfunction @@ -400,7 +400,7 @@ endfunction function! s:jumpToParent(node) if !empty(a:node.parent) call a:node.parent.putCursorHere(1, 0) - call nerdtree#centerView() + call b:NERDTree.ui.centerView() else call nerdtree#echo("cannot jump to parent") endif @@ -410,7 +410,7 @@ endfunction " moves the cursor to the root node function! s:jumpToRoot() call b:NERDTreeRoot.putCursorHere(1, 0) - call nerdtree#centerView() + call b:NERDTree.ui.centerView() endfunction " FUNCTION: s:jumpToNextSibling(node) {{{1 @@ -434,7 +434,7 @@ function! s:jumpToSibling(currentNode, forward) if !empty(sibling) call sibling.putCursorHere(1, 0) - call nerdtree#centerView() + call b:NERDTree.ui.centerView() endif endfunction @@ -570,53 +570,29 @@ function! s:showMenu(node) endfunction " FUNCTION: s:toggleIgnoreFilter() {{{1 -" toggles the use of the NERDTreeIgnore option function! s:toggleIgnoreFilter() - let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled - call b:NERDTree.ui.renderViewSavingPosition() - call nerdtree#centerView() + call b:NERDTree.ui.toggleIgnoreFilter() endfunction " FUNCTION: s:toggleShowBookmarks() {{{1 -" toggles the display of bookmarks function! s:toggleShowBookmarks() - let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks - if b:NERDTreeShowBookmarks - call b:NERDTree.render() - call nerdtree#putCursorOnBookmarkTable() - else - call b:NERDTree.ui.renderViewSavingPosition() - endif - call nerdtree#centerView() + call b:NERDTree.ui.toggleShowBookmarks() endfunction " FUNCTION: s:toggleShowFiles() {{{1 -" toggles the display of hidden files function! s:toggleShowFiles() - let b:NERDTreeShowFiles = !b:NERDTreeShowFiles - call b:NERDTree.ui.renderViewSavingPosition() - call nerdtree#centerView() + call b:NERDTree.ui.toggleShowFiles() endfunction " FUNCTION: s:toggleShowHidden() {{{1 " toggles the display of hidden files function! s:toggleShowHidden() - let b:NERDTreeShowHidden = !b:NERDTreeShowHidden - call b:NERDTree.ui.renderViewSavingPosition() - call nerdtree#centerView() + call b:NERDTree.ui.toggleShowHidden() endfunction " FUNCTION: s:toggleZoom() {{{1 -" zoom (maximize/minimize) the NERDTree window function! s:toggleZoom() - if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed - let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize - exec "silent vertical resize ". size - let b:NERDTreeZoomed = 0 - else - exec "vertical resize" - let b:NERDTreeZoomed = 1 - endif + call b:NERDTree.ui.toggleZoom() endfunction "FUNCTION: nerdtree#ui_glue#upDir(keepState) {{{1 diff --git a/lib/nerdtree/ui.vim b/lib/nerdtree/ui.vim index 003e566..ed93d80 100644 --- a/lib/nerdtree/ui.vim +++ b/lib/nerdtree/ui.vim @@ -3,6 +3,26 @@ let s:UI = {} let g:NERDTreeUI = s:UI + +function! s:UI.lolcats() + echomsg "lolcats" +endfunction + +"FUNCTION: s:UI.centerView() {{{2 +"centers the nerd tree window around the cursor (provided the nerd tree +"options permit) +function! s:UI.centerView() + if g:NERDTreeAutoCenter + let current_line = winline() + let lines_to_top = current_line + let lines_to_bottom = winheight(nerdtree#getTreeWinNum()) - current_line + if lines_to_top < g:NERDTreeAutoCenterThreshold || lines_to_bottom < g:NERDTreeAutoCenterThreshold + normal! zz + endif + endif +endfunction + +"FUNCTION: s:UI.new(nerdtree) {{{1 function! s:UI.New(nerdtree) let newObj = copy(self) let newObj.nerdtree = a:nerdtree @@ -260,3 +280,53 @@ function! s:UI.renderViewSavingPosition() call currentNode.putCursorHere(0, 0) endif endfunction + +" FUNCTION: s:UI.toggleIgnoreFilter() {{{1 +" toggles the use of the NERDTreeIgnore option +function! s:UI.toggleIgnoreFilter() + let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled + call b:NERDTree.ui.renderViewSavingPosition() + call b:NERDTree.ui.centerView() +endfunction + +" FUNCTION: s:UI.toggleShowBookmarks() {{{1 +" toggles the display of bookmarks +function! s:UI.toggleShowBookmarks() + let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks + if b:NERDTreeShowBookmarks + call b:NERDTree.render() + call nerdtree#putCursorOnBookmarkTable() + else + call b:NERDTree.ui.renderViewSavingPosition() + endif + call b:NERDTree.ui.centerView() +endfunction + +" FUNCTION: s:UI.toggleShowFiles() {{{1 +" toggles the display of hidden files +function! s:UI.toggleShowFiles() + let b:NERDTreeShowFiles = !b:NERDTreeShowFiles + call b:NERDTree.ui.renderViewSavingPosition() + call b:NERDTree.ui.centerView() +endfunction + +" FUNCTION: s:UI.toggleShowHidden() {{{1 +" toggles the display of hidden files +function! s:UI.toggleShowHidden() + let b:NERDTreeShowHidden = !b:NERDTreeShowHidden + call b:NERDTree.ui.renderViewSavingPosition() + call self.centerView() +endfunction + +" FUNCTION: s:UI.toggleZoom() {{{1 +" zoom (maximize/minimize) the NERDTree window +function! s:UI.toggleZoom() + if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed + let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize + exec "silent vertical resize ". size + let b:NERDTreeZoomed = 0 + else + exec "vertical resize" + let b:NERDTreeZoomed = 1 + endif +endfunction