mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Store pathToOpen using new atom.set/getWindowState api
When you use `setWindowState`, your data is saved across refreshes. You can only store state that can be serialized to JSON.
This commit is contained in:
@@ -7,15 +7,18 @@ namespace v8_extensions {
|
||||
class Native : public CefV8Handler {
|
||||
public:
|
||||
Native();
|
||||
|
||||
|
||||
virtual bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE;
|
||||
|
||||
|
||||
// Provide the reference counting implementation for this class.
|
||||
IMPLEMENT_REFCOUNTING(Native);
|
||||
|
||||
private:
|
||||
std::string windowState;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -76,4 +76,10 @@ var $native = {};
|
||||
native function getPlatform();
|
||||
$native.getPlatform = getPlatform;
|
||||
|
||||
native function setWindowState(state);
|
||||
$native.setWindowState = setWindowState;
|
||||
|
||||
native function getWindowState();
|
||||
$native.getWindowState = getWindowState;
|
||||
|
||||
})();
|
||||
|
||||
@@ -31,6 +31,7 @@ void throwException(const CefRefPtr<CefV8Value>& global, CefRefPtr<CefV8Exceptio
|
||||
Native::Native() : CefV8Handler() {
|
||||
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"v8_extensions/native.js"];
|
||||
NSString *extensionCode = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
|
||||
windowState = "{}";
|
||||
CefRegisterExtension("v8/native", [extensionCode UTF8String], this);
|
||||
}
|
||||
|
||||
@@ -486,6 +487,16 @@ bool Native::Execute(const CefString& name,
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (name == "setWindowState") {
|
||||
windowState = arguments[0]->GetStringValue().ToString();
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (name == "getWindowState") {
|
||||
retval = CefV8Value::CreateString(windowState);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
@@ -109,3 +109,16 @@ _.extend atom,
|
||||
if name is 'reply'
|
||||
[messageId, callbackIndex] = data.shift()
|
||||
@pendingBrowserProcessCallbacks[messageId]?[callbackIndex]?(data...)
|
||||
|
||||
setWindowState: (keyPath, value) ->
|
||||
windowState = @getWindowState()
|
||||
_.setValueForKeyPath(windowState, keyPath, value)
|
||||
$native.setWindowState(JSON.stringify(windowState))
|
||||
windowState
|
||||
|
||||
getWindowState: (keyPath) ->
|
||||
windowState = JSON.parse($native.getWindowState())
|
||||
if keyPath
|
||||
_.valueForKeyPath(windowState, keyPath)
|
||||
else
|
||||
windowState
|
||||
|
||||
@@ -47,8 +47,10 @@ windowAdditions =
|
||||
false
|
||||
|
||||
shutdown: ->
|
||||
@rootView?.deactivate()
|
||||
@rootView = null
|
||||
if @rootView
|
||||
atom.setWindowState('pathToOpen', @rootView.project.getPath())
|
||||
@rootView.deactivate()
|
||||
@rootView = null
|
||||
$(window).unbind('focus')
|
||||
$(window).unbind('blur')
|
||||
$(window).off('before')
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# Like sands through the hourglass, so are the days of our lives.
|
||||
require 'atom'
|
||||
require 'window'
|
||||
window.attachRootView(window.location.params.pathToOpen)
|
||||
|
||||
pathToOpen = atom.getWindowState('pathToOpen') ? window.location.params.pathToOpen
|
||||
window.attachRootView(pathToOpen)
|
||||
|
||||
Reference in New Issue
Block a user