diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-09 20:45:53 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 09:57:21 (GMT) |
commit | d0d7eb2a8445472c2bf5ecce04cc9987c51bd31c (patch) | |
tree | ec03f052271075e78be6c402fb94bf027f9ab248 | |
parent | 875c2d3ab0d6a5f06393b377cfc5ffddcad5baac (diff) | |
download | fluxbox_paul-d0d7eb2a8445472c2bf5ecce04cc9987c51bd31c.zip fluxbox_paul-d0d7eb2a8445472c2bf5ecce04cc9987c51bd31c.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.hh | 14 |
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 | ||
37 | namespace FbTk { | 38 | namespace 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 | |||
242 | private: | 251 | private: |
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 | ||