diff --git a/build/org.eclipse.cdt.make.ui/icons/obj16/command_obj.gif b/build/org.eclipse.cdt.make.ui/icons/obj16/command_obj.gif
new file mode 100644
index 00000000000..f13e465665b
Binary files /dev/null and b/build/org.eclipse.cdt.make.ui/icons/obj16/command_obj.gif differ
diff --git a/build/org.eclipse.cdt.make.ui/icons/obj16/relation_obj.gif b/build/org.eclipse.cdt.make.ui/icons/obj16/relation_obj.gif
new file mode 100644
index 00000000000..852dc81ba6a
Binary files /dev/null and b/build/org.eclipse.cdt.make.ui/icons/obj16/relation_obj.gif differ
diff --git a/build/org.eclipse.cdt.make.ui/icons/obj16/trule_obj.gif b/build/org.eclipse.cdt.make.ui/icons/obj16/trule_obj.gif
index f3a90dba990..64c522da372 100644
Binary files a/build/org.eclipse.cdt.make.ui/icons/obj16/trule_obj.gif and b/build/org.eclipse.cdt.make.ui/icons/obj16/trule_obj.gif differ
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIImages.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIImages.java
index 8cb52efedb3..516e81609ef 100644
--- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIImages.java
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIImages.java
@@ -54,10 +54,19 @@ public class MakeUIImages {
public static final String IMG_OBJS_MAKEFILE_MACRO = NAME_PREFIX + "macro_obj.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_MAKEFILE_MACRO = createManaged(OBJ, IMG_OBJS_MAKEFILE_MACRO);
+
public static final String IMG_OBJS_MAKEFILE_TARGET_RULE = NAME_PREFIX + "trule_obj.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_MAKEFILE_TARGET_RULE = createManaged(OBJ, IMG_OBJS_MAKEFILE_TARGET_RULE);
+
public static final String IMG_OBJS_MAKEFILE_INFERENCE_RULE = NAME_PREFIX + "irule_obj.gif"; //$NON-NLS-1$
public static final ImageDescriptor DESC_MAKEFILE_INFERENCE_RULE = createManaged(OBJ, IMG_OBJS_MAKEFILE_INFERENCE_RULE);
+
+ public static final String IMG_OBJS_MAKEFILE_RELATION = NAME_PREFIX + "relation_obj.gif"; //$NON-NLS-1$
+ public static final ImageDescriptor DESC_MAKEFILE_RELATION = createManaged(OBJ, IMG_OBJS_MAKEFILE_RELATION);
+
+ public static final String IMG_OBJS_MAKEFILE_COMMAND = NAME_PREFIX + "command_obj.gif"; //$NON-NLS-1$
+ public static final ImageDescriptor DESC_MAKEFILE_COMMAND = createManaged(OBJ, IMG_OBJS_MAKEFILE_COMMAND);
+
public static final String IMG_TOOLS_MAKEFILE_SEGMENT_EDIT= NAME_PREFIX + "segment_edit.gif";
private static ImageDescriptor createManaged(String prefix, String name) {
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java
index 776b3f4eb8d..97d36f54945 100644
--- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeUIPlugin.java
@@ -4,6 +4,10 @@ import java.lang.reflect.InvocationTargetException;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import org.eclipse.cdt.make.internal.ui.editor.IMakefileDocumentProvider;
+import org.eclipse.cdt.make.internal.ui.editor.MakefileDocumentProvider;
+import org.eclipse.cdt.make.internal.ui.editor.WorkingCopyManager;
+import org.eclipse.cdt.make.ui.IWorkingCopyManager;
import org.eclipse.cdt.make.ui.actions.UpdateMakeProjectAction;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
@@ -30,6 +34,9 @@ public class MakeUIPlugin extends AbstractUIPlugin implements IStartup {
//Resource bundle.
private ResourceBundle resourceBundle;
+ private IWorkingCopyManager fWorkingCopyManager;
+ private IMakefileDocumentProvider fMakefileDocumentProvider;
+
/**
* The constructor.
*/
@@ -215,4 +222,28 @@ public class MakeUIPlugin extends AbstractUIPlugin implements IStartup {
return windows[0].getShell();
}
}
+
+ public synchronized IMakefileDocumentProvider getMakefileDocumentProvider() {
+ if (fMakefileDocumentProvider == null) {
+ fMakefileDocumentProvider= new MakefileDocumentProvider();
+ }
+ return fMakefileDocumentProvider;
+ }
+
+ public synchronized IWorkingCopyManager getWorkingCopyManager() {
+ if (fWorkingCopyManager == null) {
+ IMakefileDocumentProvider provider= getMakefileDocumentProvider();
+ fWorkingCopyManager= new WorkingCopyManager(provider);
+ }
+ return fWorkingCopyManager;
+ }
+
+ public void shutdown() throws CoreException {
+ super.shutdown();
+ if (fWorkingCopyManager != null) {
+ fWorkingCopyManager.shutdown();
+ fWorkingCopyManager= null;
+ }
+ }
+
}
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/IMakefileDocumentProvider.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/IMakefileDocumentProvider.java
new file mode 100644
index 00000000000..baeea749cab
--- /dev/null
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/IMakefileDocumentProvider.java
@@ -0,0 +1,25 @@
+/*
+ */
+package org.eclipse.cdt.make.internal.ui.editor;
+
+import org.eclipse.cdt.make.core.makefile.IMakefile;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+/**
+ */
+public interface IMakefileDocumentProvider extends IDocumentProvider {
+
+ /**
+ * Shuts down this provider.
+ */
+ void shutdown();
+
+ /**
+ * Returns the working copy for the given element.
+ *
+ * @param element the element
+ * @return the working copy for the given element
+ */
+ IMakefile getWorkingCopy(Object element);
+
+}
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java
index c2448a6f8fd..9cb0020d880 100644
--- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java
@@ -11,17 +11,22 @@
package org.eclipse.cdt.make.internal.ui.editor;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
+import org.eclipse.cdt.make.core.makefile.ICommand;
+import org.eclipse.cdt.make.core.makefile.IComment;
+import org.eclipse.cdt.make.core.makefile.IEmptyLine;
import org.eclipse.cdt.make.core.makefile.IInferenceRule;
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
import org.eclipse.cdt.make.core.makefile.IMakefile;
+import org.eclipse.cdt.make.core.makefile.IParent;
import org.eclipse.cdt.make.core.makefile.IRule;
-import org.eclipse.cdt.make.core.makefile.IStatement;
+import org.eclipse.cdt.make.core.makefile.IDirective;
import org.eclipse.cdt.make.core.makefile.ITargetRule;
import org.eclipse.cdt.make.internal.core.makefile.NullMakefile;
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
+import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
+import org.eclipse.cdt.make.ui.IWorkingCopyManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -35,7 +40,7 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -59,6 +64,8 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
public Object[] getChildren(Object element) {
if (element == fInput) {
return getElements(element);
+ } else if (element instanceof IParent) {
+ return getElements(element);
}
return new Object[0];
}
@@ -67,7 +74,7 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
public Object getParent(Object element) {
- if (element instanceof IStatement)
+ if (element instanceof IDirective)
return fInput;
return fInput;
}
@@ -76,22 +83,41 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
public boolean hasChildren(Object element) {
- return element == fInput;
+ if (element == fInput) {
+ return true;
+ } else if (element instanceof IParent) {
+ return true;
+ }
+ return false;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
- List list = new ArrayList();
- if (showMacroDefinition) {
- list.addAll(Arrays.asList(makefile.getMacroDefinitions()));
+ IDirective[] statements;
+ if (inputElement == fInput) {
+ statements = makefile.getStatements();
+ } else if (inputElement instanceof IParent) {
+ statements = ((IParent)inputElement).getStatements();
+ } else {
+ statements = new IDirective[0];
}
- if (showInferenceRule) {
- list.addAll(Arrays.asList(makefile.getInferenceRules()));
- }
- if (showTargetRule) {
- list.addAll(Arrays.asList(makefile.getTargetRules()));
+ List list = new ArrayList(statements.length);
+ for (int i = 0; i < statements.length; i++) {
+ if (showMacroDefinition && statements[i] instanceof IMacroDefinition) {
+ list.add(statements[i]);
+ } else if (showInferenceRule && statements[i] instanceof IInferenceRule) {
+ list.add(statements[i]);
+ } else if (showTargetRule && statements[i] instanceof ITargetRule) {
+ list.add(statements[i]);
+ } else {
+ boolean irrelevant = (statements[i] instanceof IComment ||
+ statements[i] instanceof IEmptyLine);
+ if (!irrelevant) {
+ list.add(statements[i]);
+ }
+ }
}
return list.toArray();
}
@@ -111,8 +137,19 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
}
if (newInput != null) {
- IDocument document= fDocumentProvider.getDocument(newInput);
- makefile = fEditor.getMakefile(document);
+ IWorkingCopyManager manager= MakeUIPlugin.getDefault().getWorkingCopyManager();
+ makefile = manager.getWorkingCopy((IEditorInput)newInput);
+ if (makefile == null) {
+ makefile = nullMakefile;
+ }
+// IDocument document= fDocumentProvider.getDocument(newInput);
+// makefile = fEditor.getMakefile();
+// try {
+// String content = document.get();
+// Reader r = new StringReader(content);
+// makefile.parse(r);
+// } catch (IOException e) {
+// }
}
}
@@ -130,6 +167,10 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_INFERENCE_RULE);
} else if (element instanceof IMacroDefinition) {
return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO);
+ } else if (element instanceof IParent) {
+ return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_RELATION);
+ } else if (element instanceof ICommand) {
+ return MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_COMMAND);
}
return super.getImage(element);
}
@@ -138,23 +179,30 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object element) {
+ String name;
if (element instanceof IRule) {
- return ((IRule) element).getTarget().toString();
+ name = ((IRule) element).getTarget().toString().trim();
} else if (element instanceof IMacroDefinition) {
- return ((IMacroDefinition) element).getName();
+ name = ((IMacroDefinition) element).getName().trim();
+ } else {
+ name = super.getText(element);
}
- return super.getText(element);
+ if (name != null) {
+ name = name.trim();
+ if (name.length() > 20) {
+ name = name.substring(0, 20) + "..."; //$NON-NLS-1$
+ }
+ }
+ return name;
}
}
- protected IDocumentProvider fDocumentProvider;
protected MakefileEditor fEditor;
protected Object fInput;
- public MakefileContentOutlinePage(IDocumentProvider provider, MakefileEditor editor) {
+ public MakefileContentOutlinePage(MakefileEditor editor) {
super();
- fDocumentProvider = provider;
fEditor = editor;
}
@@ -202,8 +250,8 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
fEditor.resetHighlightRange();
} else if (selection instanceof IStructuredSelection){
Object element = ((IStructuredSelection) selection).getFirstElement();
- if (element instanceof IStatement) {
- IStatement statement = (IStatement)element;
+ if (element instanceof IDirective) {
+ IDirective statement = (IDirective)element;
int startLine = statement.getStartLine() - 1;
int endLine = statement.getEndLine() - 1;
try {
@@ -232,7 +280,7 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
if (control != null && !control.isDisposed()) {
control.setRedraw(false);
viewer.setInput(fInput);
- viewer.expandAll();
+ //viewer.expandAll();
control.setRedraw(true);
}
}
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java
index 5f700f59af3..a3abe9cdabb 100644
--- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java
@@ -10,19 +10,47 @@
***********************************************************************/
package org.eclipse.cdt.make.internal.ui.editor;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Iterator;
+
+import org.eclipse.cdt.make.core.MakeCorePlugin;
+import org.eclipse.cdt.make.core.makefile.IMakefile;
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefilePartitionScanner;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.DefaultPartitioner;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.FileDocumentProvider;
/**
*/
-public class MakefileDocumentProvider extends FileDocumentProvider {
+public class MakefileDocumentProvider extends FileDocumentProvider implements IMakefileDocumentProvider {
private static MakefilePartitionScanner scanner = null;
+ /**
+ * Bundle of all required informations to allow working copy management.
+ */
+ protected class MakefileInfo extends FileInfo {
+
+ IMakefile fCopy;
+
+ public MakefileInfo(IDocument document, IAnnotationModel model, FileSynchronizer fileSynchronizer, IMakefile copy) {
+ super(document, model, fileSynchronizer);
+ fCopy = copy;
+ }
+
+ public void setModificationStamp(long timeStamp) {
+ fModificationStamp = timeStamp;
+ }
+ }
+
/**
* Constructor for MakefileDocumentProvider.
*/
@@ -53,4 +81,96 @@ public class MakefileDocumentProvider extends FileDocumentProvider {
return scanner;
}
+ /*
+ * @see AbstractDocumentProvider#createElementInfo(Object)
+ */
+ protected ElementInfo createElementInfo(Object element) throws CoreException {
+ if (element instanceof IFileEditorInput) {
+
+ IFileEditorInput input = (IFileEditorInput) element;
+ IMakefile makefile = createMakefile(input.getFile());
+ if (makefile == null) {
+ return super.createElementInfo(element);
+ }
+ try {
+ refreshFile(input.getFile());
+ } catch (CoreException x) {
+ handleCoreException(x, "FileDocumentProvider.createElementInfo");
+ }
+
+ IDocument d = null;
+ IStatus s = null;
+
+ try {
+ d = createDocument(element);
+ } catch (CoreException x) {
+ s = x.getStatus();
+ d = createEmptyDocument();
+ }
+
+ IAnnotationModel m = createAnnotationModel(element);
+ FileSynchronizer f = new FileSynchronizer(input);
+ f.install();
+
+ FileInfo info = new MakefileInfo(d, m, f, makefile);
+ info.fModificationStamp = computeModificationStamp(input.getFile());
+ info.fStatus = s;
+ info.fEncoding = getPersistedEncoding(input);
+
+ return info;
+ }
+
+ return super.createElementInfo(element);
+ }
+
+ /**
+ * @param file
+ * @return
+ */
+ private IMakefile createMakefile(IFile file) {
+ return MakeCorePlugin.getDefault().createMakefile(file);
+ }
+
+ /*
+ * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object, IDocument, boolean)
+ */
+ protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
+
+ // Update the makefile directives tree;
+ ElementInfo elementInfo= getElementInfo(element);
+ if (elementInfo instanceof MakefileInfo) {
+ MakefileInfo info= (MakefileInfo) elementInfo;
+ String content = document.get();
+ StringReader reader = new StringReader(content);
+ try {
+ info.fCopy.parse(reader);
+ } catch (IOException e) {
+ }
+ }
+ super.doSaveDocument(monitor, element, document, overwrite);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.make.internal.ui.editor.IMakefileDocumentProvider#shutdown()
+ */
+ public void shutdown() {
+ Iterator e = getConnectedElements();
+ while (e.hasNext()) {
+ disconnect(e.next());
+ }
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
+ */
+ public IMakefile getWorkingCopy(Object element) {
+
+ ElementInfo elementInfo = getElementInfo(element);
+ if (elementInfo instanceof MakefileInfo) {
+ MakefileInfo info = (MakefileInfo) elementInfo;
+ return info.fCopy;
+ }
+ return null;
+ }
+
}
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java
index 8f6047cb071..6ae32470819 100644
--- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java
@@ -10,19 +10,13 @@
***********************************************************************/
package org.eclipse.cdt.make.internal.ui.editor;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
import java.util.ResourceBundle;
import org.eclipse.cdt.make.core.makefile.IMakefile;
-import org.eclipse.cdt.make.internal.core.makefile.NullMakefile;
-import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefile;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
@@ -40,31 +34,45 @@ public class MakefileEditor extends TextEditor {
private MakefileContentOutlinePage getOutlinePage() {
if (page == null) {
- page = new MakefileContentOutlinePage(getDocumentProvider(), this);
+ page = new MakefileContentOutlinePage(this);
page.setInput(getEditorInput());
}
return page;
}
- public IMakefile getMakefile() {
- IDocument document = getDocumentProvider().getDocument(getEditorInput());
- return getMakefile(document);
- }
-
- public IMakefile getMakefile(IDocument document) {
- if (document != null) {
- if (makefile == null || isDirty()) {
- try {
- String content = document.get();
- Reader r = new StringReader(content);
- makefile = new PosixMakefile(r);
- } catch (IOException e) {
- makefile = new NullMakefile();
- }
- }
- }
- return makefile;
- }
+// public IMakefile getMakefile() {
+// IDocument document = getDocumentProvider().getDocument(getEditorInput());
+// if (makefile == null) {
+// makefile = new GNUMakefile();
+// try {
+// String content = document.get();
+// Reader r = new StringReader(content);
+// makefile.parse(r);
+// } catch (IOException e) {
+// }
+// IEditorInput input = getEditorInput();
+// if (makefile instanceof GNUMakefile) {
+// GNUMakefile gnu = (GNUMakefile)makefile;
+// if (input instanceof IFileEditorInput) {
+// IFile file = ((IFileEditorInput)input).getFile();
+// String[] dirs = gnu.getIncludeDirectories();
+// String[] includes = new String[dirs.length + 1];
+// System.arraycopy(dirs, 0, includes, 0, dirs.length);
+// String cwd = file.getLocation().removeLastSegments(1).toOSString();
+// includes[dirs.length] = cwd;
+// gnu.setIncludeDirectories(includes);
+// }
+// }
+// } else if (isDirty()) {
+// try {
+// String content = document.get();
+// Reader r = new StringReader(content);
+// makefile.parse(r);
+// } catch (IOException e) {
+// }
+// }
+// return makefile;
+// }
public MakefileEditor() {
super();
@@ -80,7 +88,7 @@ public class MakefileEditor extends TextEditor {
setRangeIndicator(new DefaultRangeIndicator());
setEditorContextMenuId("#MakefileEditorContext"); //$NON-NLS-1$
setRulerContextMenuId("#MakefileRulerContext"); //$NON-NLS-1$
- setDocumentProvider(new MakefileDocumentProvider());
+ setDocumentProvider(MakeUIPlugin.getDefault().getMakefileDocumentProvider());
}
/* (non-Javadoc)
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/WorkingCopyManager.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/WorkingCopyManager.java
new file mode 100644
index 00000000000..a98f7fe995f
--- /dev/null
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/WorkingCopyManager.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.make.internal.ui.editor;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.make.core.makefile.IMakefile;
+import org.eclipse.cdt.make.ui.IWorkingCopyManager;
+import org.eclipse.cdt.make.ui.IWorkingCopyManagerExtension;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.Assert;
+import org.eclipse.ui.IEditorInput;
+
+
+/**
+ * This working copy manager works together with a given compilation unit document provider and
+ * additionally offers to "overwrite" the working copy provided by this document provider.
+ */
+public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyManagerExtension {
+
+ private IMakefileDocumentProvider fDocumentProvider;
+ private Map fMap;
+ private boolean fIsShuttingDown;
+
+ /**
+ * Creates a new working copy manager that co-operates with the given
+ * compilation unit document provider.
+ *
+ * @param provider the provider
+ */
+ public WorkingCopyManager(IMakefileDocumentProvider provider) {
+ Assert.isNotNull(provider);
+ fDocumentProvider= provider;
+ }
+
+ /*
+ * @see org.eclipse.jdt.ui.IWorkingCopyManager#connect(org.eclipse.ui.IEditorInput)
+ */
+ public void connect(IEditorInput input) throws CoreException {
+ fDocumentProvider.connect(input);
+ }
+
+ /*
+ * @see org.eclipse.jdt.ui.IWorkingCopyManager#disconnect(org.eclipse.ui.IEditorInput)
+ */
+ public void disconnect(IEditorInput input) {
+ fDocumentProvider.disconnect(input);
+ }
+
+ /*
+ * @see org.eclipse.jdt.ui.IWorkingCopyManager#shutdown()
+ */
+ public void shutdown() {
+ if (!fIsShuttingDown) {
+ fIsShuttingDown= true;
+ try {
+ if (fMap != null) {
+ fMap.clear();
+ fMap= null;
+ }
+ fDocumentProvider.shutdown();
+ } finally {
+ fIsShuttingDown= false;
+ }
+ }
+ }
+
+ /*
+ * @see org.eclipse.jdt.ui.IWorkingCopyManager#getWorkingCopy(org.eclipse.ui.IEditorInput)
+ */
+ public IMakefile getWorkingCopy(IEditorInput input) {
+ IMakefile unit= fMap == null ? null : (IMakefile) fMap.get(input);
+ return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#setWorkingCopy(org.eclipse.ui.IEditorInput, org.eclipse.jdt.core.ICompilationUnit)
+ */
+ public void setWorkingCopy(IEditorInput input, IMakefile workingCopy) {
+ if (fDocumentProvider.getDocument(input) != null) {
+ if (fMap == null)
+ fMap= new HashMap();
+ fMap.put(input, workingCopy);
+ }
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IWorkingCopyManagerExtension#removeWorkingCopy(org.eclipse.ui.IEditorInput)
+ */
+ public void removeWorkingCopy(IEditorInput input) {
+ fMap.remove(input);
+ if (fMap.isEmpty())
+ fMap= null;
+ }
+}
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java
index 0b288725449..46260079f78 100644
--- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java
@@ -15,10 +15,11 @@ import java.util.ArrayList;
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
import org.eclipse.cdt.make.core.makefile.IMakefile;
import org.eclipse.cdt.make.core.makefile.IRule;
-import org.eclipse.cdt.make.core.makefile.IStatement;
+import org.eclipse.cdt.make.core.makefile.IDirective;
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
-import org.eclipse.cdt.make.internal.ui.editor.MakefileEditor;
+import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
+import org.eclipse.cdt.make.ui.IWorkingCopyManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
@@ -31,6 +32,7 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IEditorPart;
/**
* MakefileCompletionProcessor
@@ -70,10 +72,13 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
protected IContextInformationValidator fValidator = new Validator();
protected Image imageMacro = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO);
protected Image imageTarget = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_TARGET_RULE);
- protected MakefileEditor fEditor;
- public MakefileCompletionProcessor(MakefileEditor editor) {
+ protected IEditorPart fEditor;
+ protected IWorkingCopyManager fManager;
+
+ public MakefileCompletionProcessor(IEditorPart editor) {
fEditor = editor;
+ fManager = MakeUIPlugin.getDefault().getWorkingCopyManager();
}
/* (non-Javadoc)
@@ -81,8 +86,12 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
boolean macro = inMacro(viewer, documentOffset);
- IMakefile makefile = fEditor.getMakefile(viewer.getDocument());
- IStatement[] statements = null;
+ IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
+// IMakefile makefile = fEditor.getMakefile();
+// String content = viewer.getDocument().get();
+// Reader r = new StringReader(content);
+// makefile.parse(r);
+ IDirective[] statements = null;
if (macro) {
statements = makefile.getMacroDefinitions();
} else {
@@ -100,7 +109,7 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
if (statements[i] instanceof IMacroDefinition) {
name = ((IMacroDefinition) statements[i]).getName();
image = imageMacro;
- infoString = ((IMacroDefinition)statements[i]).getValue();
+ infoString = ((IMacroDefinition)statements[i]).getValue().toString();
} else if (statements[i] instanceof IRule) {
name = ((IRule) statements[i]).getTarget().toString();
image = imageTarget;
@@ -131,15 +140,17 @@ public class MakefileCompletionProcessor implements IContentAssistProcessor {
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
boolean macro = inMacro(viewer, documentOffset);
- IMakefile makefile = fEditor.getMakefile(viewer.getDocument());
+ IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
+ //IMakefile makefile = fEditor.getMakefile(viewer.getDocument());
+ //IMakefile makefile = fEditor.getMakefile();
ArrayList contextList = new ArrayList();
if (macro) {
- IStatement[] statements = makefile.getMacroDefinitions();
+ IDirective[] statements = makefile.getMacroDefinitions();
for (int i = 0; i < statements.length; i++) {
if (statements[i] instanceof IMacroDefinition) {
String name = ((IMacroDefinition) statements[i]).getName();
if (name != null && name.equals(wordPart.getString())) {
- String value = ((IMacroDefinition) statements[i]).getValue();
+ String value = ((IMacroDefinition) statements[i]).getValue().toString();
if (value != null && value.length() > 0) {
contextList.add(value);
}
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/IWorkingCopyManager.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/IWorkingCopyManager.java
new file mode 100644
index 00000000000..54e4b739ace
--- /dev/null
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/IWorkingCopyManager.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.make.ui;
+
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.ui.IEditorInput;
+
+import org.eclipse.cdt.make.core.makefile.IMakefile;
+
+/**
+ * Interface for accessing working copies of IMakefile
+ * objects. The original unit is only given indirectly by means
+ * of an IEditorInput
. The life cycle is as follows:
+ *
connect
creates and remembers a working copy of the
+ * unit which is encoded in the given editor inputgetWorkingCopy
returns the working copy remembered on
+ * connect
disconnect
destroys the working copy remembered on
+ * connect
+ * This interface is not intended to be implemented by clients. + *
+ * + * + */ +public interface IWorkingCopyManager { + + /** + * Connects the given editor input to this manager. After calling + * this method, a working copy will be available for the compilation unit encoded + * in the given editor input (does nothing if there is no encoded compilation unit). + * + * @param input the editor input + * @exception CoreException if the working copy cannot be created for the + * unit + */ + void connect(IEditorInput input) throws CoreException; + + /** + * Disconnects the given editor input from this manager. After calling + * this method, a working copy for the compilation unit encoded + * in the given editor input will no longer be available. Does nothing if there + * is no encoded compilation unit, or if there is no remembered working copy for + * the compilation unit. + * + * @param input the editor input + */ + void disconnect(IEditorInput input); + + /** + * Returns the working copy remembered for the compilation unit encoded in the + * given editor input. + * + * @param input the editor input + * @return the working copy of the compilation unit, ornull
if the
+ * input does not encode an editor input, or if there is no remembered working
+ * copy for this compilation unit
+ */
+ IMakefile getWorkingCopy(IEditorInput input);
+
+ /**
+ * Shuts down this working copy manager. All working copies still remembered
+ * by this manager are destroyed.
+ */
+ void shutdown();
+}
diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/IWorkingCopyManagerExtension.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/IWorkingCopyManagerExtension.java
new file mode 100644
index 00000000000..e33fa7c3f78
--- /dev/null
+++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/IWorkingCopyManagerExtension.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.make.ui;
+
+import org.eclipse.ui.IEditorInput;
+
+import org.eclipse.cdt.make.core.makefile.IMakefile;
+
+/**
+ * Extension interface for IWorkingCopyManager
.
+ * @since 2.1
+ */
+public interface IWorkingCopyManagerExtension {
+
+ /**
+ * Sets the given working copy for the given editor input. If the given editor input
+ * is not connected to this working copy manager, this call has no effect. + * This working copy manager does not assume the ownership of this working copy, i.e., + * the given working copy is not automatically be freed when this manager is shut down. + * + * @param input the editor input + * @param workingCopy the working copy + */ + void setWorkingCopy(IEditorInput input, IMakefile workingCopy); + + /** + * Removes the working copy set for the given editor input. If there is no + * working copy set for this input or this input is not connected to this + * working copy manager, this call has no effect. + * + * @param input the editor input + */ + void removeWorkingCopy(IEditorInput input); +}