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.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file hotkey.h
|
|
|
|
/// @brief Hotkey handler
|
|
|
|
/// @ingroup hotkey menu event window
|
|
|
|
|
|
|
|
#ifndef LAGI_PRE
|
2011-07-16 05:36:42 +02:00
|
|
|
#include <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
|
|
|
#include <memory>
|
2011-01-18 00:53:46 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
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
|
|
|
#endif
|
|
|
|
|
2011-10-28 22:40:32 +02:00
|
|
|
#include <libaegisub/signal.h>
|
|
|
|
|
2011-10-18 00:00:38 +02:00
|
|
|
namespace json {
|
|
|
|
class UnknownElement;
|
|
|
|
typedef std::map<std::string, UnknownElement> Object;
|
|
|
|
}
|
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 agi {
|
|
|
|
namespace hotkey {
|
|
|
|
|
|
|
|
/// @class Combo
|
|
|
|
/// A Combo represents a linear sequence of characters set in an std::vector. This makes up
|
|
|
|
/// a single combination, or "Hotkey".
|
|
|
|
class Combo {
|
2011-10-28 22:40:32 +02:00
|
|
|
std::vector<std::string> key_map;
|
|
|
|
std::string cmd_name;
|
|
|
|
std::string context;
|
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
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
/// @param ctx Context
|
|
|
|
/// @param cmd Command name
|
2011-10-28 22:40:32 +02:00
|
|
|
Combo(std::string const& ctx, std::string const& cmd, std::vector<std::string> const& keys)
|
|
|
|
: key_map(keys)
|
|
|
|
, cmd_name(cmd)
|
|
|
|
, context(ctx)
|
|
|
|
{
|
|
|
|
}
|
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
|
|
|
|
|
|
|
/// String representation of the Combo
|
2011-07-15 19:36:06 +02:00
|
|
|
std::string Str() const;
|
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
|
|
|
|
|
|
|
/// String suitable for usage in a menu.
|
2011-07-15 19:36:06 +02:00
|
|
|
std::string StrMenu() const;
|
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
|
|
|
|
|
|
|
/// Get the literal combo map.
|
|
|
|
/// @return ComboMap (std::vector) of linear key sequence.
|
2011-10-28 22:40:32 +02:00
|
|
|
const std::vector<std::string>& Get() const { return key_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
|
|
|
|
|
|
|
/// Command name triggered by the combination.
|
|
|
|
/// @return Command name
|
2011-07-15 19:36:06 +02:00
|
|
|
const std::string& CmdName() const { return cmd_name; }
|
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
|
|
|
|
|
|
|
/// Context this Combo is triggered in.
|
2011-07-15 19:36:06 +02:00
|
|
|
const std::string& Context() const { return context; }
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// @class Hotkey
|
|
|
|
/// Holds the map of Combo instances and handles searching for matching key sequences.
|
|
|
|
class Hotkey {
|
2011-10-28 22:40:32 +02:00
|
|
|
public:
|
|
|
|
/// Map to hold Combo instances
|
|
|
|
typedef std::multimap<std::string, Combo> HotkeyMap;
|
|
|
|
private:
|
|
|
|
HotkeyMap str_map; ///< String representation -> Combo
|
|
|
|
HotkeyMap cmd_map; ///< Command name -> Combo
|
|
|
|
const std::string config_file; ///< Default user config location.
|
|
|
|
|
|
|
|
/// Build hotkey map.
|
|
|
|
/// @param context Context being parsed.
|
|
|
|
/// @param object json::Object holding items for context being parsed.
|
|
|
|
void BuildHotkey(std::string const& context, const json::Object& object);
|
|
|
|
|
|
|
|
/// Insert Combo into HotkeyMap instance.
|
|
|
|
/// @param combo Combo to insert.
|
|
|
|
void ComboInsert(Combo const& combo);
|
|
|
|
|
|
|
|
/// Write active Hotkey configuration to disk.
|
|
|
|
void Flush();
|
|
|
|
|
|
|
|
/// Announce that the loaded hotkeys have been changed
|
|
|
|
agi::signal::Signal<> HotkeysChanged;
|
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
|
|
|
public:
|
|
|
|
/// Constructor
|
|
|
|
/// @param file Location of user config file.
|
|
|
|
/// @param default_config Default config.
|
|
|
|
Hotkey(const std::string &file, const std::string &default_config);
|
|
|
|
|
|
|
|
/// Scan for a matching key.
|
|
|
|
/// @param context Context requested.
|
2011-01-16 08:17:53 +01:00
|
|
|
/// @param str Hyphen separated key sequence.
|
2011-07-26 21:52:25 +02:00
|
|
|
/// @param always Enable the "Always" override context
|
2011-12-22 22:27:06 +01:00
|
|
|
/// @return Name of command or "" if none match
|
|
|
|
std::string Scan(const std::string &context, const std::string &str, bool always) const;
|
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-18 00:53:46 +01:00
|
|
|
/// Get the string representation of the hotkeys for the given command
|
|
|
|
/// @param context Context requested
|
|
|
|
/// @param command Command name
|
|
|
|
/// @return A vector of all hotkeys for that command in the context
|
|
|
|
std::vector<std::string> GetHotkeys(const std::string &context, const std::string &command) const;
|
|
|
|
|
2011-07-26 21:52:57 +02:00
|
|
|
/// Get a string representation of a hotkeys for the given command
|
|
|
|
/// @param context Context requested
|
|
|
|
/// @param command Command name
|
|
|
|
/// @return A hotkey for the given command or "" if there are none
|
|
|
|
std::string GetHotkey(const std::string &context, const std::string &command) const;
|
|
|
|
|
2011-10-28 22:40:32 +02:00
|
|
|
/// Get the raw command name -> combo map for all registered hotkeys
|
|
|
|
HotkeyMap const& GetHotkeyMap() const { return cmd_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
|
|
|
|
2011-10-28 22:40:32 +02:00
|
|
|
/// Replace the loaded hotkeys with a new set
|
|
|
|
void SetHotkeyMap(HotkeyMap const& new_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
|
|
|
|
2011-10-28 22:40:32 +02:00
|
|
|
DEFINE_SIGNAL_ADDERS(HotkeysChanged, AddHotkeyChangeListener)
|
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
|
|
|
|
} // namespace agi
|