diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryDropDownAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryDropDownAction.java
index 59bcac0df94..6724a0e84af 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryDropDownAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryDropDownAction.java
@@ -30,7 +30,7 @@ public class IBHistoryDropDownAction extends Action implements IMenuCreator {
private IBViewPart fView;
public ClearHistoryAction(IBViewPart view) {
- super(IBMessages.HistoryDropDownAction_ClearHistory_label);
+ super(IBMessages.IBHistoryDropDownAction_ClearHistory_label);
fView= view;
}
@@ -48,7 +48,7 @@ public class IBHistoryDropDownAction extends Action implements IMenuCreator {
public IBHistoryDropDownAction(IBViewPart view) {
fHierarchyView= view;
fMenu= null;
- setToolTipText(IBMessages.HistoryDropDownAction_tooltip);
+ setToolTipText(IBMessages.IBHistoryDropDownAction_tooltip);
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, "history_list.gif"); //$NON-NLS-1$
setMenuCreator(this);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java
index 73ec4aec227..6119899dd44 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java
@@ -48,9 +48,9 @@ public class IBHistoryListAction extends Action {
private HistoryListDialog(Shell shell, ITranslationUnit[] elements) {
super(shell);
setHelpAvailable(false);
- setTitle(IBMessages.HistoryListAction_HistoryDialog_title);
+ setTitle(IBMessages.IBHistoryListAction_HistoryDialog_title);
String[] buttonLabels= new String[] {
- IBMessages.HistoryListAction_Remove_label,
+ IBMessages.IBHistoryListAction_Remove_label,
};
IListAdapter adapter= new IListAdapter() {
@@ -69,7 +69,7 @@ public class IBHistoryListAction extends Action {
CUILabelProvider labelProvider= new CUILabelProvider(CElementLabels.APPEND_ROOT_PATH, CElementImageProvider.OVERLAY_ICONS);
fHistoryList= new ListDialogField(adapter, buttonLabels, labelProvider);
- fHistoryList.setLabelText(IBMessages.HistoryListAction_HistoryList_label);
+ fHistoryList.setLabelText(IBMessages.IBHistoryListAction_HistoryList_label);
fHistoryList.setElements(Arrays.asList(elements));
ISelection sel;
@@ -163,7 +163,7 @@ public class IBHistoryListAction extends Action {
public IBHistoryListAction(IBViewPart view) {
fView= view;
- setText(IBMessages.HistoryListAction_label);
+ setText(IBMessages.IBHistoryListAction_label);
}
/*
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java
index c7a2410b1fa..5276ea36449 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java
@@ -16,17 +16,17 @@ import org.eclipse.osgi.util.NLS;
public class IBMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.includebrowser.IBMessages"; //$NON-NLS-1$
- public static String HistoryDropDownAction_ClearHistory_label;
+ public static String IBHistoryDropDownAction_ClearHistory_label;
- public static String HistoryDropDownAction_tooltip;
+ public static String IBHistoryDropDownAction_tooltip;
- public static String HistoryListAction_HistoryDialog_title;
+ public static String IBHistoryListAction_HistoryDialog_title;
- public static String HistoryListAction_HistoryList_label;
+ public static String IBHistoryListAction_HistoryList_label;
- public static String HistoryListAction_label;
+ public static String IBHistoryListAction_label;
- public static String HistoryListAction_Remove_label;
+ public static String IBHistoryListAction_Remove_label;
public static String IBViewPart_falseInputMessage;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties
index 261018a5f9c..837133bb12d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties
@@ -16,12 +16,12 @@ IBViewPart_showIncludesTo_label=Show Files Included
IBViewPart_showInclude_label=Open Include
IBViewPart_showFolders_label=Show Folders
IBViewPart_showFolders_tooltip=Show Folders
-IBViewPart_previousMatch_label=Previous Match
+IBViewPart_previousMatch_label=Previous Include
IBViewPart_showIncludesTo_tooltip=Show Files Included
IBViewPart_IncludedByContentDescription=Files including ''{0}'' - in {1}
IBViewPart_IncludesToContentDescription=Files included by ''{0}'' - in {1}
IBViewPart_hideInactive_tooltip=Hide Includes from Inactive Code
-IBViewPart_previousMatch_tooltip=Show Previous Match
+IBViewPart_previousMatch_tooltip=Show Previous Include
IBViewPart_OpenWithMenu_label=Open With
IBViewPart_hideInactive_label=Hide Inactive Includes
IBViewPart_hideSystem_tooltip=Hide System Includes
@@ -30,13 +30,13 @@ IBViewPart_hideSystem_label=Hide System Includes
IBViewPart_workspaceScope=workspace
IBViewPart_refresh_label=Refresh
IBViewPart_FocusOn_label=Focus On ''{0}''
-IBViewPart_nextMatch_label=Next Match
+IBViewPart_nextMatch_label=Next Include
IBViewPart_refresh_tooltip=Refresh View Content
IBViewPart_falseInputMessage=Include Hierarchies can be shown for C or C++ files, only. They have to be part of the workspace.
-IBViewPart_nextMatch_tooltip=Show Next Match
-HistoryListAction_HistoryDialog_title=Include Browser History
-HistoryDropDownAction_ClearHistory_label=Clear History
-HistoryListAction_Remove_label=Remove
-HistoryDropDownAction_tooltip=Show History List
-HistoryListAction_HistoryList_label=Select a file to show in the Include Browser:
-HistoryListAction_label=Open History...
+IBViewPart_nextMatch_tooltip=Show Next Include
+IBHistoryListAction_HistoryDialog_title=Include Browser History
+IBHistoryDropDownAction_ClearHistory_label=Clear History
+IBHistoryListAction_Remove_label=Remove
+IBHistoryDropDownAction_tooltip=Show History List
+IBHistoryListAction_HistoryList_label=Select a file to show in the Include Browser:
+IBHistoryListAction_label=Open History...
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java
index 88c76a33f16..ff889fc9c43 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java
@@ -120,7 +120,6 @@ public class IBNode implements IAdaptable {
/**
* Defines whether this is a system include (angle-brackets).
- * @see FileInclusionNode#isSystemInclude().
*/
public void setIsSystemInclude(boolean isSystemInclude) {
fIsSystemInclude= isSystemInclude;
@@ -137,7 +136,6 @@ public class IBNode implements IAdaptable {
/**
* Defines whether the inclusion appears in active code.
- * @see FileInclusionNode#isInActiveCode().
*/
public void setIsActiveCode(boolean isActiveCode) {
fIsActive= isActiveCode;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java
index ce2807a562a..6f81f3654c5 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java
@@ -48,7 +48,6 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorDescriptor;
@@ -86,6 +85,7 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.internal.ui.util.Messages;
import org.eclipse.cdt.internal.ui.viewsupport.ExtendedTreeViewer;
+import org.eclipse.cdt.internal.ui.viewsupport.TreeNavigator;
import org.eclipse.cdt.internal.ui.viewsupport.WorkingSetFilterUI;
/**
@@ -481,47 +481,24 @@ public class IBViewPart extends ViewPart
mm.add(fFilterInactiveAction);
}
- private TreeItem getNextTreeItem(boolean forward) {
- Tree tree= fTreeViewer.getTree();
- TreeItem[] selectedNodes= tree.getSelection();
- TreeItem selectedItem= null;
- for (int i = 0; i < selectedNodes.length; i++) {
- TreeItem item = selectedNodes[i];
- if (item.getData() instanceof IBNode) {
- selectedItem= item;
- break;
- }
+ private IBNode getNextNode(boolean forward) {
+ TreeNavigator navigator= new TreeNavigator(fTreeViewer.getTree(), IBNode.class);
+ TreeItem selectedItem= navigator.getSelectedItemOrFirstOnLevel(1, forward);
+ if (selectedItem == null) {
+ return null;
+ }
+
+ if (selectedItem.getData().equals(fLastNavigationNode)) {
+ selectedItem= navigator.getNextSibbling(selectedItem, forward);
}
- if (selectedItem == null) {
- // try to obtain an include on level 1;
- if (tree.getItemCount() > 0) {
- selectedItem= tree.getItem(0);
- int itemCount= selectedItem.getItemCount();
- if (itemCount > 0) {
- return selectedItem.getItem(forward ? 0 : itemCount-1);
- }
- }
- return null;
- }
- IBNode selectedNode= (IBNode) selectedItem.getData();
- if (!selectedNode.equals(fLastNavigationNode)) {
- return selectedItem;
- }
-
- TreeItem parentItem= selectedItem.getParentItem();
- int itemCount = parentItem.getItemCount();
- if (parentItem != null && itemCount > 1) {
- int index= parentItem.indexOf(selectedItem);
- index = (index + (forward ? 1 : itemCount-1)) % itemCount;
- return parentItem.getItem(index);
- }
- return null;
+
+ return selectedItem == null ? null : (IBNode) selectedItem.getData();
}
protected void onNextOrPrevious(boolean forward) {
- TreeItem nextItem= getNextTreeItem(forward);
- if (nextItem != null && nextItem.getData() instanceof IBNode) {
- StructuredSelection sel= new StructuredSelection(nextItem.getData());
+ IBNode nextItem= getNextNode(forward);
+ if (nextItem != null) {
+ StructuredSelection sel= new StructuredSelection(nextItem);
fTreeViewer.setSelection(sel);
onShowInclude(sel);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/TreeNavigator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/TreeNavigator.java
new file mode 100644
index 00000000000..65d2250e067
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/TreeNavigator.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * 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.ui.viewsupport;
+
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+/**
+ * Utility to perform next/previous navigation on a tree.
+ * @author markus.schorn@windriver.com
+ */
+public class TreeNavigator {
+ private Tree fTree;
+ private Class fDataClass;
+
+ /**
+ * Creates a tree navigator for the given tree. It allows for finding tree items.
+ * In case you supply a dataClass only nodes with data of this class are considered.
+ * @param tree the tree to operate on
+ * @param dataClass the required class for the data of the tree nodes, or null
.
+ */
+ public TreeNavigator(Tree tree, Class dataClass) {
+ fTree= tree;
+ fDataClass= dataClass;
+ }
+
+ /**
+ * Find the first valid item of the selection.
+ * @return the first valid item in the selection or null
+ */
+ public TreeItem getSelectedItem() {
+ return getItemOfClass(fTree.getSelection(), true);
+ }
+
+ private TreeItem getItemOfClass(TreeItem[] items, boolean fwd) {
+ for (int i = 0; i < items.length; i++) {
+ TreeItem item = items[i];
+ if (fDataClass==null || fDataClass.isInstance(item.getData())) {
+ return item;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find the first valid item on the given level. All parents have to be valid also.
+ * @param level the level to search, use 0
for the root nodes of the tree.
+ * @param fwd if set to false the tree is searched reverse from the buttom.
+ * @return the first item on the given level, or null
+ */
+ public TreeItem getFirstItemOnLevel(int level, boolean fwd) {
+ return getFirstOnLevel(fTree.getItems(), level, fwd);
+ }
+ private TreeItem getFirstOnLevel(TreeItem[] items, int level, boolean fwd) {
+ TreeItem item= getItemOfClass(items, fwd);
+ if (level <= 0 || item == null) {
+ return item;
+ }
+ return getFirstOnLevel(item.getItems(), level-1, fwd);
+ }
+
+ /**
+ * Combines the methods {@link TreeNavigator#getSelectedItem()} and
+ * {@link TreeNavigator#getFirstItemOnLevel(int, boolean)}.
+ * @param level the level to search, use 0
for the root nodes of the tree.
+ * @param fwd if set to false the tree is searched reverse from the buttom.
+ * @return the first valid item of the selection or the first item on the given level, or null
+ */
+ public TreeItem getSelectedItemOrFirstOnLevel(int level, boolean fwd) {
+ TreeItem result= getSelectedItem();
+ if (result == null) {
+ result= getFirstItemOnLevel(level, fwd);
+ }
+ return result;
+ }
+
+ /**
+ * Searches for the next valid sibbling of the given item.
+ * @param current a tree item to start the search
+ * @param forward if false the previous sibbling is returned
+ * @return the next sibbling after the given one, or null
+ */
+ public TreeItem getNextSibbling(TreeItem current, boolean forward) {
+ TreeItem parentItem= current.getParentItem();
+ int itemCount = parentItem.getItemCount();
+ if (parentItem != null && itemCount > 1) {
+ int index= parentItem.indexOf(current);
+ index = (index + (forward ? 1 : itemCount-1)) % itemCount;
+ return parentItem.getItem(index);
+ }
+ return null;
+ }
+}