mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge branch 'master' into ns-switch-to-display-layers
# Conflicts: # src/text-editor.coffee
This commit is contained in:
@@ -244,11 +244,14 @@ class CommandRegistry
|
||||
(@selectorBasedListenersByCommandName[event.type] ? [])
|
||||
.filter (listener) -> currentTarget.webkitMatchesSelector(listener.selector)
|
||||
.sort (a, b) -> a.compare(b)
|
||||
listeners = listeners.concat(selectorBasedListeners)
|
||||
listeners = selectorBasedListeners.concat(listeners)
|
||||
|
||||
matched = true if listeners.length > 0
|
||||
|
||||
for listener in listeners
|
||||
# Call inline listeners first in reverse registration order,
|
||||
# and selector-based listeners by specificity and reverse
|
||||
# registration order.
|
||||
for listener in listeners by -1
|
||||
break if immediatePropagationStopped
|
||||
listener.callback.call(currentTarget, dispatchedEvent)
|
||||
|
||||
@@ -271,8 +274,8 @@ class SelectorBasedListener
|
||||
@sequenceNumber = SequenceCount++
|
||||
|
||||
compare: (other) ->
|
||||
other.specificity - @specificity or
|
||||
other.sequenceNumber - @sequenceNumber
|
||||
@specificity - other.specificity or
|
||||
@sequenceNumber - other.sequenceNumber
|
||||
|
||||
class InlineListener
|
||||
constructor: (@callback) ->
|
||||
|
||||
@@ -577,15 +577,23 @@ class Pane extends Model
|
||||
else
|
||||
return true
|
||||
|
||||
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"]
|
||||
saveDialog = (saveButtonText, saveFn, message) =>
|
||||
chosen = @applicationDelegate.confirm
|
||||
message: message
|
||||
detailedMessage: "Your changes will be lost if you close this item without saving."
|
||||
buttons: [saveButtonText, "Cancel", "Don't save"]
|
||||
switch chosen
|
||||
when 0 then saveFn(item, saveError)
|
||||
when 1 then false
|
||||
when 2 then true
|
||||
|
||||
switch chosen
|
||||
when 0 then @saveItem(item, -> true)
|
||||
when 1 then false
|
||||
when 2 then true
|
||||
saveError = (error) =>
|
||||
if error
|
||||
saveDialog("Save as", @saveItemAs, "'#{item.getTitle?() ? uri}' could not be saved.\nError: #{@getMessageForErrorCode(error.code)}")
|
||||
else
|
||||
true
|
||||
|
||||
saveDialog("Save", @saveItem, "'#{item.getTitle?() ? uri}' has changes, do you want to save them?")
|
||||
|
||||
# Public: Save the active item.
|
||||
saveActiveItem: (nextAction) ->
|
||||
@@ -602,9 +610,11 @@ class Pane extends Model
|
||||
# Public: Save the given item.
|
||||
#
|
||||
# * `item` The item to save.
|
||||
# * `nextAction` (optional) {Function} which will be called after the item is
|
||||
# successfully saved.
|
||||
saveItem: (item, nextAction) ->
|
||||
# * `nextAction` (optional) {Function} which will be called with no argument
|
||||
# after the item is successfully saved, or with the error if it failed.
|
||||
# The return value will be that of `nextAction` or `undefined` if it was not
|
||||
# provided
|
||||
saveItem: (item, nextAction) =>
|
||||
if typeof item?.getURI is 'function'
|
||||
itemURI = item.getURI()
|
||||
else if typeof item?.getUri is 'function'
|
||||
@@ -613,9 +623,12 @@ class Pane extends Model
|
||||
if itemURI?
|
||||
try
|
||||
item.save?()
|
||||
nextAction?()
|
||||
catch error
|
||||
@handleSaveError(error, item)
|
||||
nextAction?()
|
||||
if nextAction
|
||||
nextAction(error)
|
||||
else
|
||||
@handleSaveError(error, item)
|
||||
else
|
||||
@saveItemAs(item, nextAction)
|
||||
|
||||
@@ -623,9 +636,11 @@ class Pane extends Model
|
||||
# path they select.
|
||||
#
|
||||
# * `item` The item to save.
|
||||
# * `nextAction` (optional) {Function} which will be called after the item is
|
||||
# successfully saved.
|
||||
saveItemAs: (item, nextAction) ->
|
||||
# * `nextAction` (optional) {Function} which will be called with no argument
|
||||
# after the item is successfully saved, or with the error if it failed.
|
||||
# The return value will be that of `nextAction` or `undefined` if it was not
|
||||
# provided
|
||||
saveItemAs: (item, nextAction) =>
|
||||
return unless item?.saveAs?
|
||||
|
||||
saveOptions = item.getSaveDialogOptions?() ? {}
|
||||
@@ -634,9 +649,12 @@ class Pane extends Model
|
||||
if newItemPath
|
||||
try
|
||||
item.saveAs(newItemPath)
|
||||
nextAction?()
|
||||
catch error
|
||||
@handleSaveError(error, item)
|
||||
nextAction?()
|
||||
if nextAction
|
||||
nextAction(error)
|
||||
else
|
||||
@handleSaveError(error, item)
|
||||
|
||||
# Public: Save all items.
|
||||
saveItems: ->
|
||||
|
||||
@@ -26,8 +26,20 @@ class TextEditorRegistry
|
||||
# editor is destroyed.
|
||||
add: (editor) ->
|
||||
@editors.add(editor)
|
||||
editor.registered = true
|
||||
|
||||
@emitter.emit 'did-add-editor', editor
|
||||
new Disposable => @editors.delete(editor)
|
||||
new Disposable => @remove(editor)
|
||||
|
||||
# Remove a `TextEditor`.
|
||||
#
|
||||
# * `editor` The editor to remove.
|
||||
#
|
||||
# Returns a {Boolean} indicating whether the editor was successfully removed.
|
||||
remove: (editor) ->
|
||||
removed = @editors.delete(editor)
|
||||
editor.registered = false
|
||||
removed
|
||||
|
||||
# Invoke the given callback with all the current and future registered
|
||||
# `TextEditors`.
|
||||
|
||||
@@ -76,6 +76,7 @@ class TextEditor extends Model
|
||||
defaultCharWidth: null
|
||||
height: null
|
||||
width: null
|
||||
registered: false
|
||||
|
||||
Object.defineProperty @prototype, "element",
|
||||
get: -> @getElement()
|
||||
@@ -202,7 +203,7 @@ class TextEditor extends Model
|
||||
tokenizedBuffer: tokenizedBufferState
|
||||
largeFileMode: @largeFileMode
|
||||
displayLayerId: @displayLayer.id
|
||||
registered: atom.textEditors.editors.has this
|
||||
registered: @registered
|
||||
|
||||
subscribeToBuffer: ->
|
||||
@buffer.retain()
|
||||
|
||||
@@ -1092,7 +1092,7 @@ class Workspace extends Model
|
||||
if editor.getPath()
|
||||
checkoutHead = =>
|
||||
@project.repositoryForDirectory(new Directory(editor.getDirectoryPath()))
|
||||
.then (repository) =>
|
||||
.then (repository) ->
|
||||
repository?.async.checkoutHeadForEditor(editor)
|
||||
|
||||
if @config.get('editor.confirmCheckoutHeadRevision')
|
||||
|
||||
Reference in New Issue
Block a user