Mercurial > projects > dwt-addons
diff dwtx/jface/text/link/LinkedModeUI.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | f70d9508c95c |
children |
line wrap: on
line diff
--- a/dwtx/jface/text/link/LinkedModeUI.d Wed Aug 27 14:49:30 2008 +0200 +++ b/dwtx/jface/text/link/LinkedModeUI.d Mon Sep 08 00:51:37 2008 +0200 @@ -100,17 +100,47 @@ * Constant indicating that this UI should never cycle from the last * position to the first and vice versa. */ - public static const Object CYCLE_NEVER= new Object(); + public static Object CYCLE_NEVER_; + public static Object CYCLE_NEVER(){ + if( CYCLE_NEVER_ is null ){ + synchronized( LinkedModeUI.classinfo ){ + if( CYCLE_NEVER_ is null ){ + CYCLE_NEVER_ = new Object(); + } + } + } + return CYCLE_NEVER_; + } /** * Constant indicating that this UI should always cycle from the last * position to the first and vice versa. */ - public static const Object CYCLE_ALWAYS= new Object(); + public static Object CYCLE_ALWAYS_; + public static Object CYCLE_ALWAYS(){ + if( CYCLE_ALWAYS_ is null ){ + synchronized( LinkedModeUI.classinfo ){ + if( CYCLE_ALWAYS_ is null ){ + CYCLE_ALWAYS_ = new Object(); + } + } + } + return CYCLE_ALWAYS_; + } /** * Constant indicating that this UI should cycle from the last position to * the first and vice versa if its model is not nested. */ - public static const Object CYCLE_WHEN_NO_PARENT= new Object(); + public static Object CYCLE_WHEN_NO_PARENT_; + public static Object CYCLE_WHEN_NO_PARENT(){ + if( CYCLE_WHEN_NO_PARENT_ is null ){ + synchronized( LinkedModeUI.classinfo ){ + if( CYCLE_WHEN_NO_PARENT_ is null ){ + CYCLE_WHEN_NO_PARENT_ = new Object(); + } + } + } + return CYCLE_WHEN_NO_PARENT_; + } /** * Listener that gets notified when the linked mode UI switches its focus position. @@ -192,7 +222,7 @@ * @param viewer the viewer */ public this(ITextViewer viewer) { - Assert.isNotNull(viewer); + Assert.isNotNull(cast(Object)viewer); fTextViewer= viewer; } @@ -332,7 +362,7 @@ // focus away. StyledText text; - final ITextViewer viewer; + ITextViewer viewer; Display display; if (fCurrentTarget is null || (text= fCurrentTarget.fWidget) is null @@ -345,21 +375,19 @@ else { // Post in UI thread since the assistant popup will only get the focus after we lose it. - display.asyncExec(new class() Runnable { - public void run() { - if (fIsActive && cast(IEditingSupportRegistry)viewer ) { - IEditingSupport[] helpers= (cast(IEditingSupportRegistry) viewer).getRegisteredSupports(); - for (int i= 0; i < helpers.length; i++) { - if (helpers[i].ownsFocusShell()) - return; - } + display.asyncExec(dgRunnable( (ITextViewer viewer_) { + if (fIsActive && cast(IEditingSupportRegistry)viewer_ ) { + IEditingSupport[] helpers= (cast(IEditingSupportRegistry) viewer_).getRegisteredSupports(); + for (int i= 0; i < helpers.length; i++) { + if (helpers[i].ownsFocusShell()) + return; } + } - // else - leave(ILinkedModeListener.EXIT_ALL); + // else + leave(ILinkedModeListener.EXIT_ALL); - } - }); + }, viewer )); } } @@ -587,23 +615,23 @@ /* Our team of event listeners */ /** The shell listener. */ - private Closer fCloser= new Closer(); + private Closer fCloser; /** The linked mode listener. */ - private ILinkedModeListener fLinkedListener= new ExitListener(); + private ILinkedModeListener fLinkedListener; /** The selection listener. */ - private MySelectionListener fSelectionListener= new MySelectionListener(); + private MySelectionListener fSelectionListener; /** The content assist listener. */ - private ProposalListener fProposalListener= new ProposalListener(); + private ProposalListener fProposalListener; /** * The document listener. * @since 3.1 */ - private IDocumentListener fDocumentListener= new DocumentListener(); + private IDocumentListener fDocumentListener; /** The last caret position, used by fCaretListener. */ - private const Position fCaretPosition= new Position(0, 0); + private const Position fCaretPosition; /** The exit policy to control custom exit behavior */ - private IExitPolicy fExitPolicy= new NullExitPolicy(); + private IExitPolicy fExitPolicy; /** The current frame position shown in the UI, or <code>null</code>. */ private LinkedPosition fFramePosition; /** The last visited position, used for undo / redo. */ @@ -615,28 +643,29 @@ /** State indicator to prevent multiple invocation of leave. */ private bool fIsActive= false; /** The position updater for the exit position. */ - private IPositionUpdater fPositionUpdater= new DefaultPositionUpdater(getCategory()); + private IPositionUpdater fPositionUpdater; /** Whether to show context info. */ private bool fDoContextInfo= false; /** Whether we have begun a compound change, but not yet closed. */ private bool fHasOpenCompoundChange= false; /** The position listener. */ - private ILinkedModeUIFocusListener fPositionListener= new EmtpyFocusListener(); - private IAutoEditStrategy fAutoEditVetoer= new class() IAutoEditStrategy { + private ILinkedModeUIFocusListener fPositionListener; + private IAutoEditStrategy fAutoEditVetoer; + private void fAutoEditVetoer_init(){ + fAutoEditVetoer = new class() IAutoEditStrategy { + /* + * @see dwtx.jface.text.IAutoEditStrategy#customizeDocumentCommand(dwtx.jface.text.IDocument, dwtx.jface.text.DocumentCommand) + */ + public void customizeDocumentCommand(IDocument document, DocumentCommand command) { + // invalidate the change to ensure that the change is performed on the document only. + if (fModel.anyPositionContains(command.offset)) { + command.doit= false; + command.caretOffset= command.offset + command.length; + } - /* - * @see dwtx.jface.text.IAutoEditStrategy#customizeDocumentCommand(dwtx.jface.text.IDocument, dwtx.jface.text.DocumentCommand) - */ - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { - // invalidate the change to ensure that the change is performed on the document only. - if (fModel.anyPositionContains(command.offset)) { - command.doit= false; - command.caretOffset= command.offset + command.length; } - - } - }; - + }; + } /** Whether this UI is in simple highlighting mode or not. */ private bool fSimple; @@ -647,6 +676,19 @@ */ private bool fIsColoredLabelsSupportEnabled= false; + private this(){ + fCloser= new Closer(); + fLinkedListener= new ExitListener(); + fSelectionListener= new MySelectionListener(); + fProposalListener= new ProposalListener(); + fDocumentListener= new DocumentListener(); + fCaretPosition= new Position(0, 0); + fExitPolicy= new NullExitPolicy(); + fPositionUpdater= new DefaultPositionUpdater(getCategory()); + fPositionListener= new EmtpyFocusListener(); + fAutoEditVetoer_init(); + } + /** * Creates a new UI on the given model and the set of viewers. The model * must provide a tab stop sequence with a non-empty list of tab stops. @@ -656,6 +698,7 @@ * UI should act */ public this(LinkedModeModel model, LinkedModeUITarget[] targets) { + this(); constructor(model, targets); } @@ -666,6 +709,7 @@ * @param viewer the viewer upon which the linked mode UI should act */ public this(LinkedModeModel model, ITextViewer viewer) { + this(); constructor(model, [new EmptyTarget(viewer)]); } @@ -677,6 +721,7 @@ * UI should act */ public this(LinkedModeModel model, ITextViewer[] viewers) { + this(); LinkedModeUITarget[] array= new LinkedModeUITarget[viewers.length]; for (int i= 0; i < array.length; i++) { array[i]= new EmptyTarget(viewers[i]); @@ -691,6 +736,7 @@ * @param target the target upon which the linked mode UI should act */ public this(LinkedModeModel model, LinkedModeUITarget target) { + this(); constructor(model, [target]); } @@ -703,7 +749,7 @@ */ private void constructor(LinkedModeModel model, LinkedModeUITarget[] targets) { Assert.isNotNull(model); - Assert.isNotNull(targets); + //Assert.isNotNull(targets); Assert.isTrue(targets.length > 0); Assert.isTrue(model.getTabStopSequence().size() > 0); @@ -799,7 +845,7 @@ */ public void setCyclingMode(Object mode) { if (mode !is CYCLE_ALWAYS && mode !is CYCLE_NEVER && mode !is CYCLE_WHEN_NO_PARENT) - throw new IllegalArgumentException(); + throw new IllegalArgumentException(null); if (mode is CYCLE_ALWAYS || mode is CYCLE_WHEN_NO_PARENT && !fModel.isNested()) fIterator.setCycling(true); @@ -847,7 +893,7 @@ fAssistant.hidePossibleCompletions(); } - private void switchPosition(LinkedPosition pos, bool select, bool showProposals) { + private void switchPosition(LinkedPosition pos, bool select_, bool showProposals) { Assert.isNotNull(pos); if (pos.equals(fFramePosition)) return; @@ -865,7 +911,7 @@ switchViewer(oldDoc, newDoc, pos); fFramePosition= pos; - if (select) + if (select_) select(); if (fFramePosition is fExitPosition && !fIterator.isCycling()) leave(ILinkedModeListener.NONE); @@ -892,9 +938,9 @@ IAnnotationModel model= sv.getAnnotationModel(); if ( cast(IAnnotationModelExtension)model ) { IAnnotationModelExtension ext= cast(IAnnotationModelExtension) model; - IAnnotationModel ourModel= ext.getAnnotationModel(getUniqueKey()); + IAnnotationModel ourModel= ext.getAnnotationModel(stringcast(getUniqueKey())); if (ourModel is null) { - ext.addAnnotationModel(getUniqueKey(), lpa); + ext.addAnnotationModel(stringcast(getUniqueKey()), lpa); } } } @@ -908,7 +954,7 @@ IAnnotationModel model= sv.getAnnotationModel(); if ( cast(IAnnotationModelExtension)model ) { IAnnotationModelExtension ext= cast(IAnnotationModelExtension) model; - ext.removeAnnotationModel(getUniqueKey()); + ext.removeAnnotationModel(stringcast(getUniqueKey())); } } } @@ -959,7 +1005,7 @@ private void connect() { Assert.isNotNull(fCurrentTarget); ITextViewer viewer= fCurrentTarget.getViewer(); - Assert.isNotNull(viewer); + Assert.isNotNull(cast(Object)viewer); fCurrentTarget.fWidget= viewer.getTextWidget(); if (fCurrentTarget.fWidget is null) leave(ILinkedModeListener.EXIT_ALL); @@ -1072,10 +1118,10 @@ String[] partitionings= ext.getPartitionings(); Set contentTypes= new HashSet(20); for (int i= 0; i < partitionings.length; i++) { - contentTypes.addAll(Arrays.asList(ext.getLegalContentTypes(partitionings[i]))); + contentTypes.addAll(Arrays.asList(stringcast(ext.getLegalContentTypes(partitionings[i])))); } contentTypes.add(IDocument.DEFAULT_CONTENT_TYPE); - return (String[]) contentTypes.toArray(new String[contentTypes.size()]); + return stringcast( contentTypes.toArray()); } return document.getLegalContentTypes(); } @@ -1097,13 +1143,13 @@ } private String getUniqueKey() { - return "linked.annotationmodelkey."+toString(); //$NON-NLS-1$ + return "linked.annotationmodelkey."~toString(); //$NON-NLS-1$ } private void disconnect() { Assert.isNotNull(fCurrentTarget); ITextViewer viewer= fCurrentTarget.getViewer(); - Assert.isNotNull(viewer); + Assert.isNotNull(cast(Object)viewer); viewer.getDocument().removeDocumentListener(fDocumentListener); @@ -1135,7 +1181,7 @@ redraw(); } - void leave(final int flags) { + void leave(int flags) { if (!fIsActive) return; fIsActive= false; @@ -1180,37 +1226,35 @@ for (int i= 0; i < fTargets.length; i++) { IDocument doc= fTargets[i].getViewer().getDocument(); if (doc !is null) - docs.add(doc); + docs.add(cast(Object)doc); } fModel.stopForwarding(flags); - Runnable runnable= new class() Runnable { - public void run() { - if (fExitPosition !is null) - fExitPosition.getDocument().removePosition(fExitPosition); + Runnable runnable= dgRunnable( (int flags_){ + if (fExitPosition !is null) + fExitPosition.getDocument().removePosition(fExitPosition); - for (Iterator iter = docs.iterator(); iter.hasNext(); ) { - IDocument doc= cast(IDocument) iter.next(); - doc.removePositionUpdater(fPositionUpdater); - bool uninstallCat= false; - String[] cats= doc.getPositionCategories(); - for (int j= 0; j < cats.length; j++) { - if (getCategory().equals(cats[j])) { - uninstallCat= true; - break; - } + for (Iterator iter = docs.iterator(); iter.hasNext(); ) { + IDocument doc= cast(IDocument) iter.next(); + doc.removePositionUpdater(fPositionUpdater); + bool uninstallCat= false; + String[] cats= doc.getPositionCategories(); + for (int j= 0; j < cats.length; j++) { + if (getCategory().equals(cats[j])) { + uninstallCat= true; + break; } - if (uninstallCat) - try { - doc.removePositionCategory(getCategory()); - } catch (BadPositionCategoryException e) { - // ignore - } } - fModel.exit(flags); + if (uninstallCat) + try { + doc.removePositionCategory(getCategory()); + } catch (BadPositionCategoryException e) { + // ignore + } } - }; + fModel.exit(flags_); + }, flags ); // remove positions (both exit positions AND linked positions in the // model) asynchronously to make sure that the annotation painter @@ -1278,7 +1322,7 @@ * @param listener the new listener, never <code>null</code>. */ protected void setPositionListener(ILinkedModeUIFocusListener listener) { - Assert.isNotNull(listener); + Assert.isNotNull(cast(Object)listener); fPositionListener= listener; }