mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-06 23:26:25 +03:00
Move dimension helpers from window to Atom class
This commit is contained in:
parent
4e3c5d2aba
commit
4be4868959
@ -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
|
||||
|
||||
|
@ -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', =>
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user