Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-patch] Patch for PR 44892


> -----Original Message-----
> From: Alain Magloire [mailto:alain@xxxxxxx]
> Sent: Monday, October 20, 2003 4:04 PM
> To: cdt-patch@xxxxxxxxxxx
> Subject: Re: [cdt-patch] Patch for PR 44892
> 
> 
> > 
> > In my continuing quest for parity at the platform level 
> with all of the
> > features we have missed during the last few busy months of 
> activity, here
> > is a patch which addresses the fact that the CDT has no 
> support for the
> > ShowIn navigation hook.
> > 
> > This patch hits three files:
> > CEditor: To add support to provide a ShowInContext
> > CView: To add support for receiving an IShowInContext
> > CPerspectiveFactory: To add support for adding the show in binding
> >                      to the CView and the Navigator.
> > 
> > The patch is _totally_ trivial and was taken against CDT 1.2 branch.
> > 
> > For the ChangeLog:
> >  Add missing support for the Nagivate > ShowIn hook into the 
> >  C/C++ Editor, C/C++ Project View and add the hooks into the
> >  perspective.
> > 
> > 
> 
> Nice, Thanks!!
> 
> Patch applied.
> 
> Do you have time for the context menu in the CEditor, the action
> should also be accessible this way and not only via the 
> Navigate > ShowIn.

This patch (again applied against CDT 1.2, and I noticed that you
didn't apply the original patch against CDT 1.2 so there is a bit
of cross talk, let me know if this is a problem) provides a bit of
clean-up to the C/C++ Editor context menu to make it match the
look/feel of the Java Editor context menu.  It also adds in a new
command/action which will provide the Show In CView capability from
the context menu.

Hits CEditor, bunch of properties and creates a new OpenInCViewAction.

For the ChangeLog:
 Add missing support for the C Editor context menu to show the entry
 in the C/C++ Project view. Reorganized the context menu to include
 source related sub-menus.
 

Index: plugin.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/plugin.properties,v
retrieving revision 1.28
diff -u -r1.28 plugin.properties
--- plugin.properties	1 Oct 2003 13:33:39 -0000	1.28
+++ plugin.properties	22 Oct 2003 19:42:55 -0000
@@ -54,6 +54,9 @@
 ActionDefinition.opendecl.name= Open Declaration
 ActionDefinition.opendecl.description= Open an editor on the selected element's declaration(s)
 
+ActionDefinition.opencview.name= Show in C/C++ Project view
+ActionDefinition.opencview.description= Show the selected resource in the C/C++ Project view
+
 CEditor.name=C Editor
 CPluginPreferencePage.name=C/C++
 CPluginEditorPreferencePage.name=C/C++ Editor
Index: plugin.xml
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/plugin.xml,v
retrieving revision 1.53
diff -u -r1.53 plugin.xml
--- plugin.xml	1 Oct 2003 22:15:38 -0000	1.53
+++ plugin.xml	22 Oct 2003 19:42:56 -0000
@@ -27,9 +27,9 @@
    <extension-point id="CElementFilters" name="%elementFiltersName"/>
    <extension-point id="BinaryParserPage" name="Binary Parser Page"/>
 <!-- =========================================================================== -->
-<!-- Extension Implementation: must implement org.eclipse.jface.text.ITextHover  -->
-<!-- Purpose: Provide a perspective specific text hovering for CEditor files     -->
 <!-- Extension point: org.eclipse.cdt.ui.textHovers                        -->
+<!-- Purpose: Provide a perspective specific text hovering for CEditor files     -->
+<!-- Extension Implementation: must implement org.eclipse.jface.text.ITextHover  -->
 <!-- =========================================================================== -->
    <extension-point id="textHovers" name="%textHoversName"/>
 
@@ -130,8 +130,8 @@
             id="org.eclipse.cdt.ui.CView">
       </view>
    </extension>
-<!-- The wizards -->
 <!-- For C Wizards -->
+<!-- The wizards -->
    <extension
          point="org.eclipse.ui.newWizards">
       <category
@@ -392,12 +392,12 @@
             category="org.eclipse.cdt.ui.category.source"
             id="org.eclipse.cdt.ui.edit.opendecl">
       </command>
