mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
This method is public, and a spec for TextEditorComponent dependend on it staying synchronous
166 lines
4.4 KiB
CoffeeScript
166 lines
4.4 KiB
CoffeeScript
_ = require 'underscore-plus'
|
|
ipc = require 'ipc'
|
|
remote = require 'remote'
|
|
shell = require 'shell'
|
|
{Disposable} = require 'event-kit'
|
|
{getWindowLoadSettings, setWindowLoadSettings} = require './window-load-settings-helpers'
|
|
|
|
module.exports =
|
|
class ApplicationDelegate
|
|
open: (params) ->
|
|
ipc.send('open', params)
|
|
|
|
pickFolder: (callback) ->
|
|
responseChannel = "atom-pick-folder-response"
|
|
ipc.on responseChannel, (path) ->
|
|
ipc.removeAllListeners(responseChannel)
|
|
callback(path)
|
|
ipc.send("pick-folder", responseChannel)
|
|
|
|
getCurrentWindow: ->
|
|
remote.getCurrentWindow()
|
|
|
|
closeWindow: ->
|
|
ipc.send("call-window-method", "close")
|
|
|
|
getWindowSize: ->
|
|
[width, height] = remote.getCurrentWindow().getSize()
|
|
{width, height}
|
|
|
|
setWindowSize: (width, height) ->
|
|
remote.getCurrentWindow().setSize(width, height)
|
|
|
|
getWindowPosition: ->
|
|
[x, y] = remote.getCurrentWindow().getPosition()
|
|
{x, y}
|
|
|
|
setWindowPosition: (x, y) ->
|
|
ipc.send("call-window-method", "setPosition", x, y)
|
|
|
|
centerWindow: ->
|
|
ipc.send("call-window-method", "center")
|
|
|
|
focusWindow: ->
|
|
ipc.send("call-window-method", "focus")
|
|
|
|
showWindow: ->
|
|
ipc.send("call-window-method", "show")
|
|
|
|
hideWindow: ->
|
|
ipc.send("call-window-method", "hide")
|
|
|
|
restartWindow: ->
|
|
ipc.send("call-window-method", "restart")
|
|
|
|
isWindowMaximized: ->
|
|
remote.getCurrentWindow().isMaximized()
|
|
|
|
maximizeWindow: ->
|
|
ipc.send("call-window-method", "maximize")
|
|
|
|
isWindowFullScreen: ->
|
|
remote.getCurrentWindow().isFullScreen()
|
|
|
|
setWindowFullScreen: (fullScreen=false) ->
|
|
ipc.send("call-window-method", "setFullScreen", fullScreen)
|
|
|
|
openWindowDevTools: ->
|
|
remote.getCurrentWindow().openDevTools()
|
|
|
|
toggleWindowDevTools: ->
|
|
remote.getCurrentWindow().toggleDevTools()
|
|
|
|
executeJavaScriptInWindowDevTools: (code) ->
|
|
remote.getCurrentWindow().executeJavaScriptInDevTools(code)
|
|
|
|
setWindowDocumentEdited: (edited) ->
|
|
ipc.send("call-window-method", "setDocumentEdited", edited)
|
|
|
|
setRepresentedFilename: (filename) ->
|
|
ipc.send("call-window-method", "setRepresentedFilename", filename)
|
|
|
|
setRepresentedDirectoryPaths: (paths) ->
|
|
loadSettings = getWindowLoadSettings()
|
|
loadSettings['initialPaths'] = paths
|
|
setWindowLoadSettings(loadSettings)
|
|
|
|
setAutoHideWindowMenuBar: (autoHide) ->
|
|
ipc.send("call-window-method", "setAutoHideMenuBar", autoHide)
|
|
|
|
setWindowMenuBarVisibility: (visible) ->
|
|
remote.getCurrentWindow().setMenuBarVisibility(visible)
|
|
|
|
getPrimaryDisplayWorkAreaSize: ->
|
|
screen = remote.require 'screen'
|
|
screen.getPrimaryDisplay().workAreaSize
|
|
|
|
confirm: ({message, detailedMessage, buttons}) ->
|
|
buttons ?= {}
|
|
if _.isArray(buttons)
|
|
buttonLabels = buttons
|
|
else
|
|
buttonLabels = Object.keys(buttons)
|
|
|
|
dialog = remote.require('dialog')
|
|
chosen = dialog.showMessageBox(remote.getCurrentWindow(), {
|
|
type: 'info'
|
|
message: message
|
|
detail: detailedMessage
|
|
buttons: buttonLabels
|
|
})
|
|
|
|
if _.isArray(buttons)
|
|
chosen
|
|
else
|
|
callback = buttons[buttonLabels[chosen]]
|
|
callback?()
|
|
|
|
showMessageDialog: (params) ->
|
|
|
|
showSaveDialog: (params) ->
|
|
if _.isString(params)
|
|
params = defaultPath: params
|
|
else
|
|
params = _.clone(params)
|
|
params.title ?= 'Save File'
|
|
params.defaultPath ?= getWindowLoadSettings().initialPaths[0]
|
|
dialog = remote.require('dialog')
|
|
dialog.showSaveDialog remote.getCurrentWindow(), params
|
|
|
|
playBeepSound: ->
|
|
shell.beep()
|
|
|
|
onDidOpenLocations: (callback) ->
|
|
outerCallback = (message, detail) ->
|
|
if message is 'open-locations'
|
|
callback(detail)
|
|
|
|
ipc.on('message', outerCallback)
|
|
new Disposable ->
|
|
ipc.removeEventListener('message', outerCallback)
|
|
|
|
onUpdateAvailable: (callback) ->
|
|
outerCallback = (message, detail) ->
|
|
if message is 'update-available'
|
|
callback(detail)
|
|
|
|
ipc.on('message', outerCallback)
|
|
new Disposable ->
|
|
ipc.removeEventListener('message', outerCallback)
|
|
|
|
onApplicationMenuCommand: (callback) ->
|
|
ipc.on('command', callback)
|
|
new Disposable ->
|
|
ipc.removeEventListener('command', callback)
|
|
|
|
onContextMenuCommand: (callback) ->
|
|
ipc.on('context-command', callback)
|
|
new Disposable ->
|
|
ipc.removeEventListener('context-command', callback)
|
|
|
|
didCancelWindowUnload: ->
|
|
ipc.send('did-cancel-window-unload')
|
|
|
|
openExternal: (url) ->
|
|
shell.openExternal(url)
|