aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 }