|
Lines 19-24
Link Here
|
| 19 |
import java.io.StringReader; |
19 |
import java.io.StringReader; |
| 20 |
import java.text.MessageFormat; |
20 |
import java.text.MessageFormat; |
| 21 |
|
21 |
|
|
|
22 |
import org.eclipse.compare.PatchReader; |
| 22 |
import org.eclipse.compare.internal.ICompareContextIds; |
23 |
import org.eclipse.compare.internal.ICompareContextIds; |
| 23 |
import org.eclipse.compare.internal.Utilities; |
24 |
import org.eclipse.compare.internal.Utilities; |
| 24 |
import org.eclipse.core.resources.IFile; |
25 |
import org.eclipse.core.resources.IFile; |
|
Lines 72-82
Link Here
|
| 72 |
private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$ |
73 |
private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$ |
| 73 |
private final static String STORE_INPUT_METHOD_ID= PAGE_NAME+".INPUT_METHOD"; //$NON-NLS-1$ |
74 |
private final static String STORE_INPUT_METHOD_ID= PAGE_NAME+".INPUT_METHOD"; //$NON-NLS-1$ |
| 74 |
private final static String STORE_WORKSPACE_PATH_ID= PAGE_NAME+".WORKSPACE_PATH"; //$NON-NLS-1$ |
75 |
private final static String STORE_WORKSPACE_PATH_ID= PAGE_NAME+".WORKSPACE_PATH"; //$NON-NLS-1$ |
| 75 |
//patch input constants |
76 |
|
| 76 |
protected final static int CLIPBOARD= 1; |
|
|
| 77 |
protected final static int FILE= 2; |
| 78 |
protected final static int WORKSPACE= 3; |
| 79 |
|
| 80 |
static final char SEPARATOR= System.getProperty("file.separator").charAt(0); //$NON-NLS-1$ |
77 |
static final char SEPARATOR= System.getProperty("file.separator").charAt(0); //$NON-NLS-1$ |
| 81 |
|
78 |
|
| 82 |
private boolean fShowError= false; |
79 |
private boolean fShowError= false; |
|
Lines 102-112
Link Here
|
| 102 |
//Allow error messages if the selected input actually has something selected in it |
99 |
//Allow error messages if the selected input actually has something selected in it |
| 103 |
fShowError=true; |
100 |
fShowError=true; |
| 104 |
switch(getInputMethod()){ |
101 |
switch(getInputMethod()){ |
| 105 |
case FILE: |
102 |
case PatchReader.FILE: |
| 106 |
fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$ |
103 |
fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$ |
| 107 |
break; |
104 |
break; |
| 108 |
|
105 |
|
| 109 |
case WORKSPACE: |
106 |
case PatchReader.WORKSPACE: |
| 110 |
fShowError = (!fTreeViewer.getSelection().isEmpty()); |
107 |
fShowError = (!fTreeViewer.getSelection().isEmpty()); |
| 111 |
break; |
108 |
break; |
| 112 |
|
109 |
|
|
Lines 131-137
Link Here
|
| 131 |
} |
128 |
} |
| 132 |
|
129 |
|
| 133 |
/* package */ String getPatchName() { |
130 |
/* package */ String getPatchName() { |
| 134 |
if (getInputMethod()==CLIPBOARD) |
131 |
if (getInputMethod()==PatchReader.CLIPBOARD) |
| 135 |
return PatchMessages.InputPatchPage_Clipboard; |
132 |
return PatchMessages.InputPatchPage_Clipboard; |
| 136 |
return getPatchFilePath(); |
133 |
return getPatchFilePath(); |
| 137 |
} |
134 |
} |
|
Lines 176-200
Link Here
|
| 176 |
|
173 |
|
| 177 |
String source= ""; //$NON-NLS-1$ |
174 |
String source= ""; //$NON-NLS-1$ |
| 178 |
|
175 |
|
| 179 |
// Create a reader for the input |
|
|
| 180 |
Reader reader= null; |
| 181 |
try { |
176 |
try { |
| 182 |
int inputMethod= getInputMethod(); |
177 |
int inputMethod= getInputMethod(); |
| 183 |
if (inputMethod==CLIPBOARD) { |
178 |
if (inputMethod==PatchReader.CLIPBOARD) { |
| 184 |
Control c= getControl(); |
179 |
Control c= getControl(); |
| 185 |
if (c != null) { |
180 |
if (c != null) { |
| 186 |
Clipboard clipboard= new Clipboard(c.getDisplay()); |
181 |
Clipboard clipboard= new Clipboard(c.getDisplay()); |
| 187 |
Object o= clipboard.getContents(TextTransfer.getInstance()); |
182 |
PatchReader.readPatchFromClipboard(clipboard, patcher); |
| 188 |
clipboard.dispose(); |
|
|
| 189 |
if (o instanceof String) |
| 190 |
reader= new StringReader((String)o); |
| 191 |
} |
183 |
} |
| 192 |
source= PatchMessages.InputPatchPage_Clipboard_title; |
184 |
source= PatchMessages.InputPatchPage_Clipboard_title; |
| 193 |
} else if (inputMethod==FILE) { |
185 |
} else if (inputMethod==PatchReader.FILE) { |
| 194 |
String patchFilePath= getPatchFilePath(); |
186 |
String patchFilePath= getPatchFilePath(); |
| 195 |
if (patchFilePath != null) { |
187 |
if (patchFilePath != null) { |
| 196 |
try { |
188 |
try { |
| 197 |
reader= new FileReader(patchFilePath); |
189 |
PatchReader.readPatchFromFile(patchFilePath, patcher); |
| 198 |
} catch (FileNotFoundException ex) { |
190 |
} catch (FileNotFoundException ex) { |
| 199 |
MessageDialog.openError(null, |
191 |
MessageDialog.openError(null, |
| 200 |
PatchMessages.InputPatchPage_PatchErrorDialog_title, |
192 |
PatchMessages.InputPatchPage_PatchErrorDialog_title, |
|
Lines 202-214
Link Here
|
| 202 |
} |
194 |
} |
| 203 |
} |
195 |
} |
| 204 |
source= PatchMessages.InputPatchPage_PatchFile_title; |
196 |
source= PatchMessages.InputPatchPage_PatchFile_title; |
| 205 |
} else if (inputMethod==WORKSPACE) { |
197 |
} else if (inputMethod==PatchReader.WORKSPACE) { |
| 206 |
//Get the selected patch file (tree will only allow for one selection) |
198 |
//Get the selected patch file (tree will only allow for one selection) |
| 207 |
IResource[] resources= Utilities.getResources(fTreeViewer.getSelection()); |
199 |
IResource[] resources= Utilities.getResources(fTreeViewer.getSelection()); |
| 208 |
IResource patchFile= resources[0]; |
200 |
IResource patchFile= resources[0]; |
| 209 |
if (patchFile!=null) { |
201 |
if (patchFile!=null) { |
| 210 |
try { |
202 |
try { |
| 211 |
reader= new FileReader(patchFile.getRawLocation().toFile()); |
203 |
PatchReader.readPatchFromFile(patchFile.getRawLocation(), patcher); |
| 212 |
} catch (FileNotFoundException ex) { |
204 |
} catch (FileNotFoundException ex) { |
| 213 |
MessageDialog.openError(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, PatchMessages.InputPatchPage_PatchFileNotFound_message); |
205 |
MessageDialog.openError(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, PatchMessages.InputPatchPage_PatchFileNotFound_message); |
| 214 |
} catch (NullPointerException nex) { |
206 |
} catch (NullPointerException nex) { |
|
Lines 218-242
Link Here
|
| 218 |
} |
210 |
} |
| 219 |
source= PatchMessages.InputPatchPage_WorkspacePatch_title; |
211 |
source= PatchMessages.InputPatchPage_WorkspacePatch_title; |
| 220 |
} |
212 |
} |
| 221 |
|
213 |
} catch (IOException e) { |
| 222 |
// parse the input |
214 |
MessageDialog.openError(null, |
| 223 |
if (reader != null) { |
215 |
PatchMessages.InputPatchPage_PatchErrorDialog_title, |
| 224 |
try { |
216 |
PatchMessages.InputPatchPage_ParseError_message); |
| 225 |
patcher.parse(new BufferedReader(reader)); |
|
|
| 226 |
} catch (IOException ex) { |
| 227 |
MessageDialog.openError(null, |
| 228 |
PatchMessages.InputPatchPage_PatchErrorDialog_title, |
| 229 |
PatchMessages.InputPatchPage_ParseError_message); |
| 230 |
} |
| 231 |
} |
| 232 |
} finally { |
| 233 |
if (reader != null) { |
| 234 |
try { |
| 235 |
reader.close(); |
| 236 |
} catch (IOException x) { |
| 237 |
// silently ignored |
| 238 |
} |
| 239 |
} |
| 240 |
} |
217 |
} |
| 241 |
|
218 |
|
| 242 |
Diff[] diffs= patcher.getDiffs(); |
219 |
Diff[] diffs= patcher.getDiffs(); |
|
Lines 340-347
Link Here
|
| 340 |
clearErrorMessage(); |
317 |
clearErrorMessage(); |
| 341 |
fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$ |
318 |
fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$ |
| 342 |
int state= getInputMethod(); |
319 |
int state= getInputMethod(); |
| 343 |
setEnablePatchFile(state==FILE); |
320 |
setEnablePatchFile(state==PatchReader.FILE); |
| 344 |
setEnableWorkspacePatch(state==WORKSPACE); |
321 |
setEnableWorkspacePatch(state==PatchReader.WORKSPACE); |
| 345 |
updateWidgetEnablements(); |
322 |
updateWidgetEnablements(); |
| 346 |
} |
323 |
} |
| 347 |
}); |
324 |
}); |
|
Lines 374-381
Link Here
|
| 374 |
//If there is anything typed in at all |
351 |
//If there is anything typed in at all |
| 375 |
fShowError = (!fTreeViewer.getSelection().isEmpty()); |
352 |
fShowError = (!fTreeViewer.getSelection().isEmpty()); |
| 376 |
int state= getInputMethod(); |
353 |
int state= getInputMethod(); |
| 377 |
setEnablePatchFile(state==FILE); |
354 |
setEnablePatchFile(state==PatchReader.FILE); |
| 378 |
setEnableWorkspacePatch(state==WORKSPACE); |
355 |
setEnableWorkspacePatch(state==PatchReader.WORKSPACE); |
| 379 |
updateWidgetEnablements(); |
356 |
updateWidgetEnablements(); |
| 380 |
} |
357 |
} |
| 381 |
}); |
358 |
}); |
|
Lines 423-429
Link Here
|
| 423 |
|
400 |
|
| 424 |
boolean gotPatch= false; |
401 |
boolean gotPatch= false; |
| 425 |
int inputMethod= getInputMethod(); |
402 |
int inputMethod= getInputMethod(); |
| 426 |
if (inputMethod==CLIPBOARD) { |
403 |
if (inputMethod==PatchReader.CLIPBOARD) { |
| 427 |
Control c= getControl(); |
404 |
Control c= getControl(); |
| 428 |
if (c != null) { |
405 |
if (c != null) { |
| 429 |
Clipboard clipboard= new Clipboard(c.getDisplay()); |
406 |
Clipboard clipboard= new Clipboard(c.getDisplay()); |
|
Lines 439-445
Link Here
|
| 439 |
error= PatchMessages.InputPatchPage_NoTextInClipboard_message; |
416 |
error= PatchMessages.InputPatchPage_NoTextInClipboard_message; |
| 440 |
} else |
417 |
} else |
| 441 |
error= PatchMessages.InputPatchPage_CouldNotReadClipboard_message; |
418 |
error= PatchMessages.InputPatchPage_CouldNotReadClipboard_message; |
| 442 |
} else if (inputMethod==FILE) { |
419 |
} else if (inputMethod==PatchReader.FILE) { |
| 443 |
String path= fPatchFileNameField.getText(); |
420 |
String path= fPatchFileNameField.getText(); |
| 444 |
if (path != null && path.length() > 0) { |
421 |
if (path != null && path.length() > 0) { |
| 445 |
File file= new File(path); |
422 |
File file= new File(path); |
|
Lines 449-455
Link Here
|
| 449 |
} else { |
426 |
} else { |
| 450 |
error= PatchMessages.InputPatchPage_NoFileName_message; |
427 |
error= PatchMessages.InputPatchPage_NoFileName_message; |
| 451 |
} |
428 |
} |
| 452 |
} else if (inputMethod==WORKSPACE) { |
429 |
} else if (inputMethod==PatchReader.WORKSPACE) { |
| 453 |
//Get the selected patch file (tree will only allow for one selection) |
430 |
//Get the selected patch file (tree will only allow for one selection) |
| 454 |
IResource[] resources= Utilities.getResources(fTreeViewer.getSelection()); |
431 |
IResource[] resources= Utilities.getResources(fTreeViewer.getSelection()); |
| 455 |
if (resources!=null&&resources.length>0) { |
432 |
if (resources!=null&&resources.length>0) { |
|
Lines 567-573
Link Here
|
| 567 |
*/ |
544 |
*/ |
| 568 |
private void restoreWidgetValues() { |
545 |
private void restoreWidgetValues() { |
| 569 |
|
546 |
|
| 570 |
int inputMethod= FILE; |
547 |
int inputMethod= PatchReader.FILE; |
| 571 |
|
548 |
|
| 572 |
IDialogSettings settings= getDialogSettings(); |
549 |
IDialogSettings settings= getDialogSettings(); |
| 573 |
if (settings != null) { |
550 |
if (settings != null) { |
|
Lines 594-601
Link Here
|
| 594 |
//if there is a valid patch on the clipboard. This will be done in adjustToCurrentTarget() |
571 |
//if there is a valid patch on the clipboard. This will be done in adjustToCurrentTarget() |
| 595 |
//so just set it to FILE now and, if there exists a patch on the clipboard, then clipboard |
572 |
//so just set it to FILE now and, if there exists a patch on the clipboard, then clipboard |
| 596 |
//will be selected automatically |
573 |
//will be selected automatically |
| 597 |
if (inputMethod == CLIPBOARD){ |
574 |
if (inputMethod == PatchReader.CLIPBOARD){ |
| 598 |
inputMethod=FILE; |
575 |
inputMethod=PatchReader.FILE; |
| 599 |
fPatchFileNameField.deselectAll(); |
576 |
fPatchFileNameField.deselectAll(); |
| 600 |
} |
577 |
} |
| 601 |
|
578 |
|
|
Lines 613-620
Link Here
|
| 613 |
//check to see if the current input is set to workspace - if it is switch it |
590 |
//check to see if the current input is set to workspace - if it is switch it |
| 614 |
//back to clipboard since there is no corresponding element to go along with |
591 |
//back to clipboard since there is no corresponding element to go along with |
| 615 |
//the tree viewer |
592 |
//the tree viewer |
| 616 |
if (inputMethod == WORKSPACE) |
593 |
if (inputMethod == PatchReader.WORKSPACE) |
| 617 |
inputMethod=FILE; |
594 |
inputMethod=PatchReader.FILE; |
| 618 |
} |
595 |
} |
| 619 |
} |
596 |
} |
| 620 |
|
597 |
|
|
Lines 682-688
Link Here
|
| 682 |
|
659 |
|
| 683 |
if (isPatchFile(reader)) { |
660 |
if (isPatchFile(reader)) { |
| 684 |
//Set choice to workspace |
661 |
//Set choice to workspace |
| 685 |
setInputButtonState(WORKSPACE); |
662 |
setInputButtonState(PatchReader.WORKSPACE); |
| 686 |
if (fTreeViewer != null && patchTarget.exists()) { |
663 |
if (fTreeViewer != null && patchTarget.exists()) { |
| 687 |
fTreeViewer.expandToLevel(patchTarget, 0); |
664 |
fTreeViewer.expandToLevel(patchTarget, 0); |
| 688 |
fTreeViewer.setSelection(new StructuredSelection(patchTarget)); |
665 |
fTreeViewer.setSelection(new StructuredSelection(patchTarget)); |
|
Lines 709-715
Link Here
|
| 709 |
if (o instanceof String) { |
686 |
if (o instanceof String) { |
| 710 |
reader = new StringReader((String) o); |
687 |
reader = new StringReader((String) o); |
| 711 |
if (isPatchFile(reader)) { |
688 |
if (isPatchFile(reader)) { |
| 712 |
setInputButtonState(CLIPBOARD); |
689 |
setInputButtonState(PatchReader.CLIPBOARD); |
| 713 |
return true; |
690 |
return true; |
| 714 |
} |
691 |
} |
| 715 |
} |
692 |
} |
|
Lines 753-788
Link Here
|
| 753 |
private void setInputButtonState(int state) { |
730 |
private void setInputButtonState(int state) { |
| 754 |
|
731 |
|
| 755 |
switch (state) { |
732 |
switch (state) { |
| 756 |
case CLIPBOARD : |
733 |
case PatchReader.CLIPBOARD : |
| 757 |
fUseClipboardButton.setSelection(true); |
734 |
fUseClipboardButton.setSelection(true); |
| 758 |
fUsePatchFileButton.setSelection(false); |
735 |
fUsePatchFileButton.setSelection(false); |
| 759 |
fUseWorkspaceButton.setSelection(false); |
736 |
fUseWorkspaceButton.setSelection(false); |
| 760 |
break; |
737 |
break; |
| 761 |
|
738 |
|
| 762 |
case FILE : |
739 |
case PatchReader.FILE : |
| 763 |
fUseClipboardButton.setSelection(false); |
740 |
fUseClipboardButton.setSelection(false); |
| 764 |
fUsePatchFileButton.setSelection(true); |
741 |
fUsePatchFileButton.setSelection(true); |
| 765 |
fUseWorkspaceButton.setSelection(false); |
742 |
fUseWorkspaceButton.setSelection(false); |
| 766 |
break; |
743 |
break; |
| 767 |
|
744 |
|
| 768 |
case WORKSPACE : |
745 |
case PatchReader.WORKSPACE : |
| 769 |
fUseClipboardButton.setSelection(false); |
746 |
fUseClipboardButton.setSelection(false); |
| 770 |
fUsePatchFileButton.setSelection(false); |
747 |
fUsePatchFileButton.setSelection(false); |
| 771 |
fUseWorkspaceButton.setSelection(true); |
748 |
fUseWorkspaceButton.setSelection(true); |
| 772 |
break; |
749 |
break; |
| 773 |
} |
750 |
} |
| 774 |
|
751 |
|
| 775 |
setEnablePatchFile(state==FILE); |
752 |
setEnablePatchFile(state==PatchReader.FILE); |
| 776 |
setEnableWorkspacePatch(state==WORKSPACE); |
753 |
setEnableWorkspacePatch(state==PatchReader.WORKSPACE); |
| 777 |
} |
754 |
} |
| 778 |
|
755 |
|
| 779 |
protected int getInputMethod() { |
756 |
protected int getInputMethod() { |
| 780 |
if (fUseClipboardButton.getSelection()) |
757 |
if (fUseClipboardButton.getSelection()) |
| 781 |
return CLIPBOARD; |
758 |
return PatchReader.CLIPBOARD; |
| 782 |
else if (fUsePatchFileButton.getSelection()) |
759 |
else if (fUsePatchFileButton.getSelection()) |
| 783 |
return FILE; |
760 |
return PatchReader.FILE; |
| 784 |
else |
761 |
else |
| 785 |
return WORKSPACE; |
762 |
return PatchReader.WORKSPACE; |
| 786 |
} |
763 |
} |
| 787 |
|
764 |
|
| 788 |
private String getPatchFilePath() { |
765 |
private String getPatchFilePath() { |