1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

2004-11-19 Alain Magloire

Fix for PR 39204
	* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
This commit is contained in:
Alain Magloire 2004-11-19 19:30:30 +00:00
parent f5891e712a
commit 442dba3306
2 changed files with 87 additions and 43 deletions

View file

@ -1,3 +1,7 @@
2004-11-19 Alain Magloire
Fix for PR 39204
* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
2004-11-19 Bogdan Gheorghe 2004-11-19 Bogdan Gheorghe
Fix for 43664 : Search should report matches outside of workspace Fix for 43664 : Search should report matches outside of workspace

View file

@ -8,7 +8,6 @@ package org.eclipse.cdt.internal.ui.editor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants; import org.eclipse.cdt.core.CCorePreferenceConstants;
@ -47,8 +46,10 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DefaultLineTracker;
import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextOperationTarget; import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
@ -96,6 +97,7 @@ import org.eclipse.ui.part.IShowInTargetList;
import org.eclipse.ui.part.ShowInContext; import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.texteditor.ChainedPreferenceStore; import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.ContentAssistAction;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
@ -850,9 +852,22 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
return null; return null;
} }
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 void startTabConversion() { private void startTabConversion() {
if (fTabConverter == null) { if (fTabConverter == null) {
fTabConverter = new TabConverter(); fTabConverter = new TabConverter();
configureTabConverter();
fTabConverter.setNumberOfSpacesPerTab(getPreferenceStore().getInt(CSourceViewerConfiguration.PREFERENCE_TAB_WIDTH)); fTabConverter.setNumberOfSpacesPerTab(getPreferenceStore().getInt(CSourceViewerConfiguration.PREFERENCE_TAB_WIDTH));
AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer(); AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
asv.addTextConverter(fTabConverter); asv.addTextConverter(fTabConverter);
@ -877,54 +892,79 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
} }
static class TabConverter implements ITextConverter { static class TabConverter implements ITextConverter {
private int fTabRatio;
private String fTabString = ""; //$NON-NLS-1$ private ILineTracker fLineTracker;
private int tabRatio = 0;
public TabConverter() {
}
public void setNumberOfSpacesPerTab(int ratio) { public void setNumberOfSpacesPerTab(int ratio) {
tabRatio = ratio; fTabRatio= ratio;
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < ratio; i++)
buffer.append(' ');
fTabString = buffer.toString();
} }
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) { public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
String text = command.text; String text= command.text;
StringBuffer buffer = new StringBuffer(); if (text == null)
final String TAB = "\t"; //$NON-NLS-1$ return;
// create tokens including the tabs
StringTokenizer tokens = new StringTokenizer(text, TAB, true); int index= text.indexOf('\t');
if (index > -1) {
int charCount = 0;
try { StringBuffer buffer= new StringBuffer();
// get offset of insertion less start of line
// buffer to determine how many characters fLineTracker.set(command.text);
// are already on this line and adjust tabs accordingly int lines= fLineTracker.getNumberOfLines();
charCount = command.offset - (document.getLineInformationOfOffset(command.offset).getOffset());
} catch (Exception ex) { try {
} for (int i= 0; i < lines; i++) {
String nextToken = null; int offset= fLineTracker.getLineOffset(i);
int spaces = 0; int endOffset= offset + fLineTracker.getLineLength(i);
while (tokens.hasMoreTokens()) { String line= text.substring(offset, endOffset);
nextToken = tokens.nextToken();
if (TAB.equals(nextToken)) { int position= 0;
spaces = tabRatio - (charCount % tabRatio); if (i == 0) {
IRegion firstLine= document.getLineInformationOfOffset(command.offset);
for (int i = 0; i < spaces; i++) { position= command.offset - firstLine.getOffset();
buffer.append(' '); }
}
int length= line.length();
charCount += spaces; for (int j= 0; j < length; j++) {
} else { char c= line.charAt(j);
buffer.append(nextToken); if (c == '\t') {
charCount += nextToken.length(); position += insertTabString(buffer, position);
} else {
buffer.append(c);
++ position;
}
}
}
command.text= buffer.toString();
} catch (BadLocationException x) {
} }
} }
command.text = buffer.toString();
} }
} }
/* Source code language to display */ /* Source code language to display */