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

Commit

Permalink
Revert "Merge pull request #870 from Cutlery-Drawer/file-icons"
Browse files Browse the repository at this point in the history
This reverts commit 10808e1, reversing
changes made to a3b2eba.
  • Loading branch information
okbel committed Nov 10, 2017
1 parent b212652 commit d1f9e81
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 229 deletions.
23 changes: 23 additions & 0 deletions lib/default-file-icons.coffee
@@ -0,0 +1,23 @@
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
26 changes: 0 additions & 26 deletions lib/default-file-icons.js

This file was deleted.

15 changes: 15 additions & 0 deletions lib/file-icons.coffee
@@ -0,0 +1,15 @@
DefaultFileIcons = require './default-file-icons'

class FileIcons
constructor: ->
@service = new DefaultFileIcons

getService: ->
@service

resetService: ->
@service = new DefaultFileIcons

setService: (@service) ->

module.exports = new FileIcons
11 changes: 3 additions & 8 deletions lib/find.coffee
Expand Up @@ -4,7 +4,7 @@ SelectNext = require './select-next'
{History, HistoryCycler} = require './history'
FindOptions = require './find-options'
BufferSearch = require './buffer-search'
getIconServices = require './get-icon-services'
FileIcons = require './file-icons'
FindView = require './find-view'
ProjectFindView = require './project-find-view'
ResultsModel = require './project/results-model'
Expand Down Expand Up @@ -117,15 +117,10 @@ module.exports =
'find-and-replace:select-skip': (event) ->
selectNextObjectForEditorElement(this).skipCurrentSelection()

consumeElementIcons: (service) ->
getIconServices().setElementIcons service
new Disposable =>
getIconServices().resetElementIcons()

consumeFileIcons: (service) ->
getIconServices().setFileIcons service
FileIcons.setService service
new Disposable ->
getIconServices().resetFileIcons()
FileIcons.resetService()

toggleAutocompletions: (value) ->
if not @findView?
Expand Down
65 changes: 0 additions & 65 deletions lib/get-icon-services.js

This file was deleted.

