From ae6f42aa91329d807e177cdabe05216049ed9d19 Mon Sep 17 00:00:00 2001 From: Remy Suen Date: Thu, 13 May 2010 20:01:39 -0400 Subject: Precheck selected files in the commit dialog 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 --- .../egit/ui/internal/actions/CommitAction.java | 30 ++++++++++++++++++++++ .../egit/ui/internal/dialogs/CommitDialog.java | 30 +++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) 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 3038e8ee31..3ee292c696 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 getSelectedFiles() { + List preselectionCandidates = new ArrayList(); + // 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 ad37752b21..da3a77c290 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 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 + * null + */ + public void setPreselectedFiles(Collection preselectedFiles) { + Assert.isNotNull(preselectedFiles); + this.preselectedFiles = preselectedFiles; + } + class HeaderSelectionListener extends SelectionAdapter { private CommitItem.Order order; -- cgit v1.2.3