Consume File-Icons' element-icon service
DELETE
lib/file-icons.coffee
-DefaultFileIcons = require './default-file-icons'
-
-class FileIcons
- constructor: ->
- @service = new DefaultFileIcons
-
- getService: ->
- @service
-
- resetService: ->
- @service = new DefaultFileIcons
-
- setService: (@service) ->
-
-module.exports = new FileIcons

MODIFY
lib/find.coffee
lib/find.coffee
@@ -4,7 +4,7 @@ SelectNext = require './select-next'
{History, HistoryCycler} = require './history'
FindOptions = require './find-options'
BufferSearch = require './buffer-search'
-FileIcons = require './file-icons'
+IconServices = require './icon-services'
FindView = require './find-view'
ProjectFindView = require './project-find-view'
ResultsModel = require './project/results-model'
@@ -117,10 +117,15 @@ module.exports =
'find-and-replace:select-skip': (event) ->
selectNextObjectForEditorElement(this).skipCurrentSelection()
+ consumeElementIcons: (service) ->
+ IconServices.set 'element-icons', service
+ new Disposable =>
+ IconServices.reset 'element-icons'
+
consumeFileIcons: (service) ->
- FileIcons.setService service
+ IconServices.set 'file-icons', service
new Disposable ->
- FileIcons.resetService()
+ IconServices.reset 'file-icons'
provideService: ->
resultsMarkerLayerForTextEditor: @findModel.resultsMarkerLayerForTextEditor.bind(@findModel)

ADD
lib/icon-services.coffee
+DefaultFileIcons = require './default-file-icons'
+{Emitter} = require 'atom'
+
+defaultServices =
+ 'file-icons': new DefaultFileIcons
+ 'element-icons': null
+
+class IconServices
+ constructor: ->
+ @emitter = new Emitter()
+ @activeServices = Object.assign {}, defaultServices
+
+ get: (name) ->
+ @activeServices[name] or defaultServices[name]
+
+ reset: (name) ->
+ @set name, defaultServices[name]
+
+ set: (name, service) ->
+ if service isnt @activeServices[name]
+ @activeServices[name] = service
+ @emitter.emit 'did-change'
+
+ onDidChange: (callback) ->
+ @emitter.on 'did-change', callback
+
+module.exports = new IconServices

MODIFY
lib/project/result-view.js
lib/project/result-view.js
-const FileIcons = require('../file-icons');
+const {CompositeDisposable} = require('atom');
+const IconServices = require('../icon-services');
const MatchView = require('./match-view');
const path = require('path');
const etch = require('etch');
@@ -28,6 +29,14 @@ class ResultView {
etch.initialize(this);
}
+ destroy() {
+ if (this.iconDisposable) {
+ this.iconDisposable.dispose()
+ this.iconDisposable = null
+ }
+ return etch.destroy(this)
+ }
+
update({item, top, bottom} = {}) {
const {
filePath, matches, isSelected, selectedMatchIndex, isExpanded,
@@ -65,9 +74,18 @@ class ResultView {
}
render() {
- let iconClass = FileIcons.getService().iconClassForPath(this.filePath, "find-and-replace");
- if (!iconClass) iconClass = [];
- if (!Array.isArray(iconClass)) iconClass = iconClass.toString().split(/\s+/g);
+ let iconClass = ''
+ const addIconToElement = IconServices.get('element-icons')
+
+ if (!this.iconDisposable && addIconToElement) {
+ this.iconDisposable = new CompositeDisposable()
+ process.nextTick(() => {
+ this.iconDisposable.add(addIconToElement(this.refs.icon, this.filePath))
+ })
+ } else {
+ const iconService = IconServices.get('file-icons')
+ iconClass = iconService.iconClassForPath(this.filePath, 'find-and-replace') || ''
+ }
let relativePath = this.filePath;
if (atom.project) {
@@ -83,6 +101,10 @@ class ResultView {
this.selectedMatchIndex === -1
);
+ iconClass = Array.isArray(iconClass)
+ ? iconClass.join(' ')
+ : iconClass.toString()
+
return (
$.li(
{
@@ -99,7 +121,8 @@ class ResultView {
$.div({ref: 'pathDetails', className: 'path-details list-item'},
$.span({className: 'disclosure-arrow'}),
$.span({
- className: iconClass.join(' ') + ' icon',
+ ref: 'icon',
+ className: iconClass + ' icon',
dataset: {name: path.basename(this.filePath)}
}),
$.span({className: 'path-name bright'},

MODIFY
package.json
package.json
"versions": {
"1.0.0": "consumeFileIcons"
}
+ },
+ "file-icons.element-icons": {
+ "versions": {
+ "1.0.0": "consumeElementIcons"
+ }
}
},
"providedServices": {

MODIFY
spec/results-view-spec.js
spec/results-view-spec.js
@@ -5,7 +5,7 @@ const path = require('path');
const temp = require("temp");
const etch = require('etch');
const ResultsPaneView = require('../lib/project/results-pane');
-const FileIcons = require('../lib/file-icons');
+const IconServices = require('../lib/icon-services');
const {beforeEach, it, fit, ffit, fffit} = require('./async-spec-helpers')
global.beforeEach(function() {

Consume File-Icons' element-icon service