diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 2f428dddd..6ab18ccdf 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -2756,7 +2756,7 @@ describe "EditorView", -> editorView = atom.workspaceView.getActiveView() view = $$ -> @div id: 'view', tabindex: -1, 'View' - editorView.getPane().showItem(view) + editorView.getPane().activateItem(view) expect(editorView.isVisible()).toBeFalsy() editorView.setText('hidden changes') @@ -2764,7 +2764,7 @@ describe "EditorView", -> displayUpdatedHandler = jasmine.createSpy("displayUpdatedHandler") editorView.on 'editor:display-updated', displayUpdatedHandler - editorView.getPane().showItem(editorView.getModel()) + editorView.getPane().activateItem(editorView.getModel()) expect(editorView.isVisible()).toBeTruthy() waitsFor -> diff --git a/spec/pane-container-spec.coffee b/spec/pane-container-spec.coffee index b9cb64d7d..5fb759860 100644 --- a/spec/pane-container-spec.coffee +++ b/spec/pane-container-spec.coffee @@ -88,7 +88,7 @@ describe "PaneContainer", -> describe ".saveAll()", -> it "saves all open pane items", -> - pane1.showItem(new TestView('4')) + pane1.activateItem(new TestView('4')) container.saveAll() @@ -167,24 +167,24 @@ describe "PaneContainer", -> describe "when there is one pane", -> it "is triggered when a new pane item is added", -> - pane1.showItem(item1b) + pane1.activateItem(item1b) expect(activeItemChangedHandler.callCount).toBe 1 expect(activeItemChangedHandler.argsForCall[0][1]).toEqual item1b it "is not triggered when the active pane item is shown again", -> - pane1.showItem(item1a) + pane1.activateItem(item1a) expect(activeItemChangedHandler).not.toHaveBeenCalled() it "is triggered when switching to an existing pane item", -> - pane1.showItem(item1b) + pane1.activateItem(item1b) activeItemChangedHandler.reset() - pane1.showItem(item1a) + pane1.activateItem(item1a) expect(activeItemChangedHandler.callCount).toBe 1 expect(activeItemChangedHandler.argsForCall[0][1]).toEqual item1a it "is triggered when the active pane item is destroyed", -> - pane1.showItem(item1b) + pane1.activateItem(item1b) activeItemChangedHandler.reset() pane1.destroyItem(item1b) @@ -192,7 +192,7 @@ describe "PaneContainer", -> expect(activeItemChangedHandler.argsForCall[0][1]).toEqual item1a it "is not triggered when an inactive pane item is destroyed", -> - pane1.showItem(item1b) + pane1.activateItem(item1b) activeItemChangedHandler.reset() pane1.destroyItem(item1a) @@ -216,16 +216,16 @@ describe "PaneContainer", -> activeItemChangedHandler.reset() it "is triggered when a new pane item is added to the active pane", -> - pane2.showItem(item2b) + pane2.activateItem(item2b) expect(activeItemChangedHandler.callCount).toBe 1 expect(activeItemChangedHandler.argsForCall[0][1]).toEqual item2b it "is not triggered when a new pane item is added to an inactive pane", -> - pane1.showItem(item1b) + pane1.activateItem(item1b) expect(activeItemChangedHandler).not.toHaveBeenCalled() it "is triggered when the active pane's active item is destroyed", -> - pane2.showItem(item2b) + pane2.activateItem(item2b) activeItemChangedHandler.reset() pane2.destroyItem(item2b) @@ -233,7 +233,7 @@ describe "PaneContainer", -> expect(activeItemChangedHandler.argsForCall[0][1]).toEqual item2a it "is not triggered when an inactive pane's active item is destroyed", -> - pane1.showItem(item1b) + pane1.activateItem(item1b) activeItemChangedHandler.reset() pane1.destroyItem(item1b) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index c24d10447..d1d031240 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -32,10 +32,10 @@ describe "Pane", -> it "displays the first item in the pane", -> expect(pane.itemViews.find('#view-1')).toExist() - describe "::showItem(item)", -> + describe "::activateItem(item)", -> it "hides all item views except the one being shown and sets the activeItem", -> expect(pane.activeItem).toBe view1 - pane.showItem(view2) + pane.activateItem(view2) expect(view1.css('display')).toBe 'none' expect(view2.css('display')).not.toBe 'none' expect(pane.activeItem).toBe view2 @@ -46,35 +46,35 @@ describe "Pane", -> container.on 'pane:active-item-changed', itemChangedHandler expect(pane.activeItem).toBe view1 - pane.showItem(view2) - pane.showItem(view2) + pane.activateItem(view2) + pane.activateItem(view2) expect(itemChangedHandler.callCount).toBe 1 expect(itemChangedHandler.argsForCall[0][1]).toBe view2 itemChangedHandler.reset() - pane.showItem(editor1) + pane.activateItem(editor1) expect(itemChangedHandler).toHaveBeenCalled() expect(itemChangedHandler.argsForCall[0][1]).toBe editor1 itemChangedHandler.reset() - describe "if the pane's active view is focused before calling showItem", -> + describe "if the pane's active view is focused before calling activateItem", -> it "focuses the new active view", -> container.attachToDom() pane.focus() expect(pane.activeView).not.toBe view2 expect(pane.activeView).toMatchSelector ':focus' - pane.showItem(view2) + pane.activateItem(view2) expect(view2).toMatchSelector ':focus' describe "when the given item isn't yet in the items list on the pane", -> view3 = null beforeEach -> view3 = new TestView(id: 'view-3', text: "View 3") - pane.showItem(editor1) + pane.activateItem(editor1) expect(pane.getActiveItemIndex()).toBe 1 it "adds it to the items list after the active item", -> - pane.showItem(view3) + pane.activateItem(view3) expect(pane.getItems()).toEqual [view1, editor1, view3, view2, editor2] expect(pane.activeItem).toBe view3 expect(pane.getActiveItemIndex()).toBe 2 @@ -83,21 +83,21 @@ describe "Pane", -> events = [] container.on 'pane:item-added', (e, item, index) -> events.push(['pane:item-added', item, index]) container.on 'pane:active-item-changed', (e, item) -> events.push(['pane:active-item-changed', item]) - pane.showItem(view3) + pane.activateItem(view3) expect(events).toEqual [['pane:item-added', view3, 2], ['pane:active-item-changed', view3]] describe "when showing a model item", -> describe "when no view has yet been appended for that item", -> it "appends and shows a view to display the item based on its `.getViewClass` method", -> - pane.showItem(editor1) + pane.activateItem(editor1) editorView = pane.activeView expect(editorView.css('display')).not.toBe 'none' expect(editorView.editor).toBe editor1 describe "when a valid view has already been appended for another item", -> it "multiple views are created for multiple items", -> - pane.showItem(editor1) - pane.showItem(editor2) + pane.activateItem(editor1) + pane.activateItem(editor2) expect(pane.itemViews.find('.editor').length).toBe 2 editorView = pane.activeView expect(editorView.css('display')).not.toBe 'none' @@ -118,11 +118,11 @@ describe "Pane", -> serialize: -> {@id, @text} getViewClass: -> TestView - pane.showItem(model1) - pane.showItem(model2) + pane.activateItem(model1) + pane.activateItem(model2) expect(pane.itemViews.find('.test-view').length).toBe initialViewCount + 2 - pane.showPreviousItem() + pane.activatePreviousItem() expect(pane.itemViews.find('.test-view').length).toBe initialViewCount + 2 pane.destroyItem(model2) @@ -134,7 +134,7 @@ describe "Pane", -> describe "when showing a view item", -> it "appends it to the itemViews div if it hasn't already been appended and shows it", -> expect(pane.itemViews.find('#view-2')).not.toExist() - pane.showItem(view2) + pane.activateItem(view2) expect(pane.itemViews.find('#view-2')).toExist() expect(pane.activeView).toBe view2 @@ -206,7 +206,7 @@ describe "Pane", -> expect(pane.getItems()).toEqual [editor1, view2, editor2] expect(pane.activeItem).toBe editor1 - pane.showItem(editor2) + pane.activateItem(editor2) pane.destroyItem(editor2) expect(pane.getItems()).toEqual [editor1, view2] expect(pane.activeItem).toBe editor1 @@ -241,8 +241,8 @@ describe "Pane", -> describe "when the item is a model", -> it "removes the associated view only when all items that require it have been removed", -> - pane.showItem(editor1) - pane.showItem(editor2) + pane.activateItem(editor1) + pane.activateItem(editor2) pane.destroyItem(editor2) expect(pane.itemViews.find('.editor')).toExist() pane.destroyItem(editor1) @@ -300,12 +300,12 @@ describe "Pane", -> it "preserves data by detaching instead of removing", -> view1.data('preservative', 1234) pane.moveItemToPane(view1, pane2, 1) - pane2.showItemAtIndex(1) + pane2.activateItemAtIndex(1) expect(pane2.activeView.data('preservative')).toBe 1234 describe "pane:close", -> it "destroys all items and removes the pane", -> - pane.showItem(editor1) + pane.activateItem(editor1) pane.trigger 'pane:close' expect(pane.hasParent()).toBeFalsy() expect(editor2.isDestroyed()).toBe true @@ -313,7 +313,7 @@ describe "Pane", -> describe "pane:close-other-items", -> it "destroys all items except the current", -> - pane.showItem(editor1) + pane.activateItem(editor1) pane.trigger 'pane:close-other-items' expect(editor2.isDestroyed()).toBe true expect(pane.getItems()).toEqual [editor1] @@ -323,7 +323,7 @@ describe "Pane", -> describe "when the current item has a save method", -> it "saves the current item", -> spyOn(editor2, 'save') - pane.showItem(editor2) + pane.activateItem(editor2) pane.saveActiveItem() expect(editor2.save).toHaveBeenCalled() @@ -341,7 +341,7 @@ describe "Pane", -> it "opens a save dialog and saves the current item as the selected path", -> newEditor = atom.project.openSync() spyOn(newEditor, 'saveAs') - pane.showItem(newEditor) + pane.activateItem(newEditor) pane.saveActiveItem() @@ -361,7 +361,7 @@ describe "Pane", -> describe "when the current item has a saveAs method", -> it "opens the save dialog and calls saveAs on the item with the selected path", -> spyOn(editor2, 'saveAs') - pane.showItem(editor2) + pane.activateItem(editor2) pane.saveActiveItemAs() @@ -409,7 +409,7 @@ describe "Pane", -> expect(activeItemTitleChangedHandler).toHaveBeenCalled() activeItemTitleChangedHandler.reset() - pane.showItem(view2) + pane.activateItem(view2) view2.trigger 'title-changed' expect(activeItemTitleChangedHandler).toHaveBeenCalled() @@ -417,7 +417,7 @@ describe "Pane", -> it "removes the pane item", -> filePath = temp.openSync('atom').path editor = atom.project.openSync(filePath) - pane.showItem(editor) + pane.activateItem(editor) expect(pane.items).toHaveLength(5) fs.removeSync(filePath) @@ -441,7 +441,7 @@ describe "Pane", -> [paneToLeft, paneToRight] = [] beforeEach -> - pane.showItem(editor1) + pane.activateItem(editor1) paneToLeft = pane.splitLeft(pane.copyActiveItem()) paneToRight = pane.splitRight(pane.copyActiveItem()) container.attachToDom() @@ -485,7 +485,7 @@ describe "Pane", -> describe "::getNextPane()", -> it "returns the next pane if one exists, wrapping around from the last pane to the first", -> - pane.showItem(editor1) + pane.activateItem(editor1) expect(pane.getNextPane()).toBeUndefined pane2 = pane.splitRight(pane.copyActiveItem()) expect(pane.getNextPane()).toBe pane2 @@ -531,7 +531,7 @@ describe "Pane", -> [pane1, view3, view4] = [] beforeEach -> pane1 = pane - pane.showItem(editor1) + pane.activateItem(editor1) view3 = new TestView(id: 'view-3', text: 'View 3') view4 = new TestView(id: 'view-4', text: 'View 4') @@ -606,7 +606,7 @@ describe "Pane", -> expect(newPane.getItems()).toEqual [view1, editor1, view2, editor2] it "restores the active item on deserialization", -> - pane.showItem(editor2) + pane.activateItem(editor2) newPane = pane.testSerialization() expect(newPane.activeItem).toEqual editor2 @@ -616,7 +616,7 @@ describe "Pane", -> class Unserializable getViewClass: -> TestView - pane.showItem(new Unserializable) + pane.activateItem(new Unserializable) newPane = pane.testSerialization() expect(newPane.activeItem).toEqual pane.items[0] diff --git a/spec/workspace-view-spec.coffee b/spec/workspace-view-spec.coffee index 51625a590..a47854dae 100644 --- a/spec/workspace-view-spec.coffee +++ b/spec/workspace-view-spec.coffee @@ -48,10 +48,10 @@ describe "WorkspaceView", -> pane2 = pane1.splitRight() pane3 = pane2.splitRight() pane4 = pane2.splitDown() - pane2.showItem(atom.project.openSync('b')) - pane3.showItem(atom.project.openSync('../sample.js')) + pane2.activateItem(atom.project.openSync('b')) + pane3.activateItem(atom.project.openSync('../sample.js')) pane3.activeItem.setCursorScreenPosition([2, 4]) - pane4.showItem(atom.project.openSync('../sample.txt')) + pane4.activateItem(atom.project.openSync('../sample.txt')) pane4.activeItem.setCursorScreenPosition([0, 2]) pane2.focus() @@ -570,7 +570,7 @@ describe "WorkspaceView", -> it "saves active editor until there are none", -> editor = atom.project.openSync('../sample.txt') spyOn(editor, 'save') - atom.workspaceView.getActivePane().showItem(editor) + atom.workspaceView.getActivePane().activateItem(editor) atom.workspaceView.trigger('core:save') expect(editor.save).toHaveBeenCalled() @@ -581,6 +581,6 @@ describe "WorkspaceView", -> it "saves active editor until there are none", -> editor = atom.project.openSync('../sample.txt') spyOn(editor, 'saveAs') - atom.workspaceView.getActivePane().showItem(editor) + atom.workspaceView.getActivePane().activateItem(editor) atom.workspaceView.trigger('core:save-as') expect(editor.saveAs).toHaveBeenCalled() diff --git a/src/pane-model.coffee b/src/pane-model.coffee index 15db07345..66b231f85 100644 --- a/src/pane-model.coffee +++ b/src/pane-model.coffee @@ -90,31 +90,31 @@ class PaneModel extends Model @items[index] # Public: Makes the next item active. - showNextItem: -> + activateNextItem: -> index = @getActiveItemIndex() if index < @items.length - 1 - @showItemAtIndex(index + 1) + @activateItemAtIndex(index + 1) else - @showItemAtIndex(0) + @activateItemAtIndex(0) # Public: Makes the previous item active. - showPreviousItem: -> + activatePreviousItem: -> index = @getActiveItemIndex() if index > 0 - @showItemAtIndex(index - 1) + @activateItemAtIndex(index - 1) else - @showItemAtIndex(@items.length - 1) + @activateItemAtIndex(@items.length - 1) # Public: Returns the index of the current active item. getActiveItemIndex: -> @items.indexOf(@activeItem) # Public: Makes the item at the given index active. - showItemAtIndex: (index) -> - @showItem(@itemAtIndex(index)) + activateItemAtIndex: (index) -> + @activateItem(@itemAtIndex(index)) # Public: Makes the given item active, adding the item if necessary. - showItem: (item) -> + activateItem: (item) -> if item? @addItem(item) @activeItem = item @@ -139,7 +139,7 @@ class PaneModel extends Model removeItem: (item, destroying) -> index = @items.indexOf(item) return if index is -1 - @showNextItem() if item is @activeItem and @items.length > 1 + @activateNextItem() if item is @activeItem and @items.length > 1 @items.splice(index, 1) @emit 'item-removed', item, index, destroying @destroy() if @items.length is 0 @@ -246,9 +246,9 @@ class PaneModel extends Model # Public: Activates the first item that matches the given URI. Returns a # boolean indicating whether a matching item was found. - showItemForUri: (uri) -> + activateItemForUri: (uri) -> if item = @itemForUri(uri) - @showItem(item) + @activateItem(item) true else false diff --git a/src/pane.coffee b/src/pane.coffee index b52329127..0385bcf23 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -25,11 +25,11 @@ class Pane extends View @div class: 'item-views', outlet: 'itemViews' @delegatesProperties 'items', 'activeItem', toProperty: 'model' - @delegatesMethods 'getItems', 'showNextItem', 'showPreviousItem', 'getActiveItemIndex', - 'showItemAtIndex', 'showItem', 'addItem', 'itemAtIndex', 'moveItem', 'moveItemToPane', + @delegatesMethods 'getItems', 'activateNextItem', 'activatePreviousItem', 'getActiveItemIndex', + 'activateItemAtIndex', 'activateItem', 'addItem', 'itemAtIndex', 'moveItem', 'moveItemToPane', 'destroyItem', 'destroyItems', 'destroyActiveItem', 'destroyInactiveItems', 'saveActiveItem', 'saveActiveItemAs', 'saveItem', 'saveItemAs', 'saveItems', - 'itemForUri', 'showItemForUri', 'promptToSaveItem', 'copyActiveItem', 'isActive', + 'itemForUri', 'activateItemForUri', 'promptToSaveItem', 'copyActiveItem', 'isActive', 'activate', toProperty: 'model' previousActiveItem: null @@ -65,18 +65,18 @@ class Pane extends View false @command 'pane:save-items', => @saveItems() - @command 'pane:show-next-item', => @showNextItem() - @command 'pane:show-previous-item', => @showPreviousItem() + @command 'pane:show-next-item', => @activateNextItem() + @command 'pane:show-previous-item', => @activatePreviousItem() - @command 'pane:show-item-1', => @showItemAtIndex(0) - @command 'pane:show-item-2', => @showItemAtIndex(1) - @command 'pane:show-item-3', => @showItemAtIndex(2) - @command 'pane:show-item-4', => @showItemAtIndex(3) - @command 'pane:show-item-5', => @showItemAtIndex(4) - @command 'pane:show-item-6', => @showItemAtIndex(5) - @command 'pane:show-item-7', => @showItemAtIndex(6) - @command 'pane:show-item-8', => @showItemAtIndex(7) - @command 'pane:show-item-9', => @showItemAtIndex(8) + @command 'pane:show-item-1', => @activateItemAtIndex(0) + @command 'pane:show-item-2', => @activateItemAtIndex(1) + @command 'pane:show-item-3', => @activateItemAtIndex(2) + @command 'pane:show-item-4', => @activateItemAtIndex(3) + @command 'pane:show-item-5', => @activateItemAtIndex(4) + @command 'pane:show-item-6', => @activateItemAtIndex(5) + @command 'pane:show-item-7', => @activateItemAtIndex(6) + @command 'pane:show-item-8', => @activateItemAtIndex(7) + @command 'pane:show-item-9', => @activateItemAtIndex(8) @command 'pane:split-left', => @splitLeft(@copyActiveItem()) @command 'pane:split-right', => @splitRight(@copyActiveItem()) @@ -92,6 +92,21 @@ class Pane extends View serializeParams: -> model: @model.serialize() + # Deprecated: Use ::activateItem + showItem: (item) -> @activateItem(item) + + # Deprecated: Use ::activateItemForUri + showItemForUri: (item) -> @activateItemForUri(item) + + # Deprecated: Use ::activateItemAtIndex + showItemAtIndex: (index) -> @activateItemAtIndex(index) + + # Deprecated: Use ::activateNextItem + showNextItem: -> @activateNextItem() + + # Deprecated: Use ::activatePreviousItem + showPreviousItem: -> @activatePreviousItem() + # Private: afterAttach: (onDom) -> @focus() if @model.focused and onDom diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index daac10423..cd5075784 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -172,7 +172,7 @@ class WorkspaceView extends View @panes.setRoot(activePane) @itemOpened(editor) - activePane.showItem(editor) + activePane.activateItem(editor) activePane.activate() if changeFocus @trigger "uri-opened" editor @@ -200,7 +200,7 @@ class WorkspaceView extends View else if split == 'left' pane = @getPanes()[0] - pane.showItem(paneItem) + pane.activateItem(paneItem) else paneItem = atom.project.openSync(uri, {initialLine}) pane = new Pane(paneItem) @@ -218,7 +218,7 @@ class WorkspaceView extends View if pane paneItem = pane.itemForUri(uri) - pane.showItem(paneItem) + pane.activateItem(paneItem) pane.activate() if changeFocus paneItem else