mirror of
https://github.com/atom/atom.git
synced 2026-02-08 05:35:04 -05:00
atom.storage
This commit is contained in:
@@ -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) ->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user