|
From: <caw...@us...> - 2006-08-08 23:59:26
|
Revision: 1557 Author: cawilliams Date: 2006-08-08 16:59:21 -0700 (Tue, 08 Aug 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1557&view=rev Log Message: ----------- move all tab conversion stuff down into RubyEditor (doesn't apply to External editor), fixes ticket #144 Modified Paths: -------------- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java =================================================================== --- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2006-08-08 23:45:26 UTC (rev 1556) +++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2006-08-08 23:59:21 UTC (rev 1557) @@ -39,7 +39,6 @@ import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; import org.eclipse.ui.texteditor.ChainedPreferenceStore; -import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; import org.eclipse.ui.views.contentoutline.ContentOutline; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; @@ -54,11 +53,8 @@ import org.rubypeople.rdt.core.ISourceReference; import org.rubypeople.rdt.core.RubyCore; import org.rubypeople.rdt.core.RubyModelException; -import org.rubypeople.rdt.core.formatter.DefaultCodeFormatterConstants; -import org.rubypeople.rdt.internal.corext.util.CodeFormatterUtil; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor.ITextConverter; -import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor.TabConverter; import org.rubypeople.rdt.internal.ui.text.ContentAssistPreference; import org.rubypeople.rdt.internal.ui.text.IRubyPartitions; import org.rubypeople.rdt.internal.ui.text.PreferencesAdapter; @@ -80,18 +76,13 @@ /** The selection changed listener */ protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener(); private RubyOutlinePage fOutlinePage; - /** The editor's tab converter */ - private TabConverter fTabConverter; /** Preference key for matching brackets */ protected final static String MATCHING_BRACKETS= PreferenceConstants.EDITOR_MATCHING_BRACKETS; /** Preference key for matching brackets color */ protected final static String MATCHING_BRACKETS_COLOR= PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR; - /** Preference key for code formatter tab size */ - private final static String CODE_FORMATTER_TAB_SIZE= DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE; - /** Preference key for inserting spaces rather than tabs */ - private final static String SPACES_FOR_TABS= DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR; + protected final static char[] BRACKETS= { '{', '}', '(', ')', '[', ']' }; /** The editor's bracket matcher */ @@ -219,7 +210,6 @@ */ protected void doSetInput(IEditorInput input) throws CoreException { super.doSetInput(input); - configureTabConverter(); setOutlinePageInput(fOutlinePage, input); } @@ -250,21 +240,7 @@ return; ((RubySourceViewerConfiguration)getSourceViewerConfiguration()).handlePropertyChangeEvent(event); - - if (SPACES_FOR_TABS.equals(property)) { - if (isTabConversionEnabled()) - startTabConversion(); - else - stopTabConversion(); - return; - } - - if (CODE_FORMATTER_TAB_SIZE.equals(property)) { - sourceViewer.updateIndentationPrefixes(); - if (fTabConverter != null) - fTabConverter.setNumberOfSpacesPerTab(getTabSize()); - } - + IContentAssistant c= sourceViewer.getContentAssistant(); if (c instanceof ContentAssistant) ContentAssistPreference.changeConfiguration((ContentAssistant) c, getPreferenceStore(), event); @@ -289,34 +265,8 @@ } } - private int getTabSize() { - IRubyElement element= getInputRubyElement(); - IRubyProject project= element == null ? null : element.getRubyProject(); - return CodeFormatterUtil.getTabWidth(project); - } - private void startTabConversion() { - if (fTabConverter == null) { - fTabConverter= new TabConverter(); - configureTabConverter(); - fTabConverter.setNumberOfSpacesPerTab(getTabSize()); - AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); - asv.addTextConverter(fTabConverter); - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 - asv.updateIndentationPrefixes(); - } - } - private void configureTabConverter() { - if (fTabConverter != null) { - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof IRubyScriptDocumentProvider) { - IRubyScriptDocumentProvider cup= (IRubyScriptDocumentProvider) provider; - fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); - } - } - } - /** * Returns the Ruby element wrapped by this editors input. * @@ -330,34 +280,6 @@ return RubyUI.getEditorInputRubyElement(getEditorInput()); } - private void stopTabConversion() { - if (fTabConverter != null) { - AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); - asv.removeTextConverter(fTabConverter); - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 - asv.updateIndentationPrefixes(); - fTabConverter= null; - } - } - - public void createPartControl(Composite parent) { - super.createPartControl(parent); - - if (isTabConversionEnabled()) - startTabConversion(); - } - - private boolean isTabConversionEnabled() { - IRubyElement element= getInputRubyElement(); - IRubyProject project= element == null ? null : element.getRubyProject(); - String option; - if (project == null) - option= RubyCore.getOption(SPACES_FOR_TABS); - else - option= project.getOption(SPACES_FOR_TABS, true); - return RubyCore.SPACE.equals(option); - } - protected void handleOutlinePageSelection(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); Iterator iter = ((IStructuredSelection) selection).iterator(); Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java =================================================================== --- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2006-08-08 23:45:26 UTC (rev 1556) +++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2006-08-08 23:59:21 UTC (rev 1557) @@ -77,6 +77,7 @@ import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.texteditor.AnnotationPreference; import org.eclipse.ui.texteditor.ContentAssistAction; +import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.MarkerAnnotation; @@ -84,8 +85,12 @@ import org.eclipse.ui.texteditor.link.EditorLinkedModeUI; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import org.rubypeople.rdt.core.IRubyElement; +import org.rubypeople.rdt.core.IRubyProject; import org.rubypeople.rdt.core.IRubyScript; +import org.rubypeople.rdt.core.RubyCore; import org.rubypeople.rdt.core.RubyModelException; +import org.rubypeople.rdt.core.formatter.DefaultCodeFormatterConstants; +import org.rubypeople.rdt.internal.corext.util.CodeFormatterUtil; import org.rubypeople.rdt.internal.corext.util.RubyModelUtil; import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds; import org.rubypeople.rdt.internal.ui.RubyPlugin; @@ -107,6 +112,9 @@ protected RubyActionGroup actionGroup; private ProjectionSupport fProjectionSupport; + + /** The editor's tab converter */ + private TabConverter fTabConverter; /** Preference key for automatically closing strings */ private final static String CLOSE_STRINGS= PreferenceConstants.EDITOR_CLOSE_STRINGS; @@ -114,7 +122,11 @@ private final static String CLOSE_BRACKETS= PreferenceConstants.EDITOR_CLOSE_BRACKETS; /** Preference key for automatically closing braces */ private final static String CLOSE_BRACES= PreferenceConstants.EDITOR_CLOSE_BRACES; - + /** Preference key for code formatter tab size */ + private final static String CODE_FORMATTER_TAB_SIZE= DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE; + /** Preference key for inserting spaces rather than tabs */ + private final static String SPACES_FOR_TABS= DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR; + /** * Mutex for the reconciler. See * https://bugs.eclipse.org/bugs/show_bug.cgi?id=63898 for a description of @@ -279,6 +291,9 @@ if (isFoldingEnabled()) projectionViewer.doOperation(ProjectionViewer.TOGGLE); + if (isTabConversionEnabled()) + startTabConversion(); + ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer instanceof ITextViewerExtension) { IPreferenceStore preferenceStore= getPreferenceStore(); @@ -661,7 +676,7 @@ */ protected void doSetInput(IEditorInput input) throws CoreException { super.doSetInput(input); - + configureTabConverter(); if (fProjectionModelUpdater != null) fProjectionModelUpdater.initialize(); } @@ -721,10 +736,24 @@ fBracketInserter.setCloseStringsEnabled(getPreferenceStore().getBoolean(property)); return; } - - ISourceViewer sourceViewer= getSourceViewer(); + + AdaptedSourceViewer sourceViewer= (AdaptedSourceViewer) getSourceViewer(); if (sourceViewer == null) return; + + if (SPACES_FOR_TABS.equals(property)) { + if (isTabConversionEnabled()) + startTabConversion(); + else + stopTabConversion(); + return; + } + + if (CODE_FORMATTER_TAB_SIZE.equals(property)) { + sourceViewer.updateIndentationPrefixes(); + if (fTabConverter != null) + fTabConverter.setNumberOfSpacesPerTab(getTabSize()); + } if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) { if (sourceViewer instanceof ProjectionViewer) { @@ -1558,4 +1587,54 @@ public FoldingActionGroup getFoldingActionGroup() { return fFoldingGroup; } + + private int getTabSize() { + IRubyElement element= getInputRubyElement(); + IRubyProject project= element == null ? null : element.getRubyProject(); + return CodeFormatterUtil.getTabWidth(project); + } + + private void startTabConversion() { + if (fTabConverter == null) { + fTabConverter= new TabConverter(); + configureTabConverter(); + fTabConverter.setNumberOfSpacesPerTab(getTabSize()); + AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); + asv.addTextConverter(fTabConverter); + // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 + asv.updateIndentationPrefixes(); + } + } + + private void configureTabConverter() { + if (fTabConverter != null) { + IDocumentProvider provider= getDocumentProvider(); + if (provider instanceof IRubyScriptDocumentProvider) { + IRubyScriptDocumentProvider cup= (IRubyScriptDocumentProvider) provider; + fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); + } + } + } + + + private void stopTabConversion() { + if (fTabConverter != null) { + AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); + asv.removeTextConverter(fTabConverter); + // http://dev.eclipse.org/bugs/show_bug.cgi?id=19270 + asv.updateIndentationPrefixes(); + fTabConverter= null; + } + } + + private boolean isTabConversionEnabled() { + IRubyElement element= getInputRubyElement(); + IRubyProject project= element == null ? null : element.getRubyProject(); + String option; + if (project == null) + option= RubyCore.getOption(SPACES_FOR_TABS); + else + option= project.getOption(SPACES_FOR_TABS, true); + return RubyCore.SPACE.equals(option); + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |