From 3d4fdd051d1f714e5f77c3250022e037291788c7 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 8 Mar 2017 10:02:35 +0100 Subject: [PATCH] Snapshot more objects --- package.json | 1 + src/atom-environment.coffee | 105 ++++++++++++++------------- src/auto-update-manager.js | 12 +-- src/command-installer.coffee | 4 +- src/command-registry.coffee | 9 ++- src/context-menu-manager.coffee | 29 +++++--- src/history-manager.js | 9 ++- src/keymap-extensions.coffee | 6 +- src/menu-manager.coffee | 9 ++- src/package-manager.coffee | 17 +++-- src/pane-container.coffee | 4 +- src/register-default-commands.coffee | 14 ++-- src/theme-manager.coffee | 4 +- src/window-event-handler.coffee | 37 +++++----- src/workspace.js | 68 +++++++++-------- 15 files changed, 181 insertions(+), 147 deletions(-) diff --git a/package.json b/package.json index 54939847f..63f71bf4a 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "normalize-package-data": "^2.0.0", "nslog": "^3", "oniguruma": "6.1.0", + "parserlib": "^1.1.1", "pathwatcher": "7.0.0", "postcss": "5.2.4", "postcss-selector-parser": "2.2.1", diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 8aa79736d..2c5398d64 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -151,6 +151,51 @@ class AtomEnvironment extends Model @commands = new CommandRegistry @grammars = new GrammarRegistry({@config}) @styles = new StyleManager() + @packages = new PackageManager({ + @config, styleManager: @styles, + commandRegistry: @commands, keymapManager: @keymaps, notificationManager: @notifications, + grammarRegistry: @grammars, deserializerManager: @deserializers, viewRegistry: @views + }) + @themes = new ThemeManager({ + packageManager: @packages, @config, styleManager: @styles, + notificationManager: @notifications, viewRegistry: @views + }) + @menu = new MenuManager({keymapManager: @keymaps, packageManager: @packages}) + @contextMenu = new ContextMenuManager({keymapManager: @keymaps}) + @packages.setMenuManager(@menu) + @packages.setContextMenuManager(@contextMenu) + @packages.setThemeManager(@themes) + + @project = new Project({notificationManager: @notifications, packageManager: @packages, @config, @applicationDelegate}) + @commandInstaller = new CommandInstaller(@applicationDelegate) + + @textEditors = new TextEditorRegistry({ + @config, grammarRegistry: @grammars, assert: @assert.bind(this), + packageManager: @packages + }) + + @workspace = new Workspace({ + @config, @project, packageManager: @packages, grammarRegistry: @grammars, deserializerManager: @deserializers, + notificationManager: @notifications, @applicationDelegate, viewRegistry: @views, assert: @assert.bind(this), + textEditorRegistry: @textEditors, + }) + + @themes.workspace = @workspace + + @autoUpdater = new AutoUpdateManager({@applicationDelegate}) + + @keymaps.loadBundledKeymaps() + @registerDefaultCommands() + @registerDefaultOpeners() + @registerDefaultDeserializers() + @registerDefaultViewProviders() + + @windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate}) + + @history = new HistoryManager({@project, @commands}) + # Keep instances of HistoryManager in sync + @disposables.add @history.onDidChangeProjects (e) => + @applicationDelegate.didChangeHistoryManager() unless e.reloaded initialize: (params={}) -> {@window, @document, @blobStore, @configDirPath, onlyLoadBaseStyleSheets} = params @@ -183,44 +228,14 @@ class AtomEnvironment extends Model @commands.attach(@window) @styles.initialize({@configDirPath}) + @packages.initialize({devMode, @configDirPath, resourcePath, safeMode}) + @themes.initialize({@configDirPath, resourcePath, safeMode}) - @packages = new PackageManager({ - devMode, @configDirPath, resourcePath, safeMode, @config, styleManager: @styles, - commandRegistry: @commands, keymapManager: @keymaps, notificationManager: @notifications, - grammarRegistry: @grammars, deserializerManager: @deserializers, viewRegistry: @views - }) - - @themes = new ThemeManager({ - packageManager: @packages, @configDirPath, resourcePath, safeMode, @config, - styleManager: @styles, notificationManager: @notifications, viewRegistry: @views - }) - - @menu = new MenuManager({resourcePath, keymapManager: @keymaps, packageManager: @packages}) - - @contextMenu = new ContextMenuManager({resourcePath, devMode, keymapManager: @keymaps}) - - @packages.setMenuManager(@menu) - @packages.setContextMenuManager(@contextMenu) - @packages.setThemeManager(@themes) - - @project = new Project({notificationManager: @notifications, packageManager: @packages, @config, @applicationDelegate}) - - @commandInstaller = new CommandInstaller(@getVersion(), @applicationDelegate) - - @textEditors = new TextEditorRegistry({ - @config, grammarRegistry: @grammars, assert: @assert.bind(this), - packageManager: @packages - }) - - @workspace = new Workspace({ - @config, @project, packageManager: @packages, grammarRegistry: @grammars, deserializerManager: @deserializers, - notificationManager: @notifications, @applicationDelegate, viewRegistry: @views, assert: @assert.bind(this), - textEditorRegistry: @textEditors, - }) - - @themes.workspace = @workspace - - @autoUpdater = new AutoUpdateManager({@applicationDelegate}) + @menu.initialize({resourcePath}) + @contextMenu.initialize({resourcePath, devMode}) + @commandInstaller.initialize(@getVersion()) + @workspace.initialize() + @autoUpdater.initialize() @config.load() @@ -233,23 +248,14 @@ class AtomEnvironment extends Model @document.head.appendChild(@stylesElement) @keymaps.subscribeToFileReadFailure() - @keymaps.loadBundledKeymaps() - - @registerDefaultCommands() - @registerDefaultOpeners() - @registerDefaultDeserializers() - @registerDefaultViewProviders() @installUncaughtErrorHandler() @attachSaveStateListeners() - @installWindowEventHandler() + @windowEventHandler.initialize(@window, @document) @observeAutoHideMenuBar() - @history = new HistoryManager({@project, @commands, @stateStore}) - # Keep instances of HistoryManager in sync - @disposables.add @history.onDidChangeProjects (e) => - @applicationDelegate.didChangeHistoryManager() unless e.reloaded + @history.initialize(@stateStore) @disposables.add @applicationDelegate.onDidChangeHistoryManager(=> @history.loadState()) attachSaveStateListeners: -> @@ -786,9 +792,6 @@ class AtomEnvironment extends Model uninstallUncaughtErrorHandler: -> @window.onerror = @previousWindowErrorHandler - installWindowEventHandler: -> - @windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate, @window, @document}) - uninstallWindowEventHandler: -> @windowEventHandler?.unsubscribe() diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index fb6325a26..111147f32 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -7,21 +7,23 @@ export default class AutoUpdateManager { this.applicationDelegate = applicationDelegate this.subscriptions = new CompositeDisposable() this.emitter = new Emitter() + } + initialize () { this.subscriptions.add( - applicationDelegate.onDidBeginCheckingForUpdate(() => { + this.applicationDelegate.onDidBeginCheckingForUpdate(() => { this.emitter.emit('did-begin-checking-for-update') }), - applicationDelegate.onDidBeginDownloadingUpdate(() => { + this.applicationDelegate.onDidBeginDownloadingUpdate(() => { this.emitter.emit('did-begin-downloading-update') }), - applicationDelegate.onDidCompleteDownloadingUpdate((details) => { + this.applicationDelegate.onDidCompleteDownloadingUpdate((details) => { this.emitter.emit('did-complete-downloading-update', details) }), - applicationDelegate.onUpdateNotAvailable(() => { + this.applicationDelegate.onUpdateNotAvailable(() => { this.emitter.emit('update-not-available') }), - applicationDelegate.onUpdateError(() => { + this.applicationDelegate.onUpdateError(() => { this.emitter.emit('update-error') }) ) diff --git a/src/command-installer.coffee b/src/command-installer.coffee index e37e6a0e6..7873014fa 100644 --- a/src/command-installer.coffee +++ b/src/command-installer.coffee @@ -26,7 +26,9 @@ symlinkCommandWithPrivilegeSync = (sourcePath, destinationPath) -> module.exports = class CommandInstaller - constructor: (@appVersion, @applicationDelegate) -> + constructor: (@applicationDelegate) -> + + initialize: (@appVersion) -> getInstallDirectory: -> "/usr/local/bin" diff --git a/src/command-registry.coffee b/src/command-registry.coffee index 056446203..269714876 100644 --- a/src/command-registry.coffee +++ b/src/command-registry.coffee @@ -91,23 +91,26 @@ class CommandRegistry # # Returns a {Disposable} on which `.dispose()` can be called to remove the # added command handler(s). - add: (target, commandName, callback) -> + add: (target, commandName, callback, throwOnInvalidSelector = true) -> if typeof commandName is 'object' commands = commandName disposable = new CompositeDisposable for commandName, callback of commands - disposable.add @add(target, commandName, callback) + disposable.add @add(target, commandName, callback, throwOnInvalidSelector) return disposable if typeof callback isnt 'function' throw new Error("Can't register a command with non-function callback.") if typeof target is 'string' - validateSelector(target) + validateSelector(target) if throwOnInvalidSelector @addSelectorBasedListener(target, commandName, callback) else @addInlineListener(target, commandName, callback) + addBundled: (target, commandName, callback) -> + @add(target, commandName, callback, false) + addSelectorBasedListener: (selector, commandName, callback) -> @selectorBasedListenersByCommandName[commandName] ?= [] listenersForCommand = @selectorBasedListenersByCommandName[commandName] diff --git a/src/context-menu-manager.coffee b/src/context-menu-manager.coffee index 4dc54cede..c15ca20a6 100644 --- a/src/context-menu-manager.coffee +++ b/src/context-menu-manager.coffee @@ -40,15 +40,17 @@ platformContextMenu = require('../package.json')?._atomMenu?['context-menu'] # {::add} for more information. module.exports = class ContextMenuManager - constructor: ({@resourcePath, @devMode, @keymapManager}) -> + constructor: ({@keymapManager}) -> @definitions = {'.overlayer': []} # TODO: Remove once color picker package stops touching private data @clear() @keymapManager.onDidLoadBundledKeymaps => @loadPlatformItems() + initialize: ({@resourcePath, @devMode}) -> + loadPlatformItems: -> if platformContextMenu? - @add(platformContextMenu) + @add(platformContextMenu, false) else menusDirPath = path.join(@resourcePath, 'menus') platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json']) @@ -107,11 +109,11 @@ class ContextMenuManager # # Returns a {Disposable} on which `.dispose()` can be called to remove the # added menu items. - add: (itemsBySelector) -> + add: (itemsBySelector, throwOnInvalidSelector = true) -> addedItemSets = [] for selector, items of itemsBySelector - validateSelector(selector) + validateSelector(selector) if throwOnInvalidSelector itemSet = new ContextMenuItemSet(selector, items) addedItemSets.push(itemSet) @itemSets.push(itemSet) @@ -206,14 +208,17 @@ class ContextMenuManager clear: -> @activeElement = null @itemSets = [] - @add 'atom-workspace': [{ - label: 'Inspect Element' - command: 'application:inspect' - devMode: true - created: (event) -> - {pageX, pageY} = event - @commandDetail = {x: pageX, y: pageY} - }] + inspectElement = { + 'atom-workspace': [{ + label: 'Inspect Element' + command: 'application:inspect' + devMode: true + created: (event) -> + {pageX, pageY} = event + @commandDetail = {x: pageX, y: pageY} + }] + } + @add(inspectElement, false) class ContextMenuItemSet constructor: (@selector, @items) -> diff --git a/src/history-manager.js b/src/history-manager.js index 5087c3bf9..ff3fbc218 100644 --- a/src/history-manager.js +++ b/src/history-manager.js @@ -8,15 +8,18 @@ import {Emitter, CompositeDisposable} from 'event-kit' // // The project history is used to enable the 'Reopen Project' menu. export class HistoryManager { - constructor ({stateStore, project, commands}) { - this.stateStore = stateStore + constructor ({project, commands}) { this.emitter = new Emitter() this.projects = [] this.disposables = new CompositeDisposable() - this.disposables.add(commands.add('atom-workspace', {'application:clear-project-history': this.clearProjects.bind(this)})) + this.disposables.add(commands.addBundled('atom-workspace', {'application:clear-project-history': this.clearProjects.bind(this)})) this.disposables.add(project.onDidChangePaths((projectPaths) => this.addProject(projectPaths))) } + initialize (stateStore) { + this.stateStore = stateStore + } + destroy () { this.disposables.dispose() } diff --git a/src/keymap-extensions.coffee b/src/keymap-extensions.coffee index bf8302f4c..76b2e8958 100644 --- a/src/keymap-extensions.coffee +++ b/src/keymap-extensions.coffee @@ -12,12 +12,12 @@ KeymapManager::onDidLoadUserKeymap = (callback) -> @emitter.on 'did-load-user-keymap', callback KeymapManager::loadBundledKeymaps = -> - keymapsPath = path.join(@resourcePath, 'keymaps') if bundledKeymaps? for keymapName, keymap of bundledKeymaps - keymapPath = path.join(keymapsPath, keymapName) - @add(keymapPath, keymap) + keymapPath = "/#{keymapName}" + @add(keymapPath, keymap, 0, false) else + keymapsPath = path.join(@resourcePath, 'keymaps') @loadKeymap(keymapsPath) @emitter.emit 'did-load-bundled-keymaps' diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index b6ed7fd1a..18dd49c5a 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -60,12 +60,17 @@ platformMenu = require('../package.json')?._atomMenu?.menu module.exports = class MenuManager constructor: ({@resourcePath, @keymapManager, @packageManager}) -> + @initialized = false @pendingUpdateOperation = null @template = [] @keymapManager.onDidLoadBundledKeymaps => @loadPlatformItems() - @keymapManager.onDidReloadKeymap => @update() @packageManager.onDidActivateInitialPackages => @sortPackagesMenu() + initialize: ({@resourcePath}) -> + @keymapManager.onDidReloadKeymap => @update() + @update() + @initialized = true + # Public: Adds the given items to the application menu. # # ## Examples @@ -89,7 +94,7 @@ class MenuManager add: (items) -> items = _.deepClone(items) @merge(@template, item) for item in items - @update() + @update() if @initialized new Disposable => @remove(items) remove: (items) -> diff --git a/src/package-manager.coffee b/src/package-manager.coffee index fb4f7a658..a7b068bbf 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -30,9 +30,8 @@ module.exports = class PackageManager constructor: (params) -> { - configDirPath, @devMode, safeMode, @resourcePath, @config, @styleManager, - @notificationManager, @keymapManager, @commandRegistry, @grammarRegistry, - @deserializerManager, @viewRegistry + @config, @styleManager, @notificationManager, @keymapManager, + @commandRegistry, @grammarRegistry, @deserializerManager, @viewRegistry } = params @emitter = new Emitter @@ -40,11 +39,6 @@ class PackageManager @packageDirPaths = [] @deferredActivationHooks = [] @triggeredActivationHooks = new Set() - if configDirPath? and not safeMode - if @devMode - @packageDirPaths.push(path.join(configDirPath, "dev", "packages")) - @packageDirPaths.push(path.join(configDirPath, "packages")) - @packagesCache = require('../package.json')?._atomPackages ? {} @initialPackagesLoaded = false @initialPackagesActivated = false @@ -57,6 +51,13 @@ class PackageManager @packageActivators = [] @registerPackageActivator(this, ['atom', 'textmate']) + initialize: (params) -> + {configDirPath, @devMode, safeMode, @resourcePath} = params + if configDirPath? and not safeMode + if @devMode + @packageDirPaths.push(path.join(configDirPath, "dev", "packages")) + @packageDirPaths.push(path.join(configDirPath, "packages")) + setContextMenuManager: (@contextMenuManager) -> setMenuManager: (@menuManager) -> diff --git a/src/pane-container.coffee b/src/pane-container.coffee index fc092122e..20d14389d 100644 --- a/src/pane-container.coffee +++ b/src/pane-container.coffee @@ -21,9 +21,11 @@ class PaneContainer extends Model @setRoot(new Pane({container: this, @config, applicationDelegate, notificationManager, deserializerManager})) @setActivePane(@getRoot()) - @monitorActivePaneItem() @monitorPaneItems() + initialize: -> + @monitorActivePaneItem() + serialize: (params) -> deserializer: 'PaneContainer' version: @serializationVersion diff --git a/src/register-default-commands.coffee b/src/register-default-commands.coffee index 8196d9237..f3ede7987 100644 --- a/src/register-default-commands.coffee +++ b/src/register-default-commands.coffee @@ -2,7 +2,7 @@ Grim = require 'grim' module.exports = ({commandRegistry, commandInstaller, config, notificationManager, project, clipboard}) -> - commandRegistry.add 'atom-workspace', + commandRegistry.addBundled 'atom-workspace', 'pane:show-next-recently-used-item': -> @getModel().getActivePane().activateNextRecentlyUsedItem() 'pane:show-previous-recently-used-item': -> @getModel().getActivePane().activatePreviousRecentlyUsedItem() 'pane:move-active-item-to-top-of-stack': -> @getModel().getActivePane().moveActiveItemToTopOfStack() @@ -79,10 +79,10 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage 'core:save-as': -> @getModel().saveActivePaneItemAs() if process.platform is 'darwin' - commandRegistry.add 'atom-workspace', 'window:install-shell-commands', -> + commandRegistry.addBundled 'atom-workspace', 'window:install-shell-commands', -> commandInstaller.installShellCommandsInteractively() - commandRegistry.add 'atom-pane', + commandRegistry.addBundled 'atom-pane', 'pane:save-items': -> @getModel().saveItems() 'pane:split-left': -> @getModel().splitLeft() 'pane:split-right': -> @getModel().splitRight() @@ -101,7 +101,7 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage 'pane:increase-size': -> @getModel().increaseSize() 'pane:decrease-size': -> @getModel().decreaseSize() - commandRegistry.add 'atom-text-editor', stopEventPropagation( + commandRegistry.addBundled 'atom-text-editor', stopEventPropagation( 'core:undo': -> @undo() 'core:redo': -> @redo() 'core:move-left': -> @moveLeft() @@ -142,7 +142,7 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage 'editor:select-line': -> @selectLinesContainingCursors() ) - commandRegistry.add 'atom-text-editor', stopEventPropagationAndGroupUndo(config, + commandRegistry.addBundled 'atom-text-editor', stopEventPropagationAndGroupUndo(config, 'core:backspace': -> @backspace() 'core:delete': -> @delete() 'core:cut': -> @cutSelectedText() @@ -165,7 +165,7 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage 'editor:copy-selection': -> @copyOnlySelectedText() ) - commandRegistry.add 'atom-text-editor:not([mini])', stopEventPropagation( + commandRegistry.addBundled 'atom-text-editor:not([mini])', stopEventPropagation( 'core:move-up': -> @moveUp() 'core:move-down': -> @moveDown() 'core:move-to-top': -> @moveToTop() @@ -203,7 +203,7 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage 'editor:scroll-to-cursor': -> @scrollToCursorPosition() ) - commandRegistry.add 'atom-text-editor:not([mini])', stopEventPropagationAndGroupUndo(config, + commandRegistry.addBundled 'atom-text-editor:not([mini])', stopEventPropagationAndGroupUndo(config, 'editor:indent': -> @indent() 'editor:auto-indent': -> @autoIndentSelectedRows() 'editor:indent-selected-rows': -> @indentSelectedRows() diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 58297b2db..f035889a2 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -9,7 +9,7 @@ fs = require 'fs-plus' # An instance of this class is always available as the `atom.themes` global. module.exports = class ThemeManager - constructor: ({@packageManager, @resourcePath, @configDirPath, @safeMode, @config, @styleManager, @notificationManager, @viewRegistry}) -> + constructor: ({@packageManager, @config, @styleManager, @notificationManager, @viewRegistry}) -> @emitter = new Emitter @styleSheetDisposablesBySourcePath = {} @lessCache = null @@ -18,6 +18,8 @@ class ThemeManager @packageManager.onDidActivateInitialPackages => @onDidChangeActiveThemes => @packageManager.reloadActivePackageStyleSheets() + initialize: ({@resourcePath, @configDirPath, @safeMode}) -> + ### Section: Event Subscription ### diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 95cd45de9..5d6ce4686 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -4,10 +4,27 @@ listen = require './delegated-listener' # Handles low-level events related to the @window. module.exports = class WindowEventHandler - constructor: ({@atomEnvironment, @applicationDelegate, @window, @document}) -> + constructor: ({@atomEnvironment, @applicationDelegate}) -> @reloadRequested = false @subscriptions = new CompositeDisposable + @handleNativeKeybindings() + + initialize: (@window, @document) -> + @subscriptions.add @atomEnvironment.commands.add @window, + 'window:toggle-full-screen': @handleWindowToggleFullScreen + 'window:close': @handleWindowClose + 'window:reload': @handleWindowReload + 'window:toggle-dev-tools': @handleWindowToggleDevTools + + if process.platform in ['win32', 'linux'] + @subscriptions.add @atomEnvironment.commands.add @window, + 'window:toggle-menu-bar': @handleWindowToggleMenuBar + + @subscriptions.add @atomEnvironment.commands.add @document, + 'core:focus-next': @handleFocusNext + 'core:focus-previous': @handleFocusPrevious + @addEventListener(@window, 'beforeunload', @handleWindowBeforeunload) @addEventListener(@window, 'focus', @handleWindowFocus) @addEventListener(@window, 'blur', @handleWindowBlur) @@ -23,27 +40,11 @@ class WindowEventHandler @subscriptions.add(@applicationDelegate.onDidEnterFullScreen(@handleEnterFullScreen)) @subscriptions.add(@applicationDelegate.onDidLeaveFullScreen(@handleLeaveFullScreen)) - @subscriptions.add @atomEnvironment.commands.add @window, - 'window:toggle-full-screen': @handleWindowToggleFullScreen - 'window:close': @handleWindowClose - 'window:reload': @handleWindowReload - 'window:toggle-dev-tools': @handleWindowToggleDevTools - - if process.platform in ['win32', 'linux'] - @subscriptions.add @atomEnvironment.commands.add @window, - 'window:toggle-menu-bar': @handleWindowToggleMenuBar - - @subscriptions.add @atomEnvironment.commands.add @document, - 'core:focus-next': @handleFocusNext - 'core:focus-previous': @handleFocusPrevious - - @handleNativeKeybindings() - # Wire commands that should be handled by Chromium for elements with the # `.native-key-bindings` class. handleNativeKeybindings: -> bindCommandToAction = (command, action) => - @subscriptions.add @atomEnvironment.commands.add '.native-key-bindings', command, (event) => + @subscriptions.add @atomEnvironment.commands.addBundled '.native-key-bindings', command, (event) => @applicationDelegate.getCurrentWindow().webContents[action]() bindCommandToAction('core:copy', 'copy') diff --git a/src/workspace.js b/src/workspace.js index f411cf823..de558dfa9 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -30,6 +30,7 @@ module.exports = class Workspace extends Model { this.updateWindowTitle = this.updateWindowTitle.bind(this) this.updateDocumentEdited = this.updateDocumentEdited.bind(this) this.didDestroyPaneItem = this.didDestroyPaneItem.bind(this) + this.didChangeActivePaneItem = this.didChangeActivePaneItem.bind(this) this.packageManager = params.packageManager this.config = params.config @@ -76,6 +77,11 @@ module.exports = class Workspace extends Model { this.subscribeToEvents() } + initialize () { + this.paneContainer.initialize() + this.didChangeActivePaneItem() + } + reset (packageManager) { this.packageManager = packageManager this.emitter.dispose() @@ -176,46 +182,44 @@ module.exports = class Workspace extends Model { } subscribeToActiveItem () { + this.project.onDidChangePaths(this.updateWindowTitle) + this.onDidChangeActivePaneItem(this.didChangeActivePaneItem) + } + + didChangeActivePaneItem (item) { this.updateWindowTitle() this.updateDocumentEdited() - this.project.onDidChangePaths(this.updateWindowTitle) + if (this.activeItemSubscriptions != null) { + this.activeItemSubscriptions.dispose() + } + this.activeItemSubscriptions = new CompositeDisposable() - this.observeActivePaneItem(item => { - this.updateWindowTitle() - this.updateDocumentEdited() + let modifiedSubscription, titleSubscription - if (this.activeItemSubscriptions != null) { - this.activeItemSubscriptions.dispose() + if (item != null && typeof item.onDidChangeTitle === 'function') { + titleSubscription = item.onDidChangeTitle(this.updateWindowTitle) + } else if (item != null && typeof item.on === 'function') { + titleSubscription = item.on('title-changed', this.updateWindowTitle) + if (titleSubscription == null || typeof titleSubscription.dispose !== 'function') { + titleSubscription = new Disposable(() => { + item.off('title-changed', this.updateWindowTitle) + }) } - this.activeItemSubscriptions = new CompositeDisposable() + } - let modifiedSubscription, titleSubscription - - if (item != null && typeof item.onDidChangeTitle === 'function') { - titleSubscription = item.onDidChangeTitle(this.updateWindowTitle) - } else if (item != null && typeof item.on === 'function') { - titleSubscription = item.on('title-changed', this.updateWindowTitle) - if (titleSubscription == null || typeof titleSubscription.dispose !== 'function') { - titleSubscription = new Disposable(() => { - item.off('title-changed', this.updateWindowTitle) - }) - } + if (item != null && typeof item.onDidChangeModified === 'function') { + modifiedSubscription = item.onDidChangeModified(this.updateDocumentEdited) + } else if (item != null && typeof item.on === 'function') { + modifiedSubscription = item.on('modified-status-changed', this.updateDocumentEdited) + if (modifiedSubscription == null || typeof modifiedSubscription.dispose !== 'function') { + modifiedSubscription = new Disposable(() => { + item.off('modified-status-changed', this.updateDocumentEdited) + }) } + } - if (item != null && typeof item.onDidChangeModified === 'function') { - modifiedSubscription = item.onDidChangeModified(this.updateDocumentEdited) - } else if (item != null && typeof item.on === 'function') { - modifiedSubscription = item.on('modified-status-changed', this.updateDocumentEdited) - if (modifiedSubscription == null || typeof modifiedSubscription.dispose !== 'function') { - modifiedSubscription = new Disposable(() => { - item.off('modified-status-changed', this.updateDocumentEdited) - }) - } - } - - if (titleSubscription != null) { this.activeItemSubscriptions.add(titleSubscription) } - if (modifiedSubscription != null) { this.activeItemSubscriptions.add(modifiedSubscription) } - }) + if (titleSubscription != null) { this.activeItemSubscriptions.add(titleSubscription) } + if (modifiedSubscription != null) { this.activeItemSubscriptions.add(modifiedSubscription) } } subscribeToAddedItems () {