mirror of
https://github.com/atom/atom.git
synced 2026-02-14 16:45:14 -05:00
RootView.initialize no longer assigns window.rootView or calls open
This commit is contained in:
@@ -27,49 +27,13 @@ class RootView extends View
|
||||
|
||||
@deserialize: ({ panesViewState, packageStates, projectPath }) ->
|
||||
atom.atomPackageStates = packageStates ? {}
|
||||
rootView = new RootView(null, suppressOpen: true)
|
||||
rootView = new RootView
|
||||
rootView.setRootPane(deserialize(panesViewState)) if panesViewState
|
||||
rootView
|
||||
|
||||
title: null
|
||||
pathToOpenIsFile: false
|
||||
|
||||
initialize: (projectOrPathToOpen, { suppressOpen } = {}) ->
|
||||
window.rootView = this
|
||||
@handleEvents()
|
||||
|
||||
if not projectOrPathToOpen or _.isString(projectOrPathToOpen)
|
||||
pathToOpen = projectOrPathToOpen
|
||||
else
|
||||
pathToOpen = project.getPath()
|
||||
@pathToOpenIsFile = pathToOpen and fs.isFile(pathToOpen)
|
||||
|
||||
config.load()
|
||||
|
||||
unless suppressOpen
|
||||
if pathToOpen
|
||||
@open(pathToOpen) if @pathToOpenIsFile
|
||||
else
|
||||
@open()
|
||||
|
||||
serialize: ->
|
||||
panesViewState: @panes.children().view()?.serialize()
|
||||
packageStates: atom.serializeAtomPackages()
|
||||
|
||||
handleFocus: (e) ->
|
||||
if @getActiveEditor()
|
||||
@getActiveEditor().focus()
|
||||
false
|
||||
else
|
||||
@setTitle(null)
|
||||
focusableChild = this.find("[tabindex=-1]:visible:first")
|
||||
if focusableChild.length
|
||||
focusableChild.focus()
|
||||
false
|
||||
else
|
||||
true
|
||||
|
||||
handleEvents: ->
|
||||
initialize: ->
|
||||
@command 'toggle-dev-tools', => atom.toggleDevTools()
|
||||
@on 'focus', (e) => @handleFocus(e)
|
||||
@subscribe $(window), 'focus', (e) =>
|
||||
@@ -101,6 +65,24 @@ class RootView extends View
|
||||
@command 'window:toggle-auto-indent-on-paste', =>
|
||||
config.set("editor.autoIndentOnPaste", !config.get("editor.autoIndentOnPaste"))
|
||||
|
||||
serialize: ->
|
||||
deserializer: 'RootView'
|
||||
panesViewState: @panes.children().view()?.serialize()
|
||||
packageStates: atom.serializeAtomPackages()
|
||||
|
||||
handleFocus: (e) ->
|
||||
if @getActiveEditor()
|
||||
@getActiveEditor().focus()
|
||||
false
|
||||
else
|
||||
@setTitle(null)
|
||||
focusableChild = this.find("[tabindex=-1]:visible:first")
|
||||
if focusableChild.length
|
||||
focusableChild.focus()
|
||||
false
|
||||
else
|
||||
true
|
||||
|
||||
afterAttach: (onDom) ->
|
||||
@focus() if onDom
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ windowAdditions =
|
||||
$(document).on 'keydown', keymap.handleKeyEvent
|
||||
keymap.bindDefaultKeys()
|
||||
|
||||
$(window).on 'core:close', => @close()
|
||||
$(window).on 'core:close', => window.close()
|
||||
|
||||
handleWindowEvents: ->
|
||||
$(window).command 'window:close', => @close()
|
||||
$(window).command 'window:close', => window.close()
|
||||
$(window).command 'window:toggle-full-screen', => atom.toggleFullScreen()
|
||||
$(window).on 'focus', -> $("body").removeClass('is-blurred')
|
||||
$(window).on 'blur', -> $("body").addClass('is-blurred')
|
||||
@@ -42,6 +42,7 @@ windowAdditions =
|
||||
# Note: RootView assigns itself on window on initialization so that
|
||||
# window.rootView is available when loading user configuration
|
||||
startApplication: ->
|
||||
handleWindowEvents()
|
||||
config.load()
|
||||
buildProjectAndRootView()
|
||||
keymap.loadBundledKeymaps()
|
||||
@@ -51,6 +52,9 @@ windowAdditions =
|
||||
$(window).on 'beforeunload', -> stopApplication(); false
|
||||
$(window).focus()
|
||||
|
||||
pathToOpen = atom.getPathToOpen()
|
||||
rootView.open(pathToOpen) if !pathToOpen or fs.isFile(pathToOpen)
|
||||
|
||||
buildProjectAndRootView: ->
|
||||
RootView = require 'root-view'
|
||||
Project = require 'project'
|
||||
@@ -60,7 +64,7 @@ windowAdditions =
|
||||
window.rootView = deserialize(windowState.rootView)
|
||||
else
|
||||
window.project = new Project(atom.getPathToOpen())
|
||||
window.rootView = new RootView(atom.getPathToOpen())
|
||||
window.rootView = new RootView
|
||||
$(rootViewParentSelector).append(rootView)
|
||||
|
||||
stopApplication: ->
|
||||
|
||||
@@ -7,12 +7,10 @@ RootView = require 'root-view'
|
||||
|
||||
describe "Autocomplete", ->
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.simulateDomAttachment()
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
|
||||
describe "@activate()", ->
|
||||
it "activates autocomplete on all existing and future editors (but not on autocomplete's own mini editor)", ->
|
||||
spyOn(AutocompleteView.prototype, 'initialize').andCallThrough()
|
||||
@@ -41,16 +39,12 @@ describe "AutocompleteView", ->
|
||||
miniEditor = null
|
||||
|
||||
beforeEach ->
|
||||
new RootView
|
||||
window.rootView = new RootView
|
||||
editor = new Editor(editSession: fixturesProject.buildEditSessionForPath('sample.js'))
|
||||
window.loadPackage('autocomplete')
|
||||
autocomplete = new AutocompleteView(editor)
|
||||
miniEditor = autocomplete.miniEditor
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
editor?.remove()
|
||||
|
||||
describe 'autocomplete:attach event', ->
|
||||
it "shows autocomplete view and focuses its mini-editor", ->
|
||||
expect(editor.find('.autocomplete')).not.toExist()
|
||||
|
||||
@@ -4,7 +4,8 @@ describe "Autoflow package", ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
new RootView
|
||||
window.rootView = new RootView
|
||||
rootView.open()
|
||||
window.loadPackage 'autoflow'
|
||||
editor = rootView.getActiveEditor()
|
||||
config.set('editor.preferredLineLength', 30)
|
||||
|
||||
@@ -4,7 +4,8 @@ describe "bracket matching", ->
|
||||
[editor, editSession, buffer] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
window.loadPackage('bracket-matcher')
|
||||
rootView.attachToDom()
|
||||
editor = rootView.getActiveEditor()
|
||||
|
||||
@@ -5,7 +5,8 @@ describe "CommandLogger", ->
|
||||
[commandLogger, editor] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
commandLogger = window.loadPackage('command-logger').packageMain
|
||||
commandLogger.eventLog = {}
|
||||
editor = rootView.getActiveEditor()
|
||||
|
||||
@@ -7,7 +7,8 @@ describe "CommandPalette", ->
|
||||
[palette] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
window.loadPackage("command-palette")
|
||||
rootView.attachToDom().focus()
|
||||
rootView.trigger 'command-palette:toggle'
|
||||
|
||||
@@ -6,8 +6,8 @@ describe "CommandPanel", ->
|
||||
[editor, buffer, commandPanel, CommandPanel] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView
|
||||
rootView.open(require.resolve 'fixtures/sample.js')
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.enableKeymap()
|
||||
editor = rootView.getActiveEditor()
|
||||
buffer = editor.activeEditSession.buffer
|
||||
@@ -33,7 +33,8 @@ describe "CommandPanel", ->
|
||||
|
||||
rootViewState = rootView.serialize()
|
||||
rootView.deactivate()
|
||||
RootView.deserialize(rootViewState).attachToDom()
|
||||
window.rootView = RootView.deserialize(rootViewState)
|
||||
rootView.attachToDom()
|
||||
window.loadPackage('command-panel')
|
||||
|
||||
expect(rootView.find('.command-panel')).not.toExist()
|
||||
|
||||
@@ -14,7 +14,8 @@ describe "EditorStats", ->
|
||||
rootView.trigger(e)
|
||||
|
||||
beforeEach ->
|
||||
new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
|
||||
date = new Date()
|
||||
mins = date.getMinutes()
|
||||
|
||||
@@ -10,7 +10,8 @@ describe 'FuzzyFinder', ->
|
||||
[finderView] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.enableKeymap()
|
||||
finderView = window.loadPackage("fuzzy-finder").packageMain.createView()
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ describe "Gists package", ->
|
||||
[editor] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(fixturesProject.resolve('sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
window.loadPackage('gists')
|
||||
editor = rootView.getActiveEditor()
|
||||
spyOn($, 'ajax')
|
||||
|
||||
@@ -5,15 +5,13 @@ describe 'GoToLine', ->
|
||||
[goToLine, editor] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.enableKeymap()
|
||||
editor = rootView.getActiveEditor()
|
||||
goToLine = GoToLineView.activate()
|
||||
editor.setCursorBufferPosition([1,0])
|
||||
|
||||
afterEach ->
|
||||
rootView.remove()
|
||||
|
||||
describe "when editor:go-to-line is triggered", ->
|
||||
it "attaches to the root view", ->
|
||||
expect(goToLine.hasParent()).toBeFalsy()
|
||||
|
||||
@@ -6,7 +6,7 @@ _ = require 'underscore'
|
||||
describe "MarkdownPreview", ->
|
||||
beforeEach ->
|
||||
project.setPath(project.resolve('markdown'))
|
||||
rootView = new RootView(project.getPath())
|
||||
window.rootView = new RootView
|
||||
window.loadPackage("markdown-preview")
|
||||
spyOn(MarkdownPreview.prototype, 'loadHtml')
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ describe 'Package Generator', ->
|
||||
[packageGenerator] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
window.loadPackage("package-generator")
|
||||
|
||||
afterEach ->
|
||||
|
||||
@@ -9,12 +9,9 @@ fdescribe "##PackageName##View", ->
|
||||
##packageName## = null
|
||||
|
||||
beforeEach ->
|
||||
new RootView()
|
||||
window.rootView = new RootView
|
||||
##packageName## = window.loadPackage('##packageName##', activateImmediately: true)
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
|
||||
describe "when the ##package-name##:toggle event is triggered", ->
|
||||
it "attaches and then detaches the view", ->
|
||||
expect(rootView.find('.##package-name##')).not.toExist()
|
||||
|
||||
@@ -10,7 +10,8 @@ Package = require 'package'
|
||||
describe "Snippets extension", ->
|
||||
[buffer, editor, editSession] = []
|
||||
beforeEach ->
|
||||
new RootView(project.resolve('sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
spyOn(LoadSnippetsTask.prototype, 'start')
|
||||
|
||||
packageWithSnippets = window.loadPackage("package-with-snippets")
|
||||
|
||||
@@ -5,19 +5,17 @@ StatusBar = require 'status-bar/lib/status-bar-view'
|
||||
fs = require 'fs'
|
||||
|
||||
describe "StatusBar", ->
|
||||
[rootView, editor, statusBar, buffer] = []
|
||||
[editor, statusBar, buffer] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.simulateDomAttachment()
|
||||
StatusBar.activate()
|
||||
editor = rootView.getActiveEditor()
|
||||
statusBar = rootView.find('.status-bar').view()
|
||||
buffer = editor.getBuffer()
|
||||
|
||||
afterEach ->
|
||||
rootView.remove()
|
||||
|
||||
describe "@initialize", ->
|
||||
it "appends a status bar to all existing and new editors", ->
|
||||
expect(rootView.panes.find('.pane').length).toBe 1
|
||||
@@ -34,8 +32,8 @@ describe "StatusBar", ->
|
||||
|
||||
describe "when associated with an unsaved buffer", ->
|
||||
it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", ->
|
||||
rootView.remove()
|
||||
rootView = new RootView
|
||||
rootView.deactivate()
|
||||
window.rootView = new RootView
|
||||
rootView.open()
|
||||
rootView.simulateDomAttachment()
|
||||
StatusBar.activate()
|
||||
|
||||
@@ -2,12 +2,13 @@ RootView = require 'root-view'
|
||||
fs = require 'fs'
|
||||
|
||||
describe "StripTrailingWhitespace", ->
|
||||
[rootView, editor, path] = []
|
||||
[editor, path] = []
|
||||
|
||||
beforeEach ->
|
||||
path = "/tmp/atom-whitespace.txt"
|
||||
fs.write(path, "")
|
||||
rootView = new RootView(path)
|
||||
window.rootView = new RootView
|
||||
rootView.open(path)
|
||||
|
||||
window.loadPackage('strip-trailing-whitespace')
|
||||
rootView.focus()
|
||||
|
||||
@@ -7,14 +7,13 @@ describe "SymbolsView", ->
|
||||
[symbolsView, setArraySpy] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures'))
|
||||
window.rootView = new RootView
|
||||
window.loadPackage("symbols-view")
|
||||
|
||||
rootView.attachToDom()
|
||||
setArraySpy = spyOn(SymbolsView.prototype, 'setArray').andCallThrough()
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
setArraySpy.reset()
|
||||
|
||||
describe "when tags can be generated for a file", ->
|
||||
|
||||
@@ -7,16 +7,14 @@ describe "TabView", ->
|
||||
[editor, buffer, tabs] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.open('sample.txt')
|
||||
rootView.simulateDomAttachment()
|
||||
window.loadPackage("tabs")
|
||||
editor = rootView.getActiveEditor()
|
||||
tabs = rootView.find('.tabs').view()
|
||||
|
||||
afterEach ->
|
||||
rootView.remove()
|
||||
|
||||
describe "@activate", ->
|
||||
it "appends a status bear to all existing and new editors", ->
|
||||
expect(rootView.panes.find('.pane').length).toBe 1
|
||||
@@ -25,7 +23,7 @@ describe "TabView", ->
|
||||
expect(rootView.find('.pane').length).toBe 2
|
||||
expect(rootView.panes.find('.pane > .tabs').length).toBe 2
|
||||
|
||||
describe "#initialize()", ->
|
||||
describe ".initialize()", ->
|
||||
it "creates a tab for each edit session on the editor to which the tab-strip belongs", ->
|
||||
expect(editor.editSessions.length).toBe 2
|
||||
expect(tabs.find('.tab').length).toBe 2
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
treeView: null
|
||||
|
||||
activate: (@state) ->
|
||||
if @state.attached == undefined and not rootView.pathToOpenIsFile
|
||||
@state.attached = true
|
||||
@state.attached ?= true unless rootView.getActiveEditSession()
|
||||
|
||||
@createView() if @state.attached
|
||||
rootView.command 'tree-view:toggle', => @createView().toggle()
|
||||
|
||||
@@ -10,7 +10,7 @@ describe "TreeView", ->
|
||||
|
||||
beforeEach ->
|
||||
project.setPath(project.resolve('tree-view'))
|
||||
new RootView(project.getPath())
|
||||
window.rootView = new RootView
|
||||
|
||||
window.loadPackage("tree-view")
|
||||
rootView.trigger 'tree-view:toggle'
|
||||
@@ -50,7 +50,8 @@ describe "TreeView", ->
|
||||
beforeEach ->
|
||||
project.setPath(undefined)
|
||||
rootView.deactivate()
|
||||
new RootView()
|
||||
window.rootView = new RootView()
|
||||
rootView.open()
|
||||
treeView = window.loadPackage("tree-view").packageMain.createView()
|
||||
|
||||
it "does not attach to the root view or create a root node when initialized", ->
|
||||
@@ -75,15 +76,14 @@ describe "TreeView", ->
|
||||
describe "when the root view is opened to a file path", ->
|
||||
it "does not attach to the root view but does create a root node when initialized", ->
|
||||
rootView.deactivate()
|
||||
new RootView(require.resolve('fixtures/tree-view/tree-view.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('tree-view.js')
|
||||
treeView = window.loadPackage("tree-view").packageMain.createView()
|
||||
expect(treeView.hasParent()).toBeFalsy()
|
||||
expect(treeView.root).toExist()
|
||||
|
||||
describe "when the root view is opened to a directory", ->
|
||||
it "attaches to the root view", ->
|
||||
rootView.deactivate()
|
||||
new RootView(require.resolve('fixtures/tree-view'))
|
||||
treeView = window.loadPackage("tree-view").packageMain.createView()
|
||||
expect(treeView.hasParent()).toBeTruthy()
|
||||
expect(treeView.root).toExist()
|
||||
@@ -95,7 +95,7 @@ describe "TreeView", ->
|
||||
|
||||
rootViewState = rootView.serialize()
|
||||
rootView.deactivate()
|
||||
RootView.deserialize(rootViewState)
|
||||
window.rootView = RootView.deserialize(rootViewState)
|
||||
window.loadPackage("tree-view")
|
||||
treeView = rootView.find(".tree-view").view()
|
||||
|
||||
@@ -110,7 +110,7 @@ describe "TreeView", ->
|
||||
|
||||
rootViewState = rootView.serialize()
|
||||
rootView.deactivate()
|
||||
RootView.deserialize(rootViewState)
|
||||
window.rootView = RootView.deserialize(rootViewState)
|
||||
|
||||
rootView.attachToDom()
|
||||
window.loadPackage("tree-view")
|
||||
@@ -607,7 +607,7 @@ describe "TreeView", ->
|
||||
fs.write(filePath, "doesn't matter")
|
||||
|
||||
project.setPath(rootDirPath)
|
||||
new RootView(rootDirPath)
|
||||
window.rootView = new RootView(rootDirPath)
|
||||
window.loadPackage('tree-view')
|
||||
rootView.trigger 'tree-view:toggle'
|
||||
treeView = rootView.find(".tree-view").view()
|
||||
|
||||
@@ -4,16 +4,14 @@ describe "WrapGuide", ->
|
||||
[editor, wrapGuide] = []
|
||||
|
||||
beforeEach ->
|
||||
new RootView(require.resolve('fixtures/sample.js'))
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
window.loadPackage('wrap-guide')
|
||||
rootView.attachToDom()
|
||||
editor = rootView.getActiveEditor()
|
||||
wrapGuide = rootView.find('.wrap-guide').view()
|
||||
editor.width(editor.charWidth * wrapGuide.getDefaultColumn() * 2)
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
|
||||
describe "@initialize", ->
|
||||
it "appends a wrap guide to all existing and new editors", ->
|
||||
expect(rootView.panes.find('.pane').length).toBe 1
|
||||
|
||||
Reference in New Issue
Block a user