diff options
author | Chris Aniszczyk | 2011-02-24 17:38:27 +0000 |
---|---|---|
committer | Code Review | 2011-02-24 17:38:27 +0000 |
commit | a3d175a0436bf3a0e95d960a36505b7e9a277451 (patch) | |
tree | fc51d9b8ca53b03b76ddb5390523fabba5ab5ad5 | |
parent | 488d7beb621be7f6acc61a7c5ed4919d08c07e91 (diff) | |
parent | b0a2a2289d0dd245d1f5d5e769b3cd5dc6f13e40 (diff) | |
download | egit-a3d175a0436bf3a0e95d960a36505b7e9a277451.tar.gz egit-a3d175a0436bf3a0e95d960a36505b7e9a277451.tar.xz egit-a3d175a0436bf3a0e95d960a36505b7e9a277451.zip |
Merge "Do not allow to delete working dir but not to remove projects"
2 files changed, 76 insertions, 38 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/DeleteRepositoryConfirmDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/DeleteRepositoryConfirmDialog.java index 2501b05539..11a56283cb 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/DeleteRepositoryConfirmDialog.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/DeleteRepositoryConfirmDialog.java @@ -32,16 +32,20 @@ public class DeleteRepositoryConfirmDialog extends TitleAreaDialog { private final Repository repository; private boolean shouldDelete = false; + private boolean shouldRemoveProjects = false; + private int numberOfProjects = 0; /** * @param parentShell * @param repository + * @param numberOfProjects */ public DeleteRepositoryConfirmDialog(Shell parentShell, - Repository repository) { + Repository repository, int numberOfProjects) { super(parentShell); setHelpAvailable(false); this.repository = repository; + this.numberOfProjects = numberOfProjects; } @Override @@ -55,10 +59,16 @@ public class DeleteRepositoryConfirmDialog extends TitleAreaDialog { if (repository.isBare()) return main; final Button deleteWorkDir = new Button(main, SWT.CHECK); + final Button removeProjects = new Button(main, SWT.CHECK); deleteWorkDir.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { shouldDelete = deleteWorkDir.getSelection(); + removeProjects.setEnabled(!shouldDelete); + if (shouldDelete && numberOfProjects > 0) { + removeProjects.setSelection(true); + shouldRemoveProjects = true; + } } }); GridDataFactory.fillDefaults().grab(true, false).applyTo(deleteWorkDir); @@ -67,6 +77,20 @@ public class DeleteRepositoryConfirmDialog extends TitleAreaDialog { .bind( UIText.DeleteRepositoryConfirmDialog_DeleteWorkingDirectoryCheckbox, repository.getWorkTree().getPath())); + if (numberOfProjects > 0) { + removeProjects.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + shouldRemoveProjects = removeProjects.getSelection(); + } + }); + GridDataFactory.fillDefaults().grab(true, false).applyTo(removeProjects); + removeProjects + .setText(NLS + .bind(UIText.RepositoriesView_ConfirmProjectDeletion_Question, + Integer.valueOf(numberOfProjects))); + } else + removeProjects.setVisible(false); return main; } @@ -94,4 +118,11 @@ public class DeleteRepositoryConfirmDialog extends TitleAreaDialog { public boolean shouldDeleteWorkingDir() { return shouldDelete; } + + /** + * @return if the working directory should be deleted + */ + public boolean shouldRemoveProjects() { + return shouldRemoveProjects; + } } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java index df3cfe0abf..44e57a8278 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java @@ -76,6 +76,8 @@ public class RemoveCommand extends return; } boolean deleteWorkingDir = false; + boolean removeProjects = false; + final List<IProject> projectsToDelete = findProjectsToDelete(selectedNodes); if (delete) { if (selectedNodes.size() > 1) { return; @@ -95,61 +97,49 @@ public class RemoveCommand extends // confirm dialog with check box // "delete also working directory" DeleteRepositoryConfirmDialog dlg = new DeleteRepositoryConfirmDialog( - getShell(event), repository); + getShell(event), repository, projectsToDelete.size()); if (dlg.open() != Window.OK) return; deleteWorkingDir = dlg.shouldDeleteWorkingDir(); + removeProjects = dlg.shouldRemoveProjects(); } } } + else { + if (!projectsToDelete.isEmpty()) { + final boolean[] confirmedCanceled = new boolean[] { false, + false }; + Display.getDefault().syncExec(new Runnable() { + + public void run() { + try { + confirmedCanceled[0] = confirmProjectDeletion( + projectsToDelete, event); + } catch (OperationCanceledException e) { + confirmedCanceled[1] = true; + } + } + }); + if (confirmedCanceled[1]) + return; + removeProjects = confirmedCanceled[0]; + } + } + final boolean deleteWorkDir = deleteWorkingDir; + final boolean removeProj = removeProjects; Job job = new Job("Remove Repositories Job") { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { - final List<IProject> projectsToDelete = new ArrayList<IProject>(); monitor .setTaskName(UIText.RepositoriesView_DeleteRepoDeterminProjectsMessage); - for (RepositoryNode node : selectedNodes) { - if (node.getRepository().isBare()) - continue; - File workDir = node.getRepository().getWorkTree(); - final IPath wdPath = new Path(workDir.getAbsolutePath()); - for (IProject prj : ResourcesPlugin.getWorkspace() - .getRoot().getProjects()) { - if (monitor.isCanceled()) - return Status.OK_STATUS; - if (wdPath.isPrefixOf(prj.getLocation())) { - projectsToDelete.add(prj); - } - } - } - final boolean[] confirmedCanceled = new boolean[] { false, - false }; - - if (!projectsToDelete.isEmpty()) { - Display.getDefault().syncExec(new Runnable() { - - public void run() { - try { - confirmedCanceled[0] = confirmProjectDeletion( - projectsToDelete, event); - } catch (OperationCanceledException e) { - confirmedCanceled[1] = true; - } - } - }); - } - if (confirmedCanceled[1]) { - // canceled: return - return Status.OK_STATUS; - } - if (confirmedCanceled[0]) { + if (removeProj) { // confirmed deletion IWorkspaceRunnable wsr = new IWorkspaceRunnable() { @@ -196,6 +186,23 @@ public class RemoveCommand extends service.schedule(job); } + private List<IProject> findProjectsToDelete(final List<RepositoryNode> selectedNodes) { + final List<IProject> projectsToDelete = new ArrayList<IProject>(); + for (RepositoryNode node : selectedNodes) { + if (node.getRepository().isBare()) + continue; + File workDir = node.getRepository().getWorkTree(); + final IPath wdPath = new Path(workDir.getAbsolutePath()); + for (IProject prj : ResourcesPlugin.getWorkspace() + .getRoot().getProjects()) { + if (wdPath.isPrefixOf(prj.getLocation())) { + projectsToDelete.add(prj); + } + } + } + return projectsToDelete; + } + @SuppressWarnings("boxing") private boolean confirmProjectDeletion(List<IProject> projectsToDelete, ExecutionEvent event) throws OperationCanceledException { |