Révision 486

tmp/org.txm.practically.rcp/plugin.xml (revision 486)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.2"?>
3
<plugin>
4
   <extension-point id="xmlCommandHandlers" name="XMLCommandHandlers" schema="schema/xmlCommandHandlers.exsd"/>
5
   <extension-point id="defineMacro" name="Define a macro" schema="schema/defineMacro.exsd"/>
6
   <extension-point id="scriptingSupport" name="Macro Scripting Support" schema="schema/scriptingSupport.exsd"/>
7
   <extension
8
         point="org.eclipse.core.runtime.preferences">
9
      <initializer
10
            class="practicallymacro.preferences.Initializer">
11
      </initializer>
12
   </extension>
13

  
14
   <extension
15
         point="org.eclipse.ui.actionSets">
16
      <actionSet
17
            id="com.none.playActionSet"
18
            label="EditorMacros.PlayActionSet"
19
            visible="true">
20
         <action
21
               class="practicallymacro.actions.PlayDropdownAction"
22
               definitionId="practicallymacro.actions.playLastMacro"
23
               icon="icons/play.gif"
24
               id="practicallymacro.actions.playMacroAction"
25
               label="&amp;Play Macro"
26
               style="pulldown"
27
               toolbarPath="Normal/additions"
28
               tooltip="Play Macro">
29
<!--            <enablement>
30
            	<or>
31
               		<objectClass name="org.eclipse.jface.text.ITextSelection"/>
32
               		<objectClass name="org.eclipse.core.resources.IFile"/>
33
               	</or>
34
            </enablement>
35
            -->
36
          </action>
37
         <action
38
               class="practicallymacro.actions.RecordCommandAction"
39
               definitionId="practicallymacro.actions.recordMacro"
40
               icon="icons/record.gif"
41
               id="practicallymacro.actions.recordMacroAction"
42
               label="&amp;Record Macro"
43
               retarget="false"
44
               state="false"
45
               style="push"
46
               toolbarPath="Normal/additions"
47
               tooltip="Record Macro">
48
            <!--<enablement>
49
            	<or>
50
               		<objectClass name="org.eclipse.jface.text.ITextSelection"/>
51
               	</or>
52
            </enablement>-->
53
         </action>
54
      </actionSet>
55
   </extension>
56
   
57
   <extension
58
         point="org.eclipse.ui.commands">
59
      <command
60
            categoryId="practicallymacro.category.utility.command"
61
            defaultHandler="practicallymacro.commands.PlayHandler"
62
            description="Play the last recorded macro"
63
            id="practicallymacro.actions.playLastMacro"
64
            name="Play last macro"/>
65
      <command
66
            categoryId="practicallymacro.category.utility.command"
67
            defaultHandler="practicallymacro.commands.QuickPlayHandler"
68
            description="Play a command"
69
            id="practicallymacro.actions.quickExecuteCommand"
70
            name="Quick Play Command"/>
71
      <command
72
            categoryId="practicallymacro.category.utility.command"
73
            defaultHandler="practicallymacro.commands.RecordHandler"
74
            description="Record a new macro"
75
            id="practicallymacro.actions.recordMacro"
76
            name="Record Macro"/>
77
      <command
78
            categoryId="practicallymacro.category.utility.command"
79
            defaultHandler="practicallymacro.commands.PlayCommand"
80
            description="Play any defined command"
81
            id="practicallymacro.actions.playCommand"
82
            name="Play command"/>
83
      <command
84
            categoryId="practicallymacro.category.utility.command"
85
            defaultHandler="practicallymacro.commands.MarkSelectionStart"
86
            description="Set the mark at the location of the current selection start."
87
            id="practicallymacro.actions.markSelectionStartCommand"
88
            name="Mark selection start"/>
89
      <command
90
            categoryId="practicallymacro.category.utility.command"
91
            defaultHandler="practicallymacro.commands.MarkSelectionEnd"
92
            description="Set the mark at the location of the current selection end"
93
            id="practicallymacro.actions.markSelectionEndCommand"
94
            name="Mark selection end"/>
95
      <command
96
            categoryId="practicallymacro.category.utility.command"
97
            defaultHandler="practicallymacro.commands.MoveCursorToMark"
98
            description="Set the cursor at the last mark location"
99
            id="practicallymacro.actions.setCursorAtMarkCommand"
100
            name="Set cursor at mark"/>
101
      <category
102
            description="Editor macros defined by the user"
103
            id="practicallymacro.category.usermacros"
104
            name="User defined editor macros">
105
      </category>
106
      <category
107
            description="Utiliity commands for recording editor macros"
108
            id="practicallymacro.category.utility.command"
109
            name="PracticallyMacro utility command">
110
      </category>
111
      <command
112
            categoryId="practicallymacro.category.utility.command"
113
            defaultHandler="practicallymacro.commands.ExtendSelectionToMark"
114
            description="Extend the current selection to the current mark position, or the current cursor position if there is no mark.  If there is no selection, use the current cursor position."
115
            id="practicallymacro.actions.extendSelectionToMarkCommand"
116
            name="Extend selection to mark">
117
      </command>
118
   </extension>
119
   <extension
120
         point="org.eclipse.ui.bindings">
121
      <key
122
            commandId="practicallymacro.actions.playLastMacro"
123
            contextId="org.eclipse.ui.textEditorScope"
124
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
125
            sequence="M1+M3+P"/>
126
      <key
127
            commandId="practicallymacro.actions.recordMacro"
128
            contextId="org.eclipse.ui.textEditorScope"
129
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
130
            sequence="M1+M3+R"/>
131
      <key
132
            commandId="practicallymacro.actions.quickExecuteCommand"
133
            contextId="org.eclipse.ui.textEditorScope"
134
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
135
            sequence="M1+M3+Q"/>
136
   </extension>
137
   <extension
138
         point="PracticallyMacro.xmlCommandHandlers">
139
      <XMLCommandHandler class="practicallymacro.commands.EclipseCommand" type="EclipseCommand"/>
140
      <XMLCommandHandler class="practicallymacro.commands.InsertStringCommand" type="InsertStringCommand"/>
141
      <XMLCommandHandler class="practicallymacro.commands.MacroScriptCommand" type="MacroScriptCommand"/>
142
      <XMLCommandHandler class="practicallymacro.commands.StyledTextCommand" type="styledTextCommand"/>
143
      <XMLCommandHandler class="practicallymacro.commands.FindCommand" type="MacroFindCommand"/>
144
      <XMLCommandHandler class="practicallymacro.commands.KeystrokeCommand" type="MacroKeystrokeCommand"/>
145
   </extension>
146
   <extension
147
         point="org.eclipse.ui.preferencePages">
148
      <page
149
            category="practicallymacro.editormacros.optionsPage"
150
            class="practicallymacro.dialogs.MacroDefinitionsPage"
151
            id="practicallymacro.editormacros.editingpage"
152
            name="Editor Macro Definitions">
153
      </page>
154
      <page
155
            class="practicallymacro.dialogs.OptionsPage"
156
            id="practicallymacro.editormacros.optionsPage"
157
            name="Practically Macro Options">
158
      </page>
159
   </extension>
160

  
161
	<extension point="org.eclipse.help.contexts">
162
	    <contexts file="helpContexts.xml" />
163
	</extension>
164
 <extension
165
       point="org.eclipse.ui.startup">
166
    <startup
167
          class="practicallymacro.editormacros.MacroEarlyStatup">
168
    </startup>
169
 </extension>
170

  
171
</plugin>
0 172

  
tmp/org.txm.practically.rcp/.settings/CVS/Repository (revision 486)
1
PracticallyMacro/.settings
tmp/org.txm.practically.rcp/.settings/CVS/Root (revision 486)
1
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro
tmp/org.txm.practically.rcp/.settings/CVS/Entries (revision 486)
1
/org.eclipse.jdt.core.prefs/1.3/Thu Oct  8 21:09:12 2009//
2
D
tmp/org.txm.practically.rcp/helpContexts.xml (revision 486)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?NLS TYPE="org.eclipse.help.contexts"?>
3
  
4
  <contexts>
5
    <context id="overallHelp">
6
      <description>Help for Practically Macro plugin</description>
7
      <topic href="doc/overall.html" label="Practically Macro"/>
8
    </context>
9
    <context id="editDialogHelp">
10
      <description>Help for Practically Macro edit dialog</description>
11
      <topic href="doc/macroEdit.html" label="Practically Macro macro editing"/>
12
    </context>
13
    <context id="managingMacrosHelp">
14
      <description>Help for Practically Macro edit dialog</description>
15
      <topic href="doc/macroManage.html" label="Practically Macro macro management"/>
16
    </context>
17
  </contexts>
0 18

  
tmp/org.txm.practically.rcp/.classpath (revision 486)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="src" path="src"/>
5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.practically.rcp/META-INF/CVS/Repository (revision 486)
1
PracticallyMacro/META-INF
tmp/org.txm.practically.rcp/META-INF/CVS/Root (revision 486)
1
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro
tmp/org.txm.practically.rcp/META-INF/CVS/Entries (revision 486)
1
/MANIFEST.MF/1.13/Sat Jan  4 23:52:51 2014//
2
D
tmp/org.txm.practically.rcp/META-INF/MANIFEST.MF (revision 486)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: PracticallyMacro Plug-in
4
Bundle-SymbolicName: PracticallyMacro;singleton:=true
5
Bundle-Version: 0.4.5
6
Bundle-Activator: practicallymacro.editormacros.Activator
7
Require-Bundle: org.eclipse.ui,
8
 org.eclipse.core.runtime,
9
 org.eclipse.jface.text,
10
 org.eclipse.ui.workbench.texteditor,
11
 org.eclipse.ui.editors,
12
 org.eclipse.ui.console,
13
 org.eclipse.core.expressions,
14
 org.eclipse.e4.ui.model.workbench;resolution:=optional,
15
 org.eclipse.e4.core.contexts;resolution:=optional
16
Bundle-ActivationPolicy: lazy
17
Export-Package: practicallymacro.commands,
18
 practicallymacro.util
19
Bundle-RequiredExecutionEnvironment: J2SE-1.5
20

  
21

  
0 22

  
tmp/org.txm.practically.rcp/schema/defineMacro.exsd (revision 486)
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="EditorMacros" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="EditorMacros" id="defineMacro" name="Define a macro"/>
7
      </appinfo>
8
      <documentation>
9
         This extension point is provided to allow users to publish macros they have defined in plugin form (instead of forcing users to import them from a file).  Users can do this by recording a macro and copying the text from the export dialog.
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="macroDefinition" minOccurs="1" maxOccurs="unbounded"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="macroDefinition">
51
      <complexType>
52
      </complexType>
53
   </element>
54

  
55
   <annotation>
56
      <appinfo>
57
         <meta.section type="since"/>
58
      </appinfo>
59
      <documentation>
60
         [Enter the first release in which this extension point appears.]
61
      </documentation>
62
   </annotation>
63

  
64
   <annotation>
65
      <appinfo>
66
         <meta.section type="examples"/>
67
      </appinfo>
68
      <documentation>
69
         [Enter extension point usage example here.]
70
      </documentation>
71
   </annotation>
72

  
73
   <annotation>
74
      <appinfo>
75
         <meta.section type="apiinfo"/>
76
      </appinfo>
77
      <documentation>
78
         [Enter API information here.]
79
      </documentation>
80
   </annotation>
81

  
82
   <annotation>
83
      <appinfo>
84
         <meta.section type="implementation"/>
85
      </appinfo>
86
      <documentation>
87
         [Enter information about supplied implementation of this extension point.]
88
      </documentation>
89
   </annotation>
90

  
91

  
92
</schema>
0 93

  
tmp/org.txm.practically.rcp/schema/scriptingSupport.exsd (revision 486)
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="PracticallyMacro" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="PracticallyMacro" id="scriptingSupport" name="Macro Scripting Support"/>
7
      </appinfo>
8
      <documentation>
9
         This extension point allows scripting languages to be plugged into the macro script command.  If there are no scripting extension defined, then the macro script command will not be available.
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence minOccurs="1" maxOccurs="unbounded">
21
            <element ref="scriptSupport"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="scriptSupport">
51
      <annotation>
52
         <documentation>
53
            You should supply a class that implements the IMacroScriptSupport interface.  The main duties of this class are to provide a unique ID, to allow editing of the script in a dialog, and to execute the script (on the main thread) when requested.
54
         </documentation>
55
      </annotation>
56
      <complexType>
57
         <attribute name="class" type="string" use="required">
58
            <annotation>
59
               <documentation>
60
                  
61
               </documentation>
62
               <appinfo>
63
                  <meta.attribute kind="java" basedOn=":practicallymacro.commands.IMacroScriptSupport"/>
64
               </appinfo>
65
            </annotation>
66
         </attribute>
67
      </complexType>
68
   </element>
69

  
70
   <annotation>
71
      <appinfo>
72
         <meta.section type="since"/>
73
      </appinfo>
74
      <documentation>
75
         [Enter the first release in which this extension point appears.]
76
      </documentation>
77
   </annotation>
78

  
79
   <annotation>
80
      <appinfo>
81
         <meta.section type="examples"/>
82
      </appinfo>
83
      <documentation>
84
         [Enter extension point usage example here.]
85
      </documentation>
86
   </annotation>
87

  
88
   <annotation>
89
      <appinfo>
90
         <meta.section type="apiinfo"/>
91
      </appinfo>
92
      <documentation>
93
         [Enter API information here.]
94
      </documentation>
95
   </annotation>
96

  
97
   <annotation>
98
      <appinfo>
99
         <meta.section type="implementation"/>
100
      </appinfo>
101
      <documentation>
102
         [Enter information about supplied implementation of this extension point.]
103
      </documentation>
104
   </annotation>
105

  
106

  
107
</schema>
0 108

  
tmp/org.txm.practically.rcp/schema/xmlCommandHandlers.exsd (revision 486)
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="EditorMacros" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="EditorMacros" id="com.none.macros.xmlCommandHandlers" name="XMLCommandHandlers"/>
7
      </appinfo>
8
      <documentation>
9
         This extension point is for internal use at this time.  The idea is to associate handlers for reading in previously defined commands.  Since I haven&apos;t publicized a way for others to add new commands, this is effectively a private extension.
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="XMLCommandHandler" minOccurs="1" maxOccurs="unbounded"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="XMLCommandHandler">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appinfo>
58
                  <meta.attribute kind="java" basedOn=":practicallymacro.commands.IMacroCommand"/>
59
               </appinfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="type" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  
66
               </documentation>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71

  
72
   <annotation>
73
      <appinfo>
74
         <meta.section type="since"/>
75
      </appinfo>
76
      <documentation>
77
         [Enter the first release in which this extension point appears.]
78
      </documentation>
79
   </annotation>
80

  
81
   <annotation>
82
      <appinfo>
83
         <meta.section type="examples"/>
84
      </appinfo>
85
      <documentation>
86
         [Enter extension point usage example here.]
87
      </documentation>
88
   </annotation>
89

  
90
   <annotation>
91
      <appinfo>
92
         <meta.section type="apiinfo"/>
