From 45b1f0ef6407b7cef362cebefa2d77b596854cb7 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 19 Sep 2011 11:12:18 -0700 Subject: [PATCH] pane storage is super simple now. --- plugins/project/project.coffee | 18 +++++++++--------- src/pane.coffee | 24 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/plugins/project/project.coffee b/plugins/project/project.coffee index 495e03e2c..7b74a4164 100644 --- a/plugins/project/project.coffee +++ b/plugins/project/project.coffee @@ -26,33 +26,33 @@ class Project extends Pane if File.isDirectory filename @reload filename else - openedPaths = @storage('openedPaths') ? [] + openedPaths = @get 'openedPaths', [] if not _.include openedPaths, filename openedPaths.push filename - @storage('openedPaths', openedPaths) + @set 'openedPaths', openedPaths @editor.ace.on 'close', ({filename}) => if File.isFile filename - openedPaths = @storage('openedPaths') ? [] + openedPaths = @get 'openedPaths', [] openedPaths = _.without openedPaths, filename - @storage('openedPaths', openedPaths) + @set 'openedPaths', openedPaths @editor.ace.on 'loaded', => # Reopen files (remove ones that no longer exist) - openedPaths = @storage('openedPaths') ? [] + openedPaths = @get 'openedPaths', [] for path in openedPaths if File.isFile path @editor.open path else if not File.exists path openedPaths = _.without openedPaths, path - @storage('openedPaths', openedPaths) + @set 'openedPaths', openedPaths $('#project li').live 'click', (event) => $('#project .active').removeClass 'active' el = $(event.currentTarget) path = decodeURIComponent el.attr 'path' if File.isDirectory path - openedPaths = @storage('openedPaths') ? [] + openedPaths = @get 'openedPaths', [] if el.hasClass 'open' openedPaths = _.without openedPaths, path el.removeClass 'open' @@ -63,7 +63,7 @@ class Project extends Pane list = @createList path el.append list - @storage('openedPaths', openedPaths) + @set 'openedPaths', openedPaths else el.addClass 'active' activeWindow.open path @@ -89,7 +89,7 @@ class Project extends Pane type = if File.isDirectory path then 'dir' else 'file' encodedPath = encodeURIComponent path listItem = $("
  • #{filename}
  • ") - openedPaths = @storage('openedPaths') ? [] + openedPaths = @get 'openedPaths', [] if _.include(openedPaths, path) and type == 'dir' listItem.append @createList path listItem.addClass "open" diff --git a/src/pane.coffee b/src/pane.coffee index 895ad5b15..915ee9dca 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -27,20 +27,28 @@ class Pane @initialize options - storage: (key, value) -> + get: (key, defaultValue) -> try object = JSON.parse(localStorage[@storageNamespace()] ? "{}") catch error - error.message += "\n#{key}: #{value}" + error.message += "\nGetting #{key}" console.log(error) - if value? - # Putting data in - object[key] = value - localStorage[@storageNamespace()] = JSON.stringify(object) + object[key] ? defaultValue + + set: (key, value) -> + try + object = JSON.parse(localStorage[@storageNamespace()] ? "{}") + catch error + error.message += "\nSetting #{key}: #{value}" + console.log(error) + + # Putting data in + if value == undefined + delete object[key] else - # Getting data out - object[key] + object[key] = value + localStorage[@storageNamespace()] = JSON.stringify(object) toggle: -> if @showing