Skip to content

Commit

Permalink
move some more view code into the UI class
Browse files Browse the repository at this point in the history
  • Loading branch information
scrooloose committed Jul 9, 2014
1 parent eaa66aa commit 1e0d1cb
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 48 deletions.
14 changes: 0 additions & 14 deletions autoload/nerdtree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 10 additions & 34 deletions autoload/nerdtree/ui_glue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -372,7 372,7 @@ function! s:jumpToChild(currentNode, direction)

call targetNode.putCursorHere(1, 0)

call nerdtree#centerView()
call b:NERDTree.ui.centerView()
endfunction


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions lib/nerdtree/ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1e0d1cb

Please sign in to comment.