mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-09 19:43:27 +02:00
Extracted content type specific code to one common class.
This commit is contained in:
parent
21443abb26
commit
752e150205
4 changed files with 225 additions and 189 deletions
|
@ -6,13 +6,15 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Intel Corporation - Initial API and implementation
|
* Intel Corporation - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.managedbuilder.projectconverter;
|
package org.eclipse.cdt.managedbuilder.projectconverter;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
|
||||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||||
|
@ -27,7 +29,6 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.resources.ProjectScope;
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
import org.eclipse.core.resources.WorkspaceJob;
|
import org.eclipse.core.resources.WorkspaceJob;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
@ -38,14 +39,8 @@ import org.eclipse.core.runtime.content.IContentTypeSettings;
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
import org.eclipse.core.runtime.jobs.MultiRule;
|
import org.eclipse.core.runtime.jobs.MultiRule;
|
||||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||||
import org.osgi.service.prefs.BackingStoreException;
|
|
||||||
import org.osgi.service.prefs.Preferences;
|
|
||||||
|
|
||||||
class UpdateManagedProject21 {
|
class UpdateManagedProject21 {
|
||||||
|
|
||||||
private static final String CONTENT_TYPE_PREF_NODE = "content-types"; //$NON-NLS-1$
|
|
||||||
private static final String FULLPATH_CONTENT_TYPE_PREF_NODE = Platform.PI_RUNTIME + IPath.SEPARATOR + CONTENT_TYPE_PREF_NODE;
|
|
||||||
private static final String PREF_LOCAL_CONTENT_TYPE_SETTINGS = "enabled"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param monitor the monitor to allow users to cancel the long-running operation
|
* @param monitor the monitor to allow users to cancel the long-running operation
|
||||||
|
@ -153,14 +148,8 @@ class UpdateManagedProject21 {
|
||||||
// Unfortunately there is no clear API in Eclipse-3.1 to do this.
|
// Unfortunately there is no clear API in Eclipse-3.1 to do this.
|
||||||
// We should revisit this code when Eclipse-3.1.x and above is out
|
// We should revisit this code when Eclipse-3.1.x and above is out
|
||||||
// with more complete API.
|
// with more complete API.
|
||||||
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
|
|
||||||
// enable project-specific settings for this project
|
// enable project-specific settings for this project
|
||||||
contentTypePrefs.putBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, true);
|
CCorePlugin.setUseProjectSpecificContentTypes(project, true);
|
||||||
try {
|
|
||||||
contentTypePrefs.flush();
|
|
||||||
} catch (BackingStoreException e) {
|
|
||||||
// ignore ??
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now the project setting is on/enable.
|
// Now the project setting is on/enable.
|
||||||
// Add the new association in the project user setting.
|
// Add the new association in the project user setting.
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||||
import org.eclipse.cdt.core.resources.IConsole;
|
import org.eclipse.cdt.core.resources.IConsole;
|
||||||
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
|
import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
|
||||||
import org.eclipse.cdt.core.resources.ScannerProvider;
|
import org.eclipse.cdt.core.resources.ScannerProvider;
|
||||||
|
import org.eclipse.cdt.internal.core.CContentTypes;
|
||||||
import org.eclipse.cdt.internal.core.CDTLogWriter;
|
import org.eclipse.cdt.internal.core.CDTLogWriter;
|
||||||
import org.eclipse.cdt.internal.core.CDescriptorManager;
|
import org.eclipse.cdt.internal.core.CDescriptorManager;
|
||||||
import org.eclipse.cdt.internal.core.PathEntryVariableManager;
|
import org.eclipse.cdt.internal.core.PathEntryVariableManager;
|
||||||
|
@ -47,7 +48,6 @@ import org.eclipse.core.resources.IProjectDescription;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IWorkspace;
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
import org.eclipse.core.resources.IWorkspaceRunnable;
|
import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.resources.ProjectScope;
|
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
|
@ -63,9 +63,6 @@ import org.eclipse.core.runtime.Preferences;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
import org.eclipse.core.runtime.content.IContentType;
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
import org.eclipse.core.runtime.content.IContentTypeMatcher;
|
|
||||||
import org.eclipse.core.runtime.content.IContentTypeSettings;
|
|
||||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
public class CCorePlugin extends Plugin {
|
public class CCorePlugin extends Plugin {
|
||||||
|
@ -878,7 +875,7 @@ public class CCorePlugin extends Plugin {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static IContentType getContentType(String filename) {
|
public static IContentType getContentType(String filename) {
|
||||||
return getContentType(null, filename);
|
return CContentTypes.getContentType(null, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -890,108 +887,24 @@ public class CCorePlugin extends Plugin {
|
||||||
* @return the content type found or <code>null</code>
|
* @return the content type found or <code>null</code>
|
||||||
*/
|
*/
|
||||||
public static IContentType getContentType(IProject project, String filename) {
|
public static IContentType getContentType(IProject project, String filename) {
|
||||||
IContentTypeMatcher matcher= null;
|
return CContentTypes.getContentType(project, filename);
|
||||||
IScopeContext scopeCtx= null;
|
}
|
||||||
boolean preferCpp= true;
|
|
||||||
if (project != null) {
|
/**
|
||||||
// try with the project settings
|
* Tests whether the given project uses its project specific content types.
|
||||||
try {
|
*/
|
||||||
matcher= project.getContentTypeMatcher();
|
public static boolean usesProjectSpecificContentTypes(IProject project) {
|
||||||
scopeCtx= new ProjectScope(project);
|
return CContentTypes.usesProjectSpecificContentTypes(project);
|
||||||
preferCpp= CoreModel.hasCCNature(project);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
// fallback to workspace wide definitions.
|
|
||||||
matcher= Platform.getContentTypeManager();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
matcher= Platform.getContentTypeManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
IContentType[] cts = matcher.findContentTypesFor(filename);
|
|
||||||
switch (cts.length) {
|
|
||||||
case 0:
|
|
||||||
return null;
|
|
||||||
case 1:
|
|
||||||
return cts[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
int maxPossiblePriority= scopeCtx == null ? 11 : 101;
|
|
||||||
int bestPriority= -1;
|
|
||||||
IContentType bestResult= null;
|
|
||||||
|
|
||||||
for (int i = 0; i < cts.length; i++) {
|
|
||||||
IContentType candidate= cts[i];
|
|
||||||
int priority= 0;
|
|
||||||
try {
|
|
||||||
if (scopeCtx != null) {
|
|
||||||
IContentTypeSettings settings= candidate.getSettings(scopeCtx);
|
|
||||||
if (isStrictlyAssociatedWith(settings, filename)) {
|
|
||||||
priority= 100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (priority == 0 && bestPriority < 100) {
|
|
||||||
if (isStrictlyAssociatedWith(candidate, filename)) {
|
|
||||||
priority= 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isPreferredContentType(candidate, preferCpp)) {
|
|
||||||
priority+= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (CoreException e) {
|
|
||||||
// skip it
|
|
||||||
}
|
|
||||||
if (priority > bestPriority) {
|
|
||||||
if (priority == maxPossiblePriority) {
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
bestPriority= priority;
|
|
||||||
bestResult= candidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isPreferredContentType(IContentType candidate, boolean preferCpp) {
|
/**
|
||||||
while (candidate != null) {
|
* Enables or disables the project specific content types.
|
||||||
String id= candidate.getId();
|
*/
|
||||||
boolean isCpp= CONTENT_TYPE_CXXHEADER.equals(id) || CONTENT_TYPE_CXXSOURCE.equals(id);
|
public static void setUseProjectSpecificContentTypes(IProject project, boolean val) {
|
||||||
if (isCpp) {
|
CContentTypes.setUseProjectSpecificContentTypes(project, val);
|
||||||
return preferCpp;
|
|
||||||
}
|
|
||||||
boolean isC= CONTENT_TYPE_CHEADER.equals(id) || CONTENT_TYPE_CSOURCE.equals(id);
|
|
||||||
if (isC) {
|
|
||||||
return !preferCpp;
|
|
||||||
}
|
|
||||||
candidate= candidate.getBaseType();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isStrictlyAssociatedWith(IContentTypeSettings settings, String filename) {
|
|
||||||
String[] namespecs= settings.getFileSpecs(IContentType.FILE_NAME_SPEC);
|
|
||||||
for (int i = 0; i < namespecs.length; i++) {
|
|
||||||
String name = namespecs[i];
|
|
||||||
if (name.equals(filename)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check the file extensions only
|
|
||||||
int dotPosition = filename.lastIndexOf('.');
|
|
||||||
if (dotPosition >= 0 && dotPosition < filename.length()-1) {
|
|
||||||
String fileExtension= filename.substring(dotPosition + 1);
|
|
||||||
String[] extensions= settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
|
|
||||||
for (int i = 0; i < extensions.length; i++) {
|
|
||||||
String ext = extensions[i];
|
|
||||||
if (ext.equals(fileExtension)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$
|
private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$
|
||||||
private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$
|
private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$
|
||||||
|
@ -1034,5 +947,4 @@ public class CCorePlugin extends Plugin {
|
||||||
return CDOM.getInstance();
|
return CDOM.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,191 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
|
import org.eclipse.core.runtime.content.IContentTypeMatcher;
|
||||||
|
import org.eclipse.core.runtime.content.IContentTypeSettings;
|
||||||
|
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||||
|
import org.osgi.service.prefs.BackingStoreException;
|
||||||
|
import org.osgi.service.prefs.Preferences;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the access to the content types of the platform.
|
||||||
|
* @author markus.schorn@windriver.com
|
||||||
|
*/
|
||||||
|
public class CContentTypes {
|
||||||
|
private static final String PREF_LOCAL_CONTENT_TYPE_SETTINGS = "enabled"; //$NON-NLS-1$
|
||||||
|
private static final Preferences PROJECT_SCOPE = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
|
||||||
|
private static final String CONTENT_TYPE_PREF_NODE = "content-types"; //$NON-NLS-1$
|
||||||
|
private static final String FULLPATH_CONTENT_TYPE_PREF_NODE = Platform.PI_RUNTIME + IPath.SEPARATOR + CONTENT_TYPE_PREF_NODE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation for {@link CCorePlugin#getContentType(IProject, String)}.
|
||||||
|
*/
|
||||||
|
public static IContentType getContentType(IProject project, String filename) {
|
||||||
|
IContentTypeMatcher matcher= null;
|
||||||
|
IScopeContext scopeCtx= null;
|
||||||
|
boolean preferCpp= true;
|
||||||
|
if (project != null) {
|
||||||
|
// try with the project settings
|
||||||
|
try {
|
||||||
|
matcher= project.getContentTypeMatcher();
|
||||||
|
if (usesProjectSpecificContentTypes(project)) {
|
||||||
|
scopeCtx= new ProjectScope(project);
|
||||||
|
}
|
||||||
|
preferCpp= CoreModel.hasCCNature(project);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
// fallback to workspace wide definitions.
|
||||||
|
matcher= Platform.getContentTypeManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
matcher= Platform.getContentTypeManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
IContentType[] cts = matcher.findContentTypesFor(filename);
|
||||||
|
switch (cts.length) {
|
||||||
|
case 0:
|
||||||
|
return null;
|
||||||
|
case 1:
|
||||||
|
return cts[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int maxPossiblePriority= scopeCtx == null ? 11 : 101;
|
||||||
|
int bestPriority= -1;
|
||||||
|
IContentType bestResult= null;
|
||||||
|
|
||||||
|
for (int i = 0; i < cts.length; i++) {
|
||||||
|
IContentType candidate= cts[i];
|
||||||
|
int priority= 0;
|
||||||
|
try {
|
||||||
|
if (scopeCtx != null) {
|
||||||
|
IContentTypeSettings settings= candidate.getSettings(scopeCtx);
|
||||||
|
if (isStrictlyAssociatedWith(settings, filename)) {
|
||||||
|
priority= 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (priority == 0 && bestPriority < 100) {
|
||||||
|
if (isStrictlyAssociatedWith(candidate, filename)) {
|
||||||
|
priority= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isPreferredContentType(candidate, preferCpp)) {
|
||||||
|
priority+= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (CoreException e) {
|
||||||
|
// skip it
|
||||||
|
}
|
||||||
|
if (priority > bestPriority) {
|
||||||
|
if (priority == maxPossiblePriority) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
bestPriority= priority;
|
||||||
|
bestResult= candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isPreferredContentType(IContentType candidate, boolean preferCpp) {
|
||||||
|
while (candidate != null) {
|
||||||
|
String id= candidate.getId();
|
||||||
|
if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id) ||
|
||||||
|
CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
|
||||||
|
return preferCpp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id) ||
|
||||||
|
CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
|
||||||
|
return !preferCpp;
|
||||||
|
}
|
||||||
|
candidate= candidate.getBaseType();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isStrictlyAssociatedWith(IContentTypeSettings settings, String filename) {
|
||||||
|
String[] namespecs= settings.getFileSpecs(IContentType.FILE_NAME_SPEC);
|
||||||
|
for (int i = 0; i < namespecs.length; i++) {
|
||||||
|
String name = namespecs[i];
|
||||||
|
if (name.equals(filename)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check the file extensions only
|
||||||
|
int dotPosition = filename.lastIndexOf('.');
|
||||||
|
if (dotPosition >= 0 && dotPosition < filename.length()-1) {
|
||||||
|
String fileExtension= filename.substring(dotPosition + 1);
|
||||||
|
String[] extensions= settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
|
||||||
|
for (int i = 0; i < extensions.length; i++) {
|
||||||
|
String ext = extensions[i];
|
||||||
|
if (ext.equals(fileExtension)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is copied from the resources plugin and figures out whether
|
||||||
|
* project specific settings are enabled or not.
|
||||||
|
* Implementation for {@link CCorePlugin#usesProjectSpecificContentTypes(IProject)}.
|
||||||
|
*/
|
||||||
|
public static boolean usesProjectSpecificContentTypes(IProject project) {
|
||||||
|
String projectName= project.getName();
|
||||||
|
try {
|
||||||
|
// be careful looking up for our node so not to create any nodes as side effect
|
||||||
|
Preferences node = PROJECT_SCOPE;
|
||||||
|
//TODO once bug 90500 is fixed, should be simpler
|
||||||
|
// for now, take the long way
|
||||||
|
if (!node.nodeExists(projectName))
|
||||||
|
return false;
|
||||||
|
node = node.node(projectName);
|
||||||
|
if (!node.nodeExists(Platform.PI_RUNTIME))
|
||||||
|
return false;
|
||||||
|
node = node.node(Platform.PI_RUNTIME);
|
||||||
|
if (!node.nodeExists(CONTENT_TYPE_PREF_NODE))
|
||||||
|
return false;
|
||||||
|
node = node.node(CONTENT_TYPE_PREF_NODE);
|
||||||
|
return node.getBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, false);
|
||||||
|
} catch (BackingStoreException e) {
|
||||||
|
// exception treated when retrieving the project preferences
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation for {@link CCorePlugin#setUseProjectSpecificContentTypes(IProject, boolean)}.
|
||||||
|
*/
|
||||||
|
public static void setUseProjectSpecificContentTypes(IProject project, boolean val) {
|
||||||
|
ProjectScope projectScope = new ProjectScope(project);
|
||||||
|
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
|
||||||
|
if (usesProjectSpecificContentTypes(project) != val) {
|
||||||
|
// enable project-specific settings for this project
|
||||||
|
contentTypePrefs.putBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, val);
|
||||||
|
try {
|
||||||
|
contentTypePrefs.flush();
|
||||||
|
} catch (BackingStoreException e) {
|
||||||
|
// ignore ??
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,20 +7,17 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* TimeSys Corporation - Initial implementation
|
* TimeSys Corporation - Initial implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.preferences;
|
package org.eclipse.cdt.internal.ui.preferences;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
|
||||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.ProjectScope;
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.content.IContentType;
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
import org.eclipse.core.runtime.content.IContentTypeManager;
|
import org.eclipse.core.runtime.content.IContentTypeManager;
|
||||||
|
@ -36,8 +33,13 @@ import org.eclipse.swt.widgets.Event;
|
||||||
import org.eclipse.swt.widgets.Listener;
|
import org.eclipse.swt.widgets.Listener;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.dialogs.PropertyPage;
|
import org.eclipse.ui.dialogs.PropertyPage;
|
||||||
import org.osgi.service.prefs.BackingStoreException;
|
|
||||||
import org.osgi.service.prefs.Preferences;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The preference page used for displaying/editing CDT file
|
* The preference page used for displaying/editing CDT file
|
||||||
|
@ -93,16 +95,6 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String CONTENT_TYPE_PREF_NODE = "content-types"; //$NON-NLS-1$
|
|
||||||
private static final String FULLPATH_CONTENT_TYPE_PREF_NODE = Platform.PI_RUNTIME + IPath.SEPARATOR + CONTENT_TYPE_PREF_NODE;
|
|
||||||
private static final String PREF_LOCAL_CONTENT_TYPE_SETTINGS = "enabled"; //$NON-NLS-1$
|
|
||||||
// private final static String PREF_FILE_EXTENSIONS = "file-extensions"; //$NON-NLS-1$
|
|
||||||
// private final static String PREF_FILE_NAMES = "file-names"; //$NON-NLS-1$
|
|
||||||
// private final static String PREF_SEPARATOR = ","; //$NON-NLS-1$
|
|
||||||
private static final Preferences PROJECT_SCOPE = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
|
|
||||||
//private static final InstanceScope INSTANCE_SCOPE = new InstanceScope();
|
|
||||||
|
|
||||||
|
|
||||||
protected Button fUseWorkspace;
|
protected Button fUseWorkspace;
|
||||||
protected Button fUseProject;
|
protected Button fUseProject;
|
||||||
protected FixCFileTypesPreferenceBlock fPrefsBlock;
|
protected FixCFileTypesPreferenceBlock fPrefsBlock;
|
||||||
|
@ -140,7 +132,7 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
});
|
});
|
||||||
|
|
||||||
final IProject project = getProject();
|
final IProject project = getProject();
|
||||||
boolean custom = isProjectSpecificContentType(project.getName());
|
boolean custom = CCorePlugin.usesProjectSpecificContentTypes(project);
|
||||||
|
|
||||||
fUseProject = new Button(radioPane, SWT.RADIO);
|
fUseProject = new Button(radioPane, SWT.RADIO);
|
||||||
fUseProject.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useProjectSettings")); //$NON-NLS-1$
|
fUseProject.setText(PreferencesMessages.getString("CFileTypesPropertyPage.useProjectSettings")); //$NON-NLS-1$
|
||||||
|
@ -189,37 +181,11 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||||
*/
|
*/
|
||||||
public boolean performOk() {
|
public boolean performOk() {
|
||||||
|
boolean useProjectContentTypes= fUseProject.getSelection();
|
||||||
if (fUseProject.getSelection()) {
|
IProject project = getProject();
|
||||||
IProject project = getProject();
|
if (CCorePlugin.usesProjectSpecificContentTypes(project) != useProjectContentTypes) {
|
||||||
ProjectScope projectScope = new ProjectScope(project);
|
CCorePlugin.setUseProjectSpecificContentTypes(project, useProjectContentTypes);
|
||||||
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
|
computeEvents(project);
|
||||||
if (! isProjectSpecificContentType(project.getName())) {
|
|
||||||
// enable project-specific settings for this project
|
|
||||||
contentTypePrefs.putBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, true);
|
|
||||||
try {
|
|
||||||
contentTypePrefs.flush();
|
|
||||||
} catch (BackingStoreException e) {
|
|
||||||
// ignore ??
|
|
||||||
}
|
|
||||||
computeEvents(project);
|
|
||||||
}
|
|
||||||
fPrefsBlock.performOk();
|
|
||||||
} else if (fUseWorkspace.getSelection()) {
|
|
||||||
IProject project = getProject();
|
|
||||||
if (isProjectSpecificContentType(project.getName())) {
|
|
||||||
ProjectScope projectScope = new ProjectScope(project);
|
|
||||||
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
|
|
||||||
// disable project-specific settings for this project
|
|
||||||
contentTypePrefs.putBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, false);
|
|
||||||
computeEvents(project);
|
|
||||||
try {
|
|
||||||
contentTypePrefs.flush();
|
|
||||||
} catch (BackingStoreException e) {
|
|
||||||
// ignore ??
|
|
||||||
}
|
|
||||||
computeEvents(project);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return super.performOk();
|
return super.performOk();
|
||||||
}
|
}
|
||||||
|
@ -236,28 +202,6 @@ public class CFileTypesPropertyPage extends PropertyPage {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isProjectSpecificContentType(String projectName) {
|
|
||||||
try {
|
|
||||||
// be careful looking up for our node so not to create any nodes as side effect
|
|
||||||
Preferences node = PROJECT_SCOPE;
|
|
||||||
//TODO once bug 90500 is fixed, should be simpler
|
|
||||||
// for now, take the long way
|
|
||||||
if (!node.nodeExists(projectName))
|
|
||||||
return false;
|
|
||||||
node = node.node(projectName);
|
|
||||||
if (!node.nodeExists(Platform.PI_RUNTIME))
|
|
||||||
return false;
|
|
||||||
node = node.node(Platform.PI_RUNTIME);
|
|
||||||
if (!node.nodeExists(CONTENT_TYPE_PREF_NODE))
|
|
||||||
return false;
|
|
||||||
node = node.node(CONTENT_TYPE_PREF_NODE);
|
|
||||||
return node.getBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, false);
|
|
||||||
} catch (BackingStoreException e) {
|
|
||||||
// exception treated when retrieving the project preferences
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IContentType[] getRegistedContentTypes() {
|
public IContentType[] getRegistedContentTypes() {
|
||||||
String [] ids = CoreModel.getRegistedContentTypeIds();
|
String [] ids = CoreModel.getRegistedContentTypeIds();
|
||||||
IContentTypeManager manager = Platform.getContentTypeManager();
|
IContentTypeManager manager = Platform.getContentTypeManager();
|
||||||
|
|
Loading…
Add table
Reference in a new issue