Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 12-40
Link Here
|
12 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
13 |
package org.eclipse.compare.internal; |
13 |
package org.eclipse.compare.internal; |
14 |
|
14 |
|
15 |
import java.util.*; |
15 |
import java.util.ArrayList; |
|
|
16 |
import java.util.HashMap; |
17 |
import java.util.Iterator; |
16 |
import java.util.List; |
18 |
import java.util.List; |
|
|
19 |
import java.util.ResourceBundle; |
17 |
|
20 |
|
18 |
import org.eclipse.compare.ICompareContainer; |
21 |
import org.eclipse.compare.ICompareContainer; |
19 |
import org.eclipse.core.commands.operations.*; |
22 |
import org.eclipse.core.commands.operations.IOperationHistory; |
20 |
import org.eclipse.jface.action.*; |
23 |
import org.eclipse.core.commands.operations.IOperationHistoryListener; |
|
|
24 |
import org.eclipse.core.commands.operations.IUndoContext; |
25 |
import org.eclipse.core.commands.operations.OperationHistoryEvent; |
26 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.IProgressMonitor; |
28 |
import org.eclipse.jface.action.GroupMarker; |
29 |
import org.eclipse.jface.action.IAction; |
30 |
import org.eclipse.jface.action.IMenuListener; |
31 |
import org.eclipse.jface.action.IMenuManager; |
32 |
import org.eclipse.jface.action.MenuManager; |
33 |
import org.eclipse.jface.action.Separator; |
21 |
import org.eclipse.jface.preference.IPreferenceStore; |
34 |
import org.eclipse.jface.preference.IPreferenceStore; |
22 |
import org.eclipse.jface.preference.PreferenceConverter; |
35 |
import org.eclipse.jface.preference.PreferenceConverter; |
23 |
import org.eclipse.jface.text.*; |
36 |
import org.eclipse.jface.text.BadLocationException; |
24 |
import org.eclipse.jface.text.source.*; |
37 |
import org.eclipse.jface.text.IDocument; |
|
|
38 |
import org.eclipse.jface.text.IRegion; |
39 |
import org.eclipse.jface.text.ITextListener; |
40 |
import org.eclipse.jface.text.ITextViewer; |
41 |
import org.eclipse.jface.text.ITextViewerExtension5; |
42 |
import org.eclipse.jface.text.IUndoManager; |
43 |
import org.eclipse.jface.text.IUndoManagerExtension; |
44 |
import org.eclipse.jface.text.Position; |
45 |
import org.eclipse.jface.text.Region; |
46 |
import org.eclipse.jface.text.TextEvent; |
47 |
import org.eclipse.jface.text.source.CompositeRuler; |
48 |
import org.eclipse.jface.text.source.IAnnotationModel; |
49 |
import org.eclipse.jface.text.source.ISharedTextColors; |
50 |
import org.eclipse.jface.text.source.IVerticalRuler; |
51 |
import org.eclipse.jface.text.source.LineNumberRulerColumn; |
52 |
import org.eclipse.jface.text.source.SourceViewer; |
53 |
import org.eclipse.jface.text.source.SourceViewerConfiguration; |
25 |
import org.eclipse.jface.util.IPropertyChangeListener; |
54 |
import org.eclipse.jface.util.IPropertyChangeListener; |
26 |
import org.eclipse.jface.util.PropertyChangeEvent; |
55 |
import org.eclipse.jface.util.PropertyChangeEvent; |
27 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
56 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
|
57 |
import org.eclipse.jface.viewers.ISelectionProvider; |
28 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
58 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
29 |
import org.eclipse.swt.SWT; |
59 |
import org.eclipse.swt.SWT; |
30 |
import org.eclipse.swt.custom.StyledText; |
60 |
import org.eclipse.swt.custom.StyledText; |
31 |
import org.eclipse.swt.graphics.*; |
61 |
import org.eclipse.swt.graphics.Color; |
32 |
import org.eclipse.swt.widgets.*; |
62 |
import org.eclipse.swt.graphics.Font; |
|
|
63 |
import org.eclipse.swt.graphics.Image; |
64 |
import org.eclipse.swt.graphics.Point; |
65 |
import org.eclipse.swt.graphics.RGB; |
66 |
import org.eclipse.swt.graphics.Rectangle; |
67 |
import org.eclipse.swt.widgets.Composite; |
68 |
import org.eclipse.swt.widgets.Control; |
69 |
import org.eclipse.swt.widgets.Display; |
70 |
import org.eclipse.ui.IEditorInput; |
71 |
import org.eclipse.ui.IEditorSite; |
72 |
import org.eclipse.ui.IPropertyListener; |
33 |
import org.eclipse.ui.IWorkbenchActionConstants; |
73 |
import org.eclipse.ui.IWorkbenchActionConstants; |
|
|
74 |
import org.eclipse.ui.IWorkbenchPart; |
75 |
import org.eclipse.ui.IWorkbenchPartSite; |
76 |
import org.eclipse.ui.PartInitException; |
34 |
import org.eclipse.ui.PlatformUI; |
77 |
import org.eclipse.ui.PlatformUI; |
35 |
import org.eclipse.ui.editors.text.EditorsUI; |
78 |
import org.eclipse.ui.editors.text.EditorsUI; |
36 |
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; |
79 |
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; |
37 |
import org.eclipse.ui.texteditor.FindReplaceAction; |
80 |
import org.eclipse.ui.texteditor.FindReplaceAction; |
|
|
81 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
82 |
import org.eclipse.ui.texteditor.IElementStateListener; |
83 |
import org.eclipse.ui.texteditor.ITextEditor; |
38 |
/** |
84 |
/** |
39 |
* Extends the JFace SourceViewer with some convenience methods. |
85 |
* Extends the JFace SourceViewer with some convenience methods. |
40 |
*/ |
86 |
*/ |
Lines 50-55
Link Here
|
50 |
public static final String SELECT_ALL_ID= "selectAll"; //$NON-NLS-1$ |
96 |
public static final String SELECT_ALL_ID= "selectAll"; //$NON-NLS-1$ |
51 |
public static final String SAVE_ID= "save"; //$NON-NLS-1$ |
97 |
public static final String SAVE_ID= "save"; //$NON-NLS-1$ |
52 |
public static final String FIND_ID= "find"; //$NON-NLS-1$ |
98 |
public static final String FIND_ID= "find"; //$NON-NLS-1$ |
|
|
99 |
public static final String GOTO_LINE_ID= "gotoLine"; //$NON-NLS-1$ |
53 |
|
100 |
|
54 |
class TextOperationAction extends MergeViewerAction { |
101 |
class TextOperationAction extends MergeViewerAction { |
55 |
|
102 |
|
Lines 81-87
Link Here
|
81 |
this.setEnabled(isEnabled()); |
128 |
this.setEnabled(isEnabled()); |
82 |
} |
129 |
} |
83 |
} |
130 |
} |
|
|
131 |
|
132 |
class TextEditorAdapter implements ITextEditor { |
133 |
|
134 |
ITextViewer textViewer; |
135 |
IWorkbenchPart workbenchPart; |
136 |
|
137 |
public TextEditorAdapter(ITextViewer textViewer, IWorkbenchPart workbenchPart) { |
138 |
this.textViewer = textViewer; |
139 |
this.workbenchPart = workbenchPart; |
140 |
} |
141 |
|
142 |
public void close(boolean save) { |
143 |
// TODO Auto-generated method stub |
144 |
|
145 |
} |
146 |
|
147 |
public void doRevertToSaved() { |
148 |
// TODO Auto-generated method stub |
149 |
|
150 |
} |
151 |
|
152 |
public IAction getAction(String actionId) { |
153 |
// TODO Auto-generated method stub |
154 |
return null; |
155 |
} |
156 |
|
157 |
public IDocumentProvider getDocumentProvider() { |
158 |
return new IDocumentProvider(){ |
159 |
|
160 |
public void aboutToChange(Object element) { |
161 |
// TODO Auto-generated method stub |
162 |
|
163 |
} |
164 |
|
165 |
public void addElementStateListener( |
166 |
IElementStateListener listener) { |
167 |
// TODO Auto-generated method stub |
168 |
|
169 |
} |
170 |
|
171 |
public boolean canSaveDocument(Object element) { |
172 |
// TODO Auto-generated method stub |
173 |
return false; |
174 |
} |
175 |
|
176 |
public void changed(Object element) { |
177 |
// TODO Auto-generated method stub |
178 |
|
179 |
} |
180 |
|
181 |
public void connect(Object element) throws CoreException { |
182 |
// TODO Auto-generated method stub |
183 |
|
184 |
} |
185 |
|
186 |
public void disconnect(Object element) { |
187 |
// TODO Auto-generated method stub |
188 |
|
189 |
} |
190 |
|
191 |
public IAnnotationModel getAnnotationModel(Object element) { |
192 |
// TODO Auto-generated method stub |
193 |
return null; |
194 |
} |
195 |
|
196 |
public IDocument getDocument(Object element) { |
197 |
return textViewer.getDocument(); |
198 |
} |
199 |
|
200 |
public long getModificationStamp(Object element) { |
201 |
// TODO Auto-generated method stub |
202 |
return 0; |
203 |
} |
204 |
|
205 |
public long getSynchronizationStamp(Object element) { |
206 |
// TODO Auto-generated method stub |
207 |
return 0; |
208 |
} |
209 |
|
210 |
public boolean isDeleted(Object element) { |
211 |
// TODO Auto-generated method stub |
212 |
return false; |
213 |
} |
214 |
|
215 |
public boolean mustSaveDocument(Object element) { |
216 |
// TODO Auto-generated method stub |
217 |
return false; |
218 |
} |
219 |
|
220 |
public void removeElementStateListener( |
221 |
IElementStateListener listener) { |
222 |
// TODO Auto-generated method stub |
223 |
|
224 |
} |
225 |
|
226 |
public void resetDocument(Object element) throws CoreException { |
227 |
// TODO Auto-generated method stub |
228 |
|
229 |
} |
230 |
|
231 |
public void saveDocument(IProgressMonitor monitor, |
232 |
Object element, IDocument document, boolean overwrite) |
233 |
throws CoreException { |
234 |
// TODO Auto-generated method stub |
235 |
|
236 |
}}; |
237 |
} |
238 |
|
239 |
public IRegion getHighlightRange() { |
240 |
// TODO Auto-generated method stub |
241 |
return null; |
242 |
} |
243 |
|
244 |
public ISelectionProvider getSelectionProvider() { |
245 |
// TODO Auto-generated method stub |
246 |
return null; |
247 |
} |
248 |
|
249 |
public boolean isEditable() { |
250 |
// TODO Auto-generated method stub |
251 |
return false; |
252 |
} |
253 |
|
254 |
public void removeActionActivationCode(String actionId) { |
255 |
// TODO Auto-generated method stub |
256 |
|
257 |
} |
258 |
|
259 |
public void resetHighlightRange() { |
260 |
// TODO Auto-generated method stub |
261 |
|
262 |
} |
263 |
|
264 |
public void selectAndReveal(int start, int length) { |
265 |
selectAndReveal(start, length, start, length); |
266 |
} |
267 |
|
268 |
/* |
269 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#selectAndReveal(int, int, int, int) |
270 |
*/ |
271 |
private void selectAndReveal(int selectionStart, int selectionLength, int revealStart, int revealLength) { |
272 |
// TODO: |
273 |
// ISelection selection= getSelectionProvider().getSelection(); |
274 |
// if (selection instanceof ITextSelection) { |
275 |
// ITextSelection textSelection= (ITextSelection) selection; |
276 |
// if (textSelection.getOffset() != 0 || textSelection.getLength() != 0) |
277 |
// markInNavigationHistory(); |
278 |
// } |
279 |
|
280 |
StyledText widget= textViewer.getTextWidget(); |
281 |
widget.setRedraw(false); |
282 |
{ |
283 |
adjustHighlightRange(revealStart, revealLength); |
284 |
textViewer.revealRange(revealStart, revealLength); |
285 |
|
286 |
textViewer.setSelectedRange(selectionStart, selectionLength); |
287 |
|
288 |
// markInNavigationHistory(); |
289 |
} |
290 |
widget.setRedraw(true); |
291 |
} |
84 |
|
292 |
|
|
|
293 |
/* |
294 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#adjustHighlightRange(int, int) |
295 |
*/ |
296 |
private void adjustHighlightRange(int offset, int length) { |
297 |
if (textViewer == null) |
298 |
return; |
299 |
|
300 |
if (textViewer instanceof ITextViewerExtension5) { |
301 |
ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer; |
302 |
extension.exposeModelRange(new Region(offset, length)); |
303 |
} else if (!isVisible(textViewer, offset, length)) { |
304 |
textViewer.resetVisibleRegion(); |
305 |
} |
306 |
} |
307 |
|
308 |
/* |
309 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#isVisible(ISourceViewer, int, int) |
310 |
*/ |
311 |
private /*static*/ final boolean isVisible(ITextViewer viewer, int offset, int length) { |
312 |
if (viewer instanceof ITextViewerExtension5) { |
313 |
ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; |
314 |
IRegion overlap= extension.modelRange2WidgetRange(new Region(offset, length)); |
315 |
return overlap != null; |
316 |
} |
317 |
return viewer.overlapsWithVisibleRegion(offset, length); |
318 |
} |
319 |
|
320 |
|
321 |
public void setAction(String actionID, IAction action) { |
322 |
// TODO Auto-generated method stub |
323 |
|
324 |
} |
325 |
|
326 |
public void setActionActivationCode(String actionId, |
327 |
char activationCharacter, int activationKeyCode, |
328 |
int activationStateMask) { |
329 |
// TODO Auto-generated method stub |
330 |
|
331 |
} |
332 |
|
333 |
public void setHighlightRange(int offset, int length, boolean moveCursor) { |
334 |
// TODO Auto-generated method stub |
335 |
|
336 |
} |
337 |
|
338 |
public void showHighlightRangeOnly(boolean showHighlightRangeOnly) { |
339 |
// TODO Auto-generated method stub |
340 |
|
341 |
} |
342 |
|
343 |
public boolean showsHighlightRangeOnly() { |
344 |
// TODO Auto-generated method stub |
345 |
return false; |
346 |
} |
347 |
|
348 |
public IEditorInput getEditorInput() { |
349 |
// TODO Auto-generated method stub |
350 |
return null; |
351 |
} |
352 |
|
353 |
public IEditorSite getEditorSite() { |
354 |
// TODO Auto-generated method stub |
355 |
return null; |
356 |
} |
357 |
|
358 |
public void init(IEditorSite site, IEditorInput input) |
359 |
throws PartInitException { |
360 |
// TODO Auto-generated method stub |
361 |
|
362 |
} |
363 |
|
364 |
public void addPropertyListener(IPropertyListener listener) { |
365 |
// TODO Auto-generated method stub |
366 |
|
367 |
} |
368 |
|
369 |
public void createPartControl(Composite parent) { |
370 |
// TODO Auto-generated method stub |
371 |
|
372 |
} |
373 |
|
374 |
public void dispose() { |
375 |
// TODO Auto-generated method stub |
376 |
|
377 |
} |
378 |
|
379 |
public IWorkbenchPartSite getSite() { |
380 |
return workbenchPart.getSite(); |
381 |
} |
382 |
|
383 |
public String getTitle() { |
384 |
// TODO Auto-generated method stub |
385 |
return null; |
386 |
} |
387 |
|
388 |
public Image getTitleImage() { |
389 |
// TODO Auto-generated method stub |
390 |
return null; |
391 |
} |
392 |
|
393 |
public String getTitleToolTip() { |
394 |
// TODO Auto-generated method stub |
395 |
return null; |
396 |
} |
397 |
|
398 |
public void removePropertyListener(IPropertyListener listener) { |
399 |
// TODO Auto-generated method stub |
400 |
|
401 |
} |
402 |
|
403 |
public void setFocus() { |
404 |
// TODO Auto-generated method stub |
405 |
|
406 |
} |
407 |
|
408 |
public Object getAdapter(Class adapter) { |
409 |
// TODO Auto-generated method stub |
410 |
return null; |
411 |
} |
412 |
|
413 |
public void doSave(IProgressMonitor monitor) { |
414 |
// TODO Auto-generated method stub |
415 |
|
416 |
} |
417 |
|
418 |
public void doSaveAs() { |
419 |
// TODO Auto-generated method stub |
420 |
|
421 |
} |
422 |
|
423 |
public boolean isDirty() { |
424 |
// TODO Auto-generated method stub |
425 |
return false; |
426 |
} |
427 |
|
428 |
public boolean isSaveAsAllowed() { |
429 |
// TODO Auto-generated method stub |
430 |
return false; |
431 |
} |
432 |
|
433 |
public boolean isSaveOnCloseNeeded() { |
434 |
// TODO Auto-generated method stub |
435 |
return false; |
436 |
}} |
437 |
|
85 |
private ResourceBundle fResourceBundle; |
438 |
private ResourceBundle fResourceBundle; |
86 |
private Position fRegion; |
439 |
private Position fRegion; |
87 |
private boolean fEnabled= true; |
440 |
private boolean fEnabled= true; |
Lines 96-101
Link Here
|
96 |
private boolean fShowLineNumber=false; |
449 |
private boolean fShowLineNumber=false; |
97 |
private LineNumberRulerColumn fLineNumberColumn; |
450 |
private LineNumberRulerColumn fLineNumberColumn; |
98 |
private List textActions = new ArrayList(); |
451 |
private List textActions = new ArrayList(); |
|
|
452 |
|
453 |
private TextEditorAdapter fTextEditorAdapter; |
99 |
|
454 |
|
100 |
public MergeSourceViewer(Composite parent, int style, ResourceBundle bundle, ICompareContainer container) { |
455 |
public MergeSourceViewer(Composite parent, int style, ResourceBundle bundle, ICompareContainer container) { |
101 |
super(parent, new CompositeRuler(), style | SWT.H_SCROLL | SWT.V_SCROLL); |
456 |
super(parent, new CompositeRuler(), style | SWT.H_SCROLL | SWT.V_SCROLL); |
Lines 124-129
Link Here
|
124 |
IOperationHistory history = getHistory(); |
479 |
IOperationHistory history = getHistory(); |
125 |
if (history != null) |
480 |
if (history != null) |
126 |
history.addOperationHistoryListener(this); |
481 |
history.addOperationHistoryListener(this); |
|
|
482 |
fTextEditorAdapter = new TextEditorAdapter(this, container.getWorkbenchPart()); |
127 |
} |
483 |
} |
128 |
|
484 |
|
129 |
public void rememberDocument(IDocument doc) { |
485 |
public void rememberDocument(IDocument doc) { |
Lines 453-458
Link Here
|
453 |
menu.add(new Separator("edit")); //$NON-NLS-1$ |
809 |
menu.add(new Separator("edit")); //$NON-NLS-1$ |
454 |
menu.add(new Separator("find")); //$NON-NLS-1$ |
810 |
menu.add(new Separator("find")); //$NON-NLS-1$ |
455 |
addMenu(menu, FIND_ID); |
811 |
addMenu(menu, FIND_ID); |
|
|
812 |
addMenu(menu, GOTO_LINE_ID); |
456 |
|
813 |
|
457 |
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
814 |
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
458 |
|
815 |
|
Lines 648-651
Link Here
|
648 |
return ((IUndoManagerExtension)undoManager).getUndoContext(); |
1005 |
return ((IUndoManagerExtension)undoManager).getUndoContext(); |
649 |
return null; |
1006 |
return null; |
650 |
} |
1007 |
} |
|
|
1008 |
|
1009 |
public ITextEditor getTextEditorAdapter() { |
1010 |
return fTextEditorAdapter; |
1011 |
} |
651 |
} |
1012 |
} |