View | Details | Raw Unified | Return to bug 181110 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/linuxtools/rpm/ui/editor/SpecfileCompletionProcessor.java (-7 / +7 lines)
Lines 218-226 Link Here
218
	private ICompletionProposal[] computeRpmPackageProposals(ITextViewer viewer,
218
	private ICompletionProposal[] computeRpmPackageProposals(ITextViewer viewer,
219
			IRegion region, Specfile specfile, String prefix) {
219
			IRegion region, Specfile specfile, String prefix) {
220
		List rpmPkgProposalsList = Activator.getDefault().getRpmPackageList().getProposals(prefix);
220
		List rpmPkgProposalsList = Activator.getDefault().getRpmPackageList().getProposals(prefix);
221
		SpecfileElement[] elements = specfile.getSectionsElements();
221
		String currentContentType = sEditor.getInputDocument().getDocumentPartitioner().getContentType(region.getOffset());
222
		// Show rpm packages proposals only in the preamble section 
222
		// Show only proposals on lines begining with Requires, BuildRequires, etc...
223
		if (elements.length == 0 || region.getOffset() < elements[0].getLineEndPosition()) {
223
		if (currentContentType.equals(SpecfilePartitionScanner.SPEC_PACKAGES)) {
224
			if (rpmPkgProposalsList == null)
224
			if (rpmPkgProposalsList == null)
225
				return new ICompletionProposal[0];
225
				return new ICompletionProposal[0];
226
			ArrayList proposals = new ArrayList();
226
			ArrayList proposals = new ArrayList();
Lines 253-265 Link Here
253
			if (elements.length == 0 || offset < elements[0].getLineEndPosition()) {
253
			if (elements.length == 0 || offset < elements[0].getLineEndPosition()) {
254
				return Activator.getDefault().getContextTypeRegistry()
254
				return Activator.getDefault().getContextTypeRegistry()
255
						.getContextType(PREAMBLE_SECTION_TEMPLATE);
255
						.getContextType(PREAMBLE_SECTION_TEMPLATE);
256
			} else if (offset < elements[1].getLineEndPosition()) {
256
			} else if (elements.length == 1 || offset < elements[1].getLineEndPosition()) {
257
				return Activator.getDefault().getContextTypeRegistry()
257
				return Activator.getDefault().getContextTypeRegistry()
258
						.getContextType(PRE_SECTION_TEMPLATE);
258
						.getContextType(PRE_SECTION_TEMPLATE );
259
			} else if (offset < elements[2].getLineEndPosition()) {
259
			} else if (elements.length == 2 || offset < elements[2].getLineEndPosition()) {
260
				return Activator.getDefault().getContextTypeRegistry()
260
				return Activator.getDefault().getContextTypeRegistry()
261
						.getContextType(BUILD_SECTION_TEMPLATE);
261
						.getContextType(BUILD_SECTION_TEMPLATE);
262
			} else if (offset < elements[3].getLineEndPosition()) {
262
			} else if (elements.length == 3 || offset < elements[3].getLineEndPosition()) {
263
				return Activator.getDefault().getContextTypeRegistry()
263
				return Activator.getDefault().getContextTypeRegistry()
264
						.getContextType(INSTALL_SECTION_TEMPLATE);
264
						.getContextType(INSTALL_SECTION_TEMPLATE);
265
			} else {
265
			} else {
266
			
266
			
(-)src/org/eclipse/linuxtools/rpm/ui/editor/SpecfileFoldingStructureProvider.java (-4 / +4 lines)
Lines 48-67 Link Here
48
		sDocument = document;
48
		sDocument = document;
49
	}
49
	}
50
50
51
	public void updateFoldingRegions(Specfile specfile) {
51
	public void updateFoldingRegions() {
52
		try {
52
		try {
53
			ProjectionAnnotationModel model = (ProjectionAnnotationModel) sEditor
53
			ProjectionAnnotationModel model = (ProjectionAnnotationModel) sEditor
54
					.getAdapter(ProjectionAnnotationModel.class);
54
					.getAdapter(ProjectionAnnotationModel.class);
55
			if (model != null)
55
			if (model != null)
56
				updateFoldingRegions(specfile, model);
56
				updateFoldingRegions(model);
57
		} catch (BadLocationException e) {
57
		} catch (BadLocationException e) {
58
			e.printStackTrace();
58
			e.printStackTrace();
59
		}
59
		}
60
	}
60
	}
61
61
62
	void updateFoldingRegions(Specfile specfile, ProjectionAnnotationModel model)
62
	void updateFoldingRegions(ProjectionAnnotationModel model)
63
			throws BadLocationException {
63
			throws BadLocationException {
64
		Set/* <Position> */structure = createFoldingStructure(specfile);
64
		Set/* <Position> */structure = createFoldingStructure(sEditor.getSpecfile());
65
		Annotation[] deletions = computeDifferences(model, structure);
65
		Annotation[] deletions = computeDifferences(model, structure);
66
		Map/* <Annotation,Position> */additions = computeAdditions(structure);
66
		Map/* <Annotation,Position> */additions = computeAdditions(structure);
67
		if ((deletions.length != 0 || additions.size() != 0)
67
		if ((deletions.length != 0 || additions.size() != 0)
(-)src/org/eclipse/linuxtools/rpm/ui/editor/SpecfileReconcilingStrategy.java (-25 / +22 lines)
Lines 8-21 Link Here
8
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
8
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
9
import org.eclipse.linuxtools.rpm.ui.editor.outline.SpecfileContentOutlinePage;
9
import org.eclipse.linuxtools.rpm.ui.editor.outline.SpecfileContentOutlinePage;
10
import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile;
10
import org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile;
11
import org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser;
11
import org.eclipse.swt.widgets.Shell;
12
import org.eclipse.ui.texteditor.IDocumentProvider;
12
import org.eclipse.ui.texteditor.IDocumentProvider;
13
13
14
public class SpecfileReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
14
public class SpecfileReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
15
15
16
	private IDocument sDocument;
16
	private IDocument sDocument;
17
	private IProgressMonitor sProgressMonitor;
17
	private IProgressMonitor sProgressMonitor;
18
	private SpecfileParser sParser;
19
	private SpecfileFoldingStructureProvider sFoldingStructureProvider;
18
	private SpecfileFoldingStructureProvider sFoldingStructureProvider;
20
	
19
	
21
	SpecfileContentOutlinePage outline;
20
	SpecfileContentOutlinePage outline;
Lines 28-50 Link Here
28
		lastRegionOffset = Integer.MAX_VALUE;
27
		lastRegionOffset = Integer.MAX_VALUE;
29
		this.editor = editor;
28
		this.editor = editor;
30
		documentProvider = editor.getDocumentProvider();
29
		documentProvider = editor.getDocumentProvider();
31
		sParser= new SpecfileParser();
32
		sFoldingStructureProvider= new SpecfileFoldingStructureProvider(editor);
30
		sFoldingStructureProvider= new SpecfileFoldingStructureProvider(editor);
33
	}
31
	}
34
32
35
	public void reconcile(IRegion partition) {
36
		try {
37
			Specfile specfile = editor.getSpecfile();
38
			SpecfileParser parser = editor.getParser();
39
			if (specfile != null) {
40
				editor.setSpecfile(parser.parse(documentProvider
41
						.getDocument(editor.getEditorInput())));
42
				outline.update();
43
			}
44
		} catch (Exception e) {
45
			e.printStackTrace();
46
		}
47
	}
48
	
33
	
49
	public void setDocument(IDocument document) {
34
	public void setDocument(IDocument document) {
50
		sDocument= document;
35
		sDocument= document;
Lines 65-86 Link Here
65
	}
50
	}
66
51
67
	private void reconcile() {
52
	private void reconcile() {
68
		Specfile specfile= parseSpecfile();
53
		Specfile specfile = editor.getSpecfile();
69
		if (specfile != null) {
54
		if (specfile != null) {
70
			updateEditor(specfile);
55
			editor.setSpecfile(editor.getParser().parse(documentProvider
71
			updateFolding(specfile);
56
					.getDocument(editor.getEditorInput())));
57
			outline.update();
58
			updateFolding();
59
			updateEditor();
72
		}
60
		}
73
	}
61
	}
74
62
	
75
	private Specfile parseSpecfile() {
63
	public void reconcile(IRegion partition) {
76
		return sParser.parse(sDocument);
64
		reconcile();
77
	}
65
	}
78
66
79
	private void updateEditor(final Specfile specfile) {
67
	private void updateEditor() {
68
		Shell shell= editor.getSite().getShell();
69
		if (!(shell == null || shell.isDisposed())) {
70
			shell.getDisplay().asyncExec(new Runnable() {
71
				public void run() {
72
					editor.setSpecfile(editor.getParser().parse(documentProvider
73
							.getDocument(editor.getEditorInput())));
74
				}
75
			});
76
		}
80
		return;
77
		return;
81
	}
78
	}
82
79
83
	private void updateFolding(Specfile specfile) {
80
	private void updateFolding() {
84
		sFoldingStructureProvider.updateFoldingRegions(specfile);
81
		sFoldingStructureProvider.updateFoldingRegions();
85
	}
82
	}
86
}
83
}

Return to bug 181110