1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 13:25:45 +02:00

Fix for 178561: Strange behavior of Apply/OK on Code Style edit dialog

This commit is contained in:
Anton Leherbauer 2007-03-27 09:30:14 +00:00
parent 223e10318b
commit aff281c499
4 changed files with 84 additions and 61 deletions

View file

@ -23,13 +23,13 @@ import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
public class BracesTabPage extends ModifyDialogTabPage { public class BracesTabPage extends ModifyDialogTabPage {
// /** /**
// * Constant array for boolean selection * Constant array for boolean selection
// */ */
// private static String[] FALSE_TRUE = { private static String[] FALSE_TRUE = {
// DefaultCodeFormatterConstants.FALSE, DefaultCodeFormatterConstants.FALSE,
// DefaultCodeFormatterConstants.TRUE DefaultCodeFormatterConstants.TRUE
// }; };
/** /**
* Some C++ source code used for preview. * Some C++ source code used for preview.

View file

@ -28,6 +28,14 @@ import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
public class IndentationTabPage extends ModifyDialogTabPage { 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. * Some C++ source code used for preview.
*/ */

View file

@ -25,8 +25,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType; 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.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog; 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.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; 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.preferences.formatter.ProfileManager.Profile;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler; import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.internal.ui.util.Messages; 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.IDialogFieldListener;
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField; 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. * 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_WIDTH= "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_HEIGHT= "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_X= "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_Y= "modify_dialog.preferred_y"; //$NON-NLS-1$
/** /**
* The key to store the number (beginning at 0) of the tab page which had the * The key to store the number (beginning at 0) of the tab page which had the
* focus last time. * 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 APPLAY_BUTTON_ID= IDialogConstants.CLIENT_ID;
private static final int SAVE_BUTTON_ID= IDialogConstants.CLIENT_ID + 1; private static final int SAVE_BUTTON_ID= IDialogConstants.CLIENT_ID + 1;
@ -308,7 +309,6 @@ public abstract class ModifyDialog extends StatusDialog {
super.createButtonsForButtonBar(parent); super.createButtonsForButtonBar(parent);
} }
protected final void addTabPage(String title, ModifyDialogTabPage tabPage) { protected final void addTabPage(String title, ModifyDialogTabPage tabPage) {
final TabItem tabItem= new TabItem(fTabFolder, SWT.NONE); final TabItem tabItem= new TabItem(fTabFolder, SWT.NONE);
applyDialogFont(tabItem.getControl()); applyDialogFont(tabItem.getControl());
@ -325,7 +325,7 @@ public abstract class ModifyDialog extends StatusDialog {
protected void updateButtonsEnableState(IStatus status) { protected void updateButtonsEnableState(IStatus status) {
super.updateButtonsEnableState(status); super.updateButtonsEnableState(status);
if (fApplyButton != null && !fApplyButton.isDisposed()) { if (fApplyButton != null && !fApplyButton.isDisposed()) {
fApplyButton.setEnabled(!status.matches(IStatus.ERROR)); fApplyButton.setEnabled(hasChanges() && !status.matches(IStatus.ERROR));
} }
if (fSaveButton != null && !fSaveButton.isDisposed()) { if (fSaveButton != null && !fSaveButton.isDisposed()) {
fSaveButton.setEnabled(!validateProfileName().matches(IStatus.ERROR)); fSaveButton.setEnabled(!validateProfileName().matches(IStatus.ERROR));
@ -333,11 +333,6 @@ public abstract class ModifyDialog extends StatusDialog {
} }
private void doValidate() { private void doValidate() {
if (!hasChanges()) {
updateStatus(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "", null)); //$NON-NLS-1$
return;
}
IStatus status= validateProfileName(); IStatus status= validateProfileName();
if (status.matches(IStatus.ERROR)) { if (status.matches(IStatus.ERROR)) {
updateStatus(status); updateStatus(status);
@ -381,6 +376,9 @@ public abstract class ModifyDialog extends StatusDialog {
} }
private boolean hasChanges() { private boolean hasChanges() {
if (!fProfileNameField.getText().trim().equals(fProfile.getName()))
return true;
Iterator iter= fProfile.getSettings().entrySet().iterator(); Iterator iter= fProfile.getSettings().entrySet().iterator();
for (;iter.hasNext();) { for (;iter.hasNext();) {
Map.Entry curr= (Map.Entry) iter.next(); Map.Entry curr= (Map.Entry) iter.next();
@ -390,4 +388,5 @@ public abstract class ModifyDialog extends StatusDialog {
} }
return false; return false;
} }
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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.Label;
import org.eclipse.swt.widgets.Text; 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.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.Messages; 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 abstract class ModifyDialogTabPage {
public interface IModificationListener {
void updateStatus(IStatus status);
void valuesModified();
}
/** /**
* This is the default listener for any of the Preference * This is the default listener for any of the Preference
* classes. It is added by the respective factory methods and * 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. * Wrapper around a checkbox and a label.
*/ */
protected final class CheckboxPreference extends Preference { protected class ButtonPreference extends Preference {
private final String[] fValues; private final String[] fValues;
private final Button fCheckbox; private final Button fCheckbox;
@ -154,16 +160,17 @@ public abstract class ModifyDialogTabPage {
* @param key The key to store the values. * @param key The key to store the values.
* @param values An array of two elements indicating the values to store on unchecked/checked. * @param values An array of two elements indicating the values to store on unchecked/checked.
* @param text The label text for this Preference. * @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, Map preferences, String key,
String [] values, String text) { String [] values, String text, int style) {
super(preferences, key); super(preferences, key);
if (values == null || text == null) if (values == null || text == null)
throw new IllegalArgumentException(FormatterMessages.ModifyDialogTabPage_error_msg_values_text_unassigned); throw new IllegalArgumentException(FormatterMessages.ModifyDialogTabPage_error_msg_values_text_unassigned);
fValues= values; fValues= values;
fCheckbox= new Button(composite, SWT.CHECK); fCheckbox= new Button(composite, style);
fCheckbox.setText(text); fCheckbox.setText(text);
fCheckbox.setLayoutData(createGridData(numColumns, GridData.FILL_HORIZONTAL, SWT.DEFAULT)); fCheckbox.setLayoutData(createGridData(numColumns, GridData.FILL_HORIZONTAL, SWT.DEFAULT));
fCheckbox.setFont(composite.getFont()); fCheckbox.setFont(composite.getFont());
@ -197,11 +204,28 @@ public abstract class ModifyDialogTabPage {
return fValues[1].equals(getPreferences().get(getKey())); 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() { public Control getControl() {
return fCheckbox; 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. * Wrapper around a Combo box.
@ -437,7 +461,7 @@ public abstract class ModifyDialogTabPage {
*/ */
protected final static class DefaultFocusManager extends FocusAdapter { 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; private final IDialogSettings fDialogSettings;
@ -503,24 +527,6 @@ public abstract class ModifyDialogTabPage {
*/ */
protected final DefaultFocusManager fDefaultFocusManager; 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 * A pixel converter for layout calculations
*/ */
@ -535,15 +541,15 @@ public abstract class ModifyDialogTabPage {
/** /**
* The modify dialog where we can display status messages. * The modify dialog where we can display status messages.
*/ */
private final ModifyDialog fModifyDialog; private final IModificationListener fModifyListener;
/* /*
* Create a new <code>ModifyDialogTabPage</code> * Create a new <code>ModifyDialogTabPage</code>
*/ */
public ModifyDialogTabPage(ModifyDialog modifyDialog, Map workingValues) { public ModifyDialogTabPage(IModificationListener modifyListener, Map workingValues) {
fWorkingValues= workingValues; fWorkingValues= workingValues;
fModifyDialog= modifyDialog; fModifyListener= modifyListener;
fDefaultFocusManager= new DefaultFocusManager(); fDefaultFocusManager= new DefaultFocusManager();
} }
@ -652,7 +658,7 @@ public abstract class ModifyDialogTabPage {
protected abstract void doUpdatePreview(); protected abstract void doUpdatePreview();
protected void notifyValuesModified() { protected void notifyValuesModified() {
fModifyDialog.valuesModified(); fModifyListener.valuesModified();
} }
/** /**
* Each tab page should remember where its last focus was, and reset it * 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 * @param status Status describing the current page error state
*/ */
protected void updateStatus(IStatus status) { protected void updateStatus(IStatus status) {
fModifyDialog.updateStatus(status); fModifyListener.updateStatus(status);
} }
/* /*
@ -787,6 +793,16 @@ public abstract class ModifyDialogTabPage {
return pref; 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. * Create a nice javadoc comment for some string.
*/ */