Move dimension helpers from window to Atom class

This commit is contained in:
Kevin Sawicki 2013-09-26 08:50:01 -07:00
parent 4e3c5d2aba
commit 4be4868959
3 changed files with 23 additions and 19 deletions

View File

@ -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

View File

@ -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', =>

View File

@ -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()