View | Details | Raw Unified | Return to bug 190418
Collapse All | Expand All

(-)plugin.xml (+22 lines)
Lines 83-88 Link Here
83
            class="org.eclipse.compare.internal.CompareEditor"
83
            class="org.eclipse.compare.internal.CompareEditor"
84
            id="org.eclipse.compare.CompareEditor">
84
            id="org.eclipse.compare.CompareEditor">
85
      </editor>
85
      </editor>
86
      <editor
87
            class="org.eclipse.compare.internal.patch.PatchEditor"
88
            contributorClass="org.eclipse.compare.internal.patch.PatchEditorActionContributor"
89
            default="false"
90
            icon="icons/full/eview16/sample.gif"
91
            id="org.eclipse.compare.PatchEditor"
92
            name="Patch File Editor">
93
         <contentTypeBinding
94
               contentTypeId="org.eclipse.compare.patchContentType">
95
         </contentTypeBinding>
96
      </editor>
86
   </extension>
97
   </extension>
87
   
98
   
88
   <extension
99
   <extension
Lines 330-334 Link Here
330
            class="org.eclipse.compare.internal.ComparePreferenceInitializer">
341
            class="org.eclipse.compare.internal.ComparePreferenceInitializer">
331
      </initializer>
342
      </initializer>
332
   </extension>
343
   </extension>
344
   <extension
345
         point="org.eclipse.core.runtime.contentTypes">
346
      <content-type
347
            base-type="org.eclipse.core.runtime.text"
348
            describer="org.eclipse.compare.internal.patch.PatchContentDescriber"
349
            file-extensions="txt"
350
            id="org.eclipse.compare.patchContentType"
351
            name="Patch"
352
            priority="high">
353
      </content-type>
354
   </extension>
