Skip to content

Commit

Permalink
Add undo/redo operation in toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
nadment committed Dec 21, 2024
1 parent 9cd2411 commit 9a98631
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/main/java/org/apache/hop/ui/expression/ExpressionEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public class ExpressionEditor extends Composite implements IDocumentListener {
public static final String ID_TOOLBAR_COPY = "expression-editor-toolbar-10400-copy";
public static final String ID_TOOLBAR_PASTE = "expression-editor-toolbar-10410-paste";
public static final String ID_TOOLBAR_CUT = "expression-editor-toolbar-10420-cut";
public static final String ID_TOOLBAR_OPTIMIZE = "expression-editor-toolbar-10420-simplify";
public static final String ID_TOOLBAR_UNDO = "expression-editor-toolbar-10430-undo";
public static final String ID_TOOLBAR_REDO = "expression-editor-toolbar-10440-redo";
public static final String ID_TOOLBAR_OPTIMIZE = "expression-editor-toolbar-10450-simplify";

private static final String ANNOTATION_ERROR_TYPE = "org.hop.expression.error";

Expand Down Expand Up @@ -234,21 +236,21 @@ public void drop(DropTargetEvent event) {
undoItem.setImage(
GuiResource.getInstance()
.getImage("ui/images/undo.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE));
undoItem.addListener(SWT.Selection, e -> viewer.doOperation(ITextOperationTarget.UNDO));
undoItem.addListener(SWT.Selection, e -> doUndo());

MenuItem redoItem = new MenuItem(menu, SWT.PUSH);
redoItem.setText(BaseMessages.getString(PKG, "ExpressionEditor.Menu.Redo.Label"));
redoItem.setImage(
GuiResource.getInstance()
.getImage("ui/images/redo.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE));
redoItem.addListener(SWT.Selection, e -> viewer.doOperation(ITextOperationTarget.REDO));
redoItem.addListener(SWT.Selection, e -> doRedo());
new MenuItem(menu, SWT.SEPARATOR);
MenuItem cutItem = new MenuItem(menu, SWT.PUSH);
cutItem.setText(BaseMessages.getString(PKG, "ExpressionEditor.Menu.Cut.Label"));
cutItem.setImage(
GuiResource.getInstance()
.getImage("ui/images/cut.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE));
cutItem.addListener(SWT.Selection, e -> viewer.doOperation(ITextOperationTarget.CUT));
cutItem.addListener(SWT.Selection, e -> doCut());
MenuItem copyItem = new MenuItem(menu, SWT.PUSH);
copyItem.setText(BaseMessages.getString(PKG, "ExpressionEditor.Menu.Copy.Label"));
copyItem.setImage(
Expand All @@ -260,16 +262,15 @@ public void drop(DropTargetEvent event) {
pasteItem.setImage(
GuiResource.getInstance()
.getImage("ui/images/paste.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE));
pasteItem.addListener(SWT.Selection, e -> viewer.doOperation(ITextOperationTarget.PASTE));
pasteItem.addListener(SWT.Selection, e -> doPaste());
new MenuItem(menu, SWT.SEPARATOR);
MenuItem selectAllItem = new MenuItem(menu, SWT.PUSH);
selectAllItem.setText(BaseMessages.getString(PKG, "ExpressionEditor.Menu.SelectAll.Label"));
selectAllItem.setImage(
GuiResource.getInstance()
.getImage(
"ui/images/select-all.svg", ConstUi.SMALL_ICON_SIZE, ConstUi.SMALL_ICON_SIZE));
selectAllItem.addListener(
SWT.Selection, e -> viewer.doOperation(ITextOperationTarget.SELECT_ALL));
selectAllItem.addListener(SWT.Selection, e -> doSelectAll());

widget.setMenu(menu);
widget.addListener(
Expand Down Expand Up @@ -566,13 +567,32 @@ public void doSelectAll() {
viewer.doOperation(ITextOperationTarget.SELECT_ALL);
}

@GuiToolbarElement(
root = ID_TOOLBAR,
id = ID_TOOLBAR_UNDO,
image = "ui/images/undo.svg",
toolTip = "i18n::ExpressionEditor.ToolBarWidget.Undo.ToolTip",
separator = true)
public void doUndo() {
viewer.doOperation(ITextOperationTarget.UNDO);
}

@GuiToolbarElement(
root = ID_TOOLBAR,
id = ID_TOOLBAR_REDO,
image = "ui/images/redo.svg",
toolTip = "i18n::ExpressionEditor.ToolBarWidget.Redo.ToolTip")
public void doRedo() {
viewer.doOperation(ITextOperationTarget.REDO);
}

@GuiToolbarElement(
root = ID_TOOLBAR,
id = ID_TOOLBAR_OPTIMIZE,
image = "evaluate.svg",
toolTip = "i18n::ExpressionEditor.ToolBarWidget.Evaluate.ToolTip",
separator = true)
public void doOptimize() {
public void doEvaluate() {

String source = viewer.getTextWidget().getText();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ ExpressionEditor.ToolBarWidget.Copy.ToolTip=Copy selected text to clipboard
ExpressionEditor.ToolBarWidget.Cut.ToolTip=Cut selected text to clipboard
ExpressionEditor.ToolBarWidget.Evaluate.ToolTip=Evaluate or simplify expression
ExpressionEditor.ToolBarWidget.Paste.ToolTip=Paste text in clipboard
ExpressionEditor.ToolBarWidget.Redo.ToolTip=Redo an operation
ExpressionEditor.ToolBarWidget.SelectAll.ToolTip=Select all text
ExpressionEditor.ToolBarWidget.Undo.ToolTip=Undo an operation
ExpressionEditor.Tree.Arguments.Label=Arguments
ExpressionEditor.Tree.Fields.Label=Fields
ExpressionEditor.Tree.Operators.Label=Operators
Expand Down

0 comments on commit 9a98631

Please sign in to comment.