Commit 0e4e7f94 authored by daniel_e's avatar daniel_e
Browse files

New utility class that breaks the previous connection on assignment, and

* src/signalutils.{cc,h} (AutoConnection): New utility class that breaks
the previous connection on assignment, and also remembers the blocked state
of the connection permanently.

(ScopedBlock): Use Util::AutoConnection instead of SigC::Connection.

* src/filetree.{cc,h}: Use AutoConnection to manage the connection handles
of the currently selected buffer.

(on_selection_changed): Thanks to AutoConnection, we can now extinguish
a fair bit of error-prone code.
parent 85f8f02a
2003-01-11 Daniel Elstner <daniel.elstner@gmx.net>
* src/signalutils.{cc,h} (AutoConnection): New utility class that
breaks the previous connection on assignment, and also remembers the
blocked state of the connection permanently.
(ScopedBlock): Use Util::AutoConnection instead of SigC::Connection.
* src/filetree.{cc,h}: Use AutoConnection to manage the connection
handles of the currently selected buffer.
(on_selection_changed): Thanks to AutoConnection, we can now
extinguish a fair bit of error-prone code.
2003-01-01 Daniel Elstner <daniel.elstner@gmx.net>
* autogen.sh: Require automake >= 1.7.
......
......@@ -22,7 +22,6 @@
#include "filetreeprivate.h"
#include "miscutils.h"
#include "pcreshell.h"
#include "signalutils.h"
#include "stringutils.h"
#include <gtkmm/stock.h>
......@@ -777,10 +776,6 @@ void FileTree::on_selection_changed()
FileInfoPtr fileinfo;
int file_index = 0;
const bool conn_match_count_blocked = conn_match_count_.blocked();
const bool conn_modified_changed_blocked = conn_modified_changed_.blocked();
const bool conn_undo_stack_push_blocked = conn_undo_stack_push_.blocked();
conn_match_count_ .disconnect();
conn_modified_changed_.disconnect();
conn_undo_stack_push_ .disconnect();
......@@ -806,17 +801,6 @@ void FileTree::on_selection_changed()
conn_undo_stack_push_ = fileinfo->buffer->signal_undo_stack_push.
connect(SigC::slot(*this, &FileTree::on_buffer_undo_stack_push));
// Restore the blocked state of all connections.
//
if(conn_match_count_blocked)
conn_match_count_.block();
if(conn_modified_changed_blocked)
conn_modified_changed_.block();
if(conn_undo_stack_push_blocked)
conn_undo_stack_push_.block();
}
last_selected_rowref_.reset(new TreeRowRef(treestore_, Gtk::TreePath(iter)));
......
......@@ -23,6 +23,7 @@
#include "filebuffer.h"
#include "fileio.h"
#include "signalutils.h"
#include "undostack.h"
#include <gdkmm/color.h>
......@@ -107,9 +108,9 @@ private:
DirInfo toplevel_;
long sum_matches_;
SigC::Connection conn_match_count_;
SigC::Connection conn_modified_changed_;
SigC::Connection conn_undo_stack_push_;
Util::AutoConnection conn_match_count_;
Util::AutoConnection conn_modified_changed_;
Util::AutoConnection conn_undo_stack_push_;
Gtk::TreePath path_match_first_;
Gtk::TreePath path_match_last_;
......
......@@ -24,6 +24,8 @@
namespace Util
{
/**** Util::QueuedSignal ***************************************************/
QueuedSignal::QueuedSignal(int priority)
:
signal_ (),
......@@ -56,5 +58,51 @@ bool QueuedSignal::idle_handler()
return false; // disconnect idle handler
}
/**** Util::AutoConnection *************************************************/
AutoConnection::AutoConnection()
:
connection_ (),
blocked_ (false)
{}
AutoConnection::AutoConnection(const SigC::Connection& connection)
:
connection_ (connection),
blocked_ (connection_.blocked())
{}
AutoConnection::~AutoConnection()
{
connection_.disconnect();
}
void AutoConnection::block()
{
connection_.block();
blocked_ = true;
}
void AutoConnection::unblock()
{
connection_.unblock();
blocked_ = false;
}
AutoConnection& AutoConnection::operator=(const SigC::Connection& connection)
{
AutoConnection temp (connection_);
connection_ = connection;
connection_.block(blocked_);
return *this;
}
void AutoConnection::disconnect()
{
connection_.disconnect();
}
} // namespace Util
......@@ -48,6 +48,31 @@ private:
bool idle_handler();
};
class AutoConnection
{
private:
SigC::Connection connection_;
bool blocked_;
AutoConnection(const AutoConnection&);
AutoConnection& operator=(const AutoConnection&);
public:
AutoConnection();
explicit AutoConnection(const SigC::Connection& connection);
~AutoConnection();
void block();
void unblock();
bool blocked() const { return blocked_; }
AutoConnection& operator=(const SigC::Connection& connection);
void disconnect();
SigC::Connection& base() { return connection_; }
const SigC::Connection& base() const { return connection_; }
};
class ScopedConnection
{
private:
......@@ -66,13 +91,13 @@ public:
class ScopedBlock
{
private:
SigC::Connection& connection_;
AutoConnection& connection_;
ScopedBlock(const ScopedBlock&);
ScopedBlock& operator=(const ScopedBlock&);
public:
explicit ScopedBlock(SigC::Connection& connection)
explicit ScopedBlock(AutoConnection& connection)
: connection_ (connection) { connection_.block(); }
~ScopedBlock() { connection_.unblock(); }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment