Amend revisions requested in atom/tree-view#1146
DELETE
lib/default-file-icons.coffee
-fs = require 'fs-plus'
-path = require 'path'
-
-class DefaultFileIcons
- iconClassForPath: (filePath) ->
- extension = path.extname(filePath)
-
- if fs.isSymbolicLinkSync(filePath)
- 'icon-file-symlink-file'
- else if fs.isReadmePath(filePath)
- 'icon-book'
- else if fs.isCompressedExtension(extension)
- 'icon-file-zip'
- else if fs.isImageExtension(extension)
- 'icon-file-media'
- else if fs.isPdfExtension(extension)
- 'icon-file-pdf'
- else if fs.isBinaryExtension(extension)
- 'icon-file-binary'
- else
- 'icon-file-text'
-
-module.exports = DefaultFileIcons

ADD
lib/default-file-icons.js
+const fs = require('fs-plus')
+const path = require('path')
+
+class DefaultFileIcons {
+ iconClassForPath (filePath) {
+ const extension = path.extname(filePath)
+
+ if (fs.isSymbolicLinkSync(filePath)) {
+ return 'icon-file-symlink-file'
+ } else if (fs.isReadmePath(filePath)) {
+ return 'icon-book'
+ } else if (fs.isCompressedExtension(extension)) {
+ return 'icon-file-zip'
+ } else if (fs.isImageExtension(extension)) {
+ return 'icon-file-media'
+ } else if (fs.isPdfExtension(extension)) {
+ return 'icon-file-pdf'
+ } else if (fs.isBinaryExtension(extension)) {
+ return 'icon-file-binary'
+ } else {
+ return 'icon-file-text'
+ }
+ }
+}
+
+module.exports = new DefaultFileIcons()

MODIFY
lib/find.coffee
lib/find.coffee
@@ -118,14 +118,14 @@ module.exports =
selectNextObjectForEditorElement(this).skipCurrentSelection()
consumeElementIcons: (service) ->
- IconServices.set 'element-icons', service
+ IconServices.setElementIcons service
new Disposable =>
- IconServices.reset 'element-icons'
+ IconServices.resetElementIcons()
consumeFileIcons: (service) ->
- IconServices.set 'file-icons', service
+ IconServices.setFileIcons service
new Disposable ->
- IconServices.reset 'file-icons'
+ IconServices.resetFileIcons()
toggleAutocompletions: (value) ->
if not @findView?

DELETE
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

ADD
lib/icon-services.js
+const DefaultFileIcons = require('./default-file-icons')
+const {Emitter, CompositeDisposable} = require('atom')
+
+class IconServices {
+ constructor () {
+ this.emitter = new Emitter()
+ this.elementIcons = null
+ this.elementIconDisposables = new CompositeDisposable()
+ this.fileIcons = DefaultFileIcons
+ }
+
+ onDidChange (callback) {
+ return this.emitter.on('did-change', callback)
+ }
+
+ resetElementIcons () {
+ this.setElementIcons(null)
+ }
+
+ resetFileIcons () {
+ this.setFileIcons(DefaultFileIcons)
+ }
+
+ setElementIcons (service) {
+ if (service !== this.elementIcons) {
+ if (this.elementIconDisposables != null) {
+ this.elementIconDisposables.dispose()
+ }
+ if (service) { this.elementIconDisposables = new CompositeDisposable() }
+ this.elementIcons = service
+ return this.emitter.emit('did-change')
+ }
+ }
+
+ setFileIcons (service) {
+ if (service !== this.fileIcons) {
+ this.fileIcons = service
+ return this.emitter.emit('did-change')
+ }
+ }
+
+ getIconClasses (view) {
+ let iconClass = ''
+ if (this.elementIcons) {
+ if (!view.iconDisposable) {
+ view.iconDisposable = new CompositeDisposable()
+ }
+ process.nextTick(() => {
+ view.iconDisposable.add(this.elementIcons(view.refs.icon, view.filePath))
+ })
+ } else {
+ iconClass = this.fileIcons.iconClassForPath(view.filePath, 'find-and-replace') || ''
+ if (Array.isArray(iconClass)) {
+ iconClass = iconClass.join(' ')
+ }
+ }
+ return iconClass
+ }
+}
+
+module.exports = new IconServices()

MODIFY
lib/project/result-view.js
lib/project/result-view.js
-const {CompositeDisposable} = require('atom');
const IconServices = require('../icon-services');
const MatchView = require('./match-view');
const path = require('path');
@@ -85,19 +84,6 @@ class ResultView {
}
render() {
- 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) {
let rootPath;
@@ -112,9 +98,7 @@ class ResultView {
this.selectedMatchIndex === -1
);
- iconClass = Array.isArray(iconClass)
- ? iconClass.join(' ')
- : iconClass.toString()
+ const iconClass = IconServices.getIconClasses(this)
return (
$.li(

Amend revisions requested in atom/tree-view#1146