-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Find/Replace overlay: add a search- and replace- history
Adds a history feature for the find and replace bar of the overlay. The history is displayed using a menu filled with entries from the HistoryStore. fixes #1907
- Loading branch information
Maximilian Wittmer
authored and
Maximilian Wittmer
committed
Jun 24, 2024
1 parent
54609c8
commit 3b71076
Showing
8 changed files
with
216 additions
and
17 deletions.
There are no files selected for viewing
Binary file added
BIN
+331 Bytes
bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+556 Bytes
bundles/org.eclipse.ui.workbench.texteditor/icons/full/elcl16/open_history@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...ench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/SearchHistoryMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.eclipse.ui.internal.findandreplace.overlay; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionListener; | ||
import org.eclipse.swt.events.ShellAdapter; | ||
import org.eclipse.swt.events.ShellEvent; | ||
import org.eclipse.swt.events.ShellListener; | ||
import org.eclipse.swt.graphics.Point; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.swt.widgets.Table; | ||
import org.eclipse.swt.widgets.TableColumn; | ||
import org.eclipse.swt.widgets.TableItem; | ||
|
||
import org.eclipse.jface.dialogs.Dialog; | ||
import org.eclipse.jface.layout.GridDataFactory; | ||
|
||
import org.eclipse.ui.internal.findandreplace.HistoryStore; | ||
|
||
public class SearchHistoryMenu extends Dialog { | ||
private final SelectionListener selectionListener; | ||
private final HistoryStore history; | ||
private final ShellListener shellFocusListener = new ShellAdapter() { | ||
@Override | ||
public void shellDeactivated(ShellEvent e) { | ||
if (getShell().getParent() != null) { | ||
getShell().getParent().forceFocus(); | ||
} | ||
close(); | ||
} | ||
}; | ||
private Point location; | ||
private int width; | ||
|
||
public SearchHistoryMenu(Shell parent, HistoryStore history, | ||
SelectionListener menuItemSelectionListener) { | ||
super(parent); | ||
setShellStyle(SWT.MODELESS); | ||
setBlockOnOpen(false); | ||
|
||
this.selectionListener = menuItemSelectionListener; | ||
this.history = history; | ||
} | ||
|
||
public void setPosition(int x, int y, int width) { | ||
location = new Point(x, y); | ||
this.width = width; | ||
} | ||
|
||
@Override | ||
public Control createContents(Composite parent) { | ||
|
||
Table table = new Table(parent, SWT.NONE); | ||
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(table); | ||
TableColumn column = new TableColumn(table, SWT.NONE); | ||
|
||
for (String entry : history.get()) { | ||
TableItem item = new TableItem(table, SWT.NONE); | ||
item.setText(entry); | ||
} | ||
|
||
table.addSelectionListener(selectionListener); | ||
table.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> close())); | ||
getShell().layout(); | ||
|
||
positionShell(table, column); | ||
return table; | ||
} | ||
|
||
private void positionShell(Table table, TableColumn column) { | ||
if (location != null) { | ||
getShell().setBounds(location.x, location.y, width, | ||
Math.min(table.getItemHeight() * 7, table.getItemHeight() * table.getItemCount())); | ||
} | ||
int columnSize = table.getSize().x; | ||
if (table.getVerticalBar() != null) { | ||
columnSize -= table.getVerticalBar().getSize().x; | ||
} | ||
column.setWidth(columnSize); | ||
} | ||
|
||
@Override | ||
public int open() { | ||
int code = super.open(); | ||
|
||
getShell().addShellListener(shellFocusListener); | ||
|
||
return code; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.