Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 52000 Details for
Bug 160278
Tab Conversion in Assembly editor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Second patch attempt.
patch.txt (text/plain), 18.78 KB, created by
Robert Norton
on 2006-10-15 10:58:27 EDT
(
hide
)
Description:
Second patch attempt.
Filename:
MIME Type:
Creator:
Robert Norton
Created:
2006-10-15 10:58:27 EDT
Size:
18.78 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.cdt.ui >Index: src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java,v >retrieving revision 1.12 >diff -u -r1.12 CSourceViewer.java >--- src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java 10 Oct 2006 09:05:06 -0000 1.12 >+++ src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java 15 Oct 2006 14:59:25 -0000 >@@ -41,7 +41,8 @@ > import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; > import org.eclipse.ui.texteditor.AbstractTextEditor; > >-import org.eclipse.cdt.internal.ui.editor.CEditor.ITextConverter; >+import org.eclipse.cdt.internal.ui.editor.AbstractCDTEditor; >+import org.eclipse.cdt.internal.ui.editor.AbstractCDTEditor.ITextConverter; > import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; > > /** >Index: src/org/eclipse/cdt/internal/ui/editor/CEditor.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java,v >retrieving revision 1.125 >diff -u -r1.125 CEditor.java >--- src/org/eclipse/cdt/internal/ui/editor/CEditor.java 12 Oct 2006 13:31:02 -0000 1.125 >+++ src/org/eclipse/cdt/internal/ui/editor/CEditor.java 15 Oct 2006 14:59:24 -0000 >@@ -39,7 +39,6 @@ > import org.eclipse.jface.text.BadLocationException; > import org.eclipse.jface.text.BadPositionCategoryException; > import org.eclipse.jface.text.DefaultInformationControl; >-import org.eclipse.jface.text.DefaultLineTracker; > import org.eclipse.jface.text.DocumentCommand; > import org.eclipse.jface.text.DocumentEvent; > import org.eclipse.jface.text.IDocument; >@@ -47,7 +46,6 @@ > import org.eclipse.jface.text.IDocumentListener; > import org.eclipse.jface.text.IInformationControl; > import org.eclipse.jface.text.IInformationControlCreator; >-import org.eclipse.jface.text.ILineTracker; > import org.eclipse.jface.text.IPositionUpdater; > import org.eclipse.jface.text.IRegion; > import org.eclipse.jface.text.ITextHover; >@@ -126,14 +124,12 @@ > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.actions.ActionContext; > import org.eclipse.ui.actions.ActionGroup; >-import org.eclipse.ui.editors.text.TextEditor; > import org.eclipse.ui.part.EditorActionBarContributor; > import org.eclipse.ui.part.IShowInSource; > import org.eclipse.ui.part.IShowInTargetList; > import org.eclipse.ui.part.ShowInContext; > import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; > 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.ITextEditorActionDefinitionIds; >@@ -171,7 +167,6 @@ > import org.eclipse.cdt.ui.text.ICPartitions; > import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider; > >-import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil; > import org.eclipse.cdt.internal.corext.util.SimplePositionTracker; > > import org.eclipse.cdt.internal.ui.CPluginImages; >@@ -207,11 +202,7 @@ > /** > * C specific text editor. > */ >-public class CEditor extends TextEditor implements ISelectionChangedListener, IReconcilingParticipant, ICReconcilingListener { >- >- interface ITextConverter { >- void customizeDocumentCommand(IDocument document, DocumentCommand command); >- } >+public class CEditor extends AbstractCDTEditor implements ISelectionChangedListener, IReconcilingParticipant, ICReconcilingListener { > > class AdaptedSourceViewer extends CSourceViewer { > >@@ -349,80 +340,6 @@ > } > } > >- static class TabConverter implements ITextConverter { >- private int fTabRatio; >- private ILineTracker fLineTracker; >- >- public TabConverter() { >- } >- >- public void setNumberOfSpacesPerTab(int ratio) { >- fTabRatio = ratio; >- } >- >- public void setLineTracker(ILineTracker lineTracker) { >- fLineTracker = lineTracker; >- } >- >- private int insertTabString(StringBuffer buffer, int offsetInLine) { >- >- if (fTabRatio == 0) >- return 0; >- >- int remainder = offsetInLine % fTabRatio; >- remainder = fTabRatio - remainder; >- for (int i = 0; i < remainder; i++) >- buffer.append(' '); >- return remainder; >- } >- >- public void customizeDocumentCommand(IDocument document, DocumentCommand command) { >- String text = command.text; >- if (text == null) >- return; >- >- int index = text.indexOf('\t'); >- if (index > -1) { >- StringBuffer buffer = new StringBuffer(); >- >- fLineTracker.set(command.text); >- int lines = fLineTracker.getNumberOfLines(); >- >- try { >- for (int i = 0; i < lines; i++) { >- int offset = fLineTracker.getLineOffset(i); >- int endOffset = offset + fLineTracker.getLineLength(i); >- String line = text.substring(offset, endOffset); >- >- int position = 0; >- if (i == 0) { >- IRegion firstLine = document.getLineInformationOfOffset(command.offset); >- position = command.offset - firstLine.getOffset(); >- } >- >- int length = line.length(); >- for (int j = 0; j < length; j++) { >- char c = line.charAt(j); >- if (c == '\t') { >- int oldPosition = position; >- position += insertTabString(buffer, position); >- if (command.caretOffset > command.offset + oldPosition) { >- command.caretOffset += position - oldPosition - 1; >- } >- } else { >- buffer.append(c); >- ++position; >- } >- } >- } >- >- command.text = buffer.toString(); >- } catch (BadLocationException x) { >- } >- } >- } >- } >- > private class ExitPolicy implements IExitPolicy { > > final char fExitCharacter; >@@ -1530,9 +1447,6 @@ > /** The bracket inserter. */ > private BracketInserter fBracketInserter = new BracketInserter(); > >- /** The editor's tab converter */ >- private TabConverter fTabConverter; >- > /** Listener to annotation model changes that updates the error tick in the tab image */ > private CEditorErrorTickUpdater fCEditorErrorTickUpdater; > >@@ -1546,10 +1460,6 @@ > public static final String INACTIVE_CODE_ENABLE = "inactiveCodeEnable"; //$NON-NLS-1$ > /** Preference key for inactive code painter color */ > public static final String INACTIVE_CODE_COLOR = "inactiveCodeColor"; //$NON-NLS-1$ >- /** 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 */ >- public final static String SPACES_FOR_TABS = DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR; > /** Preference key for automatically closing strings */ > private final static String CLOSE_STRINGS = PreferenceConstants.EDITOR_CLOSE_STRINGS; > /** Preference key for automatically closing brackets and parenthesis */ >@@ -1635,16 +1545,6 @@ > } > > /** >- * Returns the C element wrapped by this editors input. >- * >- * @return the C element wrapped by this editors input. >- * @since 3.0 >- */ >- public ICElement getInputCElement () { >- return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(getEditorInput()); >- } >- >- /** > * Gets the current IFile input. > * This method will be remove after cdt-3.0. > * We can not guaranty that the input is an IFile, it may >@@ -1760,14 +1660,6 @@ > return; > } > >- if (SPACES_FOR_TABS.equals(property)) { >- if (isTabConversionEnabled()) >- startTabConversion(); >- else >- stopTabConversion(); >- return; >- } >- > if (PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property)) > updateHoverBehavior(); > >@@ -1781,12 +1673,6 @@ > } > } > >- if (CODE_FORMATTER_TAB_SIZE.equals(property)) { >- asv.updateIndentationPrefixes(); >- if (fTabConverter != null) >- fTabConverter.setNumberOfSpacesPerTab(getTabSize()); >- } >- > // Not implemented ... for the future. > if (TRANSLATION_TASK_TAGS.equals(event.getProperty())) { > ISourceViewer sourceViewer = getSourceViewer(); >@@ -2555,55 +2441,6 @@ > } > } > >- private void configureTabConverter() { >- if (fTabConverter != null) { >- IDocumentProvider provider = getDocumentProvider(); >- if (provider instanceof CDocumentProvider) { >- CDocumentProvider prov = (CDocumentProvider) provider; >- fTabConverter.setLineTracker(prov.createLineTracker(getEditorInput())); >- } else { >- fTabConverter.setLineTracker(new DefaultLineTracker()); >- } >- } >- } >- >- private int getTabSize() { >- ICElement element = getInputCElement(); >- ICProject project = element == null ? null : element.getCProject(); >- return CodeFormatterUtil.getTabWidth(project); >- } >- >- private void startTabConversion() { >- if (fTabConverter == null) { >- fTabConverter= new TabConverter(); >- configureTabConverter(); >- fTabConverter.setNumberOfSpacesPerTab(getTabSize()); >- AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); >- asv.addTextConverter(fTabConverter); >- asv.updateIndentationPrefixes(); >- } >- } >- >- private void stopTabConversion() { >- if (fTabConverter != null) { >- AdaptedSourceViewer asv= (AdaptedSourceViewer) getSourceViewer(); >- asv.removeTextConverter(fTabConverter); >- asv.updateIndentationPrefixes(); >- fTabConverter= null; >- } >- } >- >- private boolean isTabConversionEnabled() { >- ICElement element= getInputCElement(); >- ICProject project= element == null ? null : element.getCProject(); >- String option; >- if (project == null) >- option= CCorePlugin.getOption(SPACES_FOR_TABS); >- else >- option= project.getOption(SPACES_FOR_TABS, true); >- return CCorePlugin.SPACE.equals(option); >- } >- > /* > * @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions() > */ >Index: src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java,v >retrieving revision 1.13 >diff -u -r1.13 AsmTextEditor.java >--- src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java 6 Jul 2006 14:52:55 -0000 1.13 >+++ src/org/eclipse/cdt/internal/ui/editor/asm/AsmTextEditor.java 15 Oct 2006 14:59:25 -0000 >@@ -12,15 +12,17 @@ > package org.eclipse.cdt.internal.ui.editor.asm; > > >-import org.eclipse.cdt.ui.CUIPlugin; > import org.eclipse.jface.util.PropertyChangeEvent; >-import org.eclipse.ui.editors.text.TextEditor; >+ >+import org.eclipse.cdt.ui.CUIPlugin; >+ >+import org.eclipse.cdt.internal.ui.editor.AbstractCDTEditor; > > > /** > * Assembly text editor > */ >-public class AsmTextEditor extends TextEditor { >+public class AsmTextEditor extends AbstractCDTEditor { > /** > * Creates a new text editor. > */ >Index: src/org/eclipse/cdt/internal/ui/editor/AbstractCDTEditor.java >=================================================================== >RCS file: src/org/eclipse/cdt/internal/ui/editor/AbstractCDTEditor.java >diff -N src/org/eclipse/cdt/internal/ui/editor/AbstractCDTEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/cdt/internal/ui/editor/AbstractCDTEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,236 @@ >+package org.eclipse.cdt.internal.ui.editor; >+ >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.DefaultLineTracker; >+import org.eclipse.jface.text.DocumentCommand; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.ILineTracker; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.source.ISourceViewer; >+import org.eclipse.jface.text.source.IVerticalRuler; >+import org.eclipse.jface.util.PropertyChangeEvent; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.ui.editors.text.TextEditor; >+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; >+import org.eclipse.ui.texteditor.IDocumentProvider; >+ >+import org.eclipse.cdt.core.CCorePlugin; >+import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; >+import org.eclipse.cdt.core.model.ICElement; >+import org.eclipse.cdt.core.model.ICProject; >+import org.eclipse.cdt.ui.CUIPlugin; >+ >+import org.eclipse.cdt.internal.corext.util.CodeFormatterUtil; >+ >+public class AbstractCDTEditor extends TextEditor { >+ >+ protected interface ITextConverter { >+ void customizeDocumentCommand(IDocument document, >+ DocumentCommand command); >+ } >+ >+ protected static class TabConverter implements ITextConverter { >+ private int fTabRatio; >+ private ILineTracker fLineTracker; >+ >+ public TabConverter() { >+ } >+ >+ public void setNumberOfSpacesPerTab(int ratio) { >+ fTabRatio = ratio; >+ } >+ >+ public void setLineTracker(ILineTracker lineTracker) { >+ fLineTracker = lineTracker; >+ } >+ >+ private int insertTabString(StringBuffer buffer, int offsetInLine) { >+ >+ if (fTabRatio == 0) >+ return 0; >+ >+ int remainder = offsetInLine % fTabRatio; >+ remainder = fTabRatio - remainder; >+ for (int i = 0; i < remainder; i++) >+ buffer.append(' '); >+ return remainder; >+ } >+ >+ public void customizeDocumentCommand(IDocument document, >+ DocumentCommand command) { >+ String text = command.text; >+ if (text == null) >+ return; >+ >+ int index = text.indexOf('\t'); >+ if (index > -1) { >+ StringBuffer buffer = new StringBuffer(); >+ >+ fLineTracker.set(command.text); >+ int lines = fLineTracker.getNumberOfLines(); >+ >+ try { >+ for (int i = 0; i < lines; i++) { >+ int offset = fLineTracker.getLineOffset(i); >+ int endOffset = offset + fLineTracker.getLineLength(i); >+ String line = text.substring(offset, endOffset); >+ >+ int position = 0; >+ if (i == 0) { >+ IRegion firstLine = document >+ .getLineInformationOfOffset(command.offset); >+ position = command.offset - firstLine.getOffset(); >+ } >+ >+ int length = line.length(); >+ for (int j = 0; j < length; j++) { >+ char c = line.charAt(j); >+ if (c == '\t') { >+ int oldPosition = position; >+ position += insertTabString(buffer, position); >+ if (command.caretOffset > command.offset >+ + oldPosition) { >+ command.caretOffset += position >+ - oldPosition - 1; >+ } >+ } else { >+ buffer.append(c); >+ ++position; >+ } >+ } >+ } >+ >+ command.text = buffer.toString(); >+ } catch (BadLocationException x) { >+ } >+ } >+ } >+ } >+ >+ /** The editor's tab converter */ >+ protected TabConverter fTabConverter; >+ /** Preference key for inserting spaces rather than tabs */ >+ public static final String SPACES_FOR_TABS = DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR; >+ /** Preference key for code formatter tab size */ >+ private static final String CODE_FORMATTER_TAB_SIZE = DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE; >+ >+ public AbstractCDTEditor() { >+ // TODO Auto-generated constructor stub >+ } >+ >+ /** >+ * Returns the C element wrapped by this editors input. >+ * >+ * @return the C element wrapped by this editors input. >+ * @since 3.0 >+ */ >+ public ICElement getInputCElement() { >+ return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy( >+ getEditorInput()); >+ } >+ >+ private void configureTabConverter() { >+ if (fTabConverter != null) { >+ IDocumentProvider provider = getDocumentProvider(); >+ if (provider instanceof CDocumentProvider) { >+ CDocumentProvider prov = (CDocumentProvider) provider; >+ fTabConverter.setLineTracker(prov >+ .createLineTracker(getEditorInput())); >+ } else { >+ fTabConverter.setLineTracker(new DefaultLineTracker()); >+ } >+ } >+ } >+ >+ protected int getTabSize() { >+ ICElement element = getInputCElement(); >+ ICProject project = element == null ? null : element.getCProject(); >+ return CodeFormatterUtil.getTabWidth(project); >+ } >+ >+ protected void startTabConversion() { >+ if (fTabConverter == null) { >+ fTabConverter = new TabConverter(); >+ configureTabConverter(); >+ fTabConverter.setNumberOfSpacesPerTab(getTabSize()); >+ CSourceViewer asv = (CSourceViewer) getSourceViewer(); >+ asv.addTextConverter(fTabConverter); >+ } >+ } >+ >+ protected void stopTabConversion() { >+ if (fTabConverter != null) { >+ CSourceViewer asv = (CSourceViewer) getSourceViewer(); >+ asv.removeTextConverter(fTabConverter); >+ fTabConverter = null; >+ } >+ } >+ >+ protected boolean isTabConversionEnabled() { >+ ICElement element = getInputCElement(); >+ ICProject project = element == null ? null : element.getCProject(); >+ String option; >+ if (project == null) >+ option = CCorePlugin.getOption(SPACES_FOR_TABS); >+ else >+ option = project.getOption(SPACES_FOR_TABS, true); >+ return CCorePlugin.SPACE.equals(option); >+ } >+ >+ /** >+ * Handles a property change event describing a change of the editor's >+ * preference store and updates the preference related editor properties. >+ * >+ * @param event >+ * the property change event >+ */ >+ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { >+ String property = event.getProperty(); >+ >+ if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH >+ .equals(property)) { >+ /* >+ * Ignore tab setting since we rely on the formatter preferences. We >+ * do this outside the try-finally block to avoid that >+ * EDITOR_TAB_WIDTH is handled by the sub-class >+ * (AbstractDecoratedTextEditor). >+ */ >+ return; >+ } >+ >+ try { >+ CSourceViewer asv = (CSourceViewer) getSourceViewer(); >+ >+ if (asv != null) { >+ if (SPACES_FOR_TABS.equals(property)) { >+ if (isTabConversionEnabled()) >+ startTabConversion(); >+ else >+ stopTabConversion(); >+ return; >+ } >+ >+ if (CODE_FORMATTER_TAB_SIZE.equals(property)) { >+ if (fTabConverter != null) >+ fTabConverter.setNumberOfSpacesPerTab(getTabSize()); >+ } >+ } >+ } finally { >+ super.handlePreferenceStoreChanged(event); >+ } >+ } >+ >+ /* >+ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int) >+ */ >+ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { >+ IPreferenceStore store= getPreferenceStore(); >+ ISourceViewer sourceViewer = >+ new CSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles, store); >+ >+ getSourceViewerDecorationSupport(sourceViewer); >+ >+ return sourceViewer; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
bjorn.freeman-benson
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 160278
:
51666
| 52000