summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRemy Suen2010-05-13 20:01:39 (EDT)
committer Remy Suen2010-05-13 20:01:39 (EDT)
commitae6f42aa91329d807e177cdabe05216049ed9d19 (patch)
tree3472c8d8aca43cb81436bd83126e3e20eb25f35c
parent708aa2d18f58c7a9655045b6fe5d0483fde89e6e (diff)
downloadegit-ae6f42aa91329d807e177cdabe05216049ed9d19.zip
egit-ae6f42aa91329d807e177cdabe05216049ed9d19.tar.gz
egit-ae6f42aa91329d807e177cdabe05216049ed9d19.tar.bz2
Precheck selected files in the commit dialogrefs/changes/99/699/2
The commit dialog presents all local modifications of files but does not respect the user's selection. The dialog should precheck any files that the user has selected and any files that are in any folders that the user has selected. Bug: 304131 Change-Id: I1a0f73641b5bd5603b9fbde8fc25eb310976b3e0
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitAction.java30
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java30
2 files changed, 59 insertions, 1 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitAction.java
index 3038e8e..3ee292c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitAction.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitAction.java
@@ -16,9 +16,11 @@ import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.TimeZone;
@@ -136,6 +138,7 @@ public class CommitAction extends RepositoryAction {
commitDialog.setAmending(amending);
commitDialog.setAmendAllowed(amendAllowed);
commitDialog.setFileList(files);
+ commitDialog.setPreselectedFiles(getSelectedFiles());
commitDialog.setAuthor(author);
commitDialog.setCommitter(committer);
if(notTracked.size() == files.size())
@@ -169,6 +172,33 @@ public class CommitAction extends RepositoryAction {
previousCommit = null;
}
+ /**
+ * Retrieves a collection of files that may be committed based on the user's
+ * selection when they performed the commit action. That is, even if the
+ * user only selected one folder when the action was performed, if the
+ * folder contains any files that could be committed, they will be returned.
+ *
+ * @return a collection of files that is eligible to be committed based on
+ * the user's selection
+ */
+ private Collection<IFile> getSelectedFiles() {
+ List<IFile> preselectionCandidates = new ArrayList<IFile>();
+ // get the resources the user selected
+ IResource[] selectedResources = getSelectedResources();
+ // iterate through all the files that may be committed
+ for (IFile file : files) {
+ for (IResource resource : selectedResources) {
+ // if any selected resource contains the file, add it as a
+ // preselection candidate
+ if (resource.contains(file)) {
+ preselectionCandidates.add(file);
+ break;
+ }
+ }
+ }
+ return preselectionCandidates;
+ }
+
private void loadPreviousCommit() {
IProject project = getProjectsForSelectedResources()[0];
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java
index ad37752..da3a77c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitDialog.java
@@ -15,6 +15,7 @@ package org.eclipse.egit.ui.internal.dialogs;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
@@ -26,6 +27,7 @@ import org.eclipse.compare.CompareUI;
import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.egit.core.Activator;
@@ -193,6 +195,11 @@ public class CommitDialog extends Dialog {
CheckboxTableViewer filesViewer;
+ /**
+ * A collection of files that should be already checked in the table.
+ */
+ private Collection<IFile> preselectedFiles = Collections.emptyList();
+
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
@@ -355,9 +362,18 @@ public class CommitDialog extends Dialog {
filesViewer.setLabelProvider(new CommitLabelProvider());
filesViewer.addFilter(new CommitItemFilter());
filesViewer.setInput(items);
- filesViewer.setAllChecked(true);
filesViewer.getTable().setMenu(getContextMenu());
+ // pre-emptively check any preselected files
+ for (IFile selectedFile : preselectedFiles) {
+ for (CommitItem item : items) {
+ if (item.file.equals(selectedFile)) {
+ filesViewer.setChecked(item, true);
+ break;
+ }
+ }
+ }
+
container.pack();
return container;
}
@@ -564,6 +580,18 @@ public class CommitDialog extends Dialog {
return selectedFiles.toArray(new IFile[0]);
}
+ /**
+ * Sets the files that should be checked in this table.
+ *
+ * @param preselectedFiles
+ * the files to be checked in the dialog's table, must not be
+ * <code>null</code>
+ */
+ public void setPreselectedFiles(Collection<IFile> preselectedFiles) {
+ Assert.isNotNull(preselectedFiles);
+ this.preselectedFiles = preselectedFiles;
+ }
+
class HeaderSelectionListener extends SelectionAdapter {
private CommitItem.Order order;