提交 316c2fdd 编写于 作者: M MrIkso 提交者: skylot

fix(gui): updated SearchBar in code viewer

上级 6bbf1d09
......@@ -6,9 +6,9 @@ import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.text.BadLocationException;
......@@ -28,7 +28,14 @@ class SearchBar extends JToolBar {
private static final long serialVersionUID = 1836871286618633003L;
private static final Logger LOG = LoggerFactory.getLogger(SearchBar.class);
private static final Icon ICON_MARK = UiUtils.openSvgIcon("search/mark");
private static final Icon ICON_MARK_SELECTED = UiUtils.openSvgIcon("search/previewSelected");
private static final Icon ICON_REGEX = UiUtils.openSvgIcon("search/regexHovered");
private static final Icon ICON_REGEX_SELECTED = UiUtils.openSvgIcon("search/regexSelected");
private static final Icon ICON_WORDS = UiUtils.openSvgIcon("search/wordsHovered");
private static final Icon ICON_WORDS_SELECTED = UiUtils.openSvgIcon("search/wordsSelected");
private static final Icon ICON_MATCH = UiUtils.openSvgIcon("search/matchCaseHovered");
private static final Icon ICON_MATCH_SELECTED = UiUtils.openSvgIcon("search/matchCaseSelected");
private static final Icon ICON_UP = UiUtils.openSvgIcon("ui/top");
private static final Icon ICON_DOWN = UiUtils.openSvgIcon("ui/bottom");
private static final Icon ICON_CLOSE = UiUtils.openSvgIcon("ui/close");
......@@ -36,11 +43,10 @@ class SearchBar extends JToolBar {
private RSyntaxTextArea rTextArea;
private final JTextField searchField;
private final JCheckBox markAllCB;
private final JCheckBox regexCB;
private final JCheckBox wholeWordCB;
private final JCheckBox matchCaseCB;
private final JToggleButton markAllCB;
private final JToggleButton regexCB;
private final JToggleButton wholeWordCB;
private final JToggleButton matchCaseCB;
private boolean notFound;
public SearchBar(RSyntaxTextArea textArea) {
......@@ -70,36 +76,50 @@ class SearchBar extends JToolBar {
new TextStandardActions(searchField);
add(searchField);
JButton prevButton = new JButton(NLS.str("search.previous"));
ActionListener forwardListener = e -> search(1);
matchCaseCB = new JToggleButton();
matchCaseCB.setIcon(ICON_MATCH);
matchCaseCB.setSelectedIcon(ICON_MATCH_SELECTED);
matchCaseCB.setToolTipText(NLS.str("search.match_case"));
matchCaseCB.addActionListener(forwardListener);
add(matchCaseCB);
wholeWordCB = new JToggleButton();
wholeWordCB.setIcon(ICON_WORDS);
wholeWordCB.setSelectedIcon(ICON_WORDS_SELECTED);
wholeWordCB.setToolTipText(NLS.str("search.whole_word"));
wholeWordCB.addActionListener(forwardListener);
add(wholeWordCB);
regexCB = new JToggleButton();
regexCB.setIcon(ICON_REGEX);
regexCB.setSelectedIcon(ICON_REGEX_SELECTED);
regexCB.setToolTipText(NLS.str("search.regex"));
regexCB.addActionListener(forwardListener);
add(regexCB);
JButton prevButton = new JButton();
prevButton.setIcon(ICON_UP);
prevButton.setToolTipText(NLS.str("search.previous"));
prevButton.addActionListener(e -> search(-1));
prevButton.setBorderPainted(false);
add(prevButton);
JButton nextButton = new JButton(NLS.str("search.next"));
JButton nextButton = new JButton();
nextButton.setIcon(ICON_DOWN);
nextButton.setToolTipText(NLS.str("search.next"));
nextButton.addActionListener(e -> search(1));
nextButton.setBorderPainted(false);
add(nextButton);
ActionListener forwardListener = e -> search(0);
markAllCB = new JCheckBox(NLS.str("search.mark_all"));
markAllCB = new JToggleButton();
markAllCB.setIcon(ICON_MARK);
markAllCB.setSelectedIcon(ICON_MARK_SELECTED);
markAllCB.setToolTipText(NLS.str("search.mark_all"));
markAllCB.addActionListener(forwardListener);
add(markAllCB);
regexCB = new JCheckBox(NLS.str("search.regex"));
regexCB.addActionListener(forwardListener);
add(regexCB);
matchCaseCB = new JCheckBox(NLS.str("search.match_case"));
matchCaseCB.addActionListener(forwardListener);
add(matchCaseCB);
wholeWordCB = new JCheckBox(NLS.str("search.whole_word"));
wholeWordCB.addActionListener(forwardListener);
add(wholeWordCB);
JButton closeButton = new JButton();
closeButton.setIcon(ICON_CLOSE);
closeButton.addActionListener(e -> toggle());
......@@ -110,7 +130,7 @@ class SearchBar extends JToolBar {
setVisible(false);
}
public boolean toggle() {
public void toggle() {
boolean visible = !isVisible();
setVisible(visible);
......@@ -124,7 +144,6 @@ class SearchBar extends JToolBar {
} else {
rTextArea.requestFocus();
}
return visible;
}
private void search(int direction) {
......@@ -177,11 +196,4 @@ class SearchBar extends JToolBar {
}
searchField.repaint();
}
public void setRTextArea(RSyntaxTextArea rTextArea) {
this.rTextArea = rTextArea;
if (isVisible()) {
this.search(0);
}
}
}
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" fill-rule="evenodd">
<g fill="#6E6E6E" transform="translate(1 4)">
<rect width="1.76" height="4.994" x="8.126" y="6.429" transform="rotate(-45 9.006 8.926)"/>
<path d="M4.6,9.2 C2.05949015,9.2 -4e-16,7.14050985 -4e-16,4.6 C-4e-16,2.05949015 2.05949015,0 4.6,0 C7.14050985,0 9.2,2.05949015 9.2,4.6 C9.2,7.14050985 7.14050985,9.2 4.6,9.2 Z M4.6,7.6 C6.25685425,7.6 7.6,6.25685425 7.6,4.6 C7.6,2.94314575 6.25685425,1.6 4.6,1.6 C2.94314575,1.6 1.6,2.94314575 1.6,4.6 C1.6,6.25685425 2.94314575,7.6 4.6,7.6 Z"/>
</g>
<path fill="#6E6E6E" d="M9.88969094,5 C9.57081021,4.62042576 9.20247796,4.2837855 8.79461496,4 L13,4 L13,3 L8,3 L8,3.53890499 C7.38650137,3.24746356 6.71160471,3.06428711 6,3.01406563 L6,1 L15,1 L15,11 L10.6610948,11 C11.006647,10.2725957 11.1999998,9.45887778 11.1999998,8.5999999 C11.1999998,8.39730439 11.1892308,8.19712411 11.1682337,8 L13,8 L13,7 L10.9680969,7 C10.8642932,6.65121416 10.7274236,6.31666911 10.5611234,6 L13,6 L13,5 L9.88969094,5 Z"/>
</g>
</svg>
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="matchCaseHovered">
<g id="Cc">
<path d="M8.77476 11.8297C8.32279 12.2816 7.83717 12.623 7.31789 12.8538C6.80823 13.075 6.19279 13.1856 5.47157 13.1856C4.17337 13.1856 3.10116 12.7144 2.25492 11.772C1.41831 10.8296 1 9.5939 1 8.06491V7.93509C1 6.4061 1.42792 5.17041 2.28377 4.22802C3.13962 3.27601 4.23588 2.8 5.57254 2.8C6.81304 2.8 7.8564 3.18465 8.70263 3.95395L7.72178 5.64161C7.01979 5.0454 6.3178 4.7473 5.61581 4.7473C4.89459 4.7473 4.30319 5.03098 3.84161 5.59834C3.38964 6.1657 3.16366 6.935 3.16366 7.90624V8.05049C3.16366 9.04096 3.38964 9.81988 3.84161 10.3872C4.29357 10.9546 4.88978 11.2383 5.63024 11.2383C6.35146 11.2383 7.06787 10.9306 7.77947 10.3151L8.77476 11.8297Z" fill="#7F8B91" fill-opacity="0.9"/>
<path d="M15.6304 12.1182C15.2842 12.474 14.914 12.7432 14.5197 12.9259C14.135 13.1086 13.6542 13.2 13.0773 13.2C12.0483 13.2 11.2021 12.8346 10.5386 12.1037C9.87504 11.3633 9.54327 10.4209 9.54327 9.27656V9.11789C9.54327 7.97356 9.87984 7.03116 10.553 6.29071C11.2261 5.55025 12.0772 5.18003 13.1061 5.18003C14.135 5.18003 14.962 5.50217 15.5871 6.14646L14.6639 7.67545C14.1927 7.22349 13.6927 6.9975 13.1638 6.9975C12.7022 6.9975 12.3224 7.18983 12.0243 7.57448C11.7262 7.95913 11.5771 8.46398 11.5771 9.08904V9.26214C11.5771 9.90643 11.7262 10.4209 12.0243 10.8055C12.332 11.1902 12.7359 11.3825 13.2359 11.3825C13.736 11.3825 14.236 11.1565 14.7361 10.7046L15.6304 12.1182Z" fill="#7F8B91" fill-opacity="0.9"/>
</g>
</g>
</svg>
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="matchCaseSelected">
<g id="Cc">
<path d="M8.77476 11.8297C8.32279 12.2816 7.83717 12.623 7.31789 12.8538C6.80823 13.075 6.19279 13.1856 5.47157 13.1856C4.17337 13.1856 3.10116 12.7144 2.25492 11.772C1.41831 10.8296 1 9.5939 1 8.06491V7.93509C1 6.4061 1.42792 5.17041 2.28377 4.22802C3.13962 3.276 4.23588 2.8 5.57254 2.8C6.81304 2.8 7.8564 3.18465 8.70263 3.95395L7.72178 5.64161C7.01979 5.0454 6.3178 4.74729 5.61581 4.74729C4.89459 4.74729 4.30319 5.03097 3.84161 5.59833C3.38964 6.16569 3.16366 6.935 3.16366 7.90624V8.05048C3.16366 9.04096 3.38964 9.81988 3.84161 10.3872C4.29357 10.9546 4.88978 11.2383 5.63024 11.2383C6.35146 11.2383 7.06787 10.9306 7.77947 10.3151L8.77476 11.8297Z" fill="#40B6E0"/>
<path d="M15.6304 12.1182C15.2842 12.474 14.914 12.7432 14.5197 12.9259C14.135 13.1086 13.6542 13.2 13.0773 13.2C12.0483 13.2 11.2021 12.8346 10.5386 12.1037C9.87504 11.3633 9.54327 10.4209 9.54327 9.27656V9.11789C9.54327 7.97355 9.87984 7.03116 10.553 6.29071C11.2261 5.55025 12.0772 5.18003 13.1061 5.18003C14.135 5.18003 14.962 5.50217 15.5871 6.14646L14.6639 7.67545C14.1927 7.22348 13.6927 6.9975 13.1638 6.9975C12.7022 6.9975 12.3224 7.18983 12.0243 7.57448C11.7262 7.95913 11.5771 8.46398 11.5771 9.08904V9.26213C11.5771 9.90643 11.7262 10.4209 12.0243 10.8055C12.332 11.1902 12.7359 11.3825 13.2359 11.3825C13.736 11.3825 14.236 11.1565 14.7361 10.7046L15.6304 12.1182Z" fill="#40B6E0"/>
</g>
</g>
</svg>
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" fill-rule="evenodd">
<g fill="#40B6E0" transform="translate(1 4)">
<rect width="1.76" height="4.994" x="8.126" y="6.429" transform="rotate(-45 9.006 8.926)"/>
<path d="M4.6,9.2 C2.05949015,9.2 -4e-16,7.14050985 -4e-16,4.6 C-4e-16,2.05949015 2.05949015,0 4.6,0 C7.14050985,0 9.2,2.05949015 9.2,4.6 C9.2,7.14050985 7.14050985,9.2 4.6,9.2 Z M4.6,7.6 C6.25685425,7.6 7.6,6.25685425 7.6,4.6 C7.6,2.94314575 6.25685425,1.6 4.6,1.6 C2.94314575,1.6 1.6,2.94314575 1.6,4.6 C1.6,6.25685425 2.94314575,7.6 4.6,7.6 Z"/>
</g>
<path fill="#40B6E0" d="M9.88969094,5 C9.57081021,4.62042576 9.20247796,4.2837855 8.79461496,4 L13,4 L13,3 L8,3 L8,3.53890499 C7.38650137,3.24746356 6.71160471,3.06428711 6,3.01406563 L6,1 L15,1 L15,11 L10.6610948,11 C11.006647,10.2725957 11.1999998,9.45887778 11.1999998,8.5999999 C11.1999998,8.39730439 11.1892308,8.19712411 11.1682337,8 L13,8 L13,7 L10.9680969,7 C10.8642932,6.65121416 10.7274236,6.31666911 10.5611234,6 L13,6 L13,5 L9.88969094,5 Z"/>
</g>
</svg>
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" fill-opacity=".9" fill-rule="evenodd">
<rect width="2" height="2" x="3" y="11" fill="#7F8B91"/>
<path fill="#7F8B91" d="M9.8339746,5.61435935 L12.0980762,4.30717968 L12.8980762,5.69282032 L10.6339746,7 L12.8980762,8.30717968 L12.0980762,9.69282032 L9.8339746,8.38564065 L9.8339746,11 L8.2339746,11 L8.2339746,8.38564065 L5.96987298,9.69282032 L5.16987298,8.30717968 L7.4339746,7 L5.16987298,5.69282032 L5.96987298,4.30717968 L8.2339746,5.61435935 L8.2339746,3 L9.8339746,3 L9.8339746,5.61435935 Z"/>
</g>
</svg>
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<g fill="none" fill-rule="evenodd">
<rect width="2" height="2" x="3" y="11" fill="#40B6E0"/>
<path fill="#40B6E0" d="M9.8339746,5.61435935 L12.0980762,4.30717968 L12.8980762,5.69282032 L10.6339746,7 L12.8980762,8.30717968 L12.0980762,9.69282032 L9.8339746,8.38564065 L9.8339746,11 L8.2339746,11 L8.2339746,8.38564065 L5.96987298,9.69282032 L5.16987298,8.30717968 L7.4339746,7 L5.16987298,5.69282032 L5.96987298,4.30717968 L8.2339746,5.61435935 L8.2339746,3 L9.8339746,3 L9.8339746,5.61435935 Z"/>
</g>
</svg>
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="wordsHovered">
<path id="W" d="M14.5213 3.01418L11.6986 13H9.82624L8.01064 6.68794L6.19504 13H4.3227L1.5 3.01418H3.67021L5.3156 9.53901L7.14539 3H8.93262L10.7482 9.53901L12.4078 3.01418H14.5213Z" fill="#7F8B91" fill-opacity="0.9"/>
</g>
</svg>
<!-- Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="wordsSelected">
<path id="W" d="M14.5213 3.01418L11.6986 13H9.82624L8.01064 6.68794L6.19504 13H4.3227L1.5 3.01418H3.67021L5.3156 9.53901L7.14539 3H8.93262L10.7482 9.53901L12.4078 3.01418H14.5213Z" fill="#40B6E0"/>
</g>
</svg>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册