21 changes: 7 additions & 14 deletions lib/project/result-view.js
@@ -1,4 +1,4 @@
const getIconServices = require('../get-icon-services');
const FileIcons = require('../file-icons');
const MatchView = require('./match-view');
const path = require('path');
const etch = require('etch');
Expand Down Expand Up @@ -32,14 +32,6 @@ 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, regex,
Expand Down Expand Up @@ -84,6 +76,10 @@ 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 relativePath = this.filePath;
if (atom.project) {
let rootPath;
Expand All @@ -97,9 +93,7 @@ class ResultView {
!this.isExpanded ||
this.selectedMatchIndex === -1
);

const iconClass = getIconServices().getIconClasses(this)


return (
$.li(
{
Expand All @@ -116,8 +110,7 @@ class ResultView {
$.div({ref: 'pathDetails', className: 'path-details list-item'},
$.span({className: 'disclosure-arrow'}),
$.span({
ref: 'icon',
className: iconClass + ' icon',
className: iconClass.join(' ') + ' icon',
dataset: {name: path.basename(this.filePath)}
}),
$.span({className: 'path-name bright'},
Expand Down
5 changes: 0 additions & 5 deletions package.json
Expand Up @@ -50,11 +50,6 @@
"versions": {
"1.0.0": "consumeAutocompleteWatchEditor"
}
},
"file-icons.element-icons": {
"versions": {
"1.0.0": "consumeElementIcons"
}
}
},
"providedServices": {
Expand Down
140 changes: 29 additions & 111 deletions spec/results-view-spec.js
Expand Up @@ -6,9 +6,7 @@ const temp = require('temp');
const fs = require('fs');
const etch = require('etch');
const ResultsPaneView = require('../lib/project/results-pane');
const getIconServices = require('../lib/get-icon-services');
const DefaultFileIcons = require('../lib/default-file-icons');
const {Disposable} = require('atom')
const FileIcons = require('../lib/file-icons');
const {beforeEach, it, fit, ffit, fffit} = require('./async-spec-helpers')

global.beforeEach(function() {
Expand Down Expand Up @@ -670,115 +668,41 @@ describe('ResultsView', () => {
})
});

describe('icon services', () => {
describe('atom.file-icons', () => {
it('has a default handler', () => {
expect(getIconServices().fileIcons).toBe(DefaultFileIcons)
})

it('displays icons for common filetypes', () => {
expect(DefaultFileIcons.iconClassForPath('README.md')).toBe('icon-book')
expect(DefaultFileIcons.iconClassForPath('zip.zip')).toBe('icon-file-zip')
expect(DefaultFileIcons.iconClassForPath('a.gif')).toBe('icon-file-media')
expect(DefaultFileIcons.iconClassForPath('a.pdf')).toBe('icon-file-pdf')
expect(DefaultFileIcons.iconClassForPath('an.exe')).toBe('icon-file-binary')
expect(DefaultFileIcons.iconClassForPath('jg.js')).toBe('icon-file-text')
})

it('allows a service provider to change the handler', async () => {
const provider = {
iconClassForPath(path, context) {
expect(context).toBe('find-and-replace')
return (path.endsWith('one-long-line.coffee'))
? 'first-icon-class second-icon-class'
: ['third-icon-class', 'fourth-icon-class']
describe("icon-service lifecycle", () => {
it('renders file icon classes based on the provided file-icons service', async () => {
const fileIconsDisposable = atom.packages.serviceHub.provide('atom.file-icons', '1.0.0', {
iconClassForPath(path, context) {
expect(context).toBe("find-and-replace");
if (path.endsWith('one-long-line.coffee')) {
return "first-icon-class second-icon-class";
} else {
return ['third-icon-class', 'fourth-icon-class'];
}
}
const disposable = atom.packages.serviceHub.provide('atom.file-icons', '1.0.0', provider);
expect(getIconServices().fileIcons).toBe(provider)

projectFindView.findEditor.setText('i');
atom.commands.dispatch(projectFindView.element, 'core:confirm');
await searchPromise;

resultsView = getResultsView();
let fileIconClasses = Array.from(resultsView.element.querySelectorAll('.path-details .icon')).map(el => el.className);
expect(fileIconClasses).toContain('first-icon-class second-icon-class icon');
expect(fileIconClasses).toContain('third-icon-class fourth-icon-class icon');
expect(fileIconClasses).not.toContain('icon-file-text icon');

disposable.dispose();
projectFindView.findEditor.setText('e');
atom.commands.dispatch(projectFindView.element, 'core:confirm');

await searchPromise;
resultsView = getResultsView();
fileIconClasses = Array.from(resultsView.element.querySelectorAll('.path-details .icon')).map(el => el.className);
expect(fileIconClasses).not.toContain('first-icon-class second-icon-class icon');
expect(fileIconClasses).not.toContain('third-icon-class fourth-icon-class icon');
expect(fileIconClasses).toContain('icon-file-text icon');
})
})

describe('file-icons.element-icons', () => {
beforeEach(() => jasmine.useRealClock())

it('has no default handler', () => {
expect(getIconServices().elementIcons).toBe(null)
})

it('uses the element-icon service if available', () => {
const iconSelector = '.path-details .icon:not([data-name="fake-file-path"])'
const provider = (element, path) => {
expect(element).toBeInstanceOf(HTMLElement)
expect(typeof path === "string").toBe(true)
expect(path.length).toBeGreaterThan(0)
const classes = path.endsWith('one-long-line.coffee')
? ['foo', 'bar']
: ['baz', 'qlux']
element.classList.add(...classes)
return new Disposable(() => {
element.classList.remove(...classes)
})
}
let disposable

waitsForPromise(() => {
disposable = atom.packages.serviceHub.provide('file-icons.element-icons', '1.0.0', provider)
expect(getIconServices().elementIcons).toBe(provider)
projectFindView.findEditor.setText('i');
atom.commands.dispatch(projectFindView.element, 'core:confirm');
return searchPromise
})

waitsForPromise(() => delayFor(35))

runs(() => {
resultsView = getResultsView()
const iconElements = resultsView.element.querySelectorAll(iconSelector)
expect(iconElements[0].className.trim()).toBe('icon foo bar')
expect(iconElements[1].className.trim()).toBe('icon baz qlux')
expect(resultsView.element.querySelector('.icon-file-text')).toBe(null)
});

disposable.dispose()
projectFindView.findEditor.setText('e')
atom.commands.dispatch(projectFindView.element, 'core:confirm')
})
projectFindView.findEditor.setText('i');
atom.commands.dispatch(projectFindView.element, 'core:confirm');
await searchPromise;

waitsForPromise(() => searchPromise)
resultsView = getResultsView();
let fileIconClasses = Array.from(resultsView.element.querySelectorAll('.path-details .icon')).map(el => el.className);
expect(fileIconClasses).toContain('first-icon-class second-icon-class icon');
expect(fileIconClasses).toContain('third-icon-class fourth-icon-class icon');
expect(fileIconClasses).not.toContain('icon-file-text icon');

waitsForPromise(() => delayFor(35))
fileIconsDisposable.dispose();
projectFindView.findEditor.setText('e');
atom.commands.dispatch(projectFindView.element, 'core:confirm');

runs(() => {
resultsView = getResultsView()
const iconElements = resultsView.element.querySelectorAll(iconSelector)
expect(iconElements[0].className.trim()).toBe('icon-file-text icon')
expect(iconElements[1].className.trim()).toBe('icon-file-text icon')
expect(resultsView.element.querySelector('.foo, .bar, .baz, .qlux')).toBe(null)
})
})
await searchPromise;
resultsView = getResultsView();
fileIconClasses = Array.from(resultsView.element.querySelectorAll('.path-details .icon')).map(el => el.className);
expect(fileIconClasses).not.toContain('first-icon-class second-icon-class icon');
expect(fileIconClasses).not.toContain('third-icon-class fourth-icon-class icon');
expect(fileIconClasses).toContain('icon-file-text icon');
})
})
});

describe('updating the search while viewing results', () => {
it('resets the results message', async () => {
Expand Down Expand Up @@ -996,9 +920,3 @@ function buildMouseEvent(type, properties) {
function clickOn(element) {
element.dispatchEvent(buildMouseEvent('mousedown', { detail: 1 }));
}

function delayFor(ms) {
return new Promise(done => {
setTimeout(() => done(), ms)
})
}

0 comments on commit d1f9e81

Please sign in to comment.