From 17a6005eb0f730c6aafe10bf649abe7d100d6296 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Mon, 3 Oct 2016 18:55:30 +0300 Subject: [PATCH] [vcs-log] extract TextFilterClass --- .../log/ui/filter/VcsLogClassicFilterUi.java | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/VcsLogClassicFilterUi.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/VcsLogClassicFilterUi.java index f9ca45939586..3b8e4fa18525 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/VcsLogClassicFilterUi.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/VcsLogClassicFilterUi.java @@ -110,33 +110,7 @@ public class VcsLogClassicFilterUi implements VcsLogFilterUi { @NotNull public SearchTextField createTextFilter() { - final SearchTextFieldWithStoredHistory textFilter = new SearchTextFieldWithStoredHistory(VCS_LOG_TEXT_FILTER_HISTORY) { - @Override - protected void onFieldCleared() { - myTextFilterModel.setFilter(null); - } - }; - textFilter.setText(myTextFilterModel.getText()); - textFilter.getTextEditor().addActionListener(e -> { - myTextFilterModel.setFilter(new VcsLogTextFilterImpl(textFilter.getText())); - textFilter.addCurrentTextToHistory(); - }); - textFilter.addDocumentListener(new DocumentAdapter() { - @Override - protected void textChanged(DocumentEvent e) { - try { - myTextFilterModel.setUnsavedText(e.getDocument().getText(0, e.getDocument().getLength())); - } - catch (BadLocationException ex) { - LOG.error(ex); - } - } - }); - String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(VcsLogActionPlaces.VCS_LOG_FOCUS_TEXT_FILTER); - if (!shortcutText.isEmpty()) { - textFilter.getTextEditor().setToolTipText("Use " + shortcutText + " to switch between text filter and commits list"); - } - return textFilter; + return new TextFilterField(myTextFilterModel); } /** @@ -454,4 +428,38 @@ public class VcsLogClassicFilterUi implements VcsLogFilterUi { return ContainerUtil.newArrayList(((VcsLogUserFilterImpl)filter).getUserNamesForPresentation()); } } + + private static class TextFilterField extends SearchTextFieldWithStoredHistory { + @NotNull private final TextFilterModel myTextFilterModel; + + public TextFilterField(@NotNull TextFilterModel model) { + super(VCS_LOG_TEXT_FILTER_HISTORY); + myTextFilterModel = model; + setText(myTextFilterModel.getText()); + getTextEditor().addActionListener(e -> { + myTextFilterModel.setFilter(new VcsLogTextFilterImpl(getText())); + addCurrentTextToHistory(); + }); + addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(DocumentEvent e) { + try { + myTextFilterModel.setUnsavedText(e.getDocument().getText(0, e.getDocument().getLength())); + } + catch (BadLocationException ex) { + LOG.error(ex); + } + } + }); + String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(VcsLogActionPlaces.VCS_LOG_FOCUS_TEXT_FILTER); + if (!shortcutText.isEmpty()) { + getTextEditor().setToolTipText("Use " + shortcutText + " to switch between text filter and commits list"); + } + } + + @Override + protected void onFieldCleared() { + myTextFilterModel.setFilter(null); + } + } }