Commits

John Peberdy committed 26a960f

Remove unused 'localEditable' argument and move HgCompareEditorInput access into CompareUtils only

Comments (0)

Files changed (12)

src/com/vectrace/MercurialEclipse/actions/CompareWithCurrentDelegate.java

 		// TODO handle cases when file was renamed/copied
 		// see com.vectrace.MercurialEclipse.history.CompareRevisionAction.getStorage()
 		MercurialRevisionStorage right = new MercurialRevisionStorage(fileFromChangeSet.getFile(), cs.getChangeset());
-		CompareUtils.openEditor(left, right, false, false);
+		CompareUtils.openEditor(left, right, false);
 	}
 
 	/**

src/com/vectrace/MercurialEclipse/actions/CompareWithParentDelegate.java

 		ChangeSet cs = fileFromChangeSet.getChangeset();
 		MercurialRevisionStorage left = new MercurialRevisionStorage(fileFromChangeSet.getFile(), cs.getChangeset());
 		MercurialRevisionStorage right = MercurialUtilities.getParentRevision(cs, fileFromChangeSet.getFile());
-		CompareUtils.openEditor(left, right, false, false);
+		CompareUtils.openEditor(left, right, false);
 	}
 
 	/**

src/com/vectrace/MercurialEclipse/compare/HgCompareEditorInput.java

 	 * and does 3-way compare.
 	 * @param syncConfig
 	 */
-	public HgCompareEditorInput(CompareConfiguration configuration,
-			IFile resource, ResourceNode left, ResourceNode right, ISynchronizePageConfiguration syncConfig) {
+	public HgCompareEditorInput(CompareConfiguration configuration, IFile resource,
+			ResourceNode left, ResourceNode right, ISynchronizePageConfiguration syncConfig) {
+		this(configuration, resource, left, findParentNodeIfExists(resource, left, right), right,
+				!(left instanceof RevisionNode), syncConfig);
+
+		setTitle(resource.getName());
+	}
+
+	public HgCompareEditorInput(CompareConfiguration configuration, IFile leftResource,
+			ResourceNode ancestor, ResourceNode right) {
+		this(configuration, leftResource, new ResourceNode(leftResource), ancestor, right, true,
+				null);
+
+		setTitle(left.getName());
+
+		if (ancestor != null) {
+			configuration.setAncestorLabel(getLabel(ancestor));
+		}
+	}
+
+	private HgCompareEditorInput(CompareConfiguration configuration, IFile resource,
+			ResourceNode left, ResourceNode ancestor, ResourceNode right, boolean bLeftEditable,
+			ISynchronizePageConfiguration syncConfig) {
 		super(configuration);
+		this.syncConfig = syncConfig;
+		this.left = left;
+		this.ancestor = ancestor;
+		this.right = right;
 		this.resource = resource;
-		this.left = left;
-		this.syncConfig = syncConfig;
-		this.ancestor = findParentNodeIfExists(resource, left, right);
-		this.right = right;
-		setTitle(resource.getName());
 		configuration.setLeftLabel(getLabel(left));
-		// if left isn't a RevisionNode, then it must be the one on the filesystem
-		configuration.setLeftEditable(!(left instanceof RevisionNode));
+		configuration.setLeftEditable(bLeftEditable);
 		configuration.setRightLabel(getLabel(right));
 		configuration.setRightEditable(false);
 	}
 
-
-	private ResourceNode findParentNodeIfExists(IFile file, ResourceNode l, ResourceNode r) {
+	private static ResourceNode findParentNodeIfExists(IFile file, ResourceNode l, ResourceNode r) {
 		if (!(l instanceof RevisionNode && r instanceof RevisionNode)) {
 			return null;
 		}
 		}
 	}
 
-	public HgCompareEditorInput(CompareConfiguration configuration,
-			IFile leftResource, ResourceNode ancestor, ResourceNode right, boolean localEditable) {
-		super(configuration);
-		this.syncConfig = null;
-		this.left = new ResourceNode(leftResource);
-		this.ancestor = ancestor;
-		this.right = right;
-		this.resource = leftResource;
-		setTitle(left.getName());
-		configuration.setLeftLabel(getLabel(left));
-		configuration.setLeftEditable(localEditable);
-		if(ancestor != null) {
-			configuration.setAncestorLabel(getLabel(ancestor));
-		}
-		configuration.setRightLabel(getLabel(right));
-		configuration.setRightEditable(false);
-	}
-
 	private static String getLabel(ResourceNode node) {
 		if (node instanceof RevisionNode) {
 			return ((RevisionNode) node).getLabel();
 		}
 		return true;
 	}
-
-
-
-
 }

