1
/*******************************************************************************
2
* Copyright (c) 2000, 2010 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - initial API and implementation
10
* Axel Mueller - [289339] ported from JDT to CDT
11
*******************************************************************************/
12
package org.eclipse.cdt.internal.ui.actions;
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.IMenuListener;
16
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.MenuManager;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.ISelectionProvider;
20
import org.eclipse.jface.text.ITextSelection;
21
import org.eclipse.ui.actions.ActionGroup;
22
import org.eclipse.cdt.internal.ui.editor.CEditor;
24
public class SurroundWithActionGroup extends ActionGroup {
26
private CEditor fEditor;
27
private final String fGroup;
29
public SurroundWithActionGroup(CEditor editor, String group) {
35
* The Menu to show when right click on the editor
39
public void fillContextMenu(IMenuManager menu) {
40
ISelectionProvider selectionProvider= fEditor.getSelectionProvider();
41
if (selectionProvider == null)
44
ISelection selection= selectionProvider.getSelection();
45
if (!(selection instanceof ITextSelection))
48
ITextSelection textSelection= (ITextSelection)selection;
49
if (textSelection.getLength() == 0)
52
String menuText= ActionMessages.SurroundWithTemplateMenuAction_SubMenuName;
54
MenuManager subMenu = new MenuManager(menuText, SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID);
55
subMenu.setActionDefinitionId(SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID);
56
menu.appendToGroup(fGroup, subMenu);
57
subMenu.add(new Action() {});
58
subMenu.addMenuListener(new IMenuListener() {
59
public void menuAboutToShow(IMenuManager manager) {
61
SurroundWithTemplateMenuAction.fillMenu(manager, fEditor);