Skip to content

Commit

Permalink
Merge pull request #430 from steghoja/master
Browse files Browse the repository at this point in the history
Added context menu to outline view
  • Loading branch information
de-jcup authored Jul 25, 2022
2 parents 5789fff + ac18c28 commit 579602b
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
Expand All @@ -30,7 +31,9 @@
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;

Expand All @@ -48,6 +51,9 @@ public class AsciiDoctorContentOutlinePage extends ContentOutlinePage implements
private static final ImageDescriptor IMG_DESC_NOT_LINKED = createOutlineImageDescriptor("sync_broken.png");
private static final ImageDescriptor IMG_DESC_EXPAND_ALL = createOutlineImageDescriptor("expandall.png");
private static final ImageDescriptor IMG_DESC_COLLAPSE_ALL = createOutlineImageDescriptor("collapseall.png");

private static final String MENU_ID = "de.jcup.asciidoctoreditor.outline";
private static final String CONTEXT_MENU_ID = "AsciiDoctorOutlinePageContextMenu";

private AsciiDoctorEditorTreeContentProvider contentProvider;
private Object input;
Expand Down Expand Up @@ -99,6 +105,8 @@ public void createControl(Composite parent) {

viewMenuManager.add(new Separator("treeGroup")); //$NON-NLS-1$
viewMenuManager.add(toggleLinkingAction);

configureContextMenu();

/*
* when no input is set on init state - let the editor rebuild outline (async)
Expand All @@ -109,6 +117,16 @@ public void createControl(Composite parent) {

}

private void configureContextMenu() {
MenuManager menuManager = new MenuManager(CONTEXT_MENU_ID, CONTEXT_MENU_ID);
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.setRemoveAllWhenShown(true);

Menu contextMenu = menuManager.createContextMenu(getTreeViewer().getTree());
getTreeViewer().getTree().setMenu(contextMenu);
getSite().registerContextMenu(MENU_ID, menuManager, getTreeViewer());
}

@Override
public void doubleClick(DoubleClickEvent event) {
if (editor == null) {
Expand Down

0 comments on commit 579602b

Please sign in to comment.