93
      </appinfo>
94
      <documentation>
95
         [Enter API information here.]
96
      </documentation>
97
   </annotation>
98

  
99
   <annotation>
100
      <appinfo>
101
         <meta.section type="implementation"/>
102
      </appinfo>
103
      <documentation>
104
         [Enter information about supplied implementation of this extension point.]
105
      </documentation>
106
   </annotation>
107

  
108

  
109
</schema>
0 110

  
tmp/org.txm.practically.rcp/schema/CVS/Entries (revision 486)
1
/defineMacro.exsd/1.1/Wed Oct 22 22:12:13 2008//
2
/scriptingSupport.exsd/1.1/Wed Oct 22 22:12:13 2008//
3
/xmlCommandHandlers.exsd/1.1/Wed Oct 22 22:12:13 2008//
4
D
tmp/org.txm.practically.rcp/schema/CVS/Repository (revision 486)
1
PracticallyMacro/schema
tmp/org.txm.practically.rcp/schema/CVS/Root (revision 486)
1
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro
tmp/org.txm.practically.rcp/Instructions.txt (revision 486)
1
---how to record
2
---how to play
3
---gotchas
4
----commands you can't use
5
----recording modes 
6
---sharing
7

  
8
Practically Macro
9
================================================================================
10
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.
11

  
12
Requirements
13
--------------------------------------------------------------------------------
14
Eclipse 3.4 or greater; will not run correctly at 3.3.  Requires the workbench.  Shouldn't require jdt.  
15

  
16
Recording a macro
17
--------------------------------------------------------------------------------
18
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.  
19
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.
20
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. 
21

  
22
Playing a macro
23
--------------------------------------------------------------------------------
24
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.
25

  
26
Gotchas
27
-------------------------------------------------------------------------------
28
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.
29
Here are some types of actions that make sense to record as part of a macro:
30
1)typing characters (see note below)
31
2)navigation characters (ex. arrows, page down)
32
3)find dialog (I've supplied my own since the standard dialog isn't public)
33
4)incremental find (with some hacking)
34
5)previously recorded macros
35
6)other commands that don't pop up dialogs (ex. file save, find next, organize imports, toggle insert mode)
36
 
37
Here are some types of actions that almost certainly won't work correctly:
38
1) Commands that bring up dialogs (ex. Go to line)
39
2) Wizards and other dialogs (ex. Open File)
40
3) ctrl+space intellisense
41
4) invoking code templates like "foreach"
42

  
43
Special notes
44
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.
45

  
46
Editing macros
47
------------------------------------------------------------------------------------------
48
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).
49
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.
50

  
51
Sharing macros
52
---------------------------------------------------------------------------------------------
53
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).  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:
54
   <extension point="PracticallyMacro.defineMacro">
55
       <include the text from the export page here>
56
   </extension>
57

  
58

  
59
Special macro helper commands
60
---------------------------------------------------------------------------------------------
61
1)Mark selection start - set a 'mark' at the current selection start, or at the caret pos if no selection
62
2)Mark selection end - set a 'mark' at the current selection end, or at the caret pos if no selection
63
3)Move cursor to mark - Set the editor cursor to the current mark position
64
4)Insert string - this is the workhorse command used to add text. Can contain carriage returns.
65
5)Find - perform various kinds of text searching
66
6)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.
67
7)Macro script - You can write whatever scripts you'd like using beanshell.  I pass in several variables for the editor that should be useful.
68

  
69
The Mark commands are provided as a way to maintain some state while other operations are performed without requiring scripting.  
70
For example, to comment a selected area, you could record a sequence of commands like:
71
a)mark selection start
72
b)move cursor right (puts cursor at end of selection
73
c)insert string "*/"
74
d)move cursor to mark
75
e)insert string "/*"
76

  
77
Macro scripting is embryonic and complicated.  There is some help when you are editing the script itself (via "question mark" help).
0 78

  
tmp/org.txm.practically.rcp/.project (revision 486)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>PracticallyMacro</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
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/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/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/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/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>   &lt;extension point="PracticallyMacro.defineMacro"&gt;
14
      include the text from the export page here
15
   &lt;/extension&gt;</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/src/practicallymacro/CVS/Entries (revision 486)
1
D/actions////
2
D/commands////
3
D/dialogs////
4
D/editormacros////
5
D/model////
6
D/preferences////
7
D/util////
tmp/org.txm.practically.rcp/src/practicallymacro/CVS/Repository (revision 486)
1
PracticallyMacro/src/practicallymacro
tmp/org.txm.practically.rcp/src/practicallymacro/CVS/Root (revision 486)
1
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro
tmp/org.txm.practically.rcp/src/practicallymacro/editormacros/CVS/Root (revision 486)
1
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro
tmp/org.txm.practically.rcp/src/practicallymacro/editormacros/CVS/Entries (revision 486)
1
/Activator.java/1.5/Sat Nov 10 12:00:39 2012//
2
/MacroEarlyStatup.java/1.1/Wed Dec 10 23:19:30 2008//
3
D
tmp/org.txm.practically.rcp/src/practicallymacro/editormacros/CVS/Repository (revision 486)
1
PracticallyMacro/src/practicallymacro/editormacros
tmp/org.txm.practically.rcp/src/practicallymacro/editormacros/Activator.java (revision 486)
1
package practicallymacro.editormacros;
2

  
3
import org.eclipse.ui.plugin.AbstractUIPlugin;
4
import org.osgi.framework.BundleContext;
5

  
6
import practicallymacro.model.MacroManager;
7

  
8

  
9
/**
10
 * The activator class controls the plug-in life cycle
11
 */
