Revision 486
tmp/org.txm.practically.rcp/doc/macroEdit.html (revision 486) | ||
---|---|---|
1 |
<html> |
|
2 |
From the edit dialog, you can:<br> |
|
3 |
<ul>reorder commands in the macro</ul> |
|
4 |
<ul>remove commands</ul> |
|
5 |
<ul>add new commands</ul> |
|
6 |
<ul>edit commands that have data associated with them (ex. the Find command).</ul> |
|
7 |
<br>The Edit dialog also allows you to add a new macro id to a command that didn't previously have an associated id (thus turning it into a persistent command), or alter (or remove) the id of an existing command. |
|
8 |
<br>Adding new commands to the macro requires that you have some knowledge of the commands. There is a filter above the <bold>Available Commands</bold> list that defaults to showing only edit commands (based on looking at categories). Some commands are not appropriate to a macro, but it's impossible for me to tell what they are, so you may have to experiment. |
|
9 |
<h3>Special macro helper commands</h3> |
|
10 |
<ul>Mark selection start - set a 'mark' at the current selection start, or at the caret pos if no selection</ul> |
|
11 |
<ul>Mark selection end - set a 'mark' at the current selection end, or at the caret pos if no selection</ul> |
|
12 |
<ul>Move cursor to mark - Set the editor cursor to the current mark position</ul> |
|
13 |
<ul>Insert string - this is the workhorse command used to add text. Can contain carriage returns.</ul> |
|
14 |
<ul>Find - perform various kinds of text searching</ul> |
|
15 |
<ul>Styled Text commands - These are commands I've added to the system since they aren't commands by default. Actions like "move cursor right" are supported by the StyledText widget but aren't mapped as key bindings.</ul> |
|
16 |
<ul>Macro script - You can write whatever scripts you'd like using beanshell. I pass in several variables for the editor that should be useful.</ul> |
|
17 |
<br> |
|
18 |
The Mark commands are provided as a way to maintain some state while other operations are performed without requiring scripting. |
|
19 |
For example, to comment a selected area, you could record a sequence of commands like: |
|
20 |
<ol>mark selection start</ol> |
|
21 |
<ol>move cursor right (puts cursor at end of selection</ol> |
|
22 |
<ol>insert string "*/"</ol> |
|
23 |
<ol>move cursor to mark</ol> |
|
24 |
<ol>insert string "/*"</ol> |
|
25 |
|
|
26 |
</html> |
|
0 | 27 |
tmp/org.txm.practically.rcp/doc/CVS/Entries (revision 486) | ||
---|---|---|
1 |
/macroEdit.html/1.1/Wed Oct 22 22:12:13 2008// |
|
2 |
/macroManage.html/1.1/Wed Oct 22 22:12:13 2008// |
|
3 |
/overall.html/1.1/Wed Oct 22 22:12:13 2008// |
|
4 |
D |
tmp/org.txm.practically.rcp/doc/CVS/Repository (revision 486) | ||
---|---|---|
1 |
PracticallyMacro/doc |
tmp/org.txm.practically.rcp/doc/CVS/Root (revision 486) | ||
---|---|---|
1 |
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro |
tmp/org.txm.practically.rcp/doc/macroManage.html (revision 486) | ||
---|---|---|
1 |
<html> |
|
2 |
|
|
3 |
<h1>Creating new macros</h2> |
|
4 |
Click the <bold>New</bold> button to create a new macro from scratch. |
|
5 |
<h1>Deleting Macros</h2> |
|
6 |
Select one or more macros to delete and click the delete button. Macros that are mapped to keystrokes will fail to delete, as will macro contributed by plug-ins. To delete a macro mapped to a key, you must first remove the key binding. |
|
7 |
<h1>Editing Macros</h2> |
|
8 |
Click the <bold>Edit</bold> button to edit an existing macro. Macros contributed from plug-ins cannot be edited. |
|
9 |
<h1>Copying Macros</h2> |
|
10 |
To copy one or more macros, select them and click the <bold>Copy</bold> button. Each macro will be copied and added to the list with a new name. This is useful if you need another similar command, or if you want to see the contents of a macro contributed from a plug-in. |
|
11 |
<h1>Sharing macros</h2> |
|
12 |
Click the <bold>Export</bold> or <bold>Import</bold> buttons to export or import macros. Macros exported to a file can be imported via the import dialog into another eclipse (with the Practically Macro plugins installed, as well as any required plugins/commands). Macros with ids that already exist in the current Eclipse will be skipped (i.e. they will not replace the current command with that ID). Also, from the export dialog you can copy the XML from the text box and put that directly into a plugin.xml definition with the following extension point: |
|
13 |
<br><pre> <extension point="PracticallyMacro.defineMacro"> |
|
14 |
include the text from the export page here |
|
15 |
</extension></pre><br> |
|
16 |
When exporting to a file, you can export one macro or a set of macros to the same file. If a macro uses other macros you have defined, you should export them all together. |
|
17 |
|
|
18 |
</html> |
|
0 | 19 |
tmp/org.txm.practically.rcp/doc/overall.html (revision 486) | ||
---|---|---|
1 |
<html> |
|
2 |
<h1>Practically Macro</h1> |
|
3 |
Practically Macro is an attempt to add simple editor scripting to the Eclipse platform; it is not an attempt at scripting the Eclipse platform in general. I believe that editor scripting, while similar to general scripting, is fundamentally a different problem. The intent of this plug-in is to enable users to record/create editor macros in a lightweight manner that can be used temporarily or easily shared with others. I have tried to do this in a way that uses public API and public assumptions, and I've mostly been able to do so. In my opinion, every character entered or navigation button pressed should generate a command that can be recorded. However, Eclipse doesn't generate commands for everything, so I've done the best I can. |
|
4 |
|
|
5 |
<h2>Requirements</h2> |
|
6 |
Eclipse 3.4 or greater; will not run correctly at 3.3. Requires the workbench. Shouldn't require jdt. |
|
7 |
|
|
8 |
<h2>Recording a macro</h2> |
|
9 |
Start recording a macro by typing Alt+Ctrl+R or clicking the "Record Macro" button on the main toolbar. The Record button is only enabled when a text editor has input focus. Once record mode is invoked, the record button will appear depressed. |
|
10 |
Actions that will be captured by recording a macro are Eclipse commands and keystrokes. Mouse activity is not captured and should be avoided in the editor window. |
|
11 |
Once you are done recording a macro, click the "Record Macro" button again. If you have recorded any macro contents, a Save dialog will pop up allowing you to supply a name/id/description for the macro. You can cancel if you don't want to keep the macro. To allow the macro to be persisted across Eclipse invocations or to allow mapping the command to a keystroke, you must supply an ID. If you only supply a name, the macro can be used during the Eclipse session only. You can modify/add an ID later in the session. |
|
12 |
|
|
13 |
<h2>Playing a macro</h2> |
|
14 |
To play a macro, use the drop down menu on the "Play Macro" button. You can use the "Play command..." button to execute any Eclipse command or macro that is already defined. If there are user macros defined with ids, they will show up in a menu called "Macros". Only the last few will be available, and they will be ordered by last used time. If there are commands that do not have associated ids, they will show up in the submenu named "Temporary Macros", ordered by last used time. After you have execute a macro, clicking the Play button will execute the last executed macro. |
|
15 |
|
|
16 |
<h2>Gotchas</h2> |
|
17 |
This plug-in is built on top of the Eclipse platform. Unfortunately, the Eclipse command structure is not designed with macro recording in mind. What this means is that not all commands are recordable, and some behavior may be a little sketchy. However, you can edit a macro after recording, so you should be able to patch up behavior that isn't desirable. The lack of an official Eclipse strategy means that there is no guide to what commands should be recordable, so I don't impose any artificial limitations.<br> |
|
18 |
Here are some types of actions that make sense to record as part of a macro:<br> |
|
19 |
<ul>typing characters (see note below)</ul> |
|
20 |
<ul>navigation characters (ex. arrows, page down)</ul> |
|
21 |
<ul>find dialog (I've supplied my own since the standard dialog isn't public)</ul> |
|
22 |
<ul>incremental find (with some hacking)</ul> |
|
23 |
<ul>previously recorded macros</ul> |
|
24 |
<ul>other commands that don't pop up dialogs (ex. file save, find next, organize imports, toggle insert mode)</ul> |
|
25 |
<br> |
|
26 |
Here are some types of actions that almost certainly won't work correctly:<br> |
|
27 |
<ul>Commands that bring up dialogs (ex. Go to line)</ul> |
|
28 |
<ul>Wizards and other dialogs (ex. Open File)</ul> |
|
29 |
<ul>ctrl+space intellisense</ul> |
|
30 |
<ul>invoking code templates like "foreach"</ul> |
|
31 |
|
|
32 |
<h3>Special notes</h3> |
|
33 |
Certain keystrokes are handled specially by the language editor. However, these editors don't generate commands associated with their behavior, so they are difficult to interpret. For example, in a Java file, if you type in a '<', a '>' will be inserted and the cursor will be placed between the two symbols. Also, the editor is put into a special edit mode so that if you backspace, both characters are deleted. However, there is no set of commands generated that accomplishes these tasks. Instead, the editor document captures the initial '<' via a VerifyKeyListener and then does the inserts and sets the mode directly on the document. Therefore, if you have this setting ("Automatically Close") turned on and type a '<', then the macro will not have any commands corresponding to some of these operations. You can edit the macro afterward, but that may be inconvenient. I've added another mode on the Options page that records keys as raw key events and plays them back. This preserves the behavior of special characters like '<', but is more difficult to edit and may not be sharable with users on other platforms. |
|
34 |
<br><bold>In general, I recommend running in 'Command' mode and 'typing through' special keystroke modes while recording a macro.</bold> |
|
35 |
|
|
36 |
<h2>Editing macros</h2> |
|
37 |
You can edit macros you have recorded via the Window->Preferences->PracticallyMacro Options->Editor Macro Definitions page. From this page, you can delete existing macros or edit macros. Select a macro and click the Edit... button. From the edit dialog, you can reorder commands in the macro, remove commands, add new commands, and edit commands that have data associated with them (ex. the Find command). |
|
38 |
The Edit dialog also allows you to add a new macro id to a command that didn't previously have an associated id (thus turning it into a persistent command), or alter the id of an existing command. |
|
39 |
|
|
40 |
<h2>Sharing macros</h2> |
|
41 |
From the Editor Macro Definitions page you can export or import macros. Macros exported to a file can be imported via the import dialog into another eclipse (with the Practically Macro plugins installed, as well as any required plugins/commands). |
|
42 |
|
|
43 |
<h2>Scripting</h2> |
|
44 |
Macro scripting is provided by plugins via an extension point. See the help for different script types on pref or edit pages for those plugins. There is no innate scripting provided by the base Practically Macro plugin, but there is a default beanshell plugin paired with the main plugin. |
|
45 |
</html> |
|
0 | 46 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/PlayCommandAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import org.eclipse.jface.action.Action; |
|
4 |
import org.eclipse.jface.action.IAction; |
|
5 |
import org.eclipse.jface.viewers.ISelection; |
|
6 |
import org.eclipse.swt.widgets.Display; |
|
7 |
import org.eclipse.swt.widgets.Shell; |
|
8 |
import org.eclipse.ui.IWorkbenchWindow; |
|
9 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
|
10 |
|
|
11 |
import practicallymacro.dialogs.PlayCommandDialog; |
|
12 |
|
|
13 |
|
|
14 |
public class PlayCommandAction extends Action implements IWorkbenchWindowActionDelegate { |
|
15 |
|
|
16 |
public void dispose() { |
|
17 |
// TODO Auto-generated method stub |
|
18 |
|
|
19 |
} |
|
20 |
|
|
21 |
public void init(IWorkbenchWindow window) { |
|
22 |
// TODO Auto-generated method stub |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
public void run(IAction action) |
|
27 |
{ |
|
28 |
run(); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public void run() { |
|
33 |
Shell shell = Display.getDefault().getActiveShell(); |
|
34 |
PlayCommandDialog dlg=new PlayCommandDialog(shell); |
|
35 |
dlg.open(); |
|
36 |
} |
|
37 |
|
|
38 |
public void selectionChanged(IAction action, ISelection selection) { |
|
39 |
// TODO Auto-generated method stub |
|
40 |
|
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public String getDescription() { |
|
45 |
return "Play any command in the system"; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public String getId() { |
|
50 |
return "com.none.actions.playCommandAction"; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public String getText() { |
|
55 |
return "Play Command..."; |
|
56 |
} |
|
57 |
|
|
58 |
|
|
59 |
} |
|
0 | 60 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/MarkSelectionEndAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import org.eclipse.jface.action.Action; |
|
4 |
import org.eclipse.jface.action.IAction; |
|
5 |
import org.eclipse.jface.viewers.ISelection; |
|
6 |
import org.eclipse.swt.custom.StyledText; |
|
7 |
import org.eclipse.swt.graphics.Point; |
|
8 |
import org.eclipse.ui.IWorkbenchWindow; |
|
9 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
|
10 |
|
|
11 |
import practicallymacro.model.EditorMacro; |
|
12 |
import practicallymacro.model.MacroManager; |
|
13 |
import practicallymacro.util.Utilities; |
|
14 |
|
|
15 |
|
|
16 |
public class MarkSelectionEndAction extends Action implements |
|
17 |
IWorkbenchWindowActionDelegate { |
|
18 |
|
|
19 |
public void dispose() { |
|
20 |
// TODO Auto-generated method stub |
|
21 |
|
|
22 |
} |
|
23 |
|
|
24 |
public void init(IWorkbenchWindow window) { |
|
25 |
// TODO Auto-generated method stub |
|
26 |
|
|
27 |
} |
|
28 |
|
|
29 |
public void run(IAction action) { |
|
30 |
run(); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public void run() { |
|
35 |
StyledText styled=Utilities.getStyledText(Utilities.getActiveEditor()); |
|
36 |
if (styled!=null) |
|
37 |
{ |
|
38 |
Point sel=styled.getSelection(); |
|
39 |
EditorMacro macro=MacroManager.getManager().getCurrentMacro(); |
|
40 |
if (macro!=null) |
|
41 |
macro.setMark(sel.x+sel.y); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
public void selectionChanged(IAction action, ISelection selection) { |
|
46 |
// TODO Auto-generated method stub |
|
47 |
|
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/SetCursorToMarkAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import org.eclipse.jface.action.Action; |
|
4 |
import org.eclipse.jface.action.IAction; |
|
5 |
import org.eclipse.jface.viewers.ISelection; |
|
6 |
import org.eclipse.swt.custom.StyledText; |
|
7 |
import org.eclipse.ui.IWorkbenchWindow; |
|
8 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
|
9 |
|
|
10 |
import practicallymacro.model.EditorMacro; |
|
11 |
import practicallymacro.model.MacroManager; |
|
12 |
import practicallymacro.util.Utilities; |
|
13 |
|
|
14 |
|
|
15 |
public class SetCursorToMarkAction extends Action implements |
|
16 |
IWorkbenchWindowActionDelegate { |
|
17 |
|
|
18 |
public void dispose() { |
|
19 |
// TODO Auto-generated method stub |
|
20 |
|
|
21 |
} |
|
22 |
|
|
23 |
public void init(IWorkbenchWindow window) { |
|
24 |
// TODO Auto-generated method stub |
|
25 |
|
|
26 |
} |
|
27 |
|
|
28 |
public void run(IAction action) { |
|
29 |
run(); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void run() |
|
34 |
{ |
|
35 |
StyledText styled=Utilities.getStyledText(Utilities.getActiveEditor()); |
|
36 |
if (styled!=null) |
|
37 |
{ |
|
38 |
EditorMacro macro=MacroManager.getManager().getCurrentMacro(); |
|
39 |
if (macro!=null) |
|
40 |
{ |
|
41 |
int markPos=macro.getMark(); |
|
42 |
styled.setCaretOffset(markPos); |
|
43 |
} |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
public void selectionChanged(IAction action, ISelection selection) { |
|
48 |
// TODO Auto-generated method stub |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
} |
|
0 | 53 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/CVS/Root (revision 486) | ||
---|---|---|
1 |
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/CVS/Entries (revision 486) | ||
---|---|---|
1 |
/MacroFindAction.java/1.2/Thu Dec 4 01:13:38 2008// |
|
2 |
/MarkSelectionEndAction.java/1.1/Wed Oct 22 22:12:13 2008// |
|
3 |
/MarkSelectionStartAction.java/1.1/Wed Oct 22 22:12:13 2008// |
|
4 |
/PlayCommandAction.java/1.1/Wed Oct 22 22:12:13 2008// |
|
5 |
/PlayDropdownAction.java/1.9/Sat Jul 13 15:28:42 2013// |
|
6 |
/QuickExecuteAction.java/1.6/Sat Nov 10 12:00:39 2012// |
|
7 |
/RecordCommandAction.java/1.9/Sat Jul 13 15:28:42 2013// |
|
8 |
/SetCursorToMarkAction.java/1.1/Wed Oct 22 22:12:13 2008// |
|
9 |
D |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/CVS/Repository (revision 486) | ||
---|---|---|
1 |
PracticallyMacro/src/practicallymacro/actions |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/RecordCommandAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.eclipse.core.commands.IHandler; |
|
6 |
import org.eclipse.core.expressions.EvaluationResult; |
|
7 |
import org.eclipse.core.expressions.Expression; |
|
8 |
import org.eclipse.core.expressions.ExpressionInfo; |
|
9 |
import org.eclipse.core.expressions.IEvaluationContext; |
|
10 |
import org.eclipse.core.runtime.CoreException; |
|
11 |
import org.eclipse.jface.action.Action; |
|
12 |
import org.eclipse.jface.action.ContributionItem; |
|
13 |
import org.eclipse.jface.action.IAction; |
|
14 |
import org.eclipse.jface.action.IStatusLineManager; |
|
15 |
import org.eclipse.jface.action.StatusLineLayoutData; |
|
16 |
import org.eclipse.jface.commands.ActionHandler; |
|
17 |
import org.eclipse.jface.dialogs.Dialog; |
|
18 |
import org.eclipse.jface.text.IDocument; |
|
19 |
import org.eclipse.jface.viewers.ISelection; |
|
20 |
import org.eclipse.swt.SWT; |
|
21 |
import org.eclipse.swt.custom.CLabel; |
|
22 |
import org.eclipse.swt.custom.StyledText; |
|
23 |
import org.eclipse.swt.events.DisposeEvent; |
|
24 |
import org.eclipse.swt.events.DisposeListener; |
|
25 |
import org.eclipse.swt.graphics.Color; |
|
26 |
import org.eclipse.swt.graphics.FontMetrics; |
|
27 |
import org.eclipse.swt.graphics.GC; |
|
28 |
import org.eclipse.swt.layout.GridData; |
|
29 |
import org.eclipse.swt.layout.GridLayout; |
|
30 |
import org.eclipse.swt.widgets.Composite; |
|
31 |
import org.eclipse.swt.widgets.Display; |
|
32 |
import org.eclipse.swt.widgets.Label; |
|
33 |
import org.eclipse.swt.widgets.Shell; |
|
34 |
import org.eclipse.ui.IEditorPart; |
|
35 |
import org.eclipse.ui.ISources; |
|
36 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
|
37 |
import org.eclipse.ui.IWorkbenchWindow; |
|
38 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
|
39 |
import org.eclipse.ui.commands.ICommandService; |
|
40 |
import org.eclipse.ui.handlers.IHandlerActivation; |
|
41 |
import org.eclipse.ui.handlers.IHandlerService; |
|
42 |
import org.eclipse.ui.part.MultiPageEditorPart; |
|
43 |
import org.eclipse.ui.texteditor.AbstractTextEditor; |
|
44 |
|
|
45 |
import practicallymacro.commands.IMacroCommand; |
|
46 |
import practicallymacro.dialogs.SaveMacroDialog; |
|
47 |
import practicallymacro.editormacros.Activator; |
|
48 |
import practicallymacro.model.EditorMacro; |
|
49 |
import practicallymacro.model.MacroManager; |
|
50 |
import practicallymacro.model.MacroRecorder; |
|
51 |
import practicallymacro.preferences.Initializer; |
|
52 |
import practicallymacro.util.MacroConsole; |
|
53 |
import practicallymacro.util.Utilities; |
|
54 |
|
|
55 |
|
|
56 |
public class RecordCommandAction extends Action implements IWorkbenchWindowActionDelegate |
|
57 |
{ |
|
58 |
|
|
59 |
private static MacroRecorder mRecorder=null; |
|
60 |
// private static IAction mSavedFindAction; |
|
61 |
private static ContributionItem mRecordingWidget=null; |
|
62 |
private static DisposeListener mDisposeListener=new DisposeListener() |
|
63 |
{ |
|
64 |
public void widgetDisposed(DisposeEvent e) |
|
65 |
{ |
|
66 |
//called when styled text is closed. Should end record mode if still on |
|
67 |
shutDownRecorder(); |
|
68 |
} |
|
69 |
}; |
|
70 |
|
|
71 |
public RecordCommandAction() |
|
72 |
{ |
|
73 |
} |
|
74 |
|
|
75 |
public void dispose() |
|
76 |
{ |
|
77 |
//nothing to do here |
|
78 |
} |
|
79 |
|
|
80 |
public void init(IWorkbenchWindow window) { |
|
81 |
// TODO Auto-generated method stub |
|
82 |
|
|
83 |
} |
|
84 |
|
|
85 |
public void run(IAction action) { |
|
86 |
|
|
87 |
String state = MacroManager.getManager().getMacroState(); |
|
88 |
|
|
89 |
if (state == MacroManager.State_Idle) |
|
90 |
{ |
|
91 |
IEditorPart editor=Utilities.getActiveEditor(); |
|
92 |
StyledText styledText = Utilities.getStyledText(editor); |
|
93 |
if (styledText==null) |
|
94 |
return; |
|
95 |
|
|
96 |
styledText.addDisposeListener(mDisposeListener); |
|
97 |
|
|
98 |
IStatusLineManager statusLineManager=editor.getEditorSite().getActionBars().getStatusLineManager(); |
|
99 |
addStatusBarWidget(statusLineManager); |
|
100 |
mRecorder = new MacroRecorder(editor); |
|
101 |
mRecorder.start(); |
|
102 |
|
|
103 |
styledText.addListener(SWT.KeyDown, mRecorder); |
|
104 |
styledText.addListener(SWT.KeyUp, mRecorder); |
|
105 |
|
|
106 |
IDocument document=Utilities.getIDocumentForEditor(mRecorder.getEditor()); |
|
107 |
document.addDocumentListener(mRecorder); |
|
108 |
document.addDocumentListener(mRecorder.getMarkUpdater()); |
|
109 |
|
|
110 |
ICommandService cs = MacroManager.getOldCommandService(); |
|
111 |
cs.addExecutionListener(mRecorder); |
|
112 |
|
|
113 |
registerFindAction(); |
|
114 |
|
|
115 |
MacroManager.getManager().setMacroState(MacroManager.State_Recording); |
|
116 |
} |
|
117 |
else if (state == MacroManager.State_Recording) |
|
118 |
{ |
|
119 |
shutDownRecorder(); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
private static void shutDownRecorder() |
|
124 |
{ |
|
125 |
if (mRecorder==null) |
|
126 |
return; |
|
127 |
|
|
128 |
try |
|
129 |
{ |
|
130 |
IEditorPart editor=mRecorder.getEditor(); |
|
131 |
IEditorPart currentEditor=Utilities.getActiveEditor(); |
|
132 |
// if (editor!=currentEditor) |
|
133 |
// { |
|
134 |
// MacroConsole.getConsole().writeln("Record-mode stop failed because editor has changed"); |
|
135 |
// return; |
|
136 |
// } |
|
137 |
|
|
138 |
try |
|
139 |
{ |
|
140 |
if (currentEditor!=null) |
|
141 |
{ |
|
142 |
IStatusLineManager statusLineManager=currentEditor.getEditorSite().getActionBars().getStatusLineManager(); |
|
143 |
removeStatusBarWidget(statusLineManager); |
|
144 |
} |
|
145 |
|
|
146 |
try |
|
147 |
{ |
|
148 |
StyledText styledText = Utilities.getStyledText(editor); |
|
149 |
|
|
150 |
if (styledText!=null) |
|
151 |
{ |
|
152 |
styledText.removeListener(SWT.KeyDown, mRecorder); |
|
153 |
styledText.removeListener(SWT.KeyUp, mRecorder); |
|
154 |
styledText.removeDisposeListener(mDisposeListener); |
|
155 |
} |
|
156 |
} |
|
157 |
catch (Exception e) |
|
158 |
{ |
|
159 |
e.printStackTrace(); |
|
160 |
} |
|
161 |
|
|
162 |
try |
|
163 |
{ |
|
164 |
IDocument document=Utilities.getIDocumentForEditor(editor); |
|
165 |
if (document!=null) |
|
166 |
{ |
|
167 |
document.removeDocumentListener(mRecorder); |
|
168 |
document.removeDocumentListener(mRecorder.getMarkUpdater()); |
|
169 |
} |
|
170 |
} |
|
171 |
catch (Exception e) |
|
172 |
{ |
|
173 |
e.printStackTrace(); |
|
174 |
} |
|
175 |
|
|
176 |
ICommandService cs = MacroManager.getOldCommandService(); |
|
177 |
cs.removeExecutionListener(mRecorder); |
|
178 |
|
|
179 |
try |
|
180 |
{ |
|
181 |
unregisterFindAction(); |
|
182 |
} |
|
183 |
catch (Exception e) |
|
184 |
{ |
|
185 |
e.printStackTrace(); |
|
186 |
} |
|
187 |
} |
|
188 |
catch (Exception e) |
|
189 |
{ |
|
190 |
//catch all exceptions since we don't want anything bad that happens to prevent other cleanup |
|
191 |
e.printStackTrace(); |
|
192 |
} |
|
193 |
|
|
194 |
mRecorder.stop(); |
|
195 |
|
|
196 |
List<IMacroCommand> commands=mRecorder.getMacroCommands(); |
|
197 |
if (commands.size()>0) |
|
198 |
{ |
|
199 |
if (Activator.getDefault().getPreferenceStore().getBoolean(Initializer.Pref_CompressCharInsertsWhenRecording)) |
|
200 |
{ |
|
201 |
commands=EditorMacro.compressStringInsertions(commands); |
|
202 |
} |
|
203 |
|
|
204 |
EditorMacro newMacro=null; |
|
205 |
if (Activator.getDefault().getPreferenceStore().getBoolean(Initializer.Pref_ShowSaveDialogAfterRecording)) |
|
206 |
{ |
|
207 |
Shell shell = Display.getDefault().getActiveShell(); |
|
208 |
SaveMacroDialog dlg=new SaveMacroDialog(shell, commands); |
|
209 |
if (dlg.open()==Dialog.OK) |
|
210 |
{ |
|
211 |
//store as last recorded macro |
|
212 |
newMacro=dlg.getMacro(); |
|
213 |
} |
|
214 |
} |
|
215 |
else |
|
216 |
{ |
|
217 |
newMacro=new EditorMacro(commands, "", MacroManager.getManager().getUniqueMacroName(), ""); |
|
218 |
} |
|
219 |
|
|
220 |
if (newMacro!=null) |
|
221 |
{ |
|
222 |
MacroManager.getManager().addMacro(newMacro); |
|
223 |
MacroManager.getManager().setLastMacro(newMacro); |
|
224 |
newMacro.dump(); |
|
225 |
} |
|
226 |
|
|
227 |
} else { |
|
228 |
//do nothing; empty set of commands |
|
229 |
MacroConsole.getConsole().writeln("No commands recorded; no macro defined", MacroConsole.Type_RecordingCommand); |
|
230 |
} |
|
231 |
} |
|
232 |
finally |
|
233 |
{ |
|
234 |
mRecorder=null; |
|
235 |
MacroManager.getManager().setMacroState(MacroManager.State_Idle); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
private void addStatusBarWidget(IStatusLineManager statusLineManager) |
|
240 |
{ |
|
241 |
if (mRecordingWidget==null) |
|
242 |
{ |
|
243 |
mRecordingWidget=new RecordingWidget(); |
|
244 |
} |
|
245 |
|
|
246 |
|
|
247 |
statusLineManager.add(mRecordingWidget); |
|
248 |
statusLineManager.update(true); |
|
249 |
} |
|
250 |
|
|
251 |
private static void removeStatusBarWidget(IStatusLineManager statusLineManager) |
|
252 |
{ |
|
253 |
if (mRecordingWidget!=null) |
|
254 |
statusLineManager.remove(mRecordingWidget); |
|
255 |
statusLineManager.update(true); |
|
256 |
} |
|
257 |
|
|
258 |
public void selectionChanged(IAction action, ISelection selection) { |
|
259 |
// nothing to do |
|
260 |
} |
|
261 |
|
|
262 |
private void registerFindAction() |
|
263 |
{ |
|
264 |
//This is a hack. It's not a hack to call activateHandler, but I need to make sure |
|
265 |
//my version of the command is used, so I'm assigning it a high priority via |
|
266 |
//the 'Expression'. This is necessary starting in Juno, where they have |
|
267 |
//tweaked some of the command mapping code. |
|
268 |
|
|
269 |
// AbstractTextEditor ate=findTextEditor(mRecorder.getEditor()); |
|
270 |
// if (ate!=null) |
|
271 |
{ |
|
272 |
// mSavedFindAction=ate.getAction(ITextEditorActionConstants.FIND); |
|
273 |
IAction macroFindAction=new MacroFindAction(mRecorder); |
|
274 |
// macroFindAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.FIND_REPLACE); |
|
275 |
//// ate.removeActionActivationCode(ITextEditorActionConstants.FIND); |
|
276 |
//// ate.setAction(ITextEditorActionConstants.FIND, null); |
|
277 |
// ate.setAction(ITextEditorActionConstants.FIND, macroFindAction); |
|
278 |
|
|
279 |
IHandlerService hs = MacroManager.getOldHandlerService(); |
|
280 |
IHandler actionHandler = new ActionHandler(macroFindAction); |
|
281 |
// String id="org.eclipse.ui.textEditorScope"; |
|
282 |
// Set<String> partIDs=new HashSet<String>(); |
|
283 |
// partIDs.add("partID"); |
|
284 |
Expression expr=new HighPriorityExpression();//id, partIDs); |
|
285 |
mFindReplaceHandler = hs.activateHandler(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE, actionHandler, expr); |
|
286 |
} |
|
287 |
|
|
288 |
} |
|
289 |
|
|
290 |
private static IHandlerActivation mFindReplaceHandler=null; |
|
291 |
|
|
292 |
private static void unregisterFindAction() |
|
293 |
{ |
|
294 |
if (mFindReplaceHandler!=null) |
|
295 |
mFindReplaceHandler.getHandlerService().deactivateHandler(mFindReplaceHandler); |
|
296 |
// AbstractTextEditor ate=findTextEditor(mRecorder.getEditor()); |
|
297 |
// if (ate!=null) |
|
298 |
// { |
|
299 |
// ate.setAction(ITextEditorActionConstants.FIND, mSavedFindAction); |
|
300 |
// } |
|
301 |
} |
|
302 |
|
|
303 |
public static AbstractTextEditor findTextEditor(IEditorPart editor) |
|
304 |
{ |
|
305 |
if (editor instanceof AbstractTextEditor) |
|
306 |
return (AbstractTextEditor)editor; |
|
307 |
|
|
308 |
if (editor instanceof MultiPageEditorPart) |
|
309 |
{ |
|
310 |
MultiPageEditorPart mpe=(MultiPageEditorPart)editor; |
|
311 |
IEditorPart[] parts=mpe.findEditors(editor.getEditorInput()); |
|
312 |
for (IEditorPart editorPart : parts) |
|
313 |
{ |
|
314 |
if (editorPart instanceof AbstractTextEditor) |
|
315 |
{ |
|
316 |
return (AbstractTextEditor)editorPart; |
|
317 |
} |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
return null; |
|
322 |
} |
|
323 |
|
|
324 |
public static MacroRecorder getRecorder() |
|
325 |
{ |
|
326 |
return mRecorder; |
|
327 |
} |
|
328 |
|
|
329 |
private static class RecordingWidget extends ContributionItem |
|
330 |
{ |
|
331 |
private static int DRAW_FLAGS = SWT.DRAW_MNEMONIC | SWT.DRAW_TAB | SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER; |
|
332 |
CLabel mStatus; |
|
333 |
|
|
334 |
public static final String ID="Recording_STATUS"; |
|
335 |
|
|
336 |
public RecordingWidget() |
|
337 |
{ |
|
338 |
super(ID); |
|
339 |
} |
|
340 |
|
|
341 |
@Override |
|
342 |
public void fill(Composite parent) |
|
343 |
{ |
|
344 |
Label sep=new Label(parent, SWT.SEPARATOR); |
|
345 |
|
|
346 |
Composite comp=new Composite(parent, SWT.None); |
|
347 |
GridLayout gl=new GridLayout(1, false); |
|
348 |
gl.marginHeight=0; |
|
349 |
gl.marginWidth=0; |
|
350 |
gl.horizontalSpacing=1; |
|
351 |
gl.verticalSpacing=0; |
|
352 |
comp.setLayout(gl); |
|
353 |
|
|
354 |
String recordingString = "Recording"; |
|
355 |
|
|
356 |
mStatus=new CLabel(comp, SWT.SHADOW_NONE|SWT.CENTER); |
|
357 |
mStatus.setBackground(new Color[]{parent.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE), |
|
358 |
parent.getDisplay().getSystemColor(SWT.COLOR_CYAN)}, |
|
359 |
new int[] {100}, true); |
|
360 |
|
|
361 |
GridData lgd=new GridData(GridData.FILL_BOTH); |
|
362 |
|
|
363 |
int widthHint=(-1); |
|
364 |
int heightHint=(-1); |
|
365 |
{ |
|
366 |
GC gc = new GC(mStatus); |
|
367 |
gc.setFont(mStatus.getFont()); |
|
368 |
FontMetrics fm = gc.getFontMetrics(); |
|
369 |
widthHint = gc.textExtent(recordingString, DRAW_FLAGS).x+6; //6 pixels is built in as an indent that we can't get at. |
|
370 |
heightHint = fm.getHeight(); |
|
371 |
gc.dispose(); |
|
372 |
} |
|
373 |
|
|
374 |
lgd.widthHint=widthHint; |
|
375 |
mStatus.setLayoutData(lgd); |
|
376 |
|
|
377 |
StatusLineLayoutData data = new StatusLineLayoutData(); |
|
378 |
data.heightHint = heightHint; |
|
379 |
sep.setLayoutData(data); |
|
380 |
|
|
381 |
StatusLineLayoutData overallData = new StatusLineLayoutData(); |
|
382 |
overallData.heightHint=heightHint; |
|
383 |
overallData.widthHint=widthHint; |
|
384 |
comp.setLayoutData(overallData); |
|
385 |
|
|
386 |
mStatus.setText(recordingString); |
|
387 |
} |
|
388 |
} |
|
389 |
|
|
390 |
static class HighPriorityExpression extends Expression |
|
391 |
{ |
|
392 |
// private String id; |
|
393 |
// private Set<String> partIds; |
|
394 |
|
|
395 |
public HighPriorityExpression() //String id, Set<String> associatedPartIds) |
|
396 |
{ |
|
397 |
// this.id = id; |
|
398 |
// this.partIds = associatedPartIds; |
|
399 |
} |
|
400 |
|
|
401 |
@Override |
|
402 |
public void collectExpressionInfo(ExpressionInfo info) { |
|
403 |
//assign some high-priority items to make sure I get picked |
|
404 |
//up before the main findReplace command. I don't know |
|
405 |
//if these variables are used for anything other than assigning |
|
406 |
//priority. If so, there might be some unintended side effects. |
|
407 |
info.addVariableNameAccess(ISources.ACTIVE_CONTEXT_NAME); |
|
408 |
info.addVariableNameAccess(ISources.ACTIVE_PART_ID_NAME); |
|
409 |
info.addVariableNameAccess(ISources.ACTIVE_SITE_NAME); |
|
410 |
} |
|
411 |
|
|
412 |
@Override |
|
413 |
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException { |
|
414 |
//if I understood more about this, I might try to match up the part id of the |
|
415 |
//editor etc. As it is, I'm just allowing it to be invoked regardless. This |
|
416 |
//will only be available if a macro is currently being recorded, so the risk |
|
417 |
//doesn't seem that high. |
|
418 |
return EvaluationResult.TRUE; |
|
419 |
// Object obj = context.getVariable(ISources.ACTIVE_CONTEXT_NAME); |
|
420 |
// if (obj instanceof Collection<?>) { |
|
421 |
// boolean rc = ((Collection) obj).contains(id); |
|
422 |
// if (rc) { |
|
423 |
// return EvaluationResult.TRUE; |
|
424 |
// } |
|
425 |
// } |
|
426 |
// if (!partIds.isEmpty()) { |
|
427 |
// return EvaluationResult.valueOf(partIds.contains(context |
|
428 |
// .getVariable(ISources.ACTIVE_PART_ID_NAME))); |
|
429 |
// } |
|
430 |
// return EvaluationResult.FALSE; |
|
431 |
} |
|
432 |
|
|
433 |
@Override |
|
434 |
public boolean equals(Object obj) { |
|
435 |
if (!(obj instanceof HighPriorityExpression)) { |
|
436 |
return false; |
|
437 |
} |
|
438 |
return true; |
|
439 |
// ActionSetAndPartExpression exp = (ActionSetAndPartExpression) obj; |
|
440 |
// return id.equals(exp.id) && partIds.equals(exp.partIds); |
|
441 |
} |
|
442 |
|
|
443 |
@Override |
|
444 |
public int hashCode() { |
|
445 |
return 20; |
|
446 |
// return id.hashCode() + partIds.hashCode(); |
|
447 |
} |
|
448 |
} |
|
449 |
|
|
450 |
} |
|
0 | 451 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/MarkSelectionStartAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import org.eclipse.jface.action.Action; |
|
4 |
import org.eclipse.jface.action.IAction; |
|
5 |
import org.eclipse.jface.viewers.ISelection; |
|
6 |
import org.eclipse.swt.custom.StyledText; |
|
7 |
import org.eclipse.ui.IWorkbenchWindow; |
|
8 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
|
9 |
|
|
10 |
import practicallymacro.model.EditorMacro; |
|
11 |
import practicallymacro.model.MacroManager; |
|
12 |
import practicallymacro.util.Utilities; |
|
13 |
|
|
14 |
|
|
15 |
public class MarkSelectionStartAction extends Action implements |
|
16 |
IWorkbenchWindowActionDelegate { |
|
17 |
|
|
18 |
public void dispose() { |
|
19 |
// TODO Auto-generated method stub |
|
20 |
|
|
21 |
} |
|
22 |
|
|
23 |
public void init(IWorkbenchWindow window) { |
|
24 |
// TODO Auto-generated method stub |
|
25 |
|
|
26 |
} |
|
27 |
|
|
28 |
public void run(IAction action) { |
|
29 |
run(); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void run() { |
|
34 |
StyledText styled=Utilities.getStyledText(Utilities.getActiveEditor()); |
|
35 |
if (styled!=null) |
|
36 |
{ |
|
37 |
EditorMacro macro=MacroManager.getManager().getCurrentMacro(); |
|
38 |
if (macro!=null) |
|
39 |
macro.setMark(styled.getSelection().x); |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
public void selectionChanged(IAction action, ISelection selection) { |
|
44 |
// TODO Auto-generated method stub |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 |
} |
|
0 | 49 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/QuickExecuteAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import org.eclipse.jface.action.IAction; |
|
4 |
import org.eclipse.jface.dialogs.Dialog; |
|
5 |
import org.eclipse.jface.viewers.ISelection; |
|
6 |
import org.eclipse.swt.widgets.Display; |
|
7 |
import org.eclipse.swt.widgets.Shell; |
|
8 |
import org.eclipse.ui.IEditorPart; |
|
9 |
import org.eclipse.ui.IWorkbenchWindow; |
|
10 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
|
11 |
|
|
12 |
import practicallymacro.commands.EclipseCommand; |
|
13 |
import practicallymacro.dialogs.QuickExecuteDialog; |
|
14 |
import practicallymacro.util.Utilities; |
|
15 |
|
|
16 |
public class QuickExecuteAction implements IWorkbenchWindowActionDelegate { |
|
17 |
|
|
18 |
IWorkbenchWindow mWindow; |
|
19 |
public void dispose() { |
|
20 |
// TODO Auto-generated method stub |
|
21 |
|
|
22 |
} |
|
23 |
|
|
24 |
public void init(IWorkbenchWindow window) |
|
25 |
{ |
|
26 |
mWindow=window; |
|
27 |
} |
|
28 |
|
|
29 |
public void run(IAction action) { |
|
30 |
Shell shell=null; |
|
31 |
if (mWindow!=null) |
|
32 |
shell=mWindow.getShell(); |
|
33 |
else |
|
34 |
shell=Display.getDefault().getActiveShell(); |
|
35 |
QuickExecuteDialog dlg=new QuickExecuteDialog(shell); |
|
36 |
if (dlg.open()==Dialog.OK) |
|
37 |
{ |
|
38 |
String commandID=dlg.getCommandID(); |
|
39 |
if (commandID!=null) |
|
40 |
{ |
|
41 |
EclipseCommand command=new EclipseCommand(commandID); |
|
42 |
IEditorPart editor=Utilities.getActiveEditor(); |
|
43 |
command.execute(editor); |
|
44 |
} |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public void selectionChanged(IAction action, ISelection selection) { |
|
49 |
// TODO Auto-generated method stub |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
} |
|
0 | 54 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/MacroFindAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import org.eclipse.jface.action.Action; |
|
4 |
import org.eclipse.swt.widgets.Display; |
|
5 |
|
|
6 |
import practicallymacro.commands.FindCommand; |
|
7 |
import practicallymacro.model.MacroRecorder; |
|
8 |
|
|
9 |
public class MacroFindAction extends Action |
|
10 |
{ |
|
11 |
private MacroRecorder mRecorder; |
|
12 |
public MacroFindAction(MacroRecorder recorder) |
|
13 |
{ |
|
14 |
mRecorder=recorder; |
|
15 |
} |
|
16 |
|
|
17 |
@Override |
|
18 |
public void run() |
|
19 |
{ |
|
20 |
FindCommand fc=new FindCommand(); |
|
21 |
fc.configureNew(Display.getDefault().getActiveShell()); |
|
22 |
mRecorder.recordCommand(fc); |
|
23 |
fc.execute(mRecorder.getEditor()); |
|
24 |
System.out.println("running find action"); |
|
25 |
} |
|
26 |
|
|
27 |
} |
|
0 | 28 |
tmp/org.txm.practically.rcp/src/practicallymacro/actions/PlayDropdownAction.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.actions; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.Collections; |
|
6 |
import java.util.Comparator; |
|
7 |
import java.util.HashSet; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
import java.util.Set; |
|
11 |
|
|
12 |
import org.eclipse.core.commands.Command; |
|
13 |
import org.eclipse.jface.action.Action; |
|
14 |
import org.eclipse.jface.action.ActionContributionItem; |
|
15 |
import org.eclipse.jface.action.IAction; |
|
16 |
import org.eclipse.jface.dialogs.Dialog; |
|
17 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
18 |
import org.eclipse.jface.viewers.ISelection; |
|
19 |
import org.eclipse.swt.SWT; |
|
20 |
import org.eclipse.swt.events.MenuAdapter; |
|
21 |
import org.eclipse.swt.events.MenuEvent; |
|
22 |
import org.eclipse.swt.events.SelectionAdapter; |
|
23 |
import org.eclipse.swt.events.SelectionEvent; |
|
24 |
import org.eclipse.swt.widgets.Control; |
|
25 |
import org.eclipse.swt.widgets.Display; |
|
26 |
import org.eclipse.swt.widgets.Menu; |
|
27 |
import org.eclipse.swt.widgets.MenuItem; |
|
28 |
import org.eclipse.ui.IEditorPart; |
|
29 |
import org.eclipse.ui.IWorkbenchWindow; |
|
30 |
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate; |
|
31 |
import org.eclipse.ui.commands.ICommandService; |
|
32 |
|
|
33 |
import practicallymacro.commands.EclipseCommand; |
|
34 |
import practicallymacro.dialogs.EditMacroDialog; |
|
35 |
import practicallymacro.dialogs.MacroDefinitionsPage; |
|
36 |
import practicallymacro.model.EditorMacro; |
|
37 |
import practicallymacro.model.MacroManager; |
|
38 |
import practicallymacro.util.Utilities; |
|
39 |
|
|
40 |
|
|
41 |
public class PlayDropdownAction implements IWorkbenchWindowPulldownDelegate |
|
42 |
{ |
|
43 |
|
|
44 |
private Menu fMenu; |
|
45 |
private IAction mPlayAnyCommandAction=new PlayCommandAction(); |
|
46 |
|
|
47 |
public void dispose() { |
|
48 |
// TODO Auto-generated method stub |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
public void init(IWorkbenchWindow window) { |
|
53 |
// TODO Auto-generated method stub |
|
54 |
|
|
55 |
} |
|
56 |
|
|
57 |
public void run(IAction action) { |
|
58 |
EditorMacro macro=MacroManager.getManager().getLastMacro(); |
|
59 |
if (macro!=null) |
|
60 |
{ |
|
61 |
IEditorPart editor=Utilities.getActiveEditor(); |
|
62 |
macro.run(editor); |
|
63 |
} |
|
64 |
else |
|
65 |
{ |
|
66 |
MessageDialog.openInformation(null, "Execute last macro", "No recently recorded/used macro"); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
public void selectionChanged(IAction action, ISelection selection) { |
|
71 |
// TODO Auto-generated method stub |
|
72 |
|
|
73 |
} |
|
74 |
|
|
75 |
public Menu getMenu(Control parent) { |
|
76 |
setMenu(new Menu(parent)); |
|
77 |
fillMenu(fMenu); |
|
78 |
initMenu(); |
|
79 |
return fMenu; |
|
80 |
} |
|
81 |
|
|
82 |
protected void fillMenu(Menu menu) |
|
83 |
{ |
|
84 |
//make "run last", "execute any command..." (not just macros) |
|
85 |
ActionContributionItem item = new ActionContributionItem(mPlayAnyCommandAction); |
|
86 |
item.fill(menu, -1); |
|
87 |
|
|
88 |
List<EditorMacro> tempMacros=MacroManager.getManager().getUsedTempMacros(15); |
|
89 |
if (tempMacros.size()>0) |
|
90 |
{ |
|
91 |
MenuItem cascadeMenu=new MenuItem(menu, SWT.CASCADE); |
|
92 |
cascadeMenu.setText("Temporary macros"); |
|
93 |
Menu tempMRUMenu=new Menu(cascadeMenu); |
|
94 |
cascadeMenu.setMenu(tempMRUMenu); |
|
95 |
for (EditorMacro macro : tempMacros) |
|
96 |
{ |
|
97 |
Action action=new MacroAction(macro); |
|
98 |
item = new ActionContributionItem(action); |
|
99 |
item.fill(tempMRUMenu, -1); |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
//add the mru list of macros |
|
104 |
List<EditorMacro> macros=MacroManager.getManager().getUsedMacros(15); |
|
105 |
if (macros.size()>0) |
|
106 |
{ |
|
107 |
MenuItem cascadeMenu=new MenuItem(menu, SWT.CASCADE); |
|
108 |
cascadeMenu.setText("Saved Macros"); |
|
109 |
Menu mruMenu=new Menu(cascadeMenu); |
|
110 |
cascadeMenu.setMenu(mruMenu); |
|
111 |
for (EditorMacro editorMacro : macros) |
|
112 |
{ |
|
113 |
Action action=new MacroAction(editorMacro); |
|
114 |
item = new ActionContributionItem(action); |
|
115 |
item.fill(mruMenu, -1); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
new MenuItem(menu, SWT.SEPARATOR); |
|
120 |
|
|
121 |
//add the mru list of macro/temp macros that can be edited (or viewed?) |
|
122 |
List<EditorMacro> allMacros=new ArrayList<EditorMacro>(); |
|
123 |
allMacros.addAll(macros); |
|
124 |
allMacros.addAll(tempMacros); |
|
125 |
Collections.sort(allMacros, new Comparator<EditorMacro>() |
|
126 |
{ |
|
127 |
public int compare(EditorMacro o1, EditorMacro o2) |
|
128 |
{ |
|
129 |
return (o1.getLastUse()>o2.getLastUse())? -1 : 1; |
|
130 |
} |
|
131 |
}); |
|
132 |
if (allMacros.size()>0) |
|
133 |
{ |
|
134 |
MenuItem cascadeMenu=new MenuItem(menu, SWT.CASCADE); |
|
135 |
cascadeMenu.setText("Edit macro..."); |
|
136 |
Menu editMenu=new Menu(cascadeMenu); |
|
137 |
cascadeMenu.setMenu(editMenu); |
|
138 |
for (int i=0;i<Math.min(10, allMacros.size());i++) |
|
139 |
{ |
|
140 |
EditorMacro macro=allMacros.get(i); |
|
141 |
Action action=new EditMacroAction(macro); |
|
142 |
item = new ActionContributionItem(action); |
|
143 |
item.fill(editMenu, -1); |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
MenuItem debugItem=new MenuItem(menu, SWT.CHECK); |
|
148 |
debugItem.setText("Macro debug mode"); |
|
149 |
debugItem.setSelection(MacroManager.getManager().isMacroDebugMode()); |
|
150 |
debugItem.addSelectionListener(new SelectionAdapter() |
|
151 |
{ |
|
152 |
@Override |
|
153 |
public void widgetSelected(SelectionEvent e) |
|
154 |
{ |
|
155 |
MacroManager.getManager().setMacroDebugMode(!MacroManager.getManager().isMacroDebugMode()); |
|
156 |
} |
|
157 |
}); |
|
158 |
} |
|
159 |
|
|
160 |
private void initMenu() { |
|
161 |
// Add listener to repopulate the menu each time |
|
162 |
// it is shown because of dynamic history list |
|
163 |
fMenu.addMenuListener(new MenuAdapter() { |
|
164 |
@Override |
|
165 |
public void menuShown(MenuEvent e) { |
|
166 |
Menu m = (Menu) e.widget; |
|
167 |
MenuItem[] items = m.getItems(); |
|
168 |
for (int i = 0; i < items.length; i++) { |
|
169 |
items[i].dispose(); |
|
170 |
} |
|
171 |
fillMenu(m); |
|
172 |
} |
|
173 |
}); |
|
174 |
} |
|
175 |
|
|
176 |
private void setMenu(Menu menu) { |
|
177 |
if (fMenu != null) { |
|
178 |
fMenu.dispose(); |
|
179 |
} |
|
180 |
fMenu = menu; |
|
181 |
} |
|
182 |
|
|
183 |
protected void addToMenu(Menu menu, IAction action, int accelerator) { |
|
184 |
StringBuffer label = new StringBuffer(); |
|
185 |
if (accelerator >= 0 && accelerator < 10) { |
|
186 |
// add the numerical accelerator |
|
187 |
label.append('&'); |
|
188 |
label.append(accelerator); |
|
189 |
label.append(' '); |
|
190 |
} |
|
191 |
label.append(action.getText()); |
|
192 |
action.setText(label.toString()); |
|
193 |
ActionContributionItem item = new ActionContributionItem(action); |
|
194 |
item.fill(menu, -1); |
|
195 |
} |
|
196 |
|
|
197 |
private static class MacroAction extends Action |
|
198 |
{ |
|
199 |
private EditorMacro mMacro; |
|
200 |
public MacroAction(EditorMacro macro) |
|
201 |
{ |
|
202 |
mMacro=macro; |
|
203 |
} |
|
204 |
|
|
205 |
@Override |
|
206 |
public String getText() |
|
207 |
{ |
|
208 |
return mMacro.getName(); |
|
209 |
} |
|
210 |
|
|
211 |
@Override |
|
212 |
public void run() |
|
213 |
{ |
|
214 |
ICommandService cs = MacroManager.getOldCommandService(); |
|
215 |
Command systemCommand=null; |
|
216 |
if (mMacro.getID().length()>0) |
|
217 |
systemCommand=cs.getCommand(mMacro.getID()); |
|
218 |
|
|
219 |
//turn macro recording off so that only the top-level command will be registered IF this macro |
|
220 |
//actually corresponds to a command. Otherwise, let the commands be recorded |
|
221 |
if (systemCommand!=null && MacroManager.getManager().getMacroState()==MacroManager.State_Recording) |
|
222 |
{ |
|
223 |
//turn off command recording |
|
224 |
MacroManager.getManager().getRecorder().pauseRecording(); |
|
225 |
} |
|
226 |
IEditorPart editor=Utilities.getActiveEditor(); |
|
227 |
mMacro.run(editor); |
|
228 |
if (systemCommand!=null && MacroManager.getManager().getMacroState()==MacroManager.State_Recording) |
|
229 |
{ |
|
230 |
//turn command recording back on |
|
231 |
MacroManager.getManager().getRecorder().resumeRecording(); |
|
232 |
MacroManager.getManager().getRecorder().recordCommand(new EclipseCommand(mMacro.getID())); |
|
233 |
} |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
private static class EditMacroAction extends Action |
|
238 |
{ |
|
239 |
private EditorMacro mMacro; |
|
240 |
public EditMacroAction(EditorMacro macro) |
|
241 |
{ |
|
242 |
mMacro=macro; |
|
243 |
} |
|
244 |
|
|
245 |
@Override |
|
246 |
public String getText() |
|
247 |
{ |
|
248 |
return mMacro.getName(); |
|
249 |
} |
|
250 |
|
|
251 |
@SuppressWarnings("unchecked") |
|
252 |
protected Set<String> getIDSet() |
|
253 |
{ |
|
254 |
Map<Integer, EditorMacro> allMacros=MacroManager.getManager().getUniqueMacroMap(); |
|
255 |
Set<String> currentIDs=new HashSet<String>(); |
|
256 |
for (EditorMacro macro: allMacros.values()) |
|
257 |
{ |
|
258 |
if (macro.getID().length()>0) |
|
259 |
{ |
|
260 |
currentIDs.add(macro.getID()); |
|
261 |
} |
|
262 |
} |
|
263 |
ICommandService cs = MacroManager.getOldCommandService(); |
|
264 |
Collection<String> allCommands=cs.getDefinedCommandIds(); |
|
265 |
for (String commandID : allCommands) |
|
266 |
{ |
|
267 |
if (commandID.length()>0) |
|
268 |
{ |
|
269 |
currentIDs.add(commandID); |
|
270 |
} |
|
271 |
} |
|
272 |
return currentIDs; |
|
273 |
} |
|
274 |
|
|
275 |
@Override |
|
276 |
public void run() |
|
277 |
{ |
|
278 |
Set<String> idSet=getIDSet(); |
|
279 |
Map<Integer, EditorMacro> allMacros=MacroManager.getManager().getUniqueMacroMap(); |
|
280 |
//prevent ID from being changed? only if it's already being used by another macro? |
|
281 |
EditMacroDialog dlg=new EditMacroDialog(Display.getDefault().getActiveShell(), mMacro, idSet, (MacroDefinitionsPage.getUsageOfMacro(allMacros, mMacro).size()==0), mMacro.isContributed()); |
|
282 |
if (dlg.open()==Dialog.OK) |
|
283 |
{ |
|
284 |
allMacros.put(mMacro.getSessionID(), dlg.getMacro()); |
|
285 |
MacroManager.getManager().replaceDefinedMacros(allMacros); |
|
286 |
} |
|
287 |
} |
|
288 |
} |
|
289 |
|
|
290 |
} |
|
0 | 291 |
tmp/org.txm.practically.rcp/src/practicallymacro/model/MarkUpdater.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.model; |
|
2 |
|
|
3 |
import org.eclipse.jface.text.DocumentEvent; |
|
4 |
import org.eclipse.jface.text.IDocumentListener; |
|
5 |
|
|
6 |
public class MarkUpdater implements IDocumentListener |
|
7 |
{ |
|
8 |
private boolean mRecordMode; |
|
9 |
public MarkUpdater(boolean recordMode) |
|
10 |
{ |
|
11 |
mRecordMode=recordMode; |
|
12 |
} |
|
13 |
// @Override |
|
14 |
// public void modifyText(ExtendedModifyEvent event) |
|
15 |
// { |
|
16 |
// if (event.replacedText.length()>0) |
|
17 |
// { |
|
18 |
// MacroManager.getManager().moveMarkOnDelete(event.start, event.replacedText.length()); |
|
19 |
// } |
|
20 |
// if (event.length>0) |
|
21 |
// { |
|
22 |
// MacroManager.getManager().moveMarkOnInsert(event.start, event.length); |
|
23 |
// } |
|
24 |
// } |
|
25 |
|
|
26 |
public void documentAboutToBeChanged(DocumentEvent event) |
|
27 |
{ |
|
28 |
//nothing to do |
|
29 |
} |
|
30 |
|
|
31 |
public void documentChanged(DocumentEvent event) |
|
32 |
{ |
|
33 |
if (event.getLength()>0) |
|
34 |
{ |
|
35 |
MacroManager.getManager().moveMarkOnDelete(mRecordMode, event.getOffset(), event.getLength()); |
|
36 |
} |
|
37 |
|
|
38 |
if (event.getText().length()>0) |
|
39 |
{ |
|
40 |
MacroManager.getManager().moveMarkOnInsert(mRecordMode, event.getOffset(), event.getText().length()); |
|
41 |
} |
|
42 |
} |
|
43 |
} |
|
0 | 44 |
tmp/org.txm.practically.rcp/src/practicallymacro/model/E4CommandHelper.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.model; |
|
2 |
|
|
3 |
import java.lang.reflect.Field; |
|
4 |
import java.lang.reflect.Method; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.eclipse.core.commands.Command; |
|
8 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
|
9 |
import org.eclipse.e4.ui.model.application.MApplication; |
|
10 |
import org.eclipse.e4.ui.model.application.commands.MCommand; |
|
11 |
import org.eclipse.ui.PlatformUI; |
|
12 |
|
|
13 |
public class E4CommandHelper { |
|
14 |
public static void addMCommandToSystem(Command newCommand) |
|
15 |
{ |
|
16 |
try |
|
17 |
{ |
|
18 |
IEclipseContext context=(IEclipseContext)PlatformUI.getWorkbench().getAdapter(IEclipseContext.class); |
|
19 |
Class commandsFactory=Class.forName("org.eclipse.e4.ui.model.application.commands.impl.CommandsFactoryImpl"); |
|
20 |
Field instanceField=commandsFactory.getField("INSTANCE"); |
|
21 |
Method createCommand=commandsFactory.getMethod("createCommand"); |
|
22 |
Object implInstance=instanceField.get(null); |
|
23 |
MCommand anMCommand=(MCommand)createCommand.invoke(implInstance); |
|
24 |
// MCommand anMCommand=CommandsFactoryImpl.INSTANCE.createCommand(); |
|
25 |
anMCommand.setElementId(newCommand.getId()); |
|
26 |
try |
|
27 |
{ |
|
28 |
anMCommand.setCommandName(newCommand.getName()); |
|
29 |
} |
|
30 |
catch (Exception e) |
|
31 |
{ |
|
32 |
e.printStackTrace(); |
|
33 |
} |
|
34 |
MApplication app=context.get(MApplication.class); |
|
35 |
List<MCommand> allCommands=app.getCommands(); |
|
36 |
boolean commandExists=false; |
|
37 |
for (MCommand mcommand : allCommands) |
|
38 |
{ |
|
39 |
if (mcommand.getElementId().equals(newCommand.getId())) |
|
40 |
{ |
|
41 |
commandExists=true; |
|
42 |
break; |
|
43 |
} |
|
44 |
} |
|
45 |
if (!commandExists) |
|
46 |
allCommands.add(anMCommand); |
|
47 |
} |
|
48 |
catch (Exception e) |
|
49 |
{ |
|
50 |
e.printStackTrace(); |
|
51 |
} |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
} |
|
0 | 57 |
tmp/org.txm.practically.rcp/src/practicallymacro/model/MacroRecorder.java (revision 486) | ||
---|---|---|
1 |
package practicallymacro.model; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashSet; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Set; |
|
7 |
|
|
8 |
import org.eclipse.core.commands.ExecutionEvent; |
|
9 |
import org.eclipse.core.commands.ExecutionException; |
|
10 |
import org.eclipse.core.commands.IExecutionListener; |
|
11 |
import org.eclipse.core.commands.NotHandledException; |
|
12 |
import org.eclipse.jface.bindings.Binding; |
|
13 |
import org.eclipse.jface.bindings.keys.KeySequence; |
|
14 |
import org.eclipse.jface.bindings.keys.KeyStroke; |
|
15 |
import org.eclipse.jface.text.DocumentEvent; |
|
16 |
import org.eclipse.jface.text.IDocumentListener; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.swt.custom.StyledText; |
|
19 |
import org.eclipse.swt.widgets.Event; |
|
20 |
import org.eclipse.swt.widgets.Listener; |
|
21 |
import org.eclipse.ui.IEditorPart; |
|
22 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
|
23 |
import org.eclipse.ui.PlatformUI; |
|
24 |
import org.eclipse.ui.keys.IBindingService; |
|
25 |
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
|
26 |
|
|
27 |
import practicallymacro.commands.EclipseCommand; |
|
28 |
import practicallymacro.commands.FindCommand; |
|
29 |
import practicallymacro.commands.IMacroCommand; |
|
30 |
import practicallymacro.commands.KeystrokeCommand; |
|
31 |
import practicallymacro.util.MacroConsole; |
|
32 |
import practicallymacro.util.Utilities; |
|
33 |
|
|
34 |
|
|
35 |
public class MacroRecorder implements Listener, IExecutionListener, IDocumentListener |
|
36 |
{ |
|
37 |
private IEditorPart mEditor; |
|
38 |
private List<IMacroCommand> mCommands; |
|
39 |
private Set<String> mNonRecordableCommandIds; |
|
40 |
private boolean mCurrentlyExecutingCommand; |
|
41 |
private boolean mRecordCommands; |
|
42 |
private MarkUpdater mMarkUpdater=new MarkUpdater(true); |
|
43 |
|
|
44 |
public MacroRecorder(IEditorPart editor) |
|
45 |
{ |
|
46 |
mEditor=editor; |
|
47 |
|
|
48 |
//TODO: get from extension point? |
|
49 |
mNonRecordableCommandIds=new HashSet<String>(); |
|
50 |
mNonRecordableCommandIds.add("practicallymacro.actions.recordMacro"); |
|
51 |
mNonRecordableCommandIds.add("practicallymacro.actions.playCommand"); |
|
52 |
mNonRecordableCommandIds.add(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE); |
|
53 |
mNonRecordableCommandIds.add("practicallymacro.actions.playLastMacro"); |
|
54 |
} |
|
55 |
|
|
56 |
public void start() |
|
57 |
{ |
|
58 |
MacroConsole.getConsole().writeln("***Started macro recording", MacroConsole.Type_RecordingCommand); |
|
59 |
mCommands=new ArrayList<IMacroCommand>(); |
|
60 |
mCurrentlyExecutingCommand=false; |
|
61 |
mRecordCommands=true; |
|
62 |
} |
|
63 |
|
|
64 |
private boolean isBound(Event event) |
|
65 |
{ |
|
66 |
IBindingService bindingService = (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class); |
|
67 |
KeyStroke k=KeyStroke.getInstance(event.stateMask, event.keyCode); |
|
68 |
if (k==null) |
|
69 |
return false; |
|
70 |
Binding b=bindingService.getPerfectMatch(KeySequence.getInstance(k)); |
|
71 |
return (b!=null); |
|
72 |
} |
|
73 |
|
|
74 |
public void stop() |
|
75 |
{ |
|
76 |
updateIncrementalFindMode(); |
|
77 |
MacroConsole.getConsole().writeln("***Finished recording macro", MacroConsole.Type_RecordingCommand); |
|
78 |
} |
|
79 |
|
|
80 |
public void handleEvent(Event event) { |
|
81 |
updateIncrementalFindMode(); |
|
82 |
if (event.type==SWT.KeyDown) |
|
83 |
{ |
|
84 |
if (isBound(event)) |
|
85 |
return; |
|
86 |
IMacroCommand command=null; |
Also available in: Unified diff