From 35238cd4f14f00509d1dfaf6d01566ec04eb9768 Mon Sep 17 00:00:00 2001
From: ArdourEnv <ardourenv@Roberts-iMac.home>
Date: Sun, 28 Aug 2016 13:42:24 -0400
Subject: [PATCH 1/2] Bindings dialog change

---
 gtk2_ardour/keyeditor.cc            | 13 ++++++++-----
 libs/gtkmm2ext/bindings.cc          |  7 +++++++
 libs/gtkmm2ext/gtkmm2ext/bindings.h |  1 +
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gtk2_ardour/keyeditor.cc b/gtk2_ardour/keyeditor.cc
index aea8185..f971879 100644
--- a/gtk2_ardour/keyeditor.cc
+++ b/gtk2_ardour/keyeditor.cc
@@ -62,12 +62,15 @@ using Gtkmm2ext::Bindings;
 
 sigc::signal<void> KeyEditor::UpdateBindings;
 
-void bindings_collision_dialog (Gtk::Window& parent)
+void bindings_collision_dialog (Gtk::Window& parent, const string &missing_binding, Gtkmm2ext::KeyboardKey& key)
 {
 	ArdourDialog dialog (parent, _("Colliding keybindings"), true);
-	Label label (_("The key sequence is already bound. Please remove the other binding first."));
-
-	dialog.get_vbox()->pack_start (label, true, true);
+    Label label_error (_("The key sequence is already bound. Please remove the other binding first."));
+    Label label_missing (string_compose("%1: %2\n%3: %4", _("Shortcut"), key.display_label(), _("Action"), missing_binding));
+    
+    label_missing.set_padding(0, 10);
+	dialog.get_vbox()->pack_start (label_error, true, true);
+    dialog.get_vbox()->pack_end (label_missing, true, true);
 	dialog.add_button (_("Ok"), Gtk::RESPONSE_ACCEPT);
 	dialog.show_all ();
 	dialog.run();
@@ -316,7 +319,7 @@ KeyEditor::Tab::bind (GdkEventKey* release_event, guint pressed_key)
 	Gtkmm2ext::KeyboardKey new_binding (mod, pressed_key);
 
 	if (bindings->is_bound (new_binding, Gtkmm2ext::Bindings::Press)) {
-		bindings_collision_dialog (owner);
+		bindings_collision_dialog (owner, bindings->get_action_name_by_key(new_binding, Gtkmm2ext::Bindings::Press), new_binding);
 		return;
 	}
 
diff --git a/libs/gtkmm2ext/bindings.cc b/libs/gtkmm2ext/bindings.cc
index e25ed20..de45495 100644
--- a/libs/gtkmm2ext/bindings.cc
+++ b/libs/gtkmm2ext/bindings.cc
@@ -1066,6 +1066,13 @@ Bindings::is_bound (KeyboardKey const& kb, Operation op) const
 	return km.find(kb) != km.end();
 }
 
