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)
{
if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip();
hotkey::check("Audio", context, event);
}
void AudioDisplay::OnSize(wxSizeEvent &)

View file

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

View file

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

View file

@ -247,7 +247,7 @@ void DialogStyling::OnPlayAudioButton(wxCommandEvent &) {
}
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
// actually does something
if (evt.GetKeyCode() == WXK_BACK && !evt.GetModifiers()) {

View file

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

View file

@ -683,8 +683,7 @@ void FrameMain::OnSubtitlesOpen() {
}
void FrameMain::OnKeyDown(wxKeyEvent &event) {
if (!hotkey::check("Main Frame", context.get(), event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip();
hotkey::check("Main Frame", context.get(), event);
}
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;
}
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) {
return inst->GetHotkeys(context, command);
}

View file

@ -21,6 +21,8 @@
#ifndef AGI_PRE
#include <string>
#include <vector>
#include <wx/event.h>
#endif
namespace agi {
@ -35,6 +37,7 @@ extern agi::hotkey::Hotkey *inst;
void init();
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);
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);

View file

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

View file

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

View file

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