Update TooltipManager to work with commands

Originally committed to SVN as r5231.
This commit is contained in:
Thomas Goyne 2011-01-17 23:53:52 +00:00
parent 04a4c074b0
commit 33d8dd2975
3 changed files with 45 additions and 138 deletions

View file

@ -147,46 +147,47 @@ AudioBox::AudioBox(wxWindow *parent, AudioController *_controller, SelectionCont
wxSizer *ButtonSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton *temp; wxButton *temp;
temp = new wxBitmapButton(this,Audio_Button_Prev,GETIMAGE(button_prev_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Next,GETIMAGE(button_next_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Play,GETIMAGE(button_playsel_16),wxDefaultPosition,wxDefaultSize); 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); 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); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Stop,GETIMAGE(button_stop_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,10);
temp = new wxBitmapButton(this,Audio_Button_Play_500ms_Before,GETIMAGE(button_playfivehbefore_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Play_500ms_After,GETIMAGE(button_playfivehafter_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Play_500ms_First,GETIMAGE(button_playfirstfiveh_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Play_500ms_Last,GETIMAGE(button_playlastfiveh_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Play_To_End,GETIMAGE(button_playtoend_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,10);
temp = new wxBitmapButton(this,Audio_Button_Leadin,GETIMAGE(button_leadin_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Leadout,GETIMAGE(button_leadout_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,10);
temp = new wxBitmapButton(this,Audio_Button_Commit,GETIMAGE(button_audio_commit_16),wxDefaultPosition,wxDefaultSize); 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); ButtonSizer->Add(temp,0,wxRIGHT,0);
temp = new wxBitmapButton(this,Audio_Button_Goto,GETIMAGE(button_audio_goto_16),wxDefaultPosition,wxDefaultSize); temp = new wxBitmapButton(this,Audio_Button_Goto,GETIMAGE(button_audio_goto_16),wxDefaultPosition,wxDefaultSize);
temp->SetToolTip(_("Go to selection")); temp->SetToolTip(_("Go to selection"));

View file

@ -34,88 +34,44 @@
/// @ingroup custom_control /// @ingroup custom_control
/// ///
///////////
// Headers
#include "config.h" #include "config.h"
#include "tooltip_manager.h" #include "tooltip_manager.h"
#include "include/aegisub/hotkey.h"
/// @brief Update all tips struct ToolTipBinding {
/// wxWindow *window;
void ToolTipManager::DoUpdate() { wxString toolTip;
for (std::list<ToolTipBinding>::iterator cur=tips.begin();cur!=tips.end();cur++) { const char *command;
(*cur).Update(); const char *context;
} void Update();
} };
ToolTipManager::ToolTipManager() { }
ToolTipManager::~ToolTipManager() { }
void ToolTipManager::Bind(wxWindow *window, wxString tooltip, const char *context, const char *command) {
/// @brief Add a tip ToolTipBinding tip = { window, tooltip, command, context };
/// @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;
tip.Update(); 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; static ToolTipManager instance;
return instance; instance.tips.push_back(tip);
} }
/// @brief Update a tip
///
void ToolTipBinding::Update() { void ToolTipBinding::Update() {
wxString finalTip = toolTip; std::vector<std::string> hotkeys = hotkey::get_hotkey_strs(context, command);
wxArrayString hotkeysLeft = hotkeys;
while (hotkeysLeft.Count()) { std::string str;
//H finalTip.Replace(_T("%KEY%"),Hotkeys.GetText(hotkeysLeft[0]),false); for (size_t i = 0; i < hotkeys.size(); ++i) {
hotkeysLeft.RemoveAt(0); if (i > 0) str += "/";
str += hotkeys[i];
}
if (str.empty()) {
window->SetToolTip(toolTip);
}
else {
window->SetToolTip(toolTip + " (" + str + ")");
} }
window->SetToolTip(finalTip);
} }

View file

@ -34,42 +34,16 @@
/// @ingroup custom_control /// @ingroup custom_control
/// ///
///////////
// Headers
#ifndef AGI_PRE #ifndef AGI_PRE
#include <list> #include <list>
#include <vector>
#include <wx/arrstr.h> #include <wx/arrstr.h>
#include <wx/string.h> #include <wx/string.h>
#include <wx/window.h> #include <wx/window.h>
#endif #endif
struct ToolTipBinding;
/// DOCME
/// @class ToolTipBinding
/// @brief DOCME
///
/// DOCME
class ToolTipBinding {
friend class ToolTipManager;
private:
/// DOCME
wxWindow *window;
/// DOCME
wxString toolTip;
/// DOCME
wxArrayString hotkeys;
void Update();
};
/// DOCME /// DOCME
/// @class ToolTipManager /// @class ToolTipManager
@ -77,37 +51,13 @@ private:
/// ///
/// DOCME /// DOCME
class ToolTipManager { class ToolTipManager {
private: ToolTipManager();
~ToolTipManager();
/// @brief DOCME
///
ToolTipManager() {};
ToolTipManager(ToolTipManager const&); ToolTipManager(ToolTipManager const&);
ToolTipManager& operator=(ToolTipManager const&); ToolTipManager& operator=(ToolTipManager const&);
static ToolTipManager &GetInstance();
/// DOCME
std::list<ToolTipBinding> tips; std::list<ToolTipBinding> tips;
void DoUpdate();
void AddTips(wxWindow *window,wxString tooltip,wxArrayString hotkeys);
public: public:
static void Bind(wxWindow *window, wxString tooltip, const char *context, const char *command);
/// @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);
}; };