~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/SurroundWithActionGroup.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
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;
 
13
 
 
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;
 
23
 
 
24
public class SurroundWithActionGroup extends ActionGroup {
 
25
 
 
26
        private CEditor fEditor;
 
27
        private final String fGroup;
 
28
 
 
29
        public SurroundWithActionGroup(CEditor editor, String group) {
 
30
                fEditor= editor;
 
31
                fGroup= group;
 
32
        }
 
33
 
 
34
        /**
 
35
         * The Menu to show when right click on the editor
 
36
         * {@inheritDoc}
 
37
         */
 
38
        @Override
 
39
        public void fillContextMenu(IMenuManager menu) {
 
40
                ISelectionProvider selectionProvider= fEditor.getSelectionProvider();
 
41
                if (selectionProvider == null)
 
42
                        return;
 
43
 
 
44
                ISelection selection= selectionProvider.getSelection();
 
45
                if (!(selection instanceof ITextSelection))
 
46
                        return;
 
47
 
 
48
                ITextSelection textSelection= (ITextSelection)selection;
 
49
                if (textSelection.getLength() == 0)
 
50
                        return;
 
51
 
 
52
                String menuText= ActionMessages.SurroundWithTemplateMenuAction_SubMenuName;
 
53
 
 
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) {
 
60
                                manager.removeAll();
 
61
                                SurroundWithTemplateMenuAction.fillMenu(manager, fEditor);
 
62
                        }
 
63
                });
 
64
        }
 
65
}