1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Bug 311880 - Add preference to keep position of excluded files in Project Explorer

Patch by Alex Freidin
This commit is contained in:
Anton Leherbauer 2011-02-25 08:25:25 +00:00
parent 624470f48b
commit 0463fa2968
5 changed files with 59 additions and 21 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others. * Copyright (c) 2000, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -54,6 +54,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
private SelectionButtonDialogField fOutlineGroupMembers; private SelectionButtonDialogField fOutlineGroupMembers;
private SelectionButtonDialogField fOutlineGroupMacros; private SelectionButtonDialogField fOutlineGroupMacros;
private SelectionButtonDialogField fShowSourceRootsAtTopOfProject; private SelectionButtonDialogField fShowSourceRootsAtTopOfProject;
private SelectionButtonDialogField fCViewSortOrderOfExcludedFiles;
public AppearancePreferencePage() { public AppearancePreferencePage() {
@ -101,6 +102,10 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fCViewGroupMacros= new SelectionButtonDialogField(SWT.CHECK); fCViewGroupMacros= new SelectionButtonDialogField(SWT.CHECK);
fCViewGroupMacros.setDialogFieldListener(listener); fCViewGroupMacros.setDialogFieldListener(listener);
fCViewGroupMacros.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupMacros_label); fCViewGroupMacros.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupMacros_label);
fCViewSortOrderOfExcludedFiles= new SelectionButtonDialogField(SWT.CHECK);
fCViewSortOrderOfExcludedFiles.setDialogFieldListener(listener);
fCViewSortOrderOfExcludedFiles.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label);
} }
private void initFields() { private void initFields() {
@ -115,6 +120,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fOutlineGroupMacros.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS)); fOutlineGroupMacros.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS));
boolean showSourceRootsAtTopOfProject = CCorePlugin.showSourceRootsAtTopOfProject(); boolean showSourceRootsAtTopOfProject = CCorePlugin.showSourceRootsAtTopOfProject();
fShowSourceRootsAtTopOfProject.setSelection(showSourceRootsAtTopOfProject); fShowSourceRootsAtTopOfProject.setSelection(showSourceRootsAtTopOfProject);
fCViewSortOrderOfExcludedFiles.setSelection(prefs.getBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES));
} }
/* /*
@ -152,6 +158,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
new Separator().doFillIntoGrid(result, nColumns); new Separator().doFillIntoGrid(result, nColumns);
fCViewSeparateHeaderAndSource.doFillIntoGrid(result, nColumns); fCViewSeparateHeaderAndSource.doFillIntoGrid(result, nColumns);
fCViewSortOrderOfExcludedFiles.doFillIntoGrid(result, nColumns);
String noteTitle= PreferencesMessages.AppearancePreferencePage_note; String noteTitle= PreferencesMessages.AppearancePreferencePage_note;
String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyForNewViews; String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyForNewViews;
@ -203,9 +210,10 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected()); prefs.setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected());
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, fOutlineGroupMembers.isSelected()); prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MEMBERS, fOutlineGroupMembers.isSelected());
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MACROS, fOutlineGroupMacros.isSelected()); prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MACROS, fOutlineGroupMacros.isSelected());
prefs.setValue(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES, fCViewSortOrderOfExcludedFiles.isSelected());
try { try {
new InstanceScope().getNode(CUIPlugin.PLUGIN_ID).flush(); InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID).flush();
IEclipsePreferences corePluginNode = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID); IEclipsePreferences corePluginNode = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
corePluginNode.putBoolean( corePluginNode.putBoolean(
CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT,
fShowSourceRootsAtTopOfProject.isSelected()); fShowSourceRootsAtTopOfProject.isSelected());
@ -230,8 +238,9 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES)); fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
fOutlineGroupMembers.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS)); fOutlineGroupMembers.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS));
fOutlineGroupMacros.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS)); fOutlineGroupMacros.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS));
boolean showSourceRootsPref = new DefaultScope().getNode(CCorePlugin.PLUGIN_ID).getBoolean(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, true); boolean showSourceRootsPref = DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).getBoolean(CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT, true);
fShowSourceRootsAtTopOfProject.setSelection(showSourceRootsPref); fShowSourceRootsAtTopOfProject.setSelection(showSourceRootsPref);
fCViewSortOrderOfExcludedFiles.setSelection(prefs.getDefaultBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES));
super.performDefaults(); super.performDefaults();
} }
} }

View file

@ -140,6 +140,7 @@ public final class PreferencesMessages extends NLS {
public static String AppearancePreferencePage_showTUChildren_label; public static String AppearancePreferencePage_showTUChildren_label;
public static String AppearancePreferencePage_cviewGroupIncludes_label; public static String AppearancePreferencePage_cviewGroupIncludes_label;
public static String AppearancePreferencePage_cviewSeparateHeaderAndSource_label; public static String AppearancePreferencePage_cviewSeparateHeaderAndSource_label;
public static String AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label;
public static String AppearancePreferencePage_cviewGroupMacros_label; public static String AppearancePreferencePage_cviewGroupMacros_label;
public static String AppearancePreferencePage_outlineGroupIncludes_label; public static String AppearancePreferencePage_outlineGroupIncludes_label;
public static String AppearancePreferencePage_outlineGroupMethods_label; public static String AppearancePreferencePage_outlineGroupMethods_label;

View file

@ -159,13 +159,14 @@ AppearancePreferencePage_description= Appearance of C/C++ elements in viewers:
#AppearancePreferencePage.methodreturntype.label= Show &method return types #AppearancePreferencePage.methodreturntype.label= Show &method return types
AppearancePreferencePage_showTUChildren_label= Show translation unit members AppearancePreferencePage_showTUChildren_label= Show translation unit members
AppearancePreferencePage_cviewGroupIncludes_label= Group include directives in Project Explorer and C/C++ Projects view AppearancePreferencePage_cviewGroupIncludes_label= Group include directives in Project Explorer and C/C++ Projects view
AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label=Keep sort order of excluded sources in Project Explorer and C/C++ Projects view
AppearancePreferencePage_cviewSeparateHeaderAndSource_label= Sort header files before source files in Project Explorer and C/C++ Projects view AppearancePreferencePage_cviewSeparateHeaderAndSource_label= Sort header files before source files in Project Explorer and C/C++ Projects view
AppearancePreferencePage_cviewGroupMacros_label= Group macro definitions in Project Explorer and C/C++ Projects view AppearancePreferencePage_cviewGroupMacros_label= Group macro definitions in Project Explorer and C/C++ Projects view
AppearancePreferencePage_outlineGroupIncludes_label= Group include directives in the Outline view AppearancePreferencePage_outlineGroupIncludes_label= Group include directives in the Outline view
AppearancePreferencePage_outlineGroupMethods_label=Group method definitions in the Outline view AppearancePreferencePage_outlineGroupMethods_label=Group method definitions in the Outline view
AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view
AppearancePreferencePage_note=Note: AppearancePreferencePage_note=Note:
AppearancePreferencePage_preferenceOnlyForNewViews=This preference does not affect open views AppearancePreferencePage_preferenceOnlyForNewViews=These two preferences do not affect open views
AppearancePreferencePage_outlineGroupMacros_label=Group macro definitions in the Outline view AppearancePreferencePage_outlineGroupMacros_label=Group macro definitions in the Outline view
AppearancePreferencePage_showSourceRootsAtTopOfProject_label=Show source roots at top of project AppearancePreferencePage_showSourceRootsAtTopOfProject_label=Show source roots at top of project

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others. * Copyright (c) 2005, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -15,6 +15,7 @@ package org.eclipse.cdt.ui;
import java.util.Comparator; import java.util.Comparator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage; import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
@ -125,12 +126,15 @@ public class CElementSorter extends ViewerSorter {
*/ */
private boolean fSeparateHeaderAndSource; private boolean fSeparateHeaderAndSource;
private boolean fKeepSortOrderOfExcludedFiles;
/** /**
* Default constructor for use as executable extension. * Default constructor for use as executable extension.
*/ */
public CElementSorter() { public CElementSorter() {
final IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore(); final IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
fSeparateHeaderAndSource= store.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE); fSeparateHeaderAndSource= store.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE);
fKeepSortOrderOfExcludedFiles= store.getBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES);
} }
@Override @Override
@ -159,15 +163,7 @@ public class CElementSorter extends ViewerSorter {
} }
return CCONTAINERS; return CCONTAINERS;
case ICElement.C_UNIT: case ICElement.C_UNIT:
if (fSeparateHeaderAndSource) { return getTranslationUnitCategory(cElement.getCProject().getProject(), cElement.getElementName());
if (CoreModel.isValidHeaderUnitName(cElement.getCProject().getProject(), cElement.getElementName())) {
return TRANSLATIONUNIT_HEADERS;
}
if (CoreModel.isValidSourceUnitName(cElement.getCProject().getProject(), cElement.getElementName())) {
return TRANSLATIONUNIT_SOURCE;
}
}
return TRANSLATIONUNITS;
case ICElement.C_INCLUDE: case ICElement.C_INCLUDE:
return INCLUDES; return INCLUDES;
case ICElement.C_MACRO: case ICElement.C_MACRO:
@ -219,7 +215,11 @@ public class CElementSorter extends ViewerSorter {
return PROJECTS; return PROJECTS;
case IResource.FOLDER: case IResource.FOLDER:
return RESOURCEFOLDERS; return RESOURCEFOLDERS;
default: default: // translation unit that was excluded from the build
if(fKeepSortOrderOfExcludedFiles &&
CoreModel.isValidTranslationUnitName(resource.getProject(), resource.getName())) {
return getTranslationUnitCategory(resource.getProject(), resource.getName());
}
return RESOURCES; return RESOURCES;
} }
} else if (element instanceof IStorage) { } else if (element instanceof IStorage) {
@ -255,6 +255,18 @@ public class CElementSorter extends ViewerSorter {
return NORMAL; return NORMAL;
} }
private int getTranslationUnitCategory(IProject project, String name) {
if (fSeparateHeaderAndSource) {
if (CoreModel.isValidHeaderUnitName(project, name)) {
return TRANSLATIONUNIT_HEADERS;
}
if (CoreModel.isValidSourceUnitName(project, name)) {
return TRANSLATIONUNIT_SOURCE;
}
}
return TRANSLATIONUNITS;
}
@Override @Override
public int compare(Viewer viewer, Object e1, Object e2) { public int compare(Viewer viewer, Object e1, Object e2) {
int cat1 = category(e1); int cat1 = category(e1);
@ -314,6 +326,8 @@ public class CElementSorter extends ViewerSorter {
if (name1.length() > 0 && name1.charAt(0) == '~') { if (name1.length() > 0 && name1.charAt(0) == '~') {
name1 = name1.substring(1); name1 = name1.substring(1);
} }
} else if (e1 instanceof IResource) {
name1 = ((IResource)e1).getName();
} else { } else {
name1 = e1.toString(); name1 = e1.toString();
} }
@ -327,6 +341,8 @@ public class CElementSorter extends ViewerSorter {
if (name2.length() > 0 && name2.charAt(0) == '~') { if (name2.length() > 0 && name2.charAt(0) == '~') {
name2 = name2.substring(1); name2 = name2.substring(1);
} }
} else if(e2 instanceof IResource) {
name2 = ((IResource)e2).getName();
} else { } else {
name2 = e2.toString(); name2 = e2.toString();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others. * Copyright (c) 2005, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -804,6 +804,17 @@ public class PreferenceConstants {
*/ */
public static final String CVIEW_SEPARATE_HEADER_AND_SOURCE= "org.eclipse.cdt.ui.cview.separateheaderandsource"; //$NON-NLS-1$ public static final String CVIEW_SEPARATE_HEADER_AND_SOURCE= "org.eclipse.cdt.ui.cview.separateheaderandsource"; //$NON-NLS-1$
/**
* A named preference that controls whether the sorting order of source files should be changed
* in the C/C++ Projects view and the Project Explorer view when they are excluded from build.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 5.3
*/
public static final String SORT_ORDER_OF_EXCLUDED_FILES= "org.eclipse.cdt.ui.cview.sortorderofexcludedfiles"; //$NON-NLS-1$
/** /**
* A named preference that controls which completion proposal categories * A named preference that controls which completion proposal categories
* have been excluded from the default proposal list. * have been excluded from the default proposal list.
@ -1707,12 +1718,12 @@ public class PreferenceConstants {
return node; return node;
} }
} }
node = new InstanceScope().getNode(CUIPlugin.PLUGIN_ID); node = InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID);
if (node.get(key, null) != null) { if (node.get(key, null) != null) {
return node; return node;
} }
return new DefaultScope().getNode(CUIPlugin.PLUGIN_ID); return DefaultScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID);
} }
/** /**