From e5ff47ccf25b3aa19b29a64054757d40a688bd9b Mon Sep 17 00:00:00 2001 From: Oleg Krasilnikov Date: Wed, 28 Mar 2007 08:27:13 +0000 Subject: [PATCH] perform OK logic reworked. --- .../eclipse/cdt/ui/newui/AbstractPage.java | 79 ++++++++++++++----- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java index d76f21b6438..fa1a5d196d9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.ui.newui; +import java.io.File; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; @@ -120,6 +121,11 @@ implements private static final Object NOT_NULL = new Object(); public static final String EMPTY_STR = ""; //$NON-NLS-1$ + + private static final int SAVE_MODE_OK = 1; + private static final int SAVE_MODE_APPLY = 2; + private static final int SAVE_MODE_APPLYOK = 3; + /* * Dialog widgets */ @@ -391,34 +397,62 @@ implements public void performDefaults() { if (! noContentOnPage && displayedConfig) forEach(ICPropertyTab.DEFAULTS); } - public void performApply() { performSave(false); } + public void performApply() { performSave(SAVE_MODE_APPLY); } + + /** + * There are 2 ways to perform OK for CDT property pages. + * 1st (default): + * All pages use the same editable copy of ICProjectDescription. + * When OK occurs, this object is simply set. + * + * 2nd: + * When OK occurs, each page must copy its data to new instance + * of ICProjectDescription, like it occurs during Apply event. + * It allows to avoid collisions with other property pages, + * which do not share ICProjectDescription instance. + * But some changes may be saved wrong if they are affected + * by data from another property pages (Discovery options etc). + + * To enable 2nd mode, just create the following file: + * /.metadata/.plugins/org.eclipse.cdt.ui/apply_mode + */ + public boolean performOk() { - return performSave(true); + File f = CUIPlugin.getDefault().getStateLocation().append("apply_mode").toFile(); //$NON-NLS-1$ + if (f.exists()) + return performSave(SAVE_MODE_APPLYOK); + else + return performSave(SAVE_MODE_OK); + } /** * The same code used to perform OK and Apply - * @param forOk - true means OK, false - Apply */ - private boolean performSave(boolean forOk) { - final boolean finalOk = forOk; + private boolean performSave(int mode) { + final int finalMode = mode; if (noContentOnPage || !displayedConfig) return true; - if (forOk && saveDone) return true; // do not duplicate + if ((mode == SAVE_MODE_OK || mode == SAVE_MODE_APPLYOK) && saveDone) return true; // do not duplicate - // perform in separate thread - final ICProjectDescription local_prjd = CoreModel.getDefault().getProjectDescription(prjd.getProject()); - ICConfigurationDescription c = local_prjd.getConfigurationById(resd.getConfiguration().getId()); - final ICResourceDescription local_cfgd = getResDesc(c); + final boolean needs = (mode != SAVE_MODE_OK); + final ICProjectDescription local_prjd = needs ? CoreModel.getDefault().getProjectDescription(prjd.getProject()) : null; + ICConfigurationDescription c = needs ? local_prjd.getConfigurationById(resd.getConfiguration().getId()) : null; + final ICResourceDescription local_cfgd = needs ? getResDesc(c) : null; + IRunnableWithProgress runnable = new IRunnableWithProgress() { + + private void sendOK() { + for (int j=0; j