mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-16 20:55:44 +02:00
"perform OK" logic reworked
This commit is contained in:
parent
d9ed709128
commit
169297af7e
3 changed files with 49 additions and 81 deletions
|
@ -326,7 +326,7 @@ outer:
|
||||||
c2.removeExternalSettings();
|
c2.removeExternalSettings();
|
||||||
ICExternalSetting[] v = c1.getExternalSettings();
|
ICExternalSetting[] v = c1.getExternalSettings();
|
||||||
for (int i=0; i<v.length; i++)
|
for (int i=0; i<v.length; i++)
|
||||||
cfg.createExternalSetting(v[i].getCompatibleLanguageIds(),
|
c2.createExternalSetting(v[i].getCompatibleLanguageIds(),
|
||||||
v[i].getCompatibleContentTypeIds(),
|
v[i].getCompatibleContentTypeIds(),
|
||||||
v[i].getCompatibleExtensions(), v[i].getEntries());
|
v[i].getCompatibleExtensions(), v[i].getEntries());
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,7 @@ implements
|
||||||
private static ICConfigurationDescription[] multiCfgs = null; // selected multi cfg
|
private static ICConfigurationDescription[] multiCfgs = null; // selected multi cfg
|
||||||
private static ICProjectDescription prjd = null;
|
private static ICProjectDescription prjd = null;
|
||||||
private static int cfgIndex = 0;
|
private static int cfgIndex = 0;
|
||||||
|
protected static boolean saveDone = false;
|
||||||
// private static boolean doneOK = false;
|
// private static boolean doneOK = false;
|
||||||
// tabs
|
// tabs
|
||||||
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.cPropertyTab"; //$NON-NLS-1$
|
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.cPropertyTab"; //$NON-NLS-1$
|
||||||
|
@ -139,7 +140,6 @@ implements
|
||||||
protected boolean isFolder = false;
|
protected boolean isFolder = false;
|
||||||
protected boolean isFile = false;
|
protected boolean isFile = false;
|
||||||
protected boolean isMulti = false;
|
protected boolean isMulti = false;
|
||||||
protected static int saveCounter = 0;
|
|
||||||
|
|
||||||
// tabs
|
// tabs
|
||||||
protected TabFolder folder;
|
protected TabFolder folder;
|
||||||
|
@ -183,7 +183,7 @@ implements
|
||||||
// reset static values before new session
|
// reset static values before new session
|
||||||
if (pages.size() == 0) {
|
if (pages.size() == 0) {
|
||||||
prjd = null; // force getting new descriptors
|
prjd = null; // force getting new descriptors
|
||||||
saveCounter = 0; // needs in performOK();
|
saveDone = false; // needs in performOK();
|
||||||
}
|
}
|
||||||
// register current page
|
// register current page
|
||||||
if (!pages.contains(this)) pages.add(this);
|
if (!pages.contains(this)) pages.add(this);
|
||||||
|
@ -387,67 +387,24 @@ implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean performCancel() {
|
||||||
* Saves ALL current changes in ALL affected configurations.
|
if (! noContentOnPage && displayedConfig) forEach(ICPropertyTab.CANCEL);
|
||||||
* Called after "OK" button pressed.
|
return true;
|
||||||
*
|
}
|
||||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
public void performDefaults() {
|
||||||
*/
|
if (! noContentOnPage && displayedConfig) forEach(ICPropertyTab.DEFAULTS);
|
||||||
public boolean performOk() {
|
|
||||||
// this part is to be performed by every page
|
|
||||||
if (!noContentOnPage && displayedConfig) {
|
|
||||||
doInform();
|
|
||||||
}
|
|
||||||
// checks whether it's a last page
|
|
||||||
if (++saveCounter < pages.size()) return true;
|
|
||||||
|
|
||||||
// this part is to be performed once while OK pressed.
|
|
||||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
|
||||||
public void run(IProgressMonitor monitor) {
|
|
||||||
try {
|
|
||||||
doSave(monitor);
|
|
||||||
} catch (CoreException e) { }
|
|
||||||
if (!isForPrefs())
|
|
||||||
updateViews(internalElement);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable);
|
|
||||||
try {
|
|
||||||
new ProgressMonitorDialog(getShell()).run(false, true, op);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
Throwable e1 = e.getTargetException();
|
|
||||||
CUIPlugin.errorDialog(getShell(),
|
|
||||||
UIMessages.getString("AbstractPage.8"), //$NON-NLS-1$
|
|
||||||
UIMessages.getString("AbstractPage.9"), e1, true); //$NON-NLS-1$
|
|
||||||
return false;
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
public void performApply() { performSave(false); }
|
||||||
/**
|
public boolean performOk() { return performSave(true); }
|
||||||
* Action performed upon every page while OK pressed
|
|
||||||
* Normally, all tabs are informed about this action
|
|
||||||
*/
|
|
||||||
protected void doInform() {
|
|
||||||
forEach(ICPropertyTab.OK, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action performed once while OK pressed
|
|
||||||
* Assume that all pages are already informed.
|
|
||||||
* @param monitor
|
|
||||||
* @throws CoreException
|
|
||||||
*/
|
|
||||||
protected void doSave(IProgressMonitor monitor) throws CoreException {
|
|
||||||
CoreModel.getDefault().setProjectDescription(getProject(), prjd, true, monitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply changes for all tabs but for given page & current cfg only.
|
* The same code used to perform OK and Apply
|
||||||
* Called after "Apply" button pressed.
|
* @param forOk - true means OK, false - Apply
|
||||||
*/
|
*/
|
||||||
public void performApply() {
|
private boolean performSave(boolean forOk) {
|
||||||
if (noContentOnPage || !displayedConfig) return;
|
final boolean finalOk = forOk;
|
||||||
|
if (noContentOnPage || !displayedConfig) return true;
|
||||||
|
if (forOk && saveDone) return true; // do not duplicate
|
||||||
|
|
||||||
// perform in separate thread
|
// perform in separate thread
|
||||||
final ICProjectDescription local_prjd = CoreModel.getDefault().getProjectDescription(prjd.getProject());
|
final ICProjectDescription local_prjd = CoreModel.getDefault().getProjectDescription(prjd.getProject());
|
||||||
ICConfigurationDescription c = local_prjd.getConfigurationById(resd.getConfiguration().getId());
|
ICConfigurationDescription c = local_prjd.getConfigurationById(resd.getConfiguration().getId());
|
||||||
|
@ -455,7 +412,22 @@ implements
|
||||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||||
public void run(IProgressMonitor monitor) {
|
public void run(IProgressMonitor monitor) {
|
||||||
// ask all tabs to store changes in cfg
|
// ask all tabs to store changes in cfg
|
||||||
forEach(ICPropertyTab.APPLY, local_cfgd);
|
if (finalOk) { // OK
|
||||||
|
saveDone = true;
|
||||||
|
ICConfigurationDescription[] olds = prjd.getConfigurations();
|
||||||
|
for (int i=0; i<olds.length; i++) {
|
||||||
|
resd = getResDesc(olds[i]);
|
||||||
|
ICResourceDescription r = getResDesc(local_prjd.getConfigurationById(olds[i].getId()));
|
||||||
|
for (int j=0; j<pages.size(); j++) {
|
||||||
|
AbstractPage ap = (AbstractPage)pages.get(j);
|
||||||
|
if (ap.displayedConfig) {
|
||||||
|
ap.forEach(ICPropertyTab.UPDATE, resd);
|
||||||
|
ap.forEach(ICPropertyTab.APPLY, r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else // Apply
|
||||||
|
forEach(ICPropertyTab.APPLY, local_cfgd);
|
||||||
try {
|
try {
|
||||||
CoreModel.getDefault().setProjectDescription(getProject(), local_prjd);
|
CoreModel.getDefault().setProjectDescription(getProject(), local_prjd);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -472,26 +444,11 @@ implements
|
||||||
CUIPlugin.errorDialog(getShell(),
|
CUIPlugin.errorDialog(getShell(),
|
||||||
UIMessages.getString("AbstractPage.8"), //$NON-NLS-1$
|
UIMessages.getString("AbstractPage.8"), //$NON-NLS-1$
|
||||||
UIMessages.getString("AbstractPage.9"), e1, true); //$NON-NLS-1$
|
UIMessages.getString("AbstractPage.9"), e1, true); //$NON-NLS-1$
|
||||||
|
return false;
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Inform all pages. Nothing to save
|
|
||||||
*/
|
|
||||||
public boolean performCancel() {
|
|
||||||
if (! noContentOnPage && displayedConfig)
|
|
||||||
forEach(ICPropertyTab.CANCEL);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ask all pages to set default values to current cfg
|
|
||||||
*/
|
|
||||||
public void performDefaults() {
|
|
||||||
if (! noContentOnPage && displayedConfig)
|
|
||||||
forEach(ICPropertyTab.DEFAULTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateConfigurations() {
|
private void populateConfigurations() {
|
||||||
// Do nothing if widget not created yet.
|
// Do nothing if widget not created yet.
|
||||||
if (configSelector == null) return;
|
if (configSelector == null) return;
|
||||||
|
@ -679,6 +636,13 @@ implements
|
||||||
if (displayedConfig) forEach(ICPropertyTab.DISPOSE);
|
if (displayedConfig) forEach(ICPropertyTab.DISPOSE);
|
||||||
handleResize(false); // save page size
|
handleResize(false); // save page size
|
||||||
if (pages.contains(this)) pages.remove(this);
|
if (pages.contains(this)) pages.remove(this);
|
||||||
|
// clear static variables
|
||||||
|
if (pages.size() == 0) {
|
||||||
|
prjd = null;
|
||||||
|
resd = null;
|
||||||
|
cfgDescs = null;
|
||||||
|
multiCfgs = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,5 +58,9 @@ public abstract class AbstractPrefPage extends AbstractPage
|
||||||
public void init(IWorkbench workbench) {}
|
public void init(IWorkbench workbench) {}
|
||||||
public ICResourceDescription getResDesc() { return null; }
|
public ICResourceDescription getResDesc() { return null; }
|
||||||
public void performApply() { performOk(); }
|
public void performApply() { performOk(); }
|
||||||
|
public boolean performOk() {
|
||||||
|
forEach(ICPropertyTab.OK, null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
abstract protected String getHeader();
|
abstract protected String getHeader();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue