1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

Bug 392954 - Manage Working Sets dialog can be opened when all working

sets are empty
This commit is contained in:
Tom Hochstein 2012-11-06 13:25:02 -06:00 committed by John Cortell
parent 58c1312133
commit c1210c5d8b

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2009 Intel Corporation, QNX Software Systems, and others. * Copyright (c) 2008, 2009, 2012 Intel Corporation, QNX Software Systems, 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
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Intel Corporation - initial API and implementation * Intel Corporation - initial API and implementation
* QNX Software Systems - [272416] Rework the config sets dialog * QNX Software Systems - [272416] Rework the config sets dialog
* Freescale Semiconductor - [392954] disable the action if only empty working sets exist
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.actions; package org.eclipse.cdt.ui.actions;
@ -27,27 +28,32 @@ import org.eclipse.cdt.internal.ui.workingsets.WorkingSetConfigurationDialog;
/** /**
*/ */
public class WorkingSetConfigAction implements IWorkbenchWindowActionDelegate, IPropertyChangeListener { public class WorkingSetConfigAction implements IWorkbenchWindowActionDelegate, IPropertyChangeListener {
private static final IWorkingSetManager wsm = CUIPlugin.getDefault().getWorkbench().getWorkingSetManager(); private static final IWorkingSetManager wsm = CUIPlugin.getDefault().getWorkbench().getWorkingSetManager();
private boolean enabled = true; private boolean enabled = true;
private IWorkbenchWindow window; private IWorkbenchWindow window;
private IAction action;
@Override @Override
public void run(IAction action) { public void run(IAction action) {
this.action = action;
checkWS();
if (enabled) {
new WorkingSetConfigurationDialog(window.getShell()).open(); new WorkingSetConfigurationDialog(window.getShell()).open();
} }
}
@Override @Override
public void selectionChanged(IAction action, ISelection selection) { public void selectionChanged(IAction action, ISelection selection) {
this.action = action;
checkWS(); checkWS();
if (action.isEnabled() != enabled)
action.setEnabled(enabled);
} }
@Override @Override
public void dispose() { public void dispose() {
wsm.removePropertyChangeListener(this); wsm.removePropertyChangeListener(this);
} }
@Override @Override
public void init(IWorkbenchWindow window) { public void init(IWorkbenchWindow window) {
this.window = window; this.window = window;
@ -55,12 +61,20 @@ public class WorkingSetConfigAction implements IWorkbenchWindowActionDelegate, I
checkWS(); checkWS();
} }
private IWorkingSet[] checkWS() { private void checkWS() {
enabled = false;
IWorkingSet[] w = wsm.getWorkingSets(); IWorkingSet[] w = wsm.getWorkingSets();
if (w == null) if (w == null)
w = new IWorkingSet[0]; w = new IWorkingSet[0];
enabled = w.length > 0; for (IWorkingSet ws : w) {
return w; if (!ws.isEmpty()) {
enabled = true;
break;
}
}
if (action != null) {
action.setEnabled(enabled);
}
} }
@Override @Override