From 325e849a462e488f587370437d92292d35876aa9 Mon Sep 17 00:00:00 2001 From: Philip Schatz Date: Mon, 23 Nov 2015 11:04:11 -0500 Subject: [PATCH] support updating the icon status from packages --- lib/directory-view.coffee | 8 ++++++++ lib/directory.coffee | 8 ++++++++ lib/file-view.coffee | 7 +++++++ lib/file.coffee | 8 ++++++++ spec/tree-view-spec.coffee | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+) diff --git a/lib/directory-view.coffee b/lib/directory-view.coffee index 784c64f2..3c415c9f 100644 --- a/lib/directory-view.coffee +++ b/lib/directory-view.coffee @@ -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 @@ -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 diff --git a/lib/directory.coffee b/lib/directory.coffee index 73e0ed84..482cb66a 100644 --- a/lib/directory.coffee +++ b/lib/directory.coffee @@ -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) @@ -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') diff --git a/lib/file-view.coffee b/lib/file-view.coffee index dc65a1c9..2a92cd29 100644 --- a/lib/file-view.coffee +++ b/lib/file-view.coffee @@ -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 diff --git a/lib/file.coffee b/lib/file.coffee index 657839a5..f2889beb 100644 --- a/lib/file.coffee +++ b/lib/file.coffee @@ -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) @@ -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 diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index 5051a90a..42025be6 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -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)