comparison dwtx/jface/text/TextViewerUndoManager.d @ 156:a9566845f1cb

...
author Frank Benoit <benoit@tionex.de>
date Mon, 25 Aug 2008 19:03:46 +0200
parents eb21d3dfc767
children 1a5b8f8129df
comparison
equal deleted inserted replaced
155:8442b6b2da2d 156:a9566845f1cb
188 * activities in order to partition the stream of text changes into undo-able 188 * activities in order to partition the stream of text changes into undo-able
189 * edit commands. 189 * edit commands.
190 * <p> 190 * <p>
191 * This class is not intended to be subclassed. 191 * This class is not intended to be subclassed.
192 * </p> 192 * </p>
193 * 193 *
194 * @see ITextViewer 194 * @see ITextViewer
195 * @see ITextInputListener 195 * @see ITextInputListener
196 * @see IDocumentUndoManager 196 * @see IDocumentUndoManager
197 * @see MouseListener 197 * @see MouseListener
198 * @see KeyListener 198 * @see KeyListener
199 * @see DocumentUndoManager 199 * @see DocumentUndoManager
200 * 200 *
201 * @since 3.2 201 * @since 3.2
202 * @noextend This class is not intended to be subclassed by clients. 202 * @noextend This class is not intended to be subclassed by clients.
203 */ 203 */
204 public class TextViewerUndoManager : IUndoManager, IUndoManagerExtension { 204 public class TextViewerUndoManager : IUndoManager, IUndoManagerExtension {
205 205
206 206
207 /** 207 /**
208 * Internal listener to mouse and key events. 208 * Internal listener to mouse and key events.
209 */ 209 */
210 private class KeyAndMouseListener : MouseListener, KeyListener { 210 private class KeyAndMouseListener : MouseListener, KeyListener {
211 211
285 /* 285 /*
286 * @see dwtx.jface.text.IDocumentUndoListener#documentUndoNotification(DocumentUndoEvent) 286 * @see dwtx.jface.text.IDocumentUndoListener#documentUndoNotification(DocumentUndoEvent)
287 */ 287 */
288 public void documentUndoNotification(DocumentUndoEvent event ){ 288 public void documentUndoNotification(DocumentUndoEvent event ){
289 if (!isConnected()) return; 289 if (!isConnected()) return;
290 290
291 int eventType= event.getEventType(); 291 int eventType= event.getEventType();
292 if (((eventType & DocumentUndoEvent.ABOUT_TO_UNDO) !is 0) || ((eventType & DocumentUndoEvent.ABOUT_TO_REDO) !is 0)) { 292 if (((eventType & DocumentUndoEvent.ABOUT_TO_UNDO) !is 0) || ((eventType & DocumentUndoEvent.ABOUT_TO_REDO) !is 0)) {
293 if (event.isCompound()) { 293 if (event.isCompound()) {
294 ITextViewerExtension extension= null; 294 ITextViewerExtension extension= null;
295 if ( cast(ITextViewerExtension)fTextViewer ) 295 if ( cast(ITextViewerExtension)fTextViewer )
302 public void run() { 302 public void run() {
303 if ( cast(TextViewer)fTextViewer ) 303 if ( cast(TextViewer)fTextViewer )
304 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(true); 304 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(true);
305 } 305 }
306 }); 306 });
307 307
308 } else if (((eventType & DocumentUndoEvent.UNDONE) !is 0) || ((eventType & DocumentUndoEvent.REDONE) !is 0)) { 308 } else if (((eventType & DocumentUndoEvent.UNDONE) !is 0) || ((eventType & DocumentUndoEvent.REDONE) !is 0)) {
309 fTextViewer.getTextWidget().getDisplay().syncExec(new class() Runnable { 309 fTextViewer.getTextWidget().getDisplay().syncExec(new class() Runnable {
310 public void run() { 310 public void run() {
311 if ( cast(TextViewer)fTextViewer ) 311 if ( cast(TextViewer)fTextViewer )
312 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(false); 312 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(false);
318 extension= cast(ITextViewerExtension) fTextViewer; 318 extension= cast(ITextViewerExtension) fTextViewer;
319 319
320 if (extension !is null) 320 if (extension !is null)
321 extension.setRedraw(true); 321 extension.setRedraw(true);
322 } 322 }
323 323
324 // Reveal the change if this manager's viewer has the focus. 324 // Reveal the change if this manager's viewer has the focus.
325 if (fTextViewer !is null) { 325 if (fTextViewer !is null) {
326 StyledText widget= fTextViewer.getTextWidget(); 326 StyledText widget= fTextViewer.getTextWidget();
327 if (widget !is null && !widget.isDisposed() && (widget.isFocusControl()))// || fTextViewer.getTextWidget() is control)) 327 if (widget !is null && !widget.isDisposed() && (widget.isFocusControl()))// || fTextViewer.getTextWidget() is control))
328 selectAndReveal(event.getOffset(), event.getText() is null ? 0 : event.getText().length()); 328 selectAndReveal(event.getOffset(), event.getText() is null ? 0 : event.getText().length());
338 private TextInputListener fTextInputListener; 338 private TextInputListener fTextInputListener;
339 339
340 340
341 /** The text viewer the undo manager is connected to */ 341 /** The text viewer the undo manager is connected to */
342 private ITextViewer fTextViewer; 342 private ITextViewer fTextViewer;
343 343
344 /** The undo level */ 344 /** The undo level */
345 private int fUndoLevel; 345 private int fUndoLevel;
346 346
347 /** The document undo manager that is active. */ 347 /** The document undo manager that is active. */
348 private IDocumentUndoManager fDocumentUndoManager; 348 private IDocumentUndoManager fDocumentUndoManager;
349 349
350 /** The document that is active. */ 350 /** The document that is active. */
351 private IDocument fDocument; 351 private IDocument fDocument;
352 352
353 /** The document undo listener */ 353 /** The document undo listener */
354 private IDocumentUndoListener fDocumentUndoListener; 354 private IDocumentUndoListener fDocumentUndoListener;
355 355
356 /** 356 /**
357 * Creates a new undo manager who remembers the specified number of edit commands. 357 * Creates a new undo manager who remembers the specified number of edit commands.
426 * Shows the given exception in an error dialog. 426 * Shows the given exception in an error dialog.
427 * 427 *
428 * @param title the dialog title 428 * @param title the dialog title
429 * @param ex the exception 429 * @param ex the exception
430 */ 430 */
431 private void openErrorDialog(final String title, final Exception ex) { 431 private void openErrorDialog(String title, Exception ex) {
432 Shell shell= null; 432 Shell shell= null;
433 if (isConnected()) { 433 if (isConnected()) {
434 StyledText st= fTextViewer.getTextWidget(); 434 StyledText st= fTextViewer.getTextWidget();
435 if (st !is null && !st.isDisposed()) 435 if (st !is null && !st.isDisposed())
436 shell= st.getShell(); 436 shell= st.getShell();
437 } 437 }
438 if (Display.getCurrent() !is null) 438 if (Display.getCurrent() !is null)
439 MessageDialog.openError(shell, title, ex.getLocalizedMessage()); 439 MessageDialog.openError(shell, title, ex.getLocalizedMessage());
440 else { 440 else {
441 Display display; 441 Display display;
442 final Shell finalShell= shell; 442 Shell finalShell= shell;
443 if (finalShell !is null) 443 if (finalShell !is null)
444 display= finalShell.getDisplay(); 444 display= finalShell.getDisplay();
445 else 445 else
446 display= Display.getDefault(); 446 display= Display.getDefault();
447 display.syncExec(new class() Runnable { 447 display.syncExec(dgRunnable((Shell finalShell_, String title_, Exception ex_ ) {
448 public void run() { 448 MessageDialog.openError(finalShell_, title_, ex_.getLocalizedMessage());
449 MessageDialog.openError(finalShell, title, ex.getLocalizedMessage()); 449 },finalShell, title, ex ));
450 }
451 });
452 } 450 }
453 } 451 }
454 452
455 /* 453 /*
456 * @see dwtx.jface.text.IUndoManager#setMaximalUndoLevel(int) 454 * @see dwtx.jface.text.IUndoManager#setMaximalUndoLevel(int)
489 * @see dwtx.jface.text.IUndoManager#reset() 487 * @see dwtx.jface.text.IUndoManager#reset()
490 */ 488 */
491 public void reset() { 489 public void reset() {
492 if (isConnected()) 490 if (isConnected())
493 fDocumentUndoManager.reset(); 491 fDocumentUndoManager.reset();
494 492
495 } 493 }
496 494
497 /* 495 /*
498 * @see dwtx.jface.text.IUndoManager#redoable() 496 * @see dwtx.jface.text.IUndoManager#redoable()
499 */ 497 */
562 if (isConnected()) { 560 if (isConnected()) {
563 return fDocumentUndoManager.getUndoContext(); 561 return fDocumentUndoManager.getUndoContext();
564 } 562 }
565 return null; 563 return null;
566 } 564 }
567 565
568 private void connectDocumentUndoManager(IDocument document) { 566 private void connectDocumentUndoManager(IDocument document) {
569 disconnectDocumentUndoManager(); 567 disconnectDocumentUndoManager();
570 if (document !is null) { 568 if (document !is null) {
571 fDocument= document; 569 fDocument= document;
572 DocumentUndoManagerRegistry.connect(fDocument); 570 DocumentUndoManagerRegistry.connect(fDocument);