12
public class Activator extends AbstractUIPlugin {
13

  
14
	// The plug-in ID
15
	public static final String PLUGIN_ID = "PracticallyMacro";
16

  
17
	// The shared instance
18
	private static Activator plugin;
19
	
20
	/**
21
	 * The constructor
22
	 */
23
	public Activator() {
24
	}
25

  
26
	/*
27
	 * (non-Javadoc)
28
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
29
	 */
30
	@Override
31
	public void start(BundleContext context) throws Exception {
32
		super.start(context);
33
		plugin = this;
34
	}
35

  
36
	/*
37
	 * (non-Javadoc)
38
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
39
	 */
40
	@Override
41
	public void stop(BundleContext context) throws Exception {
42
		if (!MacroManager.isNull())
43
			MacroManager.getManager().saveMacros();
44
		plugin = null;
45
		super.stop(context);
46
	}
47

  
48
	/**
49
	 * Returns the shared instance
50
	 *
51
	 * @return the shared instance
52
	 */
53
	public static Activator getDefault() {
54
		return plugin;
55
	}
56
}
0 57

  
tmp/org.txm.practically.rcp/src/practicallymacro/editormacros/MacroEarlyStatup.java (revision 486)
1
package practicallymacro.editormacros;
2
import org.eclipse.ui.IStartup;
3

  
4
import practicallymacro.model.MacroManager;
5

  
6

  
7
public class MacroEarlyStatup implements IStartup {
8

  
9
	public void earlyStartup()
10
	{
11
		//this just kicks the manager so that it will load previously defined macros
12
		//and register commands
13
		MacroManager.getManager();
14
	}
15

  
16
}
0 17

  
tmp/org.txm.practically.rcp/src/practicallymacro/util/CVS/Repository (revision 486)
1
PracticallyMacro/src/practicallymacro/util
tmp/org.txm.practically.rcp/src/practicallymacro/util/CVS/Root (revision 486)
1
:pserver:anonymous@practicalmacro.cvs.sourceforge.net:/cvsroot/practicalmacro
tmp/org.txm.practically.rcp/src/practicallymacro/util/CVS/Entries (revision 486)
1
/MacroConsole.java/1.4/Wed May 27 23:39:14 2009//
2
/Utilities.java/1.7/Sat Jan  4 23:20:02 2014//
3
D
tmp/org.txm.practically.rcp/src/practicallymacro/util/Utilities.java (revision 486)
1
package practicallymacro.util;
2

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.HashSet;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.Set;
9

  
10
import org.eclipse.core.commands.Category;
11
import org.eclipse.core.commands.Command;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.core.commands.IHandlerListener;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.jface.text.IDocument;
19
import org.eclipse.jface.text.IFindReplaceTarget;
20
import org.eclipse.jface.text.ITextOperationTarget;
21
import org.eclipse.jface.text.source.ISourceViewer;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.custom.ST;
24
import org.eclipse.swt.custom.StyledText;
25
import org.eclipse.swt.widgets.Event;
26
import org.eclipse.ui.IEditorPart;
27
import org.eclipse.ui.IPartService;
28
import org.eclipse.ui.IWorkbenchPart;
29
import org.eclipse.ui.IWorkbenchWindow;
30
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.commands.ICommandService;
32
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
33
import org.w3c.dom.CDATASection;
34
import org.w3c.dom.Document;
35
import org.w3c.dom.Element;
36
import org.w3c.dom.NodeList;
37

  
38
import practicallymacro.commands.EclipseCommand;
39
import practicallymacro.commands.FindCommand;
40
import practicallymacro.commands.IMacroCommand;
41
import practicallymacro.commands.InsertStringCommand;
42
import practicallymacro.editormacros.Activator;
43
import practicallymacro.model.MacroManager;
44

  
45

  
46
public class Utilities {
47
	private static Map<Integer, Command> mFillInCommands=new HashMap<Integer, Command>();
48
	public static final String FillInPrefix="practicallyMacro.styledTextCommand";
49
	
50
	private static Set<String> mEditCategories;
51
	
52
	static
53
	{
54
		mEditCategories=new HashSet<String>();
55
		mEditCategories.add(MacroManager.UserMacroCategoryID);
56
		mEditCategories.add("org.eclipse.ui.category.edit");
57
		mEditCategories.add("org.eclipse.ui.category.textEditor");
58
		mEditCategories.add("org.eclipse.jdt.ui.category.source");
59
		mEditCategories.add("org.eclipse.jdt.ui.category.refactoring");
60
		mEditCategories.add(MacroManager.MacroCommandCategoryID);
61
		mEditCategories.add("eclipse.ui.category.navigate");
62
		mEditCategories.add(FillInPrefix);
63
	}
64
	
65
	public static IEditorPart getActiveEditor() {
66
		
67
		IEditorPart editor = null;
68
		
69
		// find the active part
70
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
71
		if (window!=null)
72
		{
73
			IPartService partService = window.getPartService();
74
			IWorkbenchPart part = partService.getActivePart();
75
			
76
			// Is the part an editor?
77
			if (part instanceof IEditorPart) {
78
				
79
				editor = (IEditorPart) part;
80
			}
81
		}
82
		
83
		return editor;
84
	}
85

  
86
	public static StyledText getStyledText(IEditorPart editor) {
87
		
88
		if (editor==null)
89
			return null;
90
		StyledText styledText = null;
91
		
92
		ISourceViewer viewer = (ISourceViewer)
93
			editor.getAdapter(ITextOperationTarget.class);
94
		if (viewer != null) {
95
			styledText= viewer.getTextWidget();
96
		}
97
		
98
		return styledText;
99
	}
100
	
101
//	public static List<Command> getFillInCommands()
102
//	{
103
//		if (mFillInCommands.size()>0)
104
//	}
105
	
106
	private static Command getStyledTextCommand(int styledTextCode)
107
	{
108
		if (mFillInCommands.size()==0)
109
			createStyledTextCommands();
110
		
111
		return mFillInCommands.get(styledTextCode);
112
	}
113
	
114
	public static List<IMacroCommand> getMacroSupportCommands()
115
	{
116
		List<IMacroCommand> commands=new ArrayList<IMacroCommand>();
117
		commands.add(new InsertStringCommand(null));
118
		commands.addAll(MacroManager.getManager().getCanonicalScriptCommands());
119
		commands.add(new FindCommand(""));
120
		return commands;
121
	}
122

  
123
	public static void createStyledTextCommands()
124
	{
125
		if (mFillInCommands.size()>0)
126
			return;
127
		
128
		//create styled text commands and fill in map
129
		int[] styledTextConstants={ST.DELETE_PREVIOUS, ST.LINE_DOWN, ST.SELECT_WORD_PREVIOUS, ST.WORD_PREVIOUS, ST.SELECT_COLUMN_PREVIOUS, ST.COLUMN_PREVIOUS, ST.SELECT_WORD_NEXT
130
				,ST.WORD_NEXT,ST.SELECT_COLUMN_NEXT,ST.COLUMN_NEXT,ST.LINE_UP,ST.SELECT_TEXT_START,ST.TEXT_START
131
				,ST.SELECT_LINE_START,ST.LINE_START,ST.SELECT_TEXT_END,ST.TEXT_END,ST.SELECT_LINE_END,ST.LINE_END
132
				,ST.SELECT_WINDOW_END,ST.WINDOW_END,ST.SELECT_PAGE_DOWN,ST.PAGE_DOWN,ST.SELECT_WINDOW_START
133
				,ST.WINDOW_START,ST.SELECT_PAGE_UP,ST.PAGE_UP,ST.DELETE_WORD_NEXT,ST.CUT,ST.DELETE_NEXT,ST.COPY
134
				,ST.PASTE,ST.TOGGLE_OVERWRITE,ST.SELECT_LINE_UP, ST.SELECT_LINE_DOWN, ST.DELETE_WORD_PREVIOUS};
135

  
136
		ICommandService cs = MacroManager.getOldCommandService();
137
		Category cat=cs.getCategory(FillInPrefix);
138
		cat.define("Styled Text Commands", "");
139
		for (int i = 0; i < styledTextConstants.length; i++)
140
		{
141
			int constant = styledTextConstants[i];
142
			Command newCommand=cs.getCommand(FillInPrefix+"."+Integer.toString(constant));
143
			newCommand.define(getNameForStyledTextConstant(constant), "", cat);
144
			newCommand.setHandler(new StyledTextHandler(constant));
145
			mFillInCommands.put(constant, newCommand);
146
		}
147
	}
148

  
149
	public static IMacroCommand getCommandForKeyEvent(Event event)
150
	{
151
		final int key = (SWT.KEY_MASK & event.keyCode);
152
		if ((key != 0 && !Character.isISOControl(event.character)))
153
		{
154
			return new InsertStringCommand(new String(new char[]{event.character}));
155
		}
156
		
157
		boolean isCtrl=((event.stateMask & SWT.MOD1) > 0); //ctrl
158
		boolean isShift=((event.stateMask & SWT.MOD2) > 0);  //shift
159
		
160
		switch (key)
161
		{
162
			case SWT.BS:
163
				if (isCtrl)
164
					return new EclipseCommand(getStyledTextCommand(ST.DELETE_WORD_PREVIOUS).getId());
165
				else
166
					return new EclipseCommand(getStyledTextCommand(ST.DELETE_PREVIOUS).getId());
167
			case SWT.ARROW_DOWN:
168
				if (isShift && !isCtrl)
169
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_LINE_DOWN).getId());
170
				else if (!isCtrl && !isShift)
171
					return new EclipseCommand(getStyledTextCommand(ST.LINE_DOWN).getId());
172
			case SWT.ARROW_LEFT:
173
				if (isCtrl && isShift)
174
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_WORD_PREVIOUS).getId());
175
				else if (isCtrl)
