From 7347f4c8a42dfac49624a983a0c428a35cfe246e Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 15 Sep 2011 16:53:18 -0700 Subject: [PATCH] persistence, but it's too magic --- plugins/project/project.coffee | 57 +++++++++++----------------------- src/pane.coffee | 44 ++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/plugins/project/project.coffee b/plugins/project/project.coffee index 82802e472..584b9c66a 100644 --- a/plugins/project/project.coffee +++ b/plugins/project/project.coffee @@ -16,58 +16,59 @@ class Project extends Pane keymap: 'Command-Ctrl-N': 'toggle' + persistantProperties: + 'openedPaths' : [] + initialize: -> @reload(File.workingDirectory()) @editor = activeWindow.document + window.x = @ + @editor.ace.on 'open', ({filename}) => if File.isDirectory filename @reload filename else - openedPaths = @get 'openedPaths', [] - if not _.include openedPaths, filename - openedPaths.push filename - @set 'openedPaths', openedPaths + if not _.include @openedPaths, filename + @openedPaths.push filename + @openedPaths = @openedPaths # How icky, need to do this to store it @editor.ace.on 'close', ({filename}) => if File.isFile filename - openedPaths = _.without @get('openedPaths', []), filename - @set 'openedPaths', openedPaths + @openedPaths = _.without @openedPaths, filename @editor.ace.on 'loaded', => # Reopen files (remove ones that no longer exist) - openedPaths = @get 'openedPaths', [] - for path in openedPaths + for path in @openedPaths if File.isFile path @editor.open path else if not File.exists path - openedPaths = _.without(openedPaths, path) - @set "openedPaths", openedPaths - + @openedPaths = _.without @openedPaths, path $('#project li').live 'click', (event) => $('#project .active').removeClass 'active' el = $(event.currentTarget) path = decodeURIComponent el.attr 'path' if File.isDirectory path - openedPaths = @get('openedPaths', []) if el.hasClass 'open' - openedPaths = _.without(openedPaths, path) + @openedPaths = _.without @openedPaths, path el.removeClass 'open' el.children("ul").remove() else - openedPaths.push path unless _.include openedPaths, path + @openedPaths.push path unless _.include @openedPaths, path + @openedPaths = @openedPaths # How icky, need to do this to store it el.addClass 'open' list = @createList path el.append list - - @set 'openedPaths', openedPaths else el.addClass 'active' activeWindow.open path false # Don't bubble! + persistentanceNamespace: -> + @.constructor.name + @dir + reload: (dir) -> @dir = dir @html.children('#project .cwd').text _.last @dir.split '/' @@ -78,37 +79,15 @@ class Project extends Pane createList: (dir) -> paths = File.list dir - openedPaths = @get('openedPaths', []) list = $('