1 | /****************************** Module Header *******************************
|
---|
2 | *
|
---|
3 | * Module Name: undo.e
|
---|
4 | *
|
---|
5 | * Copyright (c) Netlabs EPM Distribution Project 2002
|
---|
6 | *
|
---|
7 | * $Id: undo.e 2417 2011-05-15 23:32:51Z aschn $
|
---|
8 | *
|
---|
9 | * ===========================================================================
|
---|
10 | *
|
---|
11 | * This file is part of the Netlabs EPM Distribution package and is free
|
---|
12 | * software. You can redistribute it and/or modify it under the terms of the
|
---|
13 | * GNU General Public License as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * Netlabs EPM Distribution. This library is distributed in the hope that it
|
---|
16 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
---|
17 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | * General Public License for more details.
|
---|
19 | *
|
---|
20 | ****************************************************************************/
|
---|
21 |
|
---|
22 | ; ---------------------------------------------------------------------------
|
---|
23 | ; Moved from STDCTRL.E
|
---|
24 | defc ProcessUndo
|
---|
25 | --undoaction 1, PresentState;
|
---|
26 | --undoaction 2, OldestState;
|
---|
27 | CurrentUndoState = arg(1)
|
---|
28 | --
|
---|
29 | --if CurrentUndoState<OldestState then
|
---|
30 | -- return
|
---|
31 | --endif
|
---|
32 | --sayerror 'Undoing State ' CurrentUndoState ' old='OldestState ' new='PresentState
|
---|
33 | undoaction 7, CurrentUndoState;
|
---|
34 | --refresh;
|
---|
35 |
|
---|
36 | ; ---------------------------------------------------------------------------
|
---|
37 | ; Restore standard undo recording. Some commands have to disable that
|
---|
38 | ; in order to not clutter the record list, e.g. when a command is used
|
---|
39 | ; repeatedly.
|
---|
40 | ; Values for action:
|
---|
41 | ; 0: at every keystroke (not default)
|
---|
42 | ; 1: at every command (not default)
|
---|
43 | ; 2: when moving the cursor from a modified line (default)
|
---|
44 | ; This is used by following key defcs and events, e.g.:
|
---|
45 | ; Space, Return, defselect, ProcessOtherKeys
|
---|
46 | defproc EnableUndoRec
|
---|
47 | --action = 0 -- action, the 2nd param of undoaction, must be a var
|
---|
48 | --undoaction 4, action -- 4: disable undo recording at action
|
---|
49 |
|
---|
50 | --action = 1 -- action, the 2nd param of undoaction, must be a var
|
---|
51 | --undoaction 5, action -- 5: enable undo recording at action
|
---|
52 |
|
---|
53 | action = 2 -- action, the 2nd param of undoaction, must be a var
|
---|
54 | undoaction 5, action -- 5: enable undo recording at action
|
---|
55 | return
|
---|
56 |
|
---|
57 | ; ---------------------------------------------------------------------------
|
---|
58 | ; Disable undo recording. This is used by several key defcs, e.g.:
|
---|
59 | ; Space, Tab, TypeTab, ShiftLeft, ShiftRight, DeleteChar, BackSpace
|
---|
60 | defproc DisableUndoRec
|
---|
61 | compile if 1
|
---|
62 | universal curkey
|
---|
63 | universal prevkey
|
---|
64 | -- Only disable it if current key wasn't pressed before
|
---|
65 | if curkey <> prevkey then
|
---|
66 | compile endif
|
---|
67 | action = 0 -- action, the 2nd param of undoaction, must be a var
|
---|
68 | undoaction 4, action -- 4: disable undo recording at action
|
---|
69 | action = 1 -- action, the 2nd param of undoaction, must be a var
|
---|
70 | undoaction 4, action -- 4: disable undo recording at action
|
---|
71 | action = 2 -- action, the 2nd param of undoaction, must be a var
|
---|
72 | undoaction 4, action -- 4: disable undo recording at action
|
---|
73 | compile if 1
|
---|
74 | endif
|
---|
75 | compile endif
|
---|
76 | return
|
---|
77 |
|
---|
78 | ; ---------------------------------------------------------------------------
|
---|
79 | ; Create a new undo record and restore standard undo behaviour
|
---|
80 | defproc NewUndoRec
|
---|
81 | if .modify then
|
---|
82 | undoaction 1, junk -- 1: Create a new state
|
---|
83 | call EnableUndoRec()
|
---|
84 | endif
|
---|
85 | return
|
---|
86 |
|
---|
87 | ; ---------------------------------------------------------------------------
|
---|
88 | ; Commands for accessing undo procs from REXX and C
|
---|
89 | defc RestoreUndo, EnableUndoRec
|
---|
90 | call EnableUndoRec()
|
---|
91 |
|
---|
92 | defc DisableUndoRec
|
---|
93 | call DisableUndoRec()
|
---|
94 |
|
---|
95 | defc NewUndoRec
|
---|
96 | call NewUndoRec()
|
---|
97 |
|
---|
98 | ; ---------------------------------------------------------------------------
|
---|
99 | ; Moved from STDCTRL.E
|
---|
100 | defc RenderUndoInfo
|
---|
101 | undoaction 1, PresentState -- Do to fix range, not for value.
|
---|
102 | ; undoaction 2, OldestState;
|
---|
103 | ; statestr=PresentState OldestState \0
|
---|
104 | undoaction 6, StateRange -- query range
|
---|
105 | parse value staterange with oldeststate neweststate
|
---|
106 | statestr = newestState oldeststate\0
|
---|
107 | action = 1
|
---|
108 | undoaction 4, action
|
---|
109 | -- sayerror '<'statestr'>'
|
---|
110 | call windowmessage( 1, arg(1), -- send message back to dialog
|
---|
111 | 32, -- WM_COMMAND - 0x0020
|
---|
112 | 9999,
|
---|
113 | ltoa( offset( statestr) || selector( statestr), 10))
|
---|
114 |
|
---|
115 | ; ---------------------------------------------------------------------------
|
---|
116 | ; Moved from STDCTRL.E
|
---|
117 | defc UndoDlg
|
---|
118 | ; undoaction 1, PresentState -- Do to fix range, not for value.
|
---|
119 | ; undoaction 6, StateRange -- query range
|
---|
120 | ; parse value staterange with oldeststate neweststate
|
---|
121 | ; if oldeststate = neweststate then
|
---|
122 | ; sayerror 'No other undo states recorded.'
|
---|
123 | ; else
|
---|
124 | call windowmessage( 0, getpminfo(APP_HANDLE),
|
---|
125 | 5131, -- EPM_POPUNDODLG
|
---|
126 | 0,
|
---|
127 | 0)
|
---|
128 | ; endif
|
---|
129 |
|
---|
130 | ; ---------------------------------------------------------------------------
|
---|
131 | ; Moved from STDCTRL.E
|
---|
132 | defc Undo
|
---|
133 | undo
|
---|
134 |
|
---|
135 | ; ---------------------------------------------------------------------------
|
---|
136 | ; From EPMSMP\UNDOREDO.E
|
---|
137 | ; Changed:
|
---|
138 | ; o beep disabled
|
---|
139 |
|
---|
140 | /* The following code defines a couple of keys that let you step backwards
|
---|
141 | and forwards through the undo states. For the sake of example, I've
|
---|
142 | defined the Undo key as Ctrl+U and the Redo key as Ctrl+R. You might
|
---|
143 | prefer to select other keys that don't conflict with standard EPM key
|
---|
144 | definitions. One important note - the way that the keys determine if
|
---|
145 | you're still in an undo/redo sequence is checking if the previous key
|
---|
146 | pressed was also Ctrl+U or Ctrl+R. Because of the way keys are handled,
|
---|
147 | you must press and hold the Ctrl key for as long as you're stepping back
|
---|
148 | and forth (by pressing U and R) - once you release the Ctrl key, the next
|
---|
149 | time you press Ctrl+U or Ctrl+R, they will see the previously-pressed key
|
---|
150 | as being the Ctrl key, not Ctrl+U or Ctrl+R. The same is true if you
|
---|
151 | define the keys to be a Shift or Alt combination (which implies that they
|
---|
152 | both have to have the same shift state - both start with s_, both with c_,
|
---|
153 | both with a_, or both unshifted).
|
---|
154 |
|
---|
155 | Note also that this assumes the user has not enabled undo-state recording
|
---|
156 | on *every* keystroke. If you did, then you might have to add code here
|
---|
157 | to stop recording changes on keystrokes, and it's not clear how you'd
|
---|
158 | figure out when to turn it back on.
|
---|
159 | by: Larry Margolis */
|
---|
160 |
|
---|
161 | defc Undo1
|
---|
162 | universal current_undo_state
|
---|
163 | universal curkey
|
---|
164 | universal prevkey
|
---|
165 | parse value( prevkey) with Key''\1''Cmd
|
---|
166 | UndoKeys = strip( GetAVar( 'keycmd.undo1')) strip( GetAVar( 'keycmd.redo1'))
|
---|
167 | --dprintf( 'Key = 'Key', UndoKeys = 'UndoKeys)
|
---|
168 | if wordpos( Key, UndoKeys) > 0 then -- last key was undo or redo
|
---|
169 | parse value current_undo_state with PresentState OldestState NewestState
|
---|
170 | if PresentState > OldestState then
|
---|
171 | PresentState = PresentState - 1
|
---|
172 | undoaction 7, PresentState
|
---|
173 | current_undo_State = PresentState OldestState NewestState
|
---|
174 | 'SayHint Now at state' PresentState 'of' NewestState
|
---|
175 | else
|
---|
176 | --call beep(800, 500)
|
---|
177 | 'SayHint Already at state' PresentState 'of' NewestState
|
---|
178 | endif
|
---|
179 | else
|
---|
180 | -- Need to get new state information
|
---|
181 | undoaction 1, starting_state -- Do to fix range and for value.
|
---|
182 | undoaction 6, StateRange -- query range
|
---|
183 | parse value StateRange with OldestState NewestState
|
---|
184 | if NewestState = 1 then
|
---|
185 | 'SayHint No earlier undo states available'
|
---|
186 | else
|
---|
187 | PresentState = NewestState - 1
|
---|
188 | undoaction 7, PresentState
|
---|
189 | current_undo_state = PresentState OldestState NewestState
|
---|
190 | 'SayHint Initialized at state' PresentState 'of' NewestState
|
---|
191 | endif
|
---|
192 | endif
|
---|
193 |
|
---|
194 | defc Redo1
|
---|
195 | universal current_undo_state
|
---|
196 | universal curkey
|
---|
197 | universal prevkey
|
---|
198 | parse value( prevkey) with Key''\1''Cmd
|
---|
199 | UndoKeys = strip( GetAVar( 'keycmd.undo1')) strip( GetAVar( 'keycmd.redo1'))
|
---|
200 | --dprintf( 'Key = 'Key', UndoKeys = 'UndoKeys)
|
---|
201 | if wordpos( Key, UndoKeys) > 0 then -- last key was undo or redo
|
---|
202 | parse value current_undo_state with PresentState OldestState NewestState
|
---|
203 | if PresentState < NewestState then
|
---|
204 | PresentState = PresentState + 1
|
---|
205 | undoaction 7, PresentState
|
---|
206 | current_undo_state = PresentState OldestState NewestState
|
---|
207 | 'SayHint Now at state' PresentState 'of' NewestState
|
---|
208 | else
|
---|
209 | 'SayHint Already at state' PresentState 'of' NewestState
|
---|
210 | endif
|
---|
211 | else
|
---|
212 | --call beep(800, 500)
|
---|
213 | -- Need to get new state information
|
---|
214 | undoaction 1, starting_state -- Do to fix range and for value.
|
---|
215 | undoaction 6, StateRange -- query range
|
---|
216 | parse value StateRange with OldestState NewestState
|
---|
217 | presentState = NewestState
|
---|
218 | current_undo_state = PresentState OldestState NewestState
|
---|
219 | 'SayHint Initialized at state' PresentState 'of' NewestState
|
---|
220 | endif
|
---|
221 |
|
---|