aboutsummaryrefslogtreecommitdiff
path: root/src/MenuCreator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/MenuCreator.cc')
-rw-r--r--src/MenuCreator.cc48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index 9c3cb4f..dec82c9 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -20,7 +20,7 @@
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE. 21// DEALINGS IN THE SOFTWARE.
22 22
23// $Id: MenuCreator.cc,v 1.12 2004/08/29 12:35:29 rathnor Exp $ 23// $Id: MenuCreator.cc,v 1.13 2004/08/29 21:11:24 akir Exp $
24 24
25#include "MenuCreator.hh" 25#include "MenuCreator.hh"
26 26
@@ -38,6 +38,7 @@
38 38
39#include "FbMenuParser.hh" 39#include "FbMenuParser.hh"
40#include "StyleMenuItem.hh" 40#include "StyleMenuItem.hh"
41#include "RootCmdMenuItem.hh"
41 42
42#include "FbTk/I18n.hh" 43#include "FbTk/I18n.hh"
43#include "FbTk/MultiButtonMenuItem.hh" 44#include "FbTk/MultiButtonMenuItem.hh"
@@ -93,6 +94,42 @@ static void createStyleMenu(FbTk::Menu &parent, const std::string &label,
93 94
94} 95}
95 96
97static void createRootCmdMenu(FbTk::Menu &parent, const string &label,
98 const string &directory, const string &cmd) {
99 // perform shell style ~ home directory expansion
100 string rootcmddir(FbTk::StringUtil::expandFilename(directory));
101
102 if (!FbTk::Directory::isDirectory(rootcmddir))
103 return;
104
105 FbTk::Directory dir(rootcmddir.c_str());
106
107 // create a vector of all the filenames in the directory
108 // add sort it
109 vector<string> filelist(dir.entries());
110 for (size_t file_index = 0; file_index < dir.entries(); ++file_index)
111 filelist[file_index] = dir.readFilename();
112
113 sort(filelist.begin(), filelist.end(), less<string>());
114
115 // for each file in directory add filename and path to menu
116 for (size_t file_index = 0; file_index < dir.entries(); file_index++) {
117
118 string rootcmd(rootcmddir+ '/' + filelist[file_index]);
119 // add to menu only if the file is a regular file, and not a
120 // .file or a backup~ file
121 if ((FbTk::Directory::isRegularFile(rootcmd) &&
122 (filelist[file_index][0] != '.') &&
123 (rootcmd[rootcmd.length() - 1] != '~')))
124 parent.insert(new RootCmdMenuItem(filelist[file_index], rootcmd, cmd));
125 }
126 // update menu graphics
127 parent.update();
128 Fluxbox::instance()->saveMenuFilename(rootcmddir.c_str());
129
130}
131
132
96class ParseItem { 133class ParseItem {
97public: 134public:
98 explicit ParseItem(FbTk::Menu *menu):m_menu(menu) {} 135 explicit ParseItem(FbTk::Menu *menu):m_menu(menu) {}
@@ -165,8 +202,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
165 exec_and_hide->add(exec_cmd); 202 exec_and_hide->add(exec_cmd);
166 RefCount<Command> exec_and_hide_cmd(exec_and_hide); 203 RefCount<Command> exec_and_hide_cmd(exec_and_hide);
167 menu.insert(str_label.c_str(), exec_and_hide_cmd); 204 menu.insert(str_label.c_str(), exec_and_hide_cmd);
168 } 205 } else if (str_key == "style") { // style
169 else if (str_key == "style") { // style
170 menu.insert(new StyleMenuItem(str_label, str_cmd)); 206 menu.insert(new StyleMenuItem(str_label, str_cmd));
171 } else if (str_key == "config") { 207 } else if (str_key == "config") {
172 BScreen *screen = Fluxbox::instance()->findScreen(screen_number); 208 BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
@@ -224,7 +260,11 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem) {
224 createStyleMenu(menu, str_label, 260 createStyleMenu(menu, str_label,
225 str_key == "themesmenu" ? str_cmd : str_label); 261 str_key == "themesmenu" ? str_cmd : str_label);
226 } // end of themesdir 262 } // end of themesdir
227 263 else if (str_key == "wallpapers" || str_key == "wallpapermenu" ||
264 str_key == "rootcommands") {
265 createRootCmdMenu(menu, str_label, str_label,
266 str_cmd == "" ? "fbsetbg" : str_cmd);
267 } // end of wallpapers
228 else if (str_key == "workspaces") { 268 else if (str_key == "workspaces") {
229 BScreen *screen = Fluxbox::instance()->findScreen(screen_number); 269 BScreen *screen = Fluxbox::instance()->findScreen(screen_number);
230 if (screen != 0) { 270 if (screen != 0) {