Make hotkey::check return whether any hotkeys matched, and skip events which did not match any hotkeys

Originally committed to SVN as r5241.
This commit is contained in:
Thomas Goyne 2011-01-19 03:12:46 +00:00
parent ec3d1a9d35
commit ccddf8eab1
10 changed files with 26 additions and 18 deletions

View file

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

View file

@ -1129,12 +1129,13 @@ bool BaseGrid::IsDisplayed(const AssDialogue *line) const {
/// @return
///
void BaseGrid::OnKeyDown(wxKeyEvent &event) {
event.StopPropagation();
if (hotkey::check("Subtitle Grid", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
return;
int w,h;
GetClientSize(&w,&h);
hotkey::check("Subtitle Grid", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
event.StopPropagation();
// Get scan code
int key = event.GetKeyCode();
#ifdef __APPLE__
@ -1219,8 +1220,8 @@ void BaseGrid::OnKeyDown(wxKeyEvent &event) {
return;
}
}
else {
hotkey::check("Audio", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
else if (!hotkey::check("Audio", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) {
event.Skip();
}
}

View file

@ -405,7 +405,8 @@ END_EVENT_TABLE()
///
void StyleEditBox::OnKeyDown(wxKeyEvent &event) {
hotkey::check("Styling Assistant", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
if (!hotkey::check("Styling Assistant", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip();
event.StopPropagation();
//H I think most of this can be removed.

View file

@ -314,7 +314,8 @@ void DialogTranslationEvent::OnTransBoxKey(wxKeyEvent &event) { control->OnTrans
/// @return
///
void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) {
hotkey::check("Translation Assistant", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
if (!hotkey::check("Translation Assistant", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip();
event.StopPropagation();
// H convert below to commands.

View file

@ -1362,6 +1362,7 @@ void FrameMain::OnSubtitlesSave() {
}
void FrameMain::OnKeyDown(wxKeyEvent &event) {
hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
if (!hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip();
}

View file

@ -45,7 +45,7 @@ static std::vector<std::string> keycode_names;
static std::string const& get_keycode_name(int code);
static void init_keycode_names();
std::string const& keycode_name(int code) {
static std::string const& keycode_name(int code) {
if (keycode_names.empty())
init_keycode_names();
@ -57,7 +57,7 @@ std::string const& keycode_name(int code) {
return keycode_names[code];
}
void check(std::string const& context, int key_code, wchar_t key_char, int modifier) {
bool check(std::string const& context, int key_code, wchar_t key_char, int modifier) {
std::string combo;
if ((modifier != wxMOD_NONE)) {
if ((modifier & wxMOD_CMD) != 0) combo.append("Ctrl-");
@ -66,15 +66,18 @@ void check(std::string const& context, int key_code, wchar_t key_char, int modif
}
combo += keycode_name(key_code);
if (combo.empty()) return;
if (combo.empty()) return false;
std::string command;
if (agi::hotkey::hotkey->Scan(context, combo, command) == 0) {
/// The bottom line should be removed after all the hotkey commands are fixed.
/// This is to avoid pointless exceptions.
if (command.find("/") != std::string::npos)
if (command.find("/") != std::string::npos) {
(*cmd::get(command))(wxGetApp().frame->context.get());
return true;
}
}
return false;
}
std::vector<std::string> get_hotkey_strs(std::string const& context, std::string const& command) {

View file

@ -30,7 +30,7 @@
namespace hotkey {
void check(std::string const& context, int key_code, wchar_t key_char, int modifier);
bool check(std::string const& context, int key_code, wchar_t key_char, int modifier);
std::string get_hotkey_str_first(std::string const& context, std::string const& command);
std::vector<std::string> get_hotkey_strs(std::string const& context, std::string const& command);

View file

@ -424,9 +424,9 @@ void SubsEditBox::UpdateFrameTiming(agi::vfr::Framerate const& fps) {
}
void SubsEditBox::OnKeyDown(wxKeyEvent &event) {
hotkey::check("Subtitle Edit Box", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
event.StopPropagation();
if (hotkey::check("Subtitle Edit Box", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
return;
int key = event.GetKeyCode();
if (line && (key == WXK_RETURN || key == WXK_NUMPAD_ENTER)) {

View file

@ -48,7 +48,6 @@
#include "command/command.h"
#include "include/aegisub/context.h"
#include "include/aegisub/hotkey.h"
#include "include/aegisub/audio_provider.h"
#include "ass_file.h"

View file

@ -499,8 +499,9 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
ShowCursor(activeMode != Video_Mode_Standard);
}
void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
hotkey::check("Video Display", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers());
event.StopPropagation();
if (hotkey::check("Video Display", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
return;
/*
int key = event.GetKeyCode();