176
					return new EclipseCommand(getStyledTextCommand(ST.WORD_PREVIOUS).getId());
177
				else if (isShift)
178
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_COLUMN_PREVIOUS).getId());
179
				return new EclipseCommand(getStyledTextCommand(ST.COLUMN_PREVIOUS).getId());
180
			case SWT.ARROW_RIGHT: 
181
				if (isCtrl && isShift)
182
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_WORD_NEXT).getId());
183
				else if (isCtrl)
184
					return new EclipseCommand(getStyledTextCommand(ST.WORD_NEXT).getId());
185
				else if (isShift)
186
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_COLUMN_NEXT).getId());
187
				return new EclipseCommand(getStyledTextCommand(ST.COLUMN_NEXT).getId());
188
			case SWT.ARROW_UP: 
189
				if (isShift && !isCtrl)
190
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_LINE_UP).getId());
191
				else if (!isCtrl && !isShift)
192
					return new EclipseCommand(getStyledTextCommand(ST.LINE_UP).getId());
193
			case SWT.HOME:
194
				if (isCtrl && isShift)
195
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_TEXT_START).getId());
196
				if (isCtrl)
197
					return new EclipseCommand(getStyledTextCommand(ST.TEXT_START).getId());
198
				if (isShift)
199
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_LINE_START).getId());
200
				return new EclipseCommand(getStyledTextCommand(ST.LINE_START).getId());
