aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-09 20:45:53 (GMT)
committerPaul Tagliamonte <paultag@fluxbox.org>2012-04-07 02:11:31 (GMT)
commit7f2869f20400fb52a24a7eac8224eb2003d420ae (patch)
tree9584fadb97fdf81451620b75b64d58a6c6b2afd6
parentb3986eb1604dbe38ccba9023e6cee269f0b9ef67 (diff)
downloadfluxbox_paul-7f2869f20400fb52a24a7eac8224eb2003d420ae.zip
fluxbox_paul-7f2869f20400fb52a24a7eac8224eb2003d420ae.tar.bz2
Add a "modified" signal to resources
This way, an object can be informed when a resource changes (e.g. by a lua function).
-rw-r--r--src/FbTk/Resource.hh14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh
index 518d0aa..32d24b6 100644
--- a/src/FbTk/Resource.hh
+++ b/src/FbTk/Resource.hh
@@ -28,10 +28,11 @@
28#include <string> 28#include <string>
29#include <list> 29#include <list>
30#include <iostream> 30#include <iostream>
31
32#include <exception> 31#include <exception>
33#include <typeinfo> 32#include <typeinfo>
33
34#include "ResTraits.hh" 34#include "ResTraits.hh"
35#include "Signal.hh"
35#include "XrmDatabaseHelper.hh" 36#include "XrmDatabaseHelper.hh"
36 37
37namespace FbTk { 38namespace FbTk {
@@ -206,11 +207,15 @@ public:
206 m_rm.removeResource(*this); // remove this from resource handler 207 m_rm.removeResource(*this); // remove this from resource handler
207 } 208 }
208 209
209 void setDefaultValue() { m_value = m_defaultval; } 210 void setDefaultValue() {
211 m_value = m_defaultval;
212 m_modified_sig.emit(m_value);
213 }
210 /// sets resource from string, specialized, must be implemented 214 /// sets resource from string, specialized, must be implemented
211 void setFromString(const char *strval) { 215 void setFromString(const char *strval) {
212 try { 216 try {
213 m_value = Traits::fromString(strval); 217 m_value = Traits::fromString(strval);
218 m_modified_sig.emit(m_value);
214 } 219 }
215 catch(ConversionError &e) { 220 catch(ConversionError &e) {
216 std::cerr << name() << ": " << e.what() << std::endl; 221 std::cerr << name() << ": " << e.what() << std::endl;
@@ -225,6 +230,7 @@ public:
225 virtual void setFromLua(lua::state &l) { 230 virtual void setFromLua(lua::state &l) {
226 try { 231 try {
227 m_value = Traits::fromLua(l); 232 m_value = Traits::fromLua(l);
233 m_modified_sig.emit(m_value);
228 } 234 }
229 catch(ConversionError &e) { 235 catch(ConversionError &e) {
230 std::cerr << name() << ": " << e.what() << std::endl; 236 std::cerr << name() << ": " << e.what() << std::endl;
@@ -239,9 +245,13 @@ public:
239 const T& operator*() const { return m_value; } 245 const T& operator*() const { return m_value; }
240 T *operator->() { return &m_value; } 246 T *operator->() { return &m_value; }
241 const T *operator->() const { return &m_value; } 247 const T *operator->() const { return &m_value; }
248
249 Signal<const T &>& modifiedSig() { return m_modified_sig; }
250
242private: 251private:
243 T m_value, m_defaultval; 252 T m_value, m_defaultval;
244 ResourceManager_base &m_rm; 253 ResourceManager_base &m_rm;
254 Signal<const T &> m_modified_sig;
245}; 255};
246 256
247 257