Skip to content

Commit

Permalink
Fixes Issue #3114 by adding a platform wide menu for "New ... "
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Sep 3, 2021
1 parent 871086c commit 39aea54
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 36 deletions.
3 changes: 2 additions & 1 deletion ummisco.gama.ui.modeling/META-INF/MANIFEST.MF
Expand Up @@ -26,7 +26,8 @@ Require-Bundle: msi.gama.lang.gaml;visibility:=reexport,
org.eclipse.emf.ecore,
msi.gama.ext,
org.eclipse.ui.workbench,
org.apache.commons.lang;bundle-version="2.6.0"
org.apache.commons.lang;bundle-version="2.6.0",
org.eclipse.ui.navigator;bundle-version="3.10.100"
Export-Package: msi.gama.lang.gaml.ide,
msi.gama.lang.gaml.ide.contentassist.antlr,
msi.gama.lang.gaml.ide.contentassist.antlr.internal,
Expand Down
@@ -1,20 +1,26 @@
/*********************************************************************************************
/*******************************************************************************************************
*
* 'GamlEditorBindings.java, in plugin ummisco.gama.ui.modeling, is part of the source code of the GAMA modeling and
* simulation platform. (v. 1.8.1)
* GamlEditorBindings.java, in ummisco.gama.ui.modeling, is part of the source code of the GAMA modeling and simulation
* platform (v.2.0.0).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
**********************************************************************************************/
********************************************************************************************************/
package msi.gama.lang.gaml.ui.editor;

import static msi.gama.common.interfaces.IGui.NAVIGATOR_VIEW_ID;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IWorkbenchPage;

import ummisco.gama.ui.bindings.GamaKeyBindings;
import ummisco.gama.ui.bindings.GamaKeyBindings.PluggableBinding;
import ummisco.gama.ui.navigator.GamaNavigator;
import ummisco.gama.ui.navigator.GamaNavigatorNewMenu;
import ummisco.gama.ui.utils.WorkbenchHelper;
import ummisco.gama.ui.views.IGamlEditor;

