aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Resource.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-08-02 11:56:31 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-11-01 10:04:01 (GMT)
commit476f845dcda2ff239616ec075521ab6826805245 (patch)
tree846af8c630fa22d67ad1017233afc5503b4786be /src/FbTk/Resource.hh
parent1eb80ce64236026445929fe42f3843da9e53a937 (diff)
downloadfluxbox_paul-476f845dcda2ff239616ec075521ab6826805245.zip
fluxbox_paul-476f845dcda2ff239616ec075521ab6826805245.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.hh11
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) {