aboutsummaryrefslogtreecommitdiff
path: root/src/ToolFactory.cc
diff options
context:
space:
mode:
authorThomas Lübking <thomas.luebking@gmail.com>2016-04-05 12:14:13 (GMT)
committerMathias Gumz <akira@fluxbox.org>2016-08-26 06:18:29 (GMT)
commit393ba45f91480bb10f510248837c6051b7ff6a03 (patch)
tree050ba91cec63e1265fc28f8a7810e622c2fc89d0 /src/ToolFactory.cc
parent5c1bb0a21f178ddc240aabdd2ead2da8e3d56858 (diff)
downloadfluxbox-393ba45f91480bb10f510248837c6051b7ff6a03.zip
fluxbox-393ba45f91480bb10f510248837c6051b7ff6a03.tar.bz2
toolbar: allow labeled general action buttons
With this patch you can add buttons like *.toolbar.button.foo.label: F *.toolbar.button.foo.commands: RootMenu:Exec foo *.toolbar.tools: button.foo, iconbar, ... button.*.label is mandatory button.*.commands suppots 5 mouse buttons, but the way stringtok works, it's required to add a blank (or some junk) between to colons to skip a button
Diffstat (limited to 'src/ToolFactory.cc')
-rw-r--r--src/ToolFactory.cc34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc
index a033656..4a932ea 100644
--- a/src/ToolFactory.cc
+++ b/src/ToolFactory.cc
@@ -37,6 +37,7 @@
37#include "ButtonTheme.hh" 37#include "ButtonTheme.hh"
38 38
39#include "FbTk/CommandParser.hh" 39#include "FbTk/CommandParser.hh"
40#include "FbTk/Resource.hh"
40#include "Screen.hh" 41#include "Screen.hh"
41#include "ScreenPlacement.hh" 42#include "ScreenPlacement.hh"
42#include "Toolbar.hh" 43#include "Toolbar.hh"
@@ -109,13 +110,40 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
109 return 0; 110 return 0;
110 } 111 }
111 item = new SpacerTool(size); 112 item = new SpacerTool(size);
113 } else if (name.find("button.") == 0) {
114 // A generic button. Needs a label and a command (chain) configured
115 std::string label = FbTk::Resource<std::string>
116 (m_screen.resourceManager(), "",
117 m_screen.name() + ".toolbar." + name + ".label",
118 m_screen.altName() + ".Toolbar." + name + ".Label");
119 if (label.empty())
120 return 0;
121 FbTk::TextButton *btn = new FbTk::TextButton(parent, m_button_theme->font(), label);
122
123 std::string cmd_str = FbTk::Resource<std::string>
124 (m_screen.resourceManager(), "",
125 m_screen.name() + ".toolbar." + name + ".commands",
126 m_screen.altName() + ".Toolbar." + name + ".Commands");
127 std::list<std::string> commands;
128 FbTk::StringUtil::stringtok(commands, cmd_str, ":");
129 std::list<std::string>::iterator it = commands.begin();
130 int i = 1;
131 for (; it != commands.end(); ++it, ++i) {
132 std::string cmd_str = *it;
133 FbTk::StringUtil::removeTrailingWhitespace(cmd_str);
134 FbTk::StringUtil::removeFirstWhitespace(cmd_str);
135 FbTk::RefCount<FbTk::Command<void> > cmd(cp.parse(cmd_str));
136 if (cmd)
137 btn->setOnClick(cmd, i);
138 }
139 item = new ButtonTool(btn, ToolbarItem::FIXED,
140 dynamic_cast<ButtonTheme &>(*m_button_theme),
141 screen().imageControl());
112 } else { 142 } else {
113
114 std::string cmd_str = name; 143 std::string cmd_str = name;
115 if (name == "prevwindow" || name == "nextwindow") { 144 if (name == "prevwindow" || name == "nextwindow") {
116 cmd_str += " (workspace=[current])"; 145 cmd_str += " (workspace=[current])";
117 } 146 }
118
119 FbTk::RefCount<FbTk::Command<void> > cmd(cp.parse(cmd_str)); 147 FbTk::RefCount<FbTk::Command<void> > cmd(cp.parse(cmd_str));
120 if (cmd == 0) // we need a command 148 if (cmd == 0) // we need a command
121 return 0; 149 return 0;
@@ -129,7 +157,7 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
129 0, 0, 157 0, 0,
130 button_size, button_size); 158 button_size, button_size);
131 win->setOnClick(cmd); 159 win->setOnClick(cmd);
132 item = new ButtonTool(win, ToolbarItem::SQUARE, 160 item = new ButtonTool(win, ToolbarItem::SQUARE,
133 dynamic_cast<ButtonTheme &>(*m_button_theme), 161 dynamic_cast<ButtonTheme &>(*m_button_theme),
134 screen().imageControl()); 162 screen().imageControl());
135 } 163 }