Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
// Copyright (c) 2010, Amar Takhar <verm@aegisub.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
/// @file hotkey.cpp
|
|
|
|
/// @brief Hotkey handler
|
|
|
|
/// @ingroup hotkey menu event window
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <libaegisub/hotkey.h>
|
|
|
|
|
2011-01-05 19:40:37 +01:00
|
|
|
#include "include/aegisub/hotkey.h"
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
|
|
|
#include "libresrc/libresrc.h"
|
|
|
|
#include "command/command.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2013-01-30 04:35:37 +01:00
|
|
|
|
|
|
|
#include <libaegisub/path.h>
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2013-06-09 03:35:08 +02:00
|
|
|
#include <boost/range/algorithm/find.hpp>
|
|
|
|
|
2012-01-14 02:40:32 +01:00
|
|
|
namespace {
|
2012-10-05 01:56:02 +02:00
|
|
|
const char *removed_commands_7035[] = { 0 };
|
|
|
|
const char *added_hotkeys_7035[][4] = {
|
|
|
|
{ "audio/play/line", "Audio", "R", 0 },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
2012-10-09 18:41:55 +02:00
|
|
|
const char *removed_commands_7070[] = { 0 };
|
|
|
|
const char *added_hotkeys_7070[][4] = {
|
|
|
|
{ "edit/color/primary", "Subtitle Edit Box", "Alt", "1" },
|
|
|
|
{ "edit/color/secondary", "Subtitle Edit Box", "Alt", "2" },
|
|
|
|
{ "edit/color/outline", "Subtitle Edit Box", "Alt", "3" },
|
|
|
|
{ "edit/color/shadow", "Subtitle Edit Box", "Alt", "4" },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
2012-01-14 02:40:32 +01:00
|
|
|
void migrate_hotkeys(const char *removed[], const char *added[][4]) {
|
|
|
|
agi::hotkey::Hotkey::HotkeyMap hk_map = hotkey::inst->GetHotkeyMap();
|
|
|
|
|
2013-06-09 03:24:50 +02:00
|
|
|
for (size_t i = 0; removed[i]; ++i)
|
2012-01-14 02:40:32 +01:00
|
|
|
hk_map.erase(removed[i]);
|
|
|
|
|
|
|
|
for (size_t i = 0; added[i] && added[i][0]; ++i) {
|
|
|
|
std::vector<std::string> keys;
|
2013-06-09 03:24:50 +02:00
|
|
|
keys.emplace_back(added[i][2]);
|
2012-01-14 02:40:32 +01:00
|
|
|
if (added[i][3])
|
2013-06-09 03:24:50 +02:00
|
|
|
keys.emplace_back(added[i][3]);
|
2013-06-09 03:41:55 +02:00
|
|
|
agi::hotkey::Combo combo(added[i][1], added[i][0], keys);
|
|
|
|
|
|
|
|
if (hotkey::inst->HasHotkey(combo.Context(), combo.Str()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hk_map.insert(make_pair(std::string(added[i][0]), combo));
|
2012-01-14 02:40:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hotkey::inst->SetHotkeyMap(hk_map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
namespace hotkey {
|
|
|
|
|
2011-10-28 22:40:43 +02:00
|
|
|
agi::hotkey::Hotkey *inst = 0;
|
|
|
|
void init() {
|
|
|
|
inst = new agi::hotkey::Hotkey(
|
2013-01-30 04:35:37 +01:00
|
|
|
config::path->Decode("?user/hotkey.json"),
|
2011-10-28 22:40:43 +02:00
|
|
|
GET_DEFAULT_CONFIG(default_hotkey));
|
2012-01-14 02:40:32 +01:00
|
|
|
|
2013-06-09 03:35:08 +02:00
|
|
|
auto migrations = OPT_GET("App/Hotkey Migrations")->GetListString();
|
|
|
|
|
|
|
|
if (boost::find(migrations, "7035") == end(migrations)) {
|
2012-10-05 01:56:02 +02:00
|
|
|
migrate_hotkeys(removed_commands_7035, added_hotkeys_7035);
|
2013-06-09 03:35:08 +02:00
|
|
|
migrations.emplace_back("7035");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boost::find(migrations, "7070") == end(migrations)) {
|
2012-10-09 18:41:55 +02:00
|
|
|
migrate_hotkeys(removed_commands_7070, added_hotkeys_7070);
|
2013-06-09 03:35:08 +02:00
|
|
|
migrations.emplace_back("7070");
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT_SET("App/Hotkey Migrations")->SetListString(migrations);
|
2011-10-28 22:40:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
delete inst;
|
|
|
|
}
|
|
|
|
|
2011-01-16 08:17:53 +01:00
|
|
|
static std::vector<std::string> keycode_names;
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-01-16 08:17:53 +01:00
|
|
|
static void init_keycode_names();
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-01-19 04:12:46 +01:00
|
|
|
static std::string const& keycode_name(int code) {
|
2011-01-16 08:17:53 +01:00
|
|
|
if (keycode_names.empty())
|
|
|
|
init_keycode_names();
|
|
|
|
|
|
|
|
if (static_cast<size_t>(code) > keycode_names.size()) {
|
|
|
|
static std::string str;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keycode_names[code];
|
|
|
|
}
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2013-06-09 03:24:50 +02:00
|
|
|
std::string keypress_to_str(int key_code, int modifier) {
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
std::string combo;
|
|
|
|
if ((modifier != wxMOD_NONE)) {
|
|
|
|
if ((modifier & wxMOD_CMD) != 0) combo.append("Ctrl-");
|
|
|
|
if ((modifier & wxMOD_ALT) != 0) combo.append("Alt-");
|
|
|
|
if ((modifier & wxMOD_SHIFT) != 0) combo.append("Shift-");
|
|
|
|
}
|
|
|
|
|
2011-01-16 08:17:53 +01:00
|
|
|
combo += keycode_name(key_code);
|
2011-10-28 22:40:43 +02:00
|
|
|
|
|
|
|
return combo;
|
|
|
|
}
|
|
|
|
|
2013-06-09 03:24:50 +02:00
|
|
|
bool check(std::string const& context, agi::Context *c, int key_code, int modifier) {
|
|
|
|
std::string combo = keypress_to_str(key_code, modifier);
|
2011-01-19 04:12:46 +01:00
|
|
|
if (combo.empty()) return false;
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-12-22 22:27:06 +01:00
|
|
|
std::string command = inst->Scan(context, combo, OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool());
|
|
|
|
if (!command.empty()) {
|
2013-06-09 03:24:50 +02:00
|
|
|
cmd::call(command, c);
|
|
|
|
return true;
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
}
|
2011-01-19 04:12:46 +01:00
|
|
|
return false;
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 00:34:34 +01:00
|
|
|
bool check(std::string const& context, agi::Context *c, wxKeyEvent &evt) {
|
2013-06-09 03:24:50 +02:00
|
|
|
if (!hotkey::check(context, c, evt.GetKeyCode(), evt.GetModifiers())) {
|
2012-03-13 00:34:34 +01:00
|
|
|
evt.Skip();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-18 00:53:46 +01:00
|
|
|
std::vector<std::string> get_hotkey_strs(std::string const& context, std::string const& command) {
|
2011-10-28 22:40:43 +02:00
|
|
|
return inst->GetHotkeys(context, command);
|
2011-01-18 00:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string get_hotkey_str_first(std::string const& context, std::string const& command) {
|
2011-10-28 22:40:43 +02:00
|
|
|
return inst->GetHotkey(context, command);
|
2011-01-18 00:53:46 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 08:17:53 +01:00
|
|
|
static inline void set_kc(std::vector<std::string> &vec, int code, std::string const& str) {
|
|
|
|
if (static_cast<size_t>(code) >= vec.size()) vec.resize(code * 2, "");
|
|
|
|
vec[code] = str;
|
|
|
|
}
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
|
2011-01-16 08:17:53 +01:00
|
|
|
static void init_keycode_names() {
|
|
|
|
char str[] = { 0, 0 };
|
|
|
|
for (char i = 33; i < 127; ++i) {
|
|
|
|
str[0] = i;
|
|
|
|
set_kc(keycode_names, i, str);
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
}
|
2011-01-16 08:17:53 +01:00
|
|
|
set_kc(keycode_names, WXK_TAB, "Tab");
|
2011-07-26 21:53:08 +02:00
|
|
|
set_kc(keycode_names, WXK_RETURN, "Enter");
|
2011-01-16 08:17:53 +01:00
|
|
|
set_kc(keycode_names, WXK_ESCAPE, "Escape");
|
|
|
|
set_kc(keycode_names, WXK_SPACE, "Space");
|
|
|
|
set_kc(keycode_names, WXK_DELETE, "Delete");
|
|
|
|
set_kc(keycode_names, WXK_SHIFT, "Shift");
|
|
|
|
set_kc(keycode_names, WXK_ALT, "Alt");
|
|
|
|
set_kc(keycode_names, WXK_CONTROL, "Control");
|
|
|
|
set_kc(keycode_names, WXK_PAUSE, "Pause");
|
|
|
|
set_kc(keycode_names, WXK_END, "End");
|
|
|
|
set_kc(keycode_names, WXK_HOME, "Home");
|
|
|
|
set_kc(keycode_names, WXK_LEFT, "Left");
|
|
|
|
set_kc(keycode_names, WXK_UP, "Up");
|
|
|
|
set_kc(keycode_names, WXK_RIGHT, "Right");
|
|
|
|
set_kc(keycode_names, WXK_DOWN, "Down");
|
|
|
|
set_kc(keycode_names, WXK_PRINT, "Print");
|
|
|
|
set_kc(keycode_names, WXK_INSERT, "Insert");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD0, "KP_0");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD1, "KP_1");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD2, "KP_2");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD3, "KP_3");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD4, "KP_4");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD5, "KP_5");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD6, "KP_6");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD7, "KP_7");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD8, "KP_8");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD9, "KP_9");
|
|
|
|
set_kc(keycode_names, WXK_MULTIPLY, "Asterisk");
|
|
|
|
set_kc(keycode_names, WXK_ADD, "Plus");
|
|
|
|
set_kc(keycode_names, WXK_SUBTRACT, "Hyphen");
|
|
|
|
set_kc(keycode_names, WXK_DECIMAL, "Period");
|
|
|
|
set_kc(keycode_names, WXK_DIVIDE, "Slash");
|
|
|
|
set_kc(keycode_names, WXK_F1, "F1");
|
|
|
|
set_kc(keycode_names, WXK_F2, "F2");
|
|
|
|
set_kc(keycode_names, WXK_F3, "F3");
|
|
|
|
set_kc(keycode_names, WXK_F4, "F4");
|
|
|
|
set_kc(keycode_names, WXK_F5, "F5");
|
|
|
|
set_kc(keycode_names, WXK_F6, "F6");
|
|
|
|
set_kc(keycode_names, WXK_F7, "F7");
|
|
|
|
set_kc(keycode_names, WXK_F8, "F8");
|
|
|
|
set_kc(keycode_names, WXK_F9, "F9");
|
|
|
|
set_kc(keycode_names, WXK_F10, "F10");
|
|
|
|
set_kc(keycode_names, WXK_F11, "F11");
|
|
|
|
set_kc(keycode_names, WXK_F12, "F12");
|
|
|
|
set_kc(keycode_names, WXK_F13, "F13");
|
|
|
|
set_kc(keycode_names, WXK_F14, "F14");
|
|
|
|
set_kc(keycode_names, WXK_F15, "F15");
|
|
|
|
set_kc(keycode_names, WXK_F16, "F16");
|
|
|
|
set_kc(keycode_names, WXK_F17, "F17");
|
|
|
|
set_kc(keycode_names, WXK_F18, "F18");
|
|
|
|
set_kc(keycode_names, WXK_F19, "F19");
|
|
|
|
set_kc(keycode_names, WXK_F20, "F20");
|
|
|
|
set_kc(keycode_names, WXK_F21, "F21");
|
|
|
|
set_kc(keycode_names, WXK_F22, "F22");
|
|
|
|
set_kc(keycode_names, WXK_F23, "F23");
|
|
|
|
set_kc(keycode_names, WXK_F24, "F24");
|
|
|
|
set_kc(keycode_names, WXK_NUMLOCK, "Num_Lock");
|
|
|
|
set_kc(keycode_names, WXK_SCROLL, "Scroll_Lock");
|
|
|
|
set_kc(keycode_names, WXK_PAGEUP, "PageUp");
|
|
|
|
set_kc(keycode_names, WXK_PAGEDOWN, "PageDown");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_SPACE, "KP_Space");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_TAB, "KP_Tab");
|
2011-07-26 21:53:08 +02:00
|
|
|
set_kc(keycode_names, WXK_NUMPAD_ENTER, "KP_Enter");
|
2011-01-16 08:17:53 +01:00
|
|
|
set_kc(keycode_names, WXK_NUMPAD_F1, "KP_F1");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_F2, "KP_F2");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_F3, "KP_F3");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_F4, "KP_F4");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_HOME, "KP_Home");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_LEFT, "KP_Left");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_UP, "KP_Up");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_RIGHT, "KP_Right");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_DOWN, "KP_Down");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_PAGEUP, "KP_PageUp");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_PAGEDOWN, "KP_PageDown");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_END, "KP_End");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_BEGIN, "KP_Begin");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_INSERT, "KP_insert");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_DELETE, "KP_Delete");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_EQUAL, "KP_Equal");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_MULTIPLY, "KP_Multiply");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_ADD, "KP_Add");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_SUBTRACT, "KP_Subtract");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_DECIMAL, "KP_Decimal");
|
|
|
|
set_kc(keycode_names, WXK_NUMPAD_DIVIDE, "KP_Divide");
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
}
|
|
|
|
|
2011-07-30 01:16:55 +02:00
|
|
|
} // namespace hotkey
|