diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-12 18:24:14 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 09:55:30 (GMT) |
commit | 7558677fd8b77fbb62440e83578effc48bb1e392 (patch) | |
tree | 02bd6b09f37557b1b984794951dedfd19bb47044 | |
parent | cbdc84bd064a1769410a2d5236e75ac323e79b1e (diff) | |
download | fluxbox_paul-7558677fd8b77fbb62440e83578effc48bb1e392.zip fluxbox_paul-7558677fd8b77fbb62440e83578effc48bb1e392.tar.bz2 |
Add a function for converting from XResources to lua ones
-rw-r--r-- | src/FbTk/LResource.cc | 16 | ||||
-rw-r--r-- | src/FbTk/LResource.hh | 1 | ||||
-rw-r--r-- | src/FbTk/Resource.hh | 4 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc index 78511eb..2e2a7c7 100644 --- a/src/FbTk/LResource.cc +++ b/src/FbTk/LResource.cc | |||
@@ -82,6 +82,22 @@ void LResourceManager::initState(lua::state &l) { | |||
82 | l.setfield(lua::REGISTRYINDEX, make_root); | 82 | l.setfield(lua::REGISTRYINDEX, make_root); |
83 | } | 83 | } |
84 | 84 | ||
85 | void LResourceManager::convert(ResourceManager &old, const std::string &new_file) { | ||
86 | lua::state l; | ||
87 | initState(l); | ||
88 | |||
89 | LResourceManager new_rm(old.root(), l); | ||
90 | for(ResourceList::const_iterator i = old.begin(); i != old.end(); ++i) { | ||
91 | // adding the resource to new_rm will set it to default value | ||
92 | // we save the value to a temp variable so we can restore it later | ||
93 | const std::string &t = (*i)->getString(); | ||
94 | new_rm.addResource(**i); | ||
95 | (*i)->setFromString(t.c_str()); | ||
96 | } | ||
97 | |||
98 | new_rm.save(new_file.c_str(), NULL); | ||
99 | } | ||
100 | |||
85 | LResourceManager::LResourceManager(const std::string &root, lua::state &l) | 101 | LResourceManager::LResourceManager(const std::string &root, lua::state &l) |
86 | : ResourceManager_base(root), m_l(&l) { | 102 | : ResourceManager_base(root), m_l(&l) { |
87 | l.checkstack(2); | 103 | l.checkstack(2); |
diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh index 185a029..1125707 100644 --- a/src/FbTk/LResource.hh +++ b/src/FbTk/LResource.hh | |||
@@ -38,6 +38,7 @@ namespace FbTk { | |||
38 | class LResourceManager: public ResourceManager_base { | 38 | class LResourceManager: public ResourceManager_base { |
39 | public: | 39 | public: |
40 | static void initState(lua::state &l); | 40 | static void initState(lua::state &l); |
41 | static void convert(ResourceManager &old, const std::string &new_file); | ||
41 | 42 | ||
42 | LResourceManager(const std::string &root, lua::state &l); | 43 | LResourceManager(const std::string &root, lua::state &l); |
43 | virtual bool save(const char *filename, const char *); | 44 | virtual bool save(const char *filename, const char *); |
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 744178b..00f8769 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh | |||
@@ -123,6 +123,10 @@ public: | |||
123 | template <typename ResourceType, typename Traits> | 123 | template <typename ResourceType, typename Traits> |
124 | Resource<ResourceType, Traits> &getResource(const std::string &resource); | 124 | Resource<ResourceType, Traits> &getResource(const std::string &resource); |
125 | 125 | ||
126 | const std::string &root() const { return m_root; } | ||
127 | ResourceList::const_iterator begin() { return m_resourcelist.begin(); } | ||
128 | ResourceList::const_iterator end() { return m_resourcelist.end(); } | ||
129 | |||
126 | protected: | 130 | protected: |
127 | ResourceList m_resourcelist; | 131 | ResourceList m_resourcelist; |
128 | const std::string m_root; | 132 | const std::string m_root; |