src/com/vectrace/MercurialEclipse/history/CompareRevisionAction.java

 					return;
 				}
 
-				boolean localEditable = right[0] == null;
-				CompareUtils.openEditor(left[0], right[0], false, localEditable);
+				CompareUtils.openEditor(left[0], right[0], false);
 			}
 		});
 		job.schedule();

src/com/vectrace/MercurialEclipse/synchronize/actions/OpenAction.java

 					} else {
 						parentRev = new MercurialRevisionStorage(file, parents[0]);
 					}
-					CompareUtils.openEditor(thisRev, parentRev, false, false, configuration);
+					CompareUtils.openEditor(thisRev, parentRev, false, configuration);
 				} else {
 					// incoming
 					MercurialRevisionStorage remoteRev = new MercurialRevisionStorage(
 						parentRev = new MercurialRevisionStorage(
 								file, parentCs.getChangesetIndex(), parentCs.getChangeset(), parentCs);
 					}
-					CompareUtils.openEditor(remoteRev, parentRev, false, false, configuration);
+					CompareUtils.openEditor(remoteRev, parentRev, false, configuration);
 					// the line below compares the remote changeset with the local copy.
 					// it was replaced with the code above to fix the issue 10364
 					// CompareUtils.openEditor(file, cs, true, true);

src/com/vectrace/MercurialEclipse/team/CompareAction.java

  *******************************************************************************/
 package com.vectrace.MercurialEclipse.team;
 
-import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
 import org.eclipse.compare.CompareUI;
 import org.eclipse.compare.ResourceNode;
 import org.eclipse.core.resources.IFile;
 import com.vectrace.MercurialEclipse.MercurialEclipsePlugin;
 import com.vectrace.MercurialEclipse.commands.HgParentClient;
 import com.vectrace.MercurialEclipse.commands.HgResolveClient;
-import com.vectrace.MercurialEclipse.compare.HgCompareEditorInput;
 import com.vectrace.MercurialEclipse.compare.RevisionNode;
 import com.vectrace.MercurialEclipse.exception.HgException;
 import com.vectrace.MercurialEclipse.model.ChangeSet;
 							ChangeSet cs2 = LocalChangesetCache.getInstance()
 									.getOrFetchChangeSetById(file, parents[0]);
 							if (cs2 != null) {
-								CompareUtils.openEditor(file, cs2, true);
+								CompareUtils.openEditor(file, cs2);
 								return Status.OK_STATUS;
 							}
 						}
 		ResourceNode leftNode = new ResourceNode(file);
 		// mercurial version
 		RevisionNode rightNode = new RevisionNode(new MercurialRevisionStorage(file));
