diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index a42107dd93c..bd65cd972ef 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,18 @@ +2004-03-05 Alain Magloire + + Support for ToggleEditor link action. + This action was only in the preference page. + Now it is also in the toolbar. It permits the CView + to track the CEdito selection. + + * src/org/eclipse/cdt/internal/ui/cview/CView.java + * src/org/eclipse/cdt/internal/ui/cview/CViewAction.java + * src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java + * src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java + * src/org/eclipse/cdt/internal/ui/cview/ToggleLinkingAction.java + * src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java + + 2004-03-04 Bogdan Gheorghe Added Hyperlinks to CEditor Added Navigation preference page for CEditor diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java index 5e7b44ab64e..1c51a92418e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CView.java @@ -818,14 +818,23 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha if (viewer == null) return; boolean refreshViewer = false; + String property = event.getProperty(); - if (event.getProperty() == PreferenceConstants.PREF_SHOW_CU_CHILDREN) { + if (property.equals(PreferenceConstants.PREF_SHOW_CU_CHILDREN)) { boolean showCUChildren = CPluginPreferencePage.showCompilationUnitChildren(); ((CElementContentProvider) viewer.getContentProvider()).setProvideMembers(showCUChildren); refreshViewer = true; + } else if (property.equals(PreferenceConstants.PREF_LINK_TO_EDITOR)) { + CViewActionGroup group = getActionGroup(); + if (group instanceof MainActionGroup) { + boolean enable = isLinkingEnabled(); + ((MainActionGroup)group).toggleLinkingAction.setChecked(enable); + } } - if (refreshViewer) viewer.refresh(); + if (refreshViewer) { + viewer.refresh(); + } } /** @@ -839,6 +848,10 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha return CPluginPreferencePage.isLinkToEditor(); } + public void setLinkingEnabled(boolean enable) { + CPluginPreferencePage.setLinkingEnabled(enable); + } + /** * Links to editor (if option enabled) */ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewAction.java new file mode 100644 index 00000000000..9f30d1c1f9e --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewAction.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.cview; + +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.SelectionProviderAction; + +/** + * Superclass of all actions provided by the cview. + */ +public abstract class CViewAction extends SelectionProviderAction { + + private CView cview; + + /** + * Creates a new instance of the class. + */ + public CViewAction(CView cview, String label) { + super(cview.getViewer(), label); + this.cview = cview; + } + + /** + * Returns the cview for which this action was created. + */ + public CView getCView() { + return cview; + } + + /** + * Returns the viewer + */ + protected Viewer getViewer() { + return getCView().getViewer(); + } + + /** + * Returns the shell to use within actions. + */ + protected Shell getShell() { + return getCView().getSite().getShell(); + } + + /** + * Returns the workbench. + */ + protected IWorkbench getWorkbench() { + return CUIPlugin.getDefault().getWorkbench(); + } + + /** + * Returns the workbench window. + */ + protected IWorkbenchWindow getWorkbenchWindow() { + return getCView().getSite().getWorkbenchWindow(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java index b66fbe620da..264c952bf90 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java @@ -13,15 +13,13 @@ package org.eclipse.cdt.internal.ui.cview; import java.net.MalformedURLException; import java.net.URL; -import org.eclipse.core.runtime.Platform; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.events.KeyEvent; import org.eclipse.ui.IActionBars; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.plugin.AbstractUIPlugin; /** * This is the action group for all the view actions. @@ -57,8 +55,9 @@ public abstract class CViewActionGroup extends ActionGroup { protected ImageDescriptor getImageDescriptor(String relativePath) { String iconPath = "icons/full/"; //$NON-NLS-1$ try { - AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID); - URL installURL = plugin.getDescriptor().getInstallURL(); + //AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID); + //URL installURL = plugin.getDescriptor().getInstallURL(); + URL installURL = CUIPlugin.getDefault().getDescriptor().getInstallURL(); URL url = new URL(installURL, iconPath + relativePath); return ImageDescriptor.createFromURL(url); } catch (MalformedURLException e) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java index afd6b887735..1264e53c22a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java @@ -66,6 +66,7 @@ public class MainActionGroup extends CViewActionGroup { ShowLibrariesAction clibFilterAction; // Collapsing CollapseAllAction collapseAllAction; + ToggleLinkingAction toggleLinkingAction; //Search FileSearchAction fFileSearchAction; @@ -153,6 +154,11 @@ public class MainActionGroup extends CViewActionGroup { collapseAllAction = new CollapseAllAction(getCView()); + toggleLinkingAction = new ToggleLinkingAction(getCView(), CViewMessages.getString("ToggleLinkingAction.text")); //$NON-NLS-1$ + toggleLinkingAction.setToolTipText(CViewMessages.getString("ToggleLinkingAction.toolTip")); //$NON-NLS-1$ + toggleLinkingAction.setImageDescriptor(getImageDescriptor("elcl16/synced.gif"));//$NON-NLS-1$ + toggleLinkingAction.setHoverImageDescriptor(getImageDescriptor("clcl16/synced.gif"));//$NON-NLS-1$ + fFileSearchAction = new FileSearchAction(viewer); fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(viewer); fSearchDialogAction = new SearchDialogAction(viewer, getCView().getViewSite().getWorkbenchWindow()); @@ -320,11 +326,12 @@ public class MainActionGroup extends CViewActionGroup { IToolBarManager toolBar = actionBars.getToolBarManager(); toolBar.add(new Separator()); toolBar.add(collapseAllAction); + toolBar.add(toggleLinkingAction); IMenuManager menu = actionBars.getMenuManager(); //menu.add (clibFilterAction); menu.add(patternFilterAction); - + menu.add(toggleLinkingAction); } public void dispose() { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/ToggleLinkingAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/ToggleLinkingAction.java new file mode 100644 index 00000000000..8ec59ca10c3 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/ToggleLinkingAction.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.cview; + +/** + * This action toggles whether this navigator links its selection to the active + * editor. + * + * @since 2.0 + */ +public class ToggleLinkingAction extends CViewAction { + + /** + * Constructs a new action. + */ + public ToggleLinkingAction(CView cview, String label) { + super(cview, label); + setChecked(cview.isLinkingEnabled()); + } + + /** + * Runs the action. + */ + public void run() { + getCView().setLinkingEnabled(isChecked()); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java index 9d9d53c68dc..8182e6ca9db 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/CPluginPreferencePage.java @@ -61,6 +61,10 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_LINK_TO_EDITOR); } + public static void setLinkingEnabled(boolean enable) { + CUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.PREF_LINK_TO_EDITOR, enable); + } + public static boolean showCompilationUnitChildren() { return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN); }