From 71c48ec07fab3fab48b8142d3ec0516549bcd28a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 20 Jan 2014 09:46:49 -0800 Subject: [PATCH] Open .atom files from browser process This allows a new window to be created if there is no currently focused window. --- menus/darwin.cson | 6 +++--- src/browser/atom-application.coffee | 24 +++++++++++++++++++----- src/workspace-view.coffee | 1 + src/workspace.coffee | 20 ++++++++------------ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/menus/darwin.cson b/menus/darwin.cson index a7c3dcc2d..0ad64c556 100644 --- a/menus/darwin.cson +++ b/menus/darwin.cson @@ -134,9 +134,9 @@ ] } { type: 'separator' } - { label: 'Open Your Config', command: 'window:open-your-config' } - { label: 'Open Your Keymap', command: 'window:open-your-keymap' } - { label: 'Open Your Stylesheet', command: 'window:open-your-stylesheet' } + { label: 'Open Your Config', command: 'application:open-your-config' } + { label: 'Open Your Keymap', command: 'application:open-your-keymap' } + { label: 'Open Your Stylesheet', command: 'application:open-your-stylesheet' } { type: 'separator' } { label: 'Toggle Soft Wrap', command: 'editor:toggle-soft-wrap' } ] diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 5331bac58..149e87241 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -146,11 +146,11 @@ class AtomApplication @on 'application:inspect', ({x,y}) -> @focusedWindow().browserWindow.inspectElement(x, y) @on 'application:open-documentation', -> shell.openExternal('https://www.atom.io/docs/latest/?app') @on 'application:report-issue', -> shell.openExternal('https://github.com/atom/atom/issues/new') - @on 'application:show-settings', -> - if @focusedWindow() - @focusedWindow().openPath("atom://config") - else - @openPath(pathToOpen: "atom://config") + + @openPathOnEvent('application:show-settings', 'atom://config') + @openPathOnEvent('application:open-your-stylesheet', 'atom://.atom/stylesheet') + @openPathOnEvent('application:open-your-keymap', 'atom://.atom/keymap') + @openPathOnEvent('application:open-your-config', 'atom://.atom/config') app.on 'window-all-closed', -> app.quit() if process.platform is 'win32' @@ -203,6 +203,20 @@ class AtomApplication unless @emit(command, args...) @focusedWindow()?.sendCommand(command, args...) + # Public: Open the given path in the focused window when the event is + # triggered. + # + # A new window will be created if there is no currently focused window. + # + # * eventName: The event to listen for. + # * pathToOpen: The path to open when the event is triggered. + openPathOnEvent: (eventName, pathToOpen) -> + @on eventName, -> + if window = @focusedWindow() + window.openPath(pathToOpen) + else + @openPath({pathToOpen}) + # Private: Returns the {AtomWindow} for the given path. windowForPath: (pathToOpen) -> for atomWindow in @windows diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index d8aeebda4..338b6822a 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -99,6 +99,7 @@ class WorkspaceView extends View @command 'application:minimize', -> ipc.sendChannel('command', 'application:minimize') @command 'application:zoom', -> ipc.sendChannel('command', 'application:zoom') @command 'application:bring-all-windows-to-front', -> ipc.sendChannel('command', 'application:bring-all-windows-to-front') + @command 'application:open-your-stylesheet', -> ipc.sendChannel('command', 'application:open-your-stylesheet') @command 'window:run-package-specs', => ipc.sendChannel('run-package-specs', path.join(atom.project.getPath(), 'spec')) @command 'window:increase-font-size', => diff --git a/src/workspace.coffee b/src/workspace.coffee index 57c5c2997..d09d8842d 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -27,6 +27,14 @@ class Workspace extends Model constructor: -> super @subscribe @paneContainer, 'item-destroyed', @onPaneItemDestroyed + atom.project.registerOpener (filePath) => + switch filePath + when 'atom://.atom/stylesheet' + @open(atom.themes.getUserStylesheetPath()) + when 'atom://.atom/keymap' + @open(atom.keymap.getUserKeymapPath()) + when 'atom://.atom/config' + @open(atom.config.getUserConfigPath()) # Private: Called by the Serializable mixin during deserialization deserializeParams: (params) -> @@ -38,18 +46,6 @@ class Workspace extends Model paneContainer: @paneContainer.serialize() fullScreen: atom.isFullScreen() - # Private: Open ~/.atom/user.less or ~/.atom/user.css - openUserStylesheet: -> - @open(atom.themes.getUserStylesheetPath()) - - # Private: Open ~/.atom/keymap.cson or ~/.atom/keymap.json - openUserKeymap: -> - @open(atom.keymap.getUserKeymapPath()) - - # Private: Open ~/.atom/config.cson or ~/.atom/config.json - openUserConfig: -> - @open(atom.config.getUserConfigPath()) - # Public: Asynchronously opens a given a filepath in Atom. # # * filePath: A file path