+string const&
+Bindings::get_action_name_by_key (KeyboardKey const& kb, Operation op) const
+{
+	const KeybindingMap& km = get_keymap(op);
+	return km.find(kb)->second.action_name;
+}
+
 bool
 Bindings::is_registered (Operation op, std::string const& action_name) const
 {
diff --git a/libs/gtkmm2ext/gtkmm2ext/bindings.h b/libs/gtkmm2ext/gtkmm2ext/bindings.h
index d216e04..05d44c3 100644
--- a/libs/gtkmm2ext/gtkmm2ext/bindings.h
+++ b/libs/gtkmm2ext/gtkmm2ext/bindings.h
@@ -178,6 +178,7 @@ class LIBGTKMM2EXT_API Bindings {
 	bool activate (MouseButton, Operation);
 
 	bool is_bound (KeyboardKey const&, Operation) const;
+    const std::string &get_action_name_by_key(KeyboardKey const&, Operation op) const; 
 	bool is_registered (Operation op, std::string const& action_name) const;
 
 	KeyboardKey get_binding_for_action (Glib::RefPtr<Gtk::Action>, Operation& op);
-- 
2.7.4 (Apple Git-66)


From 944d62e80058cb938731d1a7be9ae9f61d58eb63 Mon Sep 17 00:00:00 2001
From: Robert Randolph <audiolabs@gmail.com>
Date: Mon, 29 Aug 2016 10:19:04 -0400
Subject: [PATCH 2/2] Resolved potential crash in get_action_by_name() and
 fixed indentation.

---
 gtk2_ardour/keyeditor.cc            | 10 +++++-----
 libs/gtkmm2ext/bindings.cc          |  6 +++++-
 libs/gtkmm2ext/gtkmm2ext/bindings.h |  2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/gtk2_ardour/keyeditor.cc b/gtk2_ardour/keyeditor.cc
index f971879..302606b 100644
--- a/gtk2_ardour/keyeditor.cc
+++ b/gtk2_ardour/keyeditor.cc
@@ -65,12 +65,12 @@ sigc::signal<void> KeyEditor::UpdateBindings;
 void bindings_collision_dialog (Gtk::Window& parent, const string &missing_binding, Gtkmm2ext::KeyboardKey& key)
 {
 	ArdourDialog dialog (parent, _("Colliding keybindings"), true);
-    Label label_error (_("The key sequence is already bound. Please remove the other binding first."));
-    Label label_missing (string_compose("%1: %2\n%3: %4", _("Shortcut"), key.display_label(), _("Action"), missing_binding));
-    
-    label_missing.set_padding(0, 10);
+	Label label_error (_("The key sequence is already bound. Please remove the other binding first."));
+	Label label_missing (string_compose("%1: %2\n%3: %4", _("Shortcut"), key.display_label(), _("Action"), missing_binding));
+
+	label_missing.set_padding(0, 10);
 	dialog.get_vbox()->pack_start (label_error, true, true);
-    dialog.get_vbox()->pack_end (label_missing, true, true);
+	dialog.get_vbox()->pack_end (label_missing, true, true);
 	dialog.add_button (_("Ok"), Gtk::RESPONSE_ACCEPT);
 	dialog.show_all ();
 	dialog.run();
diff --git a/libs/gtkmm2ext/bindings.cc b/libs/gtkmm2ext/bindings.cc
index de45495..52834cd 100644
--- a/libs/gtkmm2ext/bindings.cc
+++ b/libs/gtkmm2ext/bindings.cc
@@ -1070,7 +1070,11 @@ string const&
 Bindings::get_action_name_by_key (KeyboardKey const& kb, Operation op) const
 {
 	const KeybindingMap& km = get_keymap(op);
-	return km.find(kb)->second.action_name;
+	if (is_bound(kb, op)) {
+		return km.find(kb)->second.action_name;
+	} else {
+		return _("no action bound");
+	}
 }
 
 bool
diff --git a/libs/gtkmm2ext/gtkmm2ext/bindings.h b/libs/gtkmm2ext/gtkmm2ext/bindings.h
index 05d44c3..9b5a923 100644
--- a/libs/gtkmm2ext/gtkmm2ext/bindings.h
+++ b/libs/gtkmm2ext/gtkmm2ext/bindings.h
@@ -178,7 +178,7 @@ class LIBGTKMM2EXT_API Bindings {
 	bool activate (MouseButton, Operation);
 
 	bool is_bound (KeyboardKey const&, Operation) const;
-    const std::string &get_action_name_by_key(KeyboardKey const&, Operation op) const; 
+	const std::string &get_action_name_by_key(KeyboardKey const&, Operation op) const; 
 	bool is_registered (Operation op, std::string const& action_name) const;
 
 	KeyboardKey get_binding_for_action (Glib::RefPtr<Gtk::Action>, Operation& op);
-- 
2.7.4 (Apple Git-66)

