diff --git a/spec/pane-container-spec.coffee b/spec/pane-container-spec.coffee index be57f2228..b518798da 100644 --- a/spec/pane-container-spec.coffee +++ b/spec/pane-container-spec.coffee @@ -129,7 +129,7 @@ describe "PaneContainer", -> beforeEach -> class TestItem shouldPromptToSave: -> true - getUri: -> 'test' + getURI: -> 'test' container = new PaneContainer container.getRoot().splitRight() diff --git a/spec/pane-container-view-spec.coffee b/spec/pane-container-view-spec.coffee index f255ab697..6c088c343 100644 --- a/spec/pane-container-view-spec.coffee +++ b/spec/pane-container-view-spec.coffee @@ -16,7 +16,7 @@ describe "PaneContainerView", -> @content: -> @div tabindex: -1 initialize: (@name) -> @text(@name) serialize: -> { deserializer: 'TestView', @name } - getUri: -> path.join(temp.dir, @name) + getURI: -> path.join(temp.dir, @name) save: -> @saved = true isEqual: (other) -> @name is other?.name onDidChangeTitle: -> new Disposable(->) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 87ae5cb27..3477acc52 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -9,7 +9,7 @@ describe "Pane", -> class Item extends Model @deserialize: ({name, uri}) -> new this(name, uri) constructor: (@name, @uri) -> - getUri: -> @uri + getURI: -> @uri getPath: -> @path serialize: -> {deserializer: 'Item', @name, @uri} isEqual: (other) -> @name is other?.name @@ -231,18 +231,18 @@ describe "Pane", -> expect(pane.getActiveItem()).toBe item1 describe "if the item is modified", -> - itemUri = null + itemURI = null beforeEach -> item1.shouldPromptToSave = -> true item1.save = jasmine.createSpy("save") item1.saveAs = jasmine.createSpy("saveAs") - item1.getUri = -> itemUri + item1.getURI = -> itemURI describe "if the [Save] option is selected", -> describe "when the item has a uri", -> it "saves the item before destroying it", -> - itemUri = "test" + itemURI = "test" spyOn(atom, 'confirm').andReturn(0) pane.destroyItem(item1) @@ -252,7 +252,7 @@ describe "Pane", -> describe "when the item has no uri", -> it "presents a save-as dialog, then saves the item with the given uri before removing and destroying it", -> - itemUri = null + itemURI = null spyOn(atom, 'showSaveDialogSync').andReturn("/selected/path") spyOn(atom, 'confirm').andReturn(0) @@ -404,15 +404,15 @@ describe "Pane", -> pane.saveActiveItemAs() expect(atom.showSaveDialogSync).not.toHaveBeenCalled() - describe "::itemForUri(uri)", -> - it "returns the item for which a call to .getUri() returns the given uri", -> + describe "::itemForURI(uri)", -> + it "returns the item for which a call to .getURI() returns the given uri", -> pane = new Pane(items: [new Item("A"), new Item("B"), new Item("C"), new Item("D")]) [item1, item2, item3] = pane.getItems() item1.uri = "a" item2.uri = "b" - expect(pane.itemForUri("a")).toBe item1 - expect(pane.itemForUri("b")).toBe item2 - expect(pane.itemForUri("bogus")).toBeUndefined() + expect(pane.itemForURI("a")).toBe item1 + expect(pane.itemForURI("b")).toBe item2 + expect(pane.itemForURI("bogus")).toBeUndefined() describe "::moveItem(item, index)", -> [pane, item1, item2, item3, item4] = [] @@ -589,7 +589,7 @@ describe "Pane", -> [item1, item2] = pane.getItems() item1.shouldPromptToSave = -> true - item1.getUri = -> "/test/path" + item1.getURI = -> "/test/path" item1.save = jasmine.createSpy("save") spyOn(atom, 'confirm').andReturn(0) @@ -604,7 +604,7 @@ describe "Pane", -> [item1, item2] = pane.getItems() item1.shouldPromptToSave = -> true - item1.getUri = -> "/test/path" + item1.getURI = -> "/test/path" item1.save = jasmine.createSpy("save") spyOn(atom, 'confirm').andReturn(1) diff --git a/spec/pane-view-spec.coffee b/spec/pane-view-spec.coffee index 428ffe114..763cc9ab4 100644 --- a/spec/pane-view-spec.coffee +++ b/spec/pane-view-spec.coffee @@ -15,7 +15,7 @@ describe "PaneView", -> initialize: ({@id, @text}) -> @emitter = new Emitter serialize: -> { deserializer: 'TestView', @id, @text } - getUri: -> @id + getURI: -> @id isEqual: (other) -> other? and @id == other.id and @text == other.text changeTitle: -> @emitter.emit 'did-change-title', 'title' diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index e520300d9..527c06971 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -96,7 +96,7 @@ describe "Workspace", -> workspace.open('a').then (o) -> editor = o runs -> - expect(editor.getUri()).toBe atom.project.getDirectories()[0]?.resolve('a') + expect(editor.getURI()).toBe atom.project.getDirectories()[0]?.resolve('a') expect(workspace.getActivePaneItem()).toBe editor expect(workspace.getActivePane().items).toEqual [editor] expect(workspace.getActivePane().activate).toHaveBeenCalled() @@ -261,21 +261,21 @@ describe "Workspace", -> runs -> # does not reopen items with no uri - expect(workspace.getActivePaneItem().getUri()).toBeUndefined() + expect(workspace.getActivePaneItem().getURI()).toBeUndefined() pane.destroyActiveItem() waitsForPromise -> workspace.reopenItem() runs -> - expect(workspace.getActivePaneItem().getUri()).not.toBeUndefined() + expect(workspace.getActivePaneItem().getURI()).not.toBeUndefined() # destroy all items - expect(workspace.getActivePaneItem().getUri()).toBe atom.project.getDirectories()[0]?.resolve('file1') + expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('file1') pane.destroyActiveItem() - expect(workspace.getActivePaneItem().getUri()).toBe atom.project.getDirectories()[0]?.resolve('b') + expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('b') pane.destroyActiveItem() - expect(workspace.getActivePaneItem().getUri()).toBe atom.project.getDirectories()[0]?.resolve('a') + expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('a') pane.destroyActiveItem() # reopens items with uris @@ -285,20 +285,20 @@ describe "Workspace", -> workspace.reopenItem() runs -> - expect(workspace.getActivePaneItem().getUri()).toBe atom.project.getDirectories()[0]?.resolve('a') + expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('a') # does not reopen items that are already open waitsForPromise -> workspace.open('b') runs -> - expect(workspace.getActivePaneItem().getUri()).toBe atom.project.getDirectories()[0]?.resolve('b') + expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('b') waitsForPromise -> workspace.reopenItem() runs -> - expect(workspace.getActivePaneItem().getUri()).toBe atom.project.getDirectories()[0]?.resolve('file1') + expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('file1') describe "::increase/decreaseFontSize()", -> it "increases/decreases the font size without going below 1", -> diff --git a/src/git-repository.coffee b/src/git-repository.coffee index 463fe279f..e0b0c46a2 100644 --- a/src/git-repository.coffee +++ b/src/git-repository.coffee @@ -232,7 +232,10 @@ class GitRepository # # * `path` (optional) {String} path in the repository to get this information # for, only needed if the repository has submodules. - getOriginUrl: (path) -> @getConfigValue('remote.origin.url', path) + getOriginURL: (path) -> @getConfigValue('remote.origin.url', path) + getOriginUrl: (path) -> + deprecate("Use ::getOriginURL instead.") + @getOriginUrl() # Public: Returns the upstream branch for the current HEAD, or null if there # is no upstream branch for the current HEAD. diff --git a/src/pane-container-view.coffee b/src/pane-container-view.coffee index 8fac99f42..d92e99299 100644 --- a/src/pane-container-view.coffee +++ b/src/pane-container-view.coffee @@ -64,7 +64,7 @@ class PaneContainerView extends View @getActivePaneView()?.activeView paneForUri: (uri) -> - atom.views.getView(@model.paneForUri(uri)).__spacePenView + atom.views.getView(@model.paneForURI(uri)).__spacePenView focusNextPaneView: -> @model.activateNextPane() diff --git a/src/pane-container.coffee b/src/pane-container.coffee index 6588d88e5..bcda87bbc 100644 --- a/src/pane-container.coffee +++ b/src/pane-container.coffee @@ -143,8 +143,8 @@ class PaneContainer extends Model getActivePaneItem: -> @getActivePane().getActiveItem() - paneForUri: (uri) -> - find @getPanes(), (pane) -> pane.itemForUri(uri)? + paneForURI: (uri) -> + find @getPanes(), (pane) -> pane.itemForURI(uri)? paneForItem: (item) -> @getPanes().find (pane) -> item in pane.getItems() diff --git a/src/pane.coffee b/src/pane.coffee index 290567a34..9cfe9a824 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -43,14 +43,15 @@ class Pane extends Model serializeParams: -> id: @id items: compact(@items.map((item) -> item.serialize?())) - activeItemUri: @activeItem?.getUri?() + activeItemURI: @activeItem?.getURI?() ? @activeItem?.getUri?() focused: @focused # Called by the Serializable mixin during deserialization. deserializeParams: (params) -> - {items, activeItemUri} = params + {items, activeItemURI, activeItemUri} = params + activeItemURI ?= activeItemUri params.items = compact(items.map (itemState) -> atom.deserializers.deserialize(itemState)) - params.activeItem = find params.items, (item) -> item.getUri?() is activeItemUri + params.activeItem = find params.items, (item) -> (item.getURI?() ? item.getUri?()) is activeItemURI params getParent: -> @parent @@ -426,10 +427,13 @@ class Pane extends Model @destroyItem(item) for item in @getItems() when item isnt @activeItem promptToSaveItem: (item) -> - return true unless typeof item.getUri is 'function' and item.shouldPromptToSave?() + if typeof item.getUri is 'function' and typeof item.getURI isnt 'function' + Grim.deprecate("Implement `::getURI` on pane items instead of `::getUri`") + + return true unless (typeof item.getURI is 'function' or typeof item.getUri is 'function') and item.shouldPromptToSave?() chosen = atom.confirm - message: "'#{item.getTitle?() ? item.getUri()}' has changes, do you want to save them?" + message: "'#{item.getTitle?() ? item.getURI?() ? item.getUri?()}' 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"] @@ -456,7 +460,7 @@ class Pane extends Model # * `nextAction` (optional) {Function} which will be called after the item is # successfully saved. saveItem: (item, nextAction) -> - if item?.getUri?() + if (item?.getURI?() ? item?.getUri?()) item.save?() nextAction?() else @@ -485,19 +489,27 @@ class Pane extends Model # none exists. # # * `uri` {String} containing a URI. + itemForURI: (uri) -> + find @items, (item) -> item.getURI?() is uri or item.getUri?() is uri + itemForUri: (uri) -> - find @items, (item) -> item.getUri?() is uri + Grim.deprecate("Use `::itemForURI` instead.") + @itemForURI(uri) # Public: Activate the first item that matches the given URI. # # Returns a {Boolean} indicating whether an item matching the URI was found. - activateItemForUri: (uri) -> - if item = @itemForUri(uri) + activateItemForURI: (uri) -> + if item = @itemForURI(uri) @activateItem(item) true else false + activateItemForUri: (uri) -> + Grim.deprecate("Use `::activateItemForURI` instead.") + @activateItemForURI(uri) + copyActiveItem: -> if @activeItem? @activeItem.copy?() ? atom.deserializers.deserialize(@activeItem.serialize()) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 826b4863a..7e576ff25 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -515,7 +515,11 @@ class TextEditor extends Model getBuffer: -> @buffer # Retrieves the current buffer's URI. - getUri: -> @buffer.getUri() + getURI: -> @buffer.getUri() + + getUri: -> + deprecate("Use `::getURI` instead") + @getURI() # Create an {TextEditor} with its initial state based on this object copy: -> diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index dcfa540cf..addfe63c5 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -52,7 +52,7 @@ module.exports = class WorkspaceView extends View Delegator.includeInto(this) - @delegatesProperty 'fullScreen', 'destroyedItemUris', toProperty: 'model' + @delegatesProperty 'fullScreen', 'destroyedItemURIs', toProperty: 'model' @delegatesMethods 'open', 'openSync', 'saveActivePaneItem', 'saveActivePaneItemAs', 'saveAll', 'destroyActivePaneItem', 'destroyActivePane', 'increaseFontSize', 'decreaseFontSize', toProperty: 'model' diff --git a/src/workspace.coffee b/src/workspace.coffee index 6242b7a6f..c4a5be5d0 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -44,7 +44,7 @@ class Workspace extends Model @properties paneContainer: null fullScreen: false - destroyedItemUris: -> [] + destroyedItemURIs: -> [] constructor: (params) -> super @@ -385,7 +385,7 @@ class Workspace extends Model split = options.split uri = atom.project.resolvePath(uri) - pane = @paneContainer.paneForUri(uri) if searchAllPanes + pane = @paneContainer.paneForURI(uri) if searchAllPanes pane ?= switch split when 'left' @getActivePane().findLeftmostSibling() @@ -394,7 +394,7 @@ class Workspace extends Model else @getActivePane() - @openUriInPane(uri, pane, options) + @openURIInPane(uri, pane, options) # Open Atom's license in the active pane. openLicense: -> @@ -423,7 +423,7 @@ class Workspace extends Model activatePane = options.activatePane ? true uri = atom.project.resolvePath(uri) - item = @getActivePane().itemForUri(uri) + item = @getActivePane().itemForURI(uri) if uri item ?= opener(uri, options) for opener in @getOpeners() when !item item ?= atom.project.openSync(uri, {initialLine, initialColumn}) @@ -433,7 +433,7 @@ class Workspace extends Model @getActivePane().activate() if activatePane item - openUriInPane: (uri, pane, options={}) -> + openURIInPane: (uri, pane, options={}) -> # TODO: Remove deprecated changeFocus option if options.changeFocus? deprecate("The `changeFocus` option has been renamed to `activatePane`") @@ -443,7 +443,7 @@ class Workspace extends Model activatePane = options.activatePane ? true if uri? - item = pane.itemForUri(uri) + item = pane.itemForURI(uri) item ?= opener(uri, options) for opener in @getOpeners() when !item item ?= atom.project.open(uri, options) @@ -467,7 +467,7 @@ class Workspace extends Model # # Returns a promise that is resolved when the item is opened reopenItem: -> - if uri = @destroyedItemUris.pop() + if uri = @destroyedItemURIs.pop() @open(uri) else Q() @@ -475,7 +475,7 @@ class Workspace extends Model # Deprecated reopenItemSync: -> deprecate("Use Workspace::reopenItem instead") - if uri = @destroyedItemUris.pop() + if uri = @destroyedItemURIs.pop() @openSync(uri) # Public: Register an opener for a uri. @@ -553,7 +553,7 @@ class Workspace extends Model # Save the active pane item. # # If the active pane item currently has a URI according to the item's - # `.getUri` method, calls `.save` on the item. Otherwise + # `.getURI` method, calls `.save` on the item. Otherwise # {::saveActivePaneItemAs} # will be called instead. This method does nothing # if the active item does not implement a `.save` method. saveActivePaneItem: -> @@ -617,8 +617,12 @@ class Workspace extends Model # * `uri` {String} uri # # Returns a {Pane} or `undefined` if no pane exists for the given URI. + paneForURI: (uri) -> + @paneContainer.paneForURI(uri) + paneForUri: (uri) -> - @paneContainer.paneForUri(uri) + deprecate("Use ::paneForURI instead.") + @paneForURI(uri) # Extended: Get the {Pane} containing the given item. # @@ -651,13 +655,19 @@ class Workspace extends Model # Removes the item's uri from the list of potential items to reopen. itemOpened: (item) -> - if uri = item.getUri?() - _.remove(@destroyedItemUris, uri) + if typeof item.getUri is 'function' and not typeof item.getURI is 'function' + deprecate("Pane items should implement `::getURI` instead of `::getUri`.") + + if uri = item.getURI?() ? item.getUri?() + _.remove(@destroyedItemURIs, uri) # Adds the destroyed item's uri to the list of items to reopen. didDestroyPaneItem: ({item}) => - if uri = item.getUri?() - @destroyedItemUris.push(uri) + if typeof item.getUri is 'function' and not typeof item.getURI is 'function' + deprecate("Pane items should implement `::getURI` instead of `::getUri`.") + + if uri = item.getURI?() ? item.getUri?() + @destroyedItemURIs.push(uri) # Called by Model superclass when destroyed destroyed: ->