Comparar commits

...

2 Commits

Autor SHA1 Mensagem Data
Nathan Sobo 91d6ad5b03 Update style guide
Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
2015-01-12 18:06:36 -08:00
Nathan Sobo 588128d4f0 Capitalize initialisms
Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
2015-01-12 18:06:31 -08:00
13 arquivos alterados com 86 adições e 53 exclusões
+4
Ver Arquivo
@@ -99,6 +99,10 @@ For more information on how to work with Atom's official packages, see
* Avoid spaces inside the curly-braces of hash literals: * Avoid spaces inside the curly-braces of hash literals:
* `{a: 1, b: 2}` instead of `{ a: 1, b: 2 }` * `{a: 1, b: 2}` instead of `{ a: 1, b: 2 }`
* Include a single line of whitespace between methods. * Include a single line of whitespace between methods.
* Capitalize initialisms and acronyms in names, except for the first word, which
should be lower-case:
* `getURI` instead of `getUri`
* `uriToOpen` instead of `URIToOpen`
## Documentation Styleguide ## Documentation Styleguide
+1 -1
Ver Arquivo
@@ -129,7 +129,7 @@ describe "PaneContainer", ->
beforeEach -> beforeEach ->
class TestItem class TestItem
shouldPromptToSave: -> true shouldPromptToSave: -> true
getUri: -> 'test' getURI: -> 'test'
container = new PaneContainer container = new PaneContainer
container.getRoot().splitRight() container.getRoot().splitRight()
+1 -1
Ver Arquivo
@@ -16,7 +16,7 @@ describe "PaneContainerView", ->
@content: -> @div tabindex: -1 @content: -> @div tabindex: -1
initialize: (@name) -> @text(@name) initialize: (@name) -> @text(@name)
serialize: -> { deserializer: 'TestView', @name } serialize: -> { deserializer: 'TestView', @name }
getUri: -> path.join(temp.dir, @name) getURI: -> path.join(temp.dir, @name)
save: -> @saved = true save: -> @saved = true
isEqual: (other) -> @name is other?.name isEqual: (other) -> @name is other?.name
onDidChangeTitle: -> new Disposable(->) onDidChangeTitle: -> new Disposable(->)
+12 -12
Ver Arquivo
@@ -9,7 +9,7 @@ describe "Pane", ->
class Item extends Model class Item extends Model
@deserialize: ({name, uri}) -> new this(name, uri) @deserialize: ({name, uri}) -> new this(name, uri)
constructor: (@name, @uri) -> constructor: (@name, @uri) ->
getUri: -> @uri getURI: -> @uri
getPath: -> @path getPath: -> @path
serialize: -> {deserializer: 'Item', @name, @uri} serialize: -> {deserializer: 'Item', @name, @uri}
isEqual: (other) -> @name is other?.name isEqual: (other) -> @name is other?.name
@@ -231,18 +231,18 @@ describe "Pane", ->
expect(pane.getActiveItem()).toBe item1 expect(pane.getActiveItem()).toBe item1
describe "if the item is modified", -> describe "if the item is modified", ->
itemUri = null itemURI = null
beforeEach -> beforeEach ->
item1.shouldPromptToSave = -> true item1.shouldPromptToSave = -> true
item1.save = jasmine.createSpy("save") item1.save = jasmine.createSpy("save")
item1.saveAs = jasmine.createSpy("saveAs") item1.saveAs = jasmine.createSpy("saveAs")
item1.getUri = -> itemUri item1.getURI = -> itemURI
describe "if the [Save] option is selected", -> describe "if the [Save] option is selected", ->
describe "when the item has a uri", -> describe "when the item has a uri", ->
it "saves the item before destroying it", -> it "saves the item before destroying it", ->
itemUri = "test" itemURI = "test"
spyOn(atom, 'confirm').andReturn(0) spyOn(atom, 'confirm').andReturn(0)
pane.destroyItem(item1) pane.destroyItem(item1)
@@ -252,7 +252,7 @@ describe "Pane", ->
describe "when the item has no uri", -> 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", -> 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, 'showSaveDialogSync').andReturn("/selected/path")
spyOn(atom, 'confirm').andReturn(0) spyOn(atom, 'confirm').andReturn(0)
@@ -404,15 +404,15 @@ describe "Pane", ->
pane.saveActiveItemAs() pane.saveActiveItemAs()
expect(atom.showSaveDialogSync).not.toHaveBeenCalled() expect(atom.showSaveDialogSync).not.toHaveBeenCalled()
describe "::itemForUri(uri)", -> describe "::itemForURI(uri)", ->
it "returns the item for which a call to .getUri() returns the given 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")]) pane = new Pane(items: [new Item("A"), new Item("B"), new Item("C"), new Item("D")])
[item1, item2, item3] = pane.getItems() [item1, item2, item3] = pane.getItems()
item1.uri = "a" item1.uri = "a"
item2.uri = "b" item2.uri = "b"
expect(pane.itemForUri("a")).toBe item1 expect(pane.itemForURI("a")).toBe item1
expect(pane.itemForUri("b")).toBe item2 expect(pane.itemForURI("b")).toBe item2
expect(pane.itemForUri("bogus")).toBeUndefined() expect(pane.itemForURI("bogus")).toBeUndefined()
describe "::moveItem(item, index)", -> describe "::moveItem(item, index)", ->
[pane, item1, item2, item3, item4] = [] [pane, item1, item2, item3, item4] = []
@@ -589,7 +589,7 @@ describe "Pane", ->
[item1, item2] = pane.getItems() [item1, item2] = pane.getItems()
item1.shouldPromptToSave = -> true item1.shouldPromptToSave = -> true
item1.getUri = -> "/test/path" item1.getURI = -> "/test/path"
item1.save = jasmine.createSpy("save") item1.save = jasmine.createSpy("save")
spyOn(atom, 'confirm').andReturn(0) spyOn(atom, 'confirm').andReturn(0)
@@ -604,7 +604,7 @@ describe "Pane", ->
[item1, item2] = pane.getItems() [item1, item2] = pane.getItems()
item1.shouldPromptToSave = -> true item1.shouldPromptToSave = -> true
item1.getUri = -> "/test/path" item1.getURI = -> "/test/path"
item1.save = jasmine.createSpy("save") item1.save = jasmine.createSpy("save")
spyOn(atom, 'confirm').andReturn(1) spyOn(atom, 'confirm').andReturn(1)
+1 -1
Ver Arquivo
@@ -15,7 +15,7 @@ describe "PaneView", ->
initialize: ({@id, @text}) -> initialize: ({@id, @text}) ->
@emitter = new Emitter @emitter = new Emitter
serialize: -> { deserializer: 'TestView', @id, @text } serialize: -> { deserializer: 'TestView', @id, @text }
getUri: -> @id getURI: -> @id
isEqual: (other) -> other? and @id == other.id and @text == other.text isEqual: (other) -> other? and @id == other.id and @text == other.text
changeTitle: -> changeTitle: ->
@emitter.emit 'did-change-title', 'title' @emitter.emit 'did-change-title', 'title'
+9 -9
Ver Arquivo
@@ -96,7 +96,7 @@ describe "Workspace", ->
workspace.open('a').then (o) -> editor = o workspace.open('a').then (o) -> editor = o
runs -> 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.getActivePaneItem()).toBe editor
expect(workspace.getActivePane().items).toEqual [editor] expect(workspace.getActivePane().items).toEqual [editor]
expect(workspace.getActivePane().activate).toHaveBeenCalled() expect(workspace.getActivePane().activate).toHaveBeenCalled()
@@ -261,21 +261,21 @@ describe "Workspace", ->
runs -> runs ->
# does not reopen items with no uri # does not reopen items with no uri
expect(workspace.getActivePaneItem().getUri()).toBeUndefined() expect(workspace.getActivePaneItem().getURI()).toBeUndefined()
pane.destroyActiveItem() pane.destroyActiveItem()
waitsForPromise -> waitsForPromise ->
workspace.reopenItem() workspace.reopenItem()
runs -> runs ->
expect(workspace.getActivePaneItem().getUri()).not.toBeUndefined() expect(workspace.getActivePaneItem().getURI()).not.toBeUndefined()
# destroy all items # 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() 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() 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() pane.destroyActiveItem()
# reopens items with uris # reopens items with uris
@@ -285,20 +285,20 @@ describe "Workspace", ->
workspace.reopenItem() workspace.reopenItem()
runs -> 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 # does not reopen items that are already open
waitsForPromise -> waitsForPromise ->
workspace.open('b') workspace.open('b')
runs -> runs ->
expect(workspace.getActivePaneItem().getUri()).toBe atom.project.getDirectories()[0]?.resolve('b') expect(workspace.getActivePaneItem().getURI()).toBe atom.project.getDirectories()[0]?.resolve('b')
waitsForPromise -> waitsForPromise ->
workspace.reopenItem() workspace.reopenItem()
runs -> 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()", -> describe "::increase/decreaseFontSize()", ->
it "increases/decreases the font size without going below 1", -> it "increases/decreases the font size without going below 1", ->
+4 -1
Ver Arquivo
@@ -232,7 +232,10 @@ class GitRepository
# #
# * `path` (optional) {String} path in the repository to get this information # * `path` (optional) {String} path in the repository to get this information
# for, only needed if the repository has submodules. # 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 # Public: Returns the upstream branch for the current HEAD, or null if there
# is no upstream branch for the current HEAD. # is no upstream branch for the current HEAD.
+1 -1
Ver Arquivo
@@ -64,7 +64,7 @@ class PaneContainerView extends View
@getActivePaneView()?.activeView @getActivePaneView()?.activeView
paneForUri: (uri) -> paneForUri: (uri) ->
atom.views.getView(@model.paneForUri(uri)).__spacePenView atom.views.getView(@model.paneForURI(uri)).__spacePenView
focusNextPaneView: -> focusNextPaneView: ->
@model.activateNextPane() @model.activateNextPane()
+2 -2
Ver Arquivo
@@ -143,8 +143,8 @@ class PaneContainer extends Model
getActivePaneItem: -> getActivePaneItem: ->
@getActivePane().getActiveItem() @getActivePane().getActiveItem()
paneForUri: (uri) -> paneForURI: (uri) ->
find @getPanes(), (pane) -> pane.itemForUri(uri)? find @getPanes(), (pane) -> pane.itemForURI(uri)?
paneForItem: (item) -> paneForItem: (item) ->
@getPanes().find (pane) -> item in pane.getItems() @getPanes().find (pane) -> item in pane.getItems()
+21 -9
Ver Arquivo
@@ -43,14 +43,15 @@ class Pane extends Model
serializeParams: -> serializeParams: ->
id: @id id: @id
items: compact(@items.map((item) -> item.serialize?())) items: compact(@items.map((item) -> item.serialize?()))
activeItemUri: @activeItem?.getUri?() activeItemURI: @activeItem?.getURI?() ? @activeItem?.getUri?()
focused: @focused focused: @focused
# Called by the Serializable mixin during deserialization. # Called by the Serializable mixin during deserialization.
deserializeParams: (params) -> deserializeParams: (params) ->
{items, activeItemUri} = params {items, activeItemURI, activeItemUri} = params
activeItemURI ?= activeItemUri
params.items = compact(items.map (itemState) -> atom.deserializers.deserialize(itemState)) 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 params
getParent: -> @parent getParent: -> @parent
@@ -426,10 +427,13 @@ class Pane extends Model
@destroyItem(item) for item in @getItems() when item isnt @activeItem @destroyItem(item) for item in @getItems() when item isnt @activeItem
promptToSaveItem: (item) -> 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 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." detailedMessage: "Your changes will be lost if you close this item without saving."
buttons: ["Save", "Cancel", "Don't Save"] 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 # * `nextAction` (optional) {Function} which will be called after the item is
# successfully saved. # successfully saved.
saveItem: (item, nextAction) -> saveItem: (item, nextAction) ->
if item?.getUri?() if (item?.getURI?() ? item?.getUri?())
item.save?() item.save?()
nextAction?() nextAction?()
else else
@@ -485,19 +489,27 @@ class Pane extends Model
# none exists. # none exists.
# #
# * `uri` {String} containing a URI. # * `uri` {String} containing a URI.
itemForURI: (uri) ->
find @items, (item) -> item.getURI?() is uri or item.getUri?() is uri
itemForUri: (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. # Public: Activate the first item that matches the given URI.
# #
# Returns a {Boolean} indicating whether an item matching the URI was found. # Returns a {Boolean} indicating whether an item matching the URI was found.
activateItemForUri: (uri) -> activateItemForURI: (uri) ->
if item = @itemForUri(uri) if item = @itemForURI(uri)
@activateItem(item) @activateItem(item)
true true
else else
false false
activateItemForUri: (uri) ->
Grim.deprecate("Use `::activateItemForURI` instead.")
@activateItemForURI(uri)
copyActiveItem: -> copyActiveItem: ->
if @activeItem? if @activeItem?
@activeItem.copy?() ? atom.deserializers.deserialize(@activeItem.serialize()) @activeItem.copy?() ? atom.deserializers.deserialize(@activeItem.serialize())
+5 -1
Ver Arquivo
@@ -515,7 +515,11 @@ class TextEditor extends Model
getBuffer: -> @buffer getBuffer: -> @buffer
# Retrieves the current buffer's URI. # 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 # Create an {TextEditor} with its initial state based on this object
copy: -> copy: ->
+1 -1
Ver Arquivo
@@ -52,7 +52,7 @@ module.exports =
class WorkspaceView extends View class WorkspaceView extends View
Delegator.includeInto(this) Delegator.includeInto(this)
@delegatesProperty 'fullScreen', 'destroyedItemUris', toProperty: 'model' @delegatesProperty 'fullScreen', 'destroyedItemURIs', toProperty: 'model'
@delegatesMethods 'open', 'openSync', @delegatesMethods 'open', 'openSync',
'saveActivePaneItem', 'saveActivePaneItemAs', 'saveAll', 'destroyActivePaneItem', 'saveActivePaneItem', 'saveActivePaneItemAs', 'saveAll', 'destroyActivePaneItem',
'destroyActivePane', 'increaseFontSize', 'decreaseFontSize', toProperty: 'model' 'destroyActivePane', 'increaseFontSize', 'decreaseFontSize', toProperty: 'model'
+24 -14
Ver Arquivo
@@ -44,7 +44,7 @@ class Workspace extends Model
@properties @properties
paneContainer: null paneContainer: null
fullScreen: false fullScreen: false
destroyedItemUris: -> [] destroyedItemURIs: -> []
constructor: (params) -> constructor: (params) ->
super super
@@ -385,7 +385,7 @@ class Workspace extends Model
split = options.split split = options.split
uri = atom.project.resolvePath(uri) uri = atom.project.resolvePath(uri)
pane = @paneContainer.paneForUri(uri) if searchAllPanes pane = @paneContainer.paneForURI(uri) if searchAllPanes
pane ?= switch split pane ?= switch split
when 'left' when 'left'
@getActivePane().findLeftmostSibling() @getActivePane().findLeftmostSibling()
@@ -394,7 +394,7 @@ class Workspace extends Model
else else
@getActivePane() @getActivePane()
@openUriInPane(uri, pane, options) @openURIInPane(uri, pane, options)
# Open Atom's license in the active pane. # Open Atom's license in the active pane.
openLicense: -> openLicense: ->
@@ -423,7 +423,7 @@ class Workspace extends Model
activatePane = options.activatePane ? true activatePane = options.activatePane ? true
uri = atom.project.resolvePath(uri) uri = atom.project.resolvePath(uri)
item = @getActivePane().itemForUri(uri) item = @getActivePane().itemForURI(uri)
if uri if uri
item ?= opener(uri, options) for opener in @getOpeners() when !item item ?= opener(uri, options) for opener in @getOpeners() when !item
item ?= atom.project.openSync(uri, {initialLine, initialColumn}) item ?= atom.project.openSync(uri, {initialLine, initialColumn})
@@ -433,7 +433,7 @@ class Workspace extends Model
@getActivePane().activate() if activatePane @getActivePane().activate() if activatePane
item item
openUriInPane: (uri, pane, options={}) -> openURIInPane: (uri, pane, options={}) ->
# TODO: Remove deprecated changeFocus option # TODO: Remove deprecated changeFocus option
if options.changeFocus? if options.changeFocus?
deprecate("The `changeFocus` option has been renamed to `activatePane`") deprecate("The `changeFocus` option has been renamed to `activatePane`")
@@ -443,7 +443,7 @@ class Workspace extends Model
activatePane = options.activatePane ? true activatePane = options.activatePane ? true
if uri? if uri?
item = pane.itemForUri(uri) item = pane.itemForURI(uri)
item ?= opener(uri, options) for opener in @getOpeners() when !item item ?= opener(uri, options) for opener in @getOpeners() when !item
item ?= atom.project.open(uri, options) 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 # Returns a promise that is resolved when the item is opened
reopenItem: -> reopenItem: ->
if uri = @destroyedItemUris.pop() if uri = @destroyedItemURIs.pop()
@open(uri) @open(uri)
else else
Q() Q()
@@ -475,7 +475,7 @@ class Workspace extends Model
# Deprecated # Deprecated
reopenItemSync: -> reopenItemSync: ->
deprecate("Use Workspace::reopenItem instead") deprecate("Use Workspace::reopenItem instead")
if uri = @destroyedItemUris.pop() if uri = @destroyedItemURIs.pop()
@openSync(uri) @openSync(uri)
# Public: Register an opener for a uri. # Public: Register an opener for a uri.
@@ -553,7 +553,7 @@ class Workspace extends Model
# Save the active pane item. # Save the active pane item.
# #
# If the active pane item currently has a URI according to the item's # 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 # {::saveActivePaneItemAs} # will be called instead. This method does nothing
# if the active item does not implement a `.save` method. # if the active item does not implement a `.save` method.
saveActivePaneItem: -> saveActivePaneItem: ->
@@ -617,8 +617,12 @@ class Workspace extends Model
# * `uri` {String} uri # * `uri` {String} uri
# #
# Returns a {Pane} or `undefined` if no pane exists for the given URI. # Returns a {Pane} or `undefined` if no pane exists for the given URI.
paneForURI: (uri) ->
@paneContainer.paneForURI(uri)
paneForUri: (uri) -> paneForUri: (uri) ->
@paneContainer.paneForUri(uri) deprecate("Use ::paneForURI instead.")
@paneForURI(uri)
# Extended: Get the {Pane} containing the given item. # 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. # Removes the item's uri from the list of potential items to reopen.
itemOpened: (item) -> itemOpened: (item) ->
if uri = item.getUri?() if typeof item.getUri is 'function' and not typeof item.getURI is 'function'
_.remove(@destroyedItemUris, uri) 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. # Adds the destroyed item's uri to the list of items to reopen.
didDestroyPaneItem: ({item}) => didDestroyPaneItem: ({item}) =>
if uri = item.getUri?() if typeof item.getUri is 'function' and not typeof item.getURI is 'function'
@destroyedItemUris.push(uri) deprecate("Pane items should implement `::getURI` instead of `::getUri`.")
if uri = item.getURI?() ? item.getUri?()
@destroyedItemURIs.push(uri)
# Called by Model superclass when destroyed # Called by Model superclass when destroyed
destroyed: -> destroyed: ->