-      <keyBinding
-            string="F3"
-            scope="org.eclipse.cdt.ui.cEditorScope"
-            command="org.eclipse.cdt.ui.edit.opendecl"
-            configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
-      </keyBinding>
+      <command
+            category="org.eclipse.cdt.ui.category.source"
+            name="%ActionDefinition.opencview.name"
+            description="%ActionDefinition.opencview.description"
+            id="org.eclipse.cdt.ui.edit.opencview">
+      </command>
    </extension>
    <extension
          id="org.eclipse.cdt.ui.CSearchPage"
Index: src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java,v
retrieving revision 1.1
diff -u -r1.1 IContextMenuConstants.java
--- src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java	26 Jun 2002 20:55:44 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/IContextMenuConstants.java	22 Oct 2003 19:42:57 -0000
@@ -98,5 +98,16 @@
 	 * Pop-up menu: name of group for properties actions (value <code>"group.properties"</code>).
 	 */	
 	public static final String GROUP_PROPERTIES=	"group.properties"; //$NON-NLS-1$
+
+	/**
+	 * Pop-up menu: name of group for source actions (value <code>"group.source"</code>).
+	 */	
+	public static final String GROUP_CSOURCE=	"group.source"; //$NON-NLS-1$
+
+	/**
+	 * Pop-up menu: name of group for source actions (value <code>"group.refactor"</code>).
+	 */	
+	public static final String GROUP_CREFACTOR=	"group.refactor"; //$NON-NLS-1$
+
 }
 
Index: src/org/eclipse/cdt/internal/ui/editor/CEditor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java,v
retrieving revision 1.32
diff -u -r1.32 CEditor.java
--- src/org/eclipse/cdt/internal/ui/editor/CEditor.java	1 Oct 2003 13:33:39 -0000	1.32
+++ src/org/eclipse/cdt/internal/ui/editor/CEditor.java	22 Oct 2003 19:43:00 -0000
@@ -31,6 +31,7 @@
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jface.action.GroupMarker;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IStatusLineManager;
@@ -77,6 +78,8 @@
 import org.eclipse.ui.editors.text.TextEditorPreferenceConstants;
 import org.eclipse.ui.internal.editors.text.EditorsPlugin;
 import org.eclipse.ui.part.EditorActionBarContributor;
+import org.eclipse.ui.part.IShowInSource;
+import org.eclipse.ui.part.ShowInContext;
 import org.eclipse.ui.texteditor.AnnotationPreference;
 import org.eclipse.ui.texteditor.ContentAssistAction;
 import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
@@ -94,7 +97,7 @@
 /**
  * C specific text editor.
  */
-public class CEditor extends TextEditor implements ISelectionChangedListener {
+public class CEditor extends TextEditor implements ISelectionChangedListener, IShowInSource {
 
 	/** The outline page */
 	protected CContentOutlinePage fOutlinePage;
@@ -440,6 +443,10 @@
 		action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
 		setAction("OpenDeclarations", action);
 
+		action = new ShowInCViewAction(this);
+		action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CVIEW);
+		setAction("ShowInCView", action); //$NON-NLS-1$
+
 		fFileSearchAction = new FileSearchAction(getSelectionProvider());
 		
 		fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(getSelectionProvider());
@@ -450,19 +457,39 @@
 	public void editorContextMenuAboutToShow(IMenuManager menu) {
 		super.editorContextMenuAboutToShow(menu);
 
+		addGroup(menu, ITextEditorActionConstants.GROUP_UNDO, IContextMenuConstants.GROUP_OPEN);
+		addGroup(menu, ITextEditorActionConstants.GROUP_COPY, IContextMenuConstants.GROUP_CSOURCE);
+		addGroup(menu, ITextEditorActionConstants.GROUP_COPY, IContextMenuConstants.GROUP_CREFACTOR);
+
 		addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_REORGANIZE);
 		addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_GENERATE);
 		addGroup(menu, ITextEditorActionConstants.GROUP_EDIT, IContextMenuConstants.GROUP_NEW);
 
