mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
More work in the executables manager and view: added a remove button, don't alllow duplicate exes from different providers in the list.
This commit is contained in:
parent
433174325e
commit
1c95fb3c77
6 changed files with 165 additions and 23 deletions
|
@ -10,8 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.core.executables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
public class ExecutablesChangeEvent extends PlatformObject implements IExecutablesChangeEvent {
|
||||
|
@ -19,9 +17,9 @@ public class ExecutablesChangeEvent extends PlatformObject implements IExecutabl
|
|||
private Executable[] oldExecutables;
|
||||
private Executable[] newExecutables;
|
||||
|
||||
public ExecutablesChangeEvent(ArrayList<Executable> oldList, ArrayList<Executable> newList) {
|
||||
oldExecutables = oldList.toArray(new Executable[oldList.size()]);
|
||||
newExecutables = newList.toArray(new Executable[newList.size()]);
|
||||
public ExecutablesChangeEvent(Executable[] oldList, Executable[] newList) {
|
||||
oldExecutables = oldList;
|
||||
newExecutables = newList;
|
||||
}
|
||||
|
||||
public Executable[] getCurrentExecutables() {
|
||||
|
|
|
@ -12,17 +12,23 @@
|
|||
package org.eclipse.cdt.debug.core.executables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
|
||||
/**
|
||||
* The Executables Manager maintains a collection of executables built by all of
|
||||
|
@ -34,7 +40,7 @@ import org.eclipse.core.runtime.jobs.Job;
|
|||
*/
|
||||
public class ExecutablesManager extends PlatformObject {
|
||||
|
||||
private ArrayList<Executable> executables = new ArrayList<Executable>();
|
||||
private HashMap<String, Executable> executables = new HashMap<String, Executable>();
|
||||
private List<IExecutablesChangeListener> changeListeners = Collections.synchronizedList(new ArrayList<IExecutablesChangeListener>());
|
||||
private List<ISourceFileRemapping> sourceFileRemappings = Collections.synchronizedList(new ArrayList<ISourceFileRemapping>());
|
||||
private List<IExecutableProvider> executableProviders = Collections.synchronizedList(new ArrayList<IExecutableProvider>());
|
||||
|
@ -142,10 +148,11 @@ public class ExecutablesManager extends PlatformObject {
|
|||
refreshJob.schedule();
|
||||
refreshJob.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
DebugPlugin.log( e );
|
||||
}
|
||||
}
|
||||
return executables.toArray(new Executable[executables.size()]);
|
||||
Collection<Executable> exes = executables.values();
|
||||
return exes.toArray(new Executable[exes.size()]);
|
||||
}
|
||||
|
||||
public String remapSourceFile(String filePath) {
|
||||
|
@ -206,11 +213,7 @@ public class ExecutablesManager extends PlatformObject {
|
|||
}
|
||||
|
||||
public boolean executableExists(IPath exePath) {
|
||||
for (Executable executable : executables) {
|
||||
if (executable.getPath().equals(exePath))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return executables.containsKey(exePath.toOSString());
|
||||
}
|
||||
|
||||
public String[] getSourceFiles(final Executable executable,
|
||||
|
@ -243,4 +246,46 @@ public class ExecutablesManager extends PlatformObject {
|
|||
return result;
|
||||
}
|
||||
|
||||
public IStatus removeExecutables(Executable[] executables, IProgressMonitor monitor) {
|
||||
IExecutableProvider[] exeProviders = getExecutableProviders();
|
||||
|
||||
IStatus result = Status.OK_STATUS;
|
||||
|
||||
Arrays.sort(exeProviders, new Comparator<IExecutableProvider>() {
|
||||
|
||||
public int compare(IExecutableProvider arg0, IExecutableProvider arg1) {
|
||||
int p0 = arg0.getPriority();
|
||||
int p1 = arg1.getPriority();
|
||||
if (p0 > p1)
|
||||
return 1;
|
||||
if (p0 < p1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
MultiStatus combinedStatus = new MultiStatus(CDebugCorePlugin.PLUGIN_ID, IStatus.WARNING, "Couldn't remove all of the selected executables", null);
|
||||
refreshNeeded = false;
|
||||
monitor.beginTask("Remove Executables", exeProviders.length);
|
||||
for (Executable executable : executables) {
|
||||
boolean handled = false;
|
||||
IStatus rmvStatus = Status.OK_STATUS;;
|
||||
for (IExecutableProvider provider : exeProviders) {
|
||||
if (!handled)
|
||||
{
|
||||
rmvStatus = provider.removeExecutable(executable, new SubProgressMonitor(monitor, 1));
|
||||
handled = rmvStatus.getSeverity() == IStatus.OK;
|
||||
}
|
||||
}
|
||||
if (!handled)
|
||||
{
|
||||
combinedStatus.add(rmvStatus);
|
||||
result = combinedStatus;
|
||||
}
|
||||
}
|
||||
monitor.done();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,9 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.core.executables;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
||||
/**
|
||||
* IExecutablesProvider supplies a list of executables to the Executables
|
||||
|
@ -23,6 +22,22 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
*/
|
||||
public interface IExecutableProvider {
|
||||
|
||||
Collection<Executable> getExecutables(IProgressMonitor monitor);
|
||||
static int LOW_PRIORITY = 25;
|
||||
static int NORMAL_PRIORITY = 50;
|
||||
static int HIGH_PRIORITY = 75;
|
||||
|
||||
/**
|
||||
* Gets the priority to be used when providing a list of executables.
|
||||
* The priority is used by the Executables Manager when multiple IExecutableProvider are available.
|
||||
* IExecutableImporter.importExecutables will be called for each one in priority order.
|
||||
*
|
||||
* @param executable
|
||||
* @return the priority level to be used for this ISourceFilesProvider
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
Executable[] getExecutables(IProgressMonitor monitor);
|
||||
|
||||
IStatus removeExecutable(Executable executable, IProgressMonitor monitor);
|
||||
|
||||
}
|
|
@ -39,6 +39,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
|||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
|
||||
public class StandardExecutableImporter implements IExecutableImporter {
|
||||
|
||||
|
@ -98,9 +99,9 @@ public class StandardExecutableImporter implements IExecutableImporter {
|
|||
}
|
||||
exeProject = CCorePlugin.getDefault().createCProject(description, newProjectHandle, null, DEBUG_PROJECT_ID);
|
||||
} catch (OperationCanceledException e) {
|
||||
e.printStackTrace();
|
||||
DebugPlugin.log( e );
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
DebugPlugin.log( e );
|
||||
}
|
||||
}
|
||||
checkProject = true;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
package org.eclipse.cdt.debug.core.executables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
|
@ -21,6 +20,7 @@ import org.eclipse.cdt.core.model.ICProject;
|
|||
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
|
||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -33,6 +33,9 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
|
||||
public class StandardExecutableProvider implements IResourceChangeListener, ICProjectDescriptionListener, IExecutableProvider {
|
||||
|
||||
|
@ -122,7 +125,7 @@ public class StandardExecutableProvider implements IResourceChangeListener, ICPr
|
|||
}
|
||||
}
|
||||
|
||||
public Collection<Executable> getExecutables(IProgressMonitor monitor) {
|
||||
public Executable[] getExecutables(IProgressMonitor monitor) {
|
||||
synchronized (executables) {
|
||||
executables.clear();
|
||||
|
||||
|
@ -155,13 +158,34 @@ public class StandardExecutableProvider implements IResourceChangeListener, ICPr
|
|||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
DebugPlugin.log( e );
|
||||
}
|
||||
monitor.worked(1);
|
||||
}
|
||||
monitor.done();
|
||||
}
|
||||
return executables;
|
||||
return executables.toArray(new Executable[executables.size()]);
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return NORMAL_PRIORITY;
|
||||
}
|
||||
|
||||
public IStatus removeExecutable(Executable executable, IProgressMonitor monitor) {
|
||||
IResource exeResource = executable.getResource();
|
||||
if (exeResource != null)
|
||||
{
|
||||
if (exeResource.isLinked())
|
||||
{
|
||||
try {
|
||||
exeResource.delete(true, monitor);
|
||||
} catch (CoreException e) {
|
||||
DebugPlugin.log( e );
|
||||
}
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
return new Status(IStatus.WARNING, CDebugCorePlugin.PLUGIN_ID, "Can't remove " + executable.getName() + ": it is built by project \"" + executable.getProject().getName() + "\"");
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,7 @@ import org.eclipse.core.runtime.Status;
|
|||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
|
@ -101,8 +102,12 @@ public class ExecutablesView extends ViewPart {
|
|||
public static final ImageDescriptor DESC_IMPORT_DISABLED = create(PATH_LCL_DISABLED, "import.gif"); //$NON-NLS-1$
|
||||
public static final ImageDescriptor DESC_COLUMNS = create(PATH_LCL, "columns.gif"); //$NON-NLS-1$
|
||||
public static final ImageDescriptor DESC_COLUMNS_DISABLED = create(PATH_LCL_DISABLED, "columns.gif"); //$NON-NLS-1$
|
||||
public static final ImageDescriptor DESC_REMOVE = create(PATH_LCL, "rem_co.gif"); //$NON-NLS-1$
|
||||
public static final ImageDescriptor DESC_REMOVE_DISABLED = create(PATH_LCL_DISABLED, "rem_co.gif"); //$NON-NLS-1$
|
||||
public static final int COLUMN_WIDTH_PADDING = 24;
|
||||
|
||||
private static final String SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
|
||||
private static ImageDescriptor create(String prefix, String name) {
|
||||
return ImageDescriptor.createFromURL(makeIconURL(prefix, name));
|
||||
}
|
||||
|
@ -216,6 +221,7 @@ public class ExecutablesView extends ViewPart {
|
|||
*/
|
||||
Action refreshAction;
|
||||
Action importAction;
|
||||
Action removeAction;
|
||||
private Action configureColumnsAction;
|
||||
|
||||
private IMemento memento;
|
||||
|
@ -233,7 +239,7 @@ public class ExecutablesView extends ViewPart {
|
|||
final SashForm sashForm = new SashForm(container, SWT.NONE);
|
||||
|
||||
// Create the two sub viewers.
|
||||
executablesViewer = new ExecutablesViewer(this, sashForm, SWT.FULL_SELECTION + SWT.BORDER);
|
||||
executablesViewer = new ExecutablesViewer(this, sashForm, SWT.FULL_SELECTION + SWT.BORDER + SWT.MULTI);
|
||||
ExecutablesManager.getExecutablesManager().addExecutablesChangeListener(executablesViewer);
|
||||
sourceFilesViewer = new SourceFilesViewer(this, sashForm, SWT.BORDER);
|
||||
|
||||
|
@ -343,12 +349,65 @@ public class ExecutablesView extends ViewPart {
|
|||
|
||||
importAction = createImportAction();
|
||||
toolBarManager.add(importAction);
|
||||
|
||||
removeAction = createRemoveAction();
|
||||
toolBarManager.add(removeAction);
|
||||
|
||||
configureColumnsAction = createConfigureColumnsAction();
|
||||
toolBarManager.add(configureColumnsAction);
|
||||
|
||||
}
|
||||
|
||||
private Action createRemoveAction() {
|
||||
Action action = new Action("Remove") {
|
||||
public void run() {
|
||||
ISelection selection = getExecutablesViewer().getSelection();
|
||||
if (selection instanceof IStructuredSelection)
|
||||
{
|
||||
Object[] selectedObjects = ((IStructuredSelection)selection).toArray();
|
||||
ArrayList<Executable> selectedExes = new ArrayList<Executable>();
|
||||
for (Object object : selectedObjects) {
|
||||
if (object instanceof Executable)
|
||||
selectedExes.add((Executable) object);
|
||||
}
|
||||
final Executable[] selectedExesArray = selectedExes.toArray(new Executable[selectedExes.size()]);
|
||||
|
||||
boolean confirm = MessageDialog.openConfirm(getSite().getShell(), "Confirm Remove Executables", "Are you sure you want to remove the selected executables?");
|
||||
|
||||
if (confirm)
|
||||
{
|
||||
Job removeJob = new UIJob("Remove Executables") {
|
||||
|
||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
IStatus result = ExecutablesManager.getExecutablesManager().removeExecutables(selectedExesArray, monitor);
|
||||
if (result.getSeverity() != IStatus.OK)
|
||||
{
|
||||
StringBuffer message = new StringBuffer(result.getMessage());
|
||||
if (result.isMultiStatus()) {
|
||||
IStatus[] children = result.getChildren();
|
||||
for (int i = 0; i < children.length && i < 6; i++) {
|
||||
message.append(SEPARATOR);
|
||||
message.append(children[i].getMessage());
|
||||
}
|
||||
}
|
||||
MessageDialog.openWarning(getSite().getShell(), "Remove Executables", message.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
removeJob.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
action.setToolTipText("Remove the selected executables");
|
||||
action.setImageDescriptor(ExecutablesView.DESC_REMOVE);
|
||||
action.setDisabledImageDescriptor(ExecutablesView.DESC_REMOVE_DISABLED);
|
||||
action.setEnabled(true);
|
||||
return action;
|
||||
}
|
||||
|
||||
private Action createConfigureColumnsAction() {
|
||||
ConfigureColumnsAction action = new ConfigureColumnsAction();
|
||||
action.setToolTipText(Messages.ExecutablesView_Columns);
|
||||
|
|
Loading…
Add table
Reference in a new issue