From 8b7021ba8b94680099f8f739f79dcea72729eeb7 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 1 Dec 2022 01:00:12 +0100 Subject: Fluid: Keep widget panel open during undo/redo (#566) --- fluid/Fl_Widget_Type.cxx | 2 +- fluid/undo.cxx | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fluid/Fl_Widget_Type.cxx b/fluid/Fl_Widget_Type.cxx index 6c9529bc8..26e407235 100644 --- a/fluid/Fl_Widget_Type.cxx +++ b/fluid/Fl_Widget_Type.cxx @@ -295,7 +295,7 @@ Fl_Type *sort(Fl_Type *parent) { //////////////////////////////////////////////////////////////// // The control panels! -static Fl_Window *the_panel; +Fl_Window *the_panel; // All the callbacks use the argument to indicate whether to load or store. // This avoids the need for pointers to all the widgets, and keeps the diff --git a/fluid/undo.cxx b/fluid/undo.cxx index b7377b89f..4f0b18cec 100644 --- a/fluid/undo.cxx +++ b/fluid/undo.cxx @@ -19,9 +19,11 @@ #include "fluid.h" #include "file.h" #include "Fl_Type.h" +#include "Fl_Widget_Type.h" #include "widget_browser.h" #include +#include #include #include #include @@ -43,6 +45,7 @@ // checkpoint files. // +extern Fl_Window* the_panel; int undo_current = 0; // Current undo level in buffer int undo_last = 0; // Last undo level in buffer @@ -80,12 +83,21 @@ void redo_cb(Fl_Widget *, void *) { if (undo_current >= undo_last) return; undo_suspend(); + if (widget_browser) widget_browser->save_scroll_position(); + int reload_panel = (the_panel && the_panel->visible()); if (!read_file(undo_filename(undo_current + 1), 0)) { // Unable to read checkpoint file, don't redo... widget_browser->rebuild(); undo_resume(); return; } + if (reload_panel) { + for (Fl_Type *t = Fl_Type::first; t; t=t->next) { + if (t->is_widget() && t->selected) + t->open(); + } + } + if (widget_browser) widget_browser->restore_scroll_position(); undo_current ++; @@ -113,12 +125,19 @@ void undo_cb(Fl_Widget *, void *) { // Undo first deletes all widgets which resets the widget_tree browser. // Save the current scroll position, so we don't scroll back to 0 at undo. if (widget_browser) widget_browser->save_scroll_position(); + int reload_panel = (the_panel && the_panel->visible()); if (!read_file(undo_filename(undo_current - 1), 0)) { // Unable to read checkpoint file, don't undo... widget_browser->rebuild(); undo_resume(); return; } + if (reload_panel) { + for (Fl_Type *t = Fl_Type::first; t; t=t->next) { + if (t->is_widget() && t->selected) + t->open(); + } + } // Restore old browser position. // Ideally, we would save the browser position insied the undo file. if (widget_browser) widget_browser->restore_scroll_position(); -- cgit v1.2.3