View | Details | Raw Unified | Return to bug 106416
Collapse All | Expand All

(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/CVS/Entries (-1 / +1 lines)
Lines 8-14 Link Here
8
/GraphicalTextViewer.java/1.9/Tue May 17 21:24:20 2005//
8
/GraphicalTextViewer.java/1.9/Tue May 17 21:24:20 2005//
9
/SelectionRange.java/1.9/Fri May 13 19:26:02 2005//
9
/SelectionRange.java/1.9/Fri May 13 19:26:02 2005//
10
/SelectionRangeRequest.java/1.3/Thu Mar 31 23:28:24 2005//
10
/SelectionRangeRequest.java/1.3/Thu Mar 31 23:28:24 2005//
11
/TextCommand.java/1.4/Thu Mar 31 23:28:24 2005//
11
/TextCommand.java/1.4/Wed Aug 03 16:36:30 2005//
12
/TextEditor.java/1.15/Tue Apr 26 19:29:55 2005//
12
/TextEditor.java/1.15/Tue Apr 26 19:29:55 2005//
13
/TextLocation.java/1.4/Thu Mar 31 23:28:24 2005//
13
/TextLocation.java/1.4/Thu Mar 31 23:28:24 2005//
14
/TextUtilities.java/1.3/Wed Mar 30 21:27:52 2005//
14
/TextUtilities.java/1.3/Wed Mar 30 21:27:52 2005//
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/edit/BlockEditPolicy.java (-31 / +38 lines)
Lines 41-46 Link Here
41
import org.eclipse.gef.examples.text.model.commands.RemoveRange;
41
import org.eclipse.gef.examples.text.model.commands.RemoveRange;
42
import org.eclipse.gef.examples.text.model.commands.RemoveText;
42
import org.eclipse.gef.examples.text.model.commands.RemoveText;
43
import org.eclipse.gef.examples.text.model.commands.SubdivideElement;
43
import org.eclipse.gef.examples.text.model.commands.SubdivideElement;
44
import org.eclipse.gef.examples.text.model.commands.ReplaceString;
44
import org.eclipse.gef.examples.text.requests.TextRequest;
45
import org.eclipse.gef.examples.text.requests.TextRequest;
45
46
46
/**
47
/**
Lines 107-114 Link Here
107
	if (TextRequest.REQ_STYLE == request.getType())
108
	if (TextRequest.REQ_STYLE == request.getType())
108
		return getTextStyleApplication((TextRequest)request);
109
		return getTextStyleApplication((TextRequest)request);
109
	if (TextRequest.REQ_INSERT == request.getType())
110
	if (TextRequest.REQ_INSERT == request.getType())
110
		return getTextInsertionCommand((TextRequest)request);
111
		return getTextInsertionCommand((TextRequest)request, false);
111
	if (TextRequest.REQ_BACKSPACE == request.getType())
112
    if (TextRequest.REQ_REPLACE == request.getType())
113
        return getTextInsertionCommand((TextRequest)request, true);
114
    if (TextRequest.REQ_BACKSPACE == request.getType())
112
		return getBackspaceCommand((TextRequest)request);
115
		return getBackspaceCommand((TextRequest)request);
113
	if (TextRequest.REQ_DELETE == request.getType())
116
	if (TextRequest.REQ_DELETE == request.getType())
114
		return getDeleteCommand((TextRequest)request);
117
		return getDeleteCommand((TextRequest)request);
Lines 120-154 Link Here
120
		return getUnindentCommand((TextRequest)request);
123
		return getUnindentCommand((TextRequest)request);
121
	if (TextRequest.REQ_INDENT == request.getType())
124
	if (TextRequest.REQ_INDENT == request.getType())
122
		return getIndentCommand((TextRequest)request);
125
		return getIndentCommand((TextRequest)request);
123
	return null;
126
    return null;
124
}
127
}
125
128
126
private Command getTextStyleApplication(TextRequest request) {
129
private Command getTextStyleApplication(TextRequest request) {
127
	SelectionRange range = request.getSelectionRange();
130
    SelectionRange range = request.getSelectionRange();
128
	ModelLocation start = new ModelLocation(
131
    ModelLocation start = new ModelLocation(
129
			(TextRun)range.begin.part.getModel(), range.begin.offset);
132
            (TextRun)range.begin.part.getModel(), range.begin.offset);
130
	ModelLocation end = new ModelLocation(
133
    ModelLocation end = new ModelLocation(
131
			(TextRun)range.end.part.getModel(), range.end.offset);
134
            (TextRun)range.end.part.getModel(), range.end.offset);
132
	CompoundEditCommand command = new CompoundEditCommand("Set Style");
135
    CompoundEditCommand command = new CompoundEditCommand("Set Style");
133
	command.setBeginLocation(start);
136
    command.setBeginLocation(start);
134
	command.setEndLocation(end);
137
    command.setEndLocation(end);
135
	
138
136
	String styleID = request.getStyleKeys()[0];
139
    String styleID = request.getStyleKeys()[0];
137
	if (Style.PROPERTY_ALIGNMENT.equals(styleID) 
140
    if (Style.PROPERTY_ALIGNMENT.equals(styleID)
138
			|| Style.PROPERTY_ORIENTATION.equals(styleID)) {
141
            || Style.PROPERTY_ORIENTATION.equals(styleID)) {
139
		Object value = request.getStyleValues()[0];
142
        Object value = request.getStyleValues()[0];
140
		for (Iterator iter = range.getLeafParts().iterator(); iter.hasNext();) {
143
        for (Iterator iter = range.getLeafParts().iterator(); iter.hasNext();) {
141
			// TODO optimize by ensuring that runs in the same container don't cause
144
            // TODO optimize by ensuring that runs in the same container don't cause
142
			// that container's style to be set multiple times
145
            // that container's style to be set multiple times
143
			TextRun run = (TextRun)((TextualEditPart)iter.next()).getModel();
146
            TextRun run = (TextRun)((TextualEditPart)iter.next()).getModel();
144
			command.pendEdit(new ApplyMultiStyle(run.getBlockContainer(), styleID, value));
147
            command.pendEdit(new ApplyMultiStyle(run.getBlockContainer(), styleID, value));
145
		}
148
        }
146
	} else if (!range.isEmpty()) {
149
    } else if (!range.isEmpty()) {
147
		command.pendEdit(new ApplyBooleanStyle(start, end, request.getStyleKeys(), 
150
        command.pendEdit(new ApplyBooleanStyle(start, end, request.getStyleKeys(),
148
				request.getStyleValues()));
151
                request.getStyleValues()));
149
	}
152
    }
150
153
151
	return command;
154
    return command;
152
}
155
}
153
156
154
private Command getIndentCommand(TextRequest request) {
157
private Command getIndentCommand(TextRequest request) {
Lines 200-206 Link Here
200
}
203
}
201
204
202
private Command getRangeRemovalCommand(TextRequest request) {
205
private Command getRangeRemovalCommand(TextRequest request) {
203
	return getTextInsertionCommand(request);
206
	return getTextInsertionCommand(request, false);
204
}
207
}
205
208
206
public EditPart getTargetEditPart(Request request) {
209
public EditPart getTargetEditPart(Request request) {
Lines 209-215 Link Here
209
	return null;
212
	return null;
210
}
213
}
211
214
212
private Command getTextInsertionCommand(TextRequest request) {
215
private Command getTextInsertionCommand(TextRequest request, boolean replace) {
213
	CompoundEditCommand command = null;
216
	CompoundEditCommand command = null;
214
	if (request.getPreviousCommand() instanceof CompoundEditCommand)
217
	if (request.getPreviousCommand() instanceof CompoundEditCommand)
215
		command = (CompoundEditCommand)request.getPreviousCommand();
218
		command = (CompoundEditCommand)request.getPreviousCommand();
Lines 240-247 Link Here
240
	}
243
	}
241
	
244
	
242
	if (request.getText() != null) {
245
	if (request.getText() != null) {
243
		InsertString insert = new InsertString(rangeBegin, request.getText(), range.begin.offset);
246
        MiniEdit edit;
244
		command.pendEdit(insert);
247
        if (replace)
248
            edit = new ReplaceString(rangeBegin, request.getText(), range.begin.offset);
249
        else
250
            edit = new InsertString(rangeBegin, request.getText(), range.begin.offset);
251
		command.pendEdit(edit);
245
	}
252
	}
246
	return command;
253
	return command;
247
}
254
}
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/model/commands/AbstractModifyString.java (+80 lines)
Line 0 Link Here
1
2
package org.eclipse.gef.examples.text.model.commands;
3
4
import org.eclipse.jface.util.Assert;
5
6
import org.eclipse.gef.examples.text.model.TextRun;
7
8
/**
9
 * This class provides a base for modifying string in a <code>TextRun</code>.
10
 * Subclasses should define what kind of modification is to be performed.
11
 */
12
public abstract class AbstractModifyString extends MiniEdit {
13
14
/**
15
 * The string that will be used to modify the <code>run</code> object.
16
 */
17
protected String pending;
18
19
/**
20
 * The characters that has been inserted.
21
 */
22
protected char insertedChars[];
23
24
/**
25
 * The offset where the modification is performed.
26
 */
27
protected final int offset;
28
29
/**
30
 * The text run on which the modification is performed.
31
 */
32
protected final TextRun run;
33
34
public AbstractModifyString(TextRun run, String c, int offset) {
35
    this.run = run;
36
    this.pending = c;
37
    this.offset = offset;
38
}
39
40
/**
41
 * @since 3.1
42
 * @param append the text to append.
43
 */
44
public void appendText(String append) {
45
    // not used now
46
    Assert.isTrue(pending == null);
47
    pending = append;
48
}
49
50
/**
51
 * @see org.eclipse.gef.commands.Command#execute()
52
 */
53
public void apply() {
54
    applyImpl();
55
    insertedChars = pending.toCharArray();
56
    pending = null;
57
}
58
59
/**
60
 * Applies this command.  This method should only do the modification to <code>run</code> object.
61
 */
62
protected abstract void applyImpl();
63
64
public boolean canApply() {
65
    return pending != null;
66
}
67
68
/**
69
 * re-executes the command for the additional character added above.
70
 */
71
public void commitPending() {
72
    //TODO: not used now.  should this be implemented in subclasses?
73
    run.insertText(pending, offset + insertedChars.length);
74
	char old[] = insertedChars;
75
	insertedChars = new char[old.length + 1];
76
	System.arraycopy(old, 0, insertedChars, 0, old.length);
77
	insertedChars[insertedChars.length - 1] = pending.toCharArray()[0];
78
	pending = null;
79
}
80
}
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/model/commands/CVS/Entries (-6 / +6 lines)
Lines 1-16 Link Here
1
/ApplyBooleanStyle.java/1.3/Wed Apr 20 17:54:29 2005//
1
/ApplyBooleanStyle.java/1.3/Wed Apr 20 17:54:29 2005//
2
/ApplyMultiStyle.java/1.2/Thu Jun 16 18:32:14 2005//
2
/ApplyMultiStyle.java/1.2/Thu Jun 16 18:32:14 2005//
3
/CompoundEditCommand.java/1.4/Wed Apr 20 00:05:15 2005//
3
/CompoundEditCommand.java/1.4/Wed Aug 03 16:34:38 2005//
4
/ConvertElementCommand.java/1.3/Wed Mar 30 21:27:52 2005//
4
/ConvertElementCommand.java/1.3/Wed Aug 03 16:34:38 2005//
5
/ExampleTextCommand.java/1.3/Thu Mar 31 23:28:24 2005//
5
/ExampleTextCommand.java/1.3/Wed Aug 03 16:34:38 2005//
6
/InsertModelElement.java/1.3/Wed Mar 30 21:27:52 2005//
6
/InsertModelElement.java/1.3/Wed Mar 30 21:27:52 2005//
7
/InsertString.java/1.3/Thu Mar 31 23:28:24 2005//
7
/InsertString.java/1.3/Thu Mar 31 23:28:24 2005//
8
/MergeWithPrevious.java/1.3/Wed Mar 30 21:27:52 2005//
8
/MergeWithPrevious.java/1.3/Wed Mar 30 21:27:52 2005//
9
/MiniEdit.java/1.3/Thu Mar 31 23:28:24 2005//
9
/MiniEdit.java/1.3/Thu Mar 31 23:28:24 2005//
10
/NestElementCommand.java/1.3/Wed Mar 30 21:27:52 2005//
10
/NestElementCommand.java/1.3/Wed Aug 03 16:34:38 2005//
11
/ProcessMacroCommand.java/1.3/Wed Mar 30 21:27:52 2005//
11
/ProcessMacroCommand.java/1.3/Wed Aug 03 16:35:32 2005//
12
/PromoteElementCommand.java/1.3/Wed Mar 30 21:27:52 2005//
12
/PromoteElementCommand.java/1.3/Wed Mar 30 21:27:52 2005//
13
/RemoveRange.java/1.3/Thu Mar 31 23:28:24 2005//
13
/RemoveRange.java/1.3/Thu Mar 31 23:28:24 2005//
14
/RemoveText.java/1.3/Thu Mar 31 23:28:24 2005//
14
/RemoveText.java/1.3/Thu Mar 31 23:28:24 2005//
15
/SingleEditCommand.java/1.4/Wed Apr 20 00:05:15 2005//
15
/SingleEditCommand.java/1.4/Wed Aug 03 16:36:12 2005//
16
/SubdivideElement.java/1.3/Wed Mar 30 21:27:52 2005//
16
/SubdivideElement.java/1.3/Wed Mar 30 21:27:52 2005//
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/model/commands/InsertString.java (-48 / +6 lines)
Lines 11-78 Link Here
11
11
12
package org.eclipse.gef.examples.text.model.commands;
12
package org.eclipse.gef.examples.text.model.commands;
13
13
14
import org.eclipse.jface.util.Assert;
15
16
import org.eclipse.gef.examples.text.model.ModelLocation;
14
import org.eclipse.gef.examples.text.model.ModelLocation;
17
import org.eclipse.gef.examples.text.model.TextRun;
15
import org.eclipse.gef.examples.text.model.TextRun;
18
16
19
/**
17
/**
20
 * @since 3.1
18
 * @since 3.1
21
 */
19
 */
22
public class InsertString extends MiniEdit {
20
public class InsertString extends AbstractModifyString {
23
24
private String pending;
25
26
private char insertedChars[];
27
28
private final int offset;
29
30
private final TextRun run;
31
21
32
public InsertString(TextRun run, String c, int offset) {
22
public InsertString(TextRun run, String c, int offset) {
33
	this.run = run;
23
	super (run, c, offset);
34
	this.pending = c;
35
	this.offset = offset;
36
}
37
38
/**
39
 * @since 3.1
40
 * @param char1
41
 */
42
public void appendText(String append) {
43
	Assert.isTrue(pending == null);
44
	pending = append;
45
}
46
47
/**
48
 * @see org.eclipse.gef.commands.Command#execute()
49
 */
50
public void apply() {
51
	run.insertText(pending, offset);
52
	insertedChars = pending.toCharArray();
53
	pending = null;
54
}
55
56
public boolean canApply() {
57
	return pending != null;
58
}
59
60
/**
61
 * re-executes the command for the additional character added above.
62
 */
63
public void commitPending() {
64
	run.insertText(pending, offset + insertedChars.length);
65
	char old[] = insertedChars;
66
	insertedChars = new char[old.length + 1];
67
	System.arraycopy(old, 0, insertedChars, 0, old.length);
68
	insertedChars[insertedChars.length - 1] = pending.toCharArray()[0];
69
	pending = null;
70
}
24
}
71
25
72
public ModelLocation getResultingLocation() {
26
public ModelLocation getResultingLocation() {
73
	return new ModelLocation(run, offset + insertedChars.length);
27
	return new ModelLocation(run, offset + insertedChars.length);
74
}
28
}
75
29
30
protected void applyImpl() {
31
    run.insertText(pending, offset);
32
}
33
76
public void reapply() {
34
public void reapply() {
77
	run.insertText(new String(insertedChars), offset);
35
	run.insertText(new String(insertedChars), offset);
78
}
36
}
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/model/commands/ReplaceString.java (+35 lines)
Line 0 Link Here
1
2
package org.eclipse.gef.examples.text.model.commands;
3
4
import org.eclipse.gef.examples.text.model.ModelLocation;
5
import org.eclipse.gef.examples.text.model.TextRun;
6
7
/**
8
 *
9
 */
10
public class ReplaceString extends AbstractModifyString {
11
12
private String replacedString;
13
14
public ReplaceString(TextRun run, String c, int offset) {
15
    super(run, c, offset);
16
}
17
18
protected void applyImpl() {
19
    replacedString = run.getText().substring(offset, offset + pending.length());
20
    run.replaceText(pending, offset);
21
22
}
23
24
public ModelLocation getResultingLocation() {
25
    return new ModelLocation(run, offset + insertedChars.length);
26
}
27
28
public void reapply() {
29
	run.replaceText(new String(insertedChars), offset);
30
}
31
32
public void rollback() {
33
    run.replaceText(replacedString, offset);
34
}
35
}
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/model/TextRun.java (+9 lines)
Lines 66-71 Link Here
66
	firePropertyChange("text", null, text);
66
	firePropertyChange("text", null, text);
67
}
67
}
68
68
69
public void replaceText(String someText, int offset) {
70
    StringBuffer buf = new StringBuffer();
71
    buf.append(text.substring(0, offset));
72
    buf.append(someText);
73
    buf.append(text.substring(offset + someText.length(), text.length()));
74
    text = buf.toString();
75
    firePropertyChange("text", null, text);
76
}
77
69
public String removeRange(int offset, int length) {
78
public String removeRange(int offset, int length) {
70
	Assert.isTrue(offset <= text.length());
79
	Assert.isTrue(offset <= text.length());
71
	Assert.isTrue(offset + length <= text.length());
80
	Assert.isTrue(offset + length <= text.length());
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/requests/TextRequest.java (-4 / +10 lines)
Lines 36-41 Link Here
36
36
37
public static final String REQ_INSERT = "TextRequest.input";
37
public static final String REQ_INSERT = "TextRequest.input";
38
38
39
public static final String REQ_REPLACE = "TextRequest.replace";
40
39
public static final String REQ_STYLE = "TextRequest.style";
41
public static final String REQ_STYLE = "TextRequest.style";
40
42
41
/**
43
/**
Lines 63-72 Link Here
63
 * @since 3.1
65
 * @since 3.1
64
 */
66
 */
65
public TextRequest(SelectionRange range, String text, AppendableCommand prevoius) {
67
public TextRequest(SelectionRange range, String text, AppendableCommand prevoius) {
66
	super(REQ_INSERT);
68
	this(REQ_INSERT, range, text, prevoius);
67
	this.text = text;
68
	this.range = range;
69
	this.previous = prevoius;
70
}
69
}
71
70
72
public TextRequest(String type, SelectionRange range) {
71
public TextRequest(String type, SelectionRange range) {
Lines 79-84 Link Here
79
	this.previous = previous;
78
	this.previous = previous;
80
}
79
}
81
80
81
public TextRequest(String type, SelectionRange range, String text, AppendableCommand prevoius) {
82
    super(type);
83
	this.text = text;
84
	this.range = range;
85
	this.previous = prevoius;
86
}
87
82
public int getInsertionOffset() {
88
public int getInsertionOffset() {
83
	return range.begin.offset;
89
	return range.begin.offset;
84
}	
90
}	
(-)/usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/tools/TextTool.java (-6 / +144 lines)
Lines 19-24 Link Here
19
import org.eclipse.swt.custom.ST;
19
import org.eclipse.swt.custom.ST;
20
import org.eclipse.swt.events.KeyEvent;
20
import org.eclipse.swt.events.KeyEvent;
21
import org.eclipse.swt.events.TraverseEvent;
21
import org.eclipse.swt.events.TraverseEvent;
22
import org.eclipse.swt.events.MouseEvent;
22
import org.eclipse.swt.graphics.Cursor;
23
import org.eclipse.swt.graphics.Cursor;
23
24
24
import org.eclipse.jface.util.Assert;
25
import org.eclipse.jface.util.Assert;
Lines 26-32 Link Here
26
import org.eclipse.jface.viewers.SelectionChangedEvent;
27
import org.eclipse.jface.viewers.SelectionChangedEvent;
27
28
28
import org.eclipse.draw2d.Cursors;
29
import org.eclipse.draw2d.Cursors;
30
import org.eclipse.draw2d.FigureCanvas;
31
import org.eclipse.draw2d.Viewport;
32
import org.eclipse.draw2d.text.CaretInfo;
29
import org.eclipse.draw2d.geometry.Rectangle;
33
import org.eclipse.draw2d.geometry.Rectangle;
34
import org.eclipse.draw2d.geometry.Point;
30
35
31
import org.eclipse.gef.DragTracker;
36
import org.eclipse.gef.DragTracker;
32
import org.eclipse.gef.EditPart;
37
import org.eclipse.gef.EditPart;
Lines 43-54 Link Here
43
import org.eclipse.gef.examples.text.TextCommand;
48
import org.eclipse.gef.examples.text.TextCommand;
44
import org.eclipse.gef.examples.text.TextLocation;
49
import org.eclipse.gef.examples.text.TextLocation;
45
import org.eclipse.gef.examples.text.TextUtilities;
50
import org.eclipse.gef.examples.text.TextUtilities;
51
import org.eclipse.gef.examples.text.edit.TextualEditPart;
52
import org.eclipse.gef.examples.text.edit.CaretSearch;
53
import org.eclipse.gef.examples.text.edit.AbstractTextualPart;
54
import org.eclipse.gef.examples.text.edit.TextStyleManager;
46
import org.eclipse.gef.examples.text.actions.StyleListener;
55
import org.eclipse.gef.examples.text.actions.StyleListener;
47
import org.eclipse.gef.examples.text.actions.StyleProvider;
56
import org.eclipse.gef.examples.text.actions.StyleProvider;
48
import org.eclipse.gef.examples.text.actions.StyleService;
57
import org.eclipse.gef.examples.text.actions.StyleService;
49
import org.eclipse.gef.examples.text.edit.CaretSearch;
50
import org.eclipse.gef.examples.text.edit.TextStyleManager;
51
import org.eclipse.gef.examples.text.edit.TextualEditPart;
52
import org.eclipse.gef.examples.text.requests.TextRequest;
58
import org.eclipse.gef.examples.text.requests.TextRequest;
53
59
54
/**
60
/**
Lines 80-85 Link Here
80
private final StyleService styleService;
86
private final StyleService styleService;
81
private List styleValues = new ArrayList();
87
private List styleValues = new ArrayList();
82
private int textInputMode;
88
private int textInputMode;
89
private boolean overwrite = false;
83
private boolean isMirrored;
90
private boolean isMirrored;
84
91
85
private final GraphicalTextViewer textViewer;
92
private final GraphicalTextViewer textViewer;
Lines 190-195 Link Here
190
		case ST.LINE_DOWN:
197
		case ST.LINE_DOWN:
191
			doSelect(CaretSearch.ROW, true, append);
198
			doSelect(CaretSearch.ROW, true, append);
192
			break;
199
			break;
200
//INSERT
201
        case ST.TOGGLE_OVERWRITE:
202
            toggleOverwrite();
203
            break;
193
//TAB
204
//TAB
194
		case SWT.TAB | SWT.SHIFT:
205
		case SWT.TAB | SWT.SHIFT:
195
			doUnindent();
206
			doUnindent();
Lines 208-214 Link Here
208
	}
227
	}
209
}
228
}
210
229
211
/**
230
private void toggleOverwrite() {
231
    overwrite = !overwrite;
232
}
233
234
private void doPageUp() {
235
    GraphicalTextViewer viewer = getTextualViewer();
236
    FigureCanvas canvas = (FigureCanvas) viewer.getControl();
237
    Viewport viewport = canvas.getViewport();
238
    Rectangle viewArea = viewport.getClientArea();
239
240
    CaretInfo caretInfo = viewer.getCaretInfo();
241
    if (caretInfo == null) {
242
        return;
243
    }
244
245
    // used to determine where the caret should be.
246
    int relativeY = caretInfo.getY();
247
    int startY = viewport.getViewLocation().y;
248
249
    // scrolling the height of the viewport above.
250
    int newY = startY - viewArea.height;
251
252
    Point newCaretPoint;
253
    if (startY > 0) {
254
        newCaretPoint = new Point (caretInfo.getX(), relativeY);
255
    } else {
256
        // the page is already at the top -- just move the caret to the very beginning.
257
        newCaretPoint = new Point(0, 0);
258
    }
259
260
    doEndPageUpDown(newCaretPoint, newY);
261
}
262
263
private void doPageDown() {
264
    GraphicalTextViewer viewer = getTextualViewer();
265
    FigureCanvas canvas = (FigureCanvas) viewer.getControl();
266
    Viewport viewport = canvas.getViewport();
267
    Rectangle viewArea = viewport.getClientArea();
268
269
    CaretInfo caretInfo = viewer.getCaretInfo();
270
    if (caretInfo == null) {
271
        return;
272
    }
273
274
    // used to determine where the caret should be.
275
    int relativeY = caretInfo.getY();
276
    int startY = viewport.getViewLocation().y;
277
    int maxY = viewport.getVerticalRangeModel().getMaximum();
278
    int maxBaseY = maxY - viewArea.height;
279
280
    // scrolling the height of the viewport above.
281
    int newY = startY + viewArea.height;
282
283
    Point newCaretPoint;
284
    if (startY < maxBaseY) {
285
        newCaretPoint = new Point (caretInfo.getX(), relativeY);
286
    } else {
287
        // the page is already at the bottom -- just move the caret to the very end.
288
        newCaretPoint = new Point(viewArea.width, maxY);
289
    }
290
291
    doEndPageUpDown(newCaretPoint, newY);
292
}
293
294
/**
295
 * Performs the end task common between page up and page down.
296
 * It scrolls the viewport and set the caret at the right position.
297
 *
298
 * @param newCaretPoint the new caret point where the caret should be set.
299
 * In some situations, this value is not directly used to set the caret location.
300
 * For example, when the caret is not completely visible in the viewport after scrolling,
301
 * the loation of caret gets adjusted so that it appears in the viewport.
302
 * @param newY the Y coordinate where the viewport should display.
303
 */
304
private void doEndPageUpDown(Point newCaretPoint, int newY) {
305
    GraphicalTextViewer viewer = getTextualViewer();
306
    FigureCanvas canvas = (FigureCanvas) viewer.getControl();
307
    canvas.scrollToY (newY);
308
    EditPart part = viewer.findObjectAt(newCaretPoint);
309
    if (part instanceof AbstractTextualPart) {
310
        AbstractTextualPart textPart = (AbstractTextualPart) part;
311
        TextLocation loc = textPart.getLocation(newCaretPoint, new int[1]);
312
313
        CaretInfo newInfo = getCaretInfo(loc, true);
314
        if (newInfo != null) {
315
            viewer.refreshViewportX(newInfo);
316
            int y = newInfo.getY();
317
            if (y < 0) {
318
                // the caret is visible in the viewport only partially
319
                // move the caret to the next line.
320
                Point movedCaretPoint = newCaretPoint.translate (0, newInfo.getLineHeight ());
321
                EditPart part2 = viewer.findObjectAt(movedCaretPoint);
322
                if (part instanceof AbstractTextualPart) {
323
                    AbstractTextualPart textPart2 = (AbstractTextualPart) part2;
324
                    loc = textPart2.getLocation(newCaretPoint, new int[1]);
325
                }
326
            }
327
        }
328
329
        viewer.setSelectionRange(new SelectionRange(loc));
330
    }
331
}
332
333
/**
334
 * Gets the caret info based on the text location.
335
 * @param location the location of the text.
336
 * @param forward
337
 * @return the caret info.
338
 */
339
private CaretInfo getCaretInfo(TextLocation location, boolean forward) {
340
    GraphicalTextViewer viewer = getTextualViewer ();
341
	if (viewer.getCaretOwner() == null)
342
		return null;
343
	if (forward && location.offset > 0) {
344
		return viewer.getCaretOwner ().getCaretPlacement(location.offset - 1, true);
345
	} else {
346
		return viewer.getCaretOwner().getCaretPlacement(location.offset, false);
347
	}
348
}
349
350
    /**
212
 * @since 3.1
351
 * @since 3.1
213
 * @param e
352
 * @param e
214
 */
353
 */
Lines 257-263 Link Here
257
 */
396
 */
258
private boolean doInsertContent(char c) {
397
private boolean doInsertContent(char c) {
259
	setTextInputMode(MODE_TYPING);
398
	setTextInputMode(MODE_TYPING);
260
	TextRequest edit = new TextRequest(getTextualViewer().getSelectionRange(), Character
399
    String type = (overwrite) ? TextRequest.REQ_REPLACE : TextRequest.REQ_INSERT;
400
    TextRequest edit = new TextRequest(type, getTextualViewer().getSelectionRange(), Character
261
			.toString(c), pendingCommand);
401
			.toString(c), pendingCommand);
262
	String keys[] = new String[styleKeys.size()];
402
	String keys[] = new String[styleKeys.size()];
263
	styleKeys.toArray(keys);
403
	styleKeys.toArray(keys);
Lines 340-345 Link Here
340
		else
480
		else
341
			getTextualViewer().setSelectionRange(new SelectionRange(newCaretLocation, newCaretLocation, false));
481
			getTextualViewer().setSelectionRange(new SelectionRange(newCaretLocation, newCaretLocation, false));
342
	}
482
	}
483
484
    // Scroll the view
485
    CaretInfo newCaretInfo = newCaretLocation.part.getCaretPlacement(newCaretLocation.offset, false);
486
    getTextualViewer().refreshViewport(newCaretInfo);
343
}
487
}
344
488
345
/**
489
/**
Lines 540-551 Link Here
540
			return ST.LINE_DOWN;
684
			return ST.LINE_DOWN;
541
		case ST.PAGE_UP:
685
		case ST.PAGE_UP:
542
			return ST.PAGE_UP;
686
			return ST.PAGE_UP;
543
		case ST.SELECT_LINE_UP:
687
		case ST.SELECT_LINE_UP:
544
			return ST.SELECT_LINE_UP;
688
			return ST.SELECT_LINE_UP;
545
		case ST.SELECT_LINE_DOWN:
689
		case ST.SELECT_LINE_DOWN:
546
			return ST.SELECT_LINE_DOWN;
690
			return ST.SELECT_LINE_DOWN;
547
691
548
		case SWT.DEL:
692
        case SWT.INSERT:
693
            return ST.TOGGLE_OVERWRITE;
694
        case SWT.DEL:
549
			return ST.DELETE_NEXT;
695
			return ST.DELETE_NEXT;
550
		case SWT.BS:
696
		case SWT.BS:
551
			return ST.DELETE_PREVIOUS;
697
			return ST.DELETE_PREVIOUS;

Return to bug 106416