mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +02:00
Fix for 178561: Strange behavior of Apply/OK on Code Style edit dialog
This commit is contained in:
parent
223e10318b
commit
aff281c499
4 changed files with 84 additions and 61 deletions
|
@ -23,13 +23,13 @@ import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
|||
|
||||
public class BracesTabPage extends ModifyDialogTabPage {
|
||||
|
||||
// /**
|
||||
// * Constant array for boolean selection
|
||||
// */
|
||||
// private static String[] FALSE_TRUE = {
|
||||
// DefaultCodeFormatterConstants.FALSE,
|
||||
// DefaultCodeFormatterConstants.TRUE
|
||||
// };
|
||||
/**
|
||||
* Constant array for boolean selection
|
||||
*/
|
||||
private static String[] FALSE_TRUE = {
|
||||
DefaultCodeFormatterConstants.FALSE,
|
||||
DefaultCodeFormatterConstants.TRUE
|
||||
};
|
||||
|
||||
/**
|
||||
* Some C++ source code used for preview.
|
||||
|
|
|
@ -28,6 +28,14 @@ import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
|||
|
||||
public class IndentationTabPage extends ModifyDialogTabPage {
|
||||
|
||||
/**
|
||||
* Constant array for boolean selection
|
||||
*/
|
||||
private static String[] FALSE_TRUE = {
|
||||
DefaultCodeFormatterConstants.FALSE,
|
||||
DefaultCodeFormatterConstants.TRUE
|
||||
};
|
||||
|
||||
/**
|
||||
* Some C++ source code used for preview.
|
||||
*/
|
||||
|
|
|
@ -25,8 +25,6 @@ import org.eclipse.core.runtime.IStatus;
|
|||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.cdt.internal.ui.preferences.formatter.ModifyDialogTabPage;
|
||||
import org.eclipse.cdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
|
@ -50,6 +48,8 @@ import org.eclipse.swt.widgets.TabItem;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||
import org.eclipse.cdt.internal.ui.preferences.formatter.ModifyDialogTabPage.IModificationListener;
|
||||
import org.eclipse.cdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile;
|
||||
import org.eclipse.cdt.internal.ui.preferences.formatter.ProfileManager.Profile;
|
||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||
|
@ -57,21 +57,22 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
|
|||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
|
||||
|
||||
public abstract class ModifyDialog extends StatusDialog {
|
||||
public abstract class ModifyDialog extends StatusDialog implements IModificationListener {
|
||||
|
||||
/**
|
||||
* The keys to retrieve the preferred area from the dialog settings.
|
||||
*/
|
||||
private static final String DS_KEY_PREFERRED_WIDTH= CUIPlugin.PLUGIN_ID + "formatter_page.modify_dialog.preferred_width"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_PREFERRED_HEIGHT= CUIPlugin.PLUGIN_ID + "formatter_page.modify_dialog.preferred_height"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_PREFERRED_X= CUIPlugin.PLUGIN_ID + "formatter_page.modify_dialog.preferred_x"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_PREFERRED_Y= CUIPlugin.PLUGIN_ID + "formatter_page.modify_dialog.preferred_y"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_PREFERRED_WIDTH= "modify_dialog.preferred_width"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_PREFERRED_HEIGHT= "modify_dialog.preferred_height"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_PREFERRED_X= "modify_dialog.preferred_x"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_PREFERRED_Y= "modify_dialog.preferred_y"; //$NON-NLS-1$
|
||||
|
||||
|
||||
/**
|
||||
* The key to store the number (beginning at 0) of the tab page which had the
|
||||
* focus last time.
|
||||
*/
|
||||
private static final String DS_KEY_LAST_FOCUS= CUIPlugin.PLUGIN_ID + "formatter_page.modify_dialog.last_focus"; //$NON-NLS-1$
|
||||
private static final String DS_KEY_LAST_FOCUS= "modify_dialog.last_focus"; //$NON-NLS-1$
|
||||
|
||||
private static final int APPLAY_BUTTON_ID= IDialogConstants.CLIENT_ID;
|
||||
private static final int SAVE_BUTTON_ID= IDialogConstants.CLIENT_ID + 1;
|
||||
|
@ -119,7 +120,7 @@ public abstract class ModifyDialog extends StatusDialog {
|
|||
}
|
||||
|
||||
protected abstract void addPages(Map values);
|
||||
|
||||
|
||||
public void create() {
|
||||
super.create();
|
||||
int lastFocusNr= 0;
|
||||
|
@ -221,12 +222,12 @@ public abstract class ModifyDialog extends StatusDialog {
|
|||
|
||||
public boolean close() {
|
||||
final Rectangle shell= getShell().getBounds();
|
||||
|
||||
|
||||
fDialogSettings.put(fKeyPreferredWidth, shell.width);
|
||||
fDialogSettings.put(fKeyPreferredHight, shell.height);
|
||||
fDialogSettings.put(fKeyPreferredX, shell.x);
|
||||
fDialogSettings.put(fKeyPreferredY, shell.y);
|
||||
|
||||
|
||||
return super.close();
|
||||
}
|
||||
|
||||
|
@ -257,7 +258,7 @@ public abstract class ModifyDialog extends StatusDialog {
|
|||
fProfileManager.setSelected(fProfile);
|
||||
doValidate();
|
||||
}
|
||||
|
||||
|
||||
private void saveButtonPressed() {
|
||||
Profile selected= new CustomProfile(fProfileNameField.getText(), new HashMap(fWorkingValues), fProfile.getVersion(), fProfileManager.getProfileVersioner().getProfileKind());
|
||||
|
||||
|
@ -306,9 +307,8 @@ public abstract class ModifyDialog extends StatusDialog {
|
|||
data.widthHint= layout.horizontalSpacing;
|
||||
label.setLayoutData(data);
|
||||
super.createButtonsForButtonBar(parent);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected final void addTabPage(String title, ModifyDialogTabPage tabPage) {
|
||||
final TabItem tabItem= new TabItem(fTabFolder, SWT.NONE);
|
||||
applyDialogFont(tabItem.getControl());
|
||||
|
@ -325,19 +325,14 @@ public abstract class ModifyDialog extends StatusDialog {
|
|||
protected void updateButtonsEnableState(IStatus status) {
|
||||
super.updateButtonsEnableState(status);
|
||||
if (fApplyButton != null && !fApplyButton.isDisposed()) {
|
||||
fApplyButton.setEnabled(!status.matches(IStatus.ERROR));
|
||||
fApplyButton.setEnabled(hasChanges() && !status.matches(IStatus.ERROR));
|
||||
}
|
||||
if (fSaveButton != null && !fSaveButton.isDisposed()) {
|
||||
fSaveButton.setEnabled(!validateProfileName().matches(IStatus.ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
private void doValidate() {
|
||||
if (!hasChanges()) {
|
||||
updateStatus(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "", null)); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
private void doValidate() {
|
||||
IStatus status= validateProfileName();
|
||||
if (status.matches(IStatus.ERROR)) {
|
||||
updateStatus(status);
|
||||
|
@ -381,6 +376,9 @@ public abstract class ModifyDialog extends StatusDialog {
|
|||
}
|
||||
|
||||
private boolean hasChanges() {
|
||||
if (!fProfileNameField.getText().trim().equals(fProfile.getName()))
|
||||
return true;
|
||||
|
||||
Iterator iter= fProfile.getSettings().entrySet().iterator();
|
||||
for (;iter.hasNext();) {
|
||||
Map.Entry curr= (Map.Entry) iter.next();
|
||||
|
@ -390,4 +388,5 @@ public abstract class ModifyDialog extends StatusDialog {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2007 IBM Corporation 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
|
||||
|
@ -42,8 +42,6 @@ import org.eclipse.swt.widgets.Group;
|
|||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||
|
@ -52,6 +50,14 @@ import org.eclipse.cdt.internal.ui.util.PixelConverter;
|
|||
|
||||
public abstract class ModifyDialogTabPage {
|
||||
|
||||
public interface IModificationListener {
|
||||
|
||||
void updateStatus(IStatus status);
|
||||
|
||||
void valuesModified();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the default listener for any of the Preference
|
||||
* classes. It is added by the respective factory methods and
|
||||
|
@ -142,7 +148,7 @@ public abstract class ModifyDialogTabPage {
|
|||
/**
|
||||
* Wrapper around a checkbox and a label.
|
||||
*/
|
||||
protected final class CheckboxPreference extends Preference {
|
||||
protected class ButtonPreference extends Preference {
|
||||
private final String[] fValues;
|
||||
private final Button fCheckbox;
|
||||
|
||||
|
@ -154,16 +160,17 @@ public abstract class ModifyDialogTabPage {
|
|||
* @param key The key to store the values.
|
||||
* @param values An array of two elements indicating the values to store on unchecked/checked.
|
||||
* @param text The label text for this Preference.
|
||||
* @param style SWT style flag for the button
|
||||
*/
|
||||
public CheckboxPreference(Composite composite, int numColumns,
|
||||
public ButtonPreference(Composite composite, int numColumns,
|
||||
Map preferences, String key,
|
||||
String [] values, String text) {
|
||||
String [] values, String text, int style) {
|
||||
super(preferences, key);
|
||||
if (values == null || text == null)
|
||||
throw new IllegalArgumentException(FormatterMessages.ModifyDialogTabPage_error_msg_values_text_unassigned);
|
||||
fValues= values;
|
||||
|
||||
fCheckbox= new Button(composite, SWT.CHECK);
|
||||
fCheckbox= new Button(composite, style);
|
||||
fCheckbox.setText(text);
|
||||
fCheckbox.setLayoutData(createGridData(numColumns, GridData.FILL_HORIZONTAL, SWT.DEFAULT));
|
||||
fCheckbox.setFont(composite.getFont());
|
||||
|
@ -197,11 +204,28 @@ public abstract class ModifyDialogTabPage {
|
|||
return fValues[1].equals(getPreferences().get(getKey()));
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
getPreferences().put(getKey(), checked ? fValues[1] : fValues[0]);
|
||||
updateWidget();
|
||||
checkboxChecked(checked);
|
||||
}
|
||||
|
||||
public Control getControl() {
|
||||
return fCheckbox;
|
||||
}
|
||||
}
|
||||
|
||||
protected final class CheckboxPreference extends ButtonPreference {
|
||||
public CheckboxPreference(Composite composite, int numColumns, Map preferences, String key, String[] values, String text) {
|
||||
super(composite, numColumns, preferences, key, values, text, SWT.CHECK);
|
||||
}
|
||||
}
|
||||
|
||||
protected final class RadioPreference extends ButtonPreference {
|
||||
public RadioPreference(Composite composite, int numColumns, Map preferences, String key, String[] values, String text) {
|
||||
super(composite, numColumns, preferences, key, values, text, SWT.RADIO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around a Combo box.
|
||||
|
@ -437,7 +461,7 @@ public abstract class ModifyDialogTabPage {
|
|||
*/
|
||||
protected final static class DefaultFocusManager extends FocusAdapter {
|
||||
|
||||
private final static String PREF_LAST_FOCUS_INDEX= CUIPlugin.PLUGIN_ID + "formatter_page.modify_dialog_tab_page.last_focus_index"; //$NON-NLS-1$
|
||||
private final static String PREF_LAST_FOCUS_INDEX= "formatter_page.modify_dialog_tab_page.last_focus_index"; //$NON-NLS-1$
|
||||
|
||||
private final IDialogSettings fDialogSettings;
|
||||
|
||||
|
@ -502,24 +526,6 @@ public abstract class ModifyDialogTabPage {
|
|||
* when they are created.
|
||||
*/
|
||||
protected final DefaultFocusManager fDefaultFocusManager;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constant array for boolean selection
|
||||
*/
|
||||
protected static String[] FALSE_TRUE = {
|
||||
DefaultCodeFormatterConstants.FALSE,
|
||||
DefaultCodeFormatterConstants.TRUE
|
||||
};
|
||||
|
||||
/**
|
||||
* Constant array for insert / not_insert.
|
||||
*/
|
||||
protected static String[] DO_NOT_INSERT_INSERT = {
|
||||
CCorePlugin.DO_NOT_INSERT,
|
||||
CCorePlugin.INSERT
|
||||
};
|
||||
|
||||
/**
|
||||
* A pixel converter for layout calculations
|
||||
|
@ -535,15 +541,15 @@ public abstract class ModifyDialogTabPage {
|
|||
/**
|
||||
* The modify dialog where we can display status messages.
|
||||
*/
|
||||
private final ModifyDialog fModifyDialog;
|
||||
private final IModificationListener fModifyListener;
|
||||
|
||||
|
||||
/*
|
||||
* Create a new <code>ModifyDialogTabPage</code>
|
||||
*/
|
||||
public ModifyDialogTabPage(ModifyDialog modifyDialog, Map workingValues) {
|
||||
public ModifyDialogTabPage(IModificationListener modifyListener, Map workingValues) {
|
||||
fWorkingValues= workingValues;
|
||||
fModifyDialog= modifyDialog;
|
||||
fModifyListener= modifyListener;
|
||||
fDefaultFocusManager= new DefaultFocusManager();
|
||||
}
|
||||
|
||||
|
@ -652,7 +658,7 @@ public abstract class ModifyDialogTabPage {
|
|||
protected abstract void doUpdatePreview();
|
||||
|
||||
protected void notifyValuesModified() {
|
||||
fModifyDialog.valuesModified();
|
||||
fModifyListener.valuesModified();
|
||||
}
|
||||
/**
|
||||
* Each tab page should remember where its last focus was, and reset it
|
||||
|
@ -673,7 +679,7 @@ public abstract class ModifyDialogTabPage {
|
|||
* @param status Status describing the current page error state
|
||||
*/
|
||||
protected void updateStatus(IStatus status) {
|
||||
fModifyDialog.updateStatus(status);
|
||||
fModifyListener.updateStatus(status);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -787,6 +793,16 @@ public abstract class ModifyDialogTabPage {
|
|||
return pref;
|
||||
}
|
||||
|
||||
protected RadioPreference createRadioPref(Composite composite, int numColumns, String name, String key,
|
||||
String [] values) {
|
||||
final RadioPreference pref= new RadioPreference(composite, numColumns,
|
||||
fWorkingValues, key, values, name);
|
||||
fDefaultFocusManager.add(pref);
|
||||
pref.addObserver(fUpdater);
|
||||
return pref;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a nice javadoc comment for some string.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue