forked from mia/Aegisub
Update TooltipManager to work with commands
Originally committed to SVN as r5231.
This commit is contained in:
parent
04a4c074b0
commit
33d8dd2975
3 changed files with 45 additions and 138 deletions
|
@ -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"));
|
||||
|
|
|
@ -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<ToolTipBinding>::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<std::string> 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,42 +34,16 @@
|
|||
/// @ingroup custom_control
|
||||
///
|
||||
|
||||
|
||||
|
||||
|
||||
///////////
|
||||
// Headers
|
||||
#ifndef AGI_PRE
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include <wx/arrstr.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/window.h>
|
||||
#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<ToolTipBinding> 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);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue