Lines 21-26
Link Here
|
21 |
|
21 |
|
22 |
import org.eclipse.compare.internal.ICompareContextIds; |
22 |
import org.eclipse.compare.internal.ICompareContextIds; |
23 |
import org.eclipse.compare.internal.Utilities; |
23 |
import org.eclipse.compare.internal.Utilities; |
|
|
24 |
import org.eclipse.core.resources.IFile; |
24 |
import org.eclipse.core.resources.IResource; |
25 |
import org.eclipse.core.resources.IResource; |
25 |
import org.eclipse.core.resources.ResourcesPlugin; |
26 |
import org.eclipse.core.resources.ResourcesPlugin; |
26 |
import org.eclipse.core.runtime.IPath; |
27 |
import org.eclipse.core.runtime.IPath; |
Lines 30-35
Link Here
|
30 |
import org.eclipse.jface.dialogs.MessageDialog; |
31 |
import org.eclipse.jface.dialogs.MessageDialog; |
31 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
32 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
32 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
33 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
|
34 |
import org.eclipse.jface.viewers.StructuredSelection; |
33 |
import org.eclipse.jface.viewers.TreeViewer; |
35 |
import org.eclipse.jface.viewers.TreeViewer; |
34 |
import org.eclipse.jface.wizard.IWizardPage; |
36 |
import org.eclipse.jface.wizard.IWizardPage; |
35 |
import org.eclipse.jface.wizard.WizardPage; |
37 |
import org.eclipse.jface.wizard.WizardPage; |
Lines 40-45
Link Here
|
40 |
import org.eclipse.swt.events.ModifyListener; |
42 |
import org.eclipse.swt.events.ModifyListener; |
41 |
import org.eclipse.swt.events.SelectionAdapter; |
43 |
import org.eclipse.swt.events.SelectionAdapter; |
42 |
import org.eclipse.swt.events.SelectionEvent; |
44 |
import org.eclipse.swt.events.SelectionEvent; |
|
|
45 |
import org.eclipse.swt.events.ShellAdapter; |
46 |
import org.eclipse.swt.events.ShellEvent; |
43 |
import org.eclipse.swt.layout.GridData; |
47 |
import org.eclipse.swt.layout.GridData; |
44 |
import org.eclipse.swt.layout.GridLayout; |
48 |
import org.eclipse.swt.layout.GridLayout; |
45 |
import org.eclipse.swt.widgets.Button; |
49 |
import org.eclipse.swt.widgets.Button; |
Lines 48-58
Link Here
|
48 |
import org.eclipse.swt.widgets.Control; |
52 |
import org.eclipse.swt.widgets.Control; |
49 |
import org.eclipse.swt.widgets.FileDialog; |
53 |
import org.eclipse.swt.widgets.FileDialog; |
50 |
import org.eclipse.swt.widgets.Label; |
54 |
import org.eclipse.swt.widgets.Label; |
|
|
55 |
import org.eclipse.swt.widgets.Shell; |
51 |
import org.eclipse.swt.widgets.Text; |
56 |
import org.eclipse.swt.widgets.Text; |
52 |
import org.eclipse.ui.PlatformUI; |
57 |
import org.eclipse.ui.PlatformUI; |
53 |
import org.eclipse.ui.model.WorkbenchContentProvider; |
58 |
import org.eclipse.ui.model.WorkbenchContentProvider; |
54 |
import org.eclipse.ui.model.WorkbenchLabelProvider; |
59 |
import org.eclipse.ui.model.WorkbenchLabelProvider; |
55 |
import org.eclipse.ui.model.WorkbenchViewerSorter; |
60 |
import org.eclipse.ui.views.navigator.ResourceSorter; |
|
|
61 |
|
62 |
|
56 |
|
63 |
|
57 |
/* package */ class InputPatchPage extends WizardPage { |
64 |
/* package */ class InputPatchPage extends WizardPage { |
58 |
|
65 |
|
Lines 64-69
Link Here
|
64 |
private final static String PAGE_NAME= "PatchWizardPage1"; //$NON-NLS-1$ |
71 |
private final static String PAGE_NAME= "PatchWizardPage1"; //$NON-NLS-1$ |
65 |
private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$ |
72 |
private final static String STORE_PATCH_FILES_ID= PAGE_NAME+".PATCH_FILES"; //$NON-NLS-1$ |
66 |
private final static String STORE_INPUT_METHOD_ID= PAGE_NAME+".INPUT_METHOD"; //$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_WORKSPACE_PATH_ID= PAGE_NAME+".WORKSPACE_PATH"; //$NON-NLS-1$ |
67 |
//patch input constants |
75 |
//patch input constants |
68 |
protected final static int CLIPBOARD= 1; |
76 |
protected final static int CLIPBOARD= 1; |
69 |
protected final static int FILE= 2; |
77 |
protected final static int FILE= 2; |
Lines 85-96
Link Here
|
85 |
|
93 |
|
86 |
private PatchWizard fPatchWizard; |
94 |
private PatchWizard fPatchWizard; |
87 |
|
95 |
|
|
|
96 |
private ActivationListener fActivationListener = new ActivationListener(); |
97 |
|
88 |
protected final static String INPUTPATCHPAGE_NAME= "InputPatchPage"; //$NON-NLS-1$ |
98 |
protected final static String INPUTPATCHPAGE_NAME= "InputPatchPage"; //$NON-NLS-1$ |
89 |
|
99 |
|
|
|
100 |
class ActivationListener extends ShellAdapter { |
101 |
public void shellActivated(ShellEvent e) { |
102 |
//Allow error messages if the selected input actually has something selected in it |
103 |
fShowError=true; |
104 |
switch(getInputMethod()){ |
105 |
case FILE: |
106 |
fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$ |
107 |
break; |
108 |
|
109 |
case WORKSPACE: |
110 |
fShowError = (!fTreeViewer.getSelection().isEmpty()); |
111 |
break; |
112 |
|
113 |
} |
114 |
updateWidgetEnablements(); |
115 |
} |
116 |
} |
117 |
|
118 |
|
90 |
InputPatchPage(PatchWizard pw) { |
119 |
InputPatchPage(PatchWizard pw) { |
91 |
super(INPUTPATCHPAGE_NAME, PatchMessages.InputPatchPage_title, null); |
120 |
super(INPUTPATCHPAGE_NAME, PatchMessages.InputPatchPage_title, null); |
92 |
fPatchWizard= pw; |
121 |
fPatchWizard= pw; |
93 |
setMessage(PatchMessages.InputPatchPage_message); |
122 |
setMessage(PatchMessages.InputPatchPage_message); |
94 |
} |
123 |
} |
95 |
|
124 |
|
96 |
/* |
125 |
/* |
Lines 115-125
Link Here
|
115 |
setControl(composite); |
144 |
setControl(composite); |
116 |
|
145 |
|
117 |
buildPatchFileGroup(composite); |
146 |
buildPatchFileGroup(composite); |
118 |
|
147 |
|
119 |
restoreWidgetValues(); |
148 |
//see if there are any better options presently selected |
120 |
|
149 |
if(!adjustToCurrentTarget()){ |
|
|
150 |
//get the persisted values |
151 |
restoreWidgetValues(); |
152 |
} |
153 |
|
154 |
//No error for dialog opening |
155 |
fShowError=false; |
156 |
clearErrorMessage(); |
121 |
updateWidgetEnablements(); |
157 |
updateWidgetEnablements(); |
122 |
|
158 |
|
|
|
159 |
Shell shell= getShell(); |
160 |
shell.addShellListener(fActivationListener); |
161 |
|
123 |
Dialog.applyDialogFont(composite); |
162 |
Dialog.applyDialogFont(composite); |
124 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICompareContextIds.PATCH_INPUT_WIZARD_PAGE); |
163 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICompareContextIds.PATCH_INPUT_WIZARD_PAGE); |
125 |
} |
164 |
} |
Lines 282-290
Link Here
|
282 |
addWorkspaceControls(parent); |
321 |
addWorkspaceControls(parent); |
283 |
|
322 |
|
284 |
// Add listeners |
323 |
// Add listeners |
285 |
fUsePatchFileButton.addSelectionListener(new SelectionAdapter() { |
324 |
fUseClipboardButton.addSelectionListener(new SelectionAdapter() { |
286 |
public void widgetSelected(SelectionEvent e) { |
325 |
public void widgetSelected(SelectionEvent e) { |
|
|
326 |
if (!fUseClipboardButton.getSelection()) |
327 |
return; |
328 |
|
329 |
clearErrorMessage(); |
287 |
fShowError= true; |
330 |
fShowError= true; |
|
|
331 |
updateWidgetEnablements(); |
332 |
} |
333 |
}); |
334 |
|
335 |
fUsePatchFileButton.addSelectionListener(new SelectionAdapter() { |
336 |
public void widgetSelected(SelectionEvent e) { |
337 |
if (!fUsePatchFileButton.getSelection()) |
338 |
return; |
339 |
//If there is anything typed in at all |
340 |
clearErrorMessage(); |
341 |
fShowError = (fPatchFileNameField.getText() != ""); //$NON-NLS-1$ |
288 |
int state= getInputMethod(); |
342 |
int state= getInputMethod(); |
289 |
setEnablePatchFile(state==FILE); |
343 |
setEnablePatchFile(state==FILE); |
290 |
setEnableWorkspacePatch(state==WORKSPACE); |
344 |
setEnableWorkspacePatch(state==WORKSPACE); |
Lines 299-317
Link Here
|
299 |
}); |
353 |
}); |
300 |
fPatchFileNameField.addModifyListener(new ModifyListener() { |
354 |
fPatchFileNameField.addModifyListener(new ModifyListener() { |
301 |
public void modifyText(ModifyEvent e) { |
355 |
public void modifyText(ModifyEvent e) { |
|
|
356 |
clearErrorMessage(); |
302 |
fShowError= true; |
357 |
fShowError= true; |
303 |
updateWidgetEnablements(); |
358 |
updateWidgetEnablements(); |
304 |
} |
359 |
} |
305 |
}); |
360 |
}); |
306 |
fPatchFileBrowseButton.addSelectionListener(new SelectionAdapter() { |
361 |
fPatchFileBrowseButton.addSelectionListener(new SelectionAdapter() { |
307 |
public void widgetSelected(SelectionEvent e) { |
362 |
public void widgetSelected(SelectionEvent e) { |
|
|
363 |
clearErrorMessage(); |
364 |
fShowError= true; |
308 |
handlePatchFileBrowseButtonPressed(); |
365 |
handlePatchFileBrowseButtonPressed(); |
309 |
updateWidgetEnablements(); |
366 |
updateWidgetEnablements(); |
310 |
} |
367 |
} |
311 |
}); |
368 |
}); |
312 |
fUseWorkspaceButton.addSelectionListener(new SelectionAdapter() { |
369 |
fUseWorkspaceButton.addSelectionListener(new SelectionAdapter() { |
313 |
public void widgetSelected(SelectionEvent e) { |
370 |
public void widgetSelected(SelectionEvent e) { |
314 |
fShowError= true; |
371 |
if (!fUseWorkspaceButton.getSelection()) |
|
|
372 |
return; |
373 |
clearErrorMessage(); |
374 |
//If there is anything typed in at all |
375 |
fShowError = (!fTreeViewer.getSelection().isEmpty()); |
315 |
int state= getInputMethod(); |
376 |
int state= getInputMethod(); |
316 |
setEnablePatchFile(state==FILE); |
377 |
setEnablePatchFile(state==FILE); |
317 |
setEnableWorkspacePatch(state==WORKSPACE); |
378 |
setEnableWorkspacePatch(state==WORKSPACE); |
Lines 321-326
Link Here
|
321 |
|
382 |
|
322 |
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
383 |
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
323 |
public void selectionChanged(SelectionChangedEvent event) { |
384 |
public void selectionChanged(SelectionChangedEvent event) { |
|
|
385 |
clearErrorMessage(); |
324 |
updateWidgetEnablements(); |
386 |
updateWidgetEnablements(); |
325 |
} |
387 |
} |
326 |
}); |
388 |
}); |
Lines 328-336
Link Here
|
328 |
|
390 |
|
329 |
private void addWorkspaceControls(Composite composite) { |
391 |
private void addWorkspaceControls(Composite composite) { |
330 |
|
392 |
|
331 |
new Label(composite, SWT.LEFT).setText(PatchMessages.InputPatchPage_WorkspaceSelectPatch_text); |
393 |
|
332 |
|
394 |
Composite newComp = new Composite(composite, SWT.NONE); |
333 |
fTreeViewer= new TreeViewer(composite, SWT.BORDER); |
395 |
GridLayout layout= new GridLayout(1, false); |
|
|
396 |
layout.marginWidth = 15; |
397 |
layout.marginHeight = 0; |
398 |
layout.marginLeft = 5; |
399 |
newComp.setLayout(layout); |
400 |
newComp.setLayoutData(new GridData(GridData.FILL_BOTH)); |
401 |
|
402 |
new Label(newComp, SWT.LEFT).setText(PatchMessages.InputPatchPage_WorkspaceSelectPatch_text); |
403 |
|
404 |
fTreeViewer= new TreeViewer(newComp, SWT.BORDER); |
334 |
final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true); |
405 |
final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true); |
335 |
gd.widthHint= 0; |
406 |
gd.widthHint= 0; |
336 |
gd.heightHint= 0; |
407 |
gd.heightHint= 0; |
Lines 338-347
Link Here
|
338 |
|
409 |
|
339 |
fTreeViewer.setLabelProvider(new WorkbenchLabelProvider()); |
410 |
fTreeViewer.setLabelProvider(new WorkbenchLabelProvider()); |
340 |
fTreeViewer.setContentProvider(new WorkbenchContentProvider()); |
411 |
fTreeViewer.setContentProvider(new WorkbenchContentProvider()); |
341 |
fTreeViewer.setSorter(new WorkbenchViewerSorter()); |
412 |
fTreeViewer.setSorter(new ResourceSorter(ResourceSorter.NAME)); |
342 |
fTreeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); |
413 |
fTreeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); |
343 |
} |
414 |
} |
344 |
|
415 |
|
|
|
416 |
|
345 |
/** |
417 |
/** |
346 |
* Updates the enable state of this page's controls. |
418 |
* Updates the enable state of this page's controls. |
347 |
*/ |
419 |
*/ |
Lines 495-501
Link Here
|
495 |
*/ |
567 |
*/ |
496 |
private void restoreWidgetValues() { |
568 |
private void restoreWidgetValues() { |
497 |
|
569 |
|
498 |
int inputMethod= CLIPBOARD; |
570 |
int inputMethod= FILE; |
499 |
|
571 |
|
500 |
IDialogSettings settings= getDialogSettings(); |
572 |
IDialogSettings settings= getDialogSettings(); |
501 |
if (settings != null) { |
573 |
if (settings != null) { |
Lines 517-522
Link Here
|
517 |
String patchFilePath= settings.get(STORE_PATCH_FILES_ID); |
589 |
String patchFilePath= settings.get(STORE_PATCH_FILES_ID); |
518 |
if (patchFilePath != null) |
590 |
if (patchFilePath != null) |
519 |
setSourceName(patchFilePath); |
591 |
setSourceName(patchFilePath); |
|
|
592 |
|
593 |
//If the previous apply patch was used with a clipboard, we need to check |
594 |
//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 |
596 |
//will be selected automatically |
597 |
if (inputMethod == CLIPBOARD){ |
598 |
inputMethod=FILE; |
599 |
fPatchFileNameField.deselectAll(); |
600 |
} |
601 |
|
602 |
//set the workspace patch selection |
603 |
String workspaceSetting = settings.get(STORE_WORKSPACE_PATH_ID); |
604 |
if (workspaceSetting != null && !workspaceSetting.equals("")){ //$NON-NLS-1$ |
605 |
//See if this resource still exists in the workspace |
606 |
IPath path = new Path(workspaceSetting); |
607 |
IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path); |
608 |
if (fTreeViewer != null && targetFile.exists()){ |
609 |
fTreeViewer.expandToLevel(targetFile, 0); |
610 |
fTreeViewer.setSelection(new StructuredSelection(targetFile)); |
611 |
} |
612 |
} else { |
613 |
//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 |
615 |
//the tree viewer |
616 |
if (inputMethod == WORKSPACE) |
617 |
inputMethod=FILE; |
618 |
} |
520 |
} |
619 |
} |
521 |
|
620 |
|
522 |
// set radio buttons state |
621 |
// set radio buttons state |
Lines 541-564
Link Here
|
541 |
|
640 |
|
542 |
sourceNames= addToHistory(sourceNames, getPatchFilePath()); |
641 |
sourceNames= addToHistory(sourceNames, getPatchFilePath()); |
543 |
settings.put(STORE_PATCH_FILES_ID, sourceNames); |
642 |
settings.put(STORE_PATCH_FILES_ID, sourceNames); |
|
|
643 |
|
644 |
//save the workspace selection |
645 |
settings.put(STORE_WORKSPACE_PATH_ID, getWorkspacePath()); |
646 |
|
544 |
} |
647 |
} |
545 |
} |
648 |
} |
546 |
|
649 |
|
|
|
650 |
private String getWorkspacePath() { |
651 |
if (fTreeViewer != null){ |
652 |
IResource[] resources= Utilities.getResources(fTreeViewer.getSelection()); |
653 |
if (resources.length > 0){ |
654 |
IResource patchFile= resources[0]; |
655 |
return patchFile.getFullPath().toString(); |
656 |
} |
657 |
|
658 |
} |
659 |
return ""; //$NON-NLS-1$ |
660 |
} |
661 |
|
547 |
// static helpers |
662 |
// static helpers |
|
|
663 |
|
664 |
/** |
665 |
* Checks to see if the file that has been selected for Apply Patch |
666 |
* is actually a patch |
667 |
* @return true if the file selected to run Apply Patch on in the workspace is a patch file |
668 |
* or if the clipboard contains a patch |
669 |
*/ |
670 |
private boolean adjustToCurrentTarget() { |
671 |
//Readjust selection if there is a patch selected in the workspace or on the clipboard |
672 |
//Check workspace first |
673 |
IResource patchTarget = fPatchWizard.getTarget(); |
674 |
if (patchTarget instanceof IFile) { |
675 |
Reader reader = null; |
676 |
try { |
677 |
try { |
678 |
reader = new FileReader(patchTarget.getRawLocation().toFile()); |
679 |
} catch (FileNotFoundException ex) {/*silently ignored*/ |
680 |
} catch (NullPointerException nex) {/*silently ignored*/ |
681 |
} |
548 |
|
682 |
|
|
|
683 |
if (isPatchFile(reader)) { |
684 |
//Set choice to workspace |
685 |
setInputButtonState(WORKSPACE); |
686 |
if (fTreeViewer != null && patchTarget.exists()) { |
687 |
fTreeViewer.expandToLevel(patchTarget, 0); |
688 |
fTreeViewer.setSelection(new StructuredSelection(patchTarget)); |
689 |
} |
690 |
return true; |
691 |
} |
692 |
} finally { |
693 |
if (reader != null) { |
694 |
try { |
695 |
reader.close(); |
696 |
} catch (IOException x) {/*silently ignored*/ |
697 |
} |
698 |
} |
699 |
} |
700 |
} else { |
701 |
//check out clipboard contents |
702 |
Reader reader = null; |
703 |
Control c = getControl(); |
704 |
if (c != null) { |
705 |
Clipboard clipboard = new Clipboard(c.getDisplay()); |
706 |
Object o = clipboard.getContents(TextTransfer.getInstance()); |
707 |
clipboard.dispose(); |
708 |
try { |
709 |
if (o instanceof String) { |
710 |
reader = new StringReader((String) o); |
711 |
if (isPatchFile(reader)) { |
712 |
setInputButtonState(CLIPBOARD); |
713 |
return true; |
714 |
} |
715 |
} |
716 |
} finally { |
717 |
if (reader != null) { |
718 |
try { |
719 |
reader.close(); |
720 |
} catch (IOException x) {/*silently ignored*/ |
721 |
} |
722 |
} |
723 |
} |
724 |
} |
725 |
} |
726 |
return false; |
727 |
} |
728 |
|
729 |
|
730 |
|
731 |
private boolean isPatchFile(Reader reader){ |
732 |
WorkspacePatcher patcher= ((PatchWizard) getWizard()).getPatcher(); |
733 |
|
734 |
try { |
735 |
patcher.parse(new BufferedReader(reader)); |
736 |
} catch (IOException ex) {return false;} |
737 |
|
738 |
Diff[] diffs= patcher.getDiffs(); |
739 |
if (diffs == null || diffs.length == 0) { |
740 |
return false; |
741 |
} |
742 |
|
743 |
return true; |
744 |
} |
745 |
|
746 |
/* |
747 |
* Clears the dialog message box |
748 |
*/ |
749 |
private void clearErrorMessage(){ |
750 |
setErrorMessage(null); |
751 |
} |
752 |
|
549 |
private void setInputButtonState(int state) { |
753 |
private void setInputButtonState(int state) { |
550 |
|
754 |
|
551 |
switch (state) { |
755 |
switch (state) { |
552 |
case CLIPBOARD : |
756 |
case CLIPBOARD : |
553 |
fUseClipboardButton.setSelection(true); |
757 |
fUseClipboardButton.setSelection(true); |
|
|
758 |
fUsePatchFileButton.setSelection(false); |
759 |
fUseWorkspaceButton.setSelection(false); |
554 |
break; |
760 |
break; |
555 |
|
761 |
|
556 |
case FILE : |
762 |
case FILE : |
|
|
763 |
fUseClipboardButton.setSelection(false); |
557 |
fUsePatchFileButton.setSelection(true); |
764 |
fUsePatchFileButton.setSelection(true); |
|
|
765 |
fUseWorkspaceButton.setSelection(false); |
558 |
break; |
766 |
break; |
559 |
|
767 |
|
560 |
case WORKSPACE : |
768 |
case WORKSPACE : |
561 |
fUsePatchFileButton.setSelection(true); |
769 |
fUseClipboardButton.setSelection(false); |
|
|
770 |
fUsePatchFileButton.setSelection(false); |
771 |
fUseWorkspaceButton.setSelection(true); |
562 |
break; |
772 |
break; |
563 |
} |
773 |
} |
564 |
|
774 |
|