summaryrefslogtreecommitdiff
path: root/fluid/Fl_Menu_Type.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2024-08-31 19:08:12 +0200
committerMatthias Melcher <github@matthiasm.com>2024-08-31 19:08:18 +0200
commitc8b8eb4b840bc612f2f2160a8b2cc27f030c5785 (patch)
treefe99195345f9732248ae3225a10d992d85c297f0 /fluid/Fl_Menu_Type.cxx
parent1da9438a1c29429c231d90167f996b3f840eb3e2 (diff)
FLUID: Fixes grouping and ungrouping, #1056
- grouping a bunch of widgets will now create the new group in the expected place - also add grouping and ungrouping of menu items - ungrouping now also works with only a few items selected instead all items, moving the selection before the group
Diffstat (limited to 'fluid/Fl_Menu_Type.cxx')
-rw-r--r--fluid/Fl_Menu_Type.cxx61
1 files changed, 61 insertions, 0 deletions
diff --git a/fluid/Fl_Menu_Type.cxx b/fluid/Fl_Menu_Type.cxx
index bf88d57eb..277ce78d8 100644
--- a/fluid/Fl_Menu_Type.cxx
+++ b/fluid/Fl_Menu_Type.cxx
@@ -29,6 +29,8 @@
#include "Fluid_Image.h"
#include "custom_widgets.h"
#include "mergeback.h"
+#include "undo.h"
+#include "widget_browser.h"
#include <FL/Fl.H>
#include <FL/fl_message.H>
@@ -175,6 +177,65 @@ Fl_Type *Fl_Menu_Item_Type::make(Strategy strategy) {
return t;
}
+void group_selected_menuitems() {
+ // The group will be created in the parent group of the current menuitem
+ Fl_Type *qq = Fl_Type::current->parent;
+ Fl_Widget_Type *q = static_cast<Fl_Widget_Type*>(Fl_Type::current);
+ if (!qq || !(qq->is_a(ID_Menu_Manager_) || qq->is_a(ID_Submenu))) {
+ fl_message("Can't create a new group here.");
+ return;
+ }
+ undo_checkpoint();
+ undo_suspend();
+ submenuflag = 1;
+ Fl_Widget_Type *n = (Fl_Widget_Type*)(q->make(kAddAfterCurrent));
+ submenuflag = 0;
+ for (Fl_Type *t = qq->next; t && (t->level > qq->level);) {
+ if (t->level != n->level || t == n || !t->selected) {
+ t = t->next;
+ continue;
+ }
+ Fl_Type *nxt = t->remove();
+ t->add(n, kAddAsLastChild);
+ t = nxt;
+ }
+ widget_browser->rebuild();
+ undo_resume();
+ set_modflag(1);
+}
+
+void ungroup_selected_menuitems() {
+ // Find the submenu
+ Fl_Type *qq = Fl_Type::current->parent;
+ Fl_Widget_Type *q = static_cast<Fl_Widget_Type*>(Fl_Type::current);
+ int q_level = q->level;
+ if (!qq || !qq->is_a(ID_Submenu)) {
+ fl_message("Only menu items inside a submenu can be ungrouped.");
+ return;
+ }
+ undo_checkpoint();
+ undo_suspend();
+ Fl_Type::current = qq;
+ for (Fl_Type *t = qq->next; t && (t->level > qq->level);) {
+ if (t->level != q_level || !t->selected) {
+ t = t->next;
+ continue;
+ }
+ Fl_Type *nxt = t->remove();
+ t->insert(qq);
+ t = nxt;
+ }
+ if (!qq->next || (qq->next->level <= qq->level)) {
+ qq->remove();
+ delete qq; // qq has no children that need to be delete
+ }
+ Fl_Type::current = q;
+ widget_browser->rebuild();
+ undo_resume();
+ set_modflag(1);
+}
+
+
/**
Create and add a new Checkbox Menu Item node.
\param[in] strategy add after current or as last child