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:
parent
624470f48b
commit
0463fa2968
5 changed files with 59 additions and 21 deletions
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -54,6 +54,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
private SelectionButtonDialogField fOutlineGroupMembers;
|
||||
private SelectionButtonDialogField fOutlineGroupMacros;
|
||||
private SelectionButtonDialogField fShowSourceRootsAtTopOfProject;
|
||||
private SelectionButtonDialogField fCViewSortOrderOfExcludedFiles;
|
||||
|
||||
|
||||
public AppearancePreferencePage() {
|
||||
|
@ -101,6 +102,10 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
fCViewGroupMacros= new SelectionButtonDialogField(SWT.CHECK);
|
||||
fCViewGroupMacros.setDialogFieldListener(listener);
|
||||
fCViewGroupMacros.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupMacros_label);
|
||||
|
||||
fCViewSortOrderOfExcludedFiles= new SelectionButtonDialogField(SWT.CHECK);
|
||||
fCViewSortOrderOfExcludedFiles.setDialogFieldListener(listener);
|
||||
fCViewSortOrderOfExcludedFiles.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label);
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
|
@ -115,6 +120,7 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
fOutlineGroupMacros.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS));
|
||||
boolean showSourceRootsAtTopOfProject = CCorePlugin.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);
|
||||
|
||||
fCViewSeparateHeaderAndSource.doFillIntoGrid(result, nColumns);
|
||||
fCViewSortOrderOfExcludedFiles.doFillIntoGrid(result, nColumns);
|
||||
|
||||
String noteTitle= PreferencesMessages.AppearancePreferencePage_note;
|
||||
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_MEMBERS, fOutlineGroupMembers.isSelected());
|
||||
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_MACROS, fOutlineGroupMacros.isSelected());
|
||||
prefs.setValue(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES, fCViewSortOrderOfExcludedFiles.isSelected());
|
||||
try {
|
||||
new InstanceScope().getNode(CUIPlugin.PLUGIN_ID).flush();
|
||||
IEclipsePreferences corePluginNode = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID);
|
||||
InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID).flush();
|
||||
IEclipsePreferences corePluginNode = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
|
||||
corePluginNode.putBoolean(
|
||||
CCorePreferenceConstants.SHOW_SOURCE_ROOTS_AT_TOP_LEVEL_OF_PROJECT,
|
||||
fShowSourceRootsAtTopOfProject.isSelected());
|
||||
|
@ -230,8 +238,9 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
|
|||
fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
|
||||
fOutlineGroupMembers.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS));
|
||||
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);
|
||||
fCViewSortOrderOfExcludedFiles.setSelection(prefs.getDefaultBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES));
|
||||
super.performDefaults();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,6 +140,7 @@ public final class PreferencesMessages extends NLS {
|
|||
public static String AppearancePreferencePage_showTUChildren_label;
|
||||
public static String AppearancePreferencePage_cviewGroupIncludes_label;
|
||||
public static String AppearancePreferencePage_cviewSeparateHeaderAndSource_label;
|
||||
public static String AppearancePreferencePage_cviewKeepSortOrderOfExcludedFiles_label;
|
||||
public static String AppearancePreferencePage_cviewGroupMacros_label;
|
||||
public static String AppearancePreferencePage_outlineGroupIncludes_label;
|
||||
public static String AppearancePreferencePage_outlineGroupMethods_label;
|
||||
|
|
|
@ -159,13 +159,14 @@ AppearancePreferencePage_description= Appearance of C/C++ elements in viewers:
|
|||
#AppearancePreferencePage.methodreturntype.label= Show &method return types
|
||||
AppearancePreferencePage_showTUChildren_label= Show translation unit members
|
||||
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_cviewGroupMacros_label= Group macro definitions in Project Explorer and C/C++ Projects view
|
||||
AppearancePreferencePage_outlineGroupIncludes_label= Group include directives in the Outline view
|
||||
AppearancePreferencePage_outlineGroupMethods_label=Group method definitions in the Outline view
|
||||
AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view
|
||||
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_showSourceRootsAtTopOfProject_label=Show source roots at top of project
|
||||
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.ui;
|
|||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
@ -125,12 +126,15 @@ public class CElementSorter extends ViewerSorter {
|
|||
*/
|
||||
private boolean fSeparateHeaderAndSource;
|
||||
|
||||
private boolean fKeepSortOrderOfExcludedFiles;
|
||||
|
||||
/**
|
||||
* Default constructor for use as executable extension.
|
||||
*/
|
||||
public CElementSorter() {
|
||||
final IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
|
||||
fSeparateHeaderAndSource= store.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE);
|
||||
fKeepSortOrderOfExcludedFiles= store.getBoolean(PreferenceConstants.SORT_ORDER_OF_EXCLUDED_FILES);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -159,15 +163,7 @@ public class CElementSorter extends ViewerSorter {
|
|||
}
|
||||
return CCONTAINERS;
|
||||
case ICElement.C_UNIT:
|
||||
if (fSeparateHeaderAndSource) {
|
||||
if (CoreModel.isValidHeaderUnitName(cElement.getCProject().getProject(), cElement.getElementName())) {
|
||||
return TRANSLATIONUNIT_HEADERS;
|
||||
}
|
||||
if (CoreModel.isValidSourceUnitName(cElement.getCProject().getProject(), cElement.getElementName())) {
|
||||
return TRANSLATIONUNIT_SOURCE;
|
||||
}
|
||||
}
|
||||
return TRANSLATIONUNITS;
|
||||
return getTranslationUnitCategory(cElement.getCProject().getProject(), cElement.getElementName());
|
||||
case ICElement.C_INCLUDE:
|
||||
return INCLUDES;
|
||||
case ICElement.C_MACRO:
|
||||
|
@ -219,7 +215,11 @@ public class CElementSorter extends ViewerSorter {
|
|||
return PROJECTS;
|
||||
case IResource.FOLDER:
|
||||
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;
|
||||
}
|
||||
} else if (element instanceof IStorage) {
|
||||
|
@ -255,6 +255,18 @@ public class CElementSorter extends ViewerSorter {
|
|||
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
|
||||
public int compare(Viewer viewer, Object e1, Object e2) {
|
||||
int cat1 = category(e1);
|
||||
|
@ -314,6 +326,8 @@ public class CElementSorter extends ViewerSorter {
|
|||
if (name1.length() > 0 && name1.charAt(0) == '~') {
|
||||
name1 = name1.substring(1);
|
||||
}
|
||||
} else if (e1 instanceof IResource) {
|
||||
name1 = ((IResource)e1).getName();
|
||||
} else {
|
||||
name1 = e1.toString();
|
||||
}
|
||||
|
@ -327,6 +341,8 @@ public class CElementSorter extends ViewerSorter {
|
|||
if (name2.length() > 0 && name2.charAt(0) == '~') {
|
||||
name2 = name2.substring(1);
|
||||
}
|
||||
} else if(e2 instanceof IResource) {
|
||||
name2 = ((IResource)e2).getName();
|
||||
} else {
|
||||
name2 = e2.toString();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* 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$
|
||||
|
||||
/**
|
||||
* 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
|
||||
* have been excluded from the default proposal list.
|
||||
|
@ -1707,12 +1718,12 @@ public class PreferenceConstants {
|
|||
return node;
|
||||
}
|
||||
}
|
||||
node = new InstanceScope().getNode(CUIPlugin.PLUGIN_ID);
|
||||
node = InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID);
|
||||
if (node.get(key, null) != null) {
|
||||
return node;
|
||||
}
|
||||
|
||||
return new DefaultScope().getNode(CUIPlugin.PLUGIN_ID);
|
||||
return DefaultScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue