From 4be4868959a8537d9a52cf010ffdeac593c7d42d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 26 Sep 2013 08:50:01 -0700 Subject: [PATCH] Move dimension helpers from window to Atom class --- src/atom.coffee | 19 +++++++++++++++++++ src/window-event-handler.coffee | 2 ++ src/window.coffee | 21 ++------------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 0df8ff830..84d07ba44 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -31,6 +31,25 @@ class Atom getCurrentWindow: -> remote.getCurrentWindow() + getDimensions: -> + browserWindow = @getCurrentWindow() + [x, y] = browserWindow.getPosition() + [width, height] = browserWindow.getSize() + {x, y, width, height} + + setDimensions: ({x, y, width, height}) -> + browserWindow = @getCurrentWindow() + browserWindow.setSize(width, height) + if x? and y? + browserWindow.setPosition(x, y) + else + browserWindow.center() + + restoreDimensions: (defaultDimensions={width: 800, height: 600})-> + dimensions = @getWindowState().getObject('dimensions') + dimensions = defaultDimensions unless dimensions?.width and dimensions?.height + @setDimensions(dimensions) + getLoadSettings: -> @getCurrentWindow().loadSettings diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 33b6f2cd5..fe3a97820 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -28,6 +28,8 @@ class WindowEventHandler atom.hide() if confirmed and not @reloadRequested and remote.getCurrentWindow().isWebViewFocused() @reloadRequested = false confirmed + @subscribe $(window), 'unload', -> + atom.getWindowState().set('dimensions', atom.getDimensions()) @subscribeToCommand $(window), 'window:toggle-full-screen', => atom.toggleFullScreen() @subscribeToCommand $(window), 'window:close', => atom.close() @subscribeToCommand $(window), 'window:reload', => diff --git a/src/window.coffee b/src/window.coffee index 4be27cdc4..3158878e5 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -9,7 +9,6 @@ WindowEventHandler = require './window-event-handler' deserializers = {} deferredDeserializers = {} -defaultWindowDimensions = {width: 800, height: 600} ### Internal ### @@ -128,25 +127,9 @@ window.deserializeEditorWindow = -> projectPath = project.getPath() atom.getLoadSettings().initialPath = projectPath -window.getDimensions = -> - browserWindow = remote.getCurrentWindow() - [x, y] = browserWindow.getPosition() - [width, height] = browserWindow.getSize() - {x, y, width, height} +window.getDimensions = -> atom.getDimensions() -window.setDimensions = ({x, y, width, height}) -> - browserWindow = remote.getCurrentWindow() - browserWindow.setSize(width, height) - if x? and y? - browserWindow.setPosition(x, y) - else - browserWindow.center() - -window.restoreDimensions = -> - dimensions = atom.getWindowState().getObject('dimensions') - dimensions = defaultWindowDimensions unless dimensions?.width and dimensions?.height - window.setDimensions(dimensions) - $(window).on 'unload', -> atom.getWindowState().set('dimensions', window.getDimensions()) +window.setDimensions = (args...) -> atom.setDimensions(args...) window.onerror = -> atom.openDevTools()