move some more view code into the UI class

This commit is contained in:
Martin Grenfell 2014-07-09 09:25:25 +01:00
parent eaa66aaf63
commit 1e0d1cbc8f
3 changed files with 80 additions and 48 deletions

View File

@ -126,20 +126,6 @@ endfunction
" SECTION: View Functions {{{1 " 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 " FUNCTION: nerdtree#chRoot(node) {{{2
" changes the current root to the selected one " changes the current root to the selected one
function! nerdtree#chRoot(node) function! nerdtree#chRoot(node)

View File

@ -243,7 +243,7 @@ endfunction
function! s:displayHelp() function! s:displayHelp()
let b:treeShowHelp = b:treeShowHelp ? 0 : 1 let b:treeShowHelp = b:treeShowHelp ? 0 : 1
call b:NERDTree.render() call b:NERDTree.render()
call nerdtree#centerView() call b:NERDTree.ui.centerView()
endfunction endfunction
" FUNCTION: s:findAndRevealPath() {{{1 " FUNCTION: s:findAndRevealPath() {{{1
@ -372,7 +372,7 @@ function! s:jumpToChild(currentNode, direction)
call targetNode.putCursorHere(1, 0) call targetNode.putCursorHere(1, 0)
call nerdtree#centerView() call b:NERDTree.ui.centerView()
endfunction endfunction
@ -400,7 +400,7 @@ endfunction
function! s:jumpToParent(node) function! s:jumpToParent(node)
if !empty(a:node.parent) if !empty(a:node.parent)
call a:node.parent.putCursorHere(1, 0) call a:node.parent.putCursorHere(1, 0)
call nerdtree#centerView() call b:NERDTree.ui.centerView()
else else
call nerdtree#echo("cannot jump to parent") call nerdtree#echo("cannot jump to parent")
endif endif
@ -410,7 +410,7 @@ endfunction
" moves the cursor to the root node " moves the cursor to the root node
function! s:jumpToRoot() function! s:jumpToRoot()
call b:NERDTreeRoot.putCursorHere(1, 0) call b:NERDTreeRoot.putCursorHere(1, 0)
call nerdtree#centerView() call b:NERDTree.ui.centerView()
endfunction endfunction
" FUNCTION: s:jumpToNextSibling(node) {{{1 " FUNCTION: s:jumpToNextSibling(node) {{{1
@ -434,7 +434,7 @@ function! s:jumpToSibling(currentNode, forward)
if !empty(sibling) if !empty(sibling)
call sibling.putCursorHere(1, 0) call sibling.putCursorHere(1, 0)
call nerdtree#centerView() call b:NERDTree.ui.centerView()
endif endif
endfunction endfunction
@ -570,53 +570,29 @@ function! s:showMenu(node)
endfunction endfunction
" FUNCTION: s:toggleIgnoreFilter() {{{1 " FUNCTION: s:toggleIgnoreFilter() {{{1
" toggles the use of the NERDTreeIgnore option
function! s:toggleIgnoreFilter() function! s:toggleIgnoreFilter()
let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled call b:NERDTree.ui.toggleIgnoreFilter()
call b:NERDTree.ui.renderViewSavingPosition()
call nerdtree#centerView()
endfunction endfunction
" FUNCTION: s:toggleShowBookmarks() {{{1 " FUNCTION: s:toggleShowBookmarks() {{{1
" toggles the display of bookmarks
function! s:toggleShowBookmarks() function! s:toggleShowBookmarks()
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks call b:NERDTree.ui.toggleShowBookmarks()
if b:NERDTreeShowBookmarks
call b:NERDTree.render()
call nerdtree#putCursorOnBookmarkTable()
else
call b:NERDTree.ui.renderViewSavingPosition()
endif
call nerdtree#centerView()
endfunction endfunction
" FUNCTION: s:toggleShowFiles() {{{1 " FUNCTION: s:toggleShowFiles() {{{1
" toggles the display of hidden files
function! s:toggleShowFiles() function! s:toggleShowFiles()
let b:NERDTreeShowFiles = !b:NERDTreeShowFiles call b:NERDTree.ui.toggleShowFiles()
call b:NERDTree.ui.renderViewSavingPosition()
call nerdtree#centerView()
endfunction endfunction
" FUNCTION: s:toggleShowHidden() {{{1 " FUNCTION: s:toggleShowHidden() {{{1
" toggles the display of hidden files " toggles the display of hidden files
function! s:toggleShowHidden() function! s:toggleShowHidden()
let b:NERDTreeShowHidden = !b:NERDTreeShowHidden call b:NERDTree.ui.toggleShowHidden()
call b:NERDTree.ui.renderViewSavingPosition()
call nerdtree#centerView()
endfunction endfunction
" FUNCTION: s:toggleZoom() {{{1 " FUNCTION: s:toggleZoom() {{{1
" zoom (maximize/minimize) the NERDTree window
function! s:toggleZoom() function! s:toggleZoom()
if exists("b:NERDTreeZoomed") && b:NERDTreeZoomed call b:NERDTree.ui.toggleZoom()
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 endfunction
"FUNCTION: nerdtree#ui_glue#upDir(keepState) {{{1 "FUNCTION: nerdtree#ui_glue#upDir(keepState) {{{1

View File

@ -3,6 +3,26 @@
let s:UI = {} let s:UI = {}
let g:NERDTreeUI = 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) function! s:UI.New(nerdtree)
let newObj = copy(self) let newObj = copy(self)
let newObj.nerdtree = a:nerdtree let newObj.nerdtree = a:nerdtree
@ -260,3 +280,53 @@ function! s:UI.renderViewSavingPosition()
call currentNode.putCursorHere(0, 0) call currentNode.putCursorHere(0, 0)
endif endif
endfunction 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