333
355
334
</plugin>
356
</plugin>
(-)compare/org/eclipse/compare/internal/patch/PatchContentDescriber.java (+51 lines)
Added Link Here
1
package org.eclipse.compare.internal.patch;
2
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
7
8
import org.eclipse.compare.internal.CompareUIPlugin;
9
import org.eclipse.core.runtime.CoreException;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.QualifiedName;
12
import org.eclipse.core.runtime.Status;
13
import org.eclipse.core.runtime.content.IContentDescriber;
14
import org.eclipse.core.runtime.content.IContentDescription;
15
16
public class PatchContentDescriber implements IContentDescriber {
17
18
	public int describe(final InputStream contents,
19
			IContentDescription description) throws IOException {
20
		try {
21
			BufferedReader reader = new BufferedReader(new InputStreamReader(
22
					contents));
23
			try {
24
				PatchReader patchReader = new PatchReader();
25
				patchReader.parse(reader);
26
				// TODO (tzarna): creates outline only for workspace patches
27
				if (patchReader.isWorkspacePatch())
28
					return VALID;
29
			} catch (IOException e) {
30
				throw new CoreException(new Status(IStatus.ERROR,
31
						CompareUIPlugin.PLUGIN_ID, 0, e.getMessage(), e));
32
			} finally {
33
				try {
34
					reader.close();
35
				} catch (IOException e) { // ignored
36
				}
37
			}
38
39
		} catch (CoreException e) {
40
			return INDETERMINATE;
41
		}
42
43
		return INDETERMINATE;
44
	}
45
46
	public QualifiedName[] getSupportedOptions() {
47
		// TODO Auto-generated method stub
48
		return null;
49
	}
50
51
}
(-)compare/org/eclipse/compare/internal/patch/PatchEditorActionContributor.java (+10 lines)
Added Link Here
1
package org.eclipse.compare.internal.patch;
2
3
import org.eclipse.ui.editors.text.TextEditorActionContributor;
4
5
public class PatchEditorActionContributor extends TextEditorActionContributor {
6
7
	public PatchEditorActionContributor() {
8
		// TODO Auto-generated constructor stub
9
	}
10
}
(-)compare/org/eclipse/compare/internal/patch/PatchContentOutlinePage.java (+103 lines)
Added Link Here
1
package org.eclipse.compare.internal.patch;
2
3
import java.io.IOException;
4
5
import org.eclipse.compare.CompareConfiguration;
6
import org.eclipse.compare.structuremergeviewer.DiffTreeViewer;
7
import org.eclipse.core.resources.IStorage;
8
import org.eclipse.core.runtime.CoreException;
9
import org.eclipse.core.runtime.ListenerList;
10
import org.eclipse.jface.action.IMenuManager;
11
import org.eclipse.jface.viewers.ISelection;
12
import org.eclipse.jface.viewers.ISelectionChangedListener;
13
import org.eclipse.jface.viewers.StructuredSelection;
14
import org.eclipse.swt.widgets.Composite;
15
import org.eclipse.swt.widgets.Control;
16
import org.eclipse.ui.IEditorInput;
17
import org.eclipse.ui.part.FileEditorInput;
18
import org.eclipse.ui.part.Page;
19
import org.eclipse.ui.texteditor.IDocumentProvider;
20
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
21
22
public class PatchContentOutlinePage extends Page implements
23
IContentOutlinePage/*, ISelectionChangedListener*/ {
24
	DiffTreeViewer treeViewer;
25
	IEditorInput fInput;
26
	private ListenerList selectionChangedListeners = new ListenerList();
27
	private WorkspacePatcher fPatcher;
28
29
	public PatchContentOutlinePage(IDocumentProvider documentProvider,
30
			PatchEditor patchEditor) {
31
		// TODO Auto-generated constructor stub
32
	}
33
34
	public void setInput(IEditorInput editorInput) {
35
		fInput = editorInput;
36
	}
37
38
	public void createControl(Composite parent) {
39
		getPatcher();
40
		CompareConfiguration patchConfiguration = new CompareConfiguration();
41
		PatchCompareEditorInput editorInput = new PatchCompareEditorInput(
42
				fPatcher, patchConfiguration) {
43
			protected void fillContextMenu(IMenuManager manager) {
44
				// TODO Auto-generated method stub
45
			}
46
		};
47
		treeViewer = (DiffTreeViewer) editorInput.createDiffViewer(parent);
48
		editorInput.buildTree();
49
	}
50
51
	private WorkspacePatcher getPatcher() {
52
		if (fPatcher == null) {
53
			if (fInput instanceof FileEditorInput) {
54
				IStorage patch = ((FileEditorInput) fInput).getStorage();
55
				WorkspacePatcher patcher = new WorkspacePatcher();
56
				if (patch != null) {
57
					try {
58
						patcher.parse(patch);
59
					} catch (IOException e) {
60
						// TODO Auto-generated catch block
61
						e.printStackTrace();
62
					} catch (CoreException e) {
63
						// TODO Auto-generated catch block
64
						e.printStackTrace();
65
					}
66
					fPatcher = patcher;
67
				}
68
			}
69
		} 
70
		return fPatcher;
71
	}
72
73
	public Control getControl() {
74
        if (treeViewer == null) {
75
			return null;
76
		}
77
        return treeViewer.getControl();
78
	}
79
80
	public void setFocus() {
81
		treeViewer.getControl().setFocus();
82
	}
83
84
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
85
		  selectionChangedListeners.add(listener);
86
	}
87
88
	public ISelection getSelection() {
89
        if (treeViewer == null) {
90
			return StructuredSelection.EMPTY;
91
		}
92
        return treeViewer.getSelection();
93
	}
94
95
	public void removeSelectionChangedListener(
96
			ISelectionChangedListener listener) {
97
		// TODO Auto-generated method stub
98
	}
99
100
	public void setSelection(ISelection selection) {
101
		// TODO Auto-generated method stub
102
	}
103
}
(-)compare/org/eclipse/compare/internal/patch/PatchEditor.java (+27 lines)
Added Link Here
1
package org.eclipse.compare.internal.patch;
2
3
import org.eclipse.ui.editors.text.TextEditor;
4
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
5
6
public class PatchEditor extends TextEditor {
7
8
	private PatchContentOutlinePage fOutlinePage;
9
10
	public PatchEditor() {
11
		// TODO Auto-generated constructor stub
12
	}
13
14
	public Object getAdapter(Class required) {
15
		if (IContentOutlinePage.class.equals(required)) {
16
			if (fOutlinePage == null) {
17
				fOutlinePage = new PatchContentOutlinePage(
18
						getDocumentProvider(), this);
19
				if (getEditorInput() != null)
20
					fOutlinePage.setInput(getEditorInput());
21
			}
22
			return fOutlinePage;
23
		}
24
		return super.getAdapter(required);
25
	}
26
27
}

Return to bug 190418