1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 53844: sort order in C/C++ view

This commit is contained in:
Anton Leherbauer 2008-01-16 09:50:40 +00:00
parent f40c392f11
commit 6fbc58a2e2
8 changed files with 92 additions and 49 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.preferences;
@ -41,15 +42,11 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator;
public class AppearancePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private static final String SHOW_TU_CHILDREN= PreferenceConstants.PREF_SHOW_CU_CHILDREN;
private static final String OUTLINE_GROUP_INCLUDES = PreferenceConstants.OUTLINE_GROUP_INCLUDES;
private static final String OUTLINE_GROUP_NAMESPACES = PreferenceConstants.OUTLINE_GROUP_NAMESPACES;
private static final String CVIEW_GROUP_INCLUDES = PreferenceConstants.CVIEW_GROUP_INCLUDES;
private SelectionButtonDialogField fShowTUChildren;
private SelectionButtonDialogField fOutlineGroupIncludes;
private SelectionButtonDialogField fOutlineGroupNamespaces;
private SelectionButtonDialogField fCViewGroupIncludes;
private SelectionButtonDialogField fCViewSeparateHeaderAndSource;
public AppearancePreferencePage() {
setPreferenceStore(PreferenceConstants.getPreferenceStore());
@ -77,14 +74,18 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
fCViewGroupIncludes.setDialogFieldListener(listener);
fCViewGroupIncludes.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewGroupIncludes_label);
}
fCViewSeparateHeaderAndSource= new SelectionButtonDialogField(SWT.CHECK);
fCViewSeparateHeaderAndSource.setDialogFieldListener(listener);
fCViewSeparateHeaderAndSource.setLabelText(PreferencesMessages.AppearancePreferencePage_cviewSeparateHeaderAndSource_label);
}
private void initFields() {
IPreferenceStore prefs= getPreferenceStore();
fShowTUChildren.setSelection(prefs.getBoolean(SHOW_TU_CHILDREN));
fCViewGroupIncludes.setSelection(prefs.getBoolean(CVIEW_GROUP_INCLUDES));
fOutlineGroupIncludes.setSelection(prefs.getBoolean(OUTLINE_GROUP_INCLUDES));
fOutlineGroupNamespaces.setSelection(prefs.getBoolean(OUTLINE_GROUP_NAMESPACES));
fShowTUChildren.setSelection(prefs.getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN));
fCViewGroupIncludes.setSelection(prefs.getBoolean(PreferenceConstants.CVIEW_GROUP_INCLUDES));
fCViewSeparateHeaderAndSource.setSelection(prefs.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE));
fOutlineGroupIncludes.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
fOutlineGroupNamespaces.setSelection(prefs.getBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
}
/*
@ -110,17 +111,16 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
result.setLayout(layout);
fShowTUChildren.doFillIntoGrid(result, nColumns);
fCViewGroupIncludes.doFillIntoGrid(result, nColumns);
fCViewGroupIncludes.doFillIntoGrid(result, nColumns);
fOutlineGroupIncludes.doFillIntoGrid(result, nColumns);
fOutlineGroupNamespaces.doFillIntoGrid(result, nColumns);
new Separator().doFillIntoGrid(result, nColumns);
fCViewSeparateHeaderAndSource.doFillIntoGrid(result, nColumns);
new Separator().doFillIntoGrid(result, nColumns);
String noteTitle= PreferencesMessages.AppearancePreferencePage_note;
String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives;
String noteTitle= PreferencesMessages.AppearancePreferencePage_note;
String noteMessage= PreferencesMessages.AppearancePreferencePage_preferenceOnlyForNewViews;
Composite noteControl= createNoteComposite(JFaceResources.getDialogFont(), result, noteTitle, noteMessage);
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan= 2;
@ -156,10 +156,11 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
*/
public boolean performOk() {
IPreferenceStore prefs= getPreferenceStore();
prefs.setValue(SHOW_TU_CHILDREN, fShowTUChildren.isSelected());
prefs.setValue(CVIEW_GROUP_INCLUDES, fCViewGroupIncludes.isSelected());
prefs.setValue(OUTLINE_GROUP_INCLUDES, fOutlineGroupIncludes.isSelected());
prefs.setValue(OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected());
prefs.setValue(PreferenceConstants.PREF_SHOW_CU_CHILDREN, fShowTUChildren.isSelected());
prefs.setValue(PreferenceConstants.CVIEW_GROUP_INCLUDES, fCViewGroupIncludes.isSelected());
prefs.setValue(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE, fCViewSeparateHeaderAndSource.isSelected());
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, fOutlineGroupIncludes.isSelected());
prefs.setValue(PreferenceConstants.OUTLINE_GROUP_NAMESPACES, fOutlineGroupNamespaces.isSelected());
CUIPlugin.getDefault().savePluginPreferences();
return super.performOk();
}
@ -169,10 +170,11 @@ public class AppearancePreferencePage extends PreferencePage implements IWorkben
*/
protected void performDefaults() {
IPreferenceStore prefs= getPreferenceStore();
fShowTUChildren.setSelection(prefs.getDefaultBoolean(SHOW_TU_CHILDREN));
fCViewGroupIncludes.setSelection(prefs.getDefaultBoolean(CVIEW_GROUP_INCLUDES));
fOutlineGroupIncludes.setSelection(prefs.getDefaultBoolean(OUTLINE_GROUP_INCLUDES));
fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(OUTLINE_GROUP_NAMESPACES));
fShowTUChildren.setSelection(prefs.getDefaultBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN));
fCViewGroupIncludes.setSelection(prefs.getDefaultBoolean(PreferenceConstants.CVIEW_GROUP_INCLUDES));
fCViewSeparateHeaderAndSource.setSelection(prefs.getDefaultBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE));
fOutlineGroupIncludes.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
fOutlineGroupNamespaces.setSelection(prefs.getDefaultBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
super.performDefaults();
}
}

