diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-08-02 11:56:31 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-08-02 11:56:31 (GMT) |
commit | 707df7d81b6df25fa98f3a867485cb7bbbbf74b8 (patch) | |
tree | d122e39c64301115e9581ee2824a6b2bde7f1cb8 /src/FbTk/Resource.hh | |
parent | b4790819bc4155cdab148dc536f55a7fc0595d9a (diff) | |
download | fluxbox_pavel-707df7d81b6df25fa98f3a867485cb7bbbbf74b8.zip fluxbox_pavel-707df7d81b6df25fa98f3a867485cb7bbbbf74b8.tar.bz2 |
Automatically save init file when a resource is modified
previously, init was autosaved only when a resource was modified using the menu. I have also
included modifications through lua code.
To avoid wasting resources, the file is not saved immediately, but with a 5 second delay (to
enable saving a bunch of changes in one go)
Diffstat (limited to 'src/FbTk/Resource.hh')
-rw-r--r-- | src/FbTk/Resource.hh | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 7a797a1..c4a7951 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh | |||
@@ -96,8 +96,6 @@ public: | |||
96 | /// @return true on success | 96 | /// @return true on success |
97 | virtual bool save(const char *filename, const char *mergefilename=0) = 0; | 97 | virtual bool save(const char *filename, const char *mergefilename=0) = 0; |
98 | 98 | ||
99 | |||
100 | |||
101 | /// Add resource to list, only used in Resource<T> | 99 | /// Add resource to list, only used in Resource<T> |
102 | virtual void addResource(Resource_base &r); | 100 | virtual void addResource(Resource_base &r); |
103 | 101 | ||
@@ -106,6 +104,9 @@ public: | |||
106 | m_resourcelist.remove(&r); | 104 | m_resourcelist.remove(&r); |
107 | } | 105 | } |
108 | 106 | ||
107 | /// Called by Resources when their value changes | ||
108 | virtual void resourceChanged(Resource_base &r) = 0; | ||
109 | |||
109 | /// searches for the resource with the resourcename | 110 | /// searches for the resource with the resourcename |
110 | /// @return pointer to resource base on success, else 0. | 111 | /// @return pointer to resource base on success, else 0. |
111 | Resource_base *findResource(const std::string &resourcename); | 112 | Resource_base *findResource(const std::string &resourcename); |
@@ -154,6 +155,8 @@ public: | |||
154 | /// Add resource to list, only used in Resource<T> | 155 | /// Add resource to list, only used in Resource<T> |
155 | virtual void addResource(Resource_base &r); | 156 | virtual void addResource(Resource_base &r); |
156 | 157 | ||
158 | virtual void resourceChanged(Resource_base &r) {}; | ||
159 | |||
157 | // this marks the database as "in use" and will avoid reloading | 160 | // this marks the database as "in use" and will avoid reloading |
158 | // resources unless it is zero. | 161 | // resources unless it is zero. |
159 | // It returns this resource manager. Useful for passing to | 162 | // It returns this resource manager. Useful for passing to |
@@ -211,12 +214,14 @@ public: | |||
211 | 214 | ||
212 | void setDefaultValue() { | 215 | void setDefaultValue() { |
213 | m_value = m_defaultval; | 216 | m_value = m_defaultval; |
217 | m_rm.resourceChanged(*this); | ||
214 | m_modified_sig.emit(m_value); | 218 | m_modified_sig.emit(m_value); |
215 | } | 219 | } |
216 | /// sets resource from string, specialized, must be implemented | 220 | /// sets resource from string, specialized, must be implemented |
217 | void setFromString(const char *strval) { | 221 | void setFromString(const char *strval) { |
218 | try { | 222 | try { |
219 | m_value = Traits::fromString(strval); | 223 | m_value = Traits::fromString(strval); |
224 | m_rm.resourceChanged(*this); | ||
220 | m_modified_sig.emit(m_value); | 225 | m_modified_sig.emit(m_value); |
221 | } | 226 | } |
222 | catch(ConversionError &e) { | 227 | catch(ConversionError &e) { |
@@ -226,6 +231,7 @@ public: | |||
226 | } | 231 | } |
227 | Accessor<T> &operator =(const T& newvalue) { | 232 | Accessor<T> &operator =(const T& newvalue) { |
228 | m_value = newvalue; | 233 | m_value = newvalue; |
234 | m_rm.resourceChanged(*this); | ||
229 | m_modified_sig.emit(m_value); | 235 | m_modified_sig.emit(m_value); |
230 | return *this; | 236 | return *this; |
231 | } | 237 | } |
@@ -236,6 +242,7 @@ public: | |||
236 | virtual void setFromLua(lua::state &l) { | 242 | virtual void setFromLua(lua::state &l) { |
237 | try { | 243 | try { |
238 | m_value = Traits::fromLua(l); | 244 | m_value = Traits::fromLua(l); |
245 | m_rm.resourceChanged(*this); | ||
239 | m_modified_sig.emit(m_value); | 246 | m_modified_sig.emit(m_value); |
240 | } | 247 | } |
241 | catch(ConversionError &e) { | 248 | catch(ConversionError &e) { |