diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2008-01-11 07:41:22 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2008-01-11 07:41:22 (GMT) |
commit | 9f2f65a698c4cc71373a7fe9d73a0889e0d3487b (patch) | |
tree | 4ad67db771d73ea3c48f80a1244037fc9754edd2 /src/WorkspaceCmd.cc | |
parent | 1f01d84c080d607a91eb417efcaf5e500b5f1d7e (diff) | |
download | fluxbox_pavel-9f2f65a698c4cc71373a7fe9d73a0889e0d3487b.zip fluxbox_pavel-9f2f65a698c4cc71373a7fe9d73a0889e0d3487b.tar.bz2 |
make FbTk::Command a template class, split parsing information out of ObjectRegistry
Diffstat (limited to 'src/WorkspaceCmd.cc')
-rw-r--r-- | src/WorkspaceCmd.cc | 94 |
1 files changed, 46 insertions, 48 deletions
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc index bc71e32..aba5914 100644 --- a/src/WorkspaceCmd.cc +++ b/src/WorkspaceCmd.cc | |||
@@ -31,7 +31,7 @@ | |||
31 | #include "WindowCmd.hh" | 31 | #include "WindowCmd.hh" |
32 | 32 | ||
33 | #include "FbTk/KeyUtil.hh" | 33 | #include "FbTk/KeyUtil.hh" |
34 | #include "FbTk/ObjectRegistry.hh" | 34 | #include "FbTk/CommandParser.hh" |
35 | #include "FbTk/stringstream.hh" | 35 | #include "FbTk/stringstream.hh" |
36 | #include "FbTk/StringUtil.hh" | 36 | #include "FbTk/StringUtil.hh" |
37 | 37 | ||
@@ -45,16 +45,14 @@ | |||
45 | #include <vector> | 45 | #include <vector> |
46 | 46 | ||
47 | using std::string; | 47 | using std::string; |
48 | using FbTk::Command; | ||
49 | using FbTk::BoolCommand; | ||
50 | 48 | ||
51 | REGISTER_OBJECT_PARSER(map, WindowListCmd::parse, Command); | 49 | REGISTER_COMMAND_PARSER(map, WindowListCmd::parse, void); |
52 | REGISTER_OBJECT_PARSER(foreach, WindowListCmd::parse, Command); | 50 | REGISTER_COMMAND_PARSER(foreach, WindowListCmd::parse, void); |
53 | 51 | ||
54 | FbTk::Command *WindowListCmd::parse(const string &command, const string &args, | 52 | FbTk::Command<void> *WindowListCmd::parse(const string &command, const string &args, |
55 | bool trusted) { | 53 | bool trusted) { |
56 | FbTk::Command *cmd = 0; | 54 | FbTk::Command<void> *cmd = 0; |
57 | FbTk::BoolCommand *filter = 0; | 55 | FbTk::Command<bool> *filter = 0; |
58 | std::vector<string> tokens; | 56 | std::vector<string> tokens; |
59 | int opts; | 57 | int opts; |
60 | string pat; | 58 | string pat; |
@@ -63,19 +61,19 @@ FbTk::Command *WindowListCmd::parse(const string &command, const string &args, | |||
63 | if (tokens.empty()) | 61 | if (tokens.empty()) |
64 | return 0; | 62 | return 0; |
65 | 63 | ||
66 | cmd = FbTk::ObjectRegistry<Command>::instance().parse(tokens[0], trusted); | 64 | cmd = FbTk::CommandParser<void>::instance().parse(tokens[0], trusted); |
67 | if (!cmd) | 65 | if (!cmd) |
68 | return 0; | 66 | return 0; |
69 | 67 | ||
70 | if (tokens.size() > 1) { | 68 | if (tokens.size() > 1) { |
71 | FocusableList::parseArgs(tokens[1], opts, pat); | 69 | FocusableList::parseArgs(tokens[1], opts, pat); |
72 | 70 | ||
73 | filter = FbTk::ObjectRegistry<BoolCommand>::instance().parse(pat, | 71 | filter = FbTk::CommandParser<bool>::instance().parse(pat, |
74 | trusted); | 72 | trusted); |
75 | } | 73 | } |
76 | 74 | ||
77 | return new WindowListCmd(FbTk::RefCount<Command>(cmd), opts, | 75 | return new WindowListCmd(FbTk::RefCount<FbTk::Command<void> >(cmd), opts, |
78 | FbTk::RefCount<BoolCommand>(filter)); | 76 | FbTk::RefCount<FbTk::Command<bool> >(filter)); |
79 | } | 77 | } |
80 | 78 | ||
81 | void WindowListCmd::execute() { | 79 | void WindowListCmd::execute() { |
@@ -92,29 +90,29 @@ void WindowListCmd::execute() { | |||
92 | WindowCmd<void>::setWindow((*it)->fbwindow()); | 90 | WindowCmd<void>::setWindow((*it)->fbwindow()); |
93 | else if (typeid(**it) == typeid(WinClient)) | 91 | else if (typeid(**it) == typeid(WinClient)) |
94 | WindowCmd<void>::setClient(dynamic_cast<WinClient *>(*it)); | 92 | WindowCmd<void>::setClient(dynamic_cast<WinClient *>(*it)); |
95 | if (!*m_filter || m_filter->bool_execute()) | 93 | if (!*m_filter || m_filter->execute()) |
96 | m_cmd->execute(); | 94 | m_cmd->execute(); |
97 | } | 95 | } |
98 | WindowCmd<void>::setClient(old); | 96 | WindowCmd<void>::setClient(old); |
99 | } | 97 | } |
100 | } | 98 | } |
101 | 99 | ||
102 | FbTk::BoolCommand *SomeCmd::parse(const string &command, const string &args, | 100 | FbTk::Command<bool> *SomeCmd::parse(const string &command, const string &args, |
103 | bool trusted) { | 101 | bool trusted) { |
104 | FbTk::BoolCommand *boolcmd = | 102 | FbTk::Command<bool> *boolcmd = |
105 | FbTk::ObjectRegistry<FbTk::BoolCommand>::instance().parse(args, | 103 | FbTk::CommandParser<bool>::instance().parse(args, |
106 | trusted); | 104 | trusted); |
107 | if (!boolcmd) | 105 | if (!boolcmd) |
108 | return 0; | 106 | return 0; |
109 | if (command == "some") | 107 | if (command == "some") |
110 | return new SomeCmd(FbTk::RefCount<FbTk::BoolCommand>(boolcmd)); | 108 | return new SomeCmd(FbTk::RefCount<FbTk::Command<bool> >(boolcmd)); |
111 | return new EveryCmd(FbTk::RefCount<FbTk::BoolCommand>(boolcmd)); | 109 | return new EveryCmd(FbTk::RefCount<FbTk::Command<bool> >(boolcmd)); |
112 | } | 110 | } |
113 | 111 | ||
114 | REGISTER_OBJECT_PARSER(some, SomeCmd::parse, BoolCommand); | 112 | REGISTER_COMMAND_PARSER(some, SomeCmd::parse, bool); |
115 | REGISTER_OBJECT_PARSER(every, SomeCmd::parse, BoolCommand); | 113 | REGISTER_COMMAND_PARSER(every, SomeCmd::parse, bool); |
116 | 114 | ||
117 | bool SomeCmd::bool_execute() { | 115 | bool SomeCmd::execute() { |
118 | BScreen *screen = Fluxbox::instance()->keyScreen(); | 116 | BScreen *screen = Fluxbox::instance()->keyScreen(); |
119 | if (screen != 0) { | 117 | if (screen != 0) { |
120 | FocusControl::Focusables win_list(screen->focusControl().creationOrderList().clientList()); | 118 | FocusControl::Focusables win_list(screen->focusControl().creationOrderList().clientList()); |
@@ -127,7 +125,7 @@ bool SomeCmd::bool_execute() { | |||
127 | WinClient *client = dynamic_cast<WinClient *>(*it); | 125 | WinClient *client = dynamic_cast<WinClient *>(*it); |
128 | if (!client) continue; | 126 | if (!client) continue; |
129 | WindowCmd<void>::setClient(client); | 127 | WindowCmd<void>::setClient(client); |
130 | if (m_cmd->bool_execute()) | 128 | if (m_cmd->execute()) |
131 | return true; | 129 | return true; |
132 | } | 130 | } |
133 | WindowCmd<void>::setClient(old); | 131 | WindowCmd<void>::setClient(old); |
@@ -135,7 +133,7 @@ bool SomeCmd::bool_execute() { | |||
135 | return false; | 133 | return false; |
136 | } | 134 | } |
137 | 135 | ||
138 | bool EveryCmd::bool_execute() { | 136 | bool EveryCmd::execute() { |
139 | BScreen *screen = Fluxbox::instance()->keyScreen(); | 137 | BScreen *screen = Fluxbox::instance()->keyScreen(); |
140 | if (screen != 0) { | 138 | if (screen != 0) { |
141 | FocusControl::Focusables win_list(screen->focusControl().creationOrderList().clientList()); | 139 | FocusControl::Focusables win_list(screen->focusControl().creationOrderList().clientList()); |
@@ -148,7 +146,7 @@ bool EveryCmd::bool_execute() { | |||
148 | WinClient *client = dynamic_cast<WinClient *>(*it); | 146 | WinClient *client = dynamic_cast<WinClient *>(*it); |
149 | if (!client) continue; | 147 | if (!client) continue; |
150 | WindowCmd<void>::setClient(client); | 148 | WindowCmd<void>::setClient(client); |
151 | if (!m_cmd->bool_execute()) | 149 | if (!m_cmd->execute()) |
152 | return false; | 150 | return false; |
153 | } | 151 | } |
154 | WindowCmd<void>::setClient(old); | 152 | WindowCmd<void>::setClient(old); |
@@ -158,7 +156,7 @@ bool EveryCmd::bool_execute() { | |||
158 | 156 | ||
159 | namespace { | 157 | namespace { |
160 | 158 | ||
161 | FbTk::Command *parseWindowList(const string &command, | 159 | FbTk::Command<void> *parseWindowList(const string &command, |
162 | const string &args, bool trusted) { | 160 | const string &args, bool trusted) { |
163 | int opts; | 161 | int opts; |
164 | string pat; | 162 | string pat; |
@@ -179,11 +177,11 @@ FbTk::Command *parseWindowList(const string &command, | |||
179 | return 0; | 177 | return 0; |
180 | } | 178 | } |
181 | 179 | ||
182 | REGISTER_OBJECT_PARSER(attach, parseWindowList, Command); | 180 | REGISTER_COMMAND_PARSER(attach, parseWindowList, void); |
183 | REGISTER_OBJECT_PARSER(nextwindow, parseWindowList, Command); | 181 | REGISTER_COMMAND_PARSER(nextwindow, parseWindowList, void); |
184 | REGISTER_OBJECT_PARSER(nextgroup, parseWindowList, Command); | 182 | REGISTER_COMMAND_PARSER(nextgroup, parseWindowList, void); |
185 | REGISTER_OBJECT_PARSER(prevwindow, parseWindowList, Command); | 183 | REGISTER_COMMAND_PARSER(prevwindow, parseWindowList, void); |
186 | REGISTER_OBJECT_PARSER(prevgroup, parseWindowList, Command); | 184 | REGISTER_COMMAND_PARSER(prevgroup, parseWindowList, void); |
187 | 185 | ||
188 | }; // end anonymous namespace | 186 | }; // end anonymous namespace |
189 | 187 | ||
@@ -219,7 +217,7 @@ void PrevWindowCmd::execute() { | |||
219 | screen->cycleFocus(m_option, &m_pat, true); | 217 | screen->cycleFocus(m_option, &m_pat, true); |
220 | } | 218 | } |
221 | 219 | ||
222 | FbTk::Command *GoToWindowCmd::parse(const string &command, | 220 | FbTk::Command<void> *GoToWindowCmd::parse(const string &command, |
223 | const string &arguments, bool trusted) { | 221 | const string &arguments, bool trusted) { |
224 | int num, opts; | 222 | int num, opts; |
225 | string args, pat; | 223 | string args, pat; |
@@ -232,7 +230,7 @@ FbTk::Command *GoToWindowCmd::parse(const string &command, | |||
232 | return new GoToWindowCmd(num, opts, pat); | 230 | return new GoToWindowCmd(num, opts, pat); |
233 | } | 231 | } |
234 | 232 | ||
235 | REGISTER_OBJECT_PARSER(gotowindow, GoToWindowCmd::parse, Command); | 233 | REGISTER_COMMAND_PARSER(gotowindow, GoToWindowCmd::parse, void); |
236 | 234 | ||
237 | void GoToWindowCmd::execute() { | 235 | void GoToWindowCmd::execute() { |
238 | BScreen *screen = Fluxbox::instance()->keyScreen(); | 236 | BScreen *screen = Fluxbox::instance()->keyScreen(); |
@@ -243,7 +241,7 @@ void GoToWindowCmd::execute() { | |||
243 | } | 241 | } |
244 | } | 242 | } |
245 | 243 | ||
246 | FbTk::Command *DirFocusCmd::parse(const string &command, | 244 | FbTk::Command<void> *DirFocusCmd::parse(const string &command, |
247 | const string &args, bool trusted) { | 245 | const string &args, bool trusted) { |
248 | if (command == "focusup") | 246 | if (command == "focusup") |
249 | return new DirFocusCmd(FocusControl::FOCUSUP); | 247 | return new DirFocusCmd(FocusControl::FOCUSUP); |
@@ -256,10 +254,10 @@ FbTk::Command *DirFocusCmd::parse(const string &command, | |||
256 | return 0; | 254 | return 0; |
257 | } | 255 | } |
258 | 256 | ||
259 | REGISTER_OBJECT_PARSER(focusup, DirFocusCmd::parse, Command); | 257 | REGISTER_COMMAND_PARSER(focusup, DirFocusCmd::parse, void); |
260 | REGISTER_OBJECT_PARSER(focusdown, DirFocusCmd::parse, Command); | 258 | REGISTER_COMMAND_PARSER(focusdown, DirFocusCmd::parse, void); |
261 | REGISTER_OBJECT_PARSER(focusleft, DirFocusCmd::parse, Command); | 259 | REGISTER_COMMAND_PARSER(focusleft, DirFocusCmd::parse, void); |
262 | REGISTER_OBJECT_PARSER(focusright, DirFocusCmd::parse, Command); | 260 | REGISTER_COMMAND_PARSER(focusright, DirFocusCmd::parse, void); |
263 | 261 | ||
264 | void DirFocusCmd::execute() { | 262 | void DirFocusCmd::execute() { |
265 | BScreen *screen = Fluxbox::instance()->keyScreen(); | 263 | BScreen *screen = Fluxbox::instance()->keyScreen(); |
@@ -271,7 +269,7 @@ void DirFocusCmd::execute() { | |||
271 | screen->focusControl().dirFocus(*win, m_dir); | 269 | screen->focusControl().dirFocus(*win, m_dir); |
272 | } | 270 | } |
273 | 271 | ||
274 | REGISTER_OBJECT(addworkspace, AddWorkspaceCmd, Command); | 272 | REGISTER_COMMAND(addworkspace, AddWorkspaceCmd, void); |
275 | 273 | ||
276 | void AddWorkspaceCmd::execute() { | 274 | void AddWorkspaceCmd::execute() { |
277 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | 275 | BScreen *screen = Fluxbox::instance()->mouseScreen(); |
@@ -279,7 +277,7 @@ void AddWorkspaceCmd::execute() { | |||
279 | screen->addWorkspace(); | 277 | screen->addWorkspace(); |
280 | } | 278 | } |
281 | 279 | ||
282 | REGISTER_OBJECT(removelastworkspace, RemoveLastWorkspaceCmd, Command); | 280 | REGISTER_COMMAND(removelastworkspace, RemoveLastWorkspaceCmd, void); |
283 | 281 | ||
284 | void RemoveLastWorkspaceCmd::execute() { | 282 | void RemoveLastWorkspaceCmd::execute() { |
285 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | 283 | BScreen *screen = Fluxbox::instance()->mouseScreen(); |
@@ -289,7 +287,7 @@ void RemoveLastWorkspaceCmd::execute() { | |||
289 | 287 | ||
290 | namespace { | 288 | namespace { |
291 | 289 | ||
292 | FbTk::Command *parseIntCmd(const string &command, const string &args, | 290 | FbTk::Command<void> *parseIntCmd(const string &command, const string &args, |
293 | bool trusted) { | 291 | bool trusted) { |
294 | int num = 1; | 292 | int num = 1; |
295 | FbTk_istringstream iss(args.c_str()); | 293 | FbTk_istringstream iss(args.c_str()); |
@@ -308,11 +306,11 @@ FbTk::Command *parseIntCmd(const string &command, const string &args, | |||
308 | return 0; | 306 | return 0; |
309 | } | 307 | } |
310 | 308 | ||
311 | REGISTER_OBJECT_PARSER(nextworkspace, parseIntCmd, Command); | 309 | REGISTER_COMMAND_PARSER(nextworkspace, parseIntCmd, void); |
312 | REGISTER_OBJECT_PARSER(prevworkspace, parseIntCmd, Command); | 310 | REGISTER_COMMAND_PARSER(prevworkspace, parseIntCmd, void); |
313 | REGISTER_OBJECT_PARSER(rightworkspace, parseIntCmd, Command); | 311 | REGISTER_COMMAND_PARSER(rightworkspace, parseIntCmd, void); |
314 | REGISTER_OBJECT_PARSER(leftworkspace, parseIntCmd, Command); | 312 | REGISTER_COMMAND_PARSER(leftworkspace, parseIntCmd, void); |
315 | REGISTER_OBJECT_PARSER(workspace, parseIntCmd, Command); | 313 | REGISTER_COMMAND_PARSER(workspace, parseIntCmd, void); |
316 | 314 | ||
317 | }; // end anonymous namespace | 315 | }; // end anonymous namespace |
318 | 316 | ||
@@ -355,7 +353,7 @@ void JumpToWorkspaceCmd::execute() { | |||
355 | } | 353 | } |
356 | } | 354 | } |
357 | 355 | ||
358 | REGISTER_OBJECT(arrangewindows, ArrangeWindowsCmd, Command); | 356 | REGISTER_COMMAND(arrangewindows, ArrangeWindowsCmd, void); |
359 | 357 | ||
360 | /** | 358 | /** |
361 | try to arrange the windows on the current workspace in a 'clever' way. | 359 | try to arrange the windows on the current workspace in a 'clever' way. |
@@ -481,7 +479,7 @@ void ArrangeWindowsCmd::execute() { | |||
481 | } | 479 | } |
482 | } | 480 | } |
483 | 481 | ||
484 | REGISTER_OBJECT(showdesktop, ShowDesktopCmd, Command); | 482 | REGISTER_COMMAND(showdesktop, ShowDesktopCmd, void); |
485 | 483 | ||
486 | void ShowDesktopCmd::execute() { | 484 | void ShowDesktopCmd::execute() { |
487 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | 485 | BScreen *screen = Fluxbox::instance()->mouseScreen(); |
@@ -497,7 +495,7 @@ void ShowDesktopCmd::execute() { | |||
497 | } | 495 | } |
498 | } | 496 | } |
499 | 497 | ||
500 | REGISTER_OBJECT(closeallwindows, CloseAllWindowsCmd, Command); | 498 | REGISTER_COMMAND(closeallwindows, CloseAllWindowsCmd, void); |
501 | 499 | ||
502 | void CloseAllWindowsCmd::execute() { | 500 | void CloseAllWindowsCmd::execute() { |
503 | BScreen *screen = Fluxbox::instance()->mouseScreen(); | 501 | BScreen *screen = Fluxbox::instance()->mouseScreen(); |