From e1f4b7415acc3ad5a252b4e83c1f37ea5926585d Mon Sep 17 00:00:00 2001 From: Desmond Brand Date: Sun, 3 Aug 2014 17:14:17 -0700 Subject: [PATCH 1/4] Add OS X proxy icon to title bar Fixes #1891. Test Plan: * Opened Atom window in directory, verified directory icon shows up * Opened a file and verified icon changed * Right clicked icon, verified menu appears * Drag file to terminal and it pastes the file path (yay) * Opened a new Atom window and opened some files in that to make sure that it didn't change the original window I didn't add any specs for this - advice welcome here. I also haven't tested on Windows or Linux but it looks like `setRepresentedFilename` is a noop on those platforms. --- src/workspace-view.coffee | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index 4206e9f83..e1b8a81ae 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -210,19 +210,23 @@ class WorkspaceView extends View confirmClose: -> @panes.confirmClose() - # Updates the application's title, based on whichever file is open. + # Updates the application's title and proxy icon based on whichever file is + # open. updateTitle: -> if projectPath = atom.project.getPath() if item = @getModel().getActivePaneItem() - @setTitle("#{item.getTitle?() ? 'untitled'} - #{projectPath}") + title = "#{item.getTitle?() ? 'untitled'} - #{projectPath}" + path = item.getPath?() ? projectPath + @setTitle(title, path) else - @setTitle(projectPath) + @setTitle(projectPath, projectPath) else @setTitle('untitled') - # Sets the application's title. - setTitle: (title) -> + # Sets the application's title (and the proxy icon on OS X) + setTitle: (title, path) -> document.title = title + atom.getCurrentWindow().setRepresentedFilename(path ? '') # Get all editor views. # From bd8ac3bb32403d4f44d9a9f186bd99d9e99451d5 Mon Sep 17 00:00:00 2001 From: Desmond Brand Date: Mon, 4 Aug 2014 11:27:47 -0700 Subject: [PATCH 2/4] path -> proxyIconPath Test plan: Crossed fingers --- src/workspace-view.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index e1b8a81ae..939630fdc 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -216,17 +216,17 @@ class WorkspaceView extends View if projectPath = atom.project.getPath() if item = @getModel().getActivePaneItem() title = "#{item.getTitle?() ? 'untitled'} - #{projectPath}" - path = item.getPath?() ? projectPath - @setTitle(title, path) + proxyIconPath = item.getPath?() ? projectPath + @setTitle(title, proxyIconPath) else @setTitle(projectPath, projectPath) else @setTitle('untitled') # Sets the application's title (and the proxy icon on OS X) - setTitle: (title, path) -> + setTitle: (title, proxyIconPath) -> document.title = title - atom.getCurrentWindow().setRepresentedFilename(path ? '') + atom.getCurrentWindow().setRepresentedFilename(proxyIconPath ? '') # Get all editor views. # From d16c0e9e414ce48928e0b72108f30cea839ed5f7 Mon Sep 17 00:00:00 2001 From: Desmond Brand Date: Mon, 4 Aug 2014 20:45:24 -0700 Subject: [PATCH 3/4] Implement setDocumentEdited too As requested by @philipgiuliani Test Plan: Opened an existing file and made a modification. The icon fades at the same time the tab close button changes to a circle. Undo makes the icon opaque again. --- src/pane-view.coffee | 12 ++++++++++-- src/workspace-view.coffee | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pane-view.coffee b/src/pane-view.coffee index d5644f652..97b28b2b8 100644 --- a/src/pane-view.coffee +++ b/src/pane-view.coffee @@ -141,13 +141,18 @@ class PaneView extends View @activeItem onActiveItemChanged: (item) => - @previousActiveItem?.off? 'title-changed', @activeItemTitleChanged + if @previousActiveItem?.off? + @previousActiveItem.off 'title-changed', @activeItemTitleChanged + @previousActiveItem.off 'modified-status-changed', + @activeItemModifiedChanged @previousActiveItem = item return unless item? hasFocus = @hasFocus() - item.on? 'title-changed', @activeItemTitleChanged + if item.on? + item.on 'title-changed', @activeItemTitleChanged + item.on 'modified-status-changed', @activeItemModifiedChanged view = @viewForItem(item) otherView.hide() for otherView in @itemViews.children().not(view).views() @itemViews.append(view) unless view.parent().is(@itemViews) @@ -183,6 +188,9 @@ class PaneView extends View activeItemTitleChanged: => @trigger 'pane:active-item-title-changed' + activeItemModifiedChanged: => + @trigger 'pane:active-item-modified-changed' + viewForItem: (item) -> return unless item? if item instanceof $ diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index 939630fdc..d38c5eda0 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -110,6 +110,7 @@ class WorkspaceView extends View atom.project.on 'path-changed', => @updateTitle() @on 'pane-container:active-pane-item-changed', => @updateTitle() @on 'pane:active-item-title-changed', '.active.pane', => @updateTitle() + @on 'pane:active-item-modified-changed', '.active.pane', => @updateDocumentEdited() @command 'application:about', -> ipc.send('command', 'application:about') @command 'application:run-all-specs', -> ipc.send('command', 'application:run-all-specs') @@ -228,6 +229,12 @@ class WorkspaceView extends View document.title = title atom.getCurrentWindow().setRepresentedFilename(proxyIconPath ? '') + # On OS X, fades the application window's proxy icon when the current file + # has been modified. + updateDocumentEdited: -> + modified = @getModel().getActivePaneItem()?.isModified?() ? false + atom.getCurrentWindow().setDocumentEdited modified + # Get all editor views. # # You should prefer {Workspace::getEditors} unless you absolutely need access From d5e30e83f63007dd66c345ba5b4839887a7c5168 Mon Sep 17 00:00:00 2001 From: Desmond Brand Date: Mon, 4 Aug 2014 20:51:37 -0700 Subject: [PATCH 4/4] Don't use project path as fallback icon for item with no path Stops the project folder icon appearing in places that don't make sense like settings and new files. Test Plan: * Opened settings and didn't see the project folder icon * Closed all tabs and saw the project folder icon --- src/workspace-view.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index d38c5eda0..1c068ea38 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -217,7 +217,7 @@ class WorkspaceView extends View if projectPath = atom.project.getPath() if item = @getModel().getActivePaneItem() title = "#{item.getTitle?() ? 'untitled'} - #{projectPath}" - proxyIconPath = item.getPath?() ? projectPath + proxyIconPath = item.getPath?() ? '' @setTitle(title, proxyIconPath) else @setTitle(projectPath, projectPath)