Skip to content

Commit

Permalink
eclipse-che#3030 add editor context menu (eclipse-che#3066)
Browse files Browse the repository at this point in the history
* eclipse-che#3030 add editor context menu
  • Loading branch information
Evgen Vidolob authored Nov 15, 2016
2 parents a373c40 + c79d5d4 commit 4354142
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public interface IdeActions {
String GROUP_PROJECT_EXPLORER_CONTEXT_MENU = "projectExplorerContextMenu";
String GROUP_EDITOR_TAB_CONTEXT_MENU = "editorTabContextMenu";
String GROUP_CONSOLES_TREE_CONTEXT_MENU = "consolesTreeContextMenu";
String GROUP_EDITOR_CONTEXT_MENU = "editorContextMenu";

String GROUP_OTHER_MENU = "otherMenu";
String GROUP_LEFT_MAIN_MENU = "leftMainMenu";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,18 @@ public void initialize() {
actionManager.registerAction("noOpAction", new NoOpAction());
actionManager.registerAction("signatureHelp", signatureHelpAction);

DefaultActionGroup editorContextMenuGroup = new DefaultActionGroup(actionManager);
actionManager.registerAction(IdeActions.GROUP_EDITOR_CONTEXT_MENU, editorContextMenuGroup);

editorContextMenuGroup.add(undoAction);
editorContextMenuGroup.add(redoAction);
editorContextMenuGroup.addSeparator();
editorContextMenuGroup.add(formatterAction);

editorContextMenuGroup.addSeparator();
editorContextMenuGroup.add(fullTextSearchAction);
editorContextMenuGroup.add(closeActiveEditorAction);

// Define hot-keys
keyBinding.getGlobal().addKey(new KeyBuilder().action().alt().charCode('n').build(), "navigateToFile");
keyBinding.getGlobal().addKey(new KeyBuilder().action().charCode('F').build(), "fullTextSearch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
import com.google.inject.Singleton;

import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.ActionGroup;
import org.eclipse.che.ide.api.action.ActionManager;
import org.eclipse.che.ide.api.action.ActionSelectedHandler;
import org.eclipse.che.ide.api.action.DefaultActionGroup;
import org.eclipse.che.ide.api.action.IdeActions;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.keybinding.KeyBindingAgent;
import org.eclipse.che.ide.api.parts.PerspectiveManager;
import org.eclipse.che.ide.ui.toolbar.CloseMenuHandler;
Expand Down Expand Up @@ -53,7 +51,6 @@ public class ContextMenu implements CloseMenuHandler, ActionSelectedHandler {
private PopupMenu popupMenu;
private MenuLockLayer lockLayer;

protected final DefaultActionGroup actions;
protected final PresentationFactory presentationFactory;

@Inject
Expand All @@ -63,7 +60,6 @@ public ContextMenu(ActionManager actionManager, KeyBindingAgent keyBindingAgent,
this.managerProvider = managerProvider;

presentationFactory = new PresentationFactory();
actions = new DefaultActionGroup(actionManager);

blockBrowserMenu();
}
Expand Down Expand Up @@ -94,7 +90,7 @@ public void onBrowserEvent(com.google.gwt.user.client.Event event) {
*/
public void show(int x, int y) {
hide();
updateActions();
ActionGroup actions = updateActions();

lockLayer = new MenuLockLayer(this);
popupMenu = new PopupMenu(actions,
Expand Down Expand Up @@ -123,24 +119,15 @@ private void calculatePosition(PopupMenu popupMenu, int x, int y) {
/**
* Updates the list of visible actions.
*/
private void updateActions() {
actions.removeAll();
protected ActionGroup updateActions() {


final ActionGroup mainActionGroup = (ActionGroup)actionManager.getAction(getGroupMenu());
if (mainActionGroup == null) {
return;
return new DefaultActionGroup(actionManager);
}

final Action[] children = mainActionGroup.getChildren(null);
for (final Action action : children) {
final Presentation presentation = presentationFactory.getPresentation(action);
final ActionEvent e = new ActionEvent(presentation, actionManager, managerProvider.get());

action.update(e);
if (presentation.isVisible()) {
actions.add(action);
}
}
return mainActionGroup;
}

protected String getGroupMenu() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.ActionGroup;
import org.eclipse.che.ide.api.action.ActionManager;
import org.eclipse.che.ide.api.action.DefaultActionGroup;
import org.eclipse.che.ide.api.action.IdeActions;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
Expand Down Expand Up @@ -57,8 +58,6 @@ public EditorTabContextMenu(@Assisted EditorTab editorTab,
this.editorPart = editorPart;
this.editorPartStack = editorPartStack;
this.actionManager = actionManager;

updateActions();
}

/** {@inheritDoc} */
Expand All @@ -67,10 +66,10 @@ protected String getGroupMenu() {
return IdeActions.GROUP_EDITOR_TAB_CONTEXT_MENU;
}

private void updateActions() {
protected ActionGroup updateActions() {
final ActionGroup mainActionGroup = (ActionGroup)actionManager.getAction(getGroupMenu());
if (mainActionGroup == null) {
return;
return new DefaultActionGroup(actionManager);
}

final Action[] children = mainActionGroup.getChildren(null);
Expand All @@ -81,5 +80,6 @@ private void updateActions() {
presentation.putClientProperty(CURRENT_TAB_PROP, editorTab);
presentation.putClientProperty(CURRENT_PANE_PROP, editorPartStack);
}
return super.updateActions();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.eclipse.che.ide.api.action.ActionManager;
import org.eclipse.che.ide.api.action.DefaultActionGroup;
import org.eclipse.che.ide.api.action.IdeActions;
import org.eclipse.che.ide.api.constraints.Anchor;
import org.eclipse.che.ide.api.constraints.Constraints;
import org.eclipse.che.ide.api.extension.Extension;
Expand Down Expand Up @@ -145,6 +146,14 @@ private void prepareActions(NewPackageAction newPackageAction,
mainContextMenuGroup.add(markDirectoryAsGroup);
mainContextMenuGroup.addSeparator();

DefaultActionGroup editorContextMenuGroup = (DefaultActionGroup)actionManager.getAction(IdeActions.GROUP_EDITOR_CONTEXT_MENU);

editorContextMenuGroup.add(quickDocumentationAction, new Constraints(Anchor.AFTER, "format"));
editorContextMenuGroup.add(quickFixAction, new Constraints(Anchor.AFTER, "showQuickDoc"));
editorContextMenuGroup.add(openDeclarationAction, new Constraints(Anchor.AFTER, "quickFix"));
editorContextMenuGroup.add(refactorGroup, new Constraints(Anchor.AFTER, "openJavaDeclaration"));
editorContextMenuGroup.add(fileStructureAction, new Constraints(Anchor.AFTER, GROUP_ASSISTANT_REFACTORING));

if (UserAgent.isMac()) {
keyBinding.getGlobal().addKey(new KeyBuilder().alt().control().charCode('b').build(), "openImplementation");
keyBinding.getGlobal().addKey(new KeyBuilder().control().charCode('j').build(), "showQuickDoc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ContextMenuEvent;
import com.google.gwt.event.dom.client.ContextMenuHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
Expand Down Expand Up @@ -118,6 +120,7 @@
import org.eclipse.che.ide.editor.orion.client.jso.OrionLinkedModelDataOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionLinkedModelGroupOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionLinkedModelOverlay;
import org.eclipse.che.ide.editor.orion.client.menu.EditorContextMenu;
import org.eclipse.che.ide.editor.orion.client.signature.SignatureHelpView;
import org.eclipse.che.ide.part.editor.multipart.EditorMultiPartStackPresenter;
import org.eclipse.che.ide.resource.Path;
Expand Down Expand Up @@ -171,15 +174,16 @@ public class OrionEditorPresenter extends AbstractEditorPresenter implements Tex
private final EditorMultiPartStackPresenter editorMultiPartStackPresenter;
private final EditorLocalizationConstants constant;
private final EditorWidgetFactory<OrionEditorWidget> editorWidgetFactory;
private final EditorInitializePromiseHolder editorModule;
private final TextEditorPartView editorView;
private final EventBus generalEventBus;
private final FileTypeIdentifier fileTypeIdentifier;
private final QuickAssistantFactory quickAssistantFactory;
private final WorkspaceAgent workspaceAgent;
private final NotificationManager notificationManager;
private final AppContext appContext;
private final SignatureHelpView signatureHelpView;
private final EditorInitializePromiseHolder editorModule;
private final TextEditorPartView editorView;
private final EventBus generalEventBus;
private final FileTypeIdentifier fileTypeIdentifier;
private final QuickAssistantFactory quickAssistantFactory;
private final WorkspaceAgent workspaceAgent;
private final NotificationManager notificationManager;
private final AppContext appContext;
private final SignatureHelpView signatureHelpView;
private final EditorContextMenu contextMenu;

private final AnnotationRendering rendering = new AnnotationRendering();
private HasKeyBindings keyBindingsManager;
Expand Down Expand Up @@ -218,7 +222,8 @@ public OrionEditorPresenter(final CodeAssistantFactory codeAssistantFactory,
final WorkspaceAgent workspaceAgent,
final NotificationManager notificationManager,
final AppContext appContext,
final SignatureHelpView signatureHelpView) {
final SignatureHelpView signatureHelpView,
final EditorContextMenu contextMenu) {
this.codeAssistantFactory = codeAssistantFactory;
this.deletedFilesController = deletedFilesController;
this.breakpointManager = breakpointManager;
Expand All @@ -238,6 +243,7 @@ public OrionEditorPresenter(final CodeAssistantFactory codeAssistantFactory,
this.notificationManager = notificationManager;
this.appContext = appContext;
this.signatureHelpView = signatureHelpView;
this.contextMenu = contextMenu;

keyBindingsManager = new TemporaryKeyBindingsManager();

Expand Down Expand Up @@ -1055,6 +1061,13 @@ public void onContentInitialized() {
isInitialized = true;
}
});

editorWidget.addDomHandler(new ContextMenuHandler() {
@Override
public void onContextMenu(ContextMenuEvent event) {
contextMenu.show(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
}
}, ContextMenuEvent.getType());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.editor.orion.client.menu;

import com.google.inject.Provider;

import org.eclipse.che.ide.api.action.ActionManager;
import org.eclipse.che.ide.api.action.IdeActions;
import org.eclipse.che.ide.api.keybinding.KeyBindingAgent;
import org.eclipse.che.ide.api.parts.PerspectiveManager;
import org.eclipse.che.ide.menu.ContextMenu;

import javax.inject.Inject;

/**
* Editor context menu, shows {@link IdeActions#GROUP_EDITOR_CONTEXT_MENU} action group.
*/
public class EditorContextMenu extends ContextMenu {

@Inject
public EditorContextMenu(ActionManager actionManager,
KeyBindingAgent keyBindingAgent,
Provider<PerspectiveManager> managerProvider) {
super(actionManager, keyBindingAgent, managerProvider);
}


@Override
protected String getGroupMenu() {
return IdeActions.GROUP_EDITOR_CONTEXT_MENU;
}
}

0 comments on commit 4354142

Please sign in to comment.