Stop key event propagation when checking for hotkeys to avoid checking keypresses that aren't hotkeys several times

Originally committed to SVN as r6577.
This commit is contained in:
Thomas Goyne 2012-03-12 23:34:34 +00:00
parent 14274a7672
commit de9cc755d2
11 changed files with 23 additions and 18 deletions

View File

@ -1119,8 +1119,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
void AudioDisplay::OnKeyDown(wxKeyEvent& event) void AudioDisplay::OnKeyDown(wxKeyEvent& event)
{ {
if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) hotkey::check("Audio", context, event);
event.Skip();
} }
void AudioDisplay::OnSize(wxSizeEvent &) void AudioDisplay::OnSize(wxSizeEvent &)

View File

@ -974,7 +974,7 @@ bool BaseGrid::IsDisplayed(const AssDialogue *line) const {
} }
void BaseGrid::OnKeyDown(wxKeyEvent &event) { void BaseGrid::OnKeyDown(wxKeyEvent &event) {
if (hotkey::check("Subtitle Grid", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (hotkey::check("Subtitle Grid", context, event))
return; return;
int w,h; int w,h;
@ -1044,9 +1044,8 @@ void BaseGrid::OnKeyDown(wxKeyEvent &event) {
return; return;
} }
} }
else if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) { else
event.Skip(); hotkey::check("Audio", context, event);
}
} }
void BaseGrid::SetByFrame(bool state) { void BaseGrid::SetByFrame(bool state) {

View File

@ -117,8 +117,7 @@ void DialogDetachedVideo::OnMinimize(wxIconizeEvent &event) {
} }
void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) { void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) {
if (!hotkey::check("Video Display", context, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) hotkey::check("Video Display", context, evt);
evt.Skip();
} }
void DialogDetachedVideo::OnVideoOpen() { void DialogDetachedVideo::OnVideoOpen() {

View File

@ -247,7 +247,7 @@ void DialogStyling::OnPlayAudioButton(wxCommandEvent &) {
} }
void DialogStyling::OnKeyDown(wxKeyEvent &evt) { void DialogStyling::OnKeyDown(wxKeyEvent &evt) {
if (!hotkey::check("Styling Assistant", c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) { if (!hotkey::check("Styling Assistant", c, evt)) {
// Move the beginning of the selection back one character so that backspace // Move the beginning of the selection back one character so that backspace
// actually does something // actually does something
if (evt.GetKeyCode() == WXK_BACK && !evt.GetModifiers()) { if (evt.GetKeyCode() == WXK_BACK && !evt.GetModifiers()) {

View File

@ -264,8 +264,7 @@ void DialogTranslation::InsertOriginal() {
void DialogTranslation::OnKeyDown(wxKeyEvent &evt) { void DialogTranslation::OnKeyDown(wxKeyEvent &evt) {
if (!hotkey::check("Translation Assistant", c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) hotkey::check("Translation Assistant", c, evt);
evt.Skip();
} }
void DialogTranslation::OnPlayVideoButton(wxCommandEvent &) { void DialogTranslation::OnPlayVideoButton(wxCommandEvent &) {

View File

@ -683,8 +683,7 @@ void FrameMain::OnSubtitlesOpen() {
} }
void FrameMain::OnKeyDown(wxKeyEvent &event) { void FrameMain::OnKeyDown(wxKeyEvent &event) {
if (!hotkey::check("Main Frame", context.get(), event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) hotkey::check("Main Frame", context.get(), event);
event.Skip();
} }
void FrameMain::OnMouseWheel(wxMouseEvent &evt) { void FrameMain::OnMouseWheel(wxMouseEvent &evt) {

View File

@ -133,6 +133,15 @@ bool check(std::string const& context, agi::Context *c, int key_code, wchar_t ke
return false; return false;
} }
bool check(std::string const& context, agi::Context *c, wxKeyEvent &evt) {
evt.StopPropagation();
if (!hotkey::check(context, c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) {
evt.Skip();
return false;
}
return true;
}
std::vector<std::string> get_hotkey_strs(std::string const& context, std::string const& command) { std::vector<std::string> get_hotkey_strs(std::string const& context, std::string const& command) {
return inst->GetHotkeys(context, command); return inst->GetHotkeys(context, command);
} }

View File

@ -21,6 +21,8 @@
#ifndef AGI_PRE #ifndef AGI_PRE
#include <string> #include <string>
#include <vector> #include <vector>
#include <wx/event.h>
#endif #endif
namespace agi { namespace agi {
@ -35,6 +37,7 @@ extern agi::hotkey::Hotkey *inst;
void init(); void init();
void clear(); void clear();
bool check(std::string const& context, agi::Context *c, wxKeyEvent &evt);
bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier); bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier);
std::string keypress_to_str(int key_code, wchar_t key_char, int modifier); std::string keypress_to_str(int key_code, wchar_t key_char, int modifier);
std::string get_hotkey_str_first(std::string const& context, std::string const& command); std::string get_hotkey_str_first(std::string const& context, std::string const& command);

View File

@ -400,8 +400,7 @@ void SubsEditBox::UpdateFrameTiming(agi::vfr::Framerate const& fps) {
} }
void SubsEditBox::OnKeyDown(wxKeyEvent &event) { void SubsEditBox::OnKeyDown(wxKeyEvent &event) {
if (!hotkey::check("Subtitle Edit Box", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) hotkey::check("Subtitle Edit Box", c, event);
event.Skip();
} }
void SubsEditBox::OnChange(wxStyledTextEvent &event) { void SubsEditBox::OnChange(wxStyledTextEvent &event) {

View File

@ -389,8 +389,7 @@ void VideoDisplay::OnContextMenu(wxContextMenuEvent&) {
} }
void VideoDisplay::OnKeyDown(wxKeyEvent &event) { void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
if (!hotkey::check("Video", con, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) hotkey::check("Video", con, event);
event.Skip();
} }
void VideoDisplay::SetZoom(double value) { void VideoDisplay::SetZoom(double value) {

View File

@ -149,7 +149,7 @@ void VideoSlider::OnMouse(wxMouseEvent &event) {
} }
void VideoSlider::OnKeyDown(wxKeyEvent &event) { void VideoSlider::OnKeyDown(wxKeyEvent &event) {
if (hotkey::check("Video", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (hotkey::check("Video", c, event))
return; return;
// Forward up/down to grid as those aren't yet handled by commands // Forward up/down to grid as those aren't yet handled by commands