Skip to content

Commit

Permalink
Upgraded the package code to make it compatible with version 1.0 of t…
Browse files Browse the repository at this point in the history
…he Atom API
  • Loading branch information
vellerefond committed Feb 9, 2015
1 parent 7d854aa commit 80120c3
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 58 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
###### 0.19.0 - Upgraded the package code to make it compatible with version 1.0 of the Atom API.

###### 0.18.5 - Minor code logic fix

###### 0.18.4 - Using synchronous open for project files and fixes regarding the project loading logic
Expand Down
2 changes: 1 addition & 1 deletion keymaps/project-ring.cson
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# please, reload (in command palette: "Window: Reload") or close and
# reopen Atom for the changes to take effect.

'.workspace ':
'atom-workspace ':
'alt-shift-\\': 'project-ring:add'
'alt-shift-=': 'project-ring:add-as'
'alt-shift-/': 'project-ring:rename'
Expand Down
12 changes: 6 additions & 6 deletions lib/project-ring-buffer-select-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class ProjectRingBufferSelectView extends View

attach: (viewModeParameters, items) ->
@viewModeParameters = viewModeParameters
atom.workspaceView.append @
$content = atom.workspaceView.find '.project-ring-buffer-select'
@self = atom.workspace.addModalPanel item: @
$content = $(atom.views.getView atom.workspace).find '.project-ring-buffer-select'
unless @isInitialized
$controls = $content.find('.controls')
$controls.find('input:button.confirm').on 'click', => @confirmed()
Expand All @@ -48,18 +48,18 @@ class ProjectRingBufferSelectView extends View
$entries.append @getEntryView title: title, description: description, path: path

destroy: ->
@detach()
@self.destroy()

confirmed: ->
bufferPaths = []
atom.workspaceView.find('.project-ring-buffer-select .entries input:checkbox.checked')\
.each (index, element) -> \
$(atom.views.getView atom.workspace).find('.project-ring-buffer-select .entries input:checkbox.checked')\
.each (index, element) ->
bufferPaths.push $(element).attr 'data-path'
@destroy()
@projectRing.handleProjectRingBufferSelectViewSelection @viewModeParameters, bufferPaths

setAllEntriesSelected: (allSelected) ->
$checkboxes = atom.workspaceView.find '.project-ring-buffer-select .entries input:checkbox'
$checkboxes = $(atom.views.getView atom.workspace).find '.project-ring-buffer-select .entries input:checkbox'
if allSelected
$checkboxes.removeClass('checked').addClass 'checked'
else
Expand Down
12 changes: 6 additions & 6 deletions lib/project-ring-input-view.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{ View, EditorView } = require 'atom-space-pen-views'
{ View, TextEditorView } = require 'atom-space-pen-views'

module.exports =
class ProjectRingInputView extends View
@content: ->
@div class: 'project-ring-input overlay from-top', =>
@div class: 'editor-container', outlet: 'editorContainer', =>
@subview 'editor', new EditorView mini: true
@subview 'editor', new TextEditorView mini: true

initialize: (projectRing) ->
@projectRing = @projectRing or projectRing
Expand All @@ -17,16 +17,16 @@ class ProjectRingInputView extends View
@editor.on 'core:cancel', => @destroy()
@isInitialized = true
@editor.find('input').off 'blur'
@editor.setPlaceholderText placeholderText
@editor.getModel().setPlaceholderText placeholderText
@editor.setText text or ''
@editor.editor.selectAll()
atom.workspaceView.append @
@editor.getModel().selectAll()
@self = atom.workspace.addModalPanel item: @
@editor.focus()
@editor.find('input').on 'blur', => @destroy()

destroy: ->
@editor.find('input').off 'blur'
@detach()
@self.destroy()

confirmed: ->
@destroy()
Expand Down
8 changes: 5 additions & 3 deletions lib/project-ring-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ProjectRingView extends SelectListView
'data': items[key]
}
@setItems itemsArray
atom.workspace.addModalPanel item: @
@filterEditorView.setPlaceholderText @viewModeParameters.placeholderText
@self = atom.workspace.addModalPanel item: @
@filterEditorView.getModel().setPlaceholderText @viewModeParameters.placeholderText
@filterEditorView.focus()

