aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/LResource.cc
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-08-02 11:56:31 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-08-02 11:56:31 (GMT)
commit707df7d81b6df25fa98f3a867485cb7bbbbf74b8 (patch)
treed122e39c64301115e9581ee2824a6b2bde7f1cb8 /src/FbTk/LResource.cc
parentb4790819bc4155cdab148dc536f55a7fc0595d9a (diff)
downloadfluxbox_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/LResource.cc')
-rw-r--r--src/FbTk/LResource.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc
index 31362bd..de90b95 100644
--- a/src/FbTk/LResource.cc
+++ b/src/FbTk/LResource.cc
@@ -26,8 +26,11 @@
26 26
27#include "I18n.hh" 27#include "I18n.hh"
28#include "LuaUtil.hh" 28#include "LuaUtil.hh"
29#include "MemFun.hh"
29#include "Resource.hh" 30#include "Resource.hh"
30 31
32// defined in LResourceHelper-lua.cc
33// contains the compiled code of LResourceHelper.lua
31extern const char LResourceHelper[]; 34extern const char LResourceHelper[];
32extern const unsigned int LResourceHelper_size; 35extern const unsigned int LResourceHelper_size;
33 36
@@ -101,8 +104,15 @@ void LResourceManager::convert(ResourceManager &old, const std::string &new_file
101 new_rm.save(new_file.c_str(), NULL); 104 new_rm.save(new_file.c_str(), NULL);
102} 105}
103 106
104LResourceManager::LResourceManager(const std::string &root, Lua &l) 107LResourceManager::LResourceManager(const std::string &root, Lua &l, unsigned int autosave)
105 : ResourceManager_base(root), m_l(&l) { 108 : ResourceManager_base(root), m_l(&l) {
109
110 m_savetimer.setInterval(autosave);
111 m_savetimer.fireOnce(true);
112 m_savetimer.setFunctor( MemFunBind(*this, &LResourceManager::save,
113 static_cast<const char *>(NULL), static_cast<const char *>(NULL)
114 ) );
115
106 setLua(l); 116 setLua(l);
107} 117}
108 118
@@ -143,6 +153,8 @@ bool LResourceManager::save(const char *filename, const char *) {
143 if(filename == NULL) 153 if(filename == NULL)
144 filename = m_filename.c_str(); 154 filename = m_filename.c_str();
145 155
156 std::cerr << "XXX SAVING " << filename << std::endl;
157
146 m_l->getfield(lua::REGISTRYINDEX, dump_resources); 158 m_l->getfield(lua::REGISTRYINDEX, dump_resources);
147 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); 159 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str());
148 m_l->pushstring(filename); 160 m_l->pushstring(filename);
@@ -194,6 +206,11 @@ void LResourceManager::doRemoveResource(Resource_base &r) {
194 m_l->pop(); 206 m_l->pop();
195} 207}
196 208
209void LResourceManager::resourceChanged(Resource_base &r) {
210 if(! m_savetimer.isTiming())
211 m_savetimer.start();
212}
213
197void LResourceManager::setLua(Lua &l) { 214void LResourceManager::setLua(Lua &l) {
198 l.checkstack(2); 215 l.checkstack(2);
199 lua::stack_sentry s(l); 216 lua::stack_sentry s(l);