From 02dcc82bdf2ba1b110100786892ce31d9463b5e8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Aug 2016 08:30:29 +0200 Subject: [PATCH 1/4] add getLongTitle --- lib/image-editor.coffee | 56 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/image-editor.coffee b/lib/image-editor.coffee index 41c86d2..959121a 100644 --- a/lib/image-editor.coffee +++ b/lib/image-editor.coffee @@ -1,3 +1,4 @@ +_ = require 'underscore-plus' path = require 'path' fs = require 'fs-plus' {Emitter, File, CompositeDisposable} = require 'atom' @@ -52,10 +53,63 @@ class ImageEditor # # Returns a {String}. getTitle: -> + @getFileName() ? 'untitled' + + # Retireves all ImageEditors in the workspace. + # + # Returns an {Array} of {ImageEditors}. + getImageEditors: -> + atom.workspace.getPaneItems().filter (item) -> item instanceof ImageEditor + + # Essential: Get unique title for display in other parts of the UI, such as + # the window title. + # + # If the editor's buffer is unsaved, its title is "untitled" + # If the editor's buffer is saved, its unique title is formatted as one + # of the following, + # * "" when it is the only editing buffer with this file name. + # * "" when other buffers have this file name. + # + # Returns a {String} + getLongTitle: -> + if @getPath() + fileName = @getFileName() + + allPathSegments = [] + for imageEditor in @getImageEditors() when imageEditor isnt this + if imageEditor.getFileName() is fileName + allPathSegments.push(imageEditor.getDirectoryPath().split(path.sep)) + + if allPathSegments.length is 0 + return fileName + + ourPathSegments = @getDirectoryPath().split(path.sep) + allPathSegments.push ourPathSegments + + loop + firstSegment = ourPathSegments[0] + + commonBase = _.all(allPathSegments, (pathSegments) -> pathSegments.length > 1 and pathSegments[0] is firstSegment) + if commonBase + pathSegments.shift() for pathSegments in allPathSegments + else + break + + "#{fileName} \u2014 #{path.join(pathSegments...)}" + else + 'untitled' + + getFileName: -> if filePath = @getPath() path.basename(filePath) else - 'untitled' + null + + getDirectoryPath: -> + if fullPath = @getPath() + path.dirname(fullPath) + else + null # Retrieves the URI of the image. # From d224f459218e0513dd41a5a6017a90f87f6339fe Mon Sep 17 00:00:00 2001 From: bene Date: Wed, 31 Aug 2016 21:57:30 +0200 Subject: [PATCH 2/4] :memo: update documentation --- lib/image-editor.coffee | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/image-editor.coffee b/lib/image-editor.coffee index 959121a..c41a6f4 100644 --- a/lib/image-editor.coffee +++ b/lib/image-editor.coffee @@ -38,7 +38,7 @@ class ImageEditor @subscriptions.add(changeSubscription) changeSubscription - # Register a callback for whne the image's title changes + # Register a callback for when the image's title changes onDidChangeTitle: (callback) -> renameSubscription = @file.onDidRename(callback) @subscriptions.add(renameSubscription) @@ -47,28 +47,29 @@ class ImageEditor destroy: -> @subscriptions.dispose() - # Retrieves the filename of the open file. + # Essential: Retireves all {ImageEditor}s in the workspace. # - # This is `'untitled'` if the file is new and not saved to the disk. + # Returns an {Array} of {ImageEditor}s. + getImageEditors: -> + atom.workspace.getPaneItems().filter (item) -> item instanceof ImageEditor + + # Essential: Get the {ImageEditor}s title for display in other parts + # of the UI such as tabs. + # + # This is `'untitled'` if the image not saved to the disk. # # Returns a {String}. getTitle: -> @getFileName() ? 'untitled' - # Retireves all ImageEditors in the workspace. - # - # Returns an {Array} of {ImageEditors}. - getImageEditors: -> - atom.workspace.getPaneItems().filter (item) -> item instanceof ImageEditor - # Essential: Get unique title for display in other parts of the UI, such as # the window title. # - # If the editor's buffer is unsaved, its title is "untitled" - # If the editor's buffer is saved, its unique title is formatted as one + # If the image is not saved to disk its title is "untitled" + # If the image is saved, its unique title is formatted as one # of the following, - # * "" when it is the only editing buffer with this file name. - # * "" when other buffers have this file name. + # * "" when it is the only existing {ImageEditor} with this file name. + # * "" when other {ImageEditors} have this file name. # # Returns a {String} getLongTitle: -> From dce076eba37be0d37de254d0c24cab3804cf7fd4 Mon Sep 17 00:00:00 2001 From: bene Date: Wed, 31 Aug 2016 22:54:34 +0200 Subject: [PATCH 3/4] :art: fix linting errors --- lib/image-editor.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/image-editor.coffee b/lib/image-editor.coffee index c41a6f4..99a0ef9 100644 --- a/lib/image-editor.coffee +++ b/lib/image-editor.coffee @@ -51,7 +51,7 @@ class ImageEditor # # Returns an {Array} of {ImageEditor}s. getImageEditors: -> - atom.workspace.getPaneItems().filter (item) -> item instanceof ImageEditor + atom.workspace.getPaneItems().filter (item) -> item instanceof ImageEditor # Essential: Get the {ImageEditor}s title for display in other parts # of the UI such as tabs. @@ -60,7 +60,7 @@ class ImageEditor # # Returns a {String}. getTitle: -> - @getFileName() ? 'untitled' + @getFileName() ? 'untitled' # Essential: Get unique title for display in other parts of the UI, such as # the window title. From 69025712f5c04414cf570352644ef33f7f0a54a8 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Sep 2016 08:44:32 +0200 Subject: [PATCH 4/4] :art: fix typos --- lib/image-editor.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/image-editor.coffee b/lib/image-editor.coffee index 99a0ef9..3f459dc 100644 --- a/lib/image-editor.coffee +++ b/lib/image-editor.coffee @@ -47,7 +47,7 @@ class ImageEditor destroy: -> @subscriptions.dispose() - # Essential: Retireves all {ImageEditor}s in the workspace. + # Essential: Retrieves all {ImageEditor}s in the workspace. # # Returns an {Array} of {ImageEditor}s. getImageEditors: -> @@ -69,7 +69,7 @@ class ImageEditor # If the image is saved, its unique title is formatted as one # of the following, # * "" when it is the only existing {ImageEditor} with this file name. - # * "" when other {ImageEditors} have this file name. + # * "" when other {ImageEditor}s have this file name. # # Returns a {String} getLongTitle: ->