mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Patch for bug 203382 provided by Tor Arne Vestbø.
This commit is contained in:
parent
81011950d8
commit
54534b7ef0
5 changed files with 52 additions and 9 deletions
|
@ -45,6 +45,7 @@ import org.eclipse.jface.text.source.IAnnotationModelListener;
|
|||
import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.text.edits.DeleteEdit;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
|
@ -316,7 +317,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
|
||||
/**
|
||||
* Annotation model dealing with c marker annotations and temporary problems.
|
||||
* Also acts as problem requestor for its translation unit. Initialiy inactive. Must explicitly be
|
||||
* Also acts as a problem requestor for its translation unit. Initially inactive. Must be explicitly
|
||||
* activated.
|
||||
*/
|
||||
protected static class TranslationUnitAnnotationModel extends ResourceMarkerAnnotationModel implements IProblemRequestor, IProblemRequestorExtension {
|
||||
|
@ -502,7 +503,6 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
boolean temporaryProblemsChanged= false;
|
||||
|
||||
synchronized (getLockObject()) {
|
||||
|
||||
boolean isCanceled= false;
|
||||
|
||||
fPreviouslyOverlaid= fCurrentlyOverlaid;
|
||||
|
@ -515,7 +515,6 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
}
|
||||
|
||||
if (reportedProblems != null && reportedProblems.size() > 0) {
|
||||
|
||||
Iterator<IProblem> e= reportedProblems.iterator();
|
||||
while (e.hasNext()) {
|
||||
|
||||
|
@ -578,7 +577,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
}
|
||||
}
|
||||
|
||||
private void overlayMarkers(Position position, ProblemAnnotation problemAnnotation) {
|
||||
private void overlayMarkers(Position position, ProblemAnnotation problemAnnotation) {
|
||||
Object value= getAnnotations(position);
|
||||
if (value instanceof List) {
|
||||
List list= (List) value;
|
||||
|
@ -648,9 +647,9 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
|
||||
synchronized (getLockObject()) {
|
||||
Object cached= fReverseMap.get(position);
|
||||
if (cached == null)
|
||||
if (cached == null) {
|
||||
fReverseMap.put(position, annotation);
|
||||
else if (cached instanceof List) {
|
||||
} else if (cached instanceof List) {
|
||||
List<Annotation> list= (List<Annotation>) cached;
|
||||
list.add(annotation);
|
||||
} else if (cached instanceof Annotation) {
|
||||
|
@ -956,8 +955,38 @@ public class CDocumentProvider extends TextFileDocumentProvider {
|
|||
// empty files.
|
||||
int lastLineLength = document.getLineLength(lastLineIndex);
|
||||
if (lastLineLength != 0) {
|
||||
document.replace(document.getLength(), 0, TextUtilities
|
||||
.getDefaultLineDelimiter(document));
|
||||
document.replace(document.getLength(), 0,
|
||||
TextUtilities.getDefaultLineDelimiter(document));
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove trailing whitespace when saving. Triggered by the flag
|
||||
// in Preferences -> C/C++ -> Editor
|
||||
if (PreferenceConstants.getPreferenceStore().getBoolean(
|
||||
PreferenceConstants.REMOVE_TRAILING_WHITESPACE)) {
|
||||
try {
|
||||
int lineCount= document.getNumberOfLines();
|
||||
for (int i= 0; i < lineCount; i++) {
|
||||
|
||||
IRegion region= document.getLineInformation(i);
|
||||
if (region.getLength() == 0)
|
||||
continue;
|
||||
|
||||
int lineStart= region.getOffset();
|
||||
int lineExclusiveEnd= lineStart + region.getLength();
|
||||
|
||||
// Find the rightmost none-whitespace character
|
||||
int charPos= lineExclusiveEnd - 1;
|
||||
while (charPos >= lineStart && Character.isWhitespace(document.getChar(charPos)))
|
||||
charPos--;
|
||||
|
||||
charPos++;
|
||||
if (charPos < lineExclusiveEnd) {
|
||||
DeleteEdit edit= new DeleteEdit(charPos, lineExclusiveEnd - charPos);
|
||||
edit.apply(document);
|
||||
}
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
|
|||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, CEditor.INACTIVE_CODE_COLOR));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, CEditor.INACTIVE_CODE_ENABLE));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.ENSURE_NEWLINE_AT_EOF));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.REMOVE_TRAILING_WHITESPACE));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PROPOSALS_BACKGROUND));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PROPOSALS_FOREGROUND));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.PARAMETERS_BACKGROUND));
|
||||
|
@ -142,7 +143,10 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
|
|||
|
||||
label = PreferencesMessages.CEditorPreferencePage_behaviorPage_ensureNewline;
|
||||
addCheckBox(behaviorComposite, label, PreferenceConstants.ENSURE_NEWLINE_AT_EOF, 0);
|
||||
|
||||
|
||||
label = PreferencesMessages.CEditorPreferencePage_behaviorPage_removeTrailingWhitespace;
|
||||
addCheckBox(behaviorComposite, label, PreferenceConstants.REMOVE_TRAILING_WHITESPACE, 0);
|
||||
|
||||
Label l = new Label(behaviorComposite, SWT.LEFT);
|
||||
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
|
||||
gd.horizontalSpan = 2;
|
||||
|
|
|
@ -91,6 +91,7 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String CEditorColoringConfigurationBlock_strikethrough;
|
||||
public static String CEditorPreferencePage_colorPage_systemDefault;
|
||||
public static String CEditorPreferencePage_behaviorPage_ensureNewline;
|
||||
public static String CEditorPreferencePage_behaviorPage_removeTrailingWhitespace;
|
||||
public static String CEditorPreferencePage_behaviorPage_matchingBrackets;
|
||||
public static String CEditorPreferencePage_behaviorPage_subWordNavigation;
|
||||
public static String CEditorPreferencePage_behaviorPage_inactiveCode;
|
||||
|
|
|
@ -86,6 +86,7 @@ CEditorColoringConfigurationBlock_strikethrough=&Strikethrough
|
|||
|
||||
CEditorPreferencePage_colorPage_systemDefault=S&ystem Default
|
||||
CEditorPreferencePage_behaviorPage_ensureNewline=Ensure &newline at end of file when saving
|
||||
CEditorPreferencePage_behaviorPage_removeTrailingWhitespace=Remove trailing &whitespace when saving
|
||||
CEditorPreferencePage_behaviorPage_matchingBrackets=Highlight &matching brackets
|
||||
CEditorPreferencePage_behaviorPage_subWordNavigation=Smart &caret positioning in identifiers
|
||||
CEditorPreferencePage_behaviorPage_inactiveCode=Highlight &inactive code
|
||||
|
|
|
@ -927,6 +927,13 @@ public class PreferenceConstants {
|
|||
*/
|
||||
public final static String ENSURE_NEWLINE_AT_EOF = "ensureNewlineAtEOF"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Preference key for whether to remove trailing whitespace when saving.
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public final static String REMOVE_TRAILING_WHITESPACE = "removeTrailingWhitespace"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* A named preference that defines whether the hint to make hover sticky should be shown.
|
||||
*
|
||||
|
@ -1410,6 +1417,7 @@ public class PreferenceConstants {
|
|||
store.setDefault(PreferenceConstants.EDITOR_AUTO_INDENT, true);
|
||||
|
||||
store.setDefault(PreferenceConstants.ENSURE_NEWLINE_AT_EOF, false);
|
||||
store.setDefault(PreferenceConstants.REMOVE_TRAILING_WHITESPACE, false);
|
||||
|
||||
// formatter profile
|
||||
store.setDefault(PreferenceConstants.FORMATTER_PROFILE, FormatterProfileManager.DEFAULT_PROFILE);
|
||||
|
|
Loading…
Add table
Reference in a new issue