mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Add Preference Page to Makefile Editor to allow
the change of settings.
This commit is contained in:
parent
662668a4ba
commit
24ce467c84
32 changed files with 3343 additions and 549 deletions
|
@ -34,6 +34,7 @@ CommandTargetCreate.description=Create a new make build target for the selected
|
|||
|
||||
PreferenceMakeProject.name=New Make Projects
|
||||
PreferenceMakeTargets.name=Make Targets
|
||||
PreferenceMakeFileEditor.name=Makefile Editor
|
||||
|
||||
PropertyMakeProject.name= C/C++ Make Project
|
||||
|
||||
|
|
|
@ -283,6 +283,12 @@
|
|||
class="org.eclipse.cdt.make.internal.ui.preferences.MakeTargetsPreferencePage"
|
||||
id="org.eclipse.cdt.make.ui.preferences.MakeTargetsPreferencePage">
|
||||
</page>
|
||||
<page
|
||||
name="%PreferenceMakeFileEditor.name"
|
||||
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
|
||||
class="org.eclipse.cdt.make.internal.ui.preferences.MakefileEditorPreferencePage"
|
||||
id="org.eclipse.cdt.make.ui.preferences.MakeFileEditorPreferencePage">
|
||||
</page>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
|
|
|
@ -17,6 +17,7 @@ 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.internal.ui.text.ColorManager;
|
||||
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
@ -24,6 +25,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
|
@ -135,6 +138,13 @@ public class MakeUIPlugin extends AbstractUIPlugin {
|
|||
return getDefault().getBundle().getSymbolicName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preference color, identified by the given preference.
|
||||
*/
|
||||
public static Color getPreferenceColor(String key) {
|
||||
return ColorManager.getDefault().getColor(PreferenceConverter.getColor(getDefault().getPreferenceStore(), key));
|
||||
}
|
||||
|
||||
public static void log(IStatus status) {
|
||||
ResourcesPlugin.getPlugin().getLog().log(status);
|
||||
}
|
||||
|
@ -252,4 +262,5 @@ public class MakeUIPlugin extends AbstractUIPlugin {
|
|||
}
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
package org.eclipse.cdt.make.internal.ui;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.preferences.MakeTargetsPreferencePage;
|
||||
import org.eclipse.cdt.make.internal.ui.preferences.MakefileEditorPreferenceConstants;
|
||||
import org.eclipse.cdt.make.internal.ui.preferences.MakefileEditorPreferencePage;
|
||||
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
|
||||
|
||||
|
||||
|
@ -18,7 +20,9 @@ public class MakeUIPreferenceInitializer extends AbstractPreferenceInitializer {
|
|||
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
|
||||
*/
|
||||
public void initializeDefaultPreferences() {
|
||||
MakeTargetsPreferencePage.initDefaults(MakeUIPlugin.getDefault().getPreferenceStore());
|
||||
MakeTargetsPreferencePage.initDefaults(MakeUIPlugin.getDefault().getPreferenceStore());
|
||||
MakefileEditorPreferenceConstants.initializeDefaultValues(MakeUIPlugin.getDefault().getPreferenceStore());
|
||||
MakefileEditorPreferencePage.initDefaults(MakeUIPlugin.getDefault().getPreferenceStore());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
/**
|
||||
* IReconcilingParticipant
|
||||
* Interface of an object participating in reconciling.
|
||||
*/
|
||||
public interface IReconcilingParticipant {
|
||||
|
||||
/**
|
||||
* Called after reconciling has been finished.
|
||||
*/
|
||||
void reconciled();
|
||||
}
|
|
@ -92,21 +92,12 @@ public class MakefileDocumentProvider extends TextFileDocumentProvider implement
|
|||
MakefileFileInfo makefileInfo= (MakefileFileInfo) info;
|
||||
setUpSynchronization(makefileInfo);
|
||||
|
||||
// IProblemRequestor requestor= cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel : null;
|
||||
|
||||
//original.becomeWorkingCopy(requestor, getProgressMonitor());
|
||||
makefileInfo.fCopy = original;
|
||||
|
||||
if (makefileInfo.fModel instanceof MakefileAnnotationModel) {
|
||||
MakefileAnnotationModel model= (MakefileAnnotationModel) makefileInfo.fModel;
|
||||
model.setMakefile(makefileInfo.fCopy);
|
||||
}
|
||||
|
||||
// if (requestor instanceof IProblemRequestorExtension) {
|
||||
// IProblemRequestorExtension extension= (IProblemRequestorExtension) requestor;
|
||||
// extension.setIsActive(isHandlingTemporaryProblems());
|
||||
// }
|
||||
|
||||
}
|
||||
return makefileInfo;
|
||||
}
|
||||
|
||||
|
@ -117,7 +108,6 @@ public class MakefileDocumentProvider extends TextFileDocumentProvider implement
|
|||
if (info instanceof MakefileFileInfo) {
|
||||
MakefileFileInfo makefileInfo= (MakefileFileInfo) info;
|
||||
if (makefileInfo.fCopy != null) {
|
||||
//makefileInfo.fCopy.dispose();
|
||||
makefileInfo.fCopy = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,6 @@ public class MakefileDocumentSetupParticipant implements IDocumentSetupParticip
|
|||
|
||||
private IDocumentPartitioner createDocumentPartitioner() {
|
||||
return new DefaultPartitioner(
|
||||
new MakefilePartitionScanner(), MakefilePartitionScanner.TYPES);
|
||||
new MakefilePartitionScanner(), MakefilePartitionScanner.MAKE_PARTITIONS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,12 @@ import java.util.ResourceBundle;
|
|||
|
||||
import org.eclipse.cdt.make.core.makefile.IDirective;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager;
|
||||
import org.eclipse.cdt.make.internal.ui.preferences.MakefileEditorPreferenceConstants;
|
||||
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileWordDetector;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
@ -26,10 +27,19 @@ import org.eclipse.jface.text.IRegion;
|
|||
import org.eclipse.jface.text.ITextOperationTarget;
|
||||
import org.eclipse.jface.text.rules.IWordDetector;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.jface.text.source.IVerticalRuler;
|
||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
|
||||
import org.eclipse.jface.text.source.projection.ProjectionSupport;
|
||||
import org.eclipse.jface.text.source.projection.ProjectionViewer;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.ListenerList;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IPartService;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
|
@ -40,14 +50,42 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
|||
import org.eclipse.ui.texteditor.TextOperationAction;
|
||||
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||
|
||||
public class MakefileEditor extends TextEditor implements ISelectionChangedListener{
|
||||
public class MakefileEditor extends TextEditor implements ISelectionChangedListener, IReconcilingParticipant {
|
||||
|
||||
/**
|
||||
* The page that shows the outline.
|
||||
*/
|
||||
protected MakefileContentOutlinePage page;
|
||||
ProjectionSupport projectionSupport;
|
||||
ProjectionMakefileUpdater fProjectionMakefileUpdater;
|
||||
private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter;
|
||||
|
||||
/**
|
||||
* Reconciling listeners.
|
||||
* @since 3.0
|
||||
*/
|
||||
private ListenerList fReconcilingListeners= new ListenerList();
|
||||
|
||||
/**
|
||||
* Property changes update the scanner
|
||||
*/
|
||||
final IPropertyChangeListener fPropertyChangeListener= new IPropertyChangeListener() {
|
||||
/*
|
||||
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
handlePreferenceStoreChanged(event);
|
||||
}
|
||||
};
|
||||
|
||||
MakefileSourceConfiguration getMakefileSourceConfiguration() {
|
||||
SourceViewerConfiguration configuration = getSourceViewerConfiguration();
|
||||
if (configuration instanceof MakefileSourceConfiguration) {
|
||||
return (MakefileSourceConfiguration)configuration;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MakefileContentOutlinePage getOutlinePage() {
|
||||
if (page == null) {
|
||||
page = new MakefileContentOutlinePage(this);
|
||||
|
@ -65,8 +103,7 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
|
||||
*/
|
||||
protected void initializeEditor() {
|
||||
|
||||
setSourceViewerConfiguration(new MakefileSourceConfiguration(new MakefileColorManager(), this));
|
||||
setSourceViewerConfiguration(new MakefileSourceConfiguration(this));
|
||||
setRangeIndicator(new DefaultRangeIndicator());
|
||||
setEditorContextMenuId("#MakefileEditorContext"); //$NON-NLS-1$
|
||||
setRulerContextMenuId("#MakefileRulerContext"); //$NON-NLS-1$
|
||||
|
@ -74,11 +111,74 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
setPreferenceStore(MakeUIPlugin.getDefault().getPreferenceStore());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.IWorkbenchPart#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fProjectionMakefileUpdater != null) {
|
||||
fProjectionMakefileUpdater.uninstall();
|
||||
fProjectionMakefileUpdater= null;
|
||||
}
|
||||
if (fPropertyChangeListener != null) {
|
||||
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||
preferenceStore.removePropertyChangeListener(fPropertyChangeListener);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
boolean isFoldingEnabled() {
|
||||
return MakeUIPlugin.getDefault().getPreferenceStore().getBoolean(MakefileEditorPreferenceConstants.EDITOR_FOLDING_ENABLED);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
public void createPartControl(Composite parent) {
|
||||
super.createPartControl(parent);
|
||||
ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
|
||||
projectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors());
|
||||
projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
|
||||
projectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
|
||||
projectionSupport.install();
|
||||
|
||||
if (isFoldingEnabled()) {
|
||||
projectionViewer.doOperation(ProjectionViewer.TOGGLE);
|
||||
}
|
||||
|
||||
ProjectionAnnotationModel model= (ProjectionAnnotationModel) getAdapter(ProjectionAnnotationModel.class);
|
||||
|
||||
fProjectionMakefileUpdater= new ProjectionMakefileUpdater();
|
||||
if (fProjectionMakefileUpdater != null) {
|
||||
fProjectionMakefileUpdater.install(this, projectionViewer);
|
||||
fProjectionMakefileUpdater.initialize();
|
||||
}
|
||||
|
||||
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||
preferenceStore.addPropertyChangeListener(fPropertyChangeListener);
|
||||
|
||||
}
|
||||
|
||||
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
||||
ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
|
||||
|
||||
// ensure decoration support has been created and configured.
|
||||
getSourceViewerDecorationSupport(viewer);
|
||||
|
||||
return viewer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* Method declared on IAdaptable
|
||||
*/
|
||||
public Object getAdapter(Class key) {
|
||||
if (key.equals(IContentOutlinePage.class)) {
|
||||
if (ProjectionAnnotationModel.class.equals(key)) {
|
||||
if (projectionSupport != null) {
|
||||
Object result = projectionSupport.getAdapter(getSourceViewer(), key);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} else if (key.equals(IContentOutlinePage.class)) {
|
||||
return getOutlinePage();
|
||||
}
|
||||
return super.getAdapter(key);
|
||||
|
@ -220,4 +320,116 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
//addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "OpenDeclarationAction"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given listener.
|
||||
* Has no effect if an identical listener was not already registered.
|
||||
*
|
||||
* @param listener The reconcile listener to be added
|
||||
* @since 3.0
|
||||
*/
|
||||
final void addReconcilingParticipant(IReconcilingParticipant listener) {
|
||||
synchronized (fReconcilingListeners) {
|
||||
fReconcilingListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given listener.
|
||||
* Has no effect if an identical listener was not already registered.
|
||||
*
|
||||
* @param listener the reconcile listener to be removed
|
||||
* @since 3.0
|
||||
*/
|
||||
final void removeReconcilingParticipant(IReconcilingParticipant listener) {
|
||||
synchronized (fReconcilingListeners) {
|
||||
fReconcilingListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
public void reconciled() {
|
||||
|
||||
|
||||
// Notify listeners
|
||||
Object[] listeners = fReconcilingListeners.getListeners();
|
||||
for (int i = 0, length= listeners.length; i < length; ++i)
|
||||
((IReconcilingParticipant)listeners[i]).reconciled();
|
||||
|
||||
// // Update Java Outline page selection
|
||||
// if (!forced && !progressMonitor.isCanceled()) {
|
||||
// Shell shell= getSite().getShell();
|
||||
// if (shell != null && !shell.isDisposed()) {
|
||||
// shell.getDisplay().asyncExec(new Runnable() {
|
||||
// public void run() {
|
||||
// selectionChanged();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert()
|
||||
*/
|
||||
protected void performRevert() {
|
||||
ProjectionViewer projectionViewer= (ProjectionViewer) getSourceViewer();
|
||||
projectionViewer.setRedraw(false);
|
||||
try {
|
||||
|
||||
boolean projectionMode= projectionViewer.isProjectionMode();
|
||||
if (projectionMode) {
|
||||
projectionViewer.disableProjection();
|
||||
if (fProjectionMakefileUpdater != null)
|
||||
fProjectionMakefileUpdater.uninstall();
|
||||
}
|
||||
|
||||
super.performRevert();
|
||||
|
||||
if (projectionMode) {
|
||||
if (fProjectionMakefileUpdater != null)
|
||||
fProjectionMakefileUpdater.install(this, projectionViewer);
|
||||
projectionViewer.enableProjection();
|
||||
}
|
||||
|
||||
} finally {
|
||||
projectionViewer.setRedraw(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.texteditor.AbstractTextEditor#handlePreferenceStoreChanged(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
*/
|
||||
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
|
||||
ISourceViewer sourceViewer= getSourceViewer();
|
||||
if (sourceViewer == null)
|
||||
return;
|
||||
|
||||
String property = event.getProperty();
|
||||
|
||||
MakefileSourceConfiguration makeConf = getMakefileSourceConfiguration();
|
||||
if (makeConf != null) {
|
||||
if (makeConf.affectsBehavior(event)) {
|
||||
makeConf.adaptToPreferenceChange(event);
|
||||
sourceViewer.invalidateTextPresentation();
|
||||
}
|
||||
}
|
||||
|
||||
if (MakefileEditorPreferenceConstants.EDITOR_FOLDING_ENABLED.equals(property)) {
|
||||
if (sourceViewer instanceof ProjectionViewer) {
|
||||
ProjectionViewer projectionViewer= (ProjectionViewer) sourceViewer;
|
||||
if (fProjectionMakefileUpdater != null)
|
||||
fProjectionMakefileUpdater.uninstall();
|
||||
// either freshly enabled or provider changed
|
||||
fProjectionMakefileUpdater= new ProjectionMakefileUpdater();
|
||||
if (fProjectionMakefileUpdater != null) {
|
||||
fProjectionMakefileUpdater.install(this, projectionViewer);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
super.handlePreferenceStoreChanged(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.text.IMakefileColorManager;
|
||||
import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager;
|
||||
import org.eclipse.cdt.make.internal.ui.text.ColorManager;
|
||||
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileAnnotationHover;
|
||||
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileCodeScanner;
|
||||
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileCompletionProcessor;
|
||||
|
@ -34,12 +33,13 @@ import org.eclipse.jface.text.rules.Token;
|
|||
import org.eclipse.jface.text.source.IAnnotationHover;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
||||
|
||||
private IMakefileColorManager colorManager;
|
||||
private MakefileCodeScanner codeScanner;
|
||||
private ColorManager colorManager;
|
||||
MakefileCodeScanner codeScanner;
|
||||
private MakefileEditor fEditor;
|
||||
|
||||
/**
|
||||
|
@ -54,10 +54,10 @@ public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
|||
/**
|
||||
* Constructor for MakeConfiguration
|
||||
*/
|
||||
public MakefileSourceConfiguration(IMakefileColorManager colorManager, MakefileEditor editor) {
|
||||
public MakefileSourceConfiguration(MakefileEditor editor) {
|
||||
super();
|
||||
fEditor = editor;
|
||||
this.colorManager = colorManager;
|
||||
colorManager = ColorManager.getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,11 +66,11 @@ public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
|||
public String[] getConfiguredContentTypes(ISourceViewer v) {
|
||||
return new String[] {
|
||||
IDocument.DEFAULT_CONTENT_TYPE,
|
||||
MakefilePartitionScanner.MAKEFILE_COMMENT,
|
||||
MakefilePartitionScanner.MAKEFILE_IF_BLOCK,
|
||||
MakefilePartitionScanner.MAKEFILE_DEF_BLOCK,
|
||||
MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK,
|
||||
MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT,
|
||||
MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION,
|
||||
MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION,
|
||||
MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION,
|
||||
MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION,
|
||||
MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION,
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -81,11 +81,11 @@ public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
|||
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
|
||||
ContentAssistant assistant = new ContentAssistant();
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), IDocument.DEFAULT_CONTENT_TYPE);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_COMMENT);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_DEF_BLOCK);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_IF_BLOCK);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION);
|
||||
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION);
|
||||
|
||||
assistant.enableAutoActivation(true);
|
||||
assistant.setAutoActivationDelay(500);
|
||||
|
@ -93,20 +93,14 @@ public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
|||
assistant.setProposalPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW);
|
||||
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW);
|
||||
//Set to Carolina blue
|
||||
assistant.setContextInformationPopupBackground(getColorManager().getColor(new RGB(0, 191, 255)));
|
||||
assistant.setContextInformationPopupBackground(colorManager.getColor(new RGB(0, 191, 255)));
|
||||
|
||||
return assistant;
|
||||
}
|
||||
|
||||
protected IMakefileColorManager getColorManager() {
|
||||
if (null == colorManager)
|
||||
colorManager = new MakefileColorManager();
|
||||
return colorManager;
|
||||
}
|
||||
|
||||
protected MakefileCodeScanner getCodeScanner() {
|
||||
if (null == codeScanner)
|
||||
codeScanner = new MakefileCodeScanner(getColorManager());
|
||||
codeScanner = new MakefileCodeScanner();
|
||||
return codeScanner;
|
||||
|
||||
}
|
||||
|
@ -121,28 +115,28 @@ public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
|||
|
||||
dr = new DefaultDamagerRepairer(getCodeScanner());
|
||||
dr = new DefaultDamagerRepairer(getCodeScanner());
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_COMMENT);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_COMMENT);
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_COMMENT_PARTITION);
|
||||
|
||||
dr = new DefaultDamagerRepairer(getCodeScanner());
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT);
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_MACRO_ASSIGNEMENT_PARTITION);
|
||||
|
||||
dr = new DefaultDamagerRepairer(getCodeScanner());
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK);
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_INCLUDE_BLOCK_PARTITION);
|
||||
|
||||
dr = new DefaultDamagerRepairer(getCodeScanner());
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK);
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_IF_BLOCK_PARTITION);
|
||||
|
||||
dr = new DefaultDamagerRepairer(getCodeScanner());
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK);
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_DEF_BLOCK_PARTITION);
|
||||
|
||||
dr = new DefaultDamagerRepairer(getCodeScanner());
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_OTHER);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_OTHER);
|
||||
reconciler.setDamager(dr, MakefilePartitionScanner.MAKEFILE_OTHER_PARTITION);
|
||||
reconciler.setRepairer(dr, MakefilePartitionScanner.MAKEFILE_OTHER_PARTITION);
|
||||
return reconciler;
|
||||
}
|
||||
|
||||
|
@ -178,4 +172,22 @@ public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
|||
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
|
||||
return new MakefileAnnotationHover(fEditor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
MakefileCodeScanner scanner = getCodeScanner();
|
||||
return scanner.affectsBehavior(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event
|
||||
*/
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
MakefileCodeScanner scanner = getCodeScanner();
|
||||
scanner.adaptToPreferenceChange(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class MakefileStorageDocumentProvider extends StorageDocumentProvider {
|
|||
|
||||
private IDocumentPartitioner createDocumentPartitioner() {
|
||||
return new DefaultPartitioner(
|
||||
new MakefilePartitionScanner(), MakefilePartitionScanner.TYPES);
|
||||
new MakefilePartitionScanner(), MakefilePartitionScanner.MAKE_PARTITIONS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.jface.text.reconciler.DirtyRegion;
|
||||
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
|
||||
import org.eclipse.jface.text.reconciler.MonoReconciler;
|
||||
|
||||
/**
|
||||
* NotifyingReconciler
|
||||
*/
|
||||
public class NotifyingReconciler extends MonoReconciler {
|
||||
|
||||
private ArrayList fReconcilingParticipants= new ArrayList();
|
||||
|
||||
/**
|
||||
* Constructor for NotifyingReconciler.
|
||||
* @param strategy
|
||||
* @param isIncremental
|
||||
*/
|
||||
public NotifyingReconciler(IReconcilingStrategy strategy, boolean isIncremental) {
|
||||
super(strategy, isIncremental);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.reconciler.AbstractReconciler#process(org.eclipse.jface.text.reconciler.DirtyRegion)
|
||||
*/
|
||||
protected void process(DirtyRegion dirtyRegion) {
|
||||
super.process(dirtyRegion);
|
||||
notifyReconcilingParticipants();
|
||||
}
|
||||
|
||||
public void addReconcilingParticipant(IReconcilingParticipant participant) {
|
||||
fReconcilingParticipants.add(participant);
|
||||
}
|
||||
|
||||
public void removeReconcilingParticipant(IReconcilingParticipant participant) {
|
||||
fReconcilingParticipants.remove(participant);
|
||||
}
|
||||
|
||||
protected void notifyReconcilingParticipants() {
|
||||
Iterator i= new ArrayList(fReconcilingParticipants).iterator();
|
||||
while (i.hasNext()) {
|
||||
((IReconcilingParticipant) i.next()).reconciled();
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.reconciler.AbstractReconciler#initialProcess()
|
||||
*/
|
||||
protected void initialProcess() {
|
||||
super.initialProcess();
|
||||
notifyReconcilingParticipants();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,398 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.make.core.makefile.IDirective;
|
||||
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
|
||||
import org.eclipse.cdt.make.core.makefile.IParent;
|
||||
import org.eclipse.cdt.make.core.makefile.IRule;
|
||||
import org.eclipse.cdt.make.core.makefile.gnu.IConditional;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.preferences.MakefileEditorPreferenceConstants;
|
||||
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.jface.text.source.projection.IProjectionListener;
|
||||
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
|
||||
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
|
||||
import org.eclipse.jface.text.source.projection.ProjectionViewer;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
|
||||
/**
|
||||
* ProjectionMakefileUpdater
|
||||
*/
|
||||
public class ProjectionMakefileUpdater implements IProjectionListener {
|
||||
|
||||
private static class MakefileProjectionAnnotation extends ProjectionAnnotation {
|
||||
|
||||
private IDirective fDirective;
|
||||
private boolean fIsComment;
|
||||
|
||||
public MakefileProjectionAnnotation(IDirective element, boolean isCollapsed, boolean isComment) {
|
||||
super(isCollapsed);
|
||||
fDirective = element;
|
||||
fIsComment = isComment;
|
||||
}
|
||||
|
||||
public IDirective getElement() {
|
||||
return fDirective;
|
||||
}
|
||||
|
||||
public void setElement(IDirective element) {
|
||||
fDirective = element;
|
||||
}
|
||||
|
||||
public boolean isComment() {
|
||||
return fIsComment;
|
||||
}
|
||||
|
||||
public void setIsComment(boolean isComment) {
|
||||
fIsComment= isComment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void install(MakefileEditor editor, ProjectionViewer viewer) {
|
||||
fEditor= editor;
|
||||
fViewer= viewer;
|
||||
fViewer.addProjectionListener(this);
|
||||
}
|
||||
|
||||
public void uninstall() {
|
||||
if (isInstalled()) {
|
||||
projectionDisabled();
|
||||
fViewer.removeProjectionListener(this);
|
||||
fViewer= null;
|
||||
fEditor= null;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isInstalled() {
|
||||
return fEditor != null;
|
||||
}
|
||||
|
||||
private class ReconcilerParticipant implements IReconcilingParticipant {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.internal.ui.editor.IReconcilingParticipant#reconciled()
|
||||
*/
|
||||
public void reconciled() {
|
||||
processReconcile();
|
||||
}
|
||||
}
|
||||
|
||||
private IDocument fCachedDocument;
|
||||
private MakefileEditor fEditor;
|
||||
private IDirective fInput;
|
||||
private ProjectionViewer fViewer;
|
||||
private IReconcilingParticipant fParticipant;
|
||||
|
||||
private boolean fAllowCollapsing = false;
|
||||
private boolean fCollapseMacroDef = false;
|
||||
private boolean fCollapseRule = false;
|
||||
private boolean fCollapseConditional = false;
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.source.projection.IProjectionListener#projectionEnabled()
|
||||
*/
|
||||
public void projectionEnabled() {
|
||||
// http://home.ott.oti.com/teams/wswb/anon/out/vms/index.html
|
||||
// projectionEnabled messages are not always paired with projectionDisabled
|
||||
// i.e. multiple enabled messages may be sent out.
|
||||
// we have to make sure that we disable first when getting an enable
|
||||
// message.
|
||||
projectionDisabled();
|
||||
|
||||
initialize();
|
||||
fParticipant= new ReconcilerParticipant();
|
||||
fEditor.addReconcilingParticipant(fParticipant);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.source.projection.IProjectionListener#projectionDisabled()
|
||||
*/
|
||||
public void projectionDisabled() {
|
||||
fCachedDocument= null;
|
||||
if (fParticipant != null) {
|
||||
fEditor.addReconcilingParticipant(fParticipant);
|
||||
fParticipant= null;
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
|
||||
if (!isInstalled())
|
||||
return;
|
||||
|
||||
initializePreferences();
|
||||
|
||||
try {
|
||||
|
||||
IDocumentProvider provider= fEditor.getDocumentProvider();
|
||||
fCachedDocument= provider.getDocument(fEditor.getEditorInput());
|
||||
fAllowCollapsing= true;
|
||||
|
||||
IWorkingCopyManager manager= MakeUIPlugin.getDefault().getWorkingCopyManager();
|
||||
fInput= manager.getWorkingCopy(fEditor.getEditorInput());
|
||||
|
||||
if (fInput != null) {
|
||||
ProjectionAnnotationModel model= (ProjectionAnnotationModel) fEditor.getAdapter(ProjectionAnnotationModel.class);
|
||||
if (model != null) {
|
||||
Map additions= computeAdditions((IParent) fInput);
|
||||
model.removeAllAnnotations();
|
||||
model.replaceAnnotations(null, additions);
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
fCachedDocument= null;
|
||||
fAllowCollapsing= false;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePreferences() {
|
||||
IPreferenceStore store = MakeUIPlugin.getDefault().getPreferenceStore();
|
||||
fCollapseMacroDef = store.getBoolean(MakefileEditorPreferenceConstants.EDITOR_FOLDING_MACRODEF);
|
||||
fCollapseRule = store.getBoolean(MakefileEditorPreferenceConstants.EDITOR_FOLDING_RULE);
|
||||
fCollapseConditional = store.getBoolean(MakefileEditorPreferenceConstants.EDITOR_FOLDING_CONDITIONAL);
|
||||
}
|
||||
|
||||
private Map computeAdditions(IParent parent) {
|
||||
Map map= new HashMap();
|
||||
computeAdditions(parent.getDirectives(), map);
|
||||
return map;
|
||||
}
|
||||
|
||||
private void computeAdditions(IDirective[] elements, Map map) {
|
||||
for (int i= 0; i < elements.length; i++) {
|
||||
IDirective element= elements[i];
|
||||
|
||||
computeAdditions(element, map);
|
||||
|
||||
if (element instanceof IParent) {
|
||||
IParent parent= (IParent) element;
|
||||
computeAdditions(parent.getDirectives(), map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void computeAdditions(IDirective element, Map map) {
|
||||
|
||||
boolean createProjection= false;
|
||||
|
||||
boolean collapse= false;
|
||||
|
||||
if (element instanceof IConditional) {
|
||||
collapse= fAllowCollapsing && fCollapseConditional;
|
||||
createProjection= true;
|
||||
} else if (element instanceof IMacroDefinition) {
|
||||
collapse= fAllowCollapsing && fCollapseMacroDef;
|
||||
createProjection= true;
|
||||
} else if (element instanceof IRule) {
|
||||
collapse= fAllowCollapsing && fCollapseRule;
|
||||
createProjection= true;
|
||||
}
|
||||
|
||||
if (createProjection) {
|
||||
Position position= createProjectionPosition(element);
|
||||
if (position != null) {
|
||||
map.put(new MakefileProjectionAnnotation(element, fAllowCollapsing, true), position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Position createProjectionPosition(IDirective element) {
|
||||
|
||||
if (fCachedDocument == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
int startLine= element.getStartLine() - 1;
|
||||
int endLine= element.getEndLine() - 1;
|
||||
if (startLine != endLine) {
|
||||
int offset= fCachedDocument.getLineOffset(startLine);
|
||||
int endOffset= fCachedDocument.getLineOffset(endLine + 1);
|
||||
return new Position(offset, endOffset - offset);
|
||||
}
|
||||
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void processReconcile() {
|
||||
if (!isInstalled())
|
||||
return;
|
||||
|
||||
ProjectionAnnotationModel model= (ProjectionAnnotationModel) fEditor.getAdapter(ProjectionAnnotationModel.class);
|
||||
if (model == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
IDocumentProvider provider= fEditor.getDocumentProvider();
|
||||
fCachedDocument= provider.getDocument(fEditor.getEditorInput());
|
||||
fAllowCollapsing= false;
|
||||
|
||||
Map additions= new HashMap();
|
||||
List deletions= new ArrayList();
|
||||
List updates= new ArrayList();
|
||||
|
||||
Map updated= computeAdditions((IParent) fInput);
|
||||
Map previous= createAnnotationMap(model);
|
||||
|
||||
|
||||
Iterator e= updated.keySet().iterator();
|
||||
while (e.hasNext()) {
|
||||
MakefileProjectionAnnotation annotation= (MakefileProjectionAnnotation) e.next();
|
||||
IDirective element= annotation.getElement();
|
||||
Position position= (Position) updated.get(annotation);
|
||||
|
||||
List annotations= (List) previous.get(element);
|
||||
if (annotations == null) {
|
||||
additions.put(annotation, position);
|
||||
} else {
|
||||
Iterator x= annotations.iterator();
|
||||
while (x.hasNext()) {
|
||||
MakefileProjectionAnnotation a= (MakefileProjectionAnnotation) x.next();
|
||||
if (annotation.isComment() == a.isComment()) {
|
||||
Position p= model.getPosition(a);
|
||||
if (p != null && !position.equals(p)) {
|
||||
p.setOffset(position.getOffset());
|
||||
p.setLength(position.getLength());
|
||||
updates.add(a);
|
||||
}
|
||||
x.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (annotations.isEmpty())
|
||||
previous.remove(element);
|
||||
}
|
||||
}
|
||||
|
||||
e= previous.values().iterator();
|
||||
while (e.hasNext()) {
|
||||
List list= (List) e.next();
|
||||
int size= list.size();
|
||||
for (int i= 0; i < size; i++)
|
||||
deletions.add(list.get(i));
|
||||
}
|
||||
|
||||
match(model, deletions, additions, updates);
|
||||
|
||||
Annotation[] removals= new Annotation[deletions.size()];
|
||||
deletions.toArray(removals);
|
||||
Annotation[] changes= new Annotation[updates.size()];
|
||||
updates.toArray(changes);
|
||||
model.modifyAnnotations(removals, additions, changes);
|
||||
|
||||
} finally {
|
||||
fCachedDocument= null;
|
||||
fAllowCollapsing= true;
|
||||
}
|
||||
}
|
||||
|
||||
private void match(ProjectionAnnotationModel model, List deletions, Map additions, List changes) {
|
||||
if (deletions.isEmpty() || (additions.isEmpty() && changes.isEmpty()))
|
||||
return;
|
||||
|
||||
List newDeletions= new ArrayList();
|
||||
List newChanges= new ArrayList();
|
||||
|
||||
Iterator deletionIterator= deletions.iterator();
|
||||
outer: while (deletionIterator.hasNext()) {
|
||||
MakefileProjectionAnnotation deleted= (MakefileProjectionAnnotation) deletionIterator.next();
|
||||
Position deletedPosition= model.getPosition(deleted);
|
||||
if (deletedPosition == null)
|
||||
continue;
|
||||
|
||||
Iterator changesIterator= changes.iterator();
|
||||
while (changesIterator.hasNext()) {
|
||||
MakefileProjectionAnnotation changed= (MakefileProjectionAnnotation) changesIterator.next();
|
||||
if (deleted.isComment() == changed.isComment()) {
|
||||
Position changedPosition= model.getPosition(changed);
|
||||
if (changedPosition == null)
|
||||
continue;
|
||||
|
||||
if (deletedPosition.getOffset() == changedPosition.getOffset()) {
|
||||
|
||||
deletedPosition.setLength(changedPosition.getLength());
|
||||
deleted.setElement(changed.getElement());
|
||||
|
||||
deletionIterator.remove();
|
||||
newChanges.add(deleted);
|
||||
|
||||
changesIterator.remove();
|
||||
newDeletions.add(changed);
|
||||
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator additionsIterator= additions.keySet().iterator();
|
||||
while (additionsIterator.hasNext()) {
|
||||
MakefileProjectionAnnotation added= (MakefileProjectionAnnotation) additionsIterator.next();
|
||||
if (deleted.isComment() == added.isComment()) {
|
||||
Position addedPosition= (Position) additions.get(added);
|
||||
|
||||
if (deletedPosition.getOffset() == addedPosition.getOffset()) {
|
||||
|
||||
deletedPosition.setLength(addedPosition.getLength());
|
||||
deleted.setElement(added.getElement());
|
||||
|
||||
deletionIterator.remove();
|
||||
newChanges.add(deleted);
|
||||
|
||||
additionsIterator.remove();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deletions.addAll(newDeletions);
|
||||
changes.addAll(newChanges);
|
||||
}
|
||||
|
||||
private Map createAnnotationMap(IAnnotationModel model) {
|
||||
Map map= new HashMap();
|
||||
Iterator e= model.getAnnotationIterator();
|
||||
while (e.hasNext()) {
|
||||
Object annotation= e.next();
|
||||
if (annotation instanceof MakefileProjectionAnnotation) {
|
||||
MakefileProjectionAnnotation directive= (MakefileProjectionAnnotation) annotation;
|
||||
List list= (List) map.get(directive.getElement());
|
||||
if (list == null) {
|
||||
list= new ArrayList(2);
|
||||
map.put(directive.getElement(), list);
|
||||
}
|
||||
list.add(directive);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,318 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.jface.dialogs.DialogPage;
|
||||
import org.eclipse.jface.dialogs.IMessageProvider;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
|
||||
/**
|
||||
* AbstraceMakeEditorPreferencePage
|
||||
*/
|
||||
public abstract class AbstractMakefileEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
|
||||
OverlayPreferenceStore fOverlayStore;
|
||||
|
||||
Map fCheckBoxes= new HashMap();
|
||||
private SelectionListener fCheckBoxListener= new SelectionListener() {
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Button button= (Button) e.widget;
|
||||
fOverlayStore.setValue((String) fCheckBoxes.get(button), button.getSelection());
|
||||
}
|
||||
};
|
||||
|
||||
Map fTextFields= new HashMap();
|
||||
private ModifyListener fTextFieldListener= new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
Text text= (Text) e.widget;
|
||||
fOverlayStore.setValue((String) fTextFields.get(text), text.getText());
|
||||
}
|
||||
};
|
||||
|
||||
private Map fNumberFields= new HashMap();
|
||||
private ModifyListener fNumberFieldListener= new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
numberFieldChanged((Text) e.widget);
|
||||
}
|
||||
};
|
||||
|
||||
public AbstractMakefileEditorPreferencePage() {
|
||||
super();
|
||||
setPreferenceStore(MakeUIPlugin.getDefault().getPreferenceStore());
|
||||
fOverlayStore= createOverlayStore();
|
||||
}
|
||||
|
||||
protected abstract OverlayPreferenceStore createOverlayStore();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
||||
*/
|
||||
public void init(IWorkbench workbench) {
|
||||
}
|
||||
|
||||
protected void initializeFields() {
|
||||
Map checkBoxes= getCheckBoxes();
|
||||
Map textFields= getTextFields();
|
||||
Iterator e= checkBoxes.keySet().iterator();
|
||||
while (e.hasNext()) {
|
||||
Button b= (Button) e.next();
|
||||
String key= (String) checkBoxes.get(b);
|
||||
b.setSelection(getOverlayStore().getBoolean(key));
|
||||
}
|
||||
|
||||
e= textFields.keySet().iterator();
|
||||
while (e.hasNext()) {
|
||||
Text t= (Text) e.next();
|
||||
String key= (String) textFields.get(t);
|
||||
t.setText(getOverlayStore().getString(key));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||
*/
|
||||
public boolean performOk() {
|
||||
getOverlayStore().propagate();
|
||||
MakeUIPlugin.getDefault().savePluginPreferences();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected OverlayPreferenceStore getOverlayStore() {
|
||||
return fOverlayStore;
|
||||
}
|
||||
|
||||
protected OverlayPreferenceStore setOverlayStore() {
|
||||
return fOverlayStore;
|
||||
}
|
||||
|
||||
protected Map getCheckBoxes() {
|
||||
return fCheckBoxes;
|
||||
}
|
||||
|
||||
protected Map getTextFields() {
|
||||
return fTextFields;
|
||||
}
|
||||
|
||||
protected Map getNumberFields() {
|
||||
return fNumberFields;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.PreferencePage#performDefaults()
|
||||
*/
|
||||
protected void performDefaults() {
|
||||
getOverlayStore().loadDefaults();
|
||||
initializeFields();
|
||||
handleDefaults();
|
||||
super.performDefaults();
|
||||
}
|
||||
|
||||
protected abstract void handleDefaults();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.dialogs.IDialogPage#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
if (getOverlayStore() != null) {
|
||||
getOverlayStore().stop();
|
||||
fOverlayStore= null;
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
protected Button addCheckBox(Composite parent, String labelText, String key, int indentation) {
|
||||
Button checkBox= new Button(parent, SWT.CHECK);
|
||||
checkBox.setText(labelText);
|
||||
checkBox.setFont(parent.getFont());
|
||||
|
||||
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
gd.horizontalIndent= indentation;
|
||||
gd.horizontalSpan= 2;
|
||||
checkBox.setLayoutData(gd);
|
||||
checkBox.addSelectionListener(fCheckBoxListener);
|
||||
|
||||
getCheckBoxes().put(checkBox, key);
|
||||
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
protected Control addTextField(Composite composite, String labelText, String key, int textLimit, int indentation, String[] errorMessages) {
|
||||
Font font= composite.getFont();
|
||||
|
||||
Label label= new Label(composite, SWT.NONE);
|
||||
label.setText(labelText);
|
||||
label.setFont(font);
|
||||
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
gd.horizontalIndent= indentation;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
Text textControl= new Text(composite, SWT.BORDER | SWT.SINGLE);
|
||||
textControl.setFont(font);
|
||||
gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
gd.widthHint= convertWidthInCharsToPixels(textLimit + 1);
|
||||
textControl.setLayoutData(gd);
|
||||
textControl.setTextLimit(textLimit);
|
||||
getTextFields().put(textControl, key);
|
||||
if (errorMessages != null) {
|
||||
getNumberFields().put(textControl, errorMessages);
|
||||
textControl.addModifyListener(fNumberFieldListener);
|
||||
} else {
|
||||
textControl.addModifyListener(fTextFieldListener);
|
||||
}
|
||||
|
||||
return textControl;
|
||||
}
|
||||
|
||||
void numberFieldChanged(Text textControl) {
|
||||
String number= textControl.getText();
|
||||
IStatus status= validatePositiveNumber(number, (String[])getNumberFields().get(textControl));
|
||||
if (!status.matches(IStatus.ERROR)) {
|
||||
getOverlayStore().setValue((String) getTextFields().get(textControl), number);
|
||||
}
|
||||
updateStatus(status);
|
||||
}
|
||||
|
||||
private IStatus validatePositiveNumber(String number, String[] errorMessages) {
|
||||
StatusInfo status= new StatusInfo();
|
||||
if (number.length() == 0) {
|
||||
status.setError(errorMessages[0]);
|
||||
} else {
|
||||
try {
|
||||
int value= Integer.parseInt(number);
|
||||
if (value < 0)
|
||||
status.setError(MessageFormat.format(errorMessages[1], new String[]{number})); //$NON-NLS-1$
|
||||
} catch (NumberFormatException e) {
|
||||
status.setError(MessageFormat.format(errorMessages[1], new String[]{number})); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
private void updateStatus(IStatus status) {
|
||||
if (!status.matches(IStatus.ERROR)) {
|
||||
Set keys= getNumberFields().keySet();
|
||||
for (Iterator iter = keys.iterator(); iter.hasNext();) {
|
||||
Text text = (Text) iter.next();
|
||||
IStatus s= validatePositiveNumber(text.getText(), (String[])getNumberFields().get(text));
|
||||
status= s.getSeverity() > status.getSeverity() ? s : status;
|
||||
}
|
||||
}
|
||||
setValid(!status.matches(IStatus.ERROR));
|
||||
applyToStatusLine(this, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Applies the status to the status line of a dialog page.
|
||||
*/
|
||||
private void applyToStatusLine(DialogPage page, IStatus status) {
|
||||
String message= status.getMessage();
|
||||
switch (status.getSeverity()) {
|
||||
case IStatus.OK:
|
||||
page.setMessage(message, IMessageProvider.NONE);
|
||||
page.setErrorMessage(null);
|
||||
break;
|
||||
case IStatus.WARNING:
|
||||
page.setMessage(message, IMessageProvider.WARNING);
|
||||
page.setErrorMessage(null);
|
||||
break;
|
||||
case IStatus.INFO:
|
||||
page.setMessage(message, IMessageProvider.INFORMATION);
|
||||
page.setErrorMessage(null);
|
||||
break;
|
||||
default:
|
||||
if (message.length() == 0) {
|
||||
message= null;
|
||||
}
|
||||
page.setMessage(null);
|
||||
page.setErrorMessage(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of size 2:
|
||||
* - first element is of type <code>Label</code>
|
||||
* - second element is of type <code>Text</code>
|
||||
* Use <code>getLabelControl</code> and <code>getTextControl</code> to get the 2 controls.
|
||||
*/
|
||||
protected Control[] addLabelledTextField(Composite composite, String label, String key, int textLimit, int indentation, String[] errorMessages) {
|
||||
Label labelControl= new Label(composite, SWT.NONE);
|
||||
labelControl.setText(label);
|
||||
labelControl.setFont(composite.getFont());
|
||||
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
gd.horizontalIndent= indentation;
|
||||
labelControl.setLayoutData(gd);
|
||||
|
||||
Text textControl= new Text(composite, SWT.BORDER | SWT.SINGLE);
|
||||
gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
gd.widthHint= convertWidthInCharsToPixels(textLimit + 1);
|
||||
textControl.setLayoutData(gd);
|
||||
textControl.setTextLimit(textLimit);
|
||||
textControl.setFont(composite.getFont());
|
||||
fTextFields.put(textControl, key);
|
||||
if (errorMessages != null) {
|
||||
fNumberFields.put(textControl, errorMessages);
|
||||
textControl.addModifyListener(fNumberFieldListener);
|
||||
} else {
|
||||
textControl.addModifyListener(fTextFieldListener);
|
||||
}
|
||||
|
||||
return new Control[]{labelControl, textControl};
|
||||
}
|
||||
|
||||
protected String loadPreviewContentFromFile(String filename) {
|
||||
String line;
|
||||
String separator= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
StringBuffer buffer= new StringBuffer(512);
|
||||
BufferedReader reader= null;
|
||||
try {
|
||||
reader= new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(filename)));
|
||||
while ((line= reader.readLine()) != null) {
|
||||
buffer.append(line);
|
||||
buffer.append(separator);
|
||||
}
|
||||
} catch (IOException io) {
|
||||
MakeUIPlugin.log(io);
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try { reader.close(); } catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.ColorDialog;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/**
|
||||
* A "button" of a certain color determined by the color picker
|
||||
*/
|
||||
public class ColorEditor {
|
||||
|
||||
private Point fExtent;
|
||||
Image fImage;
|
||||
RGB fColorValue;
|
||||
Color fColor;
|
||||
Button fButton;
|
||||
|
||||
public ColorEditor(Composite parent) {
|
||||
|
||||
fButton= new Button(parent, SWT.PUSH);
|
||||
fExtent= computeImageSize(parent);
|
||||
fImage= new Image(parent.getDisplay(), fExtent.x, fExtent.y);
|
||||
|
||||
GC gc= new GC(fImage);
|
||||
gc.setBackground(fButton.getBackground());
|
||||
gc.fillRectangle(0, 0, fExtent.x, fExtent.y);
|
||||
gc.dispose();
|
||||
|
||||
fButton.setImage(fImage);
|
||||
fButton.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
ColorDialog colorDialog= new ColorDialog(fButton.getShell());
|
||||
colorDialog.setRGB(fColorValue);
|
||||
RGB newColor = colorDialog.open();
|
||||
if (newColor != null) {
|
||||
fColorValue= newColor;
|
||||
updateColorImage();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fButton.addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent event) {
|
||||
if (fImage != null) {
|
||||
fImage.dispose();
|
||||
fImage= null;
|
||||
}
|
||||
if (fColor != null) {
|
||||
fColor.dispose();
|
||||
fColor= null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public RGB getColorValue() {
|
||||
return fColorValue;
|
||||
}
|
||||
|
||||
public void setColorValue(RGB rgb) {
|
||||
fColorValue= rgb;
|
||||
updateColorImage();
|
||||
}
|
||||
|
||||
public Button getButton() {
|
||||
return fButton;
|
||||
}
|
||||
|
||||
protected void updateColorImage() {
|
||||
|
||||
Display display= fButton.getDisplay();
|
||||
|
||||
GC gc= new GC(fImage);
|
||||
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
|
||||
gc.drawRectangle(0, 2, fExtent.x - 1, fExtent.y - 4);
|
||||
|
||||
if (fColor != null)
|
||||
fColor.dispose();
|
||||
|
||||
fColor= new Color(display, fColorValue);
|
||||
gc.setBackground(fColor);
|
||||
gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5);
|
||||
gc.dispose();
|
||||
|
||||
fButton.setImage(fImage);
|
||||
}
|
||||
|
||||
protected Point computeImageSize(Control window) {
|
||||
GC gc= new GC(window);
|
||||
Font f= JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
|
||||
gc.setFont(f);
|
||||
int height= gc.getFontMetrics().getHeight();
|
||||
gc.dispose();
|
||||
Point p= new Point(height * 3 - 6, height);
|
||||
return p;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.ui.editors.text.TextEditorPreferenceConstants;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
|
||||
/**
|
||||
* MakefileEditorPreferenceConstants
|
||||
*/
|
||||
public class MakefileEditorPreferenceConstants {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private MakefileEditorPreferenceConstants() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The symbolic names for colors for displaying code assist proposals
|
||||
* @see org.eclipse.jface.resource.ColorRegistry
|
||||
*/
|
||||
public static final String CURRENT_LINE_COLOR = "org.eclipse.cdt.make.ui.currentLineHightlightColor"; //$NON-NLS-1$
|
||||
public static final String LINE_NUMBER_RULER_COLOR = "org.eclipse.cdt.make.ui.lineNumberForegroundColor"; //$NON-NLS-1$
|
||||
public static final String PRINT_MARGIN_COLOR = "org.eclipse.cdt.make.ui.printMarginColor"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Preference key suffix for bold text style preference keys.
|
||||
*
|
||||
*/
|
||||
public static final String EDITOR_BOLD_SUFFIX= "_bold"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Preference key suffix for italic text style preference keys.
|
||||
*/
|
||||
public static final String EDITOR_ITALIC_SUFFIX= "_italic"; //$NON-NLS-1$
|
||||
|
||||
|
||||
public static final String EDITOR_FOLDING_MACRODEF = "editor_folding_default_macrodef"; //$NON-NLS-1$
|
||||
|
||||
|
||||
public static final String EDITOR_FOLDING_RULE = "editor_folding_default_rule"; //$NON-NLS-1$
|
||||
|
||||
|
||||
public static final String EDITOR_FOLDING_CONDITIONAL = "editor_folding_default_conditional"; //$NON-NLS-1$
|
||||
|
||||
public static final String EDITOR_FOLDING_ENABLED = "editor_folding_enabled"; //$NON-NLS-1$;
|
||||
|
||||
|
||||
public static void initializeDefaultValues(IPreferenceStore store) {
|
||||
TextEditorPreferenceConstants.initializeDefaultValues(store);
|
||||
store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true);
|
||||
|
||||
store.setDefault(MakefileEditorPreferenceConstants.EDITOR_FOLDING_ENABLED, false);
|
||||
store.setDefault(MakefileEditorPreferenceConstants.EDITOR_FOLDING_MACRODEF, false);
|
||||
store.setDefault(MakefileEditorPreferenceConstants.EDITOR_FOLDING_RULE, true);
|
||||
store.setDefault(MakefileEditorPreferenceConstants.EDITOR_FOLDING_CONDITIONAL, true);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,764 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.text.ColorManager;
|
||||
import org.eclipse.cdt.make.ui.IMakeHelpContextIds;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
import org.eclipse.jface.viewers.IColorProvider;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.List;
|
||||
import org.eclipse.swt.widgets.TabFolder;
|
||||
import org.eclipse.swt.widgets.TabItem;
|
||||
import org.eclipse.ui.editors.text.EditorsUI;
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
import org.eclipse.ui.model.WorkbenchViewerSorter;
|
||||
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
|
||||
|
||||
/**
|
||||
* MakeEditorPreferencePage
|
||||
* The page for setting the editor options.
|
||||
*/
|
||||
public class MakefileEditorPreferencePage extends AbstractMakefileEditorPreferencePage {
|
||||
|
||||
/** The keys of the overlay store. */
|
||||
private String[][] fSyntaxColorListModel;
|
||||
|
||||
private TableViewer fHighlightingColorListViewer;
|
||||
private final java.util.List fHighlightingColorList= new ArrayList(5);
|
||||
List fAppearanceColorList;
|
||||
|
||||
ColorEditor fAppearanceColorEditor;
|
||||
Button fAppearanceColorDefault;
|
||||
ColorEditor fSyntaxForegroundColorEditor;
|
||||
ColorEditor fBackgroundColorEditor;
|
||||
private Button fBackgroundDefaultRadioButton;
|
||||
Button fBackgroundCustomRadioButton;
|
||||
Button fBackgroundColorButton;
|
||||
Button fBoldCheckBox;
|
||||
Button fItalicCheckBox;
|
||||
|
||||
// folding
|
||||
protected Button fFoldingCheckbox;
|
||||
|
||||
private SelectionListener fSelectionListener;
|
||||
protected Map fWorkingValues;
|
||||
protected ArrayList fComboBoxes;
|
||||
|
||||
|
||||
final String[][] fAppearanceColorListModel= new String[][] {
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.lineNumberForegroundColor"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR, null}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.currentLineHighlighColor"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, null}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.printMarginColor"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR, null}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.foreground"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.background"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR}, //$NON-NLS-1$
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Item in the highlighting color list.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
private class HighlightingColorListItem {
|
||||
/** Display name */
|
||||
private String fDisplayName;
|
||||
/** Color preference key */
|
||||
private String fColorKey;
|
||||
/** Bold preference key */
|
||||
private String fBoldKey;
|
||||
/** Italic preference key */
|
||||
private String fItalicKey;
|
||||
/** Item color */
|
||||
private Color fItemColor;
|
||||
|
||||
/**
|
||||
* Initialize the item with the given values.
|
||||
*
|
||||
* @param displayName the display name
|
||||
* @param colorKey the color preference key
|
||||
* @param boldKey the bold preference key
|
||||
* @param italicKey the italic preference key
|
||||
* @param itemColor the item color
|
||||
*/
|
||||
public HighlightingColorListItem(String displayName, String colorKey, String boldKey, String italicKey, Color itemColor) {
|
||||
fDisplayName= displayName;
|
||||
fColorKey= colorKey;
|
||||
fBoldKey= boldKey;
|
||||
fItalicKey= italicKey;
|
||||
fItemColor= itemColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the bold preference key
|
||||
*/
|
||||
public String getBoldKey() {
|
||||
return fBoldKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the bold preference key
|
||||
*/
|
||||
public String getItalicKey() {
|
||||
return fItalicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the color preference key
|
||||
*/
|
||||
public String getColorKey() {
|
||||
return fColorKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the display name
|
||||
*/
|
||||
public String getDisplayName() {
|
||||
return fDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the item color
|
||||
*/
|
||||
public Color getItemColor() {
|
||||
return fItemColor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Color list label provider.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
private class ColorListLabelProvider extends LabelProvider implements IColorProvider {
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
|
||||
*/
|
||||
public String getText(Object element) {
|
||||
return ((HighlightingColorListItem)element).getDisplayName();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
|
||||
*/
|
||||
public Color getForeground(Object element) {
|
||||
return ((HighlightingColorListItem)element).getItemColor();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
|
||||
*/
|
||||
public Color getBackground(Object element) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Color list content provider.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
private class ColorListContentProvider implements IStructuredContentProvider {
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return ((java.util.List)inputElement).toArray();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public MakefileEditorPreferencePage() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected OverlayPreferenceStore createOverlayStore() {
|
||||
fSyntaxColorListModel= new String[][] {
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.makefile_editor_comment"), ColorManager.MAKE_COMMENT_COLOR, null}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.makefile_editor_macro_ref"), ColorManager.MAKE_MACRO_REF_COLOR, null}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.makefile_editor_macro_def"), ColorManager.MAKE_MACRO_DEF_COLOR, null}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.makefile_editor_function"), ColorManager.MAKE_FUNCTION_COLOR, null}, //$NON-NLS-1$
|
||||
{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.makefile_editor_keyword"), ColorManager.MAKE_KEYWORD_COLOR, null}, //$NON-NLS-1$
|
||||
};
|
||||
ArrayList overlayKeys= new ArrayList();
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR));
|
||||
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER));
|
||||
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, MakefileEditorPreferenceConstants.EDITOR_FOLDING_ENABLED));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, MakefileEditorPreferenceConstants.EDITOR_FOLDING_CONDITIONAL));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, MakefileEditorPreferenceConstants.EDITOR_FOLDING_MACRODEF));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, MakefileEditorPreferenceConstants.EDITOR_FOLDING_RULE));
|
||||
|
||||
for (int i= 0; i < fSyntaxColorListModel.length; i++) {
|
||||
String colorKey= fSyntaxColorListModel[i][1];
|
||||
addTextKeyToCover(overlayKeys, colorKey);
|
||||
}
|
||||
|
||||
OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
|
||||
overlayKeys.toArray(keys);
|
||||
return new OverlayPreferenceStore(getPreferenceStore(), keys);
|
||||
}
|
||||
|
||||
private void addTextKeyToCover(ArrayList overlayKeys, String mainKey) {
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + MakefileEditorPreferenceConstants.EDITOR_BOLD_SUFFIX));
|
||||
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + MakefileEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
protected Control createContents(Composite parent) {
|
||||
initializeDefaultColors();
|
||||
WorkbenchHelp.setHelp(getControl(), IMakeHelpContextIds.MAKE_EDITOR_PREFERENCE_PAGE);
|
||||
getOverlayStore().load();
|
||||
getOverlayStore().start();
|
||||
|
||||
TabFolder folder= new TabFolder(parent, SWT.NONE);
|
||||
folder.setLayout(new TabFolderLayout());
|
||||
folder.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
TabItem item= new TabItem(folder, SWT.NONE);
|
||||
item.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.appearance")); //$NON-NLS-1$
|
||||
item.setControl(createAppearancePage(folder));
|
||||
|
||||
item= new TabItem(folder, SWT.NONE);
|
||||
item.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.syntax")); //$NON-NLS-1$
|
||||
item.setControl(createSyntaxPage(folder));
|
||||
|
||||
item= new TabItem(folder, SWT.NONE);
|
||||
item.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.folding")); //$NON-NLS-1$
|
||||
item.setControl(createFoldingTabContent(folder));
|
||||
|
||||
initialize();
|
||||
|
||||
applyDialogFont(folder);
|
||||
return folder;
|
||||
}
|
||||
|
||||
private void initializeDefaultColors() {
|
||||
if (!getPreferenceStore().contains(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)) {
|
||||
RGB rgb= getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
|
||||
PreferenceConverter.setDefault(getOverlayStore(), AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, rgb);
|
||||
PreferenceConverter.setDefault(getPreferenceStore(), AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, rgb);
|
||||
}
|
||||
if (!getPreferenceStore().contains(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND)) {
|
||||
RGB rgb= getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB();
|
||||
PreferenceConverter.setDefault(getOverlayStore(), AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, rgb);
|
||||
PreferenceConverter.setDefault(getPreferenceStore(), AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, rgb);
|
||||
}
|
||||
if (!getPreferenceStore().contains(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR)) {
|
||||
RGB rgb= getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION).getRGB();
|
||||
PreferenceConverter.setDefault(getOverlayStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, rgb);
|
||||
PreferenceConverter.setDefault(getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, rgb);
|
||||
}
|
||||
if (!getPreferenceStore().contains(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR)) {
|
||||
RGB rgb= getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT).getRGB();
|
||||
PreferenceConverter.setDefault(getOverlayStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, rgb);
|
||||
PreferenceConverter.setDefault(getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
|
||||
initializeFields();
|
||||
|
||||
for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++) {
|
||||
fHighlightingColorList.add(
|
||||
new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1],
|
||||
fSyntaxColorListModel[i][1] + MakefileEditorPreferenceConstants.EDITOR_BOLD_SUFFIX,
|
||||
fSyntaxColorListModel[i][1] + MakefileEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX, null));
|
||||
}
|
||||
fHighlightingColorListViewer.setInput(fHighlightingColorList);
|
||||
fHighlightingColorListViewer.setSelection(new StructuredSelection(fHighlightingColorListViewer.getElementAt(0)));
|
||||
|
||||
for (int i= 0; i < fAppearanceColorListModel.length; i++) {
|
||||
fAppearanceColorList.add(fAppearanceColorListModel[i][0]);
|
||||
}
|
||||
fAppearanceColorList.getDisplay().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
if (fAppearanceColorList != null && !fAppearanceColorList.isDisposed()) {
|
||||
fAppearanceColorList.select(0);
|
||||
handleAppearanceColorListSelection();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
initializeFolding();
|
||||
initializeBackgroundColorFields();
|
||||
}
|
||||
|
||||
void initializeFolding() {
|
||||
boolean enabled= getOverlayStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
|
||||
fFoldingCheckbox.setSelection(enabled);
|
||||
}
|
||||
|
||||
void initializeDefaultFolding() {
|
||||
boolean enabled= getOverlayStore().getDefaultBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
|
||||
fFoldingCheckbox.setSelection(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void initializeBackgroundColorFields() {
|
||||
RGB rgb= PreferenceConverter.getColor(getOverlayStore(), AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
|
||||
fBackgroundColorEditor.setColorValue(rgb);
|
||||
|
||||
boolean dflt= getOverlayStore().getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
|
||||
fBackgroundDefaultRadioButton.setSelection(dflt);
|
||||
fBackgroundCustomRadioButton.setSelection(!dflt);
|
||||
fBackgroundColorButton.setEnabled(!dflt);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ant.internal.ui.preferences.AbstractMakefileEditorPreferencePage#handleDefaults()
|
||||
*/
|
||||
protected void handleDefaults() {
|
||||
handleAppearanceColorListSelection();
|
||||
handleSyntaxColorListSelection();
|
||||
initializeBackgroundColorFields();
|
||||
initializeDefaultFolding();
|
||||
}
|
||||
|
||||
private Control createSyntaxPage(Composite parent) {
|
||||
|
||||
Composite colorComposite= new Composite(parent, SWT.NONE);
|
||||
colorComposite.setLayout(new GridLayout());
|
||||
|
||||
Group backgroundComposite= new Group(colorComposite, SWT.SHADOW_ETCHED_IN);
|
||||
GridLayout layout= new GridLayout();
|
||||
layout.numColumns= 3;
|
||||
backgroundComposite.setLayout(layout);
|
||||
backgroundComposite.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.backcolor")); //$NON-NLS-1$
|
||||
|
||||
SelectionListener backgroundSelectionListener= new SelectionListener() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean custom= fBackgroundCustomRadioButton.getSelection();
|
||||
fBackgroundColorButton.setEnabled(custom);
|
||||
getOverlayStore().setValue(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, !custom);
|
||||
}
|
||||
public void widgetDefaultSelected(SelectionEvent e) {}
|
||||
};
|
||||
|
||||
fBackgroundDefaultRadioButton= new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
|
||||
fBackgroundDefaultRadioButton.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.systemdefault")); //$NON-NLS-1$
|
||||
fBackgroundDefaultRadioButton.addSelectionListener(backgroundSelectionListener);
|
||||
|
||||
fBackgroundCustomRadioButton= new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
|
||||
fBackgroundCustomRadioButton.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.custom")); //$NON-NLS-1$
|
||||
fBackgroundCustomRadioButton.addSelectionListener(backgroundSelectionListener);
|
||||
|
||||
fBackgroundColorEditor= new ColorEditor(backgroundComposite);
|
||||
fBackgroundColorButton= fBackgroundColorEditor.getButton();
|
||||
|
||||
Label label= new Label(colorComposite, SWT.LEFT);
|
||||
label.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.Foreground")); //$NON-NLS-1$
|
||||
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
Composite editorComposite= new Composite(colorComposite, SWT.NONE);
|
||||
layout= new GridLayout();
|
||||
layout.numColumns= 2;
|
||||
layout.marginHeight= 0;
|
||||
layout.marginWidth= 0;
|
||||
editorComposite.setLayout(layout);
|
||||
GridData gd= new GridData(GridData.FILL_BOTH);
|
||||
editorComposite.setLayoutData(gd);
|
||||
|
||||
fHighlightingColorListViewer= new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
|
||||
fHighlightingColorListViewer.setLabelProvider(new ColorListLabelProvider());
|
||||
fHighlightingColorListViewer.setContentProvider(new ColorListContentProvider());
|
||||
fHighlightingColorListViewer.setSorter(new WorkbenchViewerSorter());
|
||||
gd= new GridData(GridData.FILL_BOTH);
|
||||
gd.heightHint= convertHeightInCharsToPixels(5);
|
||||
fHighlightingColorListViewer.getControl().setLayoutData(gd);
|
||||
|
||||
Composite stylesComposite= new Composite(editorComposite, SWT.NONE);
|
||||
layout= new GridLayout();
|
||||
layout.marginHeight= 0;
|
||||
layout.marginWidth= 0;
|
||||
layout.numColumns= 2;
|
||||
stylesComposite.setLayout(layout);
|
||||
stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
label= new Label(stylesComposite, SWT.LEFT);
|
||||
label.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.color")); //$NON-NLS-1$
|
||||
gd= new GridData();
|
||||
gd.horizontalAlignment= GridData.BEGINNING;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
fSyntaxForegroundColorEditor= new ColorEditor(stylesComposite);
|
||||
Button foregroundColorButton= fSyntaxForegroundColorEditor.getButton();
|
||||
gd= new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalAlignment= GridData.BEGINNING;
|
||||
foregroundColorButton.setLayoutData(gd);
|
||||
|
||||
fBoldCheckBox= new Button(stylesComposite, SWT.CHECK);
|
||||
fBoldCheckBox.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.bold")); //$NON-NLS-1$
|
||||
gd= new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalAlignment= GridData.BEGINNING;
|
||||
gd.horizontalSpan= 2;
|
||||
fBoldCheckBox.setLayoutData(gd);
|
||||
|
||||
fItalicCheckBox= new Button(stylesComposite, SWT.CHECK);
|
||||
fItalicCheckBox.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.italic")); //$NON-NLS-1$
|
||||
gd= new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalAlignment= GridData.BEGINNING;
|
||||
gd.horizontalSpan= 2;
|
||||
fItalicCheckBox.setLayoutData(gd);
|
||||
|
||||
fHighlightingColorListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
handleSyntaxColorListSelection();
|
||||
}
|
||||
});
|
||||
|
||||
foregroundColorButton.addSelectionListener(new SelectionListener() {
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
// do nothing
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
HighlightingColorListItem item= getHighlightingColorListItem();
|
||||
PreferenceConverter.setValue(getOverlayStore(), item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue());
|
||||
}
|
||||
});
|
||||
|
||||
fBackgroundColorButton.addSelectionListener(new SelectionListener() {
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
// do nothing
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
PreferenceConverter.setValue(getOverlayStore(), AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, fBackgroundColorEditor.getColorValue());
|
||||
}
|
||||
});
|
||||
|
||||
fBoldCheckBox.addSelectionListener(new SelectionListener() {
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
// do nothing
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
HighlightingColorListItem item= getHighlightingColorListItem();
|
||||
getOverlayStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection());
|
||||
}
|
||||
});
|
||||
|
||||
fItalicCheckBox.addSelectionListener(new SelectionListener() {
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
// do nothing
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
HighlightingColorListItem item= getHighlightingColorListItem();
|
||||
getOverlayStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection());
|
||||
}
|
||||
});
|
||||
|
||||
return colorComposite;
|
||||
}
|
||||
|
||||
void handleAppearanceColorListSelection() {
|
||||
int i= fAppearanceColorList.getSelectionIndex();
|
||||
String key= fAppearanceColorListModel[i][1];
|
||||
RGB rgb= PreferenceConverter.getColor(getOverlayStore(), key);
|
||||
fAppearanceColorEditor.setColorValue(rgb);
|
||||
updateAppearanceColorWidgets(fAppearanceColorListModel[i][2]);
|
||||
}
|
||||
|
||||
private void updateAppearanceColorWidgets(String systemDefaultKey) {
|
||||
if (systemDefaultKey == null) {
|
||||
fAppearanceColorDefault.setSelection(false);
|
||||
fAppearanceColorDefault.setVisible(false);
|
||||
fAppearanceColorEditor.getButton().setEnabled(true);
|
||||
} else {
|
||||
boolean systemDefault= getOverlayStore().getBoolean(systemDefaultKey);
|
||||
fAppearanceColorDefault.setSelection(systemDefault);
|
||||
fAppearanceColorDefault.setVisible(true);
|
||||
fAppearanceColorEditor.getButton().setEnabled(!systemDefault);
|
||||
}
|
||||
}
|
||||
|
||||
private Control createAppearancePage(Composite parent) {
|
||||
Font font= parent.getFont();
|
||||
|
||||
Composite appearanceComposite= new Composite(parent, SWT.NONE);
|
||||
appearanceComposite.setFont(font);
|
||||
GridLayout layout= new GridLayout();
|
||||
layout.numColumns= 2;
|
||||
appearanceComposite.setLayout(layout);
|
||||
|
||||
String labelText= MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.printMarginColumn"); //$NON-NLS-1$
|
||||
String[] errorMessages= new String[]{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.empty_input_print_margin"), MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.invalid_input_print_margin")}; //$NON-NLS-1$//$NON-NLS-2$
|
||||
addTextField(appearanceComposite, labelText, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, 3, 0, errorMessages);
|
||||
|
||||
labelText= MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.tabwidth"); //$NON-NLS-1$
|
||||
errorMessages= new String[]{MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.notabwidth"), MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.39")}; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
addTextField(appearanceComposite, labelText, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, 3, 0, errorMessages);
|
||||
|
||||
// labelText= MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.spacetabs"); //$NON-NLS-1$
|
||||
// addCheckBox(appearanceComposite, labelText, MakefileEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, 1);
|
||||
|
||||
labelText= MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.showOverviewRuler"); //$NON-NLS-1$
|
||||
addCheckBox(appearanceComposite, labelText, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, 0);
|
||||
|
||||
labelText= MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.showLineNumbers"); //$NON-NLS-1$
|
||||
addCheckBox(appearanceComposite, labelText, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, 0);
|
||||
|
||||
labelText= MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.highlightCurrentLine"); //$NON-NLS-1$
|
||||
addCheckBox(appearanceComposite, labelText, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, 0);
|
||||
|
||||
labelText= MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.showPrintMargin"); //$NON-NLS-1$
|
||||
addCheckBox(appearanceComposite, labelText, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, 0);
|
||||
|
||||
|
||||
Label label= new Label(appearanceComposite, SWT.LEFT );
|
||||
label.setFont(font);
|
||||
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
|
||||
gd.horizontalSpan= 2;
|
||||
gd.heightHint= convertHeightInCharsToPixels(1) / 2;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
label= new Label(appearanceComposite, SWT.LEFT);
|
||||
label.setFont(font);
|
||||
label.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.appearanceOptions")); //$NON-NLS-1$
|
||||
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
|
||||
gd.horizontalSpan= 2;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
Composite editorComposite= new Composite(appearanceComposite, SWT.NONE);
|
||||
editorComposite.setFont(font);
|
||||
layout= new GridLayout();
|
||||
layout.numColumns= 2;
|
||||
layout.marginHeight= 0;
|
||||
layout.marginWidth= 0;
|
||||
editorComposite.setLayout(layout);
|
||||
gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
|
||||
gd.horizontalSpan= 2;
|
||||
editorComposite.setLayoutData(gd);
|
||||
|
||||
fAppearanceColorList= new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
|
||||
fAppearanceColorList.setFont(font);
|
||||
gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
|
||||
gd.heightHint= convertHeightInCharsToPixels(6);
|
||||
fAppearanceColorList.setLayoutData(gd);
|
||||
|
||||
Composite stylesComposite= new Composite(editorComposite, SWT.NONE);
|
||||
stylesComposite.setFont(font);
|
||||
layout= new GridLayout();
|
||||
layout.marginHeight= 0;
|
||||
layout.marginWidth= 0;
|
||||
layout.numColumns= 2;
|
||||
stylesComposite.setLayout(layout);
|
||||
stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
label= new Label(stylesComposite, SWT.LEFT);
|
||||
label.setFont(font);
|
||||
label.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.color")); //$NON-NLS-1$
|
||||
gd= new GridData();
|
||||
gd.horizontalAlignment= GridData.BEGINNING;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
fAppearanceColorEditor= new ColorEditor(stylesComposite);
|
||||
Button foregroundColorButton= fAppearanceColorEditor.getButton();
|
||||
foregroundColorButton.setFont(font);
|
||||
gd= new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalAlignment= GridData.BEGINNING;
|
||||
foregroundColorButton.setLayoutData(gd);
|
||||
|
||||
fAppearanceColorList.addSelectionListener(new SelectionListener() {
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
// do nothing
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
handleAppearanceColorListSelection();
|
||||
}
|
||||
});
|
||||
|
||||
SelectionListener colorDefaultSelectionListener= new SelectionListener() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean systemDefault= fAppearanceColorDefault.getSelection();
|
||||
fAppearanceColorEditor.getButton().setEnabled(!systemDefault);
|
||||
|
||||
int i= fAppearanceColorList.getSelectionIndex();
|
||||
String key= fAppearanceColorListModel[i][2];
|
||||
if (key != null)
|
||||
getOverlayStore().setValue(key, systemDefault);
|
||||
}
|
||||
public void widgetDefaultSelected(SelectionEvent e) {}
|
||||
};
|
||||
|
||||
fAppearanceColorDefault= new Button(stylesComposite, SWT.CHECK);
|
||||
fAppearanceColorDefault.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.systemdefault")); //$NON-NLS-1$
|
||||
gd= new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalAlignment= GridData.BEGINNING;
|
||||
gd.horizontalSpan= 2;
|
||||
fAppearanceColorDefault.setLayoutData(gd);
|
||||
fAppearanceColorDefault.setVisible(false);
|
||||
fAppearanceColorDefault.addSelectionListener(colorDefaultSelectionListener);
|
||||
|
||||
foregroundColorButton.addSelectionListener(new SelectionListener() {
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
// do nothing
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int i= fAppearanceColorList.getSelectionIndex();
|
||||
String key= fAppearanceColorListModel[i][1];
|
||||
|
||||
PreferenceConverter.setValue(getOverlayStore(), key, fAppearanceColorEditor.getColorValue());
|
||||
}
|
||||
});
|
||||
return appearanceComposite;
|
||||
}
|
||||
|
||||
private Composite createFoldingTabContent(TabFolder folder) {
|
||||
Composite composite= new Composite(folder, SWT.NULL);
|
||||
// assume parent page uses griddata
|
||||
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_FILL);
|
||||
composite.setLayoutData(gd);
|
||||
GridLayout layout= new GridLayout();
|
||||
layout.numColumns= 2;
|
||||
//PixelConverter pc= new PixelConverter(composite);
|
||||
//layout.verticalSpacing= pc.convertHeightInCharsToPixels(1) / 2;
|
||||
composite.setLayout(layout);
|
||||
|
||||
|
||||
/* check box for new editors */
|
||||
fFoldingCheckbox= new Button(composite, SWT.CHECK);
|
||||
fFoldingCheckbox.setText(MakefilePreferencesMessages.getString("MakefileEditorPreferencePage.foldingenable")); //$NON-NLS-1$
|
||||
gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
|
||||
fFoldingCheckbox.setLayoutData(gd);
|
||||
fFoldingCheckbox.addSelectionListener(new SelectionListener() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean enabled= fFoldingCheckbox.getSelection();
|
||||
getOverlayStore().setValue(MakefileEditorPreferenceConstants.EDITOR_FOLDING_ENABLED, enabled);
|
||||
}
|
||||
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
return composite;
|
||||
}
|
||||
|
||||
void handleSyntaxColorListSelection() {
|
||||
HighlightingColorListItem item= getHighlightingColorListItem();
|
||||
RGB rgb= PreferenceConverter.getColor(getOverlayStore(), item.getColorKey());
|
||||
fSyntaxForegroundColorEditor.setColorValue(rgb);
|
||||
fBoldCheckBox.setSelection(getOverlayStore().getBoolean(item.getBoldKey()));
|
||||
fItalicCheckBox.setSelection(getOverlayStore().getBoolean(item.getItalicKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current highlighting color list item.
|
||||
*
|
||||
* @return the current highlighting color list item
|
||||
* @since 3.0
|
||||
*/
|
||||
HighlightingColorListItem getHighlightingColorListItem() {
|
||||
IStructuredSelection selection= (IStructuredSelection) fHighlightingColorListViewer.getSelection();
|
||||
return (HighlightingColorListItem) selection.getFirstElement();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||
*/
|
||||
public boolean performOk() {
|
||||
return super.performOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param preferenceStore
|
||||
*/
|
||||
public static void initDefaults(IPreferenceStore prefs) {
|
||||
EditorsUI.useAnnotationsPreferencePage(prefs);
|
||||
EditorsUI.useQuickDiffPreferencePage(prefs);
|
||||
|
||||
// Makefile Editor color preferences
|
||||
PreferenceConverter.setDefault(prefs, ColorManager.MAKE_COMMENT_COLOR, ColorManager.MAKE_COMMENT_RGB);
|
||||
PreferenceConverter.setDefault(prefs, ColorManager.MAKE_DEFAULT_COLOR, ColorManager.MAKE_DEFAULT_RGB);
|
||||
PreferenceConverter.setDefault(prefs, ColorManager.MAKE_FUNCTION_COLOR, ColorManager.MAKE_FUNCTION_RGB);
|
||||
PreferenceConverter.setDefault(prefs, ColorManager.MAKE_KEYWORD_COLOR, ColorManager.MAKE_KEYWORD_RGB);
|
||||
PreferenceConverter.setDefault(prefs, ColorManager.MAKE_MACRO_DEF_COLOR, ColorManager.MAKE_MACRO_DEF_RGB);
|
||||
PreferenceConverter.setDefault(prefs, ColorManager.MAKE_MACRO_REF_COLOR, ColorManager.MAKE_MACRO_REF_RGB);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* MakefilePreferencesMessages
|
||||
*/
|
||||
public class MakefilePreferencesMessages {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private MakefilePreferencesMessages() {
|
||||
}
|
||||
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.make.internal.ui.preferences.MakefilePreferencesMessages"; //$NON-NLS-1$
|
||||
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return ResourceBundle.getBundle(BUNDLE_NAME).getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
} catch (NullPointerException e) {
|
||||
return '#' + key + '#';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2000, 2004 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
|
||||
###############################################################################
|
||||
|
||||
MakefileEditorPreferencePage.description=Makefile Editor settings:
|
||||
MakefileEditorPreferencePage.invalid_input_print_margin= Invalid print margin column specified
|
||||
MakefileEditorPreferencePage.empty_input_print_margin= No print margin column specified
|
||||
MakefileEditorPreferencePage.appearance=Appeara&nce
|
||||
MakefileEditorPreferencePage.printMarginColumn=Print margin col&umn:
|
||||
MakefileEditorPreferencePage.showOverviewRuler=Show overview &ruler
|
||||
MakefileEditorPreferencePage.showLineNumbers=Show lin&e numbers
|
||||
MakefileEditorPreferencePage.highlightCurrentLine=Hi&ghlight current line
|
||||
MakefileEditorPreferencePage.showPrintMargin=Sho&w print margin
|
||||
MakefileEditorPreferencePage.color=C&olor:
|
||||
MakefileEditorPreferencePage.appearanceOptions=Appearance co&lor options:
|
||||
MakefileEditorPreferencePage.lineNumberForegroundColor=Line number foreground
|
||||
MakefileEditorPreferencePage.currentLineHighlighColor=Current line highlight
|
||||
MakefileEditorPreferencePage.printMarginColor=Print margin
|
||||
MakefileEditorPreferencePage.Makefile_editor_text_1=Text
|
||||
MakefileEditorPreferencePage.Makefile_editor_processing_instuctions_2=Processing instructions
|
||||
MakefileEditorPreferencePage.Makefile_editor_constMakefile_strings_3=ConstMakefile strings
|
||||
MakefileEditorPreferencePage.Makefile_editor_tags_4=Tags
|
||||
MakefileEditorPreferencePage.Makefile_editor_comments_5=Comments
|
||||
MakefileEditorPreferencePage.tabwidth=Displayed &tab width:
|
||||
MakefileEditorPreferencePage.notabwidth=No tab width specified
|
||||
MakefileEditorPreferencePage.39=Invalid tab width specified
|
||||
MakefileEditorPreferencePage.systemdefault=System de&fault
|
||||
MakefileEditorPreferencePage.spacetabs=&Insert spaces for tabs when typing
|
||||
MakefileEditorPreferencePage.foreground= Selection foreground color
|
||||
MakefileEditorPreferencePage.background= Selection background color
|
||||
MakefileEditorPreferencePage.syntax=Synta&x
|
||||
MakefileEditorPreferencePage.backcolor=Background color
|
||||
MakefileEditorPreferencePage.custom=C&ustom:
|
||||
MakefileEditorPreferencePage.Foreground=Fore&ground:
|
||||
MakefileEditorPreferencePage.bold=&Bold
|
||||
MakefileEditorPreferencePage.italic=I&talic
|
||||
|
||||
MakefileEditorPreferencePage.folding= &Folding
|
||||
MakefileEditorPreferencePage.foldingenable= Enable folding when &opening a new editor
|
||||
|
||||
MakefileEditorPreferencePage.makefile_editor_comment=comment
|
||||
MakefileEditorPreferencePage.makefile_editor_macro_def=macro definition
|
||||
MakefileEditorPreferencePage.makefile_editor_macro_ref=macro reference
|
||||
MakefileEditorPreferencePage.makefile_editor_function=function
|
||||
MakefileEditorPreferencePage.makefile_editor_keyword=keyword
|
||||
MakefileEditorPreferencePage.makefile_editor_target=target
|
|
@ -0,0 +1,455 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceStore;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
|
||||
/**
|
||||
* OverlayPreferenceStore
|
||||
*/
|
||||
/**
|
||||
* An overlaying preference store.
|
||||
*/
|
||||
class OverlayPreferenceStore implements IPreferenceStore {
|
||||
|
||||
|
||||
public static final class TypeDescriptor {
|
||||
TypeDescriptor() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final TypeDescriptor BOOLEAN= new TypeDescriptor();
|
||||
public static final TypeDescriptor DOUBLE= new TypeDescriptor();
|
||||
public static final TypeDescriptor FLOAT= new TypeDescriptor();
|
||||
public static final TypeDescriptor INT= new TypeDescriptor();
|
||||
public static final TypeDescriptor LONG= new TypeDescriptor();
|
||||
public static final TypeDescriptor STRING= new TypeDescriptor();
|
||||
|
||||
public static class OverlayKey {
|
||||
|
||||
TypeDescriptor fDescriptor;
|
||||
String fKey;
|
||||
|
||||
public OverlayKey(TypeDescriptor descriptor, String key) {
|
||||
fDescriptor= descriptor;
|
||||
fKey= key;
|
||||
}
|
||||
}
|
||||
|
||||
private class PropertyListener implements IPropertyChangeListener {
|
||||
|
||||
/*
|
||||
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
OverlayKey key= findOverlayKey(event.getProperty());
|
||||
if (key != null)
|
||||
propagateProperty(fParent, key, fStore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IPreferenceStore fParent;
|
||||
IPreferenceStore fStore;
|
||||
private OverlayKey[] fOverlayKeys;
|
||||
|
||||
private PropertyListener fPropertyListener;
|
||||
|
||||
|
||||
public OverlayPreferenceStore(IPreferenceStore parent, OverlayKey[] overlayKeys) {
|
||||
fParent= parent;
|
||||
fOverlayKeys= overlayKeys;
|
||||
fStore= new PreferenceStore();
|
||||
}
|
||||
|
||||
OverlayKey findOverlayKey(String key) {
|
||||
for (int i= 0; i < fOverlayKeys.length; i++) {
|
||||
if (fOverlayKeys[i].fKey.equals(key))
|
||||
return fOverlayKeys[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean covers(String key) {
|
||||
return (findOverlayKey(key) != null);
|
||||
}
|
||||
|
||||
void propagateProperty(IPreferenceStore orgin, OverlayKey key, IPreferenceStore target) {
|
||||
|
||||
if (orgin.isDefault(key.fKey)) {
|
||||
if (!target.isDefault(key.fKey))
|
||||
target.setToDefault(key.fKey);
|
||||
return;
|
||||
}
|
||||
|
||||
TypeDescriptor d= key.fDescriptor;
|
||||
if (BOOLEAN == d) {
|
||||
|
||||
boolean originValue= orgin.getBoolean(key.fKey);
|
||||
boolean targetValue= target.getBoolean(key.fKey);
|
||||
if (targetValue != originValue)
|
||||
target.setValue(key.fKey, originValue);
|
||||
|
||||
} else if (DOUBLE == d) {
|
||||
|
||||
double originValue= orgin.getDouble(key.fKey);
|
||||
double targetValue= target.getDouble(key.fKey);
|
||||
if (targetValue != originValue)
|
||||
target.setValue(key.fKey, originValue);
|
||||
|
||||
} else if (FLOAT == d) {
|
||||
|
||||
float originValue= orgin.getFloat(key.fKey);
|
||||
float targetValue= target.getFloat(key.fKey);
|
||||
if (targetValue != originValue)
|
||||
target.setValue(key.fKey, originValue);
|
||||
|
||||
} else if (INT == d) {
|
||||
|
||||
int originValue= orgin.getInt(key.fKey);
|
||||
int targetValue= target.getInt(key.fKey);
|
||||
if (targetValue != originValue)
|
||||
target.setValue(key.fKey, originValue);
|
||||
|
||||
} else if (LONG == d) {
|
||||
|
||||
long originValue= orgin.getLong(key.fKey);
|
||||
long targetValue= target.getLong(key.fKey);
|
||||
if (targetValue != originValue)
|
||||
target.setValue(key.fKey, originValue);
|
||||
|
||||
} else if (STRING == d) {
|
||||
|
||||
String originValue= orgin.getString(key.fKey);
|
||||
String targetValue= target.getString(key.fKey);
|
||||
if (targetValue != null && originValue != null && !targetValue.equals(originValue))
|
||||
target.setValue(key.fKey, originValue);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void propagate() {
|
||||
for (int i= 0; i < fOverlayKeys.length; i++)
|
||||
propagateProperty(fStore, fOverlayKeys[i], fParent);
|
||||
}
|
||||
|
||||
private void loadProperty(IPreferenceStore orgin, OverlayKey key, IPreferenceStore target, boolean forceInitialization) {
|
||||
TypeDescriptor d= key.fDescriptor;
|
||||
if (BOOLEAN == d) {
|
||||
|
||||
if (forceInitialization)
|
||||
target.setValue(key.fKey, true);
|
||||
target.setValue(key.fKey, orgin.getBoolean(key.fKey));
|
||||
target.setDefault(key.fKey, orgin.getDefaultBoolean(key.fKey));
|
||||
|
||||
} else if (DOUBLE == d) {
|
||||
|
||||
if (forceInitialization)
|
||||
target.setValue(key.fKey, 1.0D);
|
||||
target.setValue(key.fKey, orgin.getDouble(key.fKey));
|
||||
target.setDefault(key.fKey, orgin.getDefaultDouble(key.fKey));
|
||||
|
||||
} else if (FLOAT == d) {
|
||||
|
||||
if (forceInitialization)
|
||||
target.setValue(key.fKey, 1.0F);
|
||||
target.setValue(key.fKey, orgin.getFloat(key.fKey));
|
||||
target.setDefault(key.fKey, orgin.getDefaultFloat(key.fKey));
|
||||
|
||||
} else if (INT == d) {
|
||||
|
||||
if (forceInitialization)
|
||||
target.setValue(key.fKey, 1);
|
||||
target.setValue(key.fKey, orgin.getInt(key.fKey));
|
||||
target.setDefault(key.fKey, orgin.getDefaultInt(key.fKey));
|
||||
|
||||
} else if (LONG == d) {
|
||||
|
||||
if (forceInitialization)
|
||||
target.setValue(key.fKey, 1L);
|
||||
target.setValue(key.fKey, orgin.getLong(key.fKey));
|
||||
target.setDefault(key.fKey, orgin.getDefaultLong(key.fKey));
|
||||
|
||||
} else if (STRING == d) {
|
||||
|
||||
if (forceInitialization)
|
||||
target.setValue(key.fKey, "1"); //$NON-NLS-1$
|
||||
target.setValue(key.fKey, orgin.getString(key.fKey));
|
||||
target.setDefault(key.fKey, orgin.getDefaultString(key.fKey));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
for (int i= 0; i < fOverlayKeys.length; i++)
|
||||
loadProperty(fParent, fOverlayKeys[i], fStore, true);
|
||||
}
|
||||
|
||||
public void loadDefaults() {
|
||||
for (int i= 0; i < fOverlayKeys.length; i++)
|
||||
setToDefault(fOverlayKeys[i].fKey);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (fPropertyListener == null) {
|
||||
fPropertyListener= new PropertyListener();
|
||||
fParent.addPropertyChangeListener(fPropertyListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (fPropertyListener != null) {
|
||||
fParent.removePropertyChangeListener(fPropertyListener);
|
||||
fPropertyListener= null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#addPropertyChangeListener(IPropertyChangeListener)
|
||||
*/
|
||||
public void addPropertyChangeListener(IPropertyChangeListener listener) {
|
||||
fStore.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#removePropertyChangeListener(IPropertyChangeListener)
|
||||
*/
|
||||
public void removePropertyChangeListener(IPropertyChangeListener listener) {
|
||||
fStore.removePropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#firePropertyChangeEvent(String, Object, Object)
|
||||
*/
|
||||
public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
|
||||
fStore.firePropertyChangeEvent(name, oldValue, newValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#contains(String)
|
||||
*/
|
||||
public boolean contains(String name) {
|
||||
return fStore.contains(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getBoolean(String)
|
||||
*/
|
||||
public boolean getBoolean(String name) {
|
||||
return fStore.getBoolean(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getDefaultBoolean(String)
|
||||
*/
|
||||
public boolean getDefaultBoolean(String name) {
|
||||
return fStore.getDefaultBoolean(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getDefaultDouble(String)
|
||||
*/
|
||||
public double getDefaultDouble(String name) {
|
||||
return fStore.getDefaultDouble(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getDefaultFloat(String)
|
||||
*/
|
||||
public float getDefaultFloat(String name) {
|
||||
return fStore.getDefaultFloat(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getDefaultInt(String)
|
||||
*/
|
||||
public int getDefaultInt(String name) {
|
||||
return fStore.getDefaultInt(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getDefaultLong(String)
|
||||
*/
|
||||
public long getDefaultLong(String name) {
|
||||
return fStore.getDefaultLong(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getDefaultString(String)
|
||||
*/
|
||||
public String getDefaultString(String name) {
|
||||
return fStore.getDefaultString(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getDouble(String)
|
||||
*/
|
||||
public double getDouble(String name) {
|
||||
return fStore.getDouble(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getFloat(String)
|
||||
*/
|
||||
public float getFloat(String name) {
|
||||
return fStore.getFloat(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getInt(String)
|
||||
*/
|
||||
public int getInt(String name) {
|
||||
return fStore.getInt(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getLong(String)
|
||||
*/
|
||||
public long getLong(String name) {
|
||||
return fStore.getLong(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#getString(String)
|
||||
*/
|
||||
public String getString(String name) {
|
||||
return fStore.getString(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#isDefault(String)
|
||||
*/
|
||||
public boolean isDefault(String name) {
|
||||
return fStore.isDefault(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#needsSaving()
|
||||
*/
|
||||
public boolean needsSaving() {
|
||||
return fStore.needsSaving();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#putValue(String, String)
|
||||
*/
|
||||
public void putValue(String name, String value) {
|
||||
if (covers(name))
|
||||
fStore.putValue(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setDefault(String, double)
|
||||
*/
|
||||
public void setDefault(String name, double value) {
|
||||
if (covers(name))
|
||||
fStore.setDefault(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setDefault(String, float)
|
||||
*/
|
||||
public void setDefault(String name, float value) {
|
||||
if (covers(name))
|
||||
fStore.setDefault(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setDefault(String, int)
|
||||
*/
|
||||
public void setDefault(String name, int value) {
|
||||
if (covers(name))
|
||||
fStore.setDefault(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setDefault(String, long)
|
||||
*/
|
||||
public void setDefault(String name, long value) {
|
||||
if (covers(name))
|
||||
fStore.setDefault(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setDefault(String, String)
|
||||
*/
|
||||
public void setDefault(String name, String value) {
|
||||
if (covers(name))
|
||||
fStore.setDefault(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setDefault(String, boolean)
|
||||
*/
|
||||
public void setDefault(String name, boolean value) {
|
||||
if (covers(name))
|
||||
fStore.setDefault(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setToDefault(String)
|
||||
*/
|
||||
public void setToDefault(String name) {
|
||||
fStore.setToDefault(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setValue(String, double)
|
||||
*/
|
||||
public void setValue(String name, double value) {
|
||||
if (covers(name))
|
||||
fStore.setValue(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setValue(String, float)
|
||||
*/
|
||||
public void setValue(String name, float value) {
|
||||
if (covers(name))
|
||||
fStore.setValue(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setValue(String, int)
|
||||
*/
|
||||
public void setValue(String name, int value) {
|
||||
if (covers(name))
|
||||
fStore.setValue(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setValue(String, long)
|
||||
*/
|
||||
public void setValue(String name, long value) {
|
||||
if (covers(name))
|
||||
fStore.setValue(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setValue(String, String)
|
||||
*/
|
||||
public void setValue(String name, String value) {
|
||||
if (covers(name))
|
||||
fStore.setValue(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPreferenceStore#setValue(String, boolean)
|
||||
*/
|
||||
public void setValue(String name, boolean value) {
|
||||
if (covers(name))
|
||||
fStore.setValue(name, value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
||||
/**
|
||||
* A settable IStatus.
|
||||
* Can be an error, warning, info or ok. For error, info and warning states,
|
||||
* a message describes the problem.
|
||||
*/
|
||||
public class StatusInfo implements IStatus {
|
||||
|
||||
private String fStatusMessage;
|
||||
private int fSeverity;
|
||||
|
||||
/**
|
||||
* Creates a status set to OK (no message)
|
||||
*/
|
||||
public StatusInfo() {
|
||||
this(OK, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a status .
|
||||
* @param severity The status severity: ERROR, WARNING, INFO and OK.
|
||||
* @param message The message of the status. Applies only for ERROR,
|
||||
* WARNING and INFO.
|
||||
*/
|
||||
public StatusInfo(int severity, String message) {
|
||||
fStatusMessage= message;
|
||||
fSeverity= severity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the status' severity is OK.
|
||||
*/
|
||||
public boolean isOK() {
|
||||
return fSeverity == IStatus.OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the status' severity is WARNING.
|
||||
*/
|
||||
public boolean isWarning() {
|
||||
return fSeverity == IStatus.WARNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the status' severity is INFO.
|
||||
*/
|
||||
public boolean isInfo() {
|
||||
return fSeverity == IStatus.INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the status' severity is ERROR.
|
||||
*/
|
||||
public boolean isError() {
|
||||
return fSeverity == IStatus.ERROR;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.IStatus#getMessage()
|
||||
*/
|
||||
public String getMessage() {
|
||||
return fStatusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status to ERROR.
|
||||
* @param errorMessage The error message (can be empty, but not null)
|
||||
*/
|
||||
public void setError(String errorMessage) {
|
||||
Assert.isNotNull(errorMessage);
|
||||
fStatusMessage= errorMessage;
|
||||
fSeverity= IStatus.ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status to WARNING.
|
||||
* @param warningMessage The warning message (can be empty, but not null)
|
||||
*/
|
||||
public void setWarning(String warningMessage) {
|
||||
Assert.isNotNull(warningMessage);
|
||||
fStatusMessage= warningMessage;
|
||||
fSeverity= IStatus.WARNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status to INFO.
|
||||
* @param infoMessage The info message (can be empty, but not null)
|
||||
*/
|
||||
public void setInfo(String infoMessage) {
|
||||
Assert.isNotNull(infoMessage);
|
||||
fStatusMessage= infoMessage;
|
||||
fSeverity= IStatus.INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status to OK.
|
||||
*/
|
||||
public void setOK() {
|
||||
fStatusMessage= null;
|
||||
fSeverity= IStatus.OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IStatus#matches(int)
|
||||
*/
|
||||
public boolean matches(int severityMask) {
|
||||
return (fSeverity & severityMask) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns always <code>false</code>.
|
||||
* @see IStatus#isMultiStatus()
|
||||
*/
|
||||
public boolean isMultiStatus() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IStatus#getSeverity()
|
||||
*/
|
||||
public int getSeverity() {
|
||||
return fSeverity;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IStatus#getPlugin()
|
||||
*/
|
||||
public String getPlugin() {
|
||||
return MakeUIPlugin.getPluginId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns always <code>null</code>.
|
||||
* @see IStatus#getException()
|
||||
*/
|
||||
public Throwable getException() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns always the error severity.
|
||||
* @see IStatus#getCode()
|
||||
*/
|
||||
public int getCode() {
|
||||
return fSeverity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns always <code>null</code>.
|
||||
* @see IStatus#getChildren()
|
||||
*/
|
||||
public IStatus[] getChildren() {
|
||||
return new IStatus[0];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Layout;
|
||||
|
||||
public class TabFolderLayout extends Layout {
|
||||
|
||||
protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) {
|
||||
if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT)
|
||||
return new Point(wHint, hHint);
|
||||
|
||||
Control [] children = composite.getChildren ();
|
||||
int count = children.length;
|
||||
int maxWidth = 0, maxHeight = 0;
|
||||
for (int i=0; i<count; i++) {
|
||||
Control child = children [i];
|
||||
Point pt = child.computeSize (SWT.DEFAULT, SWT.DEFAULT, flushCache);
|
||||
maxWidth = Math.max (maxWidth, pt.x);
|
||||
maxHeight = Math.max (maxHeight, pt.y);
|
||||
}
|
||||
|
||||
if (wHint != SWT.DEFAULT)
|
||||
maxWidth= wHint;
|
||||
if (hHint != SWT.DEFAULT)
|
||||
maxHeight= hHint;
|
||||
|
||||
return new Point(maxWidth, maxHeight);
|
||||
|
||||
}
|
||||
|
||||
protected void layout (Composite composite, boolean flushCache) {
|
||||
Rectangle rect= composite.getClientArea();
|
||||
|
||||
Control[] children = composite.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
children[i].setBounds(rect);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.text;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.text.source.ISharedTextColors;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
public class ColorManager implements ISharedTextColors {
|
||||
|
||||
public static final String MAKE_COMMENT_COLOR ="org.eclipse.cdt.make.ui.editor.comment"; //$NON-NLS-1$
|
||||
public static final String MAKE_KEYWORD_COLOR = "org.eclipse.cdt.make.ui.editor.keyword"; //$NON-NLS-1$
|
||||
public static final String MAKE_FUNCTION_COLOR = "org.eclipse.cdt.make.ui.editor.function"; //$NON-NLS-1$
|
||||
public static final String MAKE_MACRO_REF_COLOR = "org.eclipse.cdt.make.ui.editor.macro_ref"; //$NON-NLS-1$
|
||||
public static final String MAKE_MACRO_DEF_COLOR = "org.eclipse.cdt.make.ui.editor.macro_def"; //$NON-NLS-1$
|
||||
public static final String MAKE_DEFAULT_COLOR = "org.eclipse.cdt.make.ui.editor.default"; //$NON-NLS-1$
|
||||
|
||||
public static final RGB MAKE_COMMENT_RGB = new RGB(128, 0, 0);
|
||||
public static final RGB MAKE_KEYWORD_RGB = new RGB(128, 255, 0);
|
||||
public static final RGB MAKE_FUNCTION_RGB = new RGB(128, 0, 128);
|
||||
public static final RGB MAKE_MACRO_DEF_RGB = new RGB(0, 0, 128);
|
||||
public static final RGB MAKE_MACRO_REF_RGB = new RGB(0, 128, 0);
|
||||
public static final RGB MAKE_DEFAULT_RGB = new RGB(0, 0, 0);
|
||||
|
||||
private static ColorManager fgColorManager;
|
||||
|
||||
private ColorManager() {
|
||||
}
|
||||
|
||||
public static ColorManager getDefault() {
|
||||
if (fgColorManager == null) {
|
||||
fgColorManager= new ColorManager();
|
||||
}
|
||||
return fgColorManager;
|
||||
}
|
||||
|
||||
protected Map fColorTable = new HashMap(10);
|
||||
|
||||
/**
|
||||
* @see IMakefileColorManager#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
Iterator e = fColorTable.values().iterator();
|
||||
while (e.hasNext())
|
||||
((Color) e.next()).dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IMakefileColorManager#getColor(RGB)
|
||||
*/
|
||||
public Color getColor(RGB rgb) {
|
||||
Color color = (Color) fColorTable.get(rgb);
|
||||
if (color == null) {
|
||||
color = new Color(Display.getCurrent(), rgb);
|
||||
fColorTable.put(rgb, color);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.text;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
public interface IMakefileColorManager {
|
||||
public static final RGB MAKE_COMMENT = new RGB(128, 0, 0);
|
||||
public static final RGB MAKE_KEYWORD = new RGB(128, 128, 0);
|
||||
public static final RGB MAKE_FUNCTION = new RGB(128, 0, 128);
|
||||
public static final RGB MAKE_MACRO_VAR = new RGB(0, 0, 128);
|
||||
public static final RGB MAKE_META_DATA = new RGB(0, 128, 0);
|
||||
public static final RGB MAKE_DEFAULT = new RGB(0, 0, 0);
|
||||
|
||||
public static final RGB MAKE_FORM_FOREGROUND = Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB();
|
||||
public static final RGB MAKE_FORM_BACKGROUND = new RGB(0xff, 0xff, 0xff); //RGB(0xff, 0xfe, 0xf9);
|
||||
public static final RGB MAKE_DEFAULT_PAGE_HEADER = new RGB(0x48, 0x70, 0x98);
|
||||
public static final RGB MAKE_HYPERLINK_TEXT = new RGB(0, 0, 128);
|
||||
public static final RGB MAKE_CONTROL_BORDER = new RGB(195, 191, 179);
|
||||
|
||||
void dispose();
|
||||
Color getColor(RGB rgb);
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.text;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
public class MakefileColorManager implements IMakefileColorManager {
|
||||
|
||||
protected Map fColorTable = new HashMap(10);
|
||||
|
||||
/**
|
||||
* @see IMakefileColorManager#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
Iterator e = fColorTable.values().iterator();
|
||||
while (e.hasNext())
|
||||
((Color) e.next()).dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IMakefileColorManager#getColor(RGB)
|
||||
*/
|
||||
public Color getColor(RGB rgb) {
|
||||
Color color = (Color) fColorTable.get(rgb);
|
||||
if (color == null) {
|
||||
color = new Color(Display.getCurrent(), rgb);
|
||||
fColorTable.put(rgb, color);
|
||||
}
|
||||
return color;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.preferences.MakefileEditorPreferenceConstants;
|
||||
import org.eclipse.cdt.make.internal.ui.text.ColorManager;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.resource.StringConverter;
|
||||
import org.eclipse.jface.text.TextAttribute;
|
||||
import org.eclipse.jface.text.rules.IRule;
|
||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
|
||||
/**
|
||||
* AbstractMakefileEditorScanner
|
||||
*/
|
||||
public abstract class AbstractMakefileCodeScanner extends RuleBasedScanner {
|
||||
|
||||
private Map fTokenMap= new HashMap();
|
||||
private String[] fPropertyNamesColor;
|
||||
/**
|
||||
* Preference keys for boolean preferences which are <code>true</code>,
|
||||
* iff the corresponding token should be rendered bold.
|
||||
*/
|
||||
private String[] fPropertyNamesBold;
|
||||
/**
|
||||
* Preference keys for boolean preferences which are <code>true</code>,
|
||||
* iff the corresponding token should be rendered italic.
|
||||
*/
|
||||
private String[] fPropertyNamesItalic;
|
||||
|
||||
private boolean fNeedsLazyColorLoading;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the list of preference keys which define the tokens
|
||||
* used in the rules of this scanner.
|
||||
*/
|
||||
abstract protected String[] getTokenProperties();
|
||||
|
||||
/**
|
||||
* Creates the list of rules controlling this scanner.
|
||||
*/
|
||||
abstract protected List createRules();
|
||||
|
||||
/**
|
||||
* Must be called after the constructor has been called.
|
||||
*/
|
||||
public final void initialize() {
|
||||
|
||||
fPropertyNamesColor= getTokenProperties();
|
||||
int length= fPropertyNamesColor.length;
|
||||
fPropertyNamesBold= new String[length];
|
||||
fPropertyNamesItalic= new String[length];
|
||||
|
||||
for (int i= 0; i < length; i++) {
|
||||
fPropertyNamesBold[i]= fPropertyNamesColor[i] + MakefileEditorPreferenceConstants.EDITOR_BOLD_SUFFIX;
|
||||
fPropertyNamesItalic[i]= fPropertyNamesColor[i] + MakefileEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX;
|
||||
addToken(fPropertyNamesColor[i], fPropertyNamesBold[i], fPropertyNamesItalic[i]);
|
||||
}
|
||||
|
||||
initializeRules();
|
||||
}
|
||||
|
||||
private void initializeRules() {
|
||||
List rules= createRules();
|
||||
if (rules != null) {
|
||||
IRule[] result= new IRule[rules.size()];
|
||||
rules.toArray(result);
|
||||
setRules(result);
|
||||
}
|
||||
}
|
||||
|
||||
protected Token getToken(String key) {
|
||||
return (Token) fTokenMap.get(key);
|
||||
}
|
||||
|
||||
private void addToken(String colorKey, String boldKey, String italicKey) {
|
||||
fTokenMap.put(colorKey, new Token(createTextAttribute(colorKey, boldKey, italicKey)));
|
||||
}
|
||||
|
||||
private int indexOf(String property) {
|
||||
if (property != null) {
|
||||
int length= fPropertyNamesColor.length;
|
||||
for (int i= 0; i < length; i++) {
|
||||
if (property.equals(fPropertyNamesColor[i]) || property.equals(fPropertyNamesBold[i]) || property.equals(fPropertyNamesItalic[i]))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean affectsBehavior(PropertyChangeEvent event) {
|
||||
return indexOf(event.getProperty()) >= 0;
|
||||
}
|
||||
|
||||
public void adaptToPreferenceChange(PropertyChangeEvent event) {
|
||||
String p= event.getProperty();
|
||||
int index= indexOf(p);
|
||||
Token token= getToken(fPropertyNamesColor[index]);
|
||||
if (fPropertyNamesColor[index].equals(p))
|
||||
adaptToColorChange(event, token);
|
||||
else if (fPropertyNamesBold[index].equals(p))
|
||||
adaptToStyleChange(event, token, SWT.BOLD);
|
||||
else if (fPropertyNamesItalic[index].equals(p))
|
||||
adaptToStyleChange(event, token, SWT.ITALIC);
|
||||
}
|
||||
|
||||
protected void adaptToColorChange(PropertyChangeEvent event, Token token) {
|
||||
RGB rgb= null;
|
||||
Object value= event.getNewValue();
|
||||
if (value instanceof RGB) {
|
||||
rgb= (RGB) value;
|
||||
} else if (value instanceof String) {
|
||||
rgb= StringConverter.asRGB((String) value);
|
||||
}
|
||||
|
||||
if (rgb != null) {
|
||||
TextAttribute attr= (TextAttribute) token.getData();
|
||||
token.setData(new TextAttribute(ColorManager.getDefault().getColor(rgb), attr.getBackground(), attr.getStyle()));
|
||||
}
|
||||
}
|
||||
|
||||
protected void adaptToStyleChange(PropertyChangeEvent event, Token token, int styleAttribute) {
|
||||
if (token == null) {
|
||||
return;
|
||||
}
|
||||
boolean eventValue= false;
|
||||
Object value= event.getNewValue();
|
||||
if (value instanceof Boolean) {
|
||||
eventValue= ((Boolean) value).booleanValue();
|
||||
} else if (IPreferenceStore.TRUE.equals(value)) {
|
||||
eventValue= true;
|
||||
}
|
||||
|
||||
TextAttribute attr= (TextAttribute) token.getData();
|
||||
boolean activeValue= (attr.getStyle() & styleAttribute) == styleAttribute;
|
||||
if (activeValue != eventValue) {
|
||||
token.setData(new TextAttribute(attr.getForeground(), attr.getBackground(), eventValue ? attr.getStyle() | styleAttribute : attr.getStyle() & ~styleAttribute));
|
||||
}
|
||||
}
|
||||
|
||||
protected TextAttribute createTextAttribute(String colorID, String boldKey, String italicKey) {
|
||||
Color color= null;
|
||||
if (colorID != null) {
|
||||
color= MakeUIPlugin.getPreferenceColor(colorID);
|
||||
}
|
||||
IPreferenceStore store= MakeUIPlugin.getDefault().getPreferenceStore();
|
||||
int style= store.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
|
||||
if (store.getBoolean(italicKey)) {
|
||||
style |= SWT.ITALIC;
|
||||
}
|
||||
return new TextAttribute(color, null, style);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||
|
||||
import org.eclipse.jface.text.rules.ICharacterScanner;
|
||||
import org.eclipse.jface.text.rules.IPredicateRule;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
|
||||
class MacroDefinitionRule implements IPredicateRule {
|
||||
private static final int INIT_STATE = 0;
|
||||
private static final int VAR_STATE = 1;
|
||||
private static final int END_VAR_STATE = 2;
|
||||
private static final int EQUAL_STATE = 3;
|
||||
private static final int FINISH_STATE = 4;
|
||||
private static final int ERROR_STATE = 5;
|
||||
|
||||
private IToken token;
|
||||
private StringBuffer buffer = new StringBuffer();
|
||||
protected IToken defaultToken;
|
||||
|
||||
public MacroDefinitionRule(IToken token, IToken defaultToken) {
|
||||
this.token = token;
|
||||
this.defaultToken = defaultToken;
|
||||
}
|
||||
|
||||
public IToken getSuccessToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
|
||||
buffer.setLength(0);
|
||||
int state = INIT_STATE;
|
||||
|
||||
if (resume)
|
||||
scanToBeginOfLine(scanner);
|
||||
|
||||
for (int c = scanner.read(); c != ICharacterScanner.EOF; c = scanner.read()) {
|
||||
char ch = (char)c;
|
||||
switch (state) {
|
||||
case INIT_STATE :
|
||||
if (c != '\n' && Character.isWhitespace((char) c)) {
|
||||
break;
|
||||
}
|
||||
if (isValidCharacter(c)) {
|
||||
state = VAR_STATE;
|
||||
} else {
|
||||
state = ERROR_STATE;
|
||||
}
|
||||
break;
|
||||
case VAR_STATE :
|
||||
if (isValidCharacter(c)) {
|
||||
break;
|
||||
}
|
||||
case END_VAR_STATE :
|
||||
if (c != '\n' && Character.isWhitespace((char) c)) {
|
||||
state = END_VAR_STATE;
|
||||
} else if (c == ':' || c == '+') {
|
||||
state = EQUAL_STATE;
|
||||
} else if (c == '=') {
|
||||
state = FINISH_STATE;
|
||||
} else {
|
||||
if (state == END_VAR_STATE) {
|
||||
scanner.unread(); // Return back to the space
|
||||
}
|
||||
state = ERROR_STATE;
|
||||
}
|
||||
break;
|
||||
case EQUAL_STATE :
|
||||
if (c == '=') {
|
||||
state = FINISH_STATE;
|
||||
} else {
|
||||
state = ERROR_STATE;
|
||||
}
|
||||
break;
|
||||
case FINISH_STATE :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
if (state >= FINISH_STATE) {
|
||||
break;
|
||||
}
|
||||
buffer.append((char) c);
|
||||
}
|
||||
|
||||
scanner.unread();
|
||||
|
||||
if (state == FINISH_STATE) {
|
||||
scanToEndOfLine(scanner);
|
||||
return token;
|
||||
}
|
||||
|
||||
if (defaultToken.isUndefined())
|
||||
unreadBuffer(scanner);
|
||||
|
||||
return Token.UNDEFINED;
|
||||
|
||||
}
|
||||
|
||||
public IToken evaluate(ICharacterScanner scanner) {
|
||||
return evaluate(scanner, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the characters in the buffer to the scanner.
|
||||
*
|
||||
* @param scanner the scanner to be used
|
||||
*/
|
||||
protected void unreadBuffer(ICharacterScanner scanner) {
|
||||
for (int i = buffer.length() - 1; i >= 0; i--) {
|
||||
scanner.unread();
|
||||
}
|
||||
}
|
||||
|
||||
private void scanToEndOfLine(ICharacterScanner scanner) {
|
||||
int c;
|
||||
char[][] delimiters = scanner.getLegalLineDelimiters();
|
||||
while ((c = scanner.read()) != ICharacterScanner.EOF) {
|
||||
// Check for end of line since it can be used to terminate the pattern.
|
||||
for (int i = 0; i < delimiters.length; i++) {
|
||||
if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void scanToBeginOfLine(ICharacterScanner scanner) {
|
||||
while(scanner.getColumn() != 0) {
|
||||
scanner.unread();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sequenceDetected(ICharacterScanner scanner, char[] sequence) {
|
||||
for (int i = 1; i < sequence.length; i++) {
|
||||
int c = scanner.read();
|
||||
if (c == ICharacterScanner.EOF) {
|
||||
return true;
|
||||
} else if (c != sequence[i]) {
|
||||
// Non-matching character detected, rewind the scanner back to the start.
|
||||
for (; i > 0; i--) {
|
||||
scanner.unread();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
protected boolean isValidCharacter(int c) {
|
||||
char c0 = (char) c;
|
||||
return Character.isLetterOrDigit(c0) || (c0 == '_');
|
||||
}
|
||||
|
||||
}
|
|
@ -14,12 +14,22 @@ import org.eclipse.jface.text.rules.ICharacterScanner;
|
|||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.PatternRule;
|
||||
|
||||
public class MakefileSimpleMacroRule extends PatternRule {
|
||||
public class MacroReferenceRule extends PatternRule {
|
||||
|
||||
private int nOfBrackets;
|
||||
int nOfBrackets;
|
||||
int fBracket;
|
||||
|
||||
public MakefileSimpleMacroRule(IToken token) {
|
||||
super("$(", ")", token, (char) 0, true); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// public MacroReferenceRule(IToken token) {
|
||||
// super("$(", ")", token, (char) 0, true); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// }
|
||||
|
||||
public MacroReferenceRule(IToken token, String startSeq, String endSeq) {
|
||||
super(startSeq, endSeq, token, (char)0, true);
|
||||
if (endSeq.length() > 0 && endSeq.charAt(0) == '}') {
|
||||
fBracket = '{';
|
||||
} else {
|
||||
fBracket = '(';
|
||||
}
|
||||
}
|
||||
|
||||
protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
|
||||
|
@ -31,20 +41,22 @@ public class MakefileSimpleMacroRule extends PatternRule {
|
|||
int c;
|
||||
char[][] delimiters = scanner.getLegalLineDelimiters();
|
||||
while ((c = scanner.read()) != ICharacterScanner.EOF) {
|
||||
if ('(' == (char) c)
|
||||
if (fBracket == c) {
|
||||
++nOfBrackets;
|
||||
|
||||
}
|
||||
if (fEndSequence.length > 0 && c == fEndSequence[0]) {
|
||||
// Check if the specified end sequence has been found.
|
||||
if (sequenceDetected(scanner, fEndSequence, true)) {
|
||||
if (0 == --nOfBrackets)
|
||||
if (0 == --nOfBrackets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (fBreaksOnEOL) {
|
||||
// Check for end of line since it can be used to terminate the pattern.
|
||||
for (int i = 0; i < delimiters.length; i++) {
|
||||
if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false))
|
||||
if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,19 +13,15 @@ package org.eclipse.cdt.make.internal.ui.text.makefile;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.text.IMakefileColorManager;
|
||||
import org.eclipse.jface.text.TextAttribute;
|
||||
import org.eclipse.cdt.make.internal.ui.text.ColorManager;
|
||||
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||
import org.eclipse.jface.text.rules.ICharacterScanner;
|
||||
import org.eclipse.jface.text.rules.IRule;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.IWhitespaceDetector;
|
||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
import org.eclipse.jface.text.rules.MultiLineRule;
|
||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
||||
import org.eclipse.jface.text.rules.WordRule;
|
||||
|
||||
public class MakefileCodeScanner extends RuleBasedScanner {
|
||||
public class MakefileCodeScanner extends AbstractMakefileCodeScanner {
|
||||
|
||||
private final static String[] keywords = { "define", "endef", "ifdef", "ifndef", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
"ifeq", "ifneq", "else", "endif", "include", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||
|
@ -41,18 +37,30 @@ public class MakefileCodeScanner extends RuleBasedScanner {
|
|||
"shell", "origin", "foreach", "call" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
};
|
||||
|
||||
public static final String[] fTokenProperties = new String[] {
|
||||
ColorManager.MAKE_COMMENT_COLOR,
|
||||
ColorManager.MAKE_KEYWORD_COLOR,
|
||||
ColorManager.MAKE_FUNCTION_COLOR,
|
||||
ColorManager.MAKE_MACRO_REF_COLOR,
|
||||
ColorManager.MAKE_MACRO_DEF_COLOR,
|
||||
ColorManager.MAKE_DEFAULT_COLOR
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor for MakefileCodeScanner
|
||||
*/
|
||||
public MakefileCodeScanner(IMakefileColorManager provider) {
|
||||
public MakefileCodeScanner() {
|
||||
super();
|
||||
|
||||
IToken keyword = new Token(new TextAttribute(provider.getColor(IMakefileColorManager.MAKE_KEYWORD)));
|
||||
IToken function = new Token(new TextAttribute(provider.getColor(IMakefileColorManager.MAKE_FUNCTION)));
|
||||
IToken comment = new Token(new TextAttribute(provider.getColor(IMakefileColorManager.MAKE_COMMENT)));
|
||||
IToken macro = new Token(new TextAttribute(provider.getColor(IMakefileColorManager.MAKE_MACRO_VAR)));
|
||||
IToken other = new Token(new TextAttribute(provider.getColor(IMakefileColorManager.MAKE_DEFAULT)));
|
||||
initialize();
|
||||
}
|
||||
|
||||
protected List createRules() {
|
||||
IToken keyword = getToken(ColorManager.MAKE_KEYWORD_COLOR);
|
||||
IToken function = getToken(ColorManager.MAKE_FUNCTION_COLOR);
|
||||
IToken comment = getToken(ColorManager.MAKE_COMMENT_COLOR);
|
||||
IToken macroRef = getToken(ColorManager.MAKE_MACRO_REF_COLOR);
|
||||
IToken macroDef = getToken(ColorManager.MAKE_MACRO_DEF_COLOR);
|
||||
IToken other = getToken(ColorManager.MAKE_DEFAULT_COLOR);
|
||||
|
||||
List rules = new ArrayList();
|
||||
|
||||
|
@ -66,6 +74,12 @@ public class MakefileCodeScanner extends RuleBasedScanner {
|
|||
}
|
||||
}));
|
||||
|
||||
// Put before the the word rules
|
||||
MultiLineRule defineRule = new MultiLineRule("define", "endef", macroDef); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
defineRule.setColumnConstraint(0);
|
||||
rules.add(defineRule);
|
||||
rules.add(new MacroDefinitionRule(macroDef, other));
|
||||
|
||||
// Add word rule for keywords, types, and constants.
|
||||
// We restring the detection of the keywords to be the first column to be valid.
|
||||
WordRule keyWordRule = new WordRule(new MakefileWordDetector(), other);
|
||||
|
@ -78,115 +92,21 @@ public class MakefileCodeScanner extends RuleBasedScanner {
|
|||
WordRule functionRule = new WordRule(new MakefileWordDetector(), other);
|
||||
for (int i = 0; i < functions.length; i++)
|
||||
functionRule.addWord(functions[i], function);
|
||||
|
||||
rules.add(functionRule);
|
||||
|
||||
//rules.add(new PatternRule("$(", ")", macro, '\\', true)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
rules.add(new MakefileSimpleMacroRule(macro)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
rules.add(new MacroRule(macro, other));
|
||||
rules.add(new MacroReferenceRule(macroRef, "$(", ")")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
rules.add(new MacroReferenceRule(macroRef, "${", "}")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
setDefaultReturnToken(other);
|
||||
|
||||
IRule[] result = new IRule[rules.size()];
|
||||
|
||||
rules.toArray(result);
|
||||
|
||||
setRules(result);
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
private class MacroRule implements IRule {
|
||||
private static final int INIT_STATE = 0;
|
||||
private static final int VAR_STATE = 1;
|
||||
private static final int END_VAR_STATE = 2;
|
||||
private static final int EQUAL_STATE = 3;
|
||||
private static final int FINISH_STATE = 4;
|
||||
private static final int ERROR_STATE = 5;
|
||||
|
||||
private IToken token;
|
||||
private StringBuffer buffer = new StringBuffer();
|
||||
protected IToken defaultToken;
|
||||
public MacroRule(IToken token, IToken defaultToken) {
|
||||
this.token = token;
|
||||
this.defaultToken = defaultToken;
|
||||
}
|
||||
public IToken evaluate(ICharacterScanner scanner) {
|
||||
int state = INIT_STATE;
|
||||
buffer.setLength(0);
|
||||
boolean bTwoCharsAssign = false;
|
||||
|
||||
for (int c = scanner.read(); c != ICharacterScanner.EOF; c = scanner.read()) {
|
||||
switch (state) {
|
||||
case INIT_STATE :
|
||||
if (c != '\n' && Character.isWhitespace((char) c))
|
||||
break;
|
||||
if (isValidCharacter(c))
|
||||
state = VAR_STATE;
|
||||
else
|
||||
state = ERROR_STATE;
|
||||
break;
|
||||
case VAR_STATE :
|
||||
if (isValidCharacter(c))
|
||||
break;
|
||||
case END_VAR_STATE :
|
||||
if (c != '\n' && Character.isWhitespace((char) c))
|
||||
state = END_VAR_STATE;
|
||||
else if (c == ':' || c == '+') {
|
||||
bTwoCharsAssign = true;
|
||||
state = EQUAL_STATE;
|
||||
} else if (c == '=')
|
||||
state = FINISH_STATE;
|
||||
else {
|
||||
if (state == END_VAR_STATE)
|
||||
scanner.unread(); // Return back to the space
|
||||
state = ERROR_STATE;
|
||||
}
|
||||
break;
|
||||
case EQUAL_STATE :
|
||||
if (c == '=')
|
||||
state = FINISH_STATE;
|
||||
else
|
||||
state = ERROR_STATE;
|
||||
break;
|
||||
case FINISH_STATE :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
if (state >= FINISH_STATE)
|
||||
break;
|
||||
buffer.append((char) c);
|
||||
}
|
||||
|
||||
scanner.unread();
|
||||
|
||||
if (state == FINISH_STATE) {
|
||||
if (bTwoCharsAssign)
|
||||
scanner.unread();
|
||||
return token;
|
||||
}
|
||||
|
||||
if (defaultToken.isUndefined())
|
||||
unreadBuffer(scanner);
|
||||
|
||||
return Token.UNDEFINED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the characters in the buffer to the scanner.
|
||||
*
|
||||
* @param scanner the scanner to be used
|
||||
*/
|
||||
protected void unreadBuffer(ICharacterScanner scanner) {
|
||||
for (int i = buffer.length() - 1; i >= 0; i--)
|
||||
scanner.unread();
|
||||
}
|
||||
|
||||
protected boolean isValidCharacter(int c) {
|
||||
char c0 = (char) c;
|
||||
return Character.isLetterOrDigit(c0) || (c0 == '_');
|
||||
}
|
||||
/*
|
||||
* @see AbstractMakefileCodeScanner#getTokenProperties()
|
||||
*/
|
||||
protected String[] getTokenProperties() {
|
||||
return fTokenProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.rules.IRule;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.IWhitespaceDetector;
|
||||
import org.eclipse.jface.text.rules.IWordDetector;
|
||||
import org.eclipse.jface.text.rules.PatternRule;
|
||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
||||
import org.eclipse.jface.text.rules.WordRule;
|
||||
|
||||
public class MakefileMacroScanner extends RuleBasedScanner {
|
||||
private String buffer;
|
||||
private final static String[] DELIMITERS = { "\r", "\n", "\r\n" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
|
||||
public final static String tokenText = "text"; //$NON-NLS-1$
|
||||
public final static String tokenMacro = "macro"; //$NON-NLS-1$
|
||||
public final static String tokenOther = "other"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Constructor for MakefileMacroScanner
|
||||
*/
|
||||
public MakefileMacroScanner(String buffer) {
|
||||
super();
|
||||
this.buffer = buffer;
|
||||
fOffset = 0;
|
||||
|
||||
IToken tText = new Token(tokenText);
|
||||
IToken tMacro = new Token(tokenMacro);
|
||||
IToken tOther = new Token(tokenOther);
|
||||
|
||||
List rules = new ArrayList();
|
||||
|
||||
rules.add(new PatternRule("\"", "\"", tText, '\\', true)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
rules.add(new PatternRule("\'", "\'", tText, '\\', true)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
rules.add(new MakefileSimpleMacroRule(tMacro));
|
||||
|
||||
// Add generic whitespace rule.
|
||||
rules.add(new WhitespaceRule(new IWhitespaceDetector() {
|
||||
public boolean isWhitespace(char character) {
|
||||
return Character.isWhitespace(character);
|
||||
}
|
||||
}));
|
||||
|
||||
WordRule wRule = new WordRule(new IWordDetector() {
|
||||
public boolean isWordPart(char c) {
|
||||
return isWordStart(c);
|
||||
}
|
||||
public boolean isWordStart(char c) {
|
||||
return !(((short) c == EOF) || Character.isSpaceChar(c));
|
||||
}
|
||||
}, tOther);
|
||||
|
||||
rules.add(wRule);
|
||||
|
||||
IRule[] result = new IRule[rules.size()];
|
||||
|
||||
rules.toArray(result);
|
||||
|
||||
setRules(result);
|
||||
|
||||
setRange(null, 0, buffer.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RuleBasedScanner#getColumn()
|
||||
*/
|
||||
public int getColumn() {
|
||||
return fOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RuleBasedScanner#read()
|
||||
*/
|
||||
public int read() {
|
||||
int c;
|
||||
if (fOffset == buffer.length())
|
||||
c = EOF;
|
||||
else
|
||||
c = buffer.charAt(fOffset);
|
||||
++fOffset;
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RuleBasedScanner#setRange(IDocument, int, int)
|
||||
*/
|
||||
public void setRange(IDocument document, int offset, int length) {
|
||||
fDocument = document;
|
||||
fOffset = offset;
|
||||
fRangeEnd = offset + length;
|
||||
|
||||
fDelimiters = new char[DELIMITERS.length][];
|
||||
for (int i = 0; i < DELIMITERS.length; i++)
|
||||
fDelimiters[i] = DELIMITERS[i].toCharArray();
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||
import org.eclipse.jface.text.rules.ICharacterScanner;
|
||||
import org.eclipse.jface.text.rules.IPredicateRule;
|
||||
import org.eclipse.jface.text.rules.IToken;
|
||||
import org.eclipse.jface.text.rules.MultiLineRule;
|
||||
|
@ -23,29 +22,25 @@ import org.eclipse.jface.text.rules.Token;
|
|||
|
||||
public class MakefilePartitionScanner extends RuleBasedPartitionScanner {
|
||||
// Partition types
|
||||
public final static String MAKEFILE_COMMENT = "makefile_comment"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_MACRO_ASSIGNEMENT = "makefile_macro_assignement"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_INCLUDE_BLOCK = "makefile_include_block"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_IF_BLOCK = "makefile_if_block"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_DEF_BLOCK = "makefile_def_block"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_OTHER = "makefile_other"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_COMMENT_PARTITION = "makefile_comment"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_MACRO_ASSIGNEMENT_PARTITION = "makefile_macro_assignement"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_INCLUDE_BLOCK_PARTITION = "makefile_include_block"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_IF_BLOCK_PARTITION = "makefile_if_block"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_DEF_BLOCK_PARTITION = "makefile_def_block"; //$NON-NLS-1$
|
||||
public final static String MAKEFILE_OTHER_PARTITION = "makefile_other"; //$NON-NLS-1$
|
||||
|
||||
public final static String[] TYPES =
|
||||
public final static String[] MAKE_PARTITIONS =
|
||||
new String[] {
|
||||
MAKEFILE_COMMENT,
|
||||
MAKEFILE_MACRO_ASSIGNEMENT,
|
||||
MAKEFILE_INCLUDE_BLOCK,
|
||||
MAKEFILE_IF_BLOCK,
|
||||
MAKEFILE_DEF_BLOCK,
|
||||
MAKEFILE_OTHER,
|
||||
// All other
|
||||
MAKEFILE_COMMENT_PARTITION,
|
||||
MAKEFILE_MACRO_ASSIGNEMENT_PARTITION,
|
||||
MAKEFILE_INCLUDE_BLOCK_PARTITION,
|
||||
MAKEFILE_IF_BLOCK_PARTITION,
|
||||
MAKEFILE_DEF_BLOCK_PARTITION,
|
||||
MAKEFILE_OTHER_PARTITION,
|
||||
};
|
||||
|
||||
/** The predefined delimiters of this tracker */
|
||||
private char[][] fModDelimiters = { { '\r', '\n' }, {
|
||||
'\r' }, {
|
||||
'\n' }
|
||||
};
|
||||
private char[][] fModDelimiters = { { '\r', '\n' }, { '\r' }, { '\n' } };
|
||||
|
||||
/**
|
||||
* Constructor for MakefilePartitionScanner
|
||||
|
@ -53,18 +48,18 @@ public class MakefilePartitionScanner extends RuleBasedPartitionScanner {
|
|||
public MakefilePartitionScanner() {
|
||||
super();
|
||||
|
||||
IToken tComment = new Token(MAKEFILE_COMMENT);
|
||||
IToken tMacro = new Token(MAKEFILE_MACRO_ASSIGNEMENT);
|
||||
IToken tInclude = new Token(MAKEFILE_INCLUDE_BLOCK);
|
||||
IToken tIf = new Token(MAKEFILE_IF_BLOCK);
|
||||
IToken tDef = new Token(MAKEFILE_DEF_BLOCK);
|
||||
IToken tOther = new Token(MAKEFILE_OTHER);
|
||||
IToken tComment = new Token(MAKEFILE_COMMENT_PARTITION);
|
||||
IToken tMacro = new Token(MAKEFILE_MACRO_ASSIGNEMENT_PARTITION);
|
||||
IToken tInclude = new Token(MAKEFILE_INCLUDE_BLOCK_PARTITION);
|
||||
IToken tIf = new Token(MAKEFILE_IF_BLOCK_PARTITION);
|
||||
IToken tDef = new Token(MAKEFILE_DEF_BLOCK_PARTITION);
|
||||
IToken tOther = new Token(MAKEFILE_OTHER_PARTITION);
|
||||
|
||||
List rules = new ArrayList();
|
||||
|
||||
// Add rule for single line comments.
|
||||
|
||||
rules.add(new EndOfLineRule("#", tComment, '\\')); //$NON-NLS-1$
|
||||
rules.add(new EndOfLineRule("#", tComment, '\\', true)); //$NON-NLS-1$
|
||||
|
||||
rules.add(new EndOfLineRule("include", tInclude)); //$NON-NLS-1$
|
||||
|
||||
|
@ -82,7 +77,7 @@ public class MakefilePartitionScanner extends RuleBasedPartitionScanner {
|
|||
rules.add(new MultiLineRule("ifnneq", "endif", tIf)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
// Last rule must be supplied with default token!
|
||||
rules.add(new MacroRule(tMacro, tOther)); //$NON-NLS-1$
|
||||
rules.add(new MacroDefinitionRule(tMacro, tOther)); //$NON-NLS-1$
|
||||
|
||||
IPredicateRule[] result = new IPredicateRule[rules.size()];
|
||||
rules.toArray(result);
|
||||
|
@ -97,141 +92,4 @@ public class MakefilePartitionScanner extends RuleBasedPartitionScanner {
|
|||
return fModDelimiters;
|
||||
}
|
||||
|
||||
private class MacroRule implements IPredicateRule {
|
||||
private static final int INIT_STATE = 0;
|
||||
private static final int VAR_STATE = 1;
|
||||
private static final int END_VAR_STATE = 2;
|
||||
private static final int EQUAL_STATE = 3;
|
||||
private static final int FINISH_STATE = 4;
|
||||
private static final int ERROR_STATE = 5;
|
||||
|
||||
private IToken token;
|
||||
private StringBuffer buffer = new StringBuffer();
|
||||
protected IToken defaultToken;
|
||||
public MacroRule(IToken token, IToken defaultToken) {
|
||||
this.token = token;
|
||||
this.defaultToken = defaultToken;
|
||||
}
|
||||
|
||||
public IToken getSuccessToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public IToken evaluate(ICharacterScanner scanner, boolean resume) {
|
||||
buffer.setLength(0);
|
||||
int state = INIT_STATE;
|
||||
|
||||
if (resume)
|
||||
scanToBeginOfLine(scanner);
|
||||
|
||||
for (int c = scanner.read(); c != ICharacterScanner.EOF; c = scanner.read()) {
|
||||
switch (state) {
|
||||
case INIT_STATE :
|
||||
if (c != '\n' && Character.isWhitespace((char) c))
|
||||
break;
|
||||
if (isValidCharacter(c))
|
||||
state = VAR_STATE;
|
||||
else
|
||||
state = ERROR_STATE;
|
||||
break;
|
||||
case VAR_STATE :
|
||||
if (isValidCharacter(c))
|
||||
break;
|
||||
case END_VAR_STATE :
|
||||
if (c != '\n' && Character.isWhitespace((char) c))
|
||||
state = END_VAR_STATE;
|
||||
else if (c == ':' || c == '+')
|
||||
state = EQUAL_STATE;
|
||||
else if (c == '=')
|
||||
state = FINISH_STATE;
|
||||
else {
|
||||
if (state == END_VAR_STATE)
|
||||
scanner.unread(); // Return back to the space
|
||||
state = ERROR_STATE;
|
||||
}
|
||||
break;
|
||||
case EQUAL_STATE :
|
||||
if (c == '=')
|
||||
state = FINISH_STATE;
|
||||
else
|
||||
state = ERROR_STATE;
|
||||
break;
|
||||
case FINISH_STATE :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
if (state >= FINISH_STATE)
|
||||
break;
|
||||
buffer.append((char) c);
|
||||
}
|
||||
|
||||
scanner.unread();
|
||||
|
||||
if (state == FINISH_STATE) {
|
||||
scanToEndOfLine(scanner);
|
||||
return token;
|
||||
}
|
||||
|
||||
if (defaultToken.isUndefined())
|
||||
unreadBuffer(scanner);
|
||||
|
||||
return Token.UNDEFINED;
|
||||
|
||||
}
|
||||
|
||||
public IToken evaluate(ICharacterScanner scanner) {
|
||||
return evaluate(scanner, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the characters in the buffer to the scanner.
|
||||
*
|
||||
* @param scanner the scanner to be used
|
||||
*/
|
||||
protected void unreadBuffer(ICharacterScanner scanner) {
|
||||
for (int i = buffer.length() - 1; i >= 0; i--)
|
||||
scanner.unread();
|
||||
}
|
||||
|
||||
private void scanToEndOfLine(ICharacterScanner scanner) {
|
||||
int c;
|
||||
char[][] delimiters = scanner.getLegalLineDelimiters();
|
||||
while ((c = scanner.read()) != ICharacterScanner.EOF) {
|
||||
// Check for end of line since it can be used to terminate the pattern.
|
||||
for (int i = 0; i < delimiters.length; i++) {
|
||||
if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i]))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void scanToBeginOfLine(ICharacterScanner scanner) {
|
||||
while(scanner.getColumn() != 0) {
|
||||
scanner.unread();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sequenceDetected(ICharacterScanner scanner, char[] sequence) {
|
||||
for (int i = 1; i < sequence.length; i++) {
|
||||
int c = scanner.read();
|
||||
if (c == ICharacterScanner.EOF) {
|
||||
return true;
|
||||
} else if (c != sequence[i]) {
|
||||
// Non-matching character detected, rewind the scanner back to the start.
|
||||
for (; i > 0; i--)
|
||||
scanner.unread();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
protected boolean isValidCharacter(int c) {
|
||||
char c0 = (char) c;
|
||||
return Character.isLetterOrDigit(c0) || (c0 == '_');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.io.StringReader;
|
|||
|
||||
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.editor.IReconcilingParticipant;
|
||||
import org.eclipse.cdt.make.internal.ui.editor.MakefileContentOutlinePage;
|
||||
import org.eclipse.cdt.make.internal.ui.editor.MakefileEditor;
|
||||
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
|
||||
|
@ -34,8 +35,8 @@ public class MakefileReconcilingStrategy implements IReconcilingStrategy {
|
|||
private ITextEditor fEditor;
|
||||
private IWorkingCopyManager fManager;
|
||||
private IDocumentProvider fDocumentProvider;
|
||||
|
||||
private MakefileContentOutlinePage fOutliner;
|
||||
private IReconcilingParticipant fMakefileReconcilingParticipant;
|
||||
|
||||
public MakefileReconcilingStrategy(MakefileEditor editor) {
|
||||
fOutliner= editor.getOutlinePage();
|
||||
|
@ -43,6 +44,10 @@ public class MakefileReconcilingStrategy implements IReconcilingStrategy {
|
|||
fEditor= editor;
|
||||
fManager= MakeUIPlugin.getDefault().getWorkingCopyManager();
|
||||
fDocumentProvider= MakeUIPlugin.getDefault().getMakefileDocumentProvider();
|
||||
if (fEditor instanceof IReconcilingParticipant) {
|
||||
fMakefileReconcilingParticipant= (IReconcilingParticipant)fEditor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,16 +81,26 @@ public class MakefileReconcilingStrategy implements IReconcilingStrategy {
|
|||
}
|
||||
|
||||
private void reconcile() {
|
||||
IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||
if (makefile != null) {
|
||||
String content = fDocumentProvider.getDocument(fEditor.getEditorInput()).get();
|
||||
StringReader reader = new StringReader(content);
|
||||
try {
|
||||
makefile.parse(makefile.getFileName(), reader);
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||
if (makefile != null) {
|
||||
String content = fDocumentProvider.getDocument(fEditor.getEditorInput()).get();
|
||||
StringReader reader = new StringReader(content);
|
||||
try {
|
||||
makefile.parse(makefile.getFileName(), reader);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
fOutliner.update();
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if (fMakefileReconcilingParticipant != null) {
|
||||
fMakefileReconcilingParticipant.reconciled();
|
||||
}
|
||||
} finally {
|
||||
//
|
||||
}
|
||||
|
||||
fOutliner.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,6 @@ public interface IMakeHelpContextIds {
|
|||
public static final String MAKE_PREF_ERROR_PARSER = PREFIX + "newproj_parser_error"; //$NON-NLS-1$
|
||||
public static final String MAKE_PREF_BINARY_PARSER = PREFIX + "newproj_parser_binary"; //$NON-NLS-1$
|
||||
|
||||
public static final String MAKE_EDITOR_PREFERENCE_PAGE = PREFIX + "make_editor_pref"; //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue