From 393ba45f91480bb10f510248837c6051b7ff6a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Tue, 5 Apr 2016 14:14:13 +0200 Subject: 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 --- src/ToolFactory.cc | 34 +++++++++++++++++++++++++++++++--- 1 file 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 @@ #include "ButtonTheme.hh" #include "FbTk/CommandParser.hh" +#include "FbTk/Resource.hh" #include "Screen.hh" #include "ScreenPlacement.hh" #include "Toolbar.hh" @@ -109,13 +110,40 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow & return 0; } item = new SpacerTool(size); + } else if (name.find("button.") == 0) { + // A generic button. Needs a label and a command (chain) configured + std::string label = FbTk::Resource + (m_screen.resourceManager(), "", + m_screen.name() + ".toolbar." + name + ".label", + m_screen.altName() + ".Toolbar." + name + ".Label"); + if (label.empty()) + return 0; + FbTk::TextButton *btn = new FbTk::TextButton(parent, m_button_theme->font(), label); + + std::string cmd_str = FbTk::Resource + (m_screen.resourceManager(), "", + m_screen.name() + ".toolbar." + name + ".commands", + m_screen.altName() + ".Toolbar." + name + ".Commands"); + std::list commands; + FbTk::StringUtil::stringtok(commands, cmd_str, ":"); + std::list::iterator it = commands.begin(); + int i = 1; + for (; it != commands.end(); ++it, ++i) { + std::string cmd_str = *it; + FbTk::StringUtil::removeTrailingWhitespace(cmd_str); + FbTk::StringUtil::removeFirstWhitespace(cmd_str); + FbTk::RefCount > cmd(cp.parse(cmd_str)); + if (cmd) + btn->setOnClick(cmd, i); + } + item = new ButtonTool(btn, ToolbarItem::FIXED, + dynamic_cast(*m_button_theme), + screen().imageControl()); } else { - std::string cmd_str = name; if (name == "prevwindow" || name == "nextwindow") { cmd_str += " (workspace=[current])"; } - FbTk::RefCount > cmd(cp.parse(cmd_str)); if (cmd == 0) // we need a command return 0; @@ -129,7 +157,7 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow & 0, 0, button_size, button_size); win->setOnClick(cmd); - item = new ButtonTool(win, ToolbarItem::SQUARE, + item = new ButtonTool(win, ToolbarItem::SQUARE, dynamic_cast(*m_button_theme), screen().imageControl()); } -- cgit v0.11.2