2013-01-16 13:27:41 -05:00
|
|
|
/*
|
2016-03-08 08:36:05 -05:00
|
|
|
Copyright (C) 2012 Paul Davis
|
2013-01-16 13:27:41 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2013-01-16 13:27:41 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2013-01-16 13:27:41 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2013-01-16 13:27:41 -05:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-08-06 14:44:55 -04:00
|
|
|
#include <iostream>
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2015-10-05 16:10:58 -04:00
|
|
|
#include "pbd/gstdio_compat.h"
|
2015-08-01 22:38:46 -04:00
|
|
|
#include <gtkmm/accelmap.h>
|
|
|
|
#include <gtkmm/uimanager.h>
|
2013-07-15 14:29:00 -04:00
|
|
|
|
2011-03-03 22:10:17 -05:00
|
|
|
#include "pbd/convert.h"
|
2015-08-01 22:38:46 -04:00
|
|
|
#include "pbd/debug.h"
|
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/xml++.h"
|
2011-03-03 22:10:17 -05:00
|
|
|
|
|
|
|
#include "gtkmm2ext/actions.h"
|
2010-08-06 14:44:55 -04:00
|
|
|
#include "gtkmm2ext/bindings.h"
|
2015-08-01 22:38:46 -04:00
|
|
|
#include "gtkmm2ext/debug.h"
|
2010-08-06 14:44:55 -04:00
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2015-08-01 22:38:46 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2010-08-06 14:44:55 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Glib;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gtkmm2ext;
|
2015-08-01 22:38:46 -04:00
|
|
|
using namespace PBD;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
list<Bindings*> Bindings::bindings; /* global. Gulp */
|
2015-08-10 14:31:59 -04:00
|
|
|
list<ActionMap*> ActionMap::action_maps; /* global. Gulp */
|
|
|
|
PBD::Signal1<void,Bindings*> Bindings::BindingsChanged;
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
template <typename IteratorValueType>
|
|
|
|
struct ActionNameRegistered
|
|
|
|
{
|
|
|
|
ActionNameRegistered(std::string const& name)
|
2016-03-08 08:36:05 -05:00
|
|
|
: action_name(name)
|
2016-02-28 15:54:08 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool operator()(IteratorValueType elem) const {
|
|
|
|
return elem.second.action_name == action_name;
|
|
|
|
}
|
|
|
|
std::string const& action_name;
|
|
|
|
};
|
|
|
|
|
2011-03-03 22:10:17 -05:00
|
|
|
MouseButton::MouseButton (uint32_t state, uint32_t keycode)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
uint32_t ignore = ~Keyboard::RelevantModifierKeyMask;
|
|
|
|
|
|
|
|
/* this is a slightly wierd test that relies on
|
|
|
|
* gdk_keyval_is_{upper,lower}() returning true for keys that have no
|
|
|
|
* case-sensitivity. This covers mostly non-alphanumeric keys.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (gdk_keyval_is_upper (keycode) && gdk_keyval_is_lower (keycode)) {
|
|
|
|
/* key is not subject to case, so ignore SHIFT
|
|
|
|
*/
|
|
|
|
ignore |= GDK_SHIFT_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
_val = (state & ~ignore);
|
|
|
|
_val <<= 32;
|
|
|
|
_val |= keycode;
|
2011-03-03 22:10:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
MouseButton::make_button (const string& str, MouseButton& b)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
int s = 0;
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Primary") != string::npos) {
|
|
|
|
s |= Keyboard::PrimaryModifier;
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Secondary") != string::npos) {
|
|
|
|
s |= Keyboard::SecondaryModifier;
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Tertiary") != string::npos) {
|
|
|
|
s |= Keyboard::TertiaryModifier;
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Level4") != string::npos) {
|
|
|
|
s |= Keyboard::Level4Modifier;
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
string::size_type lastmod = str.find_last_of ('-');
|
|
|
|
uint32_t button_number;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (lastmod == string::npos) {
|
|
|
|
button_number = PBD::atoi (str);
|
|
|
|
} else {
|
|
|
|
button_number = PBD::atoi (str.substr (lastmod+1));
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
b = MouseButton (s, button_number);
|
|
|
|
return true;
|
2011-03-03 22:10:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
MouseButton::name () const
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
int s = state();
|
|
|
|
|
|
|
|
string str;
|
|
|
|
|
|
|
|
if (s & Keyboard::PrimaryModifier) {
|
|
|
|
str += "Primary";
|
|
|
|
}
|
|
|
|
if (s & Keyboard::SecondaryModifier) {
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
str += "Secondary";
|
|
|
|
}
|
|
|
|
if (s & Keyboard::TertiaryModifier) {
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
str += "Tertiary";
|
|
|
|
}
|
|
|
|
if (s & Keyboard::Level4Modifier) {
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
str += "Level4";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf[16];
|
|
|
|
snprintf (buf, sizeof (buf), "%u", button());
|
|
|
|
str += buf;
|
|
|
|
|
|
|
|
return str;
|
2011-03-03 22:10:17 -05:00
|
|
|
}
|
2010-08-12 17:02:01 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
/*================================ KeyboardKey ================================*/
|
2010-08-12 17:02:01 -04:00
|
|
|
KeyboardKey::KeyboardKey (uint32_t state, uint32_t keycode)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
uint32_t ignore = ~Keyboard::RelevantModifierKeyMask;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
_val = (state & ~ignore);
|
|
|
|
_val <<= 32;
|
|
|
|
_val |= keycode;
|
2015-08-10 14:31:59 -04:00
|
|
|
}
|
2010-08-12 17:02:01 -04:00
|
|
|
|
2015-08-10 14:31:59 -04:00
|
|
|
string
|
|
|
|
KeyboardKey::display_label () const
|
|
|
|
{
|
|
|
|
if (key() == 0) {
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This magically returns a string that will display the right thing
|
|
|
|
* on all platforms, notably the command key on OS X.
|
|
|
|
*/
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
uint32_t mod = state();
|
2015-10-27 14:42:31 -04:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2016-03-08 08:36:05 -05:00
|
|
|
/* We use both bits (MOD2|META) for Primary on OS X,
|
|
|
|
* but we don't want MOD2 showing up in listings.
|
|
|
|
*/
|
2015-10-27 14:42:31 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (mod & GDK_MOD2_MASK) {
|
|
|
|
mod &= ~GDK_MOD2_MASK;
|
|
|
|
}
|
2015-10-27 14:42:31 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return gtk_accelerator_get_label (key(), (GdkModifierType) mod);
|
2015-08-10 14:31:59 -04:00
|
|
|
}
|
2010-08-12 17:02:01 -04:00
|
|
|
|
2010-08-06 14:44:55 -04:00
|
|
|
string
|
|
|
|
KeyboardKey::name () const
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
int s = state();
|
|
|
|
|
|
|
|
string str;
|
|
|
|
|
|
|
|
if (s & Keyboard::PrimaryModifier) {
|
|
|
|
str += "Primary";
|
|
|
|
}
|
|
|
|
if (s & Keyboard::SecondaryModifier) {
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
str += "Secondary";
|
|
|
|
}
|
|
|
|
if (s & Keyboard::TertiaryModifier) {
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
str += "Tertiary";
|
|
|
|
}
|
|
|
|
if (s & Keyboard::Level4Modifier) {
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
str += "Level4";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!str.empty()) {
|
|
|
|
str += '-';
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *gdk_name = gdk_keyval_name (key());
|
|
|
|
|
|
|
|
if (gdk_name) {
|
|
|
|
str += gdk_name;
|
|
|
|
} else {
|
|
|
|
/* fail! */
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
KeyboardKey::make_key (const string& str, KeyboardKey& k)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
int s = 0;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Primary") != string::npos) {
|
|
|
|
s |= Keyboard::PrimaryModifier;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Secondary") != string::npos) {
|
|
|
|
s |= Keyboard::SecondaryModifier;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Tertiary") != string::npos) {
|
|
|
|
s |= Keyboard::TertiaryModifier;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (str.find ("Level4") != string::npos) {
|
|
|
|
s |= Keyboard::Level4Modifier;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* since all SINGLE key events keycodes are changed to lower case
|
|
|
|
* before looking them up, make sure we only store lower case here. The
|
|
|
|
* Shift part will be stored in the modifier part of the KeyboardKey.
|
|
|
|
*
|
|
|
|
* And yes Mildred, this doesn't cover CapsLock cases. Oh well.
|
|
|
|
*/
|
2016-03-02 16:17:54 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
string actual;
|
2016-03-02 16:17:54 -05:00
|
|
|
|
2016-03-24 07:10:54 -04:00
|
|
|
string::size_type lastmod = str.find_last_of ('-');
|
|
|
|
|
|
|
|
if (lastmod != string::npos) {
|
|
|
|
actual = str.substr (lastmod+1);
|
|
|
|
}
|
|
|
|
else {
|
2016-03-08 08:36:05 -05:00
|
|
|
actual = str;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-24 07:10:54 -04:00
|
|
|
if (actual.size() == 1) {
|
|
|
|
actual = PBD::downcase (actual);
|
2016-03-08 08:36:05 -05:00
|
|
|
}
|
2016-03-05 11:54:02 -05:00
|
|
|
|
2016-03-24 07:10:54 -04:00
|
|
|
guint keyval;
|
2016-03-08 08:36:05 -05:00
|
|
|
keyval = gdk_keyval_from_name (actual.c_str());
|
2016-03-02 16:17:54 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (keyval == GDK_VoidSymbol || keyval == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
k = KeyboardKey (s, keyval);
|
2015-08-01 22:38:46 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
return true;
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
/*================================= Bindings =================================*/
|
2015-08-08 08:36:29 -04:00
|
|
|
Bindings::Bindings (std::string const& name)
|
|
|
|
: _name (name)
|
2015-08-10 14:31:59 -04:00
|
|
|
, _action_map (0)
|
2010-08-06 14:44:55 -04:00
|
|
|
{
|
2015-08-08 08:36:29 -04:00
|
|
|
bindings.push_back (this);
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Bindings::~Bindings()
|
|
|
|
{
|
2015-08-08 08:36:29 -04:00
|
|
|
bindings.remove (this);
|
|
|
|
}
|
|
|
|
|
2015-08-10 14:31:59 -04:00
|
|
|
string
|
|
|
|
Bindings::ardour_action_name (RefPtr<Action> action)
|
|
|
|
{
|
|
|
|
/* Skip "<Actions>/" */
|
|
|
|
return action->get_accel_path ().substr (10);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardKey
|
|
|
|
Bindings::get_binding_for_action (RefPtr<Action> action, Operation& op)
|
|
|
|
{
|
|
|
|
const string action_name = ardour_action_name (action);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
for (KeybindingMap::iterator k = press_bindings.begin(); k != press_bindings.end(); ++k) {
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* option one: action has already been associated with the
|
|
|
|
* binding
|
|
|
|
*/
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (k->second.action == action) {
|
|
|
|
return k->first;
|
|
|
|
}
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* option two: action name matches, so lookup the action,
|
|
|
|
* setup the association while we're here, and return the binding.
|
|
|
|
*/
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (_action_map && k->second.action_name == action_name) {
|
|
|
|
k->second.action = _action_map->find_action (action_name);
|
|
|
|
return k->first;
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
}
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
for (KeybindingMap::iterator k = release_bindings.begin(); k != release_bindings.end(); ++k) {
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* option one: action has already been associated with the
|
|
|
|
* binding
|
|
|
|
*/
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (k->second.action == action) {
|
|
|
|
return k->first;
|
|
|
|
}
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* option two: action name matches, so lookup the action,
|
|
|
|
* setup the association while we're here, and return the binding.
|
|
|
|
*/
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (_action_map && k->second.action_name == action_name) {
|
|
|
|
k->second.action = _action_map->find_action (action_name);
|
|
|
|
return k->first;
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
return KeyboardKey::null_key();
|
2015-08-10 14:31:59 -04:00
|
|
|
}
|
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
void
|
|
|
|
Bindings::set_action_map (ActionMap& actions)
|
|
|
|
{
|
2015-09-01 13:53:19 -04:00
|
|
|
if (_action_map) {
|
|
|
|
_action_map->set_bindings (0);
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-10 14:31:59 -04:00
|
|
|
_action_map = &actions;
|
2015-09-01 13:53:19 -04:00
|
|
|
_action_map->set_bindings (this);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
dissociate ();
|
|
|
|
associate ();
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
2015-07-09 18:10:19 -04:00
|
|
|
bool
|
|
|
|
Bindings::empty_keys() const
|
|
|
|
{
|
|
|
|
return press_bindings.empty() && release_bindings.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Bindings::empty_mouse () const
|
|
|
|
{
|
|
|
|
return button_press_bindings.empty() && button_release_bindings.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Bindings::empty() const
|
|
|
|
{
|
|
|
|
return empty_keys() && empty_mouse ();
|
|
|
|
}
|
|
|
|
|
2010-08-06 14:44:55 -04:00
|
|
|
bool
|
2011-03-03 22:10:17 -05:00
|
|
|
Bindings::activate (KeyboardKey kb, Operation op)
|
2010-08-06 14:44:55 -04:00
|
|
|
{
|
2016-02-28 15:54:08 -05:00
|
|
|
KeybindingMap& kbm = get_keymap (op);
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* if shift was pressed, GDK will send us (e.g) 'E' rather than 'e'.
|
|
|
|
Our bindings all use the lower case character/keyname, so switch
|
|
|
|
to the lower case before doing the lookup.
|
|
|
|
*/
|
2016-02-26 15:47:50 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
KeyboardKey unshifted (kb.state(), gdk_keyval_to_lower (kb.key()));
|
2016-02-26 15:47:50 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
KeybindingMap::iterator k = kbm.find (unshifted);
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (k == kbm.end()) {
|
|
|
|
/* no entry for this key in the state map */
|
|
|
|
DEBUG_TRACE (DEBUG::Bindings, string_compose ("no binding for %1\n", unshifted));
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
RefPtr<Action> action;
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (k->second.action) {
|
|
|
|
action = k->second.action;
|
|
|
|
} else {
|
|
|
|
if (_action_map) {
|
|
|
|
action = _action_map->find_action (k->second.action_name);
|
|
|
|
}
|
|
|
|
}
|
2015-08-08 08:36:29 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (action) {
|
|
|
|
/* lets do it ... */
|
|
|
|
DEBUG_TRACE (DEBUG::Bindings, string_compose ("binding for %1: %2\n", unshifted, k->second.action_name));
|
|
|
|
action->activate ();
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* return true even if the action could not be found */
|
2015-08-01 22:38:46 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
return true;
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
void
|
|
|
|
Bindings::associate ()
|
|
|
|
{
|
|
|
|
KeybindingMap::iterator k;
|
|
|
|
|
2015-08-10 14:31:59 -04:00
|
|
|
if (!_action_map) {
|
|
|
|
return;
|
|
|
|
}
|
2015-09-01 13:53:19 -04:00
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
for (k = press_bindings.begin(); k != press_bindings.end(); ++k) {
|
2015-08-10 14:31:59 -04:00
|
|
|
k->second.action = _action_map->find_action (k->second.action_name);
|
2015-08-08 08:36:29 -04:00
|
|
|
if (k->second.action) {
|
|
|
|
push_to_gtk (k->first, k->second.action);
|
2015-08-10 14:31:59 -04:00
|
|
|
} else {
|
2015-09-01 13:53:19 -04:00
|
|
|
cerr << _name << " didn't find " << k->second.action_name << " in " << _action_map->name() << endl;
|
2015-08-08 08:36:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (k = release_bindings.begin(); k != release_bindings.end(); ++k) {
|
2015-08-10 14:31:59 -04:00
|
|
|
k->second.action = _action_map->find_action (k->second.action_name);
|
2015-08-08 08:36:29 -04:00
|
|
|
/* no working support in GTK for release bindings */
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseButtonBindingMap::iterator b;
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
for (b = button_press_bindings.begin(); b != button_press_bindings.end(); ++b) {
|
2015-08-10 14:31:59 -04:00
|
|
|
b->second.action = _action_map->find_action (b->second.action_name);
|
2015-08-08 08:36:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (b = button_release_bindings.begin(); b != button_release_bindings.end(); ++b) {
|
2015-08-10 14:31:59 -04:00
|
|
|
b->second.action = _action_map->find_action (b->second.action_name);
|
2015-08-08 08:36:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Bindings::dissociate ()
|
2015-08-05 10:56:36 -04:00
|
|
|
{
|
2015-08-08 08:36:29 -04:00
|
|
|
KeybindingMap::iterator k;
|
|
|
|
|
|
|
|
for (k = press_bindings.begin(); k != press_bindings.end(); ++k) {
|
|
|
|
k->second.action.clear ();
|
|
|
|
}
|
|
|
|
for (k = release_bindings.begin(); k != release_bindings.end(); ++k) {
|
|
|
|
k->second.action.clear ();
|
2015-08-05 10:56:36 -04:00
|
|
|
}
|
2015-08-08 08:36:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Bindings::push_to_gtk (KeyboardKey kb, RefPtr<Action> what)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
/* GTK has the useful feature of showing key bindings for actions in
|
|
|
|
* menus. As of August 2015, we have no interest in trying to
|
|
|
|
* reimplement this functionality, so we will use it even though we no
|
|
|
|
* longer use GTK accelerators for handling key events. To do this, we
|
|
|
|
* need to make sure that there is a fully populated GTK AccelMap set
|
|
|
|
* up with all bindings/actions.
|
|
|
|
*/
|
2015-08-08 08:36:29 -04:00
|
|
|
|
2015-08-10 14:31:59 -04:00
|
|
|
Gtk::AccelKey gtk_key;
|
|
|
|
bool entry_exists = Gtk::AccelMap::lookup_entry (what->get_accel_path(), gtk_key);
|
2015-08-08 08:36:29 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (!entry_exists) {
|
|
|
|
|
|
|
|
/* there is a trick happening here. It turns out that
|
|
|
|
* gtk_accel_map_add_entry() performs no validation checks on
|
|
|
|
* the accelerator keyval. This means we can use it to define
|
|
|
|
* ANY accelerator, even if they violate GTK's rules
|
|
|
|
* (e.g. about not using navigation keys). This works ONLY when
|
|
|
|
* the entry in the GTK accelerator map has not already been
|
|
|
|
* added. The entries will be added by the GTK UIManager when
|
|
|
|
* building menus, so this code must be called before that
|
|
|
|
* happens.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Gtk::AccelMap::add_entry (what->get_accel_path(), kb.key(), (Gdk::ModifierType) kb.state());
|
|
|
|
}
|
2015-08-08 08:36:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Bindings::replace (KeyboardKey kb, Operation op, string const & action_name, bool can_save)
|
|
|
|
{
|
2015-08-10 14:31:59 -04:00
|
|
|
if (!_action_map) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
if (is_registered(op, action_name)) {
|
|
|
|
remove(op, action_name, can_save);
|
|
|
|
}
|
|
|
|
add (kb, op, action_name, can_save);
|
|
|
|
return true;
|
2015-08-05 10:56:36 -04:00
|
|
|
}
|
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
bool
|
2015-08-08 08:36:29 -04:00
|
|
|
Bindings::add (KeyboardKey kb, Operation op, string const& action_name, bool can_save)
|
2010-08-06 14:44:55 -04:00
|
|
|
{
|
2016-02-28 15:54:08 -05:00
|
|
|
if (is_registered(op, action_name)) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
KeybindingMap& kbm = get_keymap (op);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
KeybindingMap::value_type new_pair (kb, ActionInfo (action_name));
|
|
|
|
kbm.insert (new_pair).first;
|
2015-08-05 10:56:36 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
if (can_save) {
|
|
|
|
Keyboard::keybindings_changed ();
|
|
|
|
}
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
BindingsChanged (this); /* EMIT SIGNAL */
|
|
|
|
return true;
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
bool
|
|
|
|
Bindings::remove (Operation op, std::string const& action_name, bool can_save)
|
|
|
|
{
|
|
|
|
bool erased_action = false;
|
|
|
|
KeybindingMap& kbm = get_keymap (op);
|
|
|
|
for (KeybindingMap::iterator k = kbm.begin(); k != kbm.end(); ++k) {
|
|
|
|
if (k->second.action_name == action_name) {
|
|
|
|
kbm.erase (k);
|
|
|
|
erased_action = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
if (!erased_action) {
|
|
|
|
return erased_action;
|
|
|
|
}
|
2015-08-05 10:56:36 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
if (can_save) {
|
|
|
|
Keyboard::keybindings_changed ();
|
|
|
|
}
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
BindingsChanged (this); /* EMIT SIGNAL */
|
|
|
|
return erased_action;
|
2015-08-05 10:56:36 -04:00
|
|
|
}
|
|
|
|
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2011-03-03 22:10:17 -05:00
|
|
|
bool
|
|
|
|
Bindings::activate (MouseButton bb, Operation op)
|
|
|
|
{
|
2016-02-28 15:54:08 -05:00
|
|
|
MouseButtonBindingMap& bbm = get_mousemap(op);
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
MouseButtonBindingMap::iterator b = bbm.find (bb);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (b == bbm.end()) {
|
|
|
|
/* no entry for this key in the state map */
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
RefPtr<Action> action;
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (b->second.action) {
|
|
|
|
action = b->second.action;
|
|
|
|
} else {
|
|
|
|
if (_action_map) {
|
|
|
|
action = _action_map->find_action (b->second.action_name);
|
|
|
|
}
|
|
|
|
}
|
2015-08-08 08:36:29 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (action) {
|
|
|
|
/* lets do it ... */
|
|
|
|
DEBUG_TRACE (DEBUG::Bindings, string_compose ("activating action %1\n", ardour_action_name (action)));
|
|
|
|
action->activate ();
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* return true even if the action could not be found */
|
2015-08-10 14:31:59 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
return true;
|
2011-03-03 22:10:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-08 08:36:29 -04:00
|
|
|
Bindings::add (MouseButton bb, Operation op, string const& action_name)
|
2011-03-03 22:10:17 -05:00
|
|
|
{
|
2016-02-28 15:54:08 -05:00
|
|
|
MouseButtonBindingMap& bbm = get_mousemap(op);
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
MouseButtonBindingMap::value_type newpair (bb, ActionInfo (action_name));
|
|
|
|
bbm.insert (newpair);
|
2011-03-03 22:10:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Bindings::remove (MouseButton bb, Operation op)
|
|
|
|
{
|
2016-02-28 15:54:08 -05:00
|
|
|
MouseButtonBindingMap& bbm = get_mousemap(op);
|
2016-03-08 08:36:05 -05:00
|
|
|
MouseButtonBindingMap::iterator b = bbm.find (bb);
|
2011-03-03 22:10:17 -05:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (b != bbm.end()) {
|
|
|
|
bbm.erase (b);
|
|
|
|
}
|
2011-03-03 22:10:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Bindings::save (XMLNode& root)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
XMLNode* presses = new XMLNode (X_("Press"));
|
|
|
|
|
|
|
|
for (KeybindingMap::iterator k = press_bindings.begin(); k != press_bindings.end(); ++k) {
|
|
|
|
XMLNode* child;
|
|
|
|
|
|
|
|
if (k->first.name().empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
child = new XMLNode (X_("Binding"));
|
|
|
|
child->add_property (X_("key"), k->first.name());
|
|
|
|
child->add_property (X_("action"), k->second.action_name);
|
|
|
|
presses->add_child_nocopy (*child);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MouseButtonBindingMap::iterator k = button_press_bindings.begin(); k != button_press_bindings.end(); ++k) {
|
|
|
|
XMLNode* child;
|
|
|
|
child = new XMLNode (X_("Binding"));
|
|
|
|
child->add_property (X_("button"), k->first.name());
|
|
|
|
child->add_property (X_("action"), k->second.action_name);
|
|
|
|
presses->add_child_nocopy (*child);
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode* releases = new XMLNode (X_("Release"));
|
|
|
|
|
|
|
|
for (KeybindingMap::iterator k = release_bindings.begin(); k != release_bindings.end(); ++k) {
|
|
|
|
XMLNode* child;
|
|
|
|
|
|
|
|
if (k->first.name().empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
child = new XMLNode (X_("Binding"));
|
|
|
|
child->add_property (X_("key"), k->first.name());
|
|
|
|
child->add_property (X_("action"), k->second.action_name);
|
|
|
|
releases->add_child_nocopy (*child);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MouseButtonBindingMap::iterator k = button_release_bindings.begin(); k != button_release_bindings.end(); ++k) {
|
|
|
|
XMLNode* child;
|
|
|
|
child = new XMLNode (X_("Binding"));
|
|
|
|
child->add_property (X_("button"), k->first.name());
|
|
|
|
child->add_property (X_("action"), k->second.action_name);
|
|
|
|
releases->add_child_nocopy (*child);
|
|
|
|
}
|
|
|
|
|
|
|
|
root.add_child_nocopy (*presses);
|
|
|
|
root.add_child_nocopy (*releases);
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-08-08 08:36:29 -04:00
|
|
|
Bindings::load (XMLNode const& node)
|
2010-08-06 14:44:55 -04:00
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
const XMLNodeList& children (node.children());
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
press_bindings.clear ();
|
|
|
|
release_bindings.clear ();
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
|
|
|
|
/* each node could be Press or Release */
|
|
|
|
load_operation (**i);
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
return true;
|
2011-03-03 22:10:17 -05:00
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2011-03-03 22:10:17 -05:00
|
|
|
void
|
2015-08-08 08:36:29 -04:00
|
|
|
Bindings::load_operation (XMLNode const& node)
|
2011-03-03 22:10:17 -05:00
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
if (node.name() == X_("Press") || node.name() == X_("Release")) {
|
|
|
|
|
|
|
|
Operation op;
|
|
|
|
|
|
|
|
if (node.name() == X_("Press")) {
|
|
|
|
op = Press;
|
|
|
|
} else {
|
|
|
|
op = Release;
|
|
|
|
}
|
|
|
|
|
|
|
|
const XMLNodeList& children (node.children());
|
|
|
|
|
|
|
|
for (XMLNodeList::const_iterator p = children.begin(); p != children.end(); ++p) {
|
|
|
|
|
2016-05-04 23:09:37 -04:00
|
|
|
XMLProperty const * ap;
|
|
|
|
XMLProperty const * kp;
|
|
|
|
XMLProperty const * bp;
|
|
|
|
XMLNode const * child = *p;
|
|
|
|
|
|
|
|
ap = child->property ("action");
|
|
|
|
kp = child->property ("key");
|
|
|
|
bp = child->property ("button");
|
2016-03-08 08:36:05 -05:00
|
|
|
|
|
|
|
if (!ap || (!kp && !bp)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kp) {
|
|
|
|
KeyboardKey k;
|
|
|
|
if (!KeyboardKey::make_key (kp->value(), k)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
add (k, op, ap->value());
|
|
|
|
} else {
|
|
|
|
MouseButton b;
|
|
|
|
if (!MouseButton::make_button (bp->value(), b)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
add (b, op, ap->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2015-08-04 13:57:51 -04:00
|
|
|
void
|
2015-08-05 10:56:36 -04:00
|
|
|
Bindings::get_all_actions (std::vector<std::string>& paths,
|
|
|
|
std::vector<std::string>& labels,
|
2015-08-04 13:57:51 -04:00
|
|
|
std::vector<std::string>& tooltips,
|
|
|
|
std::vector<std::string>& keys,
|
2015-08-05 10:56:36 -04:00
|
|
|
std::vector<RefPtr<Action> >& actions)
|
2015-08-04 13:57:51 -04:00
|
|
|
{
|
2015-08-10 14:31:59 -04:00
|
|
|
if (!_action_map) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-04 13:57:51 -04:00
|
|
|
/* build a reverse map from actions to bindings */
|
|
|
|
|
|
|
|
typedef map<Glib::RefPtr<Gtk::Action>,KeyboardKey> ReverseMap;
|
|
|
|
ReverseMap rmap;
|
|
|
|
|
|
|
|
for (KeybindingMap::const_iterator k = press_bindings.begin(); k != press_bindings.end(); ++k) {
|
2015-08-08 08:36:29 -04:00
|
|
|
rmap.insert (make_pair (k->second.action, k->first));
|
2015-08-04 13:57:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get a list of all actions */
|
|
|
|
|
2015-08-05 10:56:36 -04:00
|
|
|
ActionMap::Actions all_actions;
|
2015-08-10 14:31:59 -04:00
|
|
|
_action_map->get_actions (all_actions);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-05 10:56:36 -04:00
|
|
|
for (ActionMap::Actions::const_iterator act = all_actions.begin(); act != all_actions.end(); ++act) {
|
|
|
|
|
2015-08-04 13:57:51 -04:00
|
|
|
paths.push_back ((*act)->get_accel_path());
|
2015-08-05 10:56:36 -04:00
|
|
|
labels.push_back ((*act)->get_label());
|
2015-08-04 13:57:51 -04:00
|
|
|
tooltips.push_back ((*act)->get_tooltip());
|
|
|
|
|
|
|
|
ReverseMap::iterator r = rmap.find (*act);
|
2015-08-05 10:56:36 -04:00
|
|
|
|
2015-08-04 13:57:51 -04:00
|
|
|
if (r != rmap.end()) {
|
2015-08-10 14:31:59 -04:00
|
|
|
keys.push_back (r->second.display_label());
|
2015-08-04 13:57:51 -04:00
|
|
|
} else {
|
|
|
|
keys.push_back (string());
|
|
|
|
}
|
2015-08-05 10:56:36 -04:00
|
|
|
|
|
|
|
actions.push_back (*act);
|
2015-08-04 13:57:51 -04:00
|
|
|
}
|
|
|
|
}
|
2015-08-05 10:56:36 -04:00
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
Bindings*
|
2015-08-10 14:31:59 -04:00
|
|
|
Bindings::get_bindings (string const& name, ActionMap& map)
|
2015-08-08 08:36:29 -04:00
|
|
|
{
|
|
|
|
for (list<Bindings*>::iterator b = bindings.begin(); b != bindings.end(); b++) {
|
|
|
|
if ((*b)->name() == name) {
|
2015-08-10 14:31:59 -04:00
|
|
|
(*b)->set_action_map (map);
|
2015-08-08 08:36:29 -04:00
|
|
|
return *b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Bindings::associate_all ()
|
|
|
|
{
|
|
|
|
for (list<Bindings*>::iterator b = bindings.begin(); b != bindings.end(); b++) {
|
|
|
|
(*b)->associate ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
bool
|
|
|
|
Bindings::is_bound (KeyboardKey const& kb, Operation op) const
|
|
|
|
{
|
|
|
|
const KeybindingMap& km = get_keymap(op);
|
|
|
|
return km.find(kb) != km.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Bindings::is_registered (Operation op, std::string const& action_name) const
|
|
|
|
{
|
|
|
|
const KeybindingMap& km = get_keymap(op);
|
|
|
|
return std::find_if(km.begin(), km.end(), ActionNameRegistered<KeybindingMap::const_iterator::value_type>(action_name)) != km.end();
|
|
|
|
}
|
|
|
|
|
2016-03-05 11:54:02 -05:00
|
|
|
Bindings::KeybindingMap&
|
2016-02-28 15:54:08 -05:00
|
|
|
Bindings::get_keymap (Operation op)
|
|
|
|
{
|
|
|
|
switch (op) {
|
2016-03-08 08:36:05 -05:00
|
|
|
case Press:
|
|
|
|
return press_bindings;
|
|
|
|
case Release:
|
|
|
|
default:
|
|
|
|
return release_bindings;
|
2016-02-28 15:54:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 11:54:02 -05:00
|
|
|
const Bindings::KeybindingMap&
|
2016-02-28 15:54:08 -05:00
|
|
|
Bindings::get_keymap (Operation op) const
|
|
|
|
{
|
|
|
|
switch (op) {
|
2016-03-08 08:36:05 -05:00
|
|
|
case Press:
|
|
|
|
return press_bindings;
|
|
|
|
case Release:
|
|
|
|
default:
|
|
|
|
return release_bindings;
|
2016-02-28 15:54:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 11:54:02 -05:00
|
|
|
Bindings::MouseButtonBindingMap&
|
2016-02-28 15:54:08 -05:00
|
|
|
Bindings::get_mousemap (Operation op)
|
|
|
|
{
|
|
|
|
switch (op) {
|
2016-03-08 08:36:05 -05:00
|
|
|
case Press:
|
|
|
|
return button_press_bindings;
|
|
|
|
case Release:
|
|
|
|
default:
|
|
|
|
return button_release_bindings;
|
2016-02-28 15:54:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
/*==========================================ACTION MAP =========================================*/
|
|
|
|
|
2015-09-01 13:53:19 -04:00
|
|
|
ActionMap::ActionMap (string const & name)
|
|
|
|
: _name (name)
|
|
|
|
, _bindings (0)
|
|
|
|
{
|
|
|
|
action_maps.push_back (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionMap::~ActionMap ()
|
|
|
|
{
|
|
|
|
action_maps.remove (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ActionMap::set_bindings (Bindings* b)
|
|
|
|
{
|
|
|
|
_bindings = b;
|
|
|
|
}
|
|
|
|
|
2015-08-04 13:57:51 -04:00
|
|
|
void
|
|
|
|
ActionMap::get_actions (ActionMap::Actions& acts)
|
|
|
|
{
|
2015-08-08 08:36:29 -04:00
|
|
|
for (_ActionMap::iterator a = _actions.begin(); a != _actions.end(); ++a) {
|
2015-08-04 13:57:51 -04:00
|
|
|
acts.push_back (a->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-06 14:44:55 -04:00
|
|
|
RefPtr<Action>
|
|
|
|
ActionMap::find_action (const string& name)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
_ActionMap::iterator a = _actions.find (name);
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (a != _actions.end()) {
|
|
|
|
return a->second;
|
|
|
|
}
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
return RefPtr<Action>();
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
2015-08-01 22:38:46 -04:00
|
|
|
RefPtr<ActionGroup>
|
|
|
|
ActionMap::create_action_group (const string& name)
|
|
|
|
{
|
|
|
|
RefPtr<ActionGroup> g = ActionGroup::create (name);
|
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
/* this is one of the places where our own Action management code
|
|
|
|
has to touch the GTK one, because we want the GtkUIManager to
|
|
|
|
be able to create widgets (particularly Menus) from our actions.
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
This is a a necessary step for that to happen.
|
|
|
|
*/
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-08 08:36:29 -04:00
|
|
|
if (g) {
|
|
|
|
ActionManager::ui_manager->insert_action_group (g);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g;
|
2015-08-01 22:38:46 -04:00
|
|
|
}
|
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
RefPtr<Action>
|
2015-08-01 22:38:46 -04:00
|
|
|
ActionMap::register_action (RefPtr<ActionGroup> group, const char* name, const char* label)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
string fullpath;
|
2015-08-01 22:38:46 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
RefPtr<Action> act = Action::create (name, label);
|
2015-08-01 22:38:46 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
fullpath = group->get_name();
|
|
|
|
fullpath += '/';
|
|
|
|
fullpath += name;
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (_actions.insert (_ActionMap::value_type (fullpath, act)).second) {
|
|
|
|
group->add (act);
|
|
|
|
return act;
|
|
|
|
}
|
2015-08-04 13:57:51 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* already registered */
|
|
|
|
return RefPtr<Action> ();
|
2015-08-01 22:38:46 -04:00
|
|
|
}
|
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
RefPtr<Action>
|
2015-08-01 22:38:46 -04:00
|
|
|
ActionMap::register_action (RefPtr<ActionGroup> group,
|
2010-08-06 14:44:55 -04:00
|
|
|
const char* name, const char* label, sigc::slot<void> sl)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
string fullpath;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
RefPtr<Action> act = Action::create (name, label);
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
fullpath = group->get_name();
|
|
|
|
fullpath += '/';
|
|
|
|
fullpath += name;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (_actions.insert (_ActionMap::value_type (fullpath, act)).second) {
|
|
|
|
group->add (act, sl);
|
|
|
|
return act;
|
|
|
|
}
|
2015-08-01 22:38:46 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* already registered */
|
|
|
|
return RefPtr<Action>();
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
RefPtr<Action>
|
2015-08-01 22:38:46 -04:00
|
|
|
ActionMap::register_radio_action (RefPtr<ActionGroup> group,
|
|
|
|
Gtk::RadioAction::Group& rgroup,
|
2015-10-26 14:35:06 -04:00
|
|
|
const char* name, const char* label,
|
2015-08-01 22:38:46 -04:00
|
|
|
sigc::slot<void> sl)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
string fullpath;
|
2015-08-01 22:38:46 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
RefPtr<Action> act = RadioAction::create (rgroup, name, label);
|
|
|
|
RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
fullpath = group->get_name();
|
|
|
|
fullpath += '/';
|
|
|
|
fullpath += name;
|
2015-08-01 22:38:46 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (_actions.insert (_ActionMap::value_type (fullpath, act)).second) {
|
|
|
|
group->add (act, sl);
|
|
|
|
return act;
|
|
|
|
}
|
2015-08-04 13:57:51 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* already registered */
|
|
|
|
return RefPtr<Action>();
|
2015-08-01 22:38:46 -04:00
|
|
|
}
|
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
RefPtr<Action>
|
2015-08-01 22:38:46 -04:00
|
|
|
ActionMap::register_radio_action (RefPtr<ActionGroup> group,
|
|
|
|
Gtk::RadioAction::Group& rgroup,
|
2015-10-26 14:35:06 -04:00
|
|
|
const char* name, const char* label,
|
2010-08-10 17:27:19 -04:00
|
|
|
sigc::slot<void,GtkAction*> sl,
|
|
|
|
int value)
|
2010-08-06 14:44:55 -04:00
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
string fullpath;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
RefPtr<Action> act = RadioAction::create (rgroup, name, label);
|
|
|
|
RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
|
|
|
|
ract->property_value() = value;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
fullpath = group->get_name();
|
|
|
|
fullpath += '/';
|
|
|
|
fullpath += name;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (_actions.insert (_ActionMap::value_type (fullpath, act)).second) {
|
|
|
|
group->add (act, sigc::bind (sl, act->gobj()));
|
|
|
|
return act;
|
|
|
|
}
|
2015-08-04 13:57:51 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* already registered */
|
2015-08-04 13:57:51 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
return RefPtr<Action>();
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
|
|
|
|
2015-10-26 14:35:06 -04:00
|
|
|
RefPtr<Action>
|
2015-08-01 22:38:46 -04:00
|
|
|
ActionMap::register_toggle_action (RefPtr<ActionGroup> group,
|
2010-08-06 14:44:55 -04:00
|
|
|
const char* name, const char* label, sigc::slot<void> sl)
|
|
|
|
{
|
2016-03-08 08:36:05 -05:00
|
|
|
string fullpath;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
fullpath = group->get_name();
|
|
|
|
fullpath += '/';
|
|
|
|
fullpath += name;
|
2010-08-06 14:44:55 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
RefPtr<Action> act = ToggleAction::create (name, label);
|
2015-08-04 13:57:51 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
if (_actions.insert (_ActionMap::value_type (fullpath, act)).second) {
|
|
|
|
group->add (act, sl);
|
|
|
|
return act;
|
|
|
|
}
|
2015-08-04 13:57:51 -04:00
|
|
|
|
2016-03-08 08:36:05 -05:00
|
|
|
/* already registered */
|
|
|
|
return RefPtr<Action>();
|
2010-08-06 14:44:55 -04:00
|
|
|
}
|
2015-07-09 18:10:19 -04:00
|
|
|
|
2015-09-01 15:46:30 -04:00
|
|
|
void
|
|
|
|
ActionMap::get_all_actions (std::vector<std::string>& paths,
|
2016-03-08 08:36:05 -05:00
|
|
|
std::vector<std::string>& labels,
|
|
|
|
std::vector<std::string>& tooltips,
|
|
|
|
std::vector<std::string>& keys,
|
|
|
|
std::vector<RefPtr<Action> >& actions)
|
2015-09-01 15:46:30 -04:00
|
|
|
{
|
|
|
|
for (list<ActionMap*>::const_iterator map = action_maps.begin(); map != action_maps.end(); ++map) {
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-09-01 15:46:30 -04:00
|
|
|
ActionMap::Actions these_actions;
|
|
|
|
(*map)->get_actions (these_actions);
|
|
|
|
|
|
|
|
for (ActionMap::Actions::const_iterator act = these_actions.begin(); act != these_actions.end(); ++act) {
|
|
|
|
|
|
|
|
paths.push_back ((*act)->get_accel_path());
|
|
|
|
labels.push_back ((*act)->get_label());
|
|
|
|
tooltips.push_back ((*act)->get_tooltip());
|
|
|
|
actions.push_back (*act);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-09-01 15:46:30 -04:00
|
|
|
Bindings* bindings = (*map)->bindings();
|
|
|
|
|
|
|
|
if (bindings) {
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-09-01 15:46:30 -04:00
|
|
|
KeyboardKey key;
|
|
|
|
Bindings::Operation op;
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-09-01 15:46:30 -04:00
|
|
|
key = bindings->get_binding_for_action (*act, op);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-09-01 15:46:30 -04:00
|
|
|
if (key == KeyboardKey::null_key()) {
|
|
|
|
keys.push_back (string());
|
|
|
|
} else {
|
|
|
|
keys.push_back (key.display_label());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
keys.push_back (string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
these_actions.clear ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-01 22:38:46 -04:00
|
|
|
std::ostream& operator<<(std::ostream& out, Gtkmm2ext::KeyboardKey const & k) {
|
2015-08-05 10:56:36 -04:00
|
|
|
char const *gdk_name = gdk_keyval_name (k.key());
|
2015-10-27 13:29:22 -04:00
|
|
|
return out << "Key " << k.key() << " (" << (gdk_name ? gdk_name : "no-key") << ") state " << hex << k.state() << dec;
|
2015-07-09 18:10:19 -04:00
|
|
|
}
|