Skip to content

Commit c08610f

Browse files
committed
Fine tuning of Quick Search Dialog
1 parent 8b0bfa8 commit c08610f

File tree

2 files changed

+217
-12
lines changed

2 files changed

+217
-12
lines changed
Lines changed: 189 additions & 0 deletions
Loading

bundles/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/ui/QuickSearchDialog.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.eclipse.jface.resource.JFaceResources;
5959
import org.eclipse.jface.text.BadLocationException;
6060
import org.eclipse.jface.text.CursorLinePainter;
61+
import org.eclipse.jface.text.Document;
6162
import org.eclipse.jface.text.IDocument;
6263
import org.eclipse.jface.text.IRegion;
6364
import org.eclipse.jface.text.source.CompositeRuler;
@@ -153,7 +154,6 @@
153154
public class QuickSearchDialog extends SelectionStatusDialog {
154155

155156
private static final int OPEN_BUTTON_ID = IDialogConstants.OK_ID;
156-
private static final int REFRESH_BUTTON_ID = IDialogConstants.RETRY_ID;
157157

158158
public static final Styler HIGHLIGHT_STYLE = org.eclipse.search.internal.ui.text.DecoratingFileSearchLabelProvider.HIGHLIGHT_STYLE;
159159

@@ -666,7 +666,7 @@ private Label createLabels(Composite parent) {
666666
Composite labels = new Composite(parent, SWT.NONE);
667667

668668
GridLayout layout = new GridLayout();
669-
layout.numColumns = 2;
669+
layout.numColumns = 3;
670670
layout.marginWidth = 0;
671671
layout.marginHeight = 0;
672672
labels.setLayout(layout);
@@ -688,7 +688,20 @@ private Label createLabels(Composite parent) {
688688
progressLabel = new Label(labels, SWT.RIGHT);
689689
gd = new GridData(GridData.FILL_HORIZONTAL);
690690
progressLabel.setLayoutData(gd);
691-
createButton(labels, REFRESH_BUTTON_ID, Messages.QuickSearchDialog_Refresh, false);
691+
ToolBar toolBar = new ToolBar(labels, SWT.FLAT | SWT.RIGHT);
692+
ToolItem refreshItem = new ToolItem(toolBar, SWT.PUSH);
693+
Image refreshIcon = new Image(Display.getCurrent(),getClass().
694+
getClassLoader().getResourceAsStream("icons/elcl16/refresh.svg")); //$NON-NLS-1$
695+
696+
refreshItem.setImage(refreshIcon);
697+
refreshItem.setToolTipText(Messages.QuickSearchDialog_Refresh);
698+
699+
refreshItem.addDisposeListener(e -> {
700+
if (refreshIcon != null && !refreshIcon.isDisposed()) {
701+
refreshIcon.dispose();
702+
}
703+
});
704+
refreshItem.addListener(SWT.Selection, e -> refreshButtonPressed());
692705

693706
labels.setLayoutData(gd);
694707
return listLabel;
@@ -1289,6 +1302,10 @@ public void refreshWidgets() {
12891302
//element is available in the list.
12901303
openButton.setEnabled(itemCount>0);
12911304
}
1305+
//Auto-select the first search result for preview when greater than 1 result exists.
1306+
if (itemCount >= 1 && list.getSelection().isEmpty()) {
1307+
list.getTable().select(0);
1308+
}
12921309
refreshDetails();
12931310
}
12941311
}
@@ -1345,15 +1362,6 @@ protected void okPressed() {
13451362
}
13461363
}
13471364

1348-
@Override
1349-
protected void buttonPressed(int buttonId) {
1350-
if (buttonId == REFRESH_BUTTON_ID) {
1351-
refreshButtonPressed();
1352-
} else {
1353-
super.buttonPressed(buttonId);
1354-
}
1355-
}
1356-
13571365
@Override
13581366
protected void createButtonsForButtonBar(Composite parent) {
13591367
createButton(parent, OPEN_BUTTON_ID, Messages.QuickSearchDialog_Open, true);
@@ -1484,6 +1492,14 @@ public void update(LineItem match) {
14841492
} else {
14851493
//The QuickTextSearcher is already active update the query
14861494
this.searcher.setQuery(newFilter, force);
1495+
if(newFilter.getPatternString().trim().isEmpty()) {
1496+
//When pattern is cleared, clear the preview section
1497+
viewer.setDocument(new Document("")); //$NON-NLS-1$
1498+
if (lineNumberColumn != null) {
1499+
viewer.removeVerticalRulerColumn(lineNumberColumn);
1500+
viewer.addVerticalRulerColumn(lineNumberColumn);
1501+
}
1502+
}
14871503
}
14881504
if (progressJob!=null) {
14891505
progressJob.schedule();

0 commit comments

Comments
 (0)