-		CompareUtils.openEditor(leftNode, rightNode, false, true, syncConfig);
+		CompareUtils.openEditor(leftNode, rightNode, false, syncConfig);
 	}
 
 	/**
 				ancestorNode = new RevisionNode(new MercurialRevisionStorage(file, ancestor));
 			}
 
-			final HgCompareEditorInput compareInput = new HgCompareEditorInput(
-					new CompareConfiguration(), file, ancestorNode, mergeNode, true);
+			final CompareEditorInput compareInput = CompareUtils.getPrecomputedCompareInput(file,
+					ancestorNode, mergeNode);
 
 			Display.getDefault().asyncExec(new Runnable() {
 				public void run() {

src/com/vectrace/MercurialEclipse/team/CompareWithAction.java

 				Messages.getString("CompareWithAction.compareWith"), file); //$NON-NLS-1$
 		int result = dialog.open();
 		if (result == IDialogConstants.OK_ID) {
-			CompareUtils.openEditor(file, dialog.getChangeSet(), true);
+			CompareUtils.openEditor(file, dialog.getChangeSet());
 		}
 	}
 

src/com/vectrace/MercurialEclipse/ui/ChangesetInfoTray.java

 								.getChangesetIndex());
 						MercurialRevisionStorage right = new MercurialRevisionStorage(file,
 								parents[0]);
-						CompareUtils.openEditor(left, right, true, false);
+						CompareUtils.openEditor(left, right, true);
 					} catch (HgException e) {
 						MercurialEclipsePlugin.logError(e);
 					}

src/com/vectrace/MercurialEclipse/ui/CommitFilesChooser.java

 import java.util.List;
 import java.util.Set;
 
-import org.eclipse.compare.CompareEditorInput;
 import org.eclipse.compare.ResourceNode;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
 				GridData.FILL_HORIZONTAL));
 	}
 
-	protected CompareEditorInput getCompareEditorInput() {
-		if (selectedFile == null) {
-			return null;
-		}
-		MercurialRevisionStorage iStorage = new MercurialRevisionStorage(
-				selectedFile);
-		ResourceNode right = new RevisionNode(iStorage);
-		ResourceNode left = new ResourceNode(selectedFile);
-		return CompareUtils.getCompareInput(left, right, false);
-	}
-
-	@SuppressWarnings("unused")
 	private void makeActions() {
 		getViewer().addDoubleClickListener(new IDoubleClickListener() {
 			public void doubleClick(DoubleClickEvent event) {
 					selectedFile);
 			ResourceNode right = new RevisionNode(iStorage);
 			ResourceNode left = new ResourceNode(selectedFile);
-			CompareUtils.openEditor(left, right, true, false, null);
+			CompareUtils.openEditor(left, right, true, null);
 		}
 	}
 

src/com/vectrace/MercurialEclipse/utils/CompareUtils.java

 		// hide constructor of utility class.
 	}
 
-	public static void openEditor(IFile file, ChangeSet changeset, boolean localEditable) {
+	public static void openEditor(IFile file, ChangeSet changeset) {
 		int changesetIndex = changeset == null ? 0 : changeset.getChangesetIndex();
 		String changesetId = changeset == null ? null : changeset.getChangeset();
 
 			leftNode = new ResourceNode(file);
 		}
 		RevisionNode rightNode = getNode(new MercurialRevisionStorage(file, changesetIndex, changesetId, changeset));
-		openEditor(leftNode, rightNode, false, localEditable, null);
+		openEditor(leftNode, rightNode, false, null);
 	}
 
-	public static void openEditor(MercurialRevisionStorage left, MercurialRevisionStorage right, boolean dialog, boolean localEditable) {
-		openEditor(left, right, dialog, localEditable, null);
+	public static void openEditor(MercurialRevisionStorage left, MercurialRevisionStorage right, boolean dialog) {
+		openEditor(left, right, dialog, null);
 	}
 
 	public static void openEditor(MercurialRevisionStorage left, MercurialRevisionStorage right,
-			boolean dialog, boolean localEditable, ISynchronizePageConfiguration configuration) {
+			boolean dialog, ISynchronizePageConfiguration configuration) {
 		ResourceNode leftNode;
 		ResourceNode rightNode;
 		if (right == null) {
 			leftNode = getNode(left);
 			rightNode = getNode(right);
 		}
-		openEditor(leftNode, rightNode, dialog, localEditable, configuration);
+		openEditor(leftNode, rightNode, dialog, configuration);
 	}
 
 	/**
+	 * Open a compare editor asynchronously
+	 *
 	 * @param configuration might be null
 	 */
 	public static void openEditor(final ResourceNode left, final ResourceNode right,
-			final boolean dialog, final boolean localEditable,
-			final ISynchronizePageConfiguration configuration) {
+			final boolean dialog, final ISynchronizePageConfiguration configuration) {
 		Assert.isNotNull(right);
 		if (dialog) {
-			openCompareDialog(left, right, localEditable);
+			openCompareDialog(getCompareInput(left, right, null));
 			return;
 		}
 
-		final CompareEditorInput compareInput = getCompareInput(left, right, localEditable, configuration);
-		if (compareInput == null) {
-			return;
-		}
+		final CompareEditorInput compareInput = getCompareInput(left, right, configuration);
 
 		UIJob uiDiffJob = new UIJob("Preparing hg diff...") {
 			@Override
 	}
 
 	/**
-	 * Opens a compare dialog and returns it. Unfortunately the dialog is
-	 * internal Eclipse API, so it might change in future Eclipse versions.
-	 *
-	 * @param left
-	 *            the left ResourceNode to determine the compare editor input
-	 * @param right
-	 *            the right ResourceNode to determine the compare editor input
-	 */
-	public static int openCompareDialog(ResourceNode left, ResourceNode right, boolean localEditable) {
-		CompareEditorInput compareInput = getCompareInput(left, right, localEditable);
-		return openCompareDialog(compareInput);
-	}
-
-	/**
 	 * Opens a compare dialog using the given input.
 	 *
 	 * @param compareInput
 	 * @return
 	 */
-	public static int openCompareDialog(final CompareEditorInput compareInput) {
+	private static int openCompareDialog(final CompareEditorInput compareInput) {
 		Runnable uiAction = new Runnable() {
 			public void run() {
 				CompareUI.openCompareDialog(compareInput);
 		return Window.CANCEL;
 	}
 
-	public static CompareEditorInput getCompareInput(ResourceNode left, ResourceNode right,
-			boolean localEditable) {
-		return getCompareInput(left, right, localEditable, null);
-	}
-
 	/**
 	 * @param configuration might be null
 	 */
-	public static CompareEditorInput getCompareInput(ResourceNode left, ResourceNode right,
-			boolean localEditable, ISynchronizePageConfiguration configuration) {
+	private static CompareEditorInput getCompareInput(ResourceNode left, ResourceNode right,
+			ISynchronizePageConfiguration configuration) {
 		IFile resource = (IFile) right.getResource();
 		// switch left to right if left is null and put local to left
 		ResourceNode leftNode = left != null ? left : right;
 		return new HgCompareEditorInput(new CompareConfiguration(), resource, leftNode, rightNode, configuration);
 	}
 
+	public static CompareEditorInput getPrecomputedCompareInput(IFile leftResource,
+			ResourceNode ancestor, ResourceNode right) {
+		return new HgCompareEditorInput(new CompareConfiguration(), leftResource, ancestor, right);
+	}
+
 	private static RevisionNode getNode(MercurialRevisionStorage rev) {
 		return rev == null ? null : new RevisionNode(rev);
 	}

src/com/vectrace/MercurialEclipse/wizards/IncomingPage.java

 						parentRev = new MercurialRevisionStorage(
 								file, parentCs.getChangesetIndex(), parentCs.getChangeset(), parentCs);
 					}
-					CompareUtils.openEditor(remoteRev, parentRev, true, false);
+					CompareUtils.openEditor(remoteRev, parentRev, true);
 					// the line below compares the remote changeset with the local copy.
 					// it was replaced with the code above to fix the issue 10364
 					// CompareUtils.openEditor(file, cs, true, true);

src/com/vectrace/MercurialEclipse/wizards/OutgoingPage.java

 				} else {
 					parentRev = new MercurialRevisionStorage(file, parents[0]);
 				}
-				CompareUtils.openEditor(thisRev, parentRev, true, false);
+				CompareUtils.openEditor(thisRev, parentRev, true);
 			} else {
 				// It is possible that file has been removed or part of the
 				// repository but not the project (and has incoming changes)