View file

@ -137,10 +137,11 @@ public final class PreferencesMessages extends NLS {
public static String AppearancePreferencePage_description;
public static String AppearancePreferencePage_showTUChildren_label;
public static String AppearancePreferencePage_cviewGroupIncludes_label;
public static String AppearancePreferencePage_cviewSeparateHeaderAndSource_label;
public static String AppearancePreferencePage_outlineGroupIncludes_label;
public static String AppearancePreferencePage_outlineGroupNamespaces_label;
public static String AppearancePreferencePage_note;
public static String AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives;
public static String AppearancePreferencePage_preferenceOnlyForNewViews;
public static String CEditorPreferencePage_folding_title;
public static String FoldingConfigurationBlock_enable;
public static String FoldingConfigurationBlock_combo_caption;

View file

@ -149,14 +149,15 @@ CBufferPreferences_CodeReaderBuffer_Size=Size (MB)
CEditorPreferencePage_behaviourPage_EnableEditorProblemAnnotation=Enable editor problem annotation
#Appearance Preferences
AppearancePreferencePage_description= Appearance of C elements in viewers:
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 the includes in the C/C++ projects view
AppearancePreferencePage_outlineGroupIncludes_label= Group the includes in the outliner
AppearancePreferencePage_outlineGroupNamespaces_label= Group the namespaces in the outliner
AppearancePreferencePage_cviewGroupIncludes_label= Group include directives 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_outlineGroupIncludes_label= Group include directives in the Outline view
AppearancePreferencePage_outlineGroupNamespaces_label= Group namespaces in the Outline view
AppearancePreferencePage_note=Note:
AppearancePreferencePage_preferenceOnlyEffectiveForNewPerspectives=This preference may only take effect on new perspectives
AppearancePreferencePage_preferenceOnlyForNewViews=This preference does not affect open views
#Folding
CEditorPreferencePage_folding_title= &Folding

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others.
* Copyright (c) 2005, 2008 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
@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* QNX Software System
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.ui;
@ -43,6 +44,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ContentViewer;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
@ -104,7 +106,22 @@ public class CElementSorter extends ViewerSorter {
protected static final int RESOURCES= 201;
protected static final int STORAGE= 202;
protected static final int OTHERS= 500;
/**
* Flag indicating whether header files and source files should be separated.
* If <code>true</code>, header files will be sorted before source files,
* otherwise header and source files will be sorted by name.
*/
private boolean fSeparateHeaderAndSource;
/**
* Default constructor for use as executable extension.
*/
public CElementSorter() {
final IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
fSeparateHeaderAndSource= store.getBoolean(PreferenceConstants.CVIEW_SEPARATE_HEADER_AND_SOURCE);
}
public int category (Object element) {
if (element instanceof ICModel) {
return CMODEL;
@ -120,11 +137,13 @@ public class CElementSorter extends ViewerSorter {
return CCONTAINERS;
} else if (element instanceof ITranslationUnit) {
ITranslationUnit tu = (ITranslationUnit)element;
if (CoreModel.isValidHeaderUnitName(tu.getCProject().getProject(), tu.getElementName())) {
return TRANSLATIONUNIT_HEADERS;
}
if (CoreModel.isValidSourceUnitName(tu.getCProject().getProject(), tu.getElementName())) {
return TRANSLATIONUNIT_SOURCE;
if (fSeparateHeaderAndSource) {
if (CoreModel.isValidHeaderUnitName(tu.getCProject().getProject(), tu.getElementName())) {
return TRANSLATIONUNIT_HEADERS;
}
if (CoreModel.isValidSourceUnitName(tu.getCProject().getProject(), tu.getElementName())) {
return TRANSLATIONUNIT_SOURCE;
}
}
return TRANSLATIONUNITS;
} else if (element instanceof IInclude) {

View file

@ -718,7 +718,7 @@ public class PreferenceConstants {
public static final String ID_BESTMATCH_HOVER= "org.eclipse.cdt.ui.BestMatchHover"; //$NON-NLS-1$
/**
* A named preference that controls if the Outline view.
* A named preference that controls whether the Outline view should group include directives.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -726,7 +726,7 @@ public class PreferenceConstants {
public static final String OUTLINE_GROUP_INCLUDES= "org.eclipse.cdt.ui.outline.groupincludes"; //$NON-NLS-1$
/**
* A named preference that controls if the Outline view.
* A named preference that controls whether the Outline view should group namespaces.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
@ -735,7 +735,7 @@ public class PreferenceConstants {
/**
* A named preference that controls whether the outline view
* A named preference that controls whether the Outline view
* selection should stay in sync with with the element at the current cursor position.
* <p>
* Value is of type <code>Boolean</code>.
@ -744,13 +744,25 @@ public class PreferenceConstants {
public static final String OUTLINE_LINK_TO_EDITOR = "org.eclipse.cdt.ui.outline.linktoeditor"; //$NON-NLS-1$
/**
* A named preference that controls if the CView.
* A named preference that controls whether include directives should be grouped in the
* C/C++ Projects view and the Project Explorer view.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String CVIEW_GROUP_INCLUDES= "org.eclipse.cdt.ui.cview.groupincludes"; //$NON-NLS-1$
/**
* A named preference that controls whether header and source files should be separated in the
* C/C++ Projects view and the Project Explorer view.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 5.0
*/
public static final String CVIEW_SEPARATE_HEADER_AND_SOURCE= "org.eclipse.cdt.ui.cview.separateheaderandsource"; //$NON-NLS-1$
/**
* A named preference that controls which completion proposal categories
* have been excluded from the default proposal list.

View file

@ -349,5 +349,9 @@
<context id="toggle_mark_occurrences_action_context">
<description>Allows you to switch mark occurrences on and off.</description>
</context>
<context id="appearance_preference_page_context">
<description>Customize the appearance of C/C++ elements in viewers.</description>
<topic label="Appearance Preferences" href="reference/cdt_u_appearance_pref.htm"/>
</context>
</contexts>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -13,7 +13,7 @@
<h1>Appearance preferences</h1>
<p>Use the <b>Appearance</b> panel of the Preferences window to customize the appearance of C elements in the viewers.</p>
<p><img src="../images/view_appearance_prefs.png" width="627" height="524"></p>
<p><img src="../images/view_appearance_prefs.png" width="635" height="544"></p>
<table width="700px" cellpadding="5" cellspacing="0" border="1" >
<caption>
@ -25,20 +25,24 @@
</colgroup>
<tbody>
<tr>
<td width="241" valign="top"><b>Show translation unit numbers </b></td>
<td width="433" valign="top">Select this option to show translation unit numbers. </td>
<td width="241" valign="top"><b>Show translation unit members </b></td>
<td width="433" valign="top">Select this option to show translation unit members in Project Explorer and C/C++ Projects view. </td>
</tr>
<tr>
<td valign="top"><b>Group the includes in the C/C++ projects view </b></td>
<td valign="top">Select this option to group include files in the C/C++ project view. </td>
<td valign="top"><b>Group include directives in Project Explorer and C/C++ Projects view </b></td>
<td valign="top">Select this option to group include directives in Project Explorer and C/C++ Projects view. </td>
</tr>
<tr>
<td valign="top"><b>Group the includes in the outliner </b></td>
<td valign="top">Select this option to group include files in outline views. </td>
<td valign="top"><b>Group include directives in the Outline view </b></td>
<td valign="top">Select this option to group include directives in the Outline view. </td>
</tr>
<tr>
<td valign="top"><b>Group the namespaces in the outliner </b></td>
<td valign="top">Select this option to group files by namespaces in outline views. </td>
<td valign="top"><b>Group namespaces in the Outline view </b></td>
<td valign="top">Select this option to group namespace declarations in the Outline view. </td>
</tr>
<tr>
<td valign="top"><b>Sort header files before source files in Project Explorer and C/C++ Projects view </b></td>
<td valign="top">Select this option to separate header and source files in Project Explorer and C/C++ Projects view. </td>
</tr>
</tbody>
</table>