Enhanced ConnectionBlocker class, now used in ToolBar class

This commit is contained in:
Hombre 2016-10-16 14:19:59 +02:00
parent 50165dab20
commit 8f2f4e0870
2 changed files with 55 additions and 146 deletions

View File

@ -80,16 +80,24 @@ public:
class ConnectionBlocker class ConnectionBlocker
{ {
public: public:
explicit ConnectionBlocker (sigc::connection& connection) : connection (connection) explicit ConnectionBlocker (Gtk::Widget *associatedWidget, sigc::connection& connection) : connection (associatedWidget ? &connection : nullptr)
{ {
wasBlocked = connection.block(); if (this->connection) {
wasBlocked = connection.block();
}
}
explicit ConnectionBlocker (sigc::connection& connection) : connection (&connection)
{
wasBlocked = connection.block();
} }
~ConnectionBlocker () ~ConnectionBlocker ()
{ {
connection.block(wasBlocked); if (connection) {
connection->block(wasBlocked);
}
} }
private: private:
sigc::connection& connection; sigc::connection *connection;
bool wasBlocked; bool wasBlocked;
}; };

View File

@ -110,20 +110,15 @@ ToolBar::~ToolBar ()
void ToolBar::setTool (ToolMode tool) void ToolBar::setTool (ToolMode tool)
{ {
bool handWasBlocked = handConn.block (true); bool stopEdit;
bool cropWasBlocked = cropConn.block (true);
bool wbWasBlocked = true, cpWasBlocked = true;
if (wbTool) { {
wbWasBlocked = wbConn.block (true); ConnectionBlocker handBlocker(handConn);
} ConnectionBlocker straBlocker(straConn);
if (colPickerTool) { ConnectionBlocker cropBlocker(cropConn);
cpWasBlocked = cpConn.block (true); ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
}
bool straWasBlocked = straConn.block (true); stopEdit = tool == TMHand && handTool->get_active() && editingMode;
bool stopEdit = tool == TMHand && handTool->get_active() && editingMode;
handTool->set_active (false); handTool->set_active (false);
@ -156,17 +151,7 @@ void ToolBar::setTool (ToolMode tool)
current = tool; current = tool;
if (!handWasBlocked) handConn.block (false);
if (!cropWasBlocked) cropConn.block (false);
if (wbTool) {
if (!wbWasBlocked) wbConn.block (false);
} }
if (colPickerTool) {
if (!cpWasBlocked) cpConn.block (false);
}
if (!straWasBlocked) straConn.block (false);
if (stopEdit) { if (stopEdit) {
stopEditMode(); stopEditMode();
@ -180,18 +165,11 @@ void ToolBar::setTool (ToolMode tool)
void ToolBar::startEditMode() void ToolBar::startEditMode()
{ {
if (!editingMode) { if (!editingMode) {
bool handWasBlocked = handConn.block (true); {
bool cropWasBlocked = cropConn.block (true); ConnectionBlocker handBlocker(handConn);
bool wbWasBlocked = true, cpWasBlocked = true; ConnectionBlocker straBlocker(straConn);
if (colPickerTool) { ConnectionBlocker cropBlocker(cropConn);
cpWasBlocked = cpConn.block (true); ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
}
if (wbTool) {
wbWasBlocked = wbConn.block (true);
}
bool straWasBlocked = straConn.block (true);
if (current != TMHand) { if (current != TMHand) {
if (colPickerTool) { if (colPickerTool) {
@ -207,16 +185,7 @@ void ToolBar::startEditMode()
} }
handTool->set_active (true); handTool->set_active (true);
if (!handWasBlocked) handConn.block (false);
if (!cropWasBlocked) cropConn.block (false);
if (colPickerTool) {
if (!cpWasBlocked) cpConn.block (false);
} }
if (wbTool) {
if (!wbWasBlocked) wbConn.block (false);
}
if (!straWasBlocked) straConn.block (false);
editingMode = true; editingMode = true;
handTool->set_image(*editinghandimg); handTool->set_image(*editinghandimg);
@ -240,19 +209,11 @@ void ToolBar::stopEditMode()
void ToolBar::hand_pressed () void ToolBar::hand_pressed ()
{ {
{
bool handWasBlocked = handConn.block (true); ConnectionBlocker handBlocker(handConn);
bool cropWasBlocked = cropConn.block (true); ConnectionBlocker straBlocker(straConn);
bool wbWasBlocked = true, cpWasBlocked = true; ConnectionBlocker cropBlocker(cropConn);
if (colPickerTool) { ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
cpWasBlocked = cpConn.block (true);
}
if (wbTool) {
wbWasBlocked = wbConn.block (true);
}
bool straWasBlocked = straConn.block (true);
if (editingMode) { if (editingMode) {
stopEditMode(); stopEditMode();
@ -274,16 +235,8 @@ void ToolBar::hand_pressed ()
} }
handTool->set_active (true); handTool->set_active (true);
if (!handWasBlocked) handConn.block (false);
if (!cropWasBlocked) cropConn.block (false);
if (colPickerTool) {
if (!cpWasBlocked) cpConn.block (false);
}
if (wbTool) {
if (!wbWasBlocked) wbConn.block (false);
}
if (!straWasBlocked) straConn.block (false); }
if (listener) { if (listener) {
listener->toolSelected (TMHand); listener->toolSelected (TMHand);
@ -292,18 +245,11 @@ void ToolBar::hand_pressed ()
void ToolBar::wb_pressed () void ToolBar::wb_pressed ()
{ {
{
bool handWasBlocked = handConn.block (true); ConnectionBlocker handBlocker(handConn);
bool cropWasBlocked = cropConn.block (true); ConnectionBlocker straBlocker(straConn);
bool wbWasBlocked = true, cpWasBlocked = true; ConnectionBlocker cropBlocker(cropConn);
if (colPickerTool) { ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
cpWasBlocked = cpConn.block (true);
}
if (wbTool) {
wbWasBlocked = wbConn.block (true);
}
bool straWasBlocked = straConn.block (true);
if (current != TMSpotWB) { if (current != TMSpotWB) {
if (editingMode) { if (editingMode) {
@ -325,16 +271,7 @@ void ToolBar::wb_pressed ()
wbTool->set_active (true); wbTool->set_active (true);
} }
if (!handWasBlocked) handConn.block (false);
if (!cropWasBlocked) cropConn.block (false);
if (colPickerTool) {
if (!cpWasBlocked) cpConn.block (false);
} }
if (wbTool) {
if (!wbWasBlocked) wbConn.block (false);
}
if (!straWasBlocked) straConn.block (false);
if (listener) { if (listener) {
listener->toolSelected (TMSpotWB); listener->toolSelected (TMSpotWB);
@ -345,15 +282,11 @@ void ToolBar::colPicker_pressed (GdkEventButton* event)
{ {
if (event->button == 1) { if (event->button == 1) {
bool handWasBlocked = handConn.block (true); {
bool cropWasBlocked = cropConn.block (true); ConnectionBlocker handBlocker(handConn);
bool wbWasBlocked = true; ConnectionBlocker straBlocker(straConn);
bool cpWasBlocked = cpConn.block (true); ConnectionBlocker cropBlocker(cropConn);
if (wbTool) { ConnectionBlocker wbWasBlocked(wbTool, wbConn);
wbWasBlocked = wbConn.block (true);
}
bool straWasBlocked = straConn.block (true);
cropTool->set_active (false); cropTool->set_active (false);
if (wbTool) { if (wbTool) {
@ -382,11 +315,7 @@ void ToolBar::colPicker_pressed (GdkEventButton* event)
current = TMHand; current = TMHand;
} }
if (!handWasBlocked) handConn.block (false); }
if (!cropWasBlocked) cropConn.block (false);
if (!cpWasBlocked) cpConn.block (false);
if (!wbWasBlocked) wbConn.block (false);
if (!straWasBlocked) straConn.block (false);
if (listener) { if (listener) {
listener->toolSelected (current); listener->toolSelected (current);
@ -394,14 +323,12 @@ void ToolBar::colPicker_pressed (GdkEventButton* event)
} else if (event->button == 3) { } else if (event->button == 3) {
if (current == TMColorPicker) { if (current == TMColorPicker) {
// Disabling the Picker tool and entering into the "invisible pickers" mode // Disabling the Picker tool and entering into the "invisible pickers" mode
bool cpWasBlocked = cpConn.block (true); ConnectionBlocker handBlocker(handConn);
bool handWasBlocked = handConn.block (true); ConnectionBlocker cpWasBlocked(cpConn);
handTool->set_active (true); handTool->set_active (true);
colPickerTool->set_active (false); colPickerTool->set_active (false);
current = TMHand; current = TMHand;
showColorPickers(false); showColorPickers(false);
if (!cpWasBlocked) cpConn.block (false);
if (!handWasBlocked) handConn.block (false);
} else { } else {
// The Picker tool is already disabled, entering into the "invisible pickers" mode // The Picker tool is already disabled, entering into the "invisible pickers" mode
switchColorPickersVisibility(); switchColorPickersVisibility();
@ -433,19 +360,11 @@ void ToolBar::switchColorPickersVisibility()
void ToolBar::crop_pressed () void ToolBar::crop_pressed ()
{ {
{
bool handWasBlocked = handConn.block (true); ConnectionBlocker handBlocker(handConn);
bool cropWasBlocked = cropConn.block (true); ConnectionBlocker straBlocker(straConn);
bool wbWasBlocked = true, cpWasBlocked = true; ConnectionBlocker cropBlocker(cropConn);
if (colPickerTool) { ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
cpWasBlocked = cpConn.block(true);
}
if (wbTool) {
wbWasBlocked = wbConn.block (true);
}
bool straWasBlocked = straConn.block (true);
if (current != TMCropSelect) { if (current != TMCropSelect) {
if (editingMode) { if (editingMode) {
@ -468,11 +387,8 @@ void ToolBar::crop_pressed ()
cropTool->set_active (true); cropTool->set_active (true);
cropTool->grab_focus (); cropTool->grab_focus ();
if (!handWasBlocked) handConn.block (false);
if (!cropWasBlocked) cropConn.block (false); }
if (!cpWasBlocked) cpConn.block(false);
if (!wbWasBlocked) wbConn.block (false);
if (!straWasBlocked) straConn.block (false);
if (listener) { if (listener) {
listener->toolSelected (TMCropSelect); listener->toolSelected (TMCropSelect);
@ -481,19 +397,11 @@ void ToolBar::crop_pressed ()
void ToolBar::stra_pressed () void ToolBar::stra_pressed ()
{ {
{
bool handWasBlocked = handConn.block (true); ConnectionBlocker handBlocker(handConn);
bool cropWasBlocked = cropConn.block (true); ConnectionBlocker straBlocker(straConn);
bool wbWasBlocked = true, cpWasBlocked = true; ConnectionBlocker cropBlocker(cropConn);
if (colPickerTool) { ConnectionBlocker wbWasBlocked(wbTool, wbConn), cpWasBlocked(colPickerTool, cpConn);
cpWasBlocked = cpConn.block (true);
}
if (wbTool) {
wbWasBlocked = wbConn.block (true);
}
bool straWasBlocked = straConn.block (true);
if (current != TMStraighten) { if (current != TMStraighten) {
if (editingMode) { if (editingMode) {
@ -515,16 +423,9 @@ void ToolBar::stra_pressed ()
} }
straTool->set_active (true); straTool->set_active (true);
if (!handWasBlocked) handConn.block (false);
if (!cropWasBlocked) cropConn.block (false);
if (!cpWasBlocked) cpConn.block (false);
if (wbTool) {
if (!wbWasBlocked) wbConn.block (false);
} }
if (!straWasBlocked) straConn.block (false);
if (listener) { if (listener) {
listener->toolSelected (TMStraighten); listener->toolSelected (TMStraighten);
} }