aboutsummaryrefslogtreecommitdiff
path: root/src/WorkspaceCmd.cc
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2007-12-20 20:23:56 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2007-12-20 20:23:56 (GMT)
commit03dce043b78103a977bd6c48b81bb1b462aaac5f (patch)
tree6cc49956acf8c4049f7d6702058534d29c1c15c2 /src/WorkspaceCmd.cc
parentb90a7e21a9f56f8e9f92c7ec357cbf683e6fd712 (diff)
downloadfluxbox-03dce043b78103a977bd6c48b81bb1b462aaac5f.zip
fluxbox-03dce043b78103a977bd6c48b81bb1b462aaac5f.tar.bz2
added ForEach key command
Diffstat (limited to 'src/WorkspaceCmd.cc')
-rw-r--r--src/WorkspaceCmd.cc47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index 2d2964e..bb1537e 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -35,6 +35,7 @@
35#include "FbTk/KeyUtil.hh" 35#include "FbTk/KeyUtil.hh"
36#include "FbTk/ObjectRegistry.hh" 36#include "FbTk/ObjectRegistry.hh"
37#include "FbTk/stringstream.hh" 37#include "FbTk/stringstream.hh"
38#include "FbTk/StringUtil.hh"
38 39
39#ifdef HAVE_CMATH 40#ifdef HAVE_CMATH
40 #include <cmath> 41 #include <cmath>
@@ -43,30 +44,58 @@
43#endif 44#endif
44#include <algorithm> 45#include <algorithm>
45#include <functional> 46#include <functional>
47#include <vector>
46 48
47using std::string; 49using std::string;
48using FbTk::Command; 50using FbTk::Command;
49using FbTk::BoolCommand; 51using FbTk::BoolCommand;
50 52
51void WindowListCmd::execute() { 53REGISTER_OBJECT_PARSER(map, WindowListCmd::parse, Command);
52 if (m_pat.error()) { 54REGISTER_OBJECT_PARSER(foreach, WindowListCmd::parse, Command);
53 m_cmd->execute(); 55
54 return; 56FbTk::Command *WindowListCmd::parse(const string &command, const string &args,
57 bool trusted) {
58 FbTk::Command *cmd = 0;
59 FbTk::BoolCommand *filter = 0;
60 std::vector<string> tokens;
61 int opts;
62 string pat;
63
64 FbTk::StringUtil::stringTokensBetween(tokens, args, pat, '{', '}');
65 if (tokens.empty())
66 return 0;
67
68 cmd = FbTk::ObjectRegistry<Command>::instance().parse(tokens[0], trusted);
69 if (!cmd)
70 return 0;
71
72 if (tokens.size() > 1) {
73 FocusableList::parseArgs(tokens[1], opts, pat);
74
75 filter = FbTk::ObjectRegistry<BoolCommand>::instance().parse(pat,
76 trusted);
55 } 77 }
56 78
79 return new WindowListCmd(FbTk::RefCount<Command>(cmd), opts,
80 FbTk::RefCount<BoolCommand>(filter));
81}
82
83void WindowListCmd::execute() {
57 BScreen *screen = Fluxbox::instance()->keyScreen(); 84 BScreen *screen = Fluxbox::instance()->keyScreen();
58 if (screen != 0) { 85 if (screen != 0) {
59 FocusControl::Focusables win_list(screen->focusControl().creationOrderWinList().clientList()); 86 FocusableList::Focusables win_list(FocusableList::getListFromOptions(*screen, m_opts)->clientList());
60 87
61 FocusControl::Focusables::iterator it = win_list.begin(), 88 FocusableList::Focusables::iterator it = win_list.begin(),
62 it_end = win_list.end(); 89 it_end = win_list.end();
63 // save old value, so we can restore it later 90 // save old value, so we can restore it later
64 WinClient *old = WindowCmd<void>::client(); 91 WinClient *old = WindowCmd<void>::client();
65 for (; it != it_end; ++it) { 92 for (; it != it_end; ++it) {
66 if (m_pat.match(**it) && (*it)->fbwindow()) { 93 if (typeid(**it) == typeid(FluxboxWindow))
67 WindowCmd<void>::setWindow((*it)->fbwindow()); 94 WindowCmd<void>::setWindow((*it)->fbwindow());
95 else if (typeid(**it) == typeid(WinClient))
96 WindowCmd<void>::setClient(dynamic_cast<WinClient *>(*it));
97 if (!*m_filter || m_filter->bool_execute())
68 m_cmd->execute(); 98 m_cmd->execute();
69 }
70 } 99 }
71 WindowCmd<void>::setClient(old); 100 WindowCmd<void>::setClient(old);
72 } 101 }