Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
support updating the icon status from packages
Browse files Browse the repository at this point in the history
  • Loading branch information
philschatz committed Nov 23, 2015
1 parent 01ad2a9 commit 325e849
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/directory-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class DirectoryView extends HTMLElement
else
@draggable = true
@subscriptions.add @directory.onDidStatusChange => @updateStatus()
@subscriptions.add @directory.onDidIconStatusChange (iconStatus) =>
@updateIconStatus(iconStatus)
@updateStatus()

@expand() if @directory.expansionState.isExpanded
Expand All @@ -60,6 +62,12 @@ class DirectoryView extends HTMLElement
@classList.remove('status-ignored', 'status-modified', 'status-added')
@classList.add("status-#{@directory.status}") if @directory.status?

updateIconStatus: (newIconStatus) ->
if newIconStatus isnt @iconStatus and @iconStatus
@classList.remove(@iconStatus)
@classList.add(newIconStatus) if newIconStatus
@iconStatus = newIconStatus

subscribeToDirectory: ->
@subscriptions.add @directory.onDidAddEntries (addedEntries) =>
return unless @isExpanded
Expand Down
8 changes: 8 additions & 0 deletions lib/directory.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Directory
onDidStatusChange: (callback) ->
@emitter.on('did-status-change', callback)

onDidIconStatusChange: (callback) ->
@emitter.on('did-icon-status-change', callback)

onDidAddEntries: (callback) ->
@emitter.on('did-add-entries', callback)

Expand Down Expand Up @@ -91,6 +94,11 @@ class Directory
@status = newStatus
@emitter.emit('did-status-change', newStatus)

updateIconStatus: (newIconStatus) ->
if newIconStatus isnt @iconStatus
@iconStatus = newIconStatus
@emitter.emit('did-icon-status-change', newIconStatus)

# Is the given path ignored?
isPathIgnored: (filePath) ->
if atom.config.get('tree-view.hideVcsIgnoredFiles')
Expand Down
7 changes: 7 additions & 0 deletions lib/file-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ class FileView extends HTMLElement
@fileName.classList.add(FileIcons.getService().iconClassForPath(@file.path))

@subscriptions.add @file.onDidStatusChange => @updateStatus()
@subscriptions.add @file.onDidIconStatusChange (iconStatus) => @updateIconStatus(iconStatus)
@updateStatus()

updateStatus: ->
@classList.remove('status-ignored', 'status-modified', 'status-added')
@classList.add("status-#{@file.status}") if @file.status?

updateIconStatus: (newIconStatus) ->
if newIconStatus isnt @iconStatus and @iconStatus
@classList.remove(@iconStatus)
@classList.add(newIconStatus) if newIconStatus
@iconStatus = newIconStatus

getPath: ->
@fileName.dataset.path

Expand Down
8 changes: 8 additions & 0 deletions lib/file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class File
onDidStatusChange: (callback) ->
@emitter.on('did-status-change', callback)

onDidIconStatusChange: (callback) ->
@emitter.on('did-icon-status-change', callback)

# Subscribe to the project' repo for changes to the Git status of this file.
subscribeToRepo: ->
repo = repoForPath(@path)
Expand Down Expand Up @@ -62,5 +65,10 @@ class File
@status = newStatus
@emitter.emit('did-status-change', newStatus)

updateIconStatus: (newIconStatus) ->
if newIconStatus isnt @iconStatus
@iconStatus = newIconStatus
@emitter.emit('did-icon-status-change', newIconStatus)

isPathEqual: (pathToCompare) ->
@path is pathToCompare or @realPath is pathToCompare
38 changes: 38 additions & 0 deletions spec/tree-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2784,3 +2784,41 @@ describe "TreeView", ->

runs ->
expect($(treeView.roots[0].entries).find('.directory:contains(alpha):first .entry').length).toBe 3

describe "async icon status change", ->
it "adds a status class on a Directory", ->
dir1 = treeView.find('.directory:contains(dir1)').last()
expect(dir1.hasClass('test-status')).toBe(false)
dir1[0].directory.updateIconStatus('test-status')
expect(dir1.hasClass('test-status')).toBe(true)

it "updates a status class on a Directory", ->
dir1 = treeView.find('.directory:contains(dir1)').last()
dir1[0].directory.updateIconStatus('test-status1')
dir1[0].directory.updateIconStatus('test-status2')
expect(dir1.hasClass('test-status1')).toBe(false)
expect(dir1.hasClass('test-status2')).toBe(true)

it "clears a status class on a Directory", ->
dir1 = treeView.find('.directory:contains(dir1)').last()
dir1[0].directory.updateIconStatus('test-status1')
dir1[0].directory.updateIconStatus(null)
expect(dir1.hasClass('test-status1')).toBe(false)
expect(dir1.hasClass('null')).toBe(false)

it "adds a status class on a File", ->
expect(sampleJs.hasClass('test-status')).toBe(false)
sampleJs[0].file.updateIconStatus('test-status')
expect(sampleJs.hasClass('test-status')).toBe(true)

it "updates a status class on a File", ->
sampleJs[0].file.updateIconStatus('test-status1')
sampleJs[0].file.updateIconStatus('test-status2')
expect(sampleJs.hasClass('test-status1')).toBe(false)
expect(sampleJs.hasClass('test-status2')).toBe(true)

it "clears a status class on a File", ->
sampleJs[0].file.updateIconStatus('test-status1')
sampleJs[0].file.updateIconStatus(null)
expect(sampleJs.hasClass('test-status1')).toBe(false)
expect(sampleJs.hasClass('null')).toBe(false)

0 comments on commit 325e849

Please sign in to comment.