From 319b454bb882a54aa68fd13f623b802dac26ae5f Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 17 Aug 2011 05:32:27 +0000 Subject: [PATCH] Add hotkeys to the tooltip for toolbar items Originally committed to SVN as r5538. --- aegisub/src/frame_main.cpp | 2 +- aegisub/src/include/aegisub/toolbar.h | 3 ++- aegisub/src/toolbar.cpp | 29 ++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 9d17e7e82..5b04d66de 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -254,7 +254,7 @@ void FrameMain::cmd_call(wxCommandEvent& event) { void FrameMain::InitToolbar () { wxSystemOptions::SetOption("msw.remap", 0); - toolbar::AttachToolbar(this, "main", context.get()); + toolbar::AttachToolbar(this, "main", context.get(), "Default"); GetToolBar()->Realize(); } diff --git a/aegisub/src/include/aegisub/toolbar.h b/aegisub/src/include/aegisub/toolbar.h index 74175906f..0f2e8edea 100644 --- a/aegisub/src/include/aegisub/toolbar.h +++ b/aegisub/src/include/aegisub/toolbar.h @@ -30,5 +30,6 @@ namespace toolbar { /// @param frame Frame to attach the toolbar to /// @param name Name of the toolbar /// @param context Project context - void AttachToolbar(wxFrame *frame, std::string const& name, agi::Context *context); + /// @param hotkey Hotkey context for the tooltip + void AttachToolbar(wxFrame *frame, std::string const& name, agi::Context *context, std::string const& hotkey); } diff --git a/aegisub/src/toolbar.cpp b/aegisub/src/toolbar.cpp index 2b74e0e31..4e64f404d 100644 --- a/aegisub/src/toolbar.cpp +++ b/aegisub/src/toolbar.cpp @@ -20,9 +20,11 @@ #include "config.h" +#include "include/aegisub/toolbar.h" + #include "command/command.h" #include "include/aegisub/context.h" -#include "include/aegisub/toolbar.h" +#include "include/aegisub/hotkey.h" #include "libresrc/libresrc.h" #include "main.h" @@ -56,6 +58,8 @@ namespace { agi::Context *context; /// Commands for each of the buttons std::vector commands; + /// Hotkey context + std::string ht_context; /// Listener for icon size change signal agi::signal::Connection icon_size_slot; @@ -126,7 +130,20 @@ namespace { flags & cmd::COMMAND_TOGGLE ? wxITEM_CHECK : wxITEM_NORMAL; - AddTool(TOOL_ID_BASE + commands.size(), command->StrMenu(), icon, command->StrHelp(), kind); + wxString tooltip = command->StrHelp(); + + std::vector hotkeys = hotkey::get_hotkey_strs(ht_context, command->name()); + + for (size_t i = 0; i < hotkeys.size(); ++i) { + if (i == 0) + tooltip += " ("; + else + tooltip += "/"; + tooltip += hotkeys[i]; + } + if (hotkeys.size()) tooltip += ")"; + + AddTool(TOOL_ID_BASE + commands.size(), command->StrDisplay(), icon, tooltip, kind); commands.push_back(command); needs_onidle = needs_onidle || flags != cmd::COMMAND_NORMAL; @@ -141,11 +158,13 @@ namespace { Realize(); } public: - Toolbar(wxWindow *parent, std::string const& name, agi::Context *c) + Toolbar(wxWindow *parent, std::string const& name, agi::Context *c, std::string const& ht_context) : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_HORIZONTAL) , name(name) , context(c) + , ht_context(ht_context) , icon_size_slot(OPT_SUB("App/Toolbar Icon Size", &Toolbar::OnIconSizeChanged, this)) + /// @todo bind to hotkey changed event when such a thing exists { Populate(); Bind(wxEVT_COMMAND_TOOL_CLICKED, &Toolbar::OnClick, this); @@ -154,7 +173,7 @@ namespace { } namespace toolbar { - void AttachToolbar(wxFrame *frame, std::string const& name, agi::Context *c) { - frame->SetToolBar(new Toolbar(frame, name, c)); + void AttachToolbar(wxFrame *frame, std::string const& name, agi::Context *c, std::string const& hotkey) { + frame->SetToolBar(new Toolbar(frame, name, c, hotkey)); } }