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.
|
|
|
|
|
|
|
|
#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"
|
2014-01-04 01:56:18 +01:00
|
|
|
#include "compat.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>
|
2013-11-16 18:21:38 +01:00
|
|
|
#include <boost/range/iterator_range.hpp>
|
2014-01-10 02:16:17 +01:00
|
|
|
#include <wx/intl.h>
|
|
|
|
#include <wx/msgdlg.h>
|
2013-06-09 03:35:08 +02:00
|
|
|
|
2012-01-14 02:40:32 +01:00
|
|
|
namespace {
|
2014-07-05 05:16:24 +02:00
|
|
|
const char *added_hotkeys_7035[][3] = {
|
|
|
|
{"audio/play/line", "Audio", "R"},
|
|
|
|
{nullptr}
|
2012-10-05 01:56:02 +02:00
|
|
|
};
|
|
|
|
|
2014-07-05 05:16:24 +02:00
|
|
|
const char *added_hotkeys_7070[][3] = {
|
|
|
|
{"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"},
|
|
|
|
{nullptr}
|
2012-10-09 18:41:55 +02:00
|
|
|
};
|
|
|
|
|
2014-07-05 05:16:24 +02:00
|
|
|
const char *added_hotkeys_shift_back[][3] = {
|
|
|
|
{"edit/line/duplicate/shift_back", "Default", "Ctrl-Shift-D"},
|
|
|
|
{nullptr}
|
2013-06-09 03:49:32 +02:00
|
|
|
};
|
2012-01-14 02:40:32 +01:00
|
|
|
|
2014-07-05 05:16:24 +02:00
|
|
|
void migrate_hotkeys(const char *added[][3]) {
|
|
|
|
auto hk_map = hotkey::inst->GetHotkeyMap();
|
|
|
|
bool changed = false;
|
2012-01-14 02:40:32 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; added[i] && added[i][0]; ++i) {
|
2014-07-05 05:16:24 +02:00
|
|
|
agi::hotkey::Combo combo(added[i][1], added[i][0], added[i][2]);
|
2013-06-09 03:41:55 +02:00
|
|
|
|
|
|
|
if (hotkey::inst->HasHotkey(combo.Context(), combo.Str()))
|
|
|
|
continue;
|
|
|
|
|
2014-07-05 05:16:24 +02:00
|
|
|
hk_map.insert(make_pair(std::string(added[i][0]), std::move(combo)));
|
|
|
|
changed = true;
|
2012-01-14 02:40:32 +01:00
|
|
|
}
|
|
|
|
|
2014-07-05 05:16:24 +02:00
|
|
|
if (changed)
|
|
|
|
hotkey::inst->SetHotkeyMap(std::move(hk_map));
|
2012-01-14 02:40:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
agi::hotkey::Hotkey *inst = nullptr;
|
2011-10-28 22:40:43 +02:00
|
|
|
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)) {
|
2013-06-09 03:49:32 +02:00
|
|
|
migrate_hotkeys(added_hotkeys_7035);
|
2013-06-09 03:35:08 +02:00
|
|
|
migrations.emplace_back("7035");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boost::find(migrations, "7070") == end(migrations)) {
|
2013-06-09 03:49:32 +02:00
|
|
|
migrate_hotkeys(added_hotkeys_7070);
|
2013-06-09 03:35:08 +02:00
|
|
|
migrations.emplace_back("7070");
|
|
|
|
}
|
|
|
|
|
2013-06-09 03:49:32 +02:00
|
|
|
if (boost::find(migrations, "edit/line/duplicate/shift_back") == end(migrations)) {
|
|
|
|
migrate_hotkeys(added_hotkeys_shift_back);
|
|
|
|
migrations.emplace_back("edit/line/duplicate/shift_back");
|
|
|
|
}
|
|
|
|
|
2013-11-16 18:21:38 +01:00
|
|
|
if (boost::find(migrations, "duplicate -> split") == end(migrations)) {
|
|
|
|
auto hk_map = hotkey::inst->GetHotkeyMap();
|
|
|
|
for (auto const& hotkey : boost::make_iterator_range(hk_map.equal_range("edit/line/duplicate/shift"))) {
|
2014-07-05 05:16:24 +02:00
|
|
|
auto combo = agi::hotkey::Combo(hotkey.second.Context(), "edit/line/split/before", hotkey.second.Str());
|
2014-05-25 16:41:21 +02:00
|
|
|
hk_map.insert({combo.CmdName(), combo});
|
2013-11-16 18:21:38 +01:00
|
|
|
}
|
|
|
|
for (auto const& hotkey : boost::make_iterator_range(hk_map.equal_range("edit/line/duplicate/shift_back"))) {
|
2014-07-05 05:16:24 +02:00
|
|
|
auto combo = agi::hotkey::Combo(hotkey.second.Context(), "edit/line/split/after", hotkey.second.Str());
|
2014-05-25 16:41:21 +02:00
|
|
|
hk_map.insert({combo.CmdName(), combo});
|
2013-11-16 18:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hk_map.erase("edit/line/duplicate/shift");
|
|
|
|
hk_map.erase("edit/line/duplicate/shift_back");
|
|
|
|
|
2014-07-05 05:16:24 +02:00
|
|
|
hotkey::inst->SetHotkeyMap(std::move(hk_map));
|
2013-11-16 18:21:38 +01:00
|
|
|
migrations.emplace_back("duplicate -> split");
|
|
|
|
}
|
|
|
|
|
2014-03-31 18:24:56 +02:00
|
|
|
OPT_SET("App/Hotkey Migrations")->SetListString(std::move(migrations));
|
2011-10-28 22:40:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
delete inst;
|
|
|
|
}
|
|
|
|
|
2014-07-05 05:16:24 +02:00
|
|
|
static const char *keycode_name(int code) {
|
|
|
|
switch (code) {
|
|
|
|
case WXK_BACK: return "Backspace";
|
|
|
|
case WXK_TAB: return "Tab";
|
|
|
|
case WXK_RETURN: return "Enter";
|
|
|
|
case WXK_ESCAPE: return "Escape";
|
|
|
|
case WXK_SPACE: return "Space";
|
|
|
|
case WXK_DELETE: return "Delete";
|
|
|
|
case WXK_SHIFT: return "Shift";
|
|
|
|
case WXK_ALT: return "Alt";
|
|
|
|
case WXK_CONTROL: return "Control";
|
|
|
|
case WXK_PAUSE: return "Pause";
|
|
|
|
case WXK_END: return "End";
|
|
|
|
case WXK_HOME: return "Home";
|
|
|
|
case WXK_LEFT: return "Left";
|
|
|
|
case WXK_UP: return "Up";
|
|
|
|
case WXK_RIGHT: return "Right";
|
|
|
|
case WXK_DOWN: return "Down";
|
|
|
|
case WXK_PRINT: return "Print";
|
|
|
|
case WXK_INSERT: return "Insert";
|
|
|
|
case WXK_NUMPAD0: return "KP_0";
|
|
|
|
case WXK_NUMPAD1: return "KP_1";
|
|
|
|
case WXK_NUMPAD2: return "KP_2";
|
|
|
|
case WXK_NUMPAD3: return "KP_3";
|
|
|
|
case WXK_NUMPAD4: return "KP_4";
|
|
|
|
case WXK_NUMPAD5: return "KP_5";
|
|
|
|
case WXK_NUMPAD6: return "KP_6";
|
|
|
|
case WXK_NUMPAD7: return "KP_7";
|
|
|
|
case WXK_NUMPAD8: return "KP_8";
|
|
|
|
case WXK_NUMPAD9: return "KP_9";
|
|
|
|
case WXK_MULTIPLY: return "Asterisk";
|
|
|
|
case WXK_ADD: return "Plus";
|
|
|
|
case WXK_SUBTRACT: return "Hyphen";
|
|
|
|
case WXK_DECIMAL: return "Period";
|
|
|
|
case WXK_DIVIDE: return "Slash";
|
|
|
|
case WXK_F1: return "F1";
|
|
|
|
case WXK_F2: return "F2";
|
|
|
|
case WXK_F3: return "F3";
|
|
|
|
case WXK_F4: return "F4";
|
|
|
|
case WXK_F5: return "F5";
|
|
|
|
case WXK_F6: return "F6";
|
|
|
|
case WXK_F7: return "F7";
|
|
|
|
case WXK_F8: return "F8";
|
|
|
|
case WXK_F9: return "F9";
|
|
|
|
case WXK_F10: return "F10";
|
|
|
|
case WXK_F11: return "F11";
|
|
|
|
case WXK_F12: return "F12";
|
|
|
|
case WXK_F13: return "F13";
|
|
|
|
case WXK_F14: return "F14";
|
|
|
|
case WXK_F15: return "F15";
|
|
|
|
case WXK_F16: return "F16";
|
|
|
|
case WXK_F17: return "F17";
|
|
|
|
case WXK_F18: return "F18";
|
|
|
|
case WXK_F19: return "F19";
|
|
|
|
case WXK_F20: return "F20";
|
|
|
|
case WXK_F21: return "F21";
|
|
|
|
case WXK_F22: return "F22";
|
|
|
|
case WXK_F23: return "F23";
|
|
|
|
case WXK_F24: return "F24";
|
|
|
|
case WXK_NUMLOCK: return "Num_Lock";
|
|
|
|
case WXK_SCROLL: return "Scroll_Lock";
|
|
|
|
case WXK_PAGEUP: return "PageUp";
|
|
|
|
case WXK_PAGEDOWN: return "PageDown";
|
|
|
|
case WXK_NUMPAD_SPACE: return "KP_Space";
|
|
|
|
case WXK_NUMPAD_TAB: return "KP_Tab";
|
|
|
|
case WXK_NUMPAD_ENTER: return "KP_Enter";
|
|
|
|
case WXK_NUMPAD_F1: return "KP_F1";
|
|
|
|
case WXK_NUMPAD_F2: return "KP_F2";
|
|
|
|
case WXK_NUMPAD_F3: return "KP_F3";
|
|
|
|
case WXK_NUMPAD_F4: return "KP_F4";
|
|
|
|
case WXK_NUMPAD_HOME: return "KP_Home";
|
|
|
|
case WXK_NUMPAD_LEFT: return "KP_Left";
|
|
|
|
case WXK_NUMPAD_UP: return "KP_Up";
|
|
|
|
case WXK_NUMPAD_RIGHT: return "KP_Right";
|
|
|
|
case WXK_NUMPAD_DOWN: return "KP_Down";
|
|
|
|
case WXK_NUMPAD_PAGEUP: return "KP_PageUp";
|
|
|
|
case WXK_NUMPAD_PAGEDOWN: return "KP_PageDown";
|
|
|
|
case WXK_NUMPAD_END: return "KP_End";
|
|
|
|
case WXK_NUMPAD_BEGIN: return "KP_Begin";
|
|
|
|
case WXK_NUMPAD_INSERT: return "KP_insert";
|
|
|
|
case WXK_NUMPAD_DELETE: return "KP_Delete";
|
|
|
|
case WXK_NUMPAD_EQUAL: return "KP_Equal";
|
|
|
|
case WXK_NUMPAD_MULTIPLY: return "KP_Multiply";
|
|
|
|
case WXK_NUMPAD_ADD: return "KP_Add";
|
|
|
|
case WXK_NUMPAD_SUBTRACT: return "KP_Subtract";
|
|
|
|
case WXK_NUMPAD_DECIMAL: return "KP_Decimal";
|
|
|
|
case WXK_NUMPAD_DIVIDE: return "KP_Divide";
|
|
|
|
default: return "";
|
2011-01-16 08:17:53 +01:00
|
|
|
}
|
|
|
|
}
|
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-");
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:20:30 +02:00
|
|
|
if (key_code > 32 && key_code < 127)
|
2014-07-05 05:16:24 +02:00
|
|
|
combo += (char)key_code;
|
|
|
|
else
|
|
|
|
combo += keycode_name(key_code);
|
2011-10-28 22:40:43 +02:00
|
|
|
|
|
|
|
return combo;
|
|
|
|
}
|
|
|
|
|
2014-07-09 00:16:49 +02:00
|
|
|
static bool check(std::string const& context, agi::Context *c, int key_code, int modifier) {
|
2013-06-09 03:24:50 +02:00
|
|
|
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) {
|
2014-01-04 01:56:18 +01:00
|
|
|
try {
|
2014-07-09 00:16:49 +02:00
|
|
|
if (!check(context, c, evt.GetKeyCode(), evt.GetModifiers())) {
|
2014-01-04 01:56:18 +01:00
|
|
|
evt.Skip();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (cmd::CommandNotFound const& e) {
|
2014-05-29 14:57:27 +02:00
|
|
|
wxMessageBox(to_wx(e.GetMessage()), _("Invalid command name for hotkey"),
|
2014-01-04 01:56:18 +01:00
|
|
|
wxOK | wxICON_ERROR | wxCENTER | wxSTAY_ON_TOP);
|
|
|
|
return true;
|
2012-03-13 00:34:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-07-30 01:16:55 +02:00
|
|
|
} // namespace hotkey
|