diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MenuCreator.cc | 48 | ||||
-rw-r--r-- | src/RootCmdMenuItem.cc | 47 | ||||
-rw-r--r-- | src/RootCmdMenuItem.hh | 40 |
3 files changed, 131 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 | ||
97 | static 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 | |||
96 | class ParseItem { | 133 | class ParseItem { |
97 | public: | 134 | public: |
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) { |
diff --git a/src/RootCmdMenuItem.cc b/src/RootCmdMenuItem.cc new file mode 100644 index 0000000..d9e0e08 --- /dev/null +++ b/src/RootCmdMenuItem.cc | |||
@@ -0,0 +1,47 @@ | |||
1 | // RootCmdMenuItem.cc for Fluxbox Window Manager | ||
2 | // Copyright (c) 2004 Mathias Gumz | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: RootCmdMenuItem.cc,v 1.1 2004/08/29 21:11:24 akir Exp $ | ||
23 | |||
24 | #include "RootCmdMenuItem.hh" | ||
25 | |||
26 | #include "FbCommands.hh" | ||
27 | #include "fluxbox.hh" | ||
28 | |||
29 | #include "FbTk/StringUtil.hh" | ||
30 | |||
31 | RootCmdMenuItem::RootCmdMenuItem(const std::string &label, | ||
32 | const std::string &filename, | ||
33 | const std::string &cmd): | ||
34 | FbTk::MenuItem(label.c_str()), | ||
35 | m_filename(filename) { | ||
36 | |||
37 | FbTk::RefCount<FbTk::Command> | ||
38 | setwp_cmd(new FbCommands::ExecuteCmd(cmd + " \"" + m_filename + "\"")); | ||
39 | setCommand(setwp_cmd); | ||
40 | setToggleItem(true); | ||
41 | } | ||
42 | |||
43 | |||
44 | bool RootCmdMenuItem::isSelected() const { | ||
45 | return Fluxbox::instance()->getStyleFilename() == m_filename; | ||
46 | } | ||
47 | |||
diff --git a/src/RootCmdMenuItem.hh b/src/RootCmdMenuItem.hh new file mode 100644 index 0000000..c18737a --- /dev/null +++ b/src/RootCmdMenuItem.hh | |||
@@ -0,0 +1,40 @@ | |||
1 | // RootCmdMenuItem.hh for Fluxbox Window Manager | ||
2 | // Copyright (c) 2004 Mathias Gumz | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: RootCmdMenuItem.hh,v 1.1 2004/08/29 21:11:24 akir Exp $ | ||
23 | |||
24 | #ifndef ROOTCMDMENUITEM_HH | ||
25 | #define ROOTCMDMENUITEM_HH | ||
26 | |||
27 | #include "FbTk/MenuItem.hh" | ||
28 | #include <string> | ||
29 | |||
30 | class RootCmdMenuItem: public FbTk::MenuItem { | ||
31 | public: | ||
32 | RootCmdMenuItem(const std::string &label, | ||
33 | const std::string &filename, | ||
34 | const std::string &cmd = "fbsetbg"); | ||
35 | bool isSelected() const; | ||
36 | private: | ||
37 | const std::string m_filename; | ||
38 | }; | ||
39 | |||
40 | #endif // ROOTCMDMENUITEM_HH | ||