mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Provide more setting for the makefile editor.
This commit is contained in:
parent
5916669818
commit
73e222cdd8
8 changed files with 442 additions and 18 deletions
|
@ -10,11 +10,14 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.make.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IDiscoveredPathManager;
|
||||
|
@ -24,6 +27,7 @@ import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
|
|||
import org.eclipse.cdt.make.internal.core.BuildInfoFactory;
|
||||
import org.eclipse.cdt.make.internal.core.MakeTargetManager;
|
||||
import org.eclipse.cdt.make.internal.core.makefile.gnu.GNUMakefile;
|
||||
import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefile;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathManager;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigInfoFactory;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
|
||||
|
@ -56,7 +60,11 @@ public class MakeCorePlugin extends Plugin {
|
|||
|
||||
public static final String GCC_SPECS_CONSOLE_PARSER_ID = MakeCorePlugin.getUniqueIdentifier() + ".GCCSpecsConsoleParser"; //$NON-NLS-1$
|
||||
public static final String GCC_SCANNER_INFO_CONSOLE_PARSER_ID = MakeCorePlugin.getUniqueIdentifier() + ".GCCScannerInfoConsoleParser"; //$NON-NLS-1$
|
||||
|
||||
|
||||
public static final String MAKEFILE_STYLE = PLUGIN_ID + "editor_makefile_style"; //$NON-NLS-1$
|
||||
public static final String MAKEFILE_DIRS = PLUGIN_ID + "editor_makefile_dirs"; //$NON-NLS-1$
|
||||
|
||||
|
||||
private MakeTargetManager fTargetManager;
|
||||
private DiscoveredPathManager fDiscoveryPathManager;
|
||||
//The shared instance.
|
||||
|
@ -122,22 +130,47 @@ public class MakeCorePlugin extends Plugin {
|
|||
return fTargetManager;
|
||||
}
|
||||
|
||||
public IMakefile createMakefile(IFile file) {
|
||||
GNUMakefile gnu = new GNUMakefile();
|
||||
try {
|
||||
gnu.parse(file.getLocation().toOSString());
|
||||
String[] dirs = gnu.getIncludeDirectories();
|
||||
String[] includes = new String[dirs.length + 1];
|
||||
System.arraycopy(dirs, 0, includes, 0, dirs.length);
|
||||
String cwd = file.getLocation().removeLastSegments(1).toOSString();
|
||||
includes[dirs.length] = cwd;
|
||||
gnu.setIncludeDirectories(includes);
|
||||
} catch (IOException e) {
|
||||
public boolean isMakefileGNUStyle() {
|
||||
String style = getPluginPreferences().getString(MAKEFILE_STYLE);
|
||||
return (style != null && style.equalsIgnoreCase("GNU")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public String[] getMakefileDirs() {
|
||||
String stringList = getPluginPreferences().getString(MAKEFILE_DIRS);
|
||||
StringTokenizer st = new StringTokenizer(stringList, File.pathSeparator + "\n\r");//$NON-NLS-1$
|
||||
ArrayList v = new ArrayList();
|
||||
while (st.hasMoreElements()) {
|
||||
v.add(st.nextElement());
|
||||
}
|
||||
return gnu;
|
||||
return (String[])v.toArray(new String[v.size()]);
|
||||
}
|
||||
|
||||
public IMakefile createMakefile(IFile file) {
|
||||
//
|
||||
// base on a preference to chose GNU vs Posix
|
||||
//return PosixMakefile(file.getLocation);
|
||||
IMakefile makefile;
|
||||
if (isMakefileGNUStyle()) {
|
||||
GNUMakefile gnu = new GNUMakefile();
|
||||
ArrayList includeList = new ArrayList();
|
||||
includeList.addAll(Arrays.asList(gnu.getIncludeDirectories()));
|
||||
includeList.addAll(Arrays.asList(getMakefileDirs()));
|
||||
includeList.add(file.getLocation().removeLastSegments(1).toOSString());
|
||||
String[] includes = (String[]) includeList.toArray(new String[includeList.size()]);
|
||||
gnu.setIncludeDirectories(includes);
|
||||
try {
|
||||
gnu.parse(file.getLocation().toOSString());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
makefile = gnu;
|
||||
} else {
|
||||
PosixMakefile posix = new PosixMakefile();
|
||||
try {
|
||||
posix.parse(file.getLocation().toOSString());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
makefile = posix;
|
||||
}
|
||||
return makefile;
|
||||
}
|
||||
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
|
|
|
@ -58,6 +58,9 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
|
|||
scInfo.setSIProblemGenerationEnabled(true);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
|
||||
// Store default for makefile
|
||||
MakeCorePlugin.getDefault().getPluginPreferences().setDefault(MakeCorePlugin.MAKEFILE_STYLE, "GNU"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ CommandTargetCreate.description=Create a new make build target for the selected
|
|||
|
||||
PreferenceMakeProject.name=New Make Projects
|
||||
PreferenceMakeTargets.name=Make Targets
|
||||
PreferenceMakeFileEditor.name=Makefile Editor
|
||||
PreferenceMakefileEditor.name=Makefile Editor
|
||||
PreferenceMakefileSettings.name= Settings
|
||||
|
||||
PropertyMakeProject.name= C/C++ Make Project
|
||||
|
||||
|
|
|
@ -284,11 +284,17 @@
|
|||
id="org.eclipse.cdt.make.ui.preferences.MakeTargetsPreferencePage">
|
||||
</page>
|
||||
<page
|
||||
name="%PreferenceMakeFileEditor.name"
|
||||
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>
|
||||
<page
|
||||
name="%PreferenceMakefileSettings.name"
|
||||
category="org.eclipse.cdt.make.ui.preferences.MakeFileEditorPreferencePage"
|
||||
class="org.eclipse.cdt.make.internal.ui.preferences.MakefileSettingsPreferencePage"
|
||||
id="org.eclipse.cdt.make.ui.preferences.MakePreferencePage">
|
||||
</page>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
|
|
|
@ -54,9 +54,8 @@ public class MakefileEditorPreferenceConstants {
|
|||
|
||||
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 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);
|
||||
|
@ -65,6 +64,7 @@ public class MakefileEditorPreferenceConstants {
|
|||
store.setDefault(MakefileEditorPreferenceConstants.EDITOR_FOLDING_MACRODEF, false);
|
||||
store.setDefault(MakefileEditorPreferenceConstants.EDITOR_FOLDING_RULE, true);
|
||||
store.setDefault(MakefileEditorPreferenceConstants.EDITOR_FOLDING_CONDITIONAL, true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,3 +51,7 @@ MakefileEditorPreferencePage.makefile_editor_macro_ref=macro reference
|
|||
MakefileEditorPreferencePage.makefile_editor_function=function
|
||||
MakefileEditorPreferencePage.makefile_editor_keyword=keyword
|
||||
MakefileEditorPreferencePage.makefile_editor_target=target
|
||||
|
||||
MakefileSettingsPreferencePage.style=Style of Makefile
|
||||
MakefileSettingsPreferencePage.path.label=Makefile include directories
|
||||
MakefileSettingsPreferencePage.path.browse=directory
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/**********************************************************************
|
||||
* 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.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.text.PreferencesAdapter;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PathEditor;
|
||||
import org.eclipse.jface.preference.RadioGroupFieldEditor;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
|
||||
/**
|
||||
* MakePreferencePage
|
||||
*/
|
||||
public class MakefileSettingsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
|
||||
|
||||
private static final String POSIX_MAKE_LABEL = "Posix Make"; //$NON-NLS-1$
|
||||
private static final String POSIX_MAKE_VALUE = "POSIX"; //$NON-NLS-1$
|
||||
private static final String GNU_MAKE_LABEL = "GNU Make"; //$NON-NLS-1$
|
||||
private static final String GNU_MAKE_VALUE = "GNU"; //$NON-NLS-1$
|
||||
|
||||
public MakefileSettingsPreferencePage() {
|
||||
super(GRID);
|
||||
IPreferenceStore store = new PreferencesAdapter(MakeCorePlugin.getDefault().getPluginPreferences());
|
||||
setPreferenceStore(store);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FieldEditorPreferencePage#createControl(Composite)
|
||||
*/
|
||||
protected void createFieldEditors() {
|
||||
Composite parent = getFieldEditorParent();
|
||||
|
||||
String[][] personalities = {{POSIX_MAKE_LABEL, POSIX_MAKE_VALUE}, {GNU_MAKE_LABEL, GNU_MAKE_VALUE}};
|
||||
RadioGroupFieldEditor combo = new RadioGroupFieldEditor(MakeCorePlugin.MAKEFILE_STYLE,
|
||||
MakefilePreferencesMessages.getString("MakefileSettingsPreferencePage.style"),//$NON-NLS-1$
|
||||
2,
|
||||
personalities,
|
||||
getFieldEditorParent());
|
||||
addField(combo);
|
||||
|
||||
PathEditor pathEditor = new PathEditor(MakeCorePlugin.MAKEFILE_DIRS,
|
||||
MakefilePreferencesMessages.getString("MakefileSettingsPreferencePage.path.label"), //$NON-NLS-1$
|
||||
MakefilePreferencesMessages.getString("MakefileSettingsPreferencePage.path.browse"),//$NON-NLS-1$
|
||||
getFieldEditorParent());
|
||||
addField(pathEditor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the default values of this page in the preference bundle.
|
||||
*/
|
||||
public static void initDefaults(IPreferenceStore prefs) {
|
||||
}
|
||||
|
||||
public void init(IWorkbench workbench) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,308 @@
|
|||
/**********************************************************************
|
||||
* 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;
|
||||
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.ListenerList;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
|
||||
/**
|
||||
* Adapts {@link org.eclipse.core.runtime.Preferences} to
|
||||
* {@link org.eclipse.jface.preference.IPreferenceStore}
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public class PreferencesAdapter implements IPreferenceStore {
|
||||
|
||||
/**
|
||||
* Property change listener. Listens for events of type
|
||||
* {@link org.eclipse.core.runtime.Preferences.PropertyChangeEvent} and fires
|
||||
* a {@link org.eclipse.jface.util.PropertyChangeEvent} on the
|
||||
* adapter with arguments from the received event.
|
||||
*/
|
||||
private class PropertyChangeListener implements Preferences.IPropertyChangeListener {
|
||||
|
||||
/*
|
||||
* @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
|
||||
*/
|
||||
public void propertyChange(Preferences.PropertyChangeEvent event) {
|
||||
firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
|
||||
}
|
||||
}
|
||||
|
||||
/** Listeners on the adapter */
|
||||
private ListenerList fListeners= new ListenerList();
|
||||
|
||||
/** Listener on the adapted Preferences */
|
||||
private PropertyChangeListener fListener= new PropertyChangeListener();
|
||||
|
||||
/** Adapted Preferences */
|
||||
private Preferences fPreferences;
|
||||
|
||||
/** True iff no events should be forwarded */
|
||||
private boolean fSilent;
|
||||
|
||||
/**
|
||||
* Initialize with empty Preferences.
|
||||
*/
|
||||
public PreferencesAdapter() {
|
||||
this(new Preferences());
|
||||
}
|
||||
/**
|
||||
* Initialize with the given Preferences.
|
||||
*
|
||||
* @param preferences The preferences to wrap.
|
||||
*/
|
||||
public PreferencesAdapter(Preferences preferences) {
|
||||
fPreferences= preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void addPropertyChangeListener(IPropertyChangeListener listener) {
|
||||
if (fListeners.size() == 0)
|
||||
fPreferences.addPropertyChangeListener(fListener);
|
||||
fListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void removePropertyChangeListener(IPropertyChangeListener listener) {
|
||||
fListeners.remove(listener);
|
||||
if (fListeners.size() == 0)
|
||||
fPreferences.removePropertyChangeListener(fListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean contains(String name) {
|
||||
return fPreferences.contains(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
|
||||
if (!fSilent) {
|
||||
PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue);
|
||||
Object[] listeners= fListeners.getListeners();
|
||||
for (int i= 0; i < listeners.length; i++)
|
||||
((IPropertyChangeListener) listeners[i]).propertyChange(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean getBoolean(String name) {
|
||||
return fPreferences.getBoolean(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean getDefaultBoolean(String name) {
|
||||
return fPreferences.getDefaultBoolean(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public double getDefaultDouble(String name) {
|
||||
return fPreferences.getDefaultDouble(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public float getDefaultFloat(String name) {
|
||||
return fPreferences.getDefaultFloat(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public int getDefaultInt(String name) {
|
||||
return fPreferences.getDefaultInt(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public long getDefaultLong(String name) {
|
||||
return fPreferences.getDefaultLong(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getDefaultString(String name) {
|
||||
return fPreferences.getDefaultString(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public double getDouble(String name) {
|
||||
return fPreferences.getDouble(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public float getFloat(String name) {
|
||||
return fPreferences.getFloat(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public int getInt(String name) {
|
||||
return fPreferences.getInt(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public long getLong(String name) {
|
||||
return fPreferences.getLong(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getString(String name) {
|
||||
return fPreferences.getString(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean isDefault(String name) {
|
||||
return fPreferences.isDefault(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean needsSaving() {
|
||||
return fPreferences.needsSaving();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void putValue(String name, String value) {
|
||||
try {
|
||||
fSilent= true;
|
||||
fPreferences.setValue(name, value);
|
||||
} finally {
|
||||
fSilent= false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setDefault(String name, double value) {
|
||||
fPreferences.setDefault(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setDefault(String name, float value) {
|
||||
fPreferences.setDefault(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setDefault(String name, int value) {
|
||||
fPreferences.setDefault(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setDefault(String name, long value) {
|
||||
fPreferences.setDefault(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setDefault(String name, String defaultObject) {
|
||||
fPreferences.setDefault(name, defaultObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setDefault(String name, boolean value) {
|
||||
fPreferences.setDefault(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setToDefault(String name) {
|
||||
fPreferences.setToDefault(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setValue(String name, double value) {
|
||||
fPreferences.setValue(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setValue(String name, float value) {
|
||||
fPreferences.setValue(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setValue(String name, int value) {
|
||||
fPreferences.setValue(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setValue(String name, long value) {
|
||||
fPreferences.setValue(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setValue(String name, String value) {
|
||||
fPreferences.setValue(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void setValue(String name, boolean value) {
|
||||
fPreferences.setValue(name, value);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue