Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
af3
kernel
Commits
e0ffd3c3
Commit
e0ffd3c3
authored
10 years ago
by
Vincent Aravantinos
Browse files
Options
Downloads
Patches
Plain Diff
YELLOW
refs 2093
parent
f4d5c17a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/UndoRedoImpl.java
+42
-7
42 additions, 7 deletions
.../src/org/fortiss/tooling/kernel/ui/util/UndoRedoImpl.java
with
42 additions
and
7 deletions
org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/UndoRedoImpl.java
+
42
−
7
View file @
e0ffd3c3
...
...
@@ -28,77 +28,107 @@ import org.eclipse.swt.widgets.Text;
/**
* Hack class to implement undo/redo key shortcuts for swt Text fields.
* TODO: yeah looks like tha warnings swarming all over the place => RED as hell fire
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash:
C6CFC71F876775529808379C84FC2615
* @ConQAT.Rating YELLOW Hash:
6B5E3B3D3FF977AAB4287A8F4FA17C12
*/
public
class
UndoRedoImpl
implements
KeyListener
,
ModifyListener
{
/**
* Encapsulation of the Undo and Redo stack(s).
*/
/** Encapsulation of the generic undo and redo stack(s). */
private
static
class
UndoRedoStack
<
T
>
{
/** Generic undo stack. */
private
Stack
<
T
>
undo
;
/** Generic redo stack. */
private
Stack
<
T
>
redo
;
/** Constructor. */
public
UndoRedoStack
()
{
undo
=
new
Stack
<
T
>();
redo
=
new
Stack
<
T
>();
}
/** Push on the undo stack. */
public
void
pushUndo
(
T
delta
)
{
undo
.
add
(
delta
);
}
/** Push on the redo stack. */
public
void
pushRedo
(
T
delta
)
{
redo
.
add
(
delta
);
}
/** Pop from the undo stack. */
public
T
popUndo
()
{
T
res
=
undo
.
pop
();
return
res
;
}
/** Pop from the redo stack. */
public
T
popRedo
()
{
T
res
=
redo
.
pop
();
return
res
;
}
/** Clear the redo stack. */
public
void
clearRedo
()
{
redo
.
clear
();
}
/** Test if the undo stack is not empty. */
public
boolean
hasUndo
()
{
return
!
undo
.
isEmpty
();
}
/** Test if the redo stack is not empty. */
public
boolean
hasRedo
()
{
return
!
redo
.
isEmpty
();
}
}
/**
* Class encapsulating a string and a cursor position.
* This is what is going to be stored in the {@link UndoRedoStack}.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
private
static
class
StringAndPosition
{
/** String content. */
public
String
string
;
/** Cursor position. */
public
int
position
;
/** Constructor. */
public
StringAndPosition
(
String
str
,
int
pos
)
{
string
=
str
;
position
=
pos
;
}
}
/** Text widget for which the undo/redo feature is implemented. */
private
Text
editor
;
/** The undo/redo stack. */
private
UndoRedoStack
<
StringAndPosition
>
stack
;
/** Flag to know if we are in the course of applying an undo. */
private
boolean
isUndo
;
/** Flag to know if we are in the course of applying a redo. */
private
boolean
isRedo
;
/**
* To store the latest string and position (useful when we are in the course of applying an
* undo/redo and the current string and position in the widget do not represent a "valid"
* value).
*/
private
StringAndPosition
previousTextAndPosition
;
/**
...
...
@@ -118,19 +148,22 @@ public class UndoRedoImpl implements KeyListener, ModifyListener {
stack
=
new
UndoRedoStack
<
StringAndPosition
>();
}
/** Stores the information from the widget to the previousTextAndPosition attribute. */
private
void
storeTextAndPos
()
{
previousTextAndPosition
=
new
StringAndPosition
(
editor
.
getText
(),
editor
.
getSelection
().
x
);
}
/** Updates the text and cursor position of the widget according to the argument. */
private
void
setTextAndPos
(
StringAndPosition
x
)
{
editor
.
setText
(
x
.
string
);
editor
.
setSelection
(
x
.
position
);
}
/*
/*
*
* We use keyPressed for Redo and keyReleased for Undo, because, for some reason, Ctrl-z is
* captured only at release and Ctrl-y (resp. Ctrl-Shift-y) only at press.
*/
@Override
public
void
keyPressed
(
KeyEvent
e
)
{
storeTextAndPos
();
if
((
e
.
stateMask
&
SWT
.
MOD1
)
>
0
&&
!((
e
.
stateMask
&
SWT
.
ALT
)
>
0
))
{
...
...
@@ -141,10 +174,11 @@ public class UndoRedoImpl implements KeyListener, ModifyListener {
}
}
/*
/*
*
* We use keyPressed for Redo and keyReleased for Undo, because, for some reason, Ctrl-z is
* captured only at release and Ctrl-y (resp. Ctrl-Shift-y) only at press.
*/
@Override
public
void
keyReleased
(
KeyEvent
e
)
{
if
((
e
.
stateMask
&
SWT
.
MOD1
)
>
0
&&
!((
e
.
stateMask
&
SWT
.
ALT
)
>
0
))
{
boolean
isShift
=
(
e
.
stateMask
&
SWT
.
SHIFT
)
>
0
;
...
...
@@ -165,6 +199,7 @@ public class UndoRedoImpl implements KeyListener, ModifyListener {
* @see org.eclipse.swt.custom.ExtendedModifyListener#modifyText(org.eclipse.
* swt.custom.ExtendedModifyEvent)
*/
@Override
public
void
modifyText
(
ModifyEvent
event
)
{
if
(
isUndo
)
{
stack
.
pushRedo
(
previousTextAndPosition
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment