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

[125538] applied patch to fix more target drag & drop issues

- bug with renaming of target being copied.
- allow Ctr-C and then Ctrl-V without need for selecting the folder. this has a
side effect enabling copying on selection of make target. Well, at least it is
consistent with current drag&drop behaviour.
- small fixes, such as disabling "Build" button initially, or not allowing
"Add" action on multiple selection.
This commit is contained in:
Alena Laskavaia 2009-03-12 18:21:05 +00:00
parent 7386dd2f98
commit d87cfdf0b6
6 changed files with 65 additions and 28 deletions

View file

@ -106,15 +106,17 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
} }
public void renameTarget(IMakeTarget target, String name) throws CoreException { public void renameTarget(IMakeTarget target, String name) throws CoreException {
ProjectTargets projectTargets = projectMap.get(target.getProject()); MakeTarget makeTarget = (MakeTarget)target;
ProjectTargets projectTargets = projectMap.get(makeTarget.getProject());
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(target.getProject()); projectTargets = readTargets(makeTarget.getProject());
} }
if (!projectTargets.contains((MakeTarget)target)) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeMessages.getString("MakeTargetManager.target_exists"), null)); //$NON-NLS-1$ makeTarget.setName(name);
if (projectTargets.contains(makeTarget)) {
updateTarget(makeTarget);
} }
((MakeTarget)target).setName(name);
updateTarget((MakeTarget) target);
} }
public IMakeTarget[] getTargets(IContainer container) throws CoreException { public IMakeTarget[] getTargets(IContainer container) throws CoreException {

View file

@ -471,8 +471,13 @@ public class MakeTargetDialog extends Dialog {
protected void okPressed() { protected void okPressed() {
IMakeTarget target = fTarget; IMakeTarget target = fTarget;
try { try {
if (fTarget == null) { String targetName = getTargetName();
target = fTargetManager.createTarget(fContainer.getProject(), getTargetName(), targetBuildID); if (target == null) {
target = fTargetManager.createTarget(fContainer.getProject(), targetName, targetBuildID);
} else {
if (!target.getName().equals(targetName)) {
fTargetManager.renameTarget(target, targetName);
}
} }
target.setStopOnError(isStopOnError()); target.setStopOnError(isStopOnError());
target.setRunAllBuilders(runAllBuilders()); target.setRunAllBuilders(runAllBuilders());
@ -506,10 +511,6 @@ public class MakeTargetDialog extends Dialog {
if (fTarget == null || !MakeCorePlugin.getDefault().getTargetManager().targetExists(fTarget)) { if (fTarget == null || !MakeCorePlugin.getDefault().getTargetManager().targetExists(fTarget)) {
fTargetManager.addTarget(fContainer, target); fTargetManager.addTarget(fContainer, target);
} else {
if (!target.getName().equals(getTargetName())) {
fTargetManager.renameTarget(target, getTargetName());
}
} }
} catch (CoreException e) { } catch (CoreException e) {
MakeUIPlugin.errorDialog( MakeUIPlugin.errorDialog(

View file

@ -58,10 +58,12 @@ public class AddTargetAction extends SelectionListenerAction {
} }
private Object getSelectedElement() { private Object getSelectedElement() {
if (getStructuredSelection().size()==1) {
Object element = getStructuredSelection().getFirstElement(); Object element = getStructuredSelection().getFirstElement();
if (element instanceof IContainer || element instanceof IMakeTarget) { if (element instanceof IContainer || element instanceof IMakeTarget) {
return element; return element;
} }
}
return null; return null;
} }

View file

@ -30,6 +30,7 @@ public class BuildTargetAction extends SelectionListenerAction {
setToolTipText(MakeUIPlugin.getResourceString("BuildTargetAction.tooltip")); //$NON-NLS-1$ setToolTipText(MakeUIPlugin.getResourceString("BuildTargetAction.tooltip")); //$NON-NLS-1$
MakeUIImages.setImageDescriptors(this, "tool16", MakeUIImages.IMG_TOOLS_MAKE_TARGET_BUILD); //$NON-NLS-1$ MakeUIImages.setImageDescriptors(this, "tool16", MakeUIImages.IMG_TOOLS_MAKE_TARGET_BUILD); //$NON-NLS-1$
setEnabled(false);
} }
@Override @Override

View file

@ -77,11 +77,11 @@ public class MakeView extends ViewPart {
private BuildTargetAction buildTargetAction; private BuildTargetAction buildTargetAction;
private EditTargetAction editTargetAction; private EditTargetAction editTargetAction;
private DeleteTargetAction deleteTargetAction; private DeleteTargetAction deleteTargetAction;
AddTargetAction addTargetAction; private AddTargetAction addTargetAction;
private CopyTargetAction copyTargetAction; private CopyTargetAction copyTargetAction;
private PasteTargetAction pasteTargetAction; private PasteTargetAction pasteTargetAction;
TreeViewer fViewer; private TreeViewer fViewer;
DrillDownAdapter drillDownAdapter; private DrillDownAdapter drillDownAdapter;
private Action trimEmptyFolderAction; private Action trimEmptyFolderAction;
public MakeView() { public MakeView() {

View file

@ -11,8 +11,7 @@
package org.eclipse.cdt.make.ui.views; package org.eclipse.cdt.make.ui.views;
import java.util.List; import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.make.internal.ui.dnd.FileTransferDropTargetListener; import org.eclipse.cdt.make.internal.ui.dnd.FileTransferDropTargetListener;
import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetTransfer; import org.eclipse.cdt.make.internal.ui.dnd.MakeTargetTransfer;
@ -72,11 +71,7 @@ public class PasteTargetAction extends SelectionListenerAction {
return false; return false;
} }
if (selection.size() == 1 && (selection.getFirstElement() instanceof IContainer)) { return determineDropContainer()!=null;
return true;
}
return false;
} }
/** /**
@ -85,11 +80,10 @@ public class PasteTargetAction extends SelectionListenerAction {
*/ */
@Override @Override
public void run() { public void run() {
List<?> resources = getSelectedResources(); IContainer dropContainer = determineDropContainer();
if (resources.size() != 1 || !(resources.get(0) instanceof IContainer)) { if (dropContainer==null) {
return; return;
} }
IContainer dropContainer = (IContainer) resources.get(0);
Object clipboardContent; Object clipboardContent;
@ -116,4 +110,41 @@ public class PasteTargetAction extends SelectionListenerAction {
} }
/**
* Drop container is determined by first element. The rest of the logic is
* to figure out if drop is allowed. The drop is allowed if the selection is
* one {@code IContainer} or {@code IMakeTarget}s from the same folder.
*
* @return drop container or {@code null}.
*/
private IContainer determineDropContainer() {
IStructuredSelection selection = getStructuredSelection();
if (selection.size()==0) {
return null;
}
Object first = selection.getFirstElement();
if (first instanceof IContainer) {
if (selection.size()==1) {
return (IContainer)first;
} else {
return null;
}
}
if (first instanceof IMakeTarget) {
// it has to be selection of IMakeTargets only and from the same IContainer
IContainer dropContainer = ((IMakeTarget)first).getContainer();
for (Object item : selection.toList()) {
if ( !(item instanceof IMakeTarget) || ((IMakeTarget)item).getContainer()!=dropContainer ) {
return null;
}
}
return dropContainer;
}
return null;
}
} }