From e8931bf4bfd0be05b205ef81a6635d1659151ccd Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 5 Oct 2018 18:26:26 +0200 Subject: [PATCH] NotificationDisplay: react on changes of the error state this turned out to be more tricky than expected. When we initially configure the UI and invoke this->show_all(), seemingly some draw-callbacks will be scheduled into the event loop. Just set_visible(false) on the relevant buttons directly after that call will have no effect (since the widget is still hidden at that point anyway, it is not yet mapped and realised). Thus we need to schedule a callback with the Glib::signal_idle(), so our state detection runs after the initial mapping of the UI NOTE: there is a minor itch, which I don't address right now: when adding the error state and thus revealing the additional buttons, the error log grabs some additional horizontal space, even while there would be ample space for the additional buttons within the button bar. When the error state is cleared and the buttons thus hidden again, the additional horizontal space is dropped and the error log gets narrower. Probably we'd need some special GTK call to re-allocate the required space properly --- src/gui/panel/infobox-panel.cpp | 56 +++++++++----- src/gui/panel/infobox-panel.hpp | 4 +- src/gui/widget/error-log-display.hpp | 8 +- wiki/thinkPad.ichthyo.mm | 107 +++++++++++++++------------ 4 files changed, 102 insertions(+), 73 deletions(-) diff --git a/src/gui/panel/infobox-panel.cpp b/src/gui/panel/infobox-panel.cpp index 3d9668ace..8e4aa66dd 100644 --- a/src/gui/panel/infobox-panel.cpp +++ b/src/gui/panel/infobox-panel.cpp @@ -28,10 +28,7 @@ #include "gui/gtk-base.hpp" #include "gui/panel/infobox-panel.hpp" #include "gui/widget/error-log-display.hpp" -#include "lib/format-string.hpp" -using util::_Fmt; -using Glib::ustring; namespace gui { namespace panel{ @@ -43,8 +40,8 @@ namespace panel{ : Panel(panelManager, dockItem, getTitle(), getStockID()) , twoParts_{Gtk::ORIENTATION_VERTICAL} , buttons_{} - , frame_{"UI Integration Experiments"} - , logExpander_{"Error Log"} + , frame_{_("System Information")} + , logExpander_{_("Error Log")} , theLog_{} { twoParts_.pack_start(frame_); @@ -52,20 +49,41 @@ namespace panel{ buttons_.set_layout (Gtk::BUTTONBOX_START); - // buttons to trigger experiments - button_1_.set_label ("_bang"); - button_1_.set_use_underline(); - button_1_.set_tooltip_markup ("Experiment 1:\ntrigger Proc-GUI roundtrip"); - button_1_.signal_clicked().connect( - mem_fun(*this, &InfoBoxPanel::experiment_1)); - buttons_.add (button_1_); + // buttons to control the error log + buttonClear_.set_label (_("_clear Log")); + buttonClear_.set_use_underline(); + buttonClear_.set_tooltip_markup (_("Discard all contents of the error log.")); + buttonClear_.signal_clicked().connect( + [this](){ if (theLog_) theLog_->clearAll(); }); + buttonClearErr_.set_label (_("_Error OK")); + buttonClearErr_.set_use_underline(); + buttonClearErr_.set_tooltip_markup (_("Clear the error state and turn errors in to information entries.")); + buttonClearErr_.signal_clicked().connect( + [this](){ if (theLog_) theLog_->turnError_into_InfoMsg(); }); + buttonClearInfo_.set_label (_("drop _Info")); + buttonClearInfo_.set_use_underline(); + buttonClearInfo_.set_tooltip_markup (_("Discard all mere info message, retain error entries only.")); + buttonClearInfo_.signal_clicked().connect( + [this](){ if (theLog_) theLog_->clearInfoMsg(); }); + + buttons_.add (buttonClear_); + buttons_.add (buttonClearErr_); + buttons_.add (buttonClearInfo_); //(End)buttons... // show initial configuration.... this->add (twoParts_); this->show_all(); + + // schedule state update to hide the error related buttons + // after the UI is actually mapped to screen. + Glib::signal_idle() + .connect_once ( sigc::bind( + sigc::mem_fun(*this, &InfoBoxPanel::reflect_LogErrorState), false + )); } + const char* InfoBoxPanel::getTitle() { @@ -104,20 +122,20 @@ namespace panel{ frame_.set_border_width (5); frame_.add (logExpander_); frame_.show_all(); + + theLog_->signalErrorChanged().connect( + mem_fun(*this, &InfoBoxPanel::reflect_LogErrorState)); } return *theLog_; } void - InfoBoxPanel::experiment_1() + InfoBoxPanel::reflect_LogErrorState (bool isError) { - frame_.set_label("Experiment 1... BANG"); - - static uint bangNo{0}; - static _Fmt msgTemplate{"Bang #%d\n"}; - - getLog().addError (msgTemplate % ++bangNo); + buttonClearErr_.set_visible (isError); + buttonClearInfo_.set_visible (isError); + INFO (gui, "Error = %d", isError); } diff --git a/src/gui/panel/infobox-panel.hpp b/src/gui/panel/infobox-panel.hpp index e000252a1..b7e0907c5 100644 --- a/src/gui/panel/infobox-panel.hpp +++ b/src/gui/panel/infobox-panel.hpp @@ -66,13 +66,13 @@ namespace panel{ private: Gtk::Box twoParts_; Gtk::ButtonBox buttons_; - Gtk::Button button_1_; + Gtk::Button buttonClear_, buttonClearInfo_, buttonClearErr_; Gtk::Frame frame_; Gtk::Expander logExpander_; std::unique_ptr theLog_; - void experiment_1(); + void reflect_LogErrorState (bool); }; diff --git a/src/gui/widget/error-log-display.hpp b/src/gui/widget/error-log-display.hpp index d33f87aa8..358c9e1ea 100644 --- a/src/gui/widget/error-log-display.hpp +++ b/src/gui/widget/error-log-display.hpp @@ -66,6 +66,7 @@ #include "include/gui-notification-facade.h" #include "lib/format-string.hpp" #include "lib/symbol.hpp" +#include "lib/util.hpp" #include #include @@ -75,6 +76,7 @@ namespace gui { namespace widget { + using util::max; using util::_Fmt; using lib::Literal; using std::make_pair; @@ -164,14 +166,14 @@ namespace widget { bool shallNotify = not errorMarks_.empty(); errorMarks_.clear(); - size_t lineCnt = textLog_.get_buffer()->get_line_count(); + size_t lineCnt = max (0, textLog_.get_buffer()->get_line_count() - 1); string placeholder; if (lineCnt > 0) placeholder = _Fmt{_("───════ %d preceding lines removed ════───\n")} % lineCnt; textLog_.get_buffer()->set_text (placeholder); // discard existing content if (shallNotify) - errorChangedSignal_.emit (true); + errorChangedSignal_.emit (false); } @@ -267,7 +269,7 @@ namespace widget { errorMarks_.clear(); if (shallNotify) - errorChangedSignal_.emit (true); + errorChangedSignal_.emit (false); } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 1285bcd45..723417fae 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -1832,9 +1832,9 @@ - - - + + + @@ -2070,8 +2070,8 @@ - - + + @@ -2109,21 +2109,6 @@ - - - - - - - - - - - - - - - @@ -2207,7 +2192,8 @@ - + + @@ -2230,26 +2216,30 @@ - - + + + + + - - - - + + + + + - + - + @@ -2264,7 +2254,7 @@ - + @@ -2274,7 +2264,7 @@ - + @@ -2417,7 +2407,7 @@ - + @@ -2484,9 +2474,24 @@ - - + + + + + + + + + + + + + + + + + @@ -2496,13 +2501,16 @@ - - - - - - + + + + + + + + + @@ -2583,7 +2591,7 @@ - + @@ -2836,7 +2844,7 @@ - + @@ -2881,7 +2889,7 @@ - + @@ -2890,13 +2898,14 @@ - - + + + - + @@ -3006,9 +3015,9 @@ - + - + @@ -19484,7 +19493,7 @@ - +