Expand All @@ -27,19 +33,46 @@
*/
public class GamlEditorBindings {

/** The Constant MODIFIERS. */
public static final int MODIFIERS = SWT.SHIFT + SWT.ALT;

/**
* Install.
*/
public static void install() {

GamaKeyBindings.plug(new PluggableBinding(SWT.MOD1, 'g') {

@Override
public void run() {
final IGamlEditor editor = WorkbenchHelper.getActiveEditor();
if (!(editor instanceof GamlEditor)) { return; }
if (!(editor instanceof GamlEditor)) return;
((GamlEditor) editor).doSearch();
}
});

GamaKeyBindings.plug(new PluggableBinding(SWT.ALT + GamaKeyBindings.COMMAND, 'n') {

GamaNavigator navigator;

private GamaNavigator getNavigator() {
if (navigator == null) {
final IWorkbenchPage page = WorkbenchHelper.getPage();
if (page != null) { navigator = (GamaNavigator) page.findView(NAVIGATOR_VIEW_ID); }
}
return navigator;
}

@Override
public void run() {
final Point p = WorkbenchHelper.getDisplay().getCursorLocation();
IStructuredSelection s = getNavigator().getSelection();
GamaNavigatorNewMenu menu = new GamaNavigatorNewMenu(s);
menu.open(p);
// final Control c = WorkbenchHelper.getDisplay().getCursorControl();
}
});

// for (int i = 0; i < 9; i++) {
// GamaKeyBindings.plug(newBinding(i));
// }
Expand Down
@@ -1,9 +1,9 @@
/*******************************************************************************************************
*
* ummisco.gama.ui.navigator.GamaNavigator.java, in plugin ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform (v. 1.8.1)
* GamaNavigator.java, in ummisco.gama.ui.navigator, is part of the source code of the GAMA modeling and simulation
* platform (v.2.0.0).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
Expand Down Expand Up @@ -63,13 +63,28 @@
import ummisco.gama.ui.views.toolbar.IToolbarDecoratedView;
import ummisco.gama.ui.views.toolbar.Selector;

/**
* The Class GamaNavigator.
*/
public class GamaNavigator extends CommonNavigator
implements IToolbarDecoratedView, ISelectionChangedListener, IToolbarDecoratedView.Expandable {

/** The link. */
IAction link;

/** The link item. */
ToolItem linkItem;

/** The parent. */
protected Composite parent;

/** The toolbar. */
protected GamaToolbar2 toolbar;

/** The properties. */
private PropertyDialogAction properties;

/** The find control. */
private NavigatorSearchControl findControl;

@Override
Expand Down Expand Up @@ -134,6 +149,9 @@ public void saveState(final IMemento newMemento) {
super.saveState(newMemento);
}

/**
* Restore state.
*/
private void restoreState() {
if (memento == null) return;
final String saved = memento.getString("EXPANDED_STATE");
Expand Down Expand Up @@ -196,9 +214,7 @@ protected CommonViewer createCommonViewerObject(final Composite aParent) {
}

@Override
protected Object getInitialInput() {
return NavigatorRoot.getInstance();
}
protected Object getInitialInput() { return NavigatorRoot.getInstance(); }

@Override
protected void handleDoubleClick(final DoubleClickEvent anEvent) {
Expand Down Expand Up @@ -234,6 +250,7 @@ protected void fillViewMenu(final IMenuManager menu) {
};
}

/** The by date. */
final GamaCommand byDate = new GamaCommand("action.toolbar.sort2", "", "Sort by modification date", trigger -> {
final boolean enabled = ((ToolItem) trigger.widget).getSelection();

Expand All @@ -249,6 +266,7 @@ protected void fillViewMenu(final IMenuManager menu) {

});

/** The link command. */
final GamaCommand linkCommand =
new GamaCommand("navigator/navigator.link3", "", "Stay in sync with the editor", e -> link.run());

Expand Down Expand Up @@ -290,6 +308,12 @@ public void selectionChanged(final SelectionChangedEvent event) {
showStatus(element);
}

/**
* Show status.
*
* @param element
* the element
*/
private void showStatus(final VirtualContent<?> element) {
final String message = element.getStatusMessage();
final String tooltip = element.getStatusTooltip();
Expand All @@ -303,13 +327,18 @@ private void showStatus(final VirtualContent<?> element) {
@Override
public void expandAll() {
getCommonViewer().expandAll();

}

@Override
public void collapseAll() {
getCommonViewer().collapseAll();

}

/**
* Gets the selection.
*
* @return the selection
*/
public IStructuredSelection getSelection() { return getCommonViewer().getStructuredSelection(); }

}
@@ -1,15 +1,13 @@
/*********************************************************************************************
/*******************************************************************************************************
*
* 'GamaNavigatorMenu.java, in plugin ummisco.gama.ui.navigator, is part of the source code of the
* GAMA modeling and simulation platform.
* (v. 1.8.1)
* GamaNavigatorMenu.java, in ummisco.gama.ui.navigator, is part of the source code of the GAMA modeling and simulation
* platform (v.2.0.0).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
**********************************************************************************************/
********************************************************************************************************/
package ummisco.gama.ui.navigator;

import org.eclipse.core.runtime.CoreException;
Expand All @@ -29,43 +27,55 @@

/**
* Class GamaNavigatorMenu.
*
*
* @author drogoul
* @since 8 mars 2015
*
*
*/
public abstract class GamaNavigatorMenu extends GamaMenu {

@Override
public void open(final Control c, final SelectionEvent trigger) {
final Point point = c.toDisplay(new Point(trigger.x, trigger.y));
open(point);
}

/**
* Open.
*
* @param point
* the point
*/
public void open(final Point point) {
if (mainMenu == null) {
mainMenu = new Menu(WorkbenchHelper.getShell(), SWT.POP_UP);
fillMenu();
}

final Point point = c.toDisplay(new Point(trigger.x, trigger.y));
mainMenu.setLocation(point.x, point.y);
mainMenu.setVisible(true);
}

/**
*
*
*/
@Override
protected abstract void fillMenu();

/**
* Open wizard.
*
* @param id
* the id
* @param selection
* the selection
*/
public static void openWizard(final String id, final IStructuredSelection selection) {
// First see if this is a "new wizard".
IWizardDescriptor descriptor = PlatformUI.getWorkbench().getNewWizardRegistry().findWizard(id);
// If not check if it is an "import wizard".
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(id);
}
if (descriptor == null) { descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(id); }
// Or maybe an export wizard
if (descriptor == null) {
descriptor = PlatformUI.getWorkbench().getExportWizardRegistry().findWizard(id);
}
if (descriptor == null) { descriptor = PlatformUI.getWorkbench().getExportWizardRegistry().findWizard(id); }
try {
// Then if we have a wizard, open it.
if (descriptor != null) {
Expand Down

0 comments on commit 39aea54

Please sign in to comment.