getEmptyMessage: (itemCount, filteredItemCount) =>
Expand All @@ -52,4 +52,6 @@ class ProjectRingView extends SelectListView

destroy: ->
@cancel()
@detach()

cancelled: ->
@self.destroy()
63 changes: 40 additions & 23 deletions lib/project-ring.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
##############################
# Private Helper Functions -- Start #
##############################

findInArray = (array, callback) ->
return undefined unless array and array.length and typeof callback is 'function'
for element in array
return element if callback element
undefined

##############################
# Private Helper Functions -- END #
##############################

module.exports =
configDefaults:
closePreviousProjectFiles: true
filePatternToHide: null
filePatternToExcludeFromHiding: null
filePatternToHide: ''
filePatternToExcludeFromHiding: ''
keepAllOpenFilesRegardlessOfProject: false
keepOutOfPathOpenFilesInCurrentProject: false
makeTheCurrentProjectTheDefaultOnStartUp: true
projectToLoadOnStartUp: null
projectToLoadOnStartUp: ''
doNotSaveAndRestoreOpenProjectFiles: false
skipOpeningTreeViewWhenChangingProjectPath: false
useFilePatternHiding: false
Expand Down Expand Up @@ -128,7 +142,7 @@ module.exports =
setTimeout (
=>
bufferDestroyedPathProxy = bufferDestroyed.file.path.toLowerCase()
if (@statesCache['<~>'].openBufferPaths.find (openBufferPath) ->
if (findInArray @statesCache['<~>'].openBufferPaths, (openBufferPath) ->
openBufferPath.toLowerCase() is bufferDestroyedPathProxy)
@statesCache['<~>'].openBufferPaths =
@statesCache['<~>'].openBufferPaths.filter (openBufferPath) ->
Expand All @@ -137,7 +151,7 @@ module.exports =
return
return unless @inProject
atomProjectPathAsKeyProxy = @getAtomProjectPathAsKey()
if (@statesCache[atomProjectPathAsKeyProxy].openBufferPaths.find (openBufferPath) ->
if (findInArray @statesCache[atomProjectPathAsKeyProxy].openBufferPaths, (openBufferPath) ->
openBufferPath.toLowerCase() is bufferDestroyedPathProxy)
@statesCache[atomProjectPathAsKeyProxy].openBufferPaths =
@statesCache[atomProjectPathAsKeyProxy].openBufferPaths
Expand Down Expand Up @@ -233,6 +247,8 @@ module.exports =
),
0



getConfigurationPath: ->
_path = require 'path'
path = _path.join process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME'],
Expand Down Expand Up @@ -412,13 +428,13 @@ module.exports =
atomProjectPathAsKeyProxy = @getAtomProjectPathAsKey()
return if \
not manually and \
(@statesCache[atomProjectPathAsKeyProxy].bannedBufferPaths.find (bannedBufferPath) -> \
(findInArray @statesCache[atomProjectPathAsKeyProxy].bannedBufferPaths, (bannedBufferPath) -> \
bannedBufferPath.toLowerCase() is openBufferPathToAdd)
if manually
@statesCache['<~>'].openBufferPaths =
@statesCache['<~>'].openBufferPaths.filter (openBufferPath) ->
openBufferPath.toLowerCase() isnt openBufferPathToAdd
unless (@statesCache[atomProjectPathAsKeyProxy].openBufferPaths.find (openBufferPath) ->
unless (findInArray @statesCache[atomProjectPathAsKeyProxy].openBufferPaths, (openBufferPath) ->
openBufferPath.toLowerCase() is openBufferPathToAdd)
atom.workspace.once 'editor-created.project-ring editor-created-forced.project-ring', =>
setTimeout (
Expand All @@ -427,9 +443,9 @@ module.exports =
@statesCache[atomProjectPathAsKeyProxy].bannedBufferPaths.filter (bannedBufferPath) ->
bannedBufferPath.toLowerCase() isnt openBufferPathToAdd
newOpenBufferPaths = @getOpenBufferPaths().filter (openBufferPathInAll) =>
openBufferPathInAll.toLowerCase() is openBufferPathToAdd or \
@statesCache[atomProjectPathAsKeyProxy].openBufferPaths.find (openBufferPath) ->
openBufferPath.toLowerCase() is openBufferPathInAll.toLowerCase()
openBufferPathInAll.toLowerCase() is openBufferPathToAdd or
findInArray @statesCache[atomProjectPathAsKeyProxy].openBufferPaths, (openBufferPath) ->
openBufferPath.toLowerCase() is openBufferPathInAll.toLowerCase()
@statesCache[atomProjectPathAsKeyProxy].openBufferPaths = newOpenBufferPaths
@saveProjectRing()
if manually
Expand All @@ -450,7 +466,7 @@ module.exports =
return unless openBufferPathToBan
openBufferPathToBanProxy = openBufferPathToBan.toLowerCase()
atomProjectPathAsKeyProxy = @getAtomProjectPathAsKey()
unless (@statesCache[atomProjectPathAsKeyProxy].bannedBufferPaths.find (openBufferPath) ->
unless (findInArray @statesCache[atomProjectPathAsKeyProxy].bannedBufferPaths, (openBufferPath) ->
openBufferPath.toLowerCase() is openBufferPathToBanProxy)
@statesCache[atomProjectPathAsKeyProxy].openBufferPaths =
@statesCache[atomProjectPathAsKeyProxy].openBufferPaths.filter (openBufferPath) ->
Expand All @@ -468,8 +484,8 @@ module.exports =
bufferPathToAlwaysOpen = atom.workspace.getActiveEditor()?.buffer.file?.path unless bufferPathToAlwaysOpen
bufferPathToAlwaysOpenProxy = bufferPathToAlwaysOpen?.toLowerCase()
return unless \
bufferPathToAlwaysOpen and \
not (@statesCache['<~>'].openBufferPaths.find (openBufferPath) -> \
bufferPathToAlwaysOpen and
not (findInArray @statesCache['<~>'].openBufferPaths, (openBufferPath) ->
openBufferPath.toLowerCase() is bufferPathToAlwaysOpenProxy)
for stateKey in Object.keys @statesCache
continue if @statesCache[stateKey].isIgnored
Expand Down Expand Up @@ -548,7 +564,7 @@ module.exports =

addAs: (renameOnly) ->
@loadProjectRingInputView()
unless @projectRingInputView.hasParent()
unless @projectRingInputView.isVisible()
alias = atom.project.path
atomProjectPathAsKeyProxy = @getAtomProjectPathAsKey()
if @statesCache[atomProjectPathAsKeyProxy]
Expand All @@ -564,12 +580,13 @@ module.exports =
}, 'Project alias', alias

toggle: (openProjectBuffersOnly) ->
deleteKeyBinding = atom.keymap.getKeyBindings().find (keyBinding) -> keyBinding.command is 'project-ring:add'
deleteKeyBinding = findInArray atom.keymap.getKeyBindings(), (keyBinding) ->
keyBinding.command is 'project-ring:add'
if deleteKeyBinding
then deleteKeyBinding =
' (delete selected: ' + deleteKeyBinding.keystrokes.split(/\s+/)[0].replace(/-[^-]+$/, '-') + 'delete)'
else deleteKeyBinding = ''
if @projectRingView and @projectRingView.hasParent()
if @projectRingView and @projectRingView.isVisible()
@projectRingView.destroy()
else
@loadProjectRingView()
Expand All @@ -585,7 +602,7 @@ module.exports =
addFilesToProject: ->
return unless @checkIfInProject()
@loadProjectRingBufferSelectView()
unless @projectRingBufferSelectView.hasParent()
unless @projectRingBufferSelectView.isVisible()
bufferPathsToOfferForAddition = []
atomProjectPathAsKeyProxy = @getAtomProjectPathAsKey()
buffersOfCurrentProject =
Expand All @@ -597,7 +614,7 @@ module.exports =
(@statesCache[projectPath].openBufferPaths.filter (openBufferPath) ->
openBufferPathProxy = openBufferPath.toLowerCase()
openBufferPathProxy not in buffersOfCurrentProject and
not (bufferPathsToOfferForAddition.find (bufferPathSpec) ->
not (findInArray bufferPathsToOfferForAddition, (bufferPathSpec) ->
bufferPathSpec.path.toLowerCase() is openBufferPathProxy)).forEach (openBufferPath) =>
description = openBufferPath
if description.length > 40
Expand All @@ -610,7 +627,7 @@ module.exports =
bufferPathProxy = buffer.file?.path.toLowerCase()
buffer.file and
bufferPathProxy not in buffersOfCurrentProject and
not (bufferPathsToOfferForAddition.find (bufferPathSpec) ->
not (findInArray bufferPathsToOfferForAddition, (bufferPathSpec) ->
bufferPathSpec.path.toLowerCase() is bufferPathProxy)).forEach (buffer) ->
description = buffer.file.path
description = '...' + description.substr description.length - 37 if description.length > 40
Expand All @@ -629,11 +646,11 @@ module.exports =
banFilesFromProject: ->
return unless @checkIfInProject()
@loadProjectRingBufferSelectView()
unless @projectRingBufferSelectView.hasParent()
unless @projectRingBufferSelectView.isVisible()
bufferPathsToOfferForBanning = []
(atom.project.buffers.filter (buffer) ->
buffer.file and
not (bufferPathsToOfferForBanning.find (bufferPathSpec) ->
not (findInArray bufferPathsToOfferForBanning, (bufferPathSpec) ->
bufferPathSpec.path.toLowerCase() is buffer.file.path.toLowerCase())).forEach (buffer) ->
description = buffer.file.path
description = '...' + description.substr description.length - 37 if description.length > 40
Expand All @@ -647,11 +664,11 @@ module.exports =
alwaysOpenFiles: ->
return unless @checkIfInProject()
@loadProjectRingBufferSelectView()
unless @projectRingBufferSelectView.hasParent()
unless @projectRingBufferSelectView.isVisible()
bufferPathsToOfferForAlwaysOpening = []
(atom.project.buffers.filter (buffer) ->
buffer.file and
not (bufferPathsToOfferForAlwaysOpening.find (bufferPathSpec) ->
not (findInArray bufferPathsToOfferForAlwaysOpening, (bufferPathSpec) ->
bufferPathSpec.path.toLowerCase() is buffer.file.path.toLowerCase())).forEach (buffer) ->
description = buffer.file.path
description = '...' + description.substr description.length - 37 if description.length > 40
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "project-ring",
"main": "./lib/project-ring",
"version": "0.18.5",
"version": "0.19.0",
"description": "Project management for the Atom editor.",
"repository": "https://github.com/vellerefond/project-ring",
"license": "MIT",
Expand Down
15 changes: 2 additions & 13 deletions spec/project-ring-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{WorkspaceView} = require 'atom'
ProjectRing = require '../lib/project-ring'

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
Expand All @@ -10,21 +9,11 @@ describe "ProjectRing", ->
activationPromise = null

beforeEach ->
atom.workspaceView = new WorkspaceView
activationPromise = atom.packages.activatePackage('project-ring')

describe "when the project-ring:toggle event is triggered", ->
it "attaches and then detaches the view", ->
expect(atom.workspaceView.find('.project-ring')).not.toExist()

# This is an activation event, triggering it will cause the package to be
# activated.
atom.workspaceView.trigger 'project-ring:toggle'

it "reports that it need a proper spec", ->
waitsForPromise ->
activationPromise

runs ->
expect(atom.workspaceView.find('.project-ring')).toExist()
atom.workspaceView.trigger 'project-ring:toggle'
expect(atom.workspaceView.find('.project-ring')).not.toExist()
alert 'I need a proper spec!'
5 changes: 0 additions & 5 deletions spec/project-ring-view-spec.coffee

This file was deleted.

File renamed without changes.

0 comments on commit 80120c3

Please sign in to comment.