Skip to content

Commit

Permalink
Show hotkeys for vector clip tools
Browse files Browse the repository at this point in the history
Move the function to generate toolbar tooltips listing hotkeys to the
command class, so it can be used outside of toolbar.cpp .
  • Loading branch information
arch1t3cht committed Jan 21, 2025
1 parent dd48cdd commit eb2e503
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
13 changes: 13 additions & 0 deletions src/command/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "format.h"

#include <libaegisub/log.h>
#include <libaegisub/string.h>

#include "include/aegisub/hotkey.h"

#include <wx/intl.h>

Expand All @@ -32,6 +35,16 @@ static iterator find_command(std::string_view name) {
throw CommandNotFound(agi::format(_("'%s' is not a valid command name"), name));
}

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(" (" + agi::Join("/", hotkeys) + ")");

return ret;
}

void reg(std::unique_ptr<Command> cmd) {
auto name = cmd->name();
cmd_map.emplace(name, std::move(cmd));
Expand Down
3 changes: 3 additions & 0 deletions src/command/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
12 changes: 1 addition & 11 deletions src/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace {
wxITEM_NORMAL;

wxBitmap const& bitmap = command->Icon(icon_size, retina_helper.GetScaleFactor(), GetLayoutDirection());
AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), BITMAPBUNDLE(bitmap), GetTooltip(command), kind);
AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(context), BITMAPBUNDLE(bitmap), command->GetTooltip(ht_context), kind);

commands.push_back(command);
needs_onidle = needs_onidle || flags != cmd::COMMAND_NORMAL;
Expand All @@ -157,16 +157,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(" (" + agi::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))
Expand Down
2 changes: 1 addition & 1 deletion src/visual_tool_vector_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ VisualToolVectorClip::VisualToolVectorClip(VideoDisplay *parent, agi::Context *c
void VisualToolVectorClip::AddTool(std::string command_name, VisualToolVectorClipMode mode) {
cmd::Command *command = cmd::get(command_name);
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);
}


Expand Down

0 comments on commit eb2e503

Please sign in to comment.