mirror of
https://github.com/atom/atom.git
synced 2026-02-03 19:25:06 -05:00
Serialize grammar overrides for paths
This commit is contained in:
@@ -48,7 +48,10 @@ class LanguageMode
|
||||
false
|
||||
|
||||
reloadGrammar: ->
|
||||
@grammar = rootView.project.grammarForFilePath(@buffer.getPath())
|
||||
if @buffer.project?
|
||||
@grammar = @buffer.project.grammarForFilePath(@buffer.getPath())
|
||||
else
|
||||
@grammar = syntax.grammarForFilePath(@buffer.getPath())
|
||||
|
||||
isQuote: (string) ->
|
||||
/'|"/.test(string)
|
||||
|
||||
@@ -11,6 +11,10 @@ Git = require 'git'
|
||||
|
||||
module.exports =
|
||||
class Project
|
||||
|
||||
@deserialize: (state) ->
|
||||
new Project(state.path, state.grammarOverridesByPath)
|
||||
|
||||
tabLength: 2
|
||||
autoIndent: true
|
||||
softTabs: true
|
||||
@@ -18,13 +22,17 @@ class Project
|
||||
rootDirectory: null
|
||||
editSessions: null
|
||||
ignoredPathRegexes: null
|
||||
grammarOverridesByPath: {}
|
||||
grammarOverridesByPath: null
|
||||
|
||||
constructor: (path) ->
|
||||
constructor: (path, @grammarOverridesByPath={}) ->
|
||||
@setPath(path)
|
||||
@editSessions = []
|
||||
@buffers = []
|
||||
|
||||
serialize: ->
|
||||
path: @getPath()
|
||||
grammarOverridesByPath: @grammarOverridesByPath
|
||||
|
||||
destroy: ->
|
||||
editSession.destroy() for editSession in @getEditSessions()
|
||||
|
||||
@@ -34,9 +42,11 @@ class Project
|
||||
removeGrammarOverrideForPath: (path) ->
|
||||
delete @grammarOverridesByPath[path]
|
||||
|
||||
grammarOverrideForPath: (path) ->
|
||||
syntax.grammarForScopeName(@grammarOverridesByPath[path])
|
||||
|
||||
grammarForFilePath: (path) ->
|
||||
grammar = syntax.grammarForScopeName(@grammarOverridesByPath[path]) if path
|
||||
grammar or syntax.grammarForFilePath(path)
|
||||
@grammarOverrideForPath(path) or syntax.grammarForFilePath(path)
|
||||
|
||||
getPath: ->
|
||||
@rootDirectory?.path
|
||||
|
||||
@@ -23,8 +23,9 @@ class RootView extends View
|
||||
@div id: 'vertical', outlet: 'vertical', =>
|
||||
@div id: 'panes', outlet: 'panes'
|
||||
|
||||
@deserialize: ({ projectPath, panesViewState, packageStates }) ->
|
||||
rootView = new RootView(projectPath, packageStates: packageStates, suppressOpen: true)
|
||||
@deserialize: ({ projectState, panesViewState, packageStates }) ->
|
||||
project = Project.deserialize(projectState) if projectState
|
||||
rootView = new RootView(project, packageStates: packageStates, suppressOpen: true)
|
||||
rootView.setRootPane(rootView.deserializeView(panesViewState)) if panesViewState
|
||||
rootView
|
||||
|
||||
@@ -32,11 +33,16 @@ class RootView extends View
|
||||
packageStates: null
|
||||
title: null
|
||||
|
||||
initialize: (pathToOpen, { @packageStates, suppressOpen } = {}) ->
|
||||
initialize: (projectOrPathToOpen, { @packageStates, suppressOpen } = {}) ->
|
||||
window.rootView = this
|
||||
@packageStates ?= {}
|
||||
@packageModules = {}
|
||||
@project = new Project(pathToOpen)
|
||||
|
||||
if not projectOrPathToOpen or _.isString(projectOrPathToOpen)
|
||||
pathToOpen = projectOrPathToOpen
|
||||
@project = new Project(projectOrPathToOpen)
|
||||
else
|
||||
@project = projectOrPathToOpen
|
||||
|
||||
config.load()
|
||||
|
||||
@@ -48,7 +54,7 @@ class RootView extends View
|
||||
@open()
|
||||
|
||||
serialize: ->
|
||||
projectPath: @project?.getPath()
|
||||
projectState: @project?.serialize()
|
||||
panesViewState: @panes.children().view()?.serialize()
|
||||
packageStates: @serializePackages()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user