Grouping of plug-in actions

This topic has been viewed 8311 times and has 3 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Grouping of plug-in actions

Post by enkonyito »

Is it possible to group the plug-in actions on the Tools menu as actions "Create photo...", "Create photos at points of view..." and "Create video..." of the 3D View menu?
By default, all actions of a plug-in are separated in Tools menu.
EnkoNyito
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Grouping of plug-in actions

Post by Puybaret »

Not in the current version, since a separator is added before each plug-in menu item.
I guess it would be nice, but specifying groups of menu items might not be so easy to implement. If you have a simple idea, please share it.
Emmanuel Puybaret, Sweet Home 3D creator
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Grouping of plug-in actions

Post by enkonyito »

I thought that adding a loop with the list of plug-ins to put a separator after the last action of a menu would work.
A plug-in as AdvancedEditing can have several actions divided in different menus so it is not easy to group them by menu.
EnkoNyito
enkonyito
Posts: 607
Joined: Thu May 28, 2015 4:52 pm

Re: Grouping of plug-in actions

Post by enkonyito »

What do you think about this?

Code: Select all

    // Add menus to menu bar
    JMenuBar menuBar = new JMenuBar();
    fileMenu.addSeparator(); // test (enkonyito)
    menuBar.add(fileMenu);
    editMenu.addSeparator(); // test (enkonyito)
    menuBar.add(editMenu);
    furnitureMenu.addSeparator(); // test (enkonyito)
    menuBar.add(furnitureMenu);
    if (controller.getPlanController().getView() != null) {
      planMenu.addSeparator(); // test (enkonyito)
      menuBar.add(planMenu);
    }
    if (controller.getHomeController3D().getView() != null) {
      preview3DMenu.addSeparator(); // test (enkonyito)
      menuBar.add(preview3DMenu);
    }
    menuBar.add(helpMenu);

    // Add plugin actions menu items
    // debut test (enkonyito)
    // Create missing menu
    for (Action pluginAction : this.pluginActions) {
      String pluginMenu = (String)pluginAction.getValue(PluginAction.Property.MENU.name());
      if (pluginMenu != null) {
        boolean pluginMenuExisting = false;
        for (int i = 0; i < menuBar.getMenuCount(); i++) {
          JMenu menu = menuBar.getMenu(i);
          if (menu.getText().equals(pluginMenu)) {
            pluginMenuExisting = true;
            break;
          }
        }
        if (!pluginMenuExisting) {
          // Create missing menu before last menu
          JMenu menu = new JMenu(pluginMenu);
          menuBar.add(menu, menuBar.getMenuCount() - 1);
        }
      }
    }
    // Group plug-in actions by menu
    for (int i = 0; i < menuBar.getMenuCount(); i++) {
      JMenu menu = menuBar.getMenu(i);
      for (Plugin plugin : this.plugins) {
        boolean pluginActionAdded = false;
        createActionsPlugin(plugin);
        for (Action pluginAction : this.actionsPlugin) {
          String pluginMenu = (String)pluginAction.getValue(PluginAction.Property.MENU.name());
          if (pluginMenu != null) {
            if (menu.getText().equals(pluginMenu)) {
              // Add menu item to existing menu
              menu.add(new ResourceAction.MenuItemAction(pluginAction));
              pluginActionAdded = true;
            }
          }
        }
        if (pluginActionAdded) {
          menu.addSeparator();
        }
      } 
    }
    // fin test (enkonyito)
  
  //debut test (enkonyito)
  private void createActionsPlugin(Plugin plugin) {
    this.actionsPlugin = new ArrayList<Action>();
    if (plugin != null) {
      for (final PluginAction pluginAction : plugin.getActions()) {
        // Create a Swing action adapter to plug-in action
        this.actionsPlugin.add(new ActionAdapter(pluginAction)); 
      }
    }
  }
  //fin test (enkonyito)
before
Image

after
Image
EnkoNyito
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 2 guests