use of org.freeplane.core.ui.IMenuContributor in project freeplane by freeplane.
the class Activator method start.
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(final BundleContext context) throws Exception {
final Hashtable<String, String[]> props = new Hashtable<String, String[]>();
props.put("mode", new String[] { MModeController.MODENAME /*TODO: other modes too?*/
});
context.registerService(IModeControllerExtensionProvider.class.getName(), new IModeControllerExtensionProvider() {
@Override
public void installExtension(ModeController modeController) {
final MenuBuilder menuBuilder = modeController.getUserInputListenerFactory().getMenuBuilder(MenuBuilder.class);
final $$$$Action action = new $$$$Action();
modeController.addAction(action);
modeController.addMenuContributor(new IMenuContributor() {
@Override
public void updateMenus(ModeController modeController, MenuBuilder builder) {
menuBuilder.addAction("/menu_bar/file", action, MenuBuilder.AS_CHILD);
}
});
}
}, props);
}
use of org.freeplane.core.ui.IMenuContributor in project freeplane by freeplane.
the class ModeController method updateMenus.
public void updateMenus(String menuStructure, final Set<String> plugins) {
final IUserInputListenerFactory userInputListenerFactory = getUserInputListenerFactory();
userInputListenerFactory.getAcceleratorManager().loadDefaultAcceleratorPresets();
userInputListenerFactory.updateMenus(menuStructure, plugins);
final MenuBuilder menuBuilder = userInputListenerFactory.getMenuBuilder(MenuBuilder.class);
final Iterator<IMenuContributor> iterator = menuContributors.iterator();
while (iterator.hasNext()) {
iterator.next().updateMenus(this, menuBuilder);
}
}
use of org.freeplane.core.ui.IMenuContributor in project freeplane by freeplane.
the class MModeWorkspaceController method setupController.
private void setupController(ModeController modeController) {
modeController.removeExtension(UrlManager.class);
UrlManager.install(new MModeWorkspaceUrlManager());
modeController.removeExtension(LinkController.class);
LinkController.install(MModeWorkspaceLinkController.getController());
// add link type entry to the chooser
MModeWorkspaceLinkController.getController().prepareOptionPanelBuilder(((MModeController) modeController).getOptionPanelBuilder());
modeController.addINodeViewLifeCycleListener(new INodeViewLifeCycleListener() {
public void onViewCreated(Container nodeView) {
NodeView node = (NodeView) nodeView;
final DropTarget dropTarget = new DropTarget(node.getMainView(), new MNodeDropListener() {
public void drop(final DropTargetDropEvent dtde) {
DropTargetDropEvent evt = dtde;
if (dtde.getTransferable().isDataFlavorSupported(WorkspaceTransferable.WORKSPACE_NODE_FLAVOR)) {
evt = new DropTargetDropEvent(dtde.getDropTargetContext(), dtde.getLocation(), dtde.getDropAction(), dtde.getSourceActions(), false);
}
super.drop(evt);
}
});
dropTarget.setActive(true);
}
public void onViewRemoved(Container nodeView) {
}
});
modeController.addMenuContributor(new IMenuContributor() {
public void updateMenus(ModeController modeController, MenuBuilder builder) {
final String MENU_PROJECT_KEY = "/menu_bar/project";
// insert project menu into main menu
JMenu projectMenu = new JMenu(TextUtils.getText("menu.project.entry.label"));
projectMenu.setMnemonic('o');
builder.addMenuItem("/menu_bar/format", projectMenu, MENU_PROJECT_KEY, MenuBuilder.AFTER);
builder.addAction(MENU_PROJECT_KEY, WorkspaceController.getAction(WorkspaceNewProjectAction.KEY), MenuBuilder.AS_CHILD);
builder.addAction(MENU_PROJECT_KEY, WorkspaceController.getAction(WorkspaceImportProjectAction.KEY), MenuBuilder.AS_CHILD);
builder.addSeparator(MENU_PROJECT_KEY, MenuBuilder.AS_CHILD);
final String MENU_PROJECT_ADD_KEY = builder.getMenuKey(MENU_PROJECT_KEY, "new");
final JMenu addMenu = new JMenu(TextUtils.getText("workspace.action.new.label"));
builder.addMenuItem(MENU_PROJECT_KEY, addMenu, MENU_PROJECT_ADD_KEY, MenuBuilder.AS_CHILD);
builder.addAction(MENU_PROJECT_ADD_KEY, new NodeNewFolderAction(), MenuBuilder.AS_CHILD);
builder.addAction(MENU_PROJECT_ADD_KEY, new NodeNewLinkAction(), MenuBuilder.AS_CHILD);
final WorkspaceRemoveProjectAction rmProjectAction = new WorkspaceRemoveProjectAction();
builder.addAction(MENU_PROJECT_KEY, rmProjectAction, MenuBuilder.AS_CHILD);
builder.addSeparator(MENU_PROJECT_KEY, MenuBuilder.AS_CHILD);
setDefaultAccelerator(builder.getShortcutKey(builder.getMenuKey(MENU_PROJECT_KEY, WorkspaceProjectOpenLocationAction.KEY)), "control alt L");
final WorkspaceProjectOpenLocationAction openLocAction = new WorkspaceProjectOpenLocationAction();
builder.addAction(MENU_PROJECT_KEY, openLocAction, MenuBuilder.AS_CHILD);
projectMenu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
rmProjectAction.setEnabled();
openLocAction.setEnabled();
if (WorkspaceController.getCurrentProject() == null) {
addMenu.setEnabled(false);
} else {
addMenu.setEnabled(true);
}
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
}
private void setDefaultAccelerator(final String shortcutKey, String accelerator) {
if (accelerator != null) {
if (null == ResourceController.getResourceController().getProperty(shortcutKey, null)) {
if (Compat.isMacOsX()) {
accelerator = accelerator.replaceFirst("CONTROL", "META").replaceFirst("control", "meta");
}
ResourceController.getResourceController().setDefaultProperty(shortcutKey, accelerator);
}
}
}
});
}
Aggregations