mirror of
https://github.com/atom/atom.git
synced 2026-02-15 00:55:14 -05:00
Eliminate rootView.project references.
This commit is contained in:
@@ -59,7 +59,7 @@ class Editor extends View
|
||||
|
||||
@deserialize: (state) ->
|
||||
editor = new Editor(mini: state.mini, deserializing: true)
|
||||
editSessions = state.editSessions.map (state) -> EditSession.deserialize(state, rootView.project)
|
||||
editSessions = state.editSessions.map (state) -> EditSession.deserialize(state, project)
|
||||
editor.pushEditSession(editSession) for editSession in editSessions
|
||||
editor.setActiveEditSessionIndex(state.activeEditSessionIndex)
|
||||
editor.isFocused = state.isFocused
|
||||
|
||||
@@ -37,9 +37,9 @@ class GrammarView extends SelectList
|
||||
confirmed: (grammar) ->
|
||||
@cancel()
|
||||
if grammar is @autoDetect
|
||||
rootView.project.removeGrammarOverrideForPath(@path)
|
||||
project.removeGrammarOverrideForPath(@path)
|
||||
else
|
||||
rootView.project.addGrammarOverrideForPath(@path, grammar)
|
||||
project.addGrammarOverrideForPath(@path, grammar)
|
||||
@editor.reloadGrammar()
|
||||
|
||||
attach: ->
|
||||
|
||||
@@ -38,12 +38,10 @@ class RootView extends View
|
||||
window.rootView = this
|
||||
@handleEvents()
|
||||
|
||||
@project = window.project
|
||||
|
||||
if not projectOrPathToOpen or _.isString(projectOrPathToOpen)
|
||||
pathToOpen = projectOrPathToOpen
|
||||
else
|
||||
pathToOpen = @project?.getPath()
|
||||
pathToOpen = project.getPath()
|
||||
@pathToOpenIsFile = pathToOpen and fs.isFile(pathToOpen)
|
||||
|
||||
config.load()
|
||||
@@ -79,7 +77,7 @@ class RootView extends View
|
||||
|
||||
@on 'root-view:active-path-changed', (e, path) =>
|
||||
if path
|
||||
@project.setPath(path) unless @project.getRootDirectory()
|
||||
project.setPath(path) unless project.getRootDirectory()
|
||||
@setTitle(fs.base(path))
|
||||
else
|
||||
@setTitle("untitled")
|
||||
@@ -115,7 +113,7 @@ class RootView extends View
|
||||
allowActiveEditorChange = options.allowActiveEditorChange ? false
|
||||
|
||||
unless editSession = @openInExistingEditor(path, allowActiveEditorChange, changeFocus)
|
||||
editSession = @project.buildEditSessionForPath(path)
|
||||
editSession = project.buildEditSessionForPath(path)
|
||||
editor = new Editor({editSession})
|
||||
pane = new Pane(editor)
|
||||
@panes.append(pane)
|
||||
@@ -130,7 +128,7 @@ class RootView extends View
|
||||
if activeEditor = @getActiveEditor()
|
||||
activeEditor.focus() if changeFocus
|
||||
|
||||
path = @project.resolve(path) if path
|
||||
path = project.resolve(path) if path
|
||||
|
||||
if editSession = activeEditor.activateEditSessionForPath(path)
|
||||
return editSession
|
||||
@@ -141,7 +139,7 @@ class RootView extends View
|
||||
@makeEditorActive(editor, changeFocus)
|
||||
return editSession
|
||||
|
||||
editSession = @project.buildEditSessionForPath(path)
|
||||
editSession = project.buildEditSessionForPath(path)
|
||||
activeEditor.edit(editSession)
|
||||
editSession
|
||||
|
||||
@@ -170,7 +168,7 @@ class RootView extends View
|
||||
@title or "untitled"
|
||||
|
||||
setTitle: (title) ->
|
||||
projectPath = @project.getPath()
|
||||
projectPath = project.getPath()
|
||||
if not projectPath
|
||||
@title = "untitled"
|
||||
else if title
|
||||
@@ -227,7 +225,7 @@ class RootView extends View
|
||||
|
||||
remove: ->
|
||||
editor.remove() for editor in @getEditors()
|
||||
@project.destroy()
|
||||
project.destroy()
|
||||
super
|
||||
|
||||
saveAll: ->
|
||||
@@ -238,10 +236,10 @@ class RootView extends View
|
||||
@on 'editor:attached', (e, editor) -> callback(editor)
|
||||
|
||||
eachEditSession: (callback) ->
|
||||
@project.eachEditSession(callback)
|
||||
project.eachEditSession(callback)
|
||||
|
||||
eachBuffer: (callback) ->
|
||||
@project.eachBuffer(callback)
|
||||
project.eachBuffer(callback)
|
||||
|
||||
indexOfPane: (pane) ->
|
||||
index = -1
|
||||
|
||||
@@ -64,7 +64,7 @@ windowAdditions =
|
||||
$(rootViewParentSelector).append(rootView)
|
||||
|
||||
stopApplication: ->
|
||||
atom.setWindowState('pathToOpen', rootView.project.getPath())
|
||||
atom.setWindowState('pathToOpen', project.getPath())
|
||||
atom.setRootViewStateForPath project.getPath(),
|
||||
project: project.serialize()
|
||||
rootView: rootView.serialize()
|
||||
|
||||
@@ -30,7 +30,7 @@ class CommandPanelView extends View
|
||||
maxSerializedHistorySize: 100
|
||||
|
||||
initialize: (state) ->
|
||||
@commandInterpreter = new CommandInterpreter(rootView.project)
|
||||
@commandInterpreter = new CommandInterpreter(project)
|
||||
|
||||
@command 'tool-panel:unfocus', => rootView.focus()
|
||||
@command 'core:close', => @detach(); false
|
||||
|
||||
@@ -3,13 +3,12 @@ CommandPanelView = require 'command-panel/lib/command-panel-view'
|
||||
_ = require 'underscore'
|
||||
|
||||
describe "CommandPanel", ->
|
||||
[editor, buffer, commandPanel, project, CommandPanel] = []
|
||||
[editor, buffer, commandPanel, CommandPanel] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView
|
||||
rootView.open(require.resolve 'fixtures/sample.js')
|
||||
rootView.enableKeymap()
|
||||
project = rootView.project
|
||||
editor = rootView.getActiveEditor()
|
||||
buffer = editor.activeEditSession.buffer
|
||||
commandPanelMain = window.loadPackage('command-panel', activateImmediately: true).packageMain
|
||||
|
||||
@@ -65,13 +65,13 @@ class FuzzyFinderView extends SelectList
|
||||
|
||||
editor = rootView.getActiveEditor()
|
||||
if editor
|
||||
fn(editor, rootView.project.buildEditSessionForPath(path))
|
||||
fn(editor, project.buildEditSessionForPath(path))
|
||||
else
|
||||
@openPath(path)
|
||||
|
||||
confirmed : (path) ->
|
||||
return unless path.length
|
||||
if fs.isFile(rootView.project.resolve(path))
|
||||
if fs.isFile(project.resolve(path))
|
||||
@cancel()
|
||||
@openPath(path)
|
||||
else
|
||||
@@ -82,7 +82,7 @@ class FuzzyFinderView extends SelectList
|
||||
if @hasParent()
|
||||
@cancel()
|
||||
else
|
||||
return unless rootView.project.getPath()?
|
||||
return unless project.getPath()?
|
||||
@allowActiveEditorChange = false
|
||||
@populateProjectPaths()
|
||||
@attach()
|
||||
@@ -99,7 +99,7 @@ class FuzzyFinderView extends SelectList
|
||||
if @hasParent()
|
||||
@cancel()
|
||||
else
|
||||
return unless rootView.project.getPath()?
|
||||
return unless project.getPath()?
|
||||
@allowActiveEditorChange = false
|
||||
editor = rootView.getActiveEditor()
|
||||
currentWord = editor.getWordUnderCursor(wordRegex: @filenameRegex)
|
||||
@@ -149,7 +149,7 @@ class FuzzyFinderView extends SelectList
|
||||
@loadPathsTask.start()
|
||||
|
||||
populateOpenBufferPaths: ->
|
||||
editSessions = rootView.project.getEditSessions().filter (editSession)->
|
||||
editSessions = project.getEditSessions().filter (editSession)->
|
||||
editSession.getPath()?
|
||||
|
||||
editSessions = _.sortBy editSessions, (editSession) =>
|
||||
@@ -159,13 +159,13 @@ class FuzzyFinderView extends SelectList
|
||||
-(editSession.lastOpened or 1)
|
||||
|
||||
@paths = _.map editSessions, (editSession) ->
|
||||
rootView.project.relativize editSession.getPath()
|
||||
project.relativize editSession.getPath()
|
||||
|
||||
@setArray(@paths)
|
||||
|
||||
getOpenedPaths: ->
|
||||
paths = {}
|
||||
for editSession in rootView.project.getEditSessions()
|
||||
for editSession in project.getEditSessions()
|
||||
path = editSession.getPath()
|
||||
paths[path] = editSession.lastOpened if path?
|
||||
paths
|
||||
|
||||
@@ -13,12 +13,12 @@ module.exports =
|
||||
rootView.command 'fuzzy-finder:find-under-cursor', =>
|
||||
@createView().findUnderCursor()
|
||||
|
||||
if rootView.project.getPath()?
|
||||
if project.getPath()?
|
||||
LoadPathsTask = require 'fuzzy-finder/lib/load-paths-task'
|
||||
@loadPathsTask = new LoadPathsTask((paths) => @projectPaths = paths)
|
||||
@loadPathsTask.start()
|
||||
|
||||
for editSession in rootView.project.getEditSessions()
|
||||
for editSession in project.getEditSessions()
|
||||
editSession.lastOpened = state[editSession.getPath()]
|
||||
|
||||
deactivate: ->
|
||||
|
||||
@@ -9,7 +9,7 @@ class LoadPathsTask extends Task
|
||||
ignoredNames = config.get('fuzzyFinder.ignoredNames') ? []
|
||||
ignoredNames = ignoredNames.concat(config.get('core.ignoredNames') ? [])
|
||||
excludeGitIgnoredPaths = config.get('core.hideGitIgnoredFiles')
|
||||
rootPath = rootView.project.getPath()
|
||||
rootPath = project.getPath()
|
||||
@callWorkerMethod('loadPaths', rootPath, ignoredNames, excludeGitIgnoredPaths)
|
||||
|
||||
pathsLoaded: (paths) ->
|
||||
|
||||
@@ -64,7 +64,7 @@ describe 'FuzzyFinder', ->
|
||||
|
||||
describe "when root view's project has no path", ->
|
||||
beforeEach ->
|
||||
rootView.project.setPath(null)
|
||||
project.setPath(null)
|
||||
|
||||
it "does not open the FuzzyFinder", ->
|
||||
expect(rootView.find('.fuzzy-finder')).not.toExist()
|
||||
@@ -165,7 +165,7 @@ describe 'FuzzyFinder', ->
|
||||
describe "when the active editor only contains edit sessions for anonymous buffers", ->
|
||||
it "does not open", ->
|
||||
editor = rootView.getActiveEditor()
|
||||
editor.edit(rootView.project.buildEditSessionForPath())
|
||||
editor.edit(project.buildEditSessionForPath())
|
||||
editor.loadPreviousEditSession()
|
||||
editor.destroyActiveEditSession()
|
||||
expect(editor.getOpenBufferPaths().length).toBe 0
|
||||
@@ -276,15 +276,15 @@ describe 'FuzzyFinder', ->
|
||||
expect(finderView.loadPathsTask.start).not.toHaveBeenCalled()
|
||||
|
||||
it "doesn't cache buffer paths", ->
|
||||
spyOn(rootView.project, "getEditSessions").andCallThrough()
|
||||
spyOn(project, "getEditSessions").andCallThrough()
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
|
||||
waitsFor ->
|
||||
finderView.list.children('li').length > 0
|
||||
|
||||
runs ->
|
||||
expect(rootView.project.getEditSessions).toHaveBeenCalled()
|
||||
rootView.project.getEditSessions.reset()
|
||||
expect(project.getEditSessions).toHaveBeenCalled()
|
||||
project.getEditSessions.reset()
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
|
||||
|
||||
@@ -292,7 +292,7 @@ describe 'FuzzyFinder', ->
|
||||
finderView.list.children('li').length > 0
|
||||
|
||||
runs ->
|
||||
expect(rootView.project.getEditSessions).toHaveBeenCalled()
|
||||
expect(project.getEditSessions).toHaveBeenCalled()
|
||||
|
||||
it "busts the cache when the window gains focus", ->
|
||||
spyOn(LoadPathsTask.prototype, "start").andCallThrough()
|
||||
|
||||
@@ -39,7 +39,7 @@ describe "MarkdownPreview", ->
|
||||
gfmGrammar = _.find syntax.grammars, (grammar) -> grammar.scopeName is 'source.gfm'
|
||||
rootView.open('file.js')
|
||||
editor = rootView.getActiveEditor()
|
||||
rootView.project.addGrammarOverrideForPath(editor.getPath(), gfmGrammar)
|
||||
project.addGrammarOverrideForPath(editor.getPath(), gfmGrammar)
|
||||
editor.reloadGrammar()
|
||||
expect(rootView.find('.markdown-preview')).not.toExist()
|
||||
editor.trigger('markdown-preview:toggle')
|
||||
|
||||
@@ -99,7 +99,7 @@ class StatusBarView extends View
|
||||
|
||||
updatePathText: ->
|
||||
if path = @editor.getPath()
|
||||
@currentPath.text(rootView.project.relativize(path))
|
||||
@currentPath.text(project.relativize(path))
|
||||
else
|
||||
@currentPath.text('untitled')
|
||||
|
||||
|
||||
@@ -114,13 +114,13 @@ describe "StatusBar", ->
|
||||
|
||||
it "displays the current branch for files in repositories", ->
|
||||
path = require.resolve('fixtures/git/master.git/HEAD')
|
||||
rootView.project.setPath(require.resolve('fixtures/git/master.git'))
|
||||
project.setPath(require.resolve('fixtures/git/master.git'))
|
||||
rootView.open(path)
|
||||
expect(statusBar.branchArea).toBeVisible()
|
||||
expect(statusBar.branchLabel.text()).toBe 'master'
|
||||
|
||||
it "doesn't display the current branch for a file not in a repository", ->
|
||||
rootView.project.setPath('/tmp')
|
||||
project.setPath('/tmp')
|
||||
rootView.open('/tmp/temp.txt')
|
||||
expect(statusBar.branchArea).toBeHidden()
|
||||
expect(statusBar.branchLabel.text()).toBe ''
|
||||
@@ -184,7 +184,7 @@ describe "StatusBar", ->
|
||||
describe "when the editor's grammar changes", ->
|
||||
it "displays the new grammar of the editor", ->
|
||||
textGrammar = _.find syntax.grammars, (grammar) -> grammar.name is 'Plain Text'
|
||||
rootView.project.addGrammarOverrideForPath(editor.getPath(), textGrammar)
|
||||
project.addGrammarOverrideForPath(editor.getPath(), textGrammar)
|
||||
editor.reloadGrammar()
|
||||
expect(statusBar.find('.grammar-name').text()).toBe textGrammar.name
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class SymbolsView extends SelectList
|
||||
populateProjectSymbols: ->
|
||||
@list.empty()
|
||||
@setLoading("Loading symbols...")
|
||||
TagReader.getAllTags(rootView.project).done (tags) =>
|
||||
TagReader.getAllTags(project).done (tags) =>
|
||||
if tags.length > 0
|
||||
@miniEditor.show()
|
||||
@maxItems = 10
|
||||
@@ -102,7 +102,7 @@ class SymbolsView extends SelectList
|
||||
getTagLine: (tag) ->
|
||||
pattern = $.trim(tag.pattern?.replace(/(^^\/\^)|(\$\/$)/g, '')) # Remove leading /^ and trailing $/
|
||||
return unless pattern
|
||||
file = rootView.project.resolve(tag.file)
|
||||
file = project.resolve(tag.file)
|
||||
return unless fs.isFile(file)
|
||||
for line, index in fs.read(file).split('\n')
|
||||
return new Point(index, 0) if pattern is $.trim(line)
|
||||
|
||||
@@ -11,7 +11,7 @@ find: (editor) ->
|
||||
word = editor.getTextInRange(editor.getCursor().getCurrentWordBufferRange())
|
||||
return [] unless word.length > 0
|
||||
|
||||
tagsFile = @getTagsFile(rootView.project)
|
||||
tagsFile = @getTagsFile(project)
|
||||
return [] unless tagsFile
|
||||
|
||||
$tags.find(tagsFile, word) or []
|
||||
|
||||
@@ -152,15 +152,15 @@ describe "SymbolsView", ->
|
||||
expect(symbolsView.list.children('li').length).toBe 2
|
||||
expect(symbolsView).toBeVisible()
|
||||
symbolsView.confirmed(symbolsView.array[0])
|
||||
expect(rootView.getActiveEditor().getPath()).toBe rootView.project.resolve("tagged-duplicate.js")
|
||||
expect(rootView.getActiveEditor().getPath()).toBe project.resolve("tagged-duplicate.js")
|
||||
expect(rootView.getActiveEditor().getCursorBufferPosition()).toEqual [0,4]
|
||||
|
||||
describe "when the tag is in a file that doesn't exist", ->
|
||||
beforeEach ->
|
||||
fs.move(rootView.project.resolve("tagged-duplicate.js"), rootView.project.resolve("tagged-duplicate-renamed.js"))
|
||||
fs.move(project.resolve("tagged-duplicate.js"), project.resolve("tagged-duplicate-renamed.js"))
|
||||
|
||||
afterEach ->
|
||||
fs.move(rootView.project.resolve("tagged-duplicate-renamed.js"), rootView.project.resolve("tagged-duplicate.js"))
|
||||
fs.move(project.resolve("tagged-duplicate-renamed.js"), project.resolve("tagged-duplicate.js"))
|
||||
|
||||
it "doesn't display the tag", ->
|
||||
rootView.open("tagged.js")
|
||||
|
||||
@@ -41,7 +41,7 @@ class TreeView extends ScrollView
|
||||
@selectActiveFile()
|
||||
|
||||
rootView.on 'root-view:active-path-changed', => @selectActiveFile()
|
||||
rootView.project.on 'path-changed', => @updateRoot()
|
||||
project.on 'path-changed', => @updateRoot()
|
||||
@observeConfig 'core.hideGitIgnoredFiles', => @updateRoot()
|
||||
|
||||
if @root
|
||||
@@ -78,7 +78,7 @@ class TreeView extends ScrollView
|
||||
@attach()
|
||||
|
||||
attach: ->
|
||||
return unless rootView.project.getPath()
|
||||
return unless project.getPath()
|
||||
rootView.horizontal.prepend(this)
|
||||
@focus()
|
||||
|
||||
@@ -122,8 +122,8 @@ class TreeView extends ScrollView
|
||||
|
||||
updateRoot: ->
|
||||
@root?.remove()
|
||||
if rootDirectory = rootView.project.getRootDirectory()
|
||||
@root = new DirectoryView(directory: rootDirectory, isExpanded: true, project: rootView.project)
|
||||
if rootDirectory = project.getRootDirectory()
|
||||
@root = new DirectoryView(directory: rootDirectory, isExpanded: true, project: project)
|
||||
@treeViewList.append(@root)
|
||||
else
|
||||
@root = null
|
||||
@@ -137,7 +137,6 @@ class TreeView extends ScrollView
|
||||
|
||||
return unless activeFilePath = rootView.getActiveEditor()?.getPath()
|
||||
|
||||
project = rootView.project
|
||||
activePathComponents = project.relativize(activeFilePath).split('/')
|
||||
currentPath = project.getPath().replace(/\/$/, '')
|
||||
for pathComponent in activePathComponents
|
||||
@@ -217,11 +216,11 @@ class TreeView extends ScrollView
|
||||
|
||||
dialog = new Dialog
|
||||
prompt: prompt
|
||||
path: rootView.project.relativize(oldPath)
|
||||
path: project.relativize(oldPath)
|
||||
select: true
|
||||
iconClass: 'move'
|
||||
onConfirm: (newPath) =>
|
||||
newPath = rootView.project.resolve(newPath)
|
||||
newPath = project.resolve(newPath)
|
||||
directoryPath = fs.directory(newPath)
|
||||
try
|
||||
fs.makeTree(directoryPath) unless fs.exists(directoryPath)
|
||||
@@ -249,7 +248,7 @@ class TreeView extends ScrollView
|
||||
selectedEntry = @selectedEntry() or @root
|
||||
selectedPath = selectedEntry.getPath()
|
||||
directoryPath = if fs.isFile(selectedPath) then fs.directory(selectedPath) else selectedPath
|
||||
relativeDirectoryPath = rootView.project.relativize(directoryPath)
|
||||
relativeDirectoryPath = project.relativize(directoryPath)
|
||||
relativeDirectoryPath += '/' if relativeDirectoryPath.length > 0
|
||||
|
||||
dialog = new Dialog
|
||||
@@ -259,7 +258,7 @@ class TreeView extends ScrollView
|
||||
iconClass: 'add'
|
||||
onConfirm: (relativePath) =>
|
||||
endsWithDirectorySeparator = /\/$/.test(relativePath)
|
||||
path = rootView.project.resolve(relativePath)
|
||||
path = project.resolve(relativePath)
|
||||
try
|
||||
if fs.exists(path)
|
||||
pathType = if fs.isFile(path) then "file" else "directory"
|
||||
|
||||
Reference in New Issue
Block a user