summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorChirag Manwani <cmkmanwani@gmail.com>2016-02-22 15:22:30 +0530
committerNoel Grandin <noelgrandin@gmail.com>2016-02-22 12:29:39 +0000
commit1b287f14b2adc79586ae2dde6b08cd8eb960e0ce (patch)
tree1fa1990f9299488739e0b40439be4cfd7fc3e1e4 /scripting
parentb9c71ed6de669f9d8091b4d56745a3f26f65812c (diff)
tdf#98004 Added toolbar to beanshell editor with undo/redo buttons
Change-Id: I1d553473f34622e1cb1dab3ffe74ec0c5fa05605 Reviewed-on: https://gerrit.libreoffice.org/22612 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'scripting')
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java33
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java22
-rw-r--r--scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java4
3 files changed, 37 insertions, 22 deletions
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java
index fe0a1cd7efde..2a6fde0b18b2 100644
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java
@@ -52,10 +52,11 @@ public class PlainSourceView extends JScrollPane implements
private GlyphGutter gg;
private int linecount;
private boolean isModified = false;
- private UndoManager undoManager;
private static final String undoKey = "Undo";
private static final String redoKey = "Redo";
private CompoundEdit compoundEdit = null;
+ private final int noLimit = -1;
+ UndoManager undoManager;
public PlainSourceView(ScriptSourceModel model) {
this.model = model;
@@ -63,6 +64,21 @@ public class PlainSourceView extends JScrollPane implements
model.setView(this);
}
+ public void undo(){
+ if(compoundEdit!=null){
+ compoundEdit.end();
+ undoManager.addEdit(compoundEdit);
+ compoundEdit = null;
+ }
+ if(undoManager.canUndo()){
+ undoManager.undo();
+ }
+ }
+ public void redo(){
+ if(undoManager.canRedo()){
+ undoManager.redo();
+ }
+ }
public void clear() {
ta.setText("");
}
@@ -123,7 +139,7 @@ public class PlainSourceView extends JScrollPane implements
ta.insert(model.getText(), 0);
ta.setFont(new Font(Font.MONOSPACED, ta.getFont().getStyle(), ta.getFont().getSize()));
undoManager = new UndoManager();
-
+ undoManager.setLimit(noLimit);
ta.getDocument().addUndoableEditListener(new UndoableEditListener(){
@Override
public void undoableEditHappened(UndoableEditEvent editEvent) {
@@ -151,23 +167,14 @@ public class PlainSourceView extends JScrollPane implements
ta.getActionMap().put(undoKey, new AbstractAction(undoKey){
@Override
public void actionPerformed(ActionEvent event) {
- if(compoundEdit!=null){
- compoundEdit.end();
- undoManager.addEdit(compoundEdit);
- compoundEdit = null;
- }
- if(undoManager.canUndo()){
- undoManager.undo();
- }
+ undo();
}
});
ta.getActionMap().put(redoKey, new AbstractAction(redoKey){
@Override
public void actionPerformed(ActionEvent event) {
- if(undoManager.canRedo()){
- undoManager.redo();
- }
+ redo();
}
});
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
index d63eb84e0c84..5c8bd6af0624 100644
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java
@@ -23,6 +23,7 @@ import com.sun.star.script.framework.provider.ScriptEditor;
import com.sun.star.script.framework.provider.SwingInvocation;
import com.sun.star.script.provider.XScriptContext;
+import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -267,7 +268,7 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener {
}
);
- String[] labels = {"Run", "Clear", "Save", "Close"};
+ String[] labels = {"Run", "Clear", "Save", "Close","Undo","Redo"};
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
@@ -281,8 +282,8 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener {
}
}
- frame.getContentPane().add((JComponent)view, "Center");
- frame.getContentPane().add(p, "South");
+ frame.getContentPane().add((JComponent)view, BorderLayout.CENTER);
+ frame.add(p, BorderLayout.NORTH);
frame.pack();
frame.setSize(590, 480);
frame.setLocation(300, 200);
@@ -358,18 +359,23 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener {
}
public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().equals("Run")) {
+ String actionCommand = e.getActionCommand();
+ if (actionCommand.equals("Run")) {
try {
execute();
} catch (Exception invokeException) {
showErrorMessage(invokeException.getMessage());
}
- } else if (e.getActionCommand().equals("Close")) {
+ } else if (actionCommand.equals("Close")) {
doClose();
- } else if (e.getActionCommand().equals("Save")) {
+ } else if (actionCommand.equals("Save")) {
saveTextArea();
- } else if (e.getActionCommand().equals("Clear")) {
+ } else if (actionCommand.equals("Clear")) {
view.clear();
+ } else if(actionCommand.equals("Undo")){
+ view.undo();
+ } else if(actionCommand.equals("Redo")){
+ view.redo();
}
}
-} \ No newline at end of file
+}
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java
index c60b6f1ac57a..6869fc39785b 100644
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java
@@ -23,4 +23,6 @@ public interface ScriptSourceView {
boolean isModified();
void setModified(boolean value);
String getText();
-} \ No newline at end of file
+ void undo();
+ void redo();
+}