-		// Code formatting menu items -- only show in C perspective
-		addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Comment"); //$NON-NLS-1$
-		addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Uncomment"); //$NON-NLS-1$
-		// @@@ disabled for now until we get it to do something...
-		//addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$
+		//Source sub-menu item
+		MenuManager source = new MenuManager("Source", IContextMenuConstants.GROUP_CSOURCE); //$NON-NLS-1$
+		source.add(new GroupMarker(ITextEditorActionConstants.GROUP_MANAGING));
+		addGroup(source, ITextEditorActionConstants.GROUP_MANAGING, ITextEditorActionConstants.GROUP_REORGANIZE);
+		menu.appendToGroup(IContextMenuConstants.GROUP_CSOURCE, source);
 
+		//Search sub-menu item
 		MenuManager search = new MenuManager("Search", IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$
 		menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, search);
+
+		//Commands we want to hard bind in
+
+		// Code formatting menu items -- only show in C perspective
+		addAction(source, ITextEditorActionConstants.GROUP_MANAGING, "Comment"); //$NON-NLS-1$
+		addAction(source, ITextEditorActionConstants.GROUP_MANAGING, "Uncomment"); //$NON-NLS-1$
+//		menu.remove(ITextEditorActionConstants.SHIFT_RIGHT);
+//		menu.remove(ITextEditorActionConstants.SHIFT_LEFT);
+		addAction(source, ITextEditorActionConstants.GROUP_MANAGING, ITextEditorActionConstants.SHIFT_RIGHT); 
+		addAction(source, ITextEditorActionConstants.GROUP_MANAGING, ITextEditorActionConstants.SHIFT_LEFT); 
 		
+
+		// @@@ disabled for now until we get it to do something...
+		//addAction(menu, ITextEditorActionConstants.GROUP_MANAGING, "Format"); //$NON-NLS-1$
+		addAction(source, IContextMenuConstants.GROUP_REORGANIZE, "AddIncludeOnSelection"); //$NON-NLS-1$
+
 		if (SearchDialogAction.canActionBeAdded(getSelectionProvider().getSelection())){
 			search.add(fSearchDialogAction);
 		}
@@ -474,9 +501,11 @@
 			search.add(fileSearch);
 		}
 
-		addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$
-		addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$
-		addAction(menu, IContextMenuConstants.GROUP_GENERATE, "OpenDeclarations"); //$NON-NLS-1$
+		//TODO: This action should really just go away.
+		//addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$
+
+		addAction(menu, IContextMenuConstants.GROUP_OPEN, "OpenDeclarations"); //$NON-NLS-1$		
+		addAction(menu, IContextMenuConstants.GROUP_OPEN, "ShowInCView"); //$NON-NLS-1$		
 	}
 
 	public void setOutlinePageInput(CContentOutlinePage page, IEditorInput input) {
@@ -890,4 +919,15 @@
                 sourceViewer.invalidateTextPresentation();
         }
     }
+    
+	/* (non-Javadoc)
+	 * @see org.eclipse.ui.part.IShowInSource#getShowInContext()
+	 * 
+	 * This is required by the IShowInSource interface for the "ShowIn" 
+	 * navigation menu generalized in Eclipse.
+	 */
+	public ShowInContext getShowInContext() {
+		return new ShowInContext( getEditorInput(), null );
+	}
+
 }
Index: src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties,v
retrieving revision 1.6
diff -u -r1.6 CEditorMessages.properties
--- src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties	26 Aug 2003 19:15:37 -0000	1.6
+++ src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties	22 Oct 2003 19:43:00 -0000
@@ -13,6 +13,10 @@
 AddIncludeOnSelection.label=Add I&nclude@Ctrl+Shift+N
 AddIncludeOnSelection.tooltip=Add Include Statement on Selection
 
+ShowInCView.description=Show the current resource in the C/C++ Projects view
+ShowInCView.label=Show in C/C++ Projects
+ShowInCView.tooltip=Show current resource in C/C++ Projects view
+
 ClassFileEditor.error.invalid_input_message=Invalid input for Class File Editor
 
 ClassFileMarkerAnnotationModel.error.isAcceptable=ClassFileMarkerAnnotationModel.isAcceptable
