Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSergey Prigogin2009-04-25 22:46:49 +0000
committerSergey Prigogin2009-04-25 22:46:49 +0000
commit5c017b1daf67a94393983f05f879349fcd64a024 (patch)
tree92794c0bfd7ba37d74b74d27a3dda928fa2c6fcc /core
parent02d1f6533a2672c9239141b0b6e40c8e7b624f34 (diff)
downloadorg.eclipse.cdt-5c017b1daf67a94393983f05f879349fcd64a024.tar.gz
org.eclipse.cdt-5c017b1daf67a94393983f05f879349fcd64a024.tar.xz
org.eclipse.cdt-5c017b1daf67a94393983f05f879349fcd64a024.zip
Bug 249359. An option to remove trailing whitespace in either edited or all lines. End-of-file newline doesn't depend on changed lines. Separate preference page for save actions.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.ui/plugin.properties4
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml11
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java51
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AbstractPreferencePage.java3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java37
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java7
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/SaveActionsPreferencePage.java117
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java11
11 files changed, 198 insertions, 56 deletions
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 17645fdfa15..18dcdd07d0c 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -182,7 +182,8 @@ SmartTypingPreferencePage.name=Typing
ColoringPreferencePage.name=Syntax Coloring
FoldingPreferencePage.name=Folding
HoverPreferencePage.name=Hovers
-markOccurrencesPreferencePage.name= Mark Occurrences
+markOccurrencesPreferencePage.name=Mark Occurrences
+SaveActionsPreferencePage.name=Save Actions
ScalabilityPreferencePage.name=Scalability
DefaultBinaryFileEditor.name = Default Binary File Editor
@@ -528,6 +529,7 @@ preferenceKeywords.indexer=index skip references type macro search build configu
preferenceKeywords.ceditor=editor appearance navigation colors smart caret positioning highlight matching bracket inactive code foreground background save trailing whitespace newline doxygen
preferenceKeywords.contentassist=editor content code assist complete completion insert overwrite single proposal common prefix automatically auto activation trigger category categories separate specific word hippie template
+preferenceKeywords.saveactions=editor save trailing whitespace white space end file newline
preferenceKeywords.scalability=editor mode large file lines disable performance
preferenceKeywords.hover=editor hover annotation key modifier combined variable problem string source documentation
preferenceKeywords.syntaxcoloring=editor colors semantic coloring highlighting multi line single line comment task tag class struct union function method static field constant keywords local variable operators brackets strings type variable inherited method declaration
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index cf2b98745a5..7f5d1feabbd 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -710,6 +710,14 @@
<keywordReference id="org.eclipse.cdt.ui.common"/>
</page>
<page
+ name="%SaveActionsPreferencePage.name"
+ category="org.eclipse.cdt.ui.preferences.CEditorPreferencePage"
+ class="org.eclipse.cdt.internal.ui.preferences.SaveActionsPreferencePage"
+ id="org.eclipse.cdt.ui.preferences.SaveActionsPreferencePage">
+ <keywordReference id="org.eclipse.cdt.ui.saveactions"/>
+ <keywordReference id="org.eclipse.cdt.ui.common"/>
+ </page>
+ <page
name="%ScalabilityPreferencePage.name"
category="org.eclipse.cdt.ui.preferences.CEditorPreferencePage"
class="org.eclipse.cdt.internal.ui.preferences.ScalabilityPreferencePage"
@@ -756,6 +764,9 @@
label="%preferenceKeywords.hover"
id="org.eclipse.cdt.ui.hover"/>
<keyword
+ label="%preferenceKeywords.saveactions"
+ id="org.eclipse.cdt.ui.saveactions"/>
+ <keyword
label="%preferenceKeywords.scalability"
id="org.eclipse.cdt.ui.scalability"/>
<keyword
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
index a590352116b..c06f6b3ac73 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/ICHelpContextIds.java
@@ -167,6 +167,6 @@ public interface ICHelpContextIds {
public static final String PATHENTRY_VARIABLES_PREFERENCE_PAGE= PREFIX + "pathentry_variables_preference_page_context"; //$NON-NLS-1$
+ public static final String SAVE_ACTIONS_PREFERENCE_PAGE = PREFIX + "save_actions_preference_page_context"; //$NON-NLS-1$
public static final String SCALABILITY_PREFERENCE_PAGE = PREFIX + "scalability_preference_page_context"; //$NON-NLS-1$
-
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
index a3653cc433b..beac159469c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
@@ -41,6 +41,7 @@ import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
@@ -1037,7 +1038,9 @@ public class CDocumentProvider extends TextFileDocumentProvider {
*/
private void performSaveActions(ITextFileBuffer buffer, IProgressMonitor monitor) throws CoreException {
if (shouldRemoveTrailingWhitespace() || shouldAddNewlineAtEof()) {
- IRegion[] changedRegions= EditorUtility.calculateChangedLineRegions(buffer, getSubProgressMonitor(monitor, 20));
+ IRegion[] changedRegions= needsChangedRegions() ?
+ EditorUtility.calculateChangedLineRegions(buffer, getSubProgressMonitor(monitor, 20)) :
+ null;
IDocument document = buffer.getDocument();
TextEdit edit = createSaveActionEdit(document, changedRegions);
if (edit != null) {
@@ -1071,14 +1074,28 @@ public class CDocumentProvider extends TextFileDocumentProvider {
PreferenceConstants.REMOVE_TRAILING_WHITESPACE);
}
+ private static boolean isLimitedRemoveTrailingWhitespace() {
+ return PreferenceConstants.getPreferenceStore().getBoolean(
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE_LIMIT_TO_EDITED_LINES);
+ }
+
+ private static boolean needsChangedRegions() {
+ return shouldRemoveTrailingWhitespace() && isLimitedRemoveTrailingWhitespace();
+ }
+
/**
* Creates a text edit for the save actions.
* @return a text edit, or <code>null</code> if the save actions leave the file intact.
*/
private TextEdit createSaveActionEdit(IDocument document, IRegion[] changedRegions) {
TextEdit rootEdit = null;
+ TextEdit lastWhitespaceEdit = null;
try {
if (shouldRemoveTrailingWhitespace()) {
+ if (!isLimitedRemoveTrailingWhitespace()) {
+ // Pretend that the whole document changed.
+ changedRegions = new IRegion[] { new Region(0, document.getLength()) };
+ }
// Remove trailing whitespace from changed lines.
for (IRegion region : changedRegions) {
int firstLine = document.getLineOfOffset(region.getOffset());
@@ -1098,11 +1115,11 @@ public class CDocumentProvider extends TextFileDocumentProvider {
charPos++;
if (charPos < lineEnd) {
- TextEdit edit= new DeleteEdit(charPos, lineEnd - charPos);
+ lastWhitespaceEdit= new DeleteEdit(charPos, lineEnd - charPos);
if (rootEdit == null) {
rootEdit = new MultiTextEdit();
}
- rootEdit.addChild(edit);
+ rootEdit.addChild(lastWhitespaceEdit);
}
}
}
@@ -1111,22 +1128,18 @@ public class CDocumentProvider extends TextFileDocumentProvider {
// Add newline at the end of the file.
int endOffset = document.getLength();
IRegion lastLineRegion = document.getLineInformationOfOffset(endOffset);
- if (lastLineRegion.getLength() != 0) {
- for (IRegion region : changedRegions) {
- if (region.getOffset() + region.getLength() >= lastLineRegion.getOffset()) {
- // Last line has changed
- if (!shouldRemoveTrailingWhitespace() || !isWhitespaceRegion(document, lastLineRegion)) {
- TextEdit edit = new InsertEdit(endOffset,
- TextUtilities.getDefaultLineDelimiter(document));
- if (rootEdit == null) {
- rootEdit = edit;
- } else {
- rootEdit.addChild(edit);
- }
- }
- break;
- }
- }
+ // Insert newline at the end of the document if the last line is not empty and
+ // will not become empty after removal of trailing whitespace.
+ if (lastLineRegion.getLength() != 0 &&
+ (lastWhitespaceEdit == null ||
+ lastWhitespaceEdit.getOffset() != lastLineRegion.getOffset() ||
+ lastWhitespaceEdit.getLength() != lastLineRegion.getLength())) {
+ TextEdit edit = new InsertEdit(endOffset, TextUtilities.getDefaultLineDelimiter(document));
+ if (rootEdit == null) {
+ rootEdit = edit;
+ } else {
+ rootEdit.addChild(edit);
+ }
}
}
} catch (BadLocationException e) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AbstractPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AbstractPreferencePage.java
index ae34e13950c..e51614364b0 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AbstractPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/AbstractPreferencePage.java
@@ -120,7 +120,8 @@ public abstract class AbstractPreferencePage extends PreferencePage implements I
radioButton.setLayoutData(gd);
radioButton.addSelectionListener(fCheckBoxListener);
- fCheckBoxes.put(radioButton, key);
+ if (key != null)
+ fCheckBoxes.put(radioButton, key);
return radioButton;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
index 7e21f0eacbf..fd057006287 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CEditorPreferencePage.java
@@ -81,8 +81,6 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, CEditor.MATCHING_BRACKETS));
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));
@@ -228,22 +226,6 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
return behaviorComposite;
}
- private Control createSaveActionsBlock(Composite parent) {
- Composite saveActionsComposite= ControlFactory.createGroup(parent, PreferencesMessages.CEditorPreferencePage_SaveActionsTitle, 1);
-
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- saveActionsComposite.setLayout(layout);
-
- String label = PreferencesMessages.CEditorPreferencePage_behaviorPage_removeTrailingWhitespace;
- addCheckBox(saveActionsComposite, label, PreferenceConstants.REMOVE_TRAILING_WHITESPACE, 0);
-
- label = PreferencesMessages.CEditorPreferencePage_behaviorPage_ensureNewline;
- addCheckBox(saveActionsComposite, label, PreferenceConstants.ENSURE_NEWLINE_AT_EOF, 0);
-
- return saveActionsComposite;
- }
-
private void handleAppearanceColorListSelection() {
int i = fAppearanceColorList.getSelectionIndex();
String key = fAppearanceColorListModel[i][1];
@@ -293,25 +275,25 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
fOverlayStore.load();
fOverlayStore.start();
- createHeader(parent);
+ Composite contents= ControlFactory.createComposite(parent, 1);
+ contents.setLayoutData(new GridData(GridData.FILL_BOTH));
- ControlFactory.createEmptySpace(parent, 2);
- createBehaviorBlock(parent);
+ createHeader(contents);
- ControlFactory.createEmptySpace(parent, 2);
- createSaveActionsBlock(parent);
+ ControlFactory.createEmptySpace(contents, 2);
+ createBehaviorBlock(contents);
- ControlFactory.createEmptySpace(parent, 2);
+ ControlFactory.createEmptySpace(contents, 2);
String dsc= PreferencesMessages.CEditorPreferencePage_SelectDocToolDescription;
String msg= PreferencesMessages.CEditorPreferencePage_WorkspaceDefaultLabel;
IDocCommentOwner workspaceOwner= DocCommentOwnerManager.getInstance().getWorkspaceCommentOwner();
- fDocCommentOwnerComposite= new DocCommentOwnerComposite(parent, workspaceOwner, dsc, msg);
- fDocCommentOwnerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true,false).create());
+ fDocCommentOwnerComposite= new DocCommentOwnerComposite(contents, workspaceOwner, dsc, msg);
+ fDocCommentOwnerComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
initialize();
- return parent;
+ return contents;
}
private void initialize() {
@@ -357,5 +339,4 @@ public class CEditorPreferencePage extends AbstractPreferencePage {
initializeDefaultColors();
handleAppearanceColorListSelection();
}
-
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java
index 5e2e8a39c2c..745aacda392 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java
@@ -171,7 +171,7 @@ class MarkOccurrencesConfigurationBlock implements IPreferenceConfigurationBlock
private static void indent(Control control) {
GridData gridData= new GridData();
- gridData.horizontalIndent= 10;
+ gridData.horizontalIndent= 20;
control.setLayoutData(gridData);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
index 1ea3022f373..c6d3438c1df 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java
@@ -90,8 +90,6 @@ public final class PreferencesMessages extends NLS {
public static String CEditorColoringConfigurationBlock_underline;
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;
@@ -186,6 +184,11 @@ public final class PreferencesMessages extends NLS {
public static String CEditorPreferencePage_typing_smartTab;
public static String CEditorPreferencePage_WorkspaceDefaultLabel;
+ public static String SaveActionsPreferencePage_removeTrailingWhitespace;
+ public static String SaveActionsPreferencePage_inEditedLines;
+ public static String SaveActionsPreferencePage_inAllLines;
+ public static String SaveActionsPreferencePage_ensureNewline;
+
public static String SmartTypingConfigurationBlock_autoclose_title;
public static String SmartTypingConfigurationBlock_autoindent_newlines;
public static String SmartTypingConfigurationBlock_autoindent_title;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
index 5518298716f..e6a30fd23d1 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties
@@ -29,7 +29,7 @@ CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder=Present
CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle=Auto-Activation
CEditorPreferencePage_ContentAssistPage_autoActivationEnableDot=Enable "." as trigger
CEditorPreferencePage_ContentAssistPage_autoActivationEnableArrow=Enable "->" as trigger
-CEditorPreferencePage_ContentAssistPage_autoActivationDelay=dela&y (ms)
+CEditorPreferencePage_ContentAssistPage_autoActivationDelay=Dela&y (ms)
CEditorPreferencePage_ContentAssistPage_proposalFilterSelect=Completion Proposal Filter:
CEditorPreferencePage_ContentAssistPage_completionProposalBackgroundColor=Completion proposal background
CEditorPreferencePage_ContentAssistPage_completionProposalForegroundColor=Completion proposal foreground
@@ -85,8 +85,6 @@ CEditorColoringConfigurationBlock_underline=&Underline
CEditorColoringConfigurationBlock_strikethrough=&Strikethrough
CEditorPreferencePage_colorPage_systemDefault=S&ystem Default
-CEditorPreferencePage_behaviorPage_removeTrailingWhitespace=Remove trailing &whitespace in edited lines
-CEditorPreferencePage_behaviorPage_ensureNewline=Ensure &newline at the end of file
CEditorPreferencePage_behaviorPage_matchingBrackets=Highlight &matching brackets
CEditorPreferencePage_behaviorPage_subWordNavigation=Smart &caret positioning in identifiers
CEditorPreferencePage_behaviorPage_inactiveCode=Highlight &inactive code
@@ -95,6 +93,11 @@ CEditorPreferencePage_behaviorPage_matchingBracketColor=Matching brackets highli
CEditorPreferencePage_behaviorPage_inactiveCodeColor=Inactive code highlight
CEditorPreferencePage_behaviorPage_Color=Color:
+SaveActionsPreferencePage_removeTrailingWhitespace=Remove trailing &whitespace
+SaveActionsPreferencePage_inEditedLines=In &edited lines
+SaveActionsPreferencePage_inAllLines=In a&ll lines
+SaveActionsPreferencePage_ensureNewline=Ensure &newline at the end of file
+
TemplatePreferencePage_Viewer_preview=Preview:
CFileTypesPreferencePage_description=C/C++ File Types
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/SaveActionsPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/SaveActionsPreferencePage.java
new file mode 100644
index 00000000000..3bb657f1709
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/SaveActionsPreferencePage.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Google, Inc 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:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.preferences;
+
+import java.util.ArrayList;
+
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.utils.ui.controls.ControlFactory;
+
+import org.eclipse.cdt.internal.ui.ICHelpContextIds;
+import org.eclipse.cdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
+
+/*
+ * The page for configuring actions performed when a C/C++ file is saved.
+ */
+public class SaveActionsPreferencePage extends AbstractPreferencePage {
+ private Button fRadioEditedLines;
+ private Button fRadioAllLines;
+
+ public SaveActionsPreferencePage() {
+ super();
+ }
+
+ @Override
+ protected OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
+ ArrayList<OverlayKey> overlayKeys = new ArrayList<OverlayKey>();
+
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE));
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE_LIMIT_TO_EDITED_LINES));
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.ENSURE_NEWLINE_AT_EOF));
+
+ OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
+ overlayKeys.toArray(keys);
+ return keys;
+ }
+
+ /*
+ * @see PreferencePage#createControl(Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
+ ICHelpContextIds.SAVE_ACTIONS_PREFERENCE_PAGE);
+ }
+
+ // sets enabled flag for a control and all its sub-tree
+ protected static void setEnabled(Control control, boolean enable) {
+ control.setEnabled(enable);
+ if (control instanceof Composite) {
+ Composite composite = (Composite) control;
+ Control[] children = composite.getChildren();
+ for (Control element : children)
+ setEnabled(element, enable);
+ }
+ }
+
+ private Control createConfigurationBlock(Composite parent) {
+ Composite composite= ControlFactory.createComposite(parent, 1);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ String label = PreferencesMessages.SaveActionsPreferencePage_removeTrailingWhitespace;
+ Button checkboxTrailingWhitespace = addCheckBox(composite, label,
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE, 0);
+ fRadioEditedLines = addRadioButton(composite, PreferencesMessages.SaveActionsPreferencePage_inEditedLines,
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE_LIMIT_TO_EDITED_LINES, 0);
+ fRadioAllLines = addRadioButton(composite, PreferencesMessages.SaveActionsPreferencePage_inAllLines,
+ null, 0);
+ createDependency(checkboxTrailingWhitespace,
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE, fRadioEditedLines);
+ createDependency(checkboxTrailingWhitespace,
+ PreferenceConstants.REMOVE_TRAILING_WHITESPACE, fRadioAllLines);
+
+ ControlFactory.createEmptySpace(composite, 1);
+
+ label = PreferencesMessages.SaveActionsPreferencePage_ensureNewline;
+ addCheckBox(composite, label, PreferenceConstants.ENSURE_NEWLINE_AT_EOF, 0);
+
+ return composite;
+ }
+
+ /*
+ * @see PreferencePage#createContents(Composite)
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ fOverlayStore.load();
+ fOverlayStore.start();
+
+ createConfigurationBlock(parent);
+
+ initialize();
+ return parent;
+ }
+
+ private void initialize() {
+ initializeFields();
+ fRadioAllLines.setSelection(!fRadioEditedLines.getSelection());
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
index 9b66b1bf81d..6ac61779202 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java
@@ -947,6 +947,16 @@ public class PreferenceConstants {
public final static String REMOVE_TRAILING_WHITESPACE = "removeTrailingWhitespace"; //$NON-NLS-1$
/**
+ * Preference key controlling how REMOVE_TRAILING_WHITESPACE option is applied.
+ * If REMOVE_TRAILING_WHITESPACE is enabled, this option limits the scope of
+ * the removal to edited lines only. This option has no effect if
+ * REMOVE_TRAILING_WHITESPACE is disabled.
+ *
+ * @since 5.1
+ */
+ public final static String REMOVE_TRAILING_WHITESPACE_LIMIT_TO_EDITED_LINES = "removeTrailingWhitespaceEditedLines"; //$NON-NLS-1$
+
+ /**
* A named preference that defines whether the hint to make hover sticky should be shown.
*
* @since 3.1.1
@@ -1536,6 +1546,7 @@ public class PreferenceConstants {
store.setDefault(PreferenceConstants.EDITOR_AUTO_INDENT, true);
store.setDefault(PreferenceConstants.REMOVE_TRAILING_WHITESPACE, true);
+ store.setDefault(PreferenceConstants.REMOVE_TRAILING_WHITESPACE_LIMIT_TO_EDITED_LINES, true);
store.setDefault(PreferenceConstants.ENSURE_NEWLINE_AT_EOF, true);
// formatter profile

Back to the top