mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-19 23:17:16 +03:00
Pass AppDelegate to Workspace, Pane instead of bound functions
Signed-off-by: Max Brunsfeld <maxbrunsfeld@github.com>
This commit is contained in:
parent
20e07649d4
commit
84aa8471b4
@ -213,9 +213,7 @@ describe "AtomEnvironment", ->
|
||||
|
||||
describe "::unloadEditorWindow()", ->
|
||||
it "saves the serialized state of the window so it can be deserialized after reload", ->
|
||||
atomEnvironment = new AtomEnvironment(applicationDelegate: {
|
||||
isWindowFullScreen: -> false
|
||||
})
|
||||
atomEnvironment = new AtomEnvironment(applicationDelegate: atom.applicationDelegate)
|
||||
spyOn(atomEnvironment, 'saveStateSync')
|
||||
|
||||
workspaceState = atomEnvironment.workspace.serialize()
|
||||
@ -233,9 +231,7 @@ describe "AtomEnvironment", ->
|
||||
|
||||
describe "::destroy()", ->
|
||||
it "unsubscribes from all buffers", ->
|
||||
atomEnvironment = new AtomEnvironment(applicationDelegate: {
|
||||
isWindowFullScreen: -> false
|
||||
})
|
||||
atomEnvironment = new AtomEnvironment(applicationDelegate: atom.applicationDelegate)
|
||||
|
||||
waitsForPromise ->
|
||||
atomEnvironment.workspace.open("sample.js")
|
||||
|
@ -16,7 +16,7 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) ->
|
||||
|
||||
ApplicationDelegate = require '../src/application-delegate'
|
||||
applicationDelegate = new ApplicationDelegate()
|
||||
applicationDelegate.setWindowRepresentedFilename = ->
|
||||
applicationDelegate.setRepresentedFilename = ->
|
||||
applicationDelegate.setWindowDocumentEdited = ->
|
||||
window.atom = buildAtomEnvironment({applicationDelegate})
|
||||
|
||||
|
@ -5,11 +5,11 @@ describe "PaneContainer", ->
|
||||
[confirm, params] = []
|
||||
|
||||
beforeEach ->
|
||||
confirm = jasmine.createSpy('confirm').andReturn(0)
|
||||
confirm = spyOn(atom.applicationDelegate, 'confirm').andReturn(0)
|
||||
params = {
|
||||
config: atom.config,
|
||||
confirm: confirm,
|
||||
deserializerManager: atom.deserializers
|
||||
applicationDelegate: atom.applicationDelegate
|
||||
}
|
||||
|
||||
describe "serialization", ->
|
||||
|
@ -5,7 +5,7 @@ PaneAxis = require '../src/pane-axis'
|
||||
PaneContainer = require '../src/pane-container'
|
||||
|
||||
describe "Pane", ->
|
||||
[confirm, deserializerDisposable] = []
|
||||
[confirm, showSaveDialog, deserializerDisposable] = []
|
||||
|
||||
class Item
|
||||
@deserialize: ({name, uri}) -> new this(name, uri)
|
||||
@ -20,7 +20,8 @@ describe "Pane", ->
|
||||
isDestroyed: -> @destroyed
|
||||
|
||||
beforeEach ->
|
||||
confirm = jasmine.createSpy('confirm')
|
||||
confirm = spyOn(atom.applicationDelegate, 'confirm')
|
||||
showSaveDialog = spyOn(atom.applicationDelegate, 'showSaveDialog')
|
||||
deserializerDisposable = atom.deserializers.add(Item)
|
||||
|
||||
afterEach ->
|
||||
@ -28,7 +29,7 @@ describe "Pane", ->
|
||||
|
||||
paneParams = (params) ->
|
||||
extend({
|
||||
confirm: confirm,
|
||||
applicationDelegate: atom.applicationDelegate,
|
||||
config: atom.config,
|
||||
deserializerManager: atom.deserializers,
|
||||
notificationManager: atom.notifications
|
||||
@ -48,7 +49,7 @@ describe "Pane", ->
|
||||
[container, pane1, pane2] = []
|
||||
|
||||
beforeEach ->
|
||||
container = new PaneContainer(config: atom.config, confirm: confirm)
|
||||
container = new PaneContainer(config: atom.config, applicationDelegate: atom.applicationDelegate)
|
||||
container.getActivePane().splitRight()
|
||||
[pane1, pane2] = container.getPanes()
|
||||
|
||||
@ -117,7 +118,7 @@ describe "Pane", ->
|
||||
|
||||
it "throws an exception if the item is already present on a pane", ->
|
||||
item = new Item("A")
|
||||
container = new PaneContainer(config: atom.config, confirm: confirm)
|
||||
container = new PaneContainer(config: atom.config, applicationDelegate: atom.applicationDelegate)
|
||||
pane1 = container.getActivePane()
|
||||
pane1.addItem(item)
|
||||
pane2 = pane1.splitRight()
|
||||
@ -281,11 +282,11 @@ describe "Pane", ->
|
||||
it "presents a save-as dialog, then saves the item with the given uri before removing and destroying it", ->
|
||||
itemURI = null
|
||||
|
||||
spyOn(atom, 'showSaveDialogSync').andReturn("/selected/path")
|
||||
showSaveDialog.andReturn("/selected/path")
|
||||
confirm.andReturn(0)
|
||||
pane.destroyItem(item1)
|
||||
|
||||
expect(atom.showSaveDialogSync).toHaveBeenCalled()
|
||||
expect(showSaveDialog).toHaveBeenCalled()
|
||||
expect(item1.saveAs).toHaveBeenCalledWith("/selected/path")
|
||||
expect(item1 in pane.getItems()).toBe false
|
||||
expect(item1.isDestroyed()).toBe true
|
||||
@ -379,7 +380,7 @@ describe "Pane", ->
|
||||
|
||||
beforeEach ->
|
||||
pane = new Pane(paneParams(items: [new Item("A")]))
|
||||
spyOn(atom, 'showSaveDialogSync').andReturn('/selected/path')
|
||||
showSaveDialog.andReturn('/selected/path')
|
||||
|
||||
describe "when the active item has a uri", ->
|
||||
beforeEach ->
|
||||
@ -401,14 +402,14 @@ describe "Pane", ->
|
||||
it "opens a save dialog and saves the current item as the selected path", ->
|
||||
pane.getActiveItem().saveAs = jasmine.createSpy("saveAs")
|
||||
pane.saveActiveItem()
|
||||
expect(atom.showSaveDialogSync).toHaveBeenCalled()
|
||||
expect(showSaveDialog).toHaveBeenCalled()
|
||||
expect(pane.getActiveItem().saveAs).toHaveBeenCalledWith('/selected/path')
|
||||
|
||||
describe "when the current item has no saveAs method", ->
|
||||
it "does nothing", ->
|
||||
expect(pane.getActiveItem().saveAs).toBeUndefined()
|
||||
pane.saveActiveItem()
|
||||
expect(atom.showSaveDialogSync).not.toHaveBeenCalled()
|
||||
expect(showSaveDialog).not.toHaveBeenCalled()
|
||||
|
||||
describe "when the item's saveAs method throws a well-known IO error", ->
|
||||
notificationSpy = null
|
||||
@ -434,21 +435,21 @@ describe "Pane", ->
|
||||
|
||||
beforeEach ->
|
||||
pane = new Pane(paneParams(items: [new Item("A")]))
|
||||
spyOn(atom, 'showSaveDialogSync').andReturn('/selected/path')
|
||||
showSaveDialog.andReturn('/selected/path')
|
||||
|
||||
describe "when the current item has a saveAs method", ->
|
||||
it "opens the save dialog and calls saveAs on the item with the selected path", ->
|
||||
pane.getActiveItem().path = __filename
|
||||
pane.getActiveItem().saveAs = jasmine.createSpy("saveAs")
|
||||
pane.saveActiveItemAs()
|
||||
expect(atom.showSaveDialogSync).toHaveBeenCalledWith(defaultPath: __filename)
|
||||
expect(showSaveDialog).toHaveBeenCalledWith(defaultPath: __filename)
|
||||
expect(pane.getActiveItem().saveAs).toHaveBeenCalledWith('/selected/path')
|
||||
|
||||
describe "when the current item does not have a saveAs method", ->
|
||||
it "does nothing", ->
|
||||
expect(pane.getActiveItem().saveAs).toBeUndefined()
|
||||
pane.saveActiveItemAs()
|
||||
expect(atom.showSaveDialogSync).not.toHaveBeenCalled()
|
||||
expect(showSaveDialog).not.toHaveBeenCalled()
|
||||
|
||||
describe "when the item's saveAs method throws a well-known IO error", ->
|
||||
notificationSpy = null
|
||||
|
1
spec/sample-with-comments.js
Normal file
1
spec/sample-with-comments.js
Normal file
@ -0,0 +1 @@
|
||||
undefined
|
1
spec/sample.js
Normal file
1
spec/sample.js
Normal file
@ -0,0 +1 @@
|
||||
undefined
|
@ -14,8 +14,8 @@ describe "Workspace", ->
|
||||
beforeEach ->
|
||||
workspace = atom.workspace
|
||||
workspace.resetFontSize()
|
||||
spyOn(workspace, "confirm")
|
||||
setDocumentEdited = spyOn(workspace, 'setDocumentEdited')
|
||||
spyOn(atom.applicationDelegate, "confirm")
|
||||
setDocumentEdited = spyOn(atom.applicationDelegate, 'setWindowDocumentEdited')
|
||||
atom.project.setPaths([atom.project.getDirectories()[0]?.resolve('dir')])
|
||||
waits(1)
|
||||
|
||||
@ -31,10 +31,8 @@ describe "Workspace", ->
|
||||
config: atom.config, project: atom.project, packageManager: atom.packages,
|
||||
grammarRegistry: atom.grammars, deserializerManager: atom.deserializers,
|
||||
notificationManager: atom.notifications, clipboard: atom.clipboard,
|
||||
setRepresentedFilename: atom.setRepresentedFilename.bind(atom),
|
||||
setDocumentEdited: atom.setDocumentEdited.bind(atom),
|
||||
applicationDelegate: atom.applicationDelegate,
|
||||
viewRegistry: atom.views, assert: atom.assert.bind(atom),
|
||||
confirm: atom.confirm.bind(atom)
|
||||
})
|
||||
atom.workspace.deserialize(workspaceState, atom.deserializers)
|
||||
|
||||
@ -347,8 +345,8 @@ describe "Workspace", ->
|
||||
describe "when the file is over 20MB", ->
|
||||
it "prompts the user to make sure they want to open a file this big", ->
|
||||
spyOn(fs, 'getSizeSync').andReturn 20 * 1048577 # 20MB
|
||||
workspace.confirm.andCallFake -> selectedButtonIndex
|
||||
atom.workspace.confirm()
|
||||
atom.applicationDelegate.confirm.andCallFake -> selectedButtonIndex
|
||||
atom.applicationDelegate.confirm()
|
||||
selectedButtonIndex = 1 # cancel
|
||||
|
||||
editor = null
|
||||
@ -357,16 +355,16 @@ describe "Workspace", ->
|
||||
|
||||
runs ->
|
||||
expect(editor).toBeUndefined()
|
||||
expect(workspace.confirm).toHaveBeenCalled()
|
||||
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
||||
|
||||
workspace.confirm.reset()
|
||||
atom.applicationDelegate.confirm.reset()
|
||||
selectedButtonIndex = 0 # open the file
|
||||
|
||||
waitsForPromise ->
|
||||
workspace.open('sample.js').then (e) -> editor = e
|
||||
|
||||
runs ->
|
||||
expect(workspace.confirm).toHaveBeenCalled()
|
||||
expect(atom.applicationDelegate.confirm).toHaveBeenCalled()
|
||||
expect(editor.displayBuffer.largeFileMode).toBe true
|
||||
|
||||
describe "when passed a path that matches a custom opener", ->
|
||||
@ -633,9 +631,7 @@ describe "Workspace", ->
|
||||
config: atom.config, project: atom.project, packageManager: atom.packages,
|
||||
notificationManager: atom.notifications, deserializerManager: atom.deserializers,
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views, grammarRegistry: atom.grammars,
|
||||
setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'),
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion(),
|
||||
assert: atom.assert.bind(atom)
|
||||
applicationDelegate: atom.applicationDelegate, assert: atom.assert.bind(atom)
|
||||
})
|
||||
workspace2.deserialize(state, atom.deserializers)
|
||||
expect(jsPackage.loadGrammarsSync.callCount).toBe 1
|
||||
@ -693,9 +689,7 @@ describe "Workspace", ->
|
||||
config: atom.config, project: atom.project, packageManager: atom.packages,
|
||||
notificationManager: atom.notifications, deserializerManager: atom.deserializers,
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views, grammarRegistry: atom.grammars,
|
||||
setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'),
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion(),
|
||||
assert: atom.assert.bind(atom)
|
||||
applicationDelegate: atom.applicationDelegate, assert: atom.assert.bind(atom)
|
||||
})
|
||||
workspace2.deserialize(atom.workspace.serialize(), atom.deserializers)
|
||||
item = atom.workspace.getActivePaneItem()
|
||||
|
@ -175,8 +175,7 @@ class AtomEnvironment extends Model
|
||||
|
||||
@workspace = new Workspace({
|
||||
@config, @project, packageManager: @packages, grammarRegistry: @grammars, deserializerManager: @deserializers,
|
||||
notificationManager: @notifications, setRepresentedFilename: @setRepresentedFilename.bind(this),
|
||||
setDocumentEdited: @setDocumentEdited.bind(this), @clipboard, viewRegistry: @views, assert: @assert.bind(this), confirm: @confirm.bind(this)
|
||||
notificationManager: @notifications, @applicationDelegate, @clipboard, viewRegistry: @views, assert: @assert.bind(this)
|
||||
})
|
||||
@themes.workspace = @workspace
|
||||
|
||||
|
@ -15,12 +15,12 @@ class PaneContainer extends Model
|
||||
constructor: (params) ->
|
||||
super
|
||||
|
||||
{@config, notificationManager, deserializerManager, confirm} = params
|
||||
{@config, applicationDelegate, notificationManager, deserializerManager} = params
|
||||
@emitter = new Emitter
|
||||
@subscriptions = new CompositeDisposable
|
||||
@itemRegistry = new ItemRegistry
|
||||
|
||||
@setRoot(new Pane({container: this, @config, notificationManager, deserializerManager, confirm}))
|
||||
@setRoot(new Pane({container: this, @config, applicationDelegate, notificationManager, deserializerManager}))
|
||||
@setActivePane(@getRoot())
|
||||
@monitorActivePaneItem()
|
||||
@monitorPaneItems()
|
||||
|
@ -14,9 +14,7 @@ class Pane extends Model
|
||||
activeItem: undefined
|
||||
focused: false
|
||||
|
||||
@deserialize: (state, atomEnvironment) ->
|
||||
{deserializers, config, notifications} = atomEnvironment
|
||||
confirm = atomEnvironment.confirm.bind(atomEnvironment)
|
||||
@deserialize: (state, {deserializers, applicationDelegate, config, notifications}) ->
|
||||
{items, activeItemURI, activeItemUri} = state
|
||||
activeItemURI ?= activeItemUri
|
||||
state.items = compact(items.map (itemState) -> deserializers.deserialize(itemState))
|
||||
@ -27,15 +25,14 @@ class Pane extends Model
|
||||
new Pane(extend(state, {
|
||||
deserializerManager: deserializers,
|
||||
notificationManager: notifications,
|
||||
confirm: confirm,
|
||||
config: config
|
||||
config, applicationDelegate
|
||||
}))
|
||||
|
||||
constructor: (params) ->
|
||||
super
|
||||
|
||||
{
|
||||
@activeItem, @focused, @confirm, @notificationManager, @config,
|
||||
@activeItem, @focused, @applicationDelegate, @notificationManager, @config,
|
||||
@deserializerManager
|
||||
} = params
|
||||
|
||||
@ -465,7 +462,7 @@ class Pane extends Model
|
||||
else
|
||||
return true
|
||||
|
||||
chosen = @confirm
|
||||
chosen = @applicationDelegate.confirm
|
||||
message: "'#{item.getTitle?() ? uri}' has changes, do you want to save them?"
|
||||
detailedMessage: "Your changes will be lost if you close this item without saving."
|
||||
buttons: ["Save", "Cancel", "Don't Save"]
|
||||
@ -518,7 +515,7 @@ class Pane extends Model
|
||||
|
||||
saveOptions = item.getSaveDialogOptions?() ? {}
|
||||
saveOptions.defaultPath ?= item.getPath()
|
||||
newItemPath = atom.showSaveDialogSync(saveOptions)
|
||||
newItemPath = @applicationDelegate.showSaveDialog(saveOptions)
|
||||
if newItemPath
|
||||
try
|
||||
item.saveAs(newItemPath)
|
||||
@ -650,7 +647,7 @@ class Pane extends Model
|
||||
@parent.replaceChild(this, new PaneAxis({@container, orientation, children: [this], @flexScale}))
|
||||
@setFlexScale(1)
|
||||
|
||||
newPane = new Pane(extend({@confirm, @deserializerManager, @config}, params))
|
||||
newPane = new Pane(extend({@applicationDelegate, @deserializerManager, @config}, params))
|
||||
switch side
|
||||
when 'before' then @parent.insertChildBefore(this, newPane)
|
||||
when 'after' then @parent.insertChildAfter(this, newPane)
|
||||
|
@ -28,15 +28,15 @@ class Workspace extends Model
|
||||
|
||||
{
|
||||
@packageManager, @config, @project, @grammarRegistry, @notificationManager,
|
||||
@clipboard, @viewRegistry, @grammarRegistry, @setRepresentedFilename,
|
||||
@setDocumentEdited, @assert, @confirm, @deserializerManager
|
||||
@clipboard, @viewRegistry, @grammarRegistry, @applicationDelegate, @assert,
|
||||
@deserializerManager
|
||||
} = params
|
||||
|
||||
@emitter = new Emitter
|
||||
@openers = []
|
||||
@destroyedItemURIs = []
|
||||
|
||||
@paneContainer = new PaneContainer({@config, @confirm, @notificationManager, @deserializerManager})
|
||||
@paneContainer = new PaneContainer({@config, @applicationDelegate, @notificationManager, @deserializerManager})
|
||||
@paneContainer.onDidDestroyPaneItem(@didDestroyPaneItem)
|
||||
|
||||
@defaultDirectorySearcher = new DefaultDirectorySearcher()
|
||||
@ -58,7 +58,7 @@ class Workspace extends Model
|
||||
@paneContainer.destroy()
|
||||
panelContainer.destroy() for panelContainer in @panelContainers
|
||||
|
||||
@paneContainer = new PaneContainer({@config, @confirm, @notificationManager, @deserializerManager})
|
||||
@paneContainer = new PaneContainer({@config, @applicationDelegate, @notificationManager, @deserializerManager})
|
||||
@paneContainer.onDidDestroyPaneItem(@didDestroyPaneItem)
|
||||
|
||||
@panelContainers =
|
||||
@ -163,19 +163,19 @@ class Workspace extends Model
|
||||
|
||||
if item? and projectPath?
|
||||
document.title = "#{itemTitle} - #{projectPath} - #{appName}"
|
||||
@setRepresentedFilename(itemPath ? projectPath)
|
||||
@applicationDelegate.setRepresentedFilename(itemPath ? projectPath)
|
||||
else if projectPath?
|
||||
document.title = "#{projectPath} - #{appName}"
|
||||
@setRepresentedFilename(projectPath)
|
||||
@applicationDelegate.setRepresentedFilename(projectPath)
|
||||
else
|
||||
document.title = "#{itemTitle} - #{appName}"
|
||||
@setRepresentedFilename("")
|
||||
@applicationDelegate.setRepresentedFilename("")
|
||||
|
||||
# On OS X, fades the application window's proxy icon when the current file
|
||||
# has been modified.
|
||||
updateDocumentEdited: =>
|
||||
modified = @getActivePaneItem()?.isModified?() ? false
|
||||
@setDocumentEdited(modified)
|
||||
@applicationDelegate.setWindowDocumentEdited(modified)
|
||||
|
||||
###
|
||||
Section: Event Subscription
|
||||
@ -470,9 +470,6 @@ class Workspace extends Model
|
||||
|
||||
Promise.resolve(item)
|
||||
.then (item) =>
|
||||
if not pane
|
||||
pane = new Pane({items: [item], @config, @confirm})
|
||||
@paneContainer.root = pane
|
||||
@itemOpened(item)
|
||||
pane.activateItem(item) if activateItem
|
||||
pane.activate() if activatePane
|
||||
@ -503,7 +500,7 @@ class Workspace extends Model
|
||||
|
||||
largeFileMode = fileSize >= 2 * 1048576 # 2MB
|
||||
if fileSize >= 20 * 1048576 # 20MB
|
||||
choice = @confirm
|
||||
choice = @applicationDelegate.confirm
|
||||
message: 'Atom will be unresponsive during the loading of very large files.'
|
||||
detailedMessage: "Do you still want to load this file?"
|
||||
buttons: ["Proceed", "Cancel"]
|
||||
@ -521,7 +518,7 @@ class Workspace extends Model
|
||||
buildTextEditor: (params) ->
|
||||
params = _.extend({
|
||||
@config, @notificationManager, @packageManager, @clipboard, @viewRegistry,
|
||||
@grammarRegistry, @project, @assert
|
||||
@grammarRegistry, @project, @assert, @applicationDelegate
|
||||
}, params)
|
||||
new TextEditor(params)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user