201
			case SWT.END: 
202
				if (isCtrl && isShift)
203
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_TEXT_END).getId());
204
				if (isCtrl)
205
					return new EclipseCommand(getStyledTextCommand(ST.TEXT_END).getId());
206
				if (isShift)
207
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_LINE_END).getId());
208
				return new EclipseCommand(getStyledTextCommand(ST.LINE_END).getId());
209
			case SWT.PAGE_DOWN: 
210
				if (isCtrl && isShift)
211
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_WINDOW_END).getId());
212
				if (isCtrl)
213
					return new EclipseCommand(getStyledTextCommand(ST.WINDOW_END).getId());
214
				if (isShift)
215
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_PAGE_DOWN).getId());
216
				return new EclipseCommand(getStyledTextCommand(ST.PAGE_DOWN).getId());
217
			case SWT.PAGE_UP: 
218
				if (isCtrl && isShift)
219
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_WINDOW_START).getId());
220
				if (isCtrl)
221
					return new EclipseCommand(getStyledTextCommand(ST.WINDOW_START).getId());
222
				if (isShift)
223
					return new EclipseCommand(getStyledTextCommand(ST.SELECT_PAGE_UP).getId());
224
				return new EclipseCommand(getStyledTextCommand(ST.PAGE_UP).getId());
225
			case SWT.DEL:
226
				if (isCtrl)
227
					return new EclipseCommand(getStyledTextCommand(ST.DELETE_WORD_NEXT).getId());
228
				if (isShift)
229
					return new EclipseCommand(getStyledTextCommand(ST.CUT).getId());
230
				return new EclipseCommand(getStyledTextCommand(ST.DELETE_NEXT).getId());
231
			case SWT.INSERT: 
232
				if (isCtrl)
233
					return new EclipseCommand(getStyledTextCommand(ST.COPY).getId());
234
				if (isShift)
235
					return new EclipseCommand(getStyledTextCommand(ST.PASTE).getId());
236
				return new EclipseCommand(getStyledTextCommand(ST.TOGGLE_OVERWRITE).getId());
237
		}
238
		
239
		if (key == SWT.CR || key==SWT.LF)
240
		{
241
//			return new EclipseCommand("org.eclipse.ui.edit.text.smartEnter");
242
//			try
243
//			{
244
//				String delimiter=Utilities.getStyledText(Utilities.getActiveEditor()).getLineDelimiter();
245
//				return new InsertStringCommand(delimiter);
246
//			}
247
//			catch (Exception e)
248
			{
249
				return new InsertStringCommand(new String(new char[]{(char)key}));	
250
			}
251
			
252
		}
253
		
254
		if (key == SWT.TAB)
255
		{
256
			return new InsertStringCommand(new String(new char[]{(char)key}));
257
		}
258
		
259
		//skip if this doesn't seem to correspond to anything we understand
260
		return null;
261
	}
262
	
263
	public static String getNameForStyledTextConstant(int constant)
