|
From: Christopher W. <caw...@us...> - 2006-02-10 20:14:45
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19287/src/org/rubypeople/rdt/internal/ui/rubyeditor Modified Files: ExternalRubyDocumentProvider.java GotoAnnotationAction.java RubyEditorActionContributor.java RubyAbstractEditor.java RubyEditor.java RubyDocumentSetupParticipant.java ExternalRubyEditor.java RubySourceViewer.java Added Files: RubyOutlinePage.java TogglePresentationAction.java Log Message: Index: RubyDocumentSetupParticipant.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyDocumentSetupParticipant.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RubyDocumentSetupParticipant.java 2 Mar 2005 00:54:29 -0000 1.2 --- RubyDocumentSetupParticipant.java 10 Feb 2006 20:14:31 -0000 1.3 *************** *** 29,33 **** */ public void setup(IDocument document) { ! RubyTextTools tools= RubyPlugin.getDefault().getTextTools(); tools.setupRubyDocumentPartitioner(document, IRubyPartitions.RUBY_PARTITIONING); } --- 29,33 ---- */ public void setup(IDocument document) { ! RubyTextTools tools= RubyPlugin.getDefault().getRubyTextTools(); tools.setupRubyDocumentPartitioner(document, IRubyPartitions.RUBY_PARTITIONING); } Index: RubySourceViewer.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RubySourceViewer.java 18 Sep 2005 15:17:42 -0000 1.4 --- RubySourceViewer.java 10 Feb 2006 20:14:31 -0000 1.5 *************** *** 7,31 **** package org.rubypeople.rdt.internal.ui.rubyeditor; import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.IVerticalRuler; import org.eclipse.jface.text.source.projection.ProjectionViewer; import org.eclipse.swt.widgets.Composite; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.ui.PreferenceConstants; ! /* Copied from Ant StatusLineSourceViewer */ ! public class RubySourceViewer extends ProjectionViewer { private boolean isTabReplacing = false; private boolean fIgnoreTextConverters = false; private TabExpander tabExpander; public RubySourceViewer(Composite composite, IVerticalRuler verticalRuler, ! IOverviewRuler overviewRuler, boolean overviewRulerVisible, int styles) { super(composite, verticalRuler, overviewRuler, overviewRulerVisible, styles); initializeTabReplace(); } public void doOperation(int operation) { --- 7,248 ---- package org.rubypeople.rdt.internal.ui.rubyeditor; + import org.eclipse.jface.preference.IPreferenceStore; + import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.IVerticalRuler; + import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.text.source.projection.ProjectionViewer; + import org.eclipse.jface.util.IPropertyChangeListener; + import org.eclipse.jface.util.PropertyChangeEvent; + import org.eclipse.swt.custom.StyledText; + import org.eclipse.swt.graphics.Color; + import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; + import org.eclipse.swt.widgets.Display; + import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; + import org.eclipse.ui.texteditor.AbstractTextEditor; + import org.rubypeople.rdt.core.RubyCore; + import org.rubypeople.rdt.core.formatter.DefaultCodeFormatterConstants; + import org.rubypeople.rdt.core.formatter.Indents; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.ui.PreferenceConstants; ! public class RubySourceViewer extends ProjectionViewer implements IPropertyChangeListener { private boolean isTabReplacing = false; private boolean fIgnoreTextConverters = false; private TabExpander tabExpander; + + /** + * This viewer's foreground color. + * @since 0.8.0 + */ + private Color fForegroundColor; + /** + * The viewer's background color. + * @since 0.8.0 + */ + private Color fBackgroundColor; + /** + * This viewer's selection foreground color. + * @since 0.8.0 + */ + private Color fSelectionForegroundColor; + /** + * The viewer's selection background color. + * @since 0.8.0 + */ + private Color fSelectionBackgroundColor; + + /** + * The preference store. + * + * @since 0.8.0 + */ + private IPreferenceStore fPreferenceStore; + + /** + * Is this source viewer configured? + * + * @since 0.8.0 + */ + private boolean fIsConfigured; public RubySourceViewer(Composite composite, IVerticalRuler verticalRuler, ! IOverviewRuler overviewRuler, boolean overviewRulerVisible, int styles, IPreferenceStore store) { super(composite, verticalRuler, overviewRuler, overviewRulerVisible, styles); + setPreferenceStore(store); initializeTabReplace(); } + + /** + * Sets the preference store on this viewer. + * + * @param store the preference store + * + * @since 0.8.0 + */ + public void setPreferenceStore(IPreferenceStore store) { + if (fIsConfigured && fPreferenceStore != null) + fPreferenceStore.removePropertyChangeListener(this); + + fPreferenceStore= store; + + if (fIsConfigured && fPreferenceStore != null) { + fPreferenceStore.addPropertyChangeListener(this); + initializeViewerColors(); + } + } + + protected void initializeViewerColors() { + if (fPreferenceStore != null) { + + StyledText styledText= getTextWidget(); + + // ----------- foreground color -------------------- + Color color= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) + ? null + : createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay()); + styledText.setForeground(color); + + if (fForegroundColor != null) + fForegroundColor.dispose(); + + fForegroundColor= color; + + // ---------- background color ---------------------- + color= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) + ? null + : createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay()); + styledText.setBackground(color); + + if (fBackgroundColor != null) + fBackgroundColor.dispose(); + + fBackgroundColor= color; + + // ----------- selection foreground color -------------------- + color= fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR) + ? null + : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, styledText.getDisplay()); + styledText.setSelectionForeground(color); + + if (fSelectionForegroundColor != null) + fSelectionForegroundColor.dispose(); + + fSelectionForegroundColor= color; + + // ---------- selection background color ---------------------- + color= fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR) + ? null + : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, styledText.getDisplay()); + styledText.setSelectionBackground(color); + + if (fSelectionBackgroundColor != null) + fSelectionBackgroundColor.dispose(); + + fSelectionBackgroundColor= color; + } + } + + /* + * @see ISourceViewer#configure(SourceViewerConfiguration) + */ + public void configure(SourceViewerConfiguration configuration) { + + /* + * Prevent access to colors disposed in unconfigure(), see: + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641 + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177 + */ + StyledText textWidget= getTextWidget(); + if (textWidget != null && !textWidget.isDisposed()) { + Color foregroundColor= textWidget.getForeground(); + if (foregroundColor != null && foregroundColor.isDisposed()) + textWidget.setForeground(null); + Color backgroundColor= textWidget.getBackground(); + if (backgroundColor != null && backgroundColor.isDisposed()) + textWidget.setBackground(null); + } + + super.configure(configuration); + + if (fPreferenceStore != null) { + fPreferenceStore.addPropertyChangeListener(this); + initializeViewerColors(); + } + + fIsConfigured= true; + } + + /* + * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure() + * @since 0.8.0 + */ + public void unconfigure() { + if (fForegroundColor != null) { + fForegroundColor.dispose(); + fForegroundColor= null; + } + if (fBackgroundColor != null) { + fBackgroundColor.dispose(); + fBackgroundColor= null; + } + + if (fPreferenceStore != null) + fPreferenceStore.removePropertyChangeListener(this); + + super.unconfigure(); + + fIsConfigured= false; + } + + /* + * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent event) { + String property = event.getProperty(); + if (AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND.equals(property) + || AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) + || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND.equals(property) + || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) + || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR.equals(property) + || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR.equals(property) + || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR.equals(property) + || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR.equals(property)) + { + initializeViewerColors(); + } + } + + /** + * Creates a color from the information stored in the given preference store. + * Returns <code>null</code> if there is no such information available. + * + * @param store the store to read from + * @param key the key used for the lookup in the preference store + * @param display the display used create the color + * @return the created color according to the specification in the preference store + * @since 3.0 + */ + private Color createColor(IPreferenceStore store, String key, Display display) { + + RGB rgb= null; + + if (store.contains(key)) { + + if (store.isDefault(key)) + rgb= PreferenceConverter.getDefaultColor(store, key); + else + rgb= PreferenceConverter.getColor(store, key); + + if (rgb != null) + return new Color(display, rgb); + } + + return null; + } public void doOperation(int operation) { *************** *** 56,61 **** PreferenceConstants.FORMAT_USE_TAB); if (this.isTabReplacing) { ! int length = RubyPlugin.getDefault().getPreferenceStore().getInt( ! PreferenceConstants.FORMAT_INDENTATION); tabExpander = new TabExpander(length); } --- 273,277 ---- PreferenceConstants.FORMAT_USE_TAB); if (this.isTabReplacing) { ! int length = Indents.getTabWidth(RubyCore.getOptions()); tabExpander = new TabExpander(length); } *************** *** 77,79 **** --- 293,296 ---- return tabExpander.getFullIndent(); } + } Index: RubyEditorActionContributor.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RubyEditorActionContributor.java 18 Sep 2005 15:17:42 -0000 1.9 --- RubyEditorActionContributor.java 10 Feb 2006 20:14:31 -0000 1.10 *************** *** 6,14 **** import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchActionConstants; - import org.eclipse.ui.IWorkbenchPage; - import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; import org.eclipse.ui.texteditor.ITextEditor; - import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.RetargetTextEditorAction; import org.rubypeople.rdt.internal.ui.RubyUIMessages; --- 6,11 ---- *************** *** 16,69 **** public class RubyEditorActionContributor extends BasicTextEditorActionContributor { - protected RetargetTextEditorAction contentAssistProposal; - private GotoAnnotationAction fPreviousAnnotation; - private GotoAnnotationAction fNextAnnotation; ! public RubyEditorActionContributor() { ! super(); ! contentAssistProposal = new RetargetTextEditorAction(RubyUIMessages.getResourceBundle(), "ContentAssistProposal."); ! ! fPreviousAnnotation= new GotoAnnotationAction("PreviousAnnotation.", false); //$NON-NLS-1$ ! fNextAnnotation= new GotoAnnotationAction("NextAnnotation.", true); //$NON-NLS-1$ ! } ! public void contributeToMenu(IMenuManager menuManager) { ! IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); ! if (editMenu != null) { ! editMenu.add(new Separator()); ! editMenu.add(contentAssistProposal); ! } ! } ! public void setActiveEditor(IEditorPart part) { ! super.setActiveEditor(part); ! ITextEditor editor = null; ! if (part instanceof ITextEditor) ! editor = (ITextEditor) part; ! contentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); ! IActionBars bars= getActionBars(); ! bars.setGlobalActionHandler(RubyActionIds.COMMENT, getAction(editor, "Comment")); ! bars.setGlobalActionHandler(RubyActionIds.UNCOMMENT, getAction(editor, "Uncomment")); ! ! fPreviousAnnotation.setEditor(editor); ! fNextAnnotation.setEditor(editor); ! } ! ! /* ! * @see IEditorActionBarContributor#init(IActionBars, IWorkbenchPage) ! */ ! public void init(IActionBars bars, IWorkbenchPage page) { ! super.init(bars, page); ! ! // register actions that have a dynamic editor. ! bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation); ! bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation); ! bars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNextAnnotation); ! bars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPreviousAnnotation); ! } } --- 13,45 ---- public class RubyEditorActionContributor extends BasicTextEditorActionContributor { ! protected RetargetTextEditorAction contentAssistProposal; ! public RubyEditorActionContributor() { ! super(); ! contentAssistProposal = new RetargetTextEditorAction(RubyUIMessages.getResourceBundle(), ! "ContentAssistProposal."); ! } ! public void contributeToMenu(IMenuManager menuManager) { ! IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); ! if (editMenu != null) { ! editMenu.add(new Separator()); ! editMenu.add(contentAssistProposal); ! } ! } ! public void setActiveEditor(IEditorPart part) { ! super.setActiveEditor(part); ! ITextEditor editor = null; ! if (part instanceof ITextEditor) editor = (ITextEditor) part; ! contentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); ! IActionBars bars = getActionBars(); ! bars.setGlobalActionHandler(RubyActionIds.COMMENT, getAction(editor, "Comment")); ! bars.setGlobalActionHandler(RubyActionIds.UNCOMMENT, getAction(editor, "Uncomment")); ! } } Index: GotoAnnotationAction.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/GotoAnnotationAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GotoAnnotationAction.java 11 Mar 2005 03:21:14 -0000 1.3 --- GotoAnnotationAction.java 10 Feb 2006 20:14:31 -0000 1.4 *************** *** 11,18 **** package org.rubypeople.rdt.internal.ui.rubyeditor; ! import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; - import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds; --- 11,17 ---- package org.rubypeople.rdt.internal.ui.rubyeditor; ! import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds; *************** *** 26,36 **** fForward= forward; if (forward) { ! WorkbenchHelp.setHelp(this, IRubyHelpContextIds.GOTO_NEXT_ERROR_ACTION); ! // FIXME Uncomment and delete the above line when we move to 3.1+ ! //PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.GOTO_NEXT_ERROR_ACTION); } else { ! WorkbenchHelp.setHelp(this, IRubyHelpContextIds.GOTO_PREVIOUS_ERROR_ACTION); ! // FIXME Uncomment and delete the above line when we move to 3.1+ ! //PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.GOTO_PREVIOUS_ERROR_ACTION); } } --- 25,31 ---- fForward= forward; if (forward) { ! PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.GOTO_NEXT_ERROR_ACTION); } else { ! PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.GOTO_PREVIOUS_ERROR_ACTION); } } Index: RubyEditor.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** RubyEditor.java 12 Mar 2005 16:52:13 -0000 1.36 --- RubyEditor.java 10 Feb 2006 20:14:31 -0000 1.37 *************** *** 14,21 **** import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; - import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadPositionCategoryException; --- 14,21 ---- import org.eclipse.core.runtime.IStatus; [...1847 lines suppressed...] ! return unit.getElementAt(offset); ! ! } catch (RubyModelException x) { ! if (!x.isDoesNotExist()) ! RubyPlugin.log(x.getStatus()); ! // nothing found, be tolerant and go on ! } ! } ! ! return null; ! } ! ! /* ! * @see RubyEditor#getElementAt(int) ! */ ! protected IRubyElement getElementAt(int offset) { ! return getElementAt(offset, true); ! } } \ No newline at end of file --- NEW FILE: TogglePresentationAction.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.rubyeditor; import org.eclipse.jface.action.IAction; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.RubyPluginImages; import org.rubypeople.rdt.ui.IWorkingCopyManager; import org.rubypeople.rdt.ui.PreferenceConstants; /** * A tool bar action which toggles the presentation model of the * connected text editor. The editor shows either the highlight range * only or always the whole document. */ public class TogglePresentationAction extends TextEditorAction implements IPropertyChangeListener { private IPreferenceStore fStore; /** * Constructs and updates the action. */ public TogglePresentationAction() { super(RubyEditorMessages.getBundleForConstructedKeys(), "TogglePresentation.", null, IAction.AS_CHECK_BOX); //$NON-NLS-1$ RubyPluginImages.setToolImageDescriptors(this, "segment_edit.gif"); //$NON-NLS-1$ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.TOGGLE_PRESENTATION_ACTION); update(); } /* * @see IAction#actionPerformed */ public void run() { ITextEditor editor= getTextEditor(); if (editor == null) return; IRegion remembered= editor.getHighlightRange(); editor.resetHighlightRange(); boolean showAll= !editor.showsHighlightRangeOnly(); setChecked(showAll); editor.showHighlightRangeOnly(showAll); if (remembered != null) editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true); fStore.removePropertyChangeListener(this); fStore.setValue(PreferenceConstants.EDITOR_SHOW_SEGMENTS, showAll); fStore.addPropertyChangeListener(this); } /* * @see TextEditorAction#update */ public void update() { ITextEditor editor= getTextEditor(); boolean checked= (editor != null && editor.showsHighlightRangeOnly()); setChecked(checked); if (editor instanceof RubyEditor) { IWorkingCopyManager manager= RubyPlugin.getDefault().getWorkingCopyManager(); setEnabled(manager.getWorkingCopy(editor.getEditorInput()) != null); } else setEnabled(editor != null); } /* * @see TextEditorAction#setEditor(ITextEditor) */ public void setEditor(ITextEditor editor) { super.setEditor(editor); if (editor != null) { if (fStore == null) { fStore= RubyPlugin.getDefault().getPreferenceStore(); fStore.addPropertyChangeListener(this); } synchronizeWithPreference(editor); } else if (fStore != null) { fStore.removePropertyChangeListener(this); fStore= null; } update(); } /** * Synchronizes the appearance of the editor with what the preference store tells him. * * @param editor the text editor */ private void synchronizeWithPreference(ITextEditor editor) { if (editor == null) return; boolean showSegments= fStore.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS); setChecked(showSegments); if (editor.showsHighlightRangeOnly() != showSegments) { IRegion remembered= editor.getHighlightRange(); editor.resetHighlightRange(); editor.showHighlightRangeOnly(showSegments); if (remembered != null) editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true); } } /* * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(PreferenceConstants.EDITOR_SHOW_SEGMENTS)) synchronizeWithPreference(getTextEditor()); } } --- NEW FILE: RubyOutlinePage.java --- /******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.rubypeople.rdt.internal.ui.rubyeditor; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; import java.util.Vector; import org.eclipse.core.resources.IResource; [...1217 lines suppressed...] */ protected IShowInTarget getShowInTarget() { return new IShowInTarget() { public boolean show(ShowInContext context) { ISelection sel= context.getSelection(); if (sel instanceof ITextSelection) { ITextSelection tsel= (ITextSelection) sel; int offset= tsel.getOffset(); IRubyElement element= fEditor.getElementAt(offset); if (element != null) { setSelection(new StructuredSelection(element)); return true; } } return false; } }; } } Index: ExternalRubyDocumentProvider.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ExternalRubyDocumentProvider.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ExternalRubyDocumentProvider.java 5 Mar 2005 16:04:24 -0000 1.4 --- ExternalRubyDocumentProvider.java 10 Feb 2006 20:14:31 -0000 1.5 *************** *** 47,51 **** // TODO: check if this should be inherited from RubyDocumentProvider if (document != null) { ! RubyTextTools tools = RubyPlugin.getDefault().getTextTools(); IDocumentPartitioner partitioner = tools.createDocumentPartitioner(); document.setDocumentPartitioner(partitioner); --- 47,51 ---- // TODO: check if this should be inherited from RubyDocumentProvider if (document != null) { ! RubyTextTools tools = RubyPlugin.getDefault().getRubyTextTools(); IDocumentPartitioner partitioner = tools.createDocumentPartitioner(); document.setDocumentPartitioner(partitioner); Index: ExternalRubyEditor.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ExternalRubyEditor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExternalRubyEditor.java 29 Feb 2004 22:01:18 -0000 1.1 --- ExternalRubyEditor.java 10 Feb 2006 20:14:31 -0000 1.2 *************** *** 1,4 **** --- 1,6 ---- package org.rubypeople.rdt.internal.ui.rubyeditor; + import org.rubypeople.rdt.core.IRubyElement; + public class ExternalRubyEditor extends RubyAbstractEditor { *************** *** 14,16 **** --- 16,26 ---- } + protected IRubyElement getElementAt(int caret, boolean b) { + return null; + } + + protected IRubyElement getElementAt(int offset) { + return null; + } + } Index: RubyAbstractEditor.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** RubyAbstractEditor.java 30 Mar 2005 01:55:33 -0000 1.21 --- RubyAbstractEditor.java 10 Feb 2006 20:14:31 -0000 1.22 *************** *** 5,13 **** import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection; - import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; --- 5,13 ---- import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.IPreferenceStore; + import org.eclipse.jface.text.ITextViewerExtension5; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; *************** *** 21,27 **** --- 21,30 ---- import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.ChainedPreferenceStore; + import org.eclipse.ui.views.contentoutline.ContentOutline; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; + import org.rubypeople.rdt.core.IImportContainer; import org.rubypeople.rdt.core.IImportDeclaration; import org.rubypeople.rdt.core.IMember; + import org.rubypeople.rdt.core.IRubyElement; import org.rubypeople.rdt.core.IRubyScript; import org.rubypeople.rdt.core.ISourceRange; *************** *** 29,316 **** import org.rubypeople.rdt.core.RubyModelException; import org.rubypeople.rdt.internal.ui.RubyPlugin; - import org.rubypeople.rdt.internal.ui.rubyeditor.outline.DocumentModelChangeEvent; - import org.rubypeople.rdt.internal.ui.rubyeditor.outline.IDocumentModelListener; - import org.rubypeople.rdt.internal.ui.rubyeditor.outline.RubyContentOutlinePage; - import org.rubypeople.rdt.internal.ui.rubyeditor.outline.RubyCore; - import org.rubypeople.rdt.internal.ui.rubyeditor.outline.RubyModel; - import org.rubypeople.rdt.internal.ui.text.RubySourceViewerConfiguration; import org.rubypeople.rdt.internal.ui.text.RubyTextTools; import org.rubypeople.rdt.ui.IWorkingCopyManager; ! public class RubyAbstractEditor extends TextEditor { ! protected RubyContentOutlinePage outlinePage; ! protected RubyTextTools textTools; ! private IDocumentModelListener fListener; ! private RubyCore fCore; ! private RubyModel model; ! private ISourceReference reference; ! private IPreferenceStore createCombinedPreferenceStore() { ! IPreferenceStore rdtStore = RubyPlugin.getDefault().getPreferenceStore(); ! IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore(); ! return new ChainedPreferenceStore(new IPreferenceStore[] { rdtStore, generalTextStore}); ! } ! protected void initializeEditor() { ! super.initializeEditor(); ! setPreferenceStore(this.createCombinedPreferenceStore()); ! textTools = RubyPlugin.getDefault().getTextTools(); ! setSourceViewerConfiguration(new RubySourceViewerConfiguration(textTools, this)); ! if (fListener == null) { ! fListener = createRubyModelChangeListener(); ! } ! fCore = RubyCore.getDefault(); ! fCore.addDocumentModelListener(fListener); ! } ! /* ! * (non-Javadoc) ! * ! * @see org.eclipse.ui.texteditor.ExtendedTextEditor#dispose() ! */ ! public void dispose() { ! super.dispose(); ! // Remove the listener so we don't try and create markers on a closed ! // document ! fCore.removeDocumentModelListener(fListener); ! } ! /** ! * @return ! */ ! private IDocumentModelListener createRubyModelChangeListener() { ! return new IDocumentModelListener() { ! public void documentModelChanged(final DocumentModelChangeEvent event) { ! if (event.getModel() == getRubyModel()) { ! getSite().getShell().getDisplay().asyncExec(new Runnable() { ! public void run() { ! try { ! createMarkers(event.getModel().getScript()); ! } catch (CoreException e) { ! RubyPlugin.log(e); ! } ! } ! }); ! } ! } ! }; ! } ! public Object getAdapter(Class required) { ! if (IContentOutlinePage.class.equals(required)) return createRubyOutlinePage(); ! return super.getAdapter(required); ! } ! protected RubyContentOutlinePage createRubyOutlinePage() { ! outlinePage = new RubyContentOutlinePage(getSourceViewer().getDocument(), this); ! setOutlinePageInput(outlinePage, getEditorInput()); ! outlinePage.addSelectionChangedListener(new ISelectionChangedListener() { ! public void selectionChanged(SelectionChangedEvent event) { ! handleOutlinePageSelection(event); ! } ! }); ! return outlinePage; ! } ! /* ! * (non-Javadoc) ! * ! * @see org.eclipse.ui.editors.text.TextEditor#doSetInput(org.eclipse.ui.IEditorInput) ! */ ! protected void doSetInput(IEditorInput input) throws CoreException { ! super.doSetInput(input); ! setOutlinePageInput(outlinePage, input); ! } ! protected void setOutlinePageInput(RubyContentOutlinePage page, IEditorInput input) { ! if (page != null) { ! IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager(); ! page.setInput(manager.getWorkingCopy(input)); ! } ! } ! protected void handleOutlinePageSelection(SelectionChangedEvent event) { ! StructuredSelection selection = (StructuredSelection) event.getSelection(); ! Iterator iter = ((IStructuredSelection) selection).iterator(); ! while (iter.hasNext()) { ! Object o = iter.next(); ! if (o instanceof ISourceReference) { ! reference = (ISourceReference) o; ! break; ! } ! } ! // FIXME Uncomment so we bring editor to top ! if (!isActivePart() && RubyPlugin.getActivePage() != null) RubyPlugin.getActivePage().bringToTop(this); ! // setSelection(reference, !isActivePart()); ! setSelection(reference, true); ! } ! protected boolean isActivePart() { ! IWorkbenchPart part = getActivePart(); ! return part != null && part.equals(this); ! } ! private IWorkbenchPart getActivePart() { ! IWorkbenchWindow window = getSite().getWorkbenchWindow(); ! IPartService service = window.getPartService(); ! IWorkbenchPart part = service.getActivePart(); ! return part; ! } ! protected void setSelection(ISourceReference reference, boolean moveCursor) { ! if (getSelectionProvider() == null) return; ! ISelection selection = getSelectionProvider().getSelection(); ! if (selection instanceof TextSelection) { ! TextSelection textSelection = (TextSelection) selection; ! // PR 39995: [navigation] Forward history cleared after going back ! // in navigation history: ! // mark only in navigation history if the cursor is being moved ! // (which it isn't if ! // this is called from a PostSelectionEvent that should only update ! // the magnet) ! if (moveCursor && (textSelection.getOffset() != 0 || textSelection.getLength() != 0)) markInNavigationHistory(); ! } ! if (reference != null) { ! StyledText textWidget = null; ! ISourceViewer sourceViewer = getSourceViewer(); ! if (sourceViewer != null) textWidget = sourceViewer.getTextWidget(); ! if (textWidget == null) return; ! try { ! ISourceRange range = null; ! // if (reference instanceof ILocalVariable) { ! // IRubyElement je = ((ILocalVariable) reference).getParent(); ! // if (je instanceof ISourceReference) range = ((ISourceReference) je).getSourceRange(); ! // } else ! range = reference.getSourceRange(); ! if (range == null) return; ! int offset = range.getOffset(); ! int length = range.getLength(); ! if (offset < 0 || length < 0) return; ! setHighlightRange(offset, length, moveCursor); ! if (!moveCursor) ! return; ! ! offset= -1; ! length= -1; ! if (reference instanceof IMember) { ! range = ((IMember) reference).getNameRange(); ! if (range != null) { ! offset = range.getOffset(); ! length = range.getLength(); ! } ! // } else if (reference instanceof ILocalVariable) { ! // range= ((ILocalVariable)reference).getNameRange(); ! // if (range != null) { ! // offset= range.getOffset(); ! // length= range.getLength(); ! // } ! } else if (reference instanceof IImportDeclaration) { ! String name = ((IImportDeclaration) reference).getElementName(); ! if (name != null && name.length() > 0) { ! String content = reference.getSource(); ! if (content != null) { ! offset = range.getOffset() + content.indexOf(name); ! length = name.length(); ! } ! } ! } ! if (offset > -1 && length > 0) { ! try { ! textWidget.setRedraw(false); ! sourceViewer.revealRange(offset, length); ! sourceViewer.setSelectedRange(offset, length); ! } finally { ! textWidget.setRedraw(true); ! } ! markInNavigationHistory(); ! } ! } catch (RubyModelException x) {} catch (IllegalArgumentException x) {} ! } else if (moveCursor) { ! resetHighlightRange(); ! markInNavigationHistory(); ! } ! } ! protected boolean affectsTextPresentation(PropertyChangeEvent event) { ! return textTools.affectsTextPresentation(event); ! } ! /** ! * @param script ! * @throws CoreException ! */ ! private void createMarkers(IRubyScript script) throws CoreException { ! // FIXME Create Markers on the file ! // IEditorInput input = getEditorInput(); ! // if (input == null) { ! // // can happen at workbench shutdown ! // return; ! // } ! // IResource resource = (IResource) ((IAdaptable) ! // input).getAdapter(org.eclipse.core.resources.IResource.class); ! // if (resource == null) { ! // // happens if ruby file is external ! // return; ! // } ! // resource.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ONE); ! // if ! // (!RdtUiPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.CREATE_PARSER_ANNOTATIONS)) ! // { return; } ! // IDocument doc = getDocumentProvider().getDocument(getEditorInput()); ! // Set errors = script.getParseErrors(); ! // for (Iterator iter = errors.iterator(); iter.hasNext();) { ! // ParseError pe = (ParseError) iter.next(); ! // Map attributes = new HashMap(); ! // MarkerUtilities.setMessage(attributes, pe.getError()); ! // MarkerUtilities.setLineNumber(attributes, pe.getLine()); ! // try { ! // int offset = doc.getLineOffset(pe.getLine()); ! // MarkerUtilities.setCharStart(attributes, offset + pe.getStart()); ! // MarkerUtilities.setCharEnd(attributes, offset + pe.getEnd()); ! // ! // attributes.put(IMarker.SEVERITY, pe.getSeverity()); ! // try { ! // MarkerUtilities.createMarker(resource, attributes, IMarker.PROBLEM); ! // } catch (CoreException x) { ! // RubyPlugin.log(x); ! // } ! // } catch (BadLocationException e) { ! // RubyPlugin.log(e); ! // } ! // ! // } ! } ! public RubyModel getRubyModel() { ! if (model == null) { ! model = new RubyModel(); ! } ! return model; ! } } \ No newline at end of file --- 32,392 ---- import org.rubypeople.rdt.core.RubyModelException; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.text.RubyTextTools; import org.rubypeople.rdt.ui.IWorkingCopyManager; + import org.rubypeople.rdt.ui.text.RubySourceViewerConfiguration; ! public abstract class RubyAbstractEditor extends TextEditor { ! protected RubyTextTools textTools; ! private ISourceReference reference; ! /** Outliner context menu Id */ ! protected String fOutlinerContextMenuId; ! /** The selection changed listener */ ! protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener(); ! private RubyOutlinePage fOutlinePage; ! private IPreferenceStore createCombinedPreferenceStore() { ! IPreferenceStore rdtStore = RubyPlugin.getDefault().getPreferenceStore(); ! IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore(); ! return new ChainedPreferenceStore(new IPreferenceStore[] { rdtStore, generalTextStore}); ! } ! /** ! * Informs the editor that its outliner has been closed. ! */ ! public void outlinePageClosed() { ! if (fOutlinePage != null) { ! fOutlineSelectionChangedListener.uninstall(fOutlinePage); ! fOutlinePage = null; ! resetHighlightRange(); ! } ! } ! /** ! * Sets the outliner's context menu ID. ! * ! * @param menuId ! * the menu ID ! */ ! protected void setOutlinerContextMenuId(String menuId) { ! fOutlinerContextMenuId = menuId; ! } ! protected void initializeEditor() { ! super.initializeEditor(); ! setPreferenceStore(this.createCombinedPreferenceStore()); ! textTools = RubyPlugin.getDefault().getRubyTextTools(); ! setSourceViewerConfiguration(new RubySourceViewerConfiguration(textTools, this)); ! } ! /* ! * (non-Javadoc) ! * ! * @see org.eclipse.ui.texteditor.ExtendedTextEditor#dispose() ! */ ! public void dispose() { ! super.dispose(); ! } ! public Object getAdapter(Class required) { ! if (IContentOutlinePage.class.equals(required)) { ! if (fOutlinePage == null) fOutlinePage = createRubyOutlinePage(); ! return fOutlinePage; ! } ! return super.getAdapter(required); ! } ! protected RubyOutlinePage createRubyOutlinePage() { ! RubyOutlinePage outlinePage = new RubyOutlinePage(fOutlinerContextMenuId, this); ! fOutlineSelectionChangedListener.install(outlinePage); ! setOutlinePageInput(outlinePage, getEditorInput()); ! return outlinePage; ! } ! /* ! * (non-Javadoc) ! * ! * @see org.eclipse.ui.editors.text.TextEditor#doSetInput(org.eclipse.ui.IEditorInput) ! */ ! protected void doSetInput(IEditorInput input) throws CoreException { ! super.doSetInput(input); ! setOutlinePageInput(fOutlinePage, input); ! } ! protected void setOutlinePageInput(RubyOutlinePage page, IEditorInput input) { ! if (page != null) { ! IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager(); ! page.setInput(manager.getWorkingCopy(input)); ! } ! } ! protected void handleOutlinePageSelection(SelectionChangedEvent event) { ! StructuredSelection selection = (StructuredSelection) event.getSelection(); ! Iterator iter = ((IStructuredSelection) selection).iterator(); ! while (iter.hasNext()) { ! Object o = iter.next(); ! if (o instanceof ISourceReference) { ! reference = (ISourceReference) o; ! break; ! } ! } ! if (!isActivePart() && RubyPlugin.getActivePage() != null) ! RubyPlugin.getActivePage().bringToTop(this); ! // setSelection(reference, !isActivePart()); ! setSelection(reference, true); ! } ! protected boolean isActivePart() { ! IWorkbenchPart part = getActivePart(); ! return part != null && part.equals(this); ! } ! private IWorkbenchPart getActivePart() { ! IWorkbenchWindow window = getSite().getWorkbenchWindow(); ! IPartService service = window.getPartService(); ! IWorkbenchPart part = service.getActivePart(); ! return part; ! } ! public void setSelection(IRubyElement element) { ! if (element == null || element instanceof IRubyScript) { ! /* ! * If the element is an IRubyScript this unit is either the input of ! * this editor or not being displayed. In both cases, nothing should ! * happened. (http://dev.eclipse.org/bugs/show_bug.cgi?id=5128) ! */ ! return; ! } ! IRubyElement corresponding = getCorrespondingElement(element); ! if (corresponding instanceof ISourceReference) { ! ISourceReference reference = (ISourceReference) corresponding; ! // set highlight range ! setSelection(reference, true); ! // set outliner selection ! if (fOutlinePage != null) { ! fOutlineSelectionChangedListener.uninstall(fOutlinePage); ! fOutlinePage.select(reference); ! fOutlineSelectionChangedListener.install(fOutlinePage); ! } ! } ! } ! protected IRubyElement getCorrespondingElement(IRubyElement element) { ! // TODO: With new working copy story: original == working copy. ! // Note that the previous code could result in a reconcile as side ! // effect. Should check if that ! // is still required. ! return element; ! } ! /** ! * Synchronizes the outliner selection with the given element position in ! * the editor. ! * ! * @param element ! * the java element to select ! * @param checkIfOutlinePageActive ! * <code>true</code> if check for active outline page needs to ! * be done ! */ ! protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) { ! if (fOutlinePage != null && element != null ! && !(checkIfOutlinePageActive && isRubyOutlinePageActive())) { ! fOutlineSelectionChangedListener.uninstall(fOutlinePage); ! fOutlinePage.select(element); ! fOutlineSelectionChangedListener.install(fOutlinePage); ! } ! } ! private boolean isRubyOutlinePageActive() { ! IWorkbenchPart part = getActivePart(); ! return part instanceof ContentOutline ! && ((ContentOutline) part).getCurrentPage() == fOutlinePage; ! } ! protected void setSelection(ISourceReference reference, boolean moveCursor) { ! if (getSelectionProvider() == null) return; ! ISelection selection = getSelectionProvider().getSelection(); ! if (selection instanceof TextSelection) { ! TextSelection textSelection = (TextSelection) selection; ! // PR 39995: [navigation] Forward history cleared after going back ! // in navigation history: ! // mark only in navigation history if the cursor is being moved ! // (which it isn't if ! // this is called from a PostSelectionEvent that should only update ! // the magnet) ! if (moveCursor && (textSelection.getOffset() != 0 || textSelection.getLength() != 0)) ! markInNavigationHistory(); ! } ! if (reference != null) { ! StyledText textWidget = null; ! ISourceViewer sourceViewer = getSourceViewer(); ! if (sourceViewer != null) textWidget = sourceViewer.getTextWidget(); ! if (textWidget == null) return; ! try { ! ISourceRange range = null; ! // if (reference instanceof ILocalVariable) { ! // IRubyElement je = ((ILocalVariable) reference).getParent(); ! // if (je instanceof ISourceReference) range = ! // ((ISourceReference) je).getSourceRange(); ! // } else ! range = reference.getSourceRange(); ! if (range == null) return; ! int offset = range.getOffset(); ! int length = range.getLength(); ! if (offset < 0 || length < 0) return; ! setHighlightRange(offset, length, moveCursor); ! if (!moveCursor) return; ! offset = -1; ! length = -1; ! if (reference instanceof IMember) { ! range = ((IMember) reference).getNameRange(); ! if (range != null) { ! offset = range.getOffset(); ! length = range.getLength(); ! } ! // } else if (reference instanceof ILocalVariable) { ! // range= ((ILocalVariable)reference).getNameRange(); ! // if (range != null) { ! // offset= range.getOffset(); ! // length= range.getLength(); ! // } ! } else if (reference instanceof IImportDeclaration) { ! String name = ((IImportDeclaration) reference).getElementName(); ! if (name != null && name.length() > 0) { ! String content = reference.getSource(); ! if (content != null) { ! offset = range.getOffset() + content.indexOf(name); ! length = name.length(); ! } ! } ! } ! if (offset > -1 && length > 0) { ! ! try { ! textWidget.setRedraw(false); ! sourceViewer.revealRange(offset, length); ! sourceViewer.setSelectedRange(offset, length); ! } finally { ! textWidget.setRedraw(true); ! } ! ! markInNavigationHistory(); ! } ! ! } catch (RubyModelException x) { ! } catch (IllegalArgumentException x) { ! } ! ! } else if (moveCursor) { ! resetHighlightRange(); ! markInNavigationHistory(); ! } ! } ! ! protected boolean affectsTextPresentation(PropertyChangeEvent event) { ! return textTools.affectsTextPresentation(event); ! } ! ! protected void doSelectionChanged(SelectionChangedEvent event) { ! ! ISourceReference reference = null; ! ! ISelection selection = event.getSelection(); ! Iterator iter = ((IStructuredSelection) selection).iterator(); ! while (iter.hasNext()) { ! Object o = iter.next(); ! if (o instanceof ISourceReference) { ! reference = (ISourceReference) o; ! break; ! } ! } ! if (!isActivePart() && RubyPlugin.getActivePage() != null) ! RubyPlugin.getActivePage().bringToTop(this); ! ! setSelection(reference, !isActivePart()); ! } ! ! class OutlineSelectionChangedListener extends AbstractSelectionChangedListener { ! ! public void selectionChanged(SelectionChangedEvent event) { ! doSelectionChanged(event); ! } ! } ! ! /** ! * Computes and returns the source reference that includes the caret and ! * serves as provider for the outline page selection and the editor range ! * indication. ! * ! * @return the computed source reference ! * @since 3.0 ! */ ! protected ISourceReference computeHighlightRangeSourceReference() { ! ISourceViewer sourceViewer= getSourceViewer(); ! if (sourceViewer == null) ! return null; ! ! StyledText styledText= sourceViewer.getTextWidget(); ! if (styledText == null) ! return null; ! ! int caret= 0; ! if (sourceViewer instanceof ITextViewerExtension5) { ! ITextViewerExtension5 extension= (ITextViewerExtension5)sourceViewer; ! caret= extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); ! } else { ! int offset= sourceViewer.getVisibleRegion().getOffset(); ! caret= offset + styledText.getCaretOffset(); ! } ! ! IRubyElement element= getElementAt(caret, false); ! ! if ( !(element instanceof ISourceReference)) ! return null; ! ! if (element.getElementType() == IRubyElement.IMPORT) { ! ! IImportDeclaration declaration= (IImportDeclaration) element; ! IImportContainer container= (IImportContainer) declaration.getParent(); ! ISourceRange srcRange= null; ! ! try { ! srcRange= container.getSourceRange(); ! } catch (RubyModelException e) { ! } ! ! if (srcRange != null && srcRange.getOffset() == caret) ! return container; ! } ! ! return (ISourceReference) element; ! } ! ! protected abstract IRubyElement getElementAt(int caret, boolean b); ! ! protected abstract IRubyElement getElementAt(int offset); } \ No newline at end of file |