From 51f8497229819eebc6a1583d1fb7afe4af6a5ad9 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 9 Nov 2011 12:28:38 -0800 Subject: [PATCH] atom.storage --- extensions/tree/tree.coffee | 7 +++---- src/editor.coffee | 15 +++++++-------- src/startup.coffee | 2 ++ src/storage.coffee | 6 +++--- src/window.coffee | 6 ++---- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/extensions/tree/tree.coffee b/extensions/tree/tree.coffee index 4b50e2575..b706e8967 100644 --- a/extensions/tree/tree.coffee +++ b/extensions/tree/tree.coffee @@ -1,7 +1,6 @@ _ = require 'underscore' Extension = require 'extension' -Storage = require 'storage' TreePane = require 'tree/tree-pane' Watcher = require 'watcher' @@ -54,16 +53,16 @@ class Tree extends Extension Watcher.unwatch dir, @watchDir shownDirs: -> - Storage.get @shownDirStorageKey(), [] + atom.storage.get @shownDirStorageKey(), [] showDir: (dir) -> dirs = @shownDirs().concat dir - Storage.set @shownDirStorageKey(), dirs + atom.storage.set @shownDirStorageKey(), dirs Watcher.watch dir, @watchDir hideDir: (dir) -> dirs = _.without @shownDirs(), dir - Storage.set @shownDirStorageKey(), dirs + atom.storage.set @shownDirStorageKey(), dirs @unwatchDir dir, @watchDir findPath: (searchPath, paths=@paths) -> diff --git a/src/editor.coffee b/src/editor.coffee index 643d0418d..64721d15e 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -3,7 +3,6 @@ _ = require 'underscore' fs = require 'fs' ace = require 'ace/ace' -Storage = require 'storage' Pane = require 'pane' {EditSession} = require 'ace/edit_session' @@ -82,8 +81,8 @@ class Editor extends Pane null restoreOpenBuffers: -> - openPaths = Storage.get @openPathsKey, [] - focusedPath = Storage.get(@focusedPathKey) + openPaths = atom.storage.get @openPathsKey, [] + focusedPath = atom.storage.get(@focusedPathKey) @addBuffer path for path in openPaths @focusBuffer focusedPath if focusedPath @@ -104,10 +103,10 @@ class Editor extends Pane @buffers[path] = buffer - openPaths = Storage.get @openPathsKey, [] + openPaths = atom.storage.get @openPathsKey, [] unless path in openPaths openPaths.push path - Storage.set @openPathsKey, openPaths + atom.storage.set @openPathsKey, openPaths buffer.on 'change', -> buffer.$atom_dirty = true atom.event.trigger "editor:bufferAdd", path @@ -141,8 +140,8 @@ class Editor extends Pane delete @buffers[path] - openPaths = Storage.get @openPathsKey, [] - Storage.set @openPathsKey, _.without openPaths, path + openPaths = atom.storage.get @openPathsKey, [] + atom.storage.set @openPathsKey, _.without openPaths, path atom.event.trigger "editor:bufferRemove", path if path is @activePath @@ -161,7 +160,7 @@ class Editor extends Pane buffer = @buffers[path] or @addBuffer path @ace.setSession buffer - Storage.set @focusedPathKey, path + atom.storage.set @focusedPathKey, path atom.event.trigger "editor:bufferFocus", path save: (path) -> diff --git a/src/startup.coffee b/src/startup.coffee index 747477122..f27dfffa8 100644 --- a/src/startup.coffee +++ b/src/startup.coffee @@ -4,10 +4,12 @@ App = require 'app' Event = require 'event' Native = require 'native' KeyBinder = require 'key-binder' +Storage = require 'storage' window.atom = {} window.atom.native = new Native window.atom.event = new Event window.atom.keybinder = new KeyBinder +window.atom.storage = new Storage window.atom.app = new App diff --git a/src/storage.coffee b/src/storage.coffee index f3d375378..db60408b6 100644 --- a/src/storage.coffee +++ b/src/storage.coffee @@ -1,6 +1,6 @@ module.exports = class Storage - @get: (key, defaultValue) -> + get: (key, defaultValue) -> try value = OSX.NSApp.storageGet_defaultValue(key, defaultValue) @toJS value @@ -8,10 +8,10 @@ class Storage error.message += "\nGetting #{key}" console.error(error) - @set: (key, value) -> + set: (key, value) -> OSX.NSApp.storageSet_value key, value - @toJS: (value) -> + toJS: (value) -> if not value value else if value.isKindOfClass OSX.NSDictionary.class diff --git a/src/window.coffee b/src/window.coffee index 74c5dc878..a97828899 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -1,7 +1,5 @@ Browser = require 'browser' Editor = require 'editor' -Extension = require 'extension' -Storage = require 'storage' fs = require 'fs' _ = require 'underscore' @@ -27,7 +25,7 @@ windowAdditions = # Remember sizing! defaultFrame = x: 0, y: 0, width: 600, height: 800 - frame = Storage.get "window.frame.#{@path}", defaultFrame + frame = atom.storage.get "window.frame.#{@path}", defaultFrame rect = OSX.CGRectMake(frame.x, frame.y, frame.width, frame.height) $atomController.window.setFrame_display rect, true @@ -51,7 +49,7 @@ windowAdditions = width = frame.size.width height = frame.size.height - Storage.set "window.frame.#{@path}", {x:x, y:y, width:width, height:height} + atom.storage.set "window.frame.#{@path}", {x:x, y:y, width:width, height:height} loadExtensions: -> extension.shutdown() for name, extension of @extensions