264
	{
265
		switch (constant)
266
		{
267
		case ST.DELETE_PREVIOUS: return "Delete previous character";
268
		case ST.LINE_DOWN: return "Move cursor down";
269
		case ST.SELECT_WORD_PREVIOUS: return "Select previous word";
270
		case ST.WORD_PREVIOUS: return "Move cursor to previous word";
271
		case ST.SELECT_COLUMN_PREVIOUS: return "Select previous character";
272
		case ST.COLUMN_PREVIOUS: return "Move cursor left";
273
		case ST.SELECT_WORD_NEXT: return "Select next word";
274
		case ST.WORD_NEXT: return "Move cursor to next word";
275
		case ST.SELECT_COLUMN_NEXT: return "Select next character";
276
		case ST.COLUMN_NEXT: return "Move cursor right";
277
		case ST.LINE_UP: return "Move cursor up";
278
		case ST.SELECT_TEXT_START: return "Select to start of document";
279
		case ST.TEXT_START: return "Move cursor to start of document";
280
		case ST.SELECT_LINE_START: return "Select to line start";
281
		case ST.LINE_START: return "Move cursor to line start";
282
		case ST.SELECT_TEXT_END: return "Select to end of document";
283
		case ST.TEXT_END: return "Move cursor to end of document";
284
		case ST.SELECT_LINE_END: return "Select to end of line";
285
		case ST.LINE_END: return "Move cursor to end of line";
286
		case ST.SELECT_WINDOW_END: return "Select to window end";
287
		case ST.WINDOW_END: return "Move cursor to window end";
288
		case ST.SELECT_PAGE_DOWN: return "Select page down";
289
		case ST.PAGE_DOWN: return "Move cursor down a page";
290
		case ST.SELECT_WINDOW_START: return "Select to window start";
291
		case ST.WINDOW_START: return "Move cursor to window start";
292
		case ST.SELECT_PAGE_UP: return "Select page up";
293
		case ST.PAGE_UP: return "Move cursor up a page";
294
		case ST.DELETE_WORD_NEXT: return "Delete next word";
295
		case ST.DELETE_WORD_PREVIOUS: return "Delete previous word";
296
		case ST.CUT: return "Cut";
297
		case ST.DELETE_NEXT: return "Delete next character";
298
		case ST.COPY: return "Copy";
299
		case ST.PASTE: return "Paste";
300
		case ST.TOGGLE_OVERWRITE: return "Toggle overwrite mode";
301
		case ST.SELECT_LINE_DOWN: return "Select line down";
302
		case ST.SELECT_LINE_UP: return "Select line up";
303
		}
304
		
305
		return "Unknown constant";
306
	}
307

  
308
	static class StyledTextHandler implements IHandler
309
	{
310
		private int mStyledTextAction;
311
		public StyledTextHandler(int styledTextConstant)
312
		{
313
			mStyledTextAction=styledTextConstant;
314
		}
315
		
316
		public void addHandlerListener(IHandlerListener handlerListener) {
317
			
318
		}
319

  
320
		public void dispose() {
321
			
322
		}
323

  
324
		public Object execute(ExecutionEvent event) throws ExecutionException
325
		{
326
			IEditorPart target=getActiveEditor();
327
			Utilities.getStyledText(target).invokeAction(mStyledTextAction);
328
			return null;
329
		}
330

  
331
		public boolean isEnabled()
332
		{
333
			return true;
334
		}
335

  
336
		public boolean isHandled()
337
		{
338
			return true;
339
		}
340

  
341
		public void removeHandlerListener(IHandlerListener handlerListener) {
342
		}
343
		
344
	}
345

  
346
	public static boolean isEditCategory(String categoryID)
347
	{
348
		System.out.println("category test:"+categoryID);
349
		return mEditCategories.contains(categoryID);
350
	}
351
	
352
	public static IFindReplaceTarget getFindReplaceTarget(IEditorPart editor)
353
	{
354
		IFindReplaceTarget target=(IFindReplaceTarget) editor.getAdapter(IFindReplaceTarget.class);
355
		return target;
356
	}
357
	
358
	public static void persistCommand(Document doc, Element commandElement, String type, Map<String, String> attrs, Map<String, String> data)
359
	{
360
		commandElement.setAttribute(MacroManager.XML_CommandType_ATTR, type);
361
		if (attrs!=null)
362
		{
363
			for (String attr : attrs.keySet())
364
			{
365
				commandElement.setAttribute(attr, attrs.get(attr));
366
			}
367
		}
368
		
369
		if (data!=null)
370
		{
371
			for (String dataTag : data.keySet())
372
			{
373
				String dataContent=data.get(dataTag);
374
				Element dataChild = doc.createElement(dataTag);
375
				CDATASection cdataContent = doc.createCDATASection(dataContent);
376
//				child.setTextContent(dataContent);
377
				commandElement.appendChild(dataChild);
378
				dataChild.appendChild(cdataContent);
379
			}
380
		}
381
	}
382

  
383
	public static void getCommandData(Element commandElement, Set<String> attrKeys, Set<String> dataKeys, Map<String, String> attrMap, Map<String, String> dataMap)
384
	{
385
		if (attrMap!=null)
386
		{
387
			for (String attrName : attrKeys)
388
			{
389
				String attrValue=commandElement.getAttribute(attrName);
390
				attrMap.put(attrName, attrValue);
391
			}
392
		}
393
		
394
		if (dataMap!=null)
395
		{
396
			NodeList children=commandElement.getChildNodes();
397
			for (int i=0;i<children.getLength();i++)
398
			{
399
				String tagName=children.item(i).getNodeName();
400
				if (dataKeys.contains(tagName))
401
				{
402
					String data=children.item(i).getTextContent();
403
					dataMap.put(tagName, data);
404
				}
405
			}
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff