From 0f314f573b6c8bcd10aec9ef8f3148a891af1805 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 25 Jan 2013 09:23:18 -0800 Subject: [PATCH] Add match and file count to command panel preview --- .../command-panel/spec/command-panel-spec.coffee | 10 ++++++++-- .../command-panel/src/command-panel-view.coffee | 6 ++++++ src/packages/command-panel/src/preview-list.coffee | 3 +++ themes/Atom - Dark/command-panel.css | 7 +++++++ themes/Atom - Light/command-panel.css | 7 +++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/packages/command-panel/spec/command-panel-spec.coffee b/src/packages/command-panel/spec/command-panel-spec.coffee index 246302faf..557b21444 100644 --- a/src/packages/command-panel/spec/command-panel-spec.coffee +++ b/src/packages/command-panel/spec/command-panel-spec.coffee @@ -180,17 +180,19 @@ describe "CommandPanel", -> expect(commandPanel.hasParent()).toBeTruthy() describe "when the mini editor is focused", -> - it "retains focus on the mini editor and does not show the preview list", -> + it "retains focus on the mini editor and does not show the preview list or preview count", -> expect(commandPanel.miniEditor.isFocused).toBeTruthy() rootView.trigger 'command-panel:toggle-preview' expect(commandPanel.previewList).toBeHidden() + expect(commandPanel.previewCount).toBeHidden() expect(commandPanel.miniEditor.isFocused).toBeTruthy() describe "when the mini editor is not focused", -> - it "focuses the mini editor and does not show the preview list", -> + it "focuses the mini editor and does not show the preview list or preview count", -> rootView.focus() rootView.trigger 'command-panel:toggle-preview' expect(commandPanel.previewList).toBeHidden() + expect(commandPanel.previewCount).toBeHidden() expect(commandPanel.miniEditor.isFocused).toBeTruthy() describe "when the command panel is not visible", -> @@ -377,6 +379,10 @@ describe "CommandPanel", -> rootView.trigger 'command-panel:toggle' waitsForPromise -> commandPanel.execute('X x/sort/') + it "displays the number of files and operations", -> + rootView.attachToDom() + expect(commandPanel.previewCount.text()).toBe '17 matches in 4 files' + describe "when move-down and move-up are triggered on the preview list", -> it "selects the next/previous operation (if there is one), and scrolls the list if needed", -> rootView.attachToDom() diff --git a/src/packages/command-panel/src/command-panel-view.coffee b/src/packages/command-panel/src/command-panel-view.coffee index 5e212440c..7ccb74a48 100644 --- a/src/packages/command-panel/src/command-panel-view.coffee +++ b/src/packages/command-panel/src/command-panel-view.coffee @@ -24,6 +24,7 @@ class CommandPanelView extends View @content: (rootView) -> @div class: 'command-panel tool-panel', => + @div outlet: 'previewCount', class: 'preview-count' @subview 'previewList', new PreviewList(rootView) @ul class: 'error-messages', outlet: 'errorMessages' @div class: 'prompt-and-editor', => @@ -48,6 +49,7 @@ class CommandPanelView extends View @command 'core:move-down', => @navigateForwardInHistory() @previewList.hide() + @previewCount.hide() @errorMessages.hide() @prompt.iconSize(@miniEditor.fontSize) @@ -73,12 +75,14 @@ class CommandPanelView extends View togglePreview: -> if @previewList.is(':focus') @previewList.hide() + @previewCount.hide() @detach() @rootView.focus() else @attach() unless @hasParent() if @previewList.hasOperations() @previewList.show().focus() + @previewCount.show() else @miniEditor.focus() @@ -94,6 +98,7 @@ class CommandPanelView extends View detach: -> @rootView.focus() @previewList.hide() + @previewCount.hide() super escapedCommand: -> @@ -115,6 +120,7 @@ class CommandPanelView extends View else if operationsToPreview?.length @previewList.populate(operationsToPreview) @previewList.focus() + @previewCount.text("#{_.pluralize(operationsToPreview.length, 'match', 'matches')} in #{_.pluralize(@previewList.getPathCount(), 'file')}").show() else @detach() catch error diff --git a/src/packages/command-panel/src/preview-list.coffee b/src/packages/command-panel/src/preview-list.coffee index af2ea5479..0fd4541e1 100644 --- a/src/packages/command-panel/src/preview-list.coffee +++ b/src/packages/command-panel/src/preview-list.coffee @@ -84,6 +84,9 @@ class PreviewList extends ScrollView @rootView.focus() false + getPathCount: -> + _.keys(_.groupBy(@operations, (operation) -> operation.getPath())).length + getOperations: -> new Array(@operations...) diff --git a/themes/Atom - Dark/command-panel.css b/themes/Atom - Dark/command-panel.css index 8f4a6e405..116bb2baf 100644 --- a/themes/Atom - Dark/command-panel.css +++ b/themes/Atom - Dark/command-panel.css @@ -15,6 +15,13 @@ cursor: default; } +.command-panel .preview-count { + font-size: 11px; + color: #969696; + text-align: right; + padding-bottom: 1px; +} + .command-panel .preview-list li.selected, .command-panel .preview-list li.operation:hover { background-color: rgba(255, 255, 255, .13); } diff --git a/themes/Atom - Light/command-panel.css b/themes/Atom - Light/command-panel.css index 5344b859d..f9e15c3af 100644 --- a/themes/Atom - Light/command-panel.css +++ b/themes/Atom - Light/command-panel.css @@ -16,6 +16,13 @@ border: 1px solid #989898; } +.command-panel .preview-count { + font-size: 11px; + color: #333; + text-align: right; + padding-bottom: 1px; +} + .command-panel .preview-list li.selected, .command-panel .preview-list li.operation:hover { background-color: rgba(255, 255, 255, .6); }