Add RAII listener blocking utility

* Added for ToolPanel listener and Adjuster
* Follows style of ConnectionBlocker for sigc::connection
This commit is contained in:
Daniel Gao 2024-11-07 11:31:59 -05:00
parent 03a73eb3a4
commit b472fbf2ab
2 changed files with 52 additions and 0 deletions

View File

@ -25,6 +25,8 @@
#include "rtimage.h" #include "rtimage.h"
#include "rtscalable.h" #include "rtscalable.h"
#include "multilangmgr.h" #include "multilangmgr.h"
#include "adjuster.h"
#include "toolpanel.h"
#include <assert.h> #include <assert.h>
@ -77,6 +79,34 @@ void IdleRegister::destroy()
mutex.unlock(); mutex.unlock();
} }
BlockAdjusterEvents::BlockAdjusterEvents(Adjuster* adjuster) : adj(adjuster)
{
if (adj) {
adj->block(true);
}
}
BlockAdjusterEvents::~BlockAdjusterEvents()
{
if (adj) {
adj->block(false);
}
}
DisableListener::DisableListener(ToolPanel* panelToDisable) : panel(panelToDisable)
{
if (panel) {
panel->disableListener();
}
}
DisableListener::~DisableListener()
{
if (panel) {
panel->enableListener();
}
}
Glib::ustring escapeHtmlChars(const Glib::ustring &src) Glib::ustring escapeHtmlChars(const Glib::ustring &src)
{ {

View File

@ -45,7 +45,9 @@ struct CropParams;
} }
class Adjuster;
class RTImage; class RTImage;
class ToolPanel;
Glib::ustring escapeHtmlChars(const Glib::ustring &src); Glib::ustring escapeHtmlChars(const Glib::ustring &src);
bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference = true); bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference = true);
@ -161,6 +163,26 @@ private:
bool wasBlocked; bool wasBlocked;
}; };
class BlockAdjusterEvents
{
public:
explicit BlockAdjusterEvents(Adjuster* adjuster);
~BlockAdjusterEvents();
private:
Adjuster* adj;
};
class DisableListener
{
public:
explicit DisableListener(ToolPanel* panelToDisable);
~DisableListener();
private:
ToolPanel* panel;
};
/** /**
* @brief Glue box to control visibility of the MyExpender's content ; also handle the frame around it * @brief Glue box to control visibility of the MyExpender's content ; also handle the frame around it
*/ */