### Eclipse Workspace Patch 1.0 #P org.eclipse.compare Index: compare/org/eclipse/compare/internal/patch/Hunk.java =================================================================== RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Hunk.java,v retrieving revision 1.11 diff -u -r1.11 Hunk.java --- compare/org/eclipse/compare/internal/patch/Hunk.java 6 Oct 2005 17:18:00 -0000 1.11 +++ compare/org/eclipse/compare/internal/patch/Hunk.java 21 Oct 2005 14:39:03 -0000 @@ -165,4 +165,8 @@ return this; return null; } + + protected boolean getHunkProblem() { + return fHunkProblem; + } } Index: compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java =================================================================== RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java,v retrieving revision 1.30 diff -u -r1.30 PreviewPatchPage.java --- compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java 6 Oct 2005 17:18:00 -0000 1.30 +++ compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java 21 Oct 2005 14:39:03 -0000 @@ -338,11 +338,31 @@ DiffProject proj = null; if (obj instanceof DiffProject){ proj = (DiffProject) obj; + //Check to see if any of the Diffs contained by the DiffProject + //have their diff problems set + Object[] diffs = proj.getChildren(null); + for (int i= 0; i 0){ + IResource patchFile= resources[0]; + return patchFile.getFullPath().toString(); + } + + } + return ""; //$NON-NLS-1$ + } + // static helpers + + /** + * Checks to see if the file that has been selected for Apply Patch + * is actually a patch + * @return true if the file selected to run Apply Patch on in the workspace is a patch file + * or if the clipboard contains a patch + */ + private boolean adjustToCurrentTarget() { + //Readjust selection if there is a patch selected in the workspace or on the clipboard + //Check workspace first + IResource patchTarget = fPatchWizard.getTarget(); + if (patchTarget instanceof IFile) { + Reader reader = null; + try { + try { + reader = new FileReader(patchTarget.getRawLocation().toFile()); + } catch (FileNotFoundException ex) {/*silently ignored*/ + } catch (NullPointerException nex) {/*silently ignored*/ + } + if (isPatchFile(reader)) { + //Set choice to workspace + setInputButtonState(WORKSPACE); + if (fTreeViewer != null && patchTarget.exists()) { + fTreeViewer.expandToLevel(patchTarget, 0); + fTreeViewer.setSelection(new StructuredSelection(patchTarget)); + } + return true; + } + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException x) {/*silently ignored*/ + } + } + } + } else { + //check out clipboard contents + Reader reader = null; + Control c = getControl(); + if (c != null) { + Clipboard clipboard = new Clipboard(c.getDisplay()); + Object o = clipboard.getContents(TextTransfer.getInstance()); + clipboard.dispose(); + try { + if (o instanceof String) { + reader = new StringReader((String) o); + if (isPatchFile(reader)) { + setInputButtonState(CLIPBOARD); + return true; + } + } + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException x) {/*silently ignored*/ + } + } + } + } + } + return false; + } + + + + private boolean isPatchFile(Reader reader){ + WorkspacePatcher patcher= ((PatchWizard) getWizard()).getPatcher(); + + try { + patcher.parse(new BufferedReader(reader)); + } catch (IOException ex) {return false;} + + Diff[] diffs= patcher.getDiffs(); + if (diffs == null || diffs.length == 0) { + return false; + } + + return true; + } + + /* + * Clears the dialog message box + */ + private void clearErrorMessage(){ + setErrorMessage(null); + } + private void setInputButtonState(int state) { switch (state) { case CLIPBOARD : fUseClipboardButton.setSelection(true); + fUsePatchFileButton.setSelection(false); + fUseWorkspaceButton.setSelection(false); break; case FILE : + fUseClipboardButton.setSelection(false); fUsePatchFileButton.setSelection(true); + fUseWorkspaceButton.setSelection(false); break; case WORKSPACE : - fUsePatchFileButton.setSelection(true); + fUseClipboardButton.setSelection(false); + fUsePatchFileButton.setSelection(false); + fUseWorkspaceButton.setSelection(true); break; } Index: compare/org/eclipse/compare/internal/Utilities.java =================================================================== RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java,v retrieving revision 1.41 diff -u -r1.41 Utilities.java --- compare/org/eclipse/compare/internal/Utilities.java 6 Oct 2005 17:18:00 -0000 1.41 +++ compare/org/eclipse/compare/internal/Utilities.java 21 Oct 2005 14:39:03 -0000 @@ -594,7 +594,7 @@ } } - public static IResource getResource(ISelection selection) { + public static IResource getFirstResource(ISelection selection) { IResource[] resources = getResources(selection); if (resources.length > 0) return resources[0]; Index: compare/org/eclipse/compare/CompareUI.java =================================================================== RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/CompareUI.java,v retrieving revision 1.26 diff -u -r1.26 CompareUI.java --- compare/org/eclipse/compare/CompareUI.java 6 Oct 2005 17:18:00 -0000 1.26 +++ compare/org/eclipse/compare/CompareUI.java 21 Oct 2005 14:39:03 -0000 @@ -14,9 +14,7 @@ import org.eclipse.compare.internal.CompareUIPlugin; import org.eclipse.compare.internal.DocumentManager; -import org.eclipse.compare.internal.patch.WorkspacePatcher; import org.eclipse.compare.structuremergeviewer.ICompareInput; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.resource.ImageDescriptor; @@ -358,39 +356,5 @@ DocumentManager.remove(document); } - /** - * Returns a string that must be the first line of a workspace patch (a multi-project patch - * that is understood by the Apply Patch wizard). Each project to be included in the patch - * must be prefixed by the line obtained from the getWorkspacePatchProjectHeader(). - * This snippet outlines how the a workspace patch is to be created: - *
-	 *  //Write out workspace patch header
-	 *  stream.println(CompareUI.getWorkspacePatchHeader());
-	 *  for (int i=0; i
-	 * @return String
-	 * @see CompareUI#getWorkspacePatchProjectHeader(IProject)
-	 * @since 3.2
-	 */
-	public static String getWorkspacePatchHeader() {
-		return WorkspacePatcher.MULTIPROJECTPATCH_HEADER+" "+WorkspacePatcher.MULTIPROJECTPATCH_VERSION; //$NON-NLS-1$
-	}
-
-	/**
-	 * Returns the project header that must appear before any patches that apply to that
-	 * project. All patches that are encountered after this header and before the next header
-	 * are understood to belong the the project.
-	 * @param project project to be patched
-	 * @return String
-	 * @see CompareUI#getWorkspacePatchHeader()
-	 * @since 3.2
-	 */
-	public static String getWorkspacePatchProjectHeader(IProject project) {
-		return WorkspacePatcher.MULTIPROJECTPATCH_PROJECT+" "+ project.getName(); //$NON-NLS-1$
-	}
 }
 
Index: compare/org/eclipse/compare/patch/WorkspacePatcherUI.java
===================================================================
RCS file: compare/org/eclipse/compare/patch/WorkspacePatcherUI.java
diff -N compare/org/eclipse/compare/patch/WorkspacePatcherUI.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ compare/org/eclipse/compare/patch/WorkspacePatcherUI.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,41 @@
+package org.eclipse.compare.patch;
+
+import org.eclipse.compare.internal.patch.WorkspacePatcher;
+import org.eclipse.core.resources.IProject;
+
+public class WorkspacePatcherUI {
+	/**
+	 * Returns a string that must be the first line of a workspace patch (a multi-project patch 
+	 * that is understood by the Apply Patch wizard). Each project to be included in the patch
+	 * must be prefixed by the line obtained from the getWorkspacePatchProjectHeader().
+	 * This snippet outlines how the a workspace patch is to be created:
+	 * 
+	 *  //Write out workspace patch header
+	 *  stream.println(CompareUI.getWorkspacePatchHeader());
+	 *  for (int i=0; i
+	 * @return String
+	 * @see WorkspacePatcherUI#getWorkspacePatchProjectHeader(IProject)
+	 * @since 3.2
+	 */
+	public static String getWorkspacePatchHeader() {
+		return WorkspacePatcher.MULTIPROJECTPATCH_HEADER+" "+WorkspacePatcher.MULTIPROJECTPATCH_VERSION; //$NON-NLS-1$
+	}
+
+	/**
+	 * Returns the project header that must appear before any patches that apply to that
+	 * project. All patches that are encountered after this header and before the next header
+	 * are understood to belong the the project.
+	 * @param project project to be patched
+	 * @return String
+	 * @see WorkspacePatcherUI#getWorkspacePatchHeader()
+	 * @since 3.2
+	 */
+	public static String getWorkspacePatchProjectHeader(IProject project) {
+		return WorkspacePatcher.MULTIPROJECTPATCH_PROJECT+" "+ project.getName(); //$NON-NLS-1$
+	}
+}