private DefaultActionGroup createGearPopupGroup() {
    final DefaultActionGroup group = new DefaultActionGroup();

    if (myAdditionalGearActions != null) {
      addSorted(group, myAdditionalGearActions);
      group.addSeparator();
    }
    group.addAction(myToggleToolbarGroup).setAsSecondary(true);
    if (myInfo.isDocked()) {
      group.add(myToggleAutoHideModeAction);
      group.add(myToggleDockModeAction);
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
      group.add(myToggleSideModeAction);
    } else if (myInfo.isFloating()) {
      group.add(myToggleAutoHideModeAction);
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
    } else if (myInfo.isWindowed()) {
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
    } else if (myInfo.isSliding()) {
      if (!ToolWindowId.PREVIEW.equals(myInfo.getId())) {
        group.add(myToggleDockModeAction);
      }
      group.add(myToggleFloatingModeAction);
      group.add(myToggleWindowedModeAction);
      group.add(myToggleSideModeAction);
    }
    return group;
  }
 private static void addSorted(DefaultActionGroup main, ActionGroup group) {
   final AnAction[] children = group.getChildren(null);
   boolean hadSecondary = false;
   for (AnAction action : children) {
     if (group.isPrimary(action)) {
       main.add(action);
     } else {
       hadSecondary = true;
     }
   }
   if (hadSecondary) {
     main.addSeparator();
     for (AnAction action : children) {
       if (!group.isPrimary(action)) {
         main.addAction(action).setAsSecondary(true);
       }
     }
   }
   String separatorText = group.getTemplatePresentation().getText();
   if (children.length > 0 && !StringUtil.isEmpty(separatorText)) {
     main.addAction(new Separator(separatorText), Constraints.FIRST);
   }
 }