Remove unmodified editors from pane when the buffer is deleted

This commit is contained in:
probablycorey
2013-12-10 17:08:07 -08:00
parent 201717a9aa
commit 4bfcdf4d5b
4 changed files with 27 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
PaneContainer = require '../src/pane-container'
Pane = require '../src/pane'
{$, View} = require 'atom'
{fs, $, View} = require 'atom'
path = require 'path'
temp = require 'temp'
@@ -347,14 +347,14 @@ describe "Pane", ->
describe "when the current item has a saveAs method", ->
it "opens a save dialog and saves the current item as the selected path", ->
spyOn(editor2, 'saveAs')
editor2.buffer.setPath(undefined)
pane.showItem(editor2)
newEditor = atom.project.openSync()
spyOn(newEditor, 'saveAs')
pane.showItem(newEditor)
pane.trigger 'core:save'
expect(atom.showSaveDialogSync).toHaveBeenCalled()
expect(editor2.saveAs).toHaveBeenCalledWith('/selected/path')
expect(newEditor.saveAs).toHaveBeenCalledWith('/selected/path')
describe "when the current item has no saveAs method", ->
it "does nothing", ->
@@ -421,6 +421,17 @@ describe "Pane", ->
view2.trigger 'title-changed'
expect(activeItemTitleChangedHandler).toHaveBeenCalled()
describe "when an unmodifed buffer's path is deleted its pane item is removed", ->
it "removes the pane item", ->
filePath = temp.openSync('atom').path
editor = atom.project.openSync(filePath)
pane.showItem(editor)
expect(pane.items).toHaveLength(5)
fs.removeSync(filePath)
waitsFor ->
pane.items.length == 4
describe ".remove()", ->
it "destroys all the pane's items", ->
pane.remove()

View File

@@ -121,6 +121,7 @@ class Editor
@subscribe @buffer, "contents-modified", => @emit "contents-modified"
@subscribe @buffer, "contents-conflicted", => @emit "contents-conflicted"
@subscribe @buffer, "modified-status-changed", => @emit "modified-status-changed"
@subscribe @buffer, "destroyed", => @destroy()
@preserveCursorPositionOnBufferReload()
# Private:

View File

@@ -189,6 +189,8 @@ class Pane extends View
@items.splice(index, 0, item)
@getContainer()?.itemAdded(item)
@trigger 'pane:item-added', [item, index]
if item.on
@subscribe item, 'destroyed', => @destroyItem(item)
item
# Public: Remove the currently active item.
@@ -198,11 +200,11 @@ class Pane extends View
# Public: Remove the specified item.
destroyItem: (item) ->
@unsubscribe(item) if item.off
@trigger 'pane:before-item-destroyed', [item]
container = @getContainer()
if @promptToSaveItem(item)
container.itemDestroyed(item)
@getContainer()?.itemDestroyed(item)
@removeItem(item)
item.destroy?()
true

View File

@@ -116,8 +116,12 @@ class TextBuffer extends telepath.Model
@reload()
@file.on "removed", =>
@wasModifiedBeforeRemove = @getText() != @cachedDiskContents
@updateCachedDiskContents()
modified = @getText() != @cachedDiskContents
@wasModifiedBeforeRemove = modified
if modified
@updateCachedDiskContents()
else
@destroy()
@file.on "moved", =>
@emit "path-changed", this