summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2024-09-14 23:04:27 +0200
committerMatthias Melcher <github@matthiasm.com>2024-09-14 23:04:27 +0200
commit4ff85176c9df17dfd2d734dc394afdc9d50817f7 (patch)
tree07ccd5f2c590d09f789f5d57d9a61e758207ddd2 /fluid
parent382d6b2fbdb441ef8cbbe52a7dc07032aa733188 (diff)
FLUID: Improved insertion point for `duplicate`
Make a better guess where nodes should go when duplicating a branch of the scene graph
Diffstat (limited to 'fluid')
-rw-r--r--fluid/fluid.cxx23
1 files changed, 21 insertions, 2 deletions
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index e690c5f7e..ef17dc041 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -1355,6 +1355,7 @@ void copy_cb(Fl_Widget*, void*) {
fl_beep();
return;
}
+ flush_text_widgets();
ipasteoffset = 10;
if (!write_file(cutfname(),1)) {
fl_message("Can't write %s: %s", cutfname(), strerror(errno));
@@ -1370,6 +1371,7 @@ void cut_cb(Fl_Widget *, void *) {
fl_beep();
return;
}
+ flush_text_widgets();
if (!write_file(cutfname(),1)) {
fl_message("Can't write %s: %s", cutfname(), strerror(errno));
return;
@@ -1410,7 +1412,7 @@ void paste_cb(Fl_Widget*, void*) {
undo_checkpoint();
undo_suspend();
Strategy strategy = kAddAfterCurrent;
- if (Fl_Type::current && Fl_Type::current->is_a(ID_Group)) {
+ if (Fl_Type::current && Fl_Type::current->can_have_children()) {
Fl_Group_Type *current_group = static_cast<Fl_Group_Type*>(Fl_Type::current);
if (current_group->folded_ == 0) {
strategy = kAddAsLastChild;
@@ -1435,9 +1437,11 @@ void duplicate_cb(Fl_Widget*, void*) {
fl_beep();
return;
}
-
flush_text_widgets();
+ bool find_insert_position = false;
+ if (Fl_Type::current->selected) find_insert_position = true;
+
if (!write_file(cutfname(1),1)) {
fl_message("Can't write %s: %s", cutfname(1), strerror(errno));
return;
@@ -1445,6 +1449,21 @@ void duplicate_cb(Fl_Widget*, void*) {
pasteoffset = 0;
+ // Find the last selected node with the lowest level
+ int lowest_level = 9999;
+ Fl_Type *new_insert = NULL;
+ if (find_insert_position) {
+ for (Fl_Type *t = Fl_Type::first; t; t = t->next) {
+ if (t->selected && (t->level <= lowest_level)) {
+ lowest_level = t->level;
+ new_insert = t;
+ }
+ }
+ }
+ if (new_insert)
+ Fl_Type::current = new_insert;
+
+
undo_checkpoint();
undo_suspend();
if (!read_file(cutfname(1), 1, kAddAfterCurrent)) {