From e11785ce9821db88462ad9ff6aec4c84538b233b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 23 Jun 2014 16:55:44 -0700 Subject: [PATCH] Serialize packages names in Workspace --- spec/window-spec.coffee | 11 ----------- spec/workspace-spec.coffee | 11 +++++++++++ src/atom.coffee | 25 ------------------------- src/workspace.coffee | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index 5603588bf..3d27e2638 100644 --- a/spec/window-spec.coffee +++ b/spec/window-spec.coffee @@ -127,17 +127,6 @@ describe "Window", -> expect(buffer.getSubscriptionCount()).toBe 0 - it "stores the active grammars used by all the open editor", -> - waitsForPromise -> - atom.packages.activatePackage('language-javascript') - - waitsForPromise -> - atom.workspace.open('sample.js') - - runs -> - atom.unloadEditorWindow() - expect(atom.state.packagesWithActiveGrammars).toEqual ['language-javascript'] - describe "drag and drop", -> buildDragEvent = (type, files) -> dataTransfer = diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 791ec25ff..4683e6f76 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -309,3 +309,14 @@ describe "Workspace", -> expect(handler.callCount).toBe 1 editorCopy = editor.copy() expect(handler.callCount).toBe 2 + + it "stores the active grammars used by all the open editor", -> + waitsForPromise -> + atom.packages.activatePackage('language-javascript') + + waitsForPromise -> + atom.workspace.open('sample.js') + + runs -> + state = atom.workspace.serialize() + expect(state.packagesWithActiveGrammars).toEqual ['language-javascript'] diff --git a/src/atom.coffee b/src/atom.coffee index 1b65ca7e2..923e80549 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -250,22 +250,6 @@ class Atom extends Model storeWindowDimensions: -> @state.windowDimensions = @getWindowDimensions() - storeGrammarsForOpenEditors: -> - packageNames = [] - addGrammar = (grammar={}) -> - {includedGrammarScopes, packageName} = grammar - return unless packageName - - # Prevent cycles - return if packageNames.indexOf(packageName) isnt -1 - - packageNames.push(packageName) - for scopeName in includedGrammarScopes ? [] - addGrammar(atom.syntax.grammarForScopeName(scopeName)) - - addGrammar(editor.getGrammar()) for editor in @workspace.getEditors() - @state.packagesWithActiveGrammars = _.uniq(packageNames) - # Public: Get the load settings for the current window. # # Returns an object containing all the load setting key/value pairs. @@ -288,13 +272,6 @@ class Atom extends Model @packages.packageStates = @state.packageStates ? {} delete @state.packageStates - preloadGrammarsForOpenEditors: -> - startTime = Date.now() - packagesWithActiveGrammars = @state.packagesWithActiveGrammars ? [] - for packageName in packagesWithActiveGrammars - @packages.getLoadedPackage(packageName)?.loadGrammarsSync() - atom.preloadGrammarTime = Date.now() - startTime - deserializeEditorWindow: -> @deserializePackageStates() @deserializeProject() @@ -316,7 +293,6 @@ class Atom extends Model @keymaps.loadBundledKeymaps() @themes.loadBaseStylesheets() @packages.loadPackages() - @preloadGrammarsForOpenEditors() @deserializeEditorWindow() @packages.activate() @keymaps.loadUserKeymap() @@ -333,7 +309,6 @@ class Atom extends Model unloadEditorWindow: -> return if not @project and not @workspaceView - @storeGrammarsForOpenEditors() @state.syntax = @syntax.serialize() @state.project = @project.serialize() @state.workspace = @workspace.serialize() diff --git a/src/workspace.coffee b/src/workspace.coffee index daf142fee..799f545cf 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -46,6 +46,9 @@ class Workspace extends Model # Called by the Serializable mixin during deserialization deserializeParams: (params) -> + for packageName in params.packagesWithActiveGrammars ? [] + atom.packages.getLoadedPackage(packageName)?.loadGrammarsSync() + params.paneContainer = PaneContainer.deserialize(params.paneContainer) params @@ -53,6 +56,23 @@ class Workspace extends Model serializeParams: -> paneContainer: @paneContainer.serialize() fullScreen: atom.isFullScreen() + packagesWithActiveGrammars: @getPackageNamesWithActiveGrammars() + + getPackageNamesWithActiveGrammars: -> + packageNames = [] + addGrammar = (grammar={}) -> + {includedGrammarScopes, packageName} = grammar + return unless packageName + + # Prevent cycles + return if packageNames.indexOf(packageName) isnt -1 + + packageNames.push(packageName) + for scopeName in includedGrammarScopes ? [] + addGrammar(atom.syntax.grammarForScopeName(scopeName)) + + addGrammar(editor.getGrammar()) for editor in @getEditors() + _.uniq(packageNames) editorAdded: (editor) -> @emit 'editor-created', editor