From 33d8dd297523c77e39a452e22820d1994236fa66 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 17 Jan 2011 23:53:52 +0000 Subject: [PATCH] Update TooltipManager to work with commands Originally committed to SVN as r5231. --- aegisub/src/audio_box.cpp | 27 +++++----- aegisub/src/tooltip_manager.cpp | 96 +++++++++------------------------ aegisub/src/tooltip_manager.h | 60 ++------------------- 3 files changed, 45 insertions(+), 138 deletions(-) diff --git a/aegisub/src/audio_box.cpp b/aegisub/src/audio_box.cpp index 2a40f365f..49ba071bc 100644 --- a/aegisub/src/audio_box.cpp +++ b/aegisub/src/audio_box.cpp @@ -147,46 +147,47 @@ AudioBox::AudioBox(wxWindow *parent, AudioController *_controller, SelectionCont wxSizer *ButtonSizer = new wxBoxSizer(wxHORIZONTAL); wxButton *temp; temp = new wxBitmapButton(this,Audio_Button_Prev,GETIMAGE(button_prev_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Previous line or syllable (%KEY%/%KEY%)"),_T("Audio Prev Line"),_T("Audio Prev Line Alt")); + ToolTipManager::Bind(temp,_("Previous line or syllable"), "Audio", "time/prev"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Next,GETIMAGE(button_next_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Next line/syllable (%KEY%/%KEY%)"),_T("Audio Next Line"),_T("Audio Next Line Alt")); + ToolTipManager::Bind(temp,_("Next line/syllable"), "Audio", "time/next"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Play,GETIMAGE(button_playsel_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Play selection (%KEY%/%KEY%)"),_T("Audio Play"),_T("Audio Play Alt")); + ToolTipManager::Bind(temp,_("Play selection"), "Audio", "audio/play/selection"); ButtonSizer->Add(temp,0,wxRIGHT,0); + /// @todo does this make any sense with default-commit? temp = new wxBitmapButton(this,Audio_Button_Play_Row,GETIMAGE(button_playline_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Play current line (%KEY%)"),_T("Audio Play Original Line")); + ToolTipManager::Bind(temp,_("Play current line"), "Audio", "Audio Play Original Line"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Stop,GETIMAGE(button_stop_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Stop (%KEY%)"),_T("Audio Stop")); + ToolTipManager::Bind(temp,_("Stop"), "Audio", "audio/stop"); ButtonSizer->Add(temp,0,wxRIGHT,10); temp = new wxBitmapButton(this,Audio_Button_Play_500ms_Before,GETIMAGE(button_playfivehbefore_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Play 500 ms before selection (%KEY%)"),_T("Audio Play 500ms Before")); + ToolTipManager::Bind(temp,_("Play 500 ms before selection"), "Audio", "audio/play/selection/before"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Play_500ms_After,GETIMAGE(button_playfivehafter_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Play 500 ms after selection (%KEY%)"),_T("Audio Play 500ms after")); + ToolTipManager::Bind(temp,_("Play 500 ms after selection"), "Audio", "audio/play/selection/after"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Play_500ms_First,GETIMAGE(button_playfirstfiveh_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Play first 500ms of selection (%KEY%)"),_T("Audio Play First 500ms")); + ToolTipManager::Bind(temp,_("Play first 500ms of selection"), "Audio", "audio/play/selection/begin"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Play_500ms_Last,GETIMAGE(button_playlastfiveh_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Play last 500ms of selection (%KEY%)"),_T("Audio Play Last 500ms")); + ToolTipManager::Bind(temp,_("Play last 500ms of selection"), "Audio", "audio/play/selection/end"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Play_To_End,GETIMAGE(button_playtoend_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Play from selection start to end of file (%KEY%)"),_T("Audio Play To End")); + ToolTipManager::Bind(temp,_("Play from selection start to end of file"), "Audio", "audio/play/to_end"); ButtonSizer->Add(temp,0,wxRIGHT,10); temp = new wxBitmapButton(this,Audio_Button_Leadin,GETIMAGE(button_leadin_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Add lead in (%KEY%)"),_T("Audio Add Lead In")); + ToolTipManager::Bind(temp,_("Add lead in"), "Audio", "time/lead/in"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Leadout,GETIMAGE(button_leadout_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Add lead out (%KEY%)"),_T("Audio Add Lead Out")); + ToolTipManager::Bind(temp,_("Add lead out"), "Audio", "time/lead/out"); ButtonSizer->Add(temp,0,wxRIGHT,10); temp = new wxBitmapButton(this,Audio_Button_Commit,GETIMAGE(button_audio_commit_16),wxDefaultPosition,wxDefaultSize); - ToolTipManager::Bind(temp,_("Commit changes (%KEY%/%KEY%)"),_T("Audio Commit (Stay)"),_T("Audio Commit Alt")); + ToolTipManager::Bind(temp,_("Commit changes"), "Audio", "audio/commit"); ButtonSizer->Add(temp,0,wxRIGHT,0); temp = new wxBitmapButton(this,Audio_Button_Goto,GETIMAGE(button_audio_goto_16),wxDefaultPosition,wxDefaultSize); temp->SetToolTip(_("Go to selection")); diff --git a/aegisub/src/tooltip_manager.cpp b/aegisub/src/tooltip_manager.cpp index 9f47f190f..11821c241 100644 --- a/aegisub/src/tooltip_manager.cpp +++ b/aegisub/src/tooltip_manager.cpp @@ -34,88 +34,44 @@ /// @ingroup custom_control /// - -/////////// -// Headers #include "config.h" #include "tooltip_manager.h" +#include "include/aegisub/hotkey.h" -/// @brief Update all tips -/// -void ToolTipManager::DoUpdate() { - for (std::list::iterator cur=tips.begin();cur!=tips.end();cur++) { - (*cur).Update(); - } -} +struct ToolTipBinding { + wxWindow *window; + wxString toolTip; + const char *command; + const char *context; + void Update(); +}; +ToolTipManager::ToolTipManager() { } +ToolTipManager::~ToolTipManager() { } - -/// @brief Add a tip -/// @param window -/// @param tooltip -/// @param hotkeys -/// -void ToolTipManager::AddTips(wxWindow *window,wxString tooltip,wxArrayString hotkeys) { - ToolTipBinding tip; - tip.hotkeys = hotkeys; - tip.window = window; - tip.toolTip = tooltip; +void ToolTipManager::Bind(wxWindow *window, wxString tooltip, const char *context, const char *command) { + ToolTipBinding tip = { window, tooltip, command, context }; tip.Update(); - tips.push_back(tip); -} + /// @todo bind to hotkey changed signal once such a thing exists - - -/// @brief Single hotkey overload -/// @param window -/// @param tooltip -/// @param hotkey -/// -void ToolTipManager::Bind(wxWindow *window,wxString tooltip,wxString hotkey) { - wxArrayString hotkeys; - if (!hotkey.IsEmpty()) hotkeys.Add(hotkey); - Bind(window,tooltip,hotkeys); -} - - - -/// @brief Two hotkeys overload -/// @param window -/// @param tooltip -/// @param hotkey1 -/// @param hotkey2 -/// -void ToolTipManager::Bind(wxWindow *window,wxString tooltip,wxString hotkey1,wxString hotkey2) { - wxArrayString hotkeys; - hotkeys.Add(hotkey1); - hotkeys.Add(hotkey2); - Bind(window,tooltip,hotkeys); -} - - - -/// @brief Static instance -/// @return -/// -ToolTipManager &ToolTipManager::GetInstance() { static ToolTipManager instance; - return instance; + instance.tips.push_back(tip); } - - -/// @brief Update a tip -/// void ToolTipBinding::Update() { - wxString finalTip = toolTip; - wxArrayString hotkeysLeft = hotkeys; - while (hotkeysLeft.Count()) { -//H finalTip.Replace(_T("%KEY%"),Hotkeys.GetText(hotkeysLeft[0]),false); - hotkeysLeft.RemoveAt(0); + std::vector hotkeys = hotkey::get_hotkey_strs(context, command); + + std::string str; + for (size_t i = 0; i < hotkeys.size(); ++i) { + if (i > 0) str += "/"; + str += hotkeys[i]; + } + if (str.empty()) { + window->SetToolTip(toolTip); + } + else { + window->SetToolTip(toolTip + " (" + str + ")"); } - window->SetToolTip(finalTip); } - - diff --git a/aegisub/src/tooltip_manager.h b/aegisub/src/tooltip_manager.h index e538ad2de..c5dcd82da 100644 --- a/aegisub/src/tooltip_manager.h +++ b/aegisub/src/tooltip_manager.h @@ -34,42 +34,16 @@ /// @ingroup custom_control /// - - - -/////////// -// Headers #ifndef AGI_PRE #include +#include #include #include #include #endif - -/// DOCME -/// @class ToolTipBinding -/// @brief DOCME -/// -/// DOCME -class ToolTipBinding { - friend class ToolTipManager; -private: - - /// DOCME - wxWindow *window; - - /// DOCME - wxString toolTip; - - /// DOCME - wxArrayString hotkeys; - - void Update(); -}; - - +struct ToolTipBinding; /// DOCME /// @class ToolTipManager @@ -77,37 +51,13 @@ private: /// /// DOCME class ToolTipManager { -private: - - /// @brief DOCME - /// - ToolTipManager() {}; + ToolTipManager(); + ~ToolTipManager(); ToolTipManager(ToolTipManager const&); ToolTipManager& operator=(ToolTipManager const&); - static ToolTipManager &GetInstance(); - - - /// DOCME std::list tips; - void DoUpdate(); - void AddTips(wxWindow *window,wxString tooltip,wxArrayString hotkeys); - public: - - /// @brief DOCME - /// - static void Update() { GetInstance().DoUpdate(); } - - /// @brief DOCME - /// @param window - /// @param tooltip - /// @param hotkeys - /// - static void Bind(wxWindow *window,wxString tooltip,wxArrayString hotkeys) { GetInstance().AddTips(window,tooltip,hotkeys); } - static void Bind(wxWindow *window,wxString tooltip,wxString hotkey=_T("")); - static void Bind(wxWindow *window,wxString tooltip,wxString hotkey1,wxString hotkey2); + static void Bind(wxWindow *window, wxString tooltip, const char *context, const char *command); }; - -