Index: src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java,v
retrieving revision 1.3
diff -u -r1.3 ICEditorActionDefinitionIds.java
--- src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java	1 Oct 2003 13:33:39 -0000	1.3
+++ src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java	22 Oct 2003 19:43:00 -0000
@@ -47,11 +47,17 @@
 	 * (value <code>"org.eclipse.cdt.ui.edit.text.java.toggle.presentation"</code>).
 	 */
 	public static final String TOGGLE_PRESENTATION= "org.eclipse.cdt.ui.edit.text.c.toggle.presentation"; //$NON-NLS-1$
+
 	/**
 	 * Action definition ID of the open declaration action
-	 * (value <code>"org.eclipse.cdt.ui.edit.text.java.toggle.presentation"</code>).
+	 * (value <code>"org.eclipse.cdt.ui.edit.opendecl"</code>).
 	 */
 	public static final String OPEN_DECL= "org.eclipse.cdt.ui.edit.opendecl"; //$NON-NLS-1$
 
+	/**
+	 * Action definition ID of the show in C/C++ Projects View action
+	 * (value <code>"org.eclipse.cdt.ui.edit.opencview"</code>).
+	 */
+	public static final String OPEN_CVIEW= "org.eclipse.cdt.ui.edit.opencview"; //$NON-NLS-1$
 
 }
Index: src/org/eclipse/cdt/internal/ui/editor/ShowInCViewAction.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/ui/editor/ShowInCViewAction.java
diff -N src/org/eclipse/cdt/internal/ui/editor/ShowInCViewAction.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/internal/ui/editor/ShowInCViewAction.java	22 Oct 2003 19:43:00 -0000
@@ -0,0 +1,84 @@
+package org.eclipse.cdt.internal.ui.editor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.IShowInSource;
+import org.eclipse.ui.part.IShowInTarget;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.IUpdate;
+
+/**
+ * This class will open the C/C++ Projects view and highlight the
+ * selected resource matching the current resouce being edited in
+ * the C/C++ Editor.  It uses the IShowInSource/IShowInTarget to 
+ * accomplish this task so as to provide some additional portability
+ * and future proofing.
+ */
+public class ShowInCViewAction extends Action implements IUpdate {
+	private ITextEditor fEditor;
+	final String CVIEW_ID = "org.eclipse.cdt.ui.CView";
+	
+	public ShowInCViewAction() {
+		this(null);
+	}
+	
+	public ShowInCViewAction(ITextEditor editor) {	
+		super(CEditorMessages.getString("ShowInCView.label"));		 //$NON-NLS-1$
+		setToolTipText(CEditorMessages.getString("ShowInCView.tooltip")); //$NON-NLS-1$
+		setDescription(CEditorMessages.getString("ShowInCView.description")); //$NON-NLS-1$
+		
+		fEditor= editor;
+		//WorkbenchHelp.setHelp(this,	new Object[] { IJavaHelpContextIds.ADD_IMPORT_ON_SELECTION_ACTION });	
+	}
+	
+	/**
+	 * @see IAction#actionPerformed
+	 */
+	public void run() {
+		if(fEditor == null) {
+			return;
+		}
+		
+		//Locate a source and a target for us to use
+		IShowInTarget showInTarget;
+		IShowInSource showInSource;
+		try {
+			IWorkbenchPage page = fEditor.getEditorSite().getWorkbenchWindow().getActivePage();
+			IWorkbenchPart part = page.showView(CVIEW_ID);
+			if(part instanceof IShowInTarget) {
+				showInTarget = (IShowInTarget)part;
+			} else {
+				showInTarget = (IShowInTarget)part.getAdapter(IShowInTarget.class);
+			}
+
+			if(fEditor instanceof IShowInSource) {
+				showInSource = (IShowInSource)fEditor;			
+			} else {
+				showInSource = (IShowInSource)fEditor.getAdapter(IShowInSource.class);
+			}
+		} catch(Exception ex) {
+			return;
+		}
+		
+		if(showInTarget == null || showInSource == null) {
+			return;
+		}
+		
+		//Now go ahead and show it (assuming that you can!)
+		showInTarget.show(showInSource.getShowInContext());
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ui.texteditor.IUpdate#update()
+	 */
+	public void update() {
+	}
+}
+
+

Back to the top