From 8454a05bb314b3347f2237c5783908c5eb106efb Mon Sep 17 00:00:00 2001 From: Alhadis Date: Thu, 14 Apr 2016 17:52:15 +1000 Subject: [PATCH] Fix #193: Tab icons not updating when renaming extensions --- CHANGELOG.md | 4 ++++ index.coffee | 28 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e2c77e2..69ce43d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). - **Support:** `.ad`, `.am`, `.desktop`, `.directory`, `.ebuild`, `.install`, `.m4`, `.menu`, `_osc`, `PKGBUILD`, `.sed`, `_service`, `.spacemacs` - Support for numerous GNU Automake/Autoconf files +### Fixed +- [[`#193`](https://github.com/DanBrooker/file-icons/issues/193)] Tab icons now update when changing file extensions +- [[`#316`](https://github.com/DanBrooker/file-icons/issues/316)] Newly-saved files now display icons in tab + [1.7.1] - 2016-04-05 -------------------- diff --git a/index.coffee b/index.coffee index c494aa45..42068ffc 100644 --- a/index.coffee +++ b/index.coffee @@ -49,24 +49,44 @@ module.exports = observe: (enabled) -> + + # Setting up observers if enabled @observer = atom.workspace.observeTextEditors (editor) -> + workspace = atom.views.getView(atom.workspace) + openedFile = editor.getPath() # New file - if not editor.getFileName()? + unless openedFile onSave = editor.onDidSave (file) -> - pane = atom.views.getView(atom.workspace.getActivePane()) - tab = pane?.querySelector(".tab-bar > .active.tab > .title") + tab = workspace?.querySelector(".tab-bar > .active.tab > .title") # Patch data-* attributes to fix missing tab-icon - if not tab.dataset.path + if not tab?.dataset.path {path} = file tab.dataset.path = path tab.dataset.name = basename path # Remove the listener onSave.dispose() + + # Existing file: wait for pane to finish loading before querying the DOM + else + onDone = editor.onDidStopChanging () -> + tabs = workspace?.querySelectorAll(".pane > .tab-bar > .tab") + fileTabs = [].filter.call tabs, (tab) -> tab?.item is editor + + # When a file's been renamed, patch the dataset of each tab that has it open + editor.onDidChangePath (path) => + for tab in fileTabs + title = tab.itemTitle + title.dataset.path = path + title.dataset.name = basename path + # Drop the registration listener + onDone.dispose() + + # Disable observers if deactivating package else if @observer? @observer.dispose()