1
0
Fork 0

Show hotkeys for vector clip tools

Move the function to generate toolbar tooltips listing hotkeys to the
command class, so it can be used outside of toolbar.cpp .
This commit is contained in:
arch1t3cht 2022-07-12 16:54:04 +02:00
parent 7da4493a0f
commit eb07b3f9b8
4 changed files with 18 additions and 13 deletions

View File

@ -19,6 +19,9 @@
#include <libaegisub/log.h>
#include <boost/algorithm/string/join.hpp>
#include "include/aegisub/hotkey.h"
#include <wx/intl.h>
namespace cmd {
@ -32,6 +35,16 @@ namespace cmd {
return it;
}
wxString Command::GetTooltip(std::string ht_context) const {
wxString ret = StrHelp();
std::vector<std::string> hotkeys = hotkey::get_hotkey_strs(ht_context, name());
if (!hotkeys.empty())
ret += to_wx(" (" + boost::join(hotkeys, "/") + ")");
return ret;
}
void reg(std::unique_ptr<Command> cmd) {
cmd_map[cmd->name()] = std::move(cmd);
}

View File

@ -103,6 +103,9 @@ DEFINE_EXCEPTION(CommandNotFound, CommandError);
/// Short help string describing what the command does
virtual wxString StrHelp() const=0;
/// Formats the Help text together with the registered hotkey
wxString GetTooltip(std::string ht_context) const;
/// Get this command's type flags
/// @return Bitmask of CommandFlags
virtual int Type() const { return COMMAND_NORMAL; }

View File

@ -30,7 +30,6 @@
#include <libaegisub/log.h>
#include <libaegisub/signal.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/interprocess/streams/bufferstream.hpp>
#include <vector>
@ -143,7 +142,7 @@ namespace {
wxITEM_NORMAL;
wxBitmap const& bitmap = command->Icon(icon_size, retina_helper.GetScaleFactor(), GetLayoutDirection());
AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), bitmap, GetTooltip(command), kind);
AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), bitmap, command->GetTooltip(ht_context), kind);
commands.push_back(command);
needs_onidle = needs_onidle || flags != cmd::COMMAND_NORMAL;
@ -157,16 +156,6 @@ namespace {
Realize();
}
wxString GetTooltip(cmd::Command *command) {
wxString ret = command->StrHelp();
std::vector<std::string> hotkeys = hotkey::get_hotkey_strs(ht_context, command->name());
if (!hotkeys.empty())
ret += to_wx(" (" + boost::join(hotkeys, "/") + ")");
return ret;
}
public:
Toolbar(wxWindow *parent, std::string name, agi::Context *c, std::string ht_context, bool vertical)
: wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize, wxTB_NODIVIDER | wxTB_FLAT | (vertical ? wxTB_VERTICAL : wxTB_HORIZONTAL))

View File

@ -52,7 +52,7 @@ void VisualToolVectorClip::AddTool(std::string command_name, VisualToolVectorCli
}
int icon_size = OPT_GET("App/Toolbar Icon Size")->GetInt();
toolBar->AddTool(BUTTON_ID_BASE + mode, command->StrDisplay(c), command->Icon(icon_size), command->StrHelp(), wxITEM_CHECK);
toolBar->AddTool(BUTTON_ID_BASE + mode, command->StrDisplay(c), command->Icon(icon_size), command->GetTooltip("Video"), wxITEM_CHECK);
}