- Split between abstract base class (sgpem::CairoWidget) and

derived widget
- Add History::set_notify_enabled() for usage by the frontend 
(for example, when loading from file, you'll want to call
set_notify_enabled(false) before starting)


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@823 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-04 20:08:55 +00:00
parent 2174c25f74
commit 132db18b8c
8 changed files with 292 additions and 170 deletions

View file

@ -28,6 +28,13 @@
using namespace sgpem;
using namespace std;
History::History()
: _notify(true)
{
}
History::~History()
{
}
@ -52,7 +59,18 @@ History::detach(const HistoryObserver& observer)
void
History::notify_change()
{
if(!_notify) return;
for(RegisteredObservers::iterator it =_observers.begin();
it != _observers.end(); it++)
(*it)->update(*this);
}
bool
History::set_notify_enabled(bool enabled)
{
bool r = _notify;
_notify = enabled;
return r;
}

View file

@ -64,6 +64,7 @@ namespace sgpem
typedef Environment::resource_key_t resource_key_t;
typedef const std::pair<resource_key_t, Resource*> ResourcePair;
History();
virtual ~History() = 0;
virtual size_t get_size() const = 0;
@ -102,13 +103,26 @@ namespace sgpem
virtual void attach(HistoryObserver& observer);
virtual void detach(const HistoryObserver& observer);
/** \brief Enable/disable notifications to registered observers
*
* This is quite useful to disable momentarily notification while you
* do a bunch of insertions and/or deletions in one go, in order to
* speed up things.
*
* \return The old value
*/
virtual bool set_notify_enabled(bool enabled = true);
protected:
typedef std::vector<HistoryObserver*> RegisteredObservers;
RegisteredObservers _observers;
virtual void notify_change();
private:
bool _notify;
}; //~ class History
}//~ namespace sgpem