allow use of Return, KP_Enter and more in key binding editor; better display of such bindings; potential fix for "crashes" caused by an endless loop of enter/hide events involving the verbose canvas cursor

git-svn-id: svn://localhost/ardour2/branches/3.0@6109 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2009-11-17 13:54:04 +00:00
parent d0cc6edadf
commit 29d677e668
9 changed files with 119 additions and 26 deletions

View file

@ -36,6 +36,7 @@
#include "ardour/filesystem_paths.h"
#include "ardour/rc_configuration.h"
#include "utils.h"
#include "actions.h"
#include "i18n.h"
@ -248,14 +249,7 @@ ActionManager::get_all_actions (vector<string>& names, vector<string>& paths, ve
paths.push_back (accel_path);
AccelKey key;
bool known = lookup_entry (accel_path, key);
if (known) {
keys.push_back (ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod())));
} else {
keys.push_back (unbound_string);
}
keys.push_back (get_key_representation (accel_path, key));
bindings.push_back (AccelKey (key.get_key(), Gdk::ModifierType (key.get_mod())));
}
}
@ -442,3 +436,17 @@ ActionManager::map_some_state (const char* group, const char* action, sigc::slot
}
}
}
string
ActionManager::get_key_representation (const string& accel_path, AccelKey& key)
{
bool known = lookup_entry (accel_path, key);
if (known) {
uint32_t k = possibly_translate_legal_accelerator_to_real_key (key.get_key());
key = AccelKey (k, Gdk::ModifierType (key.get_mod()));
return ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
}
return unbound_string;
}

View file

@ -67,6 +67,8 @@ class ActionManager
static void set_sensitive (std::vector<Glib::RefPtr<Gtk::Action> >& actions, bool);
static std::string get_key_representation (const std::string& accel_path, Gtk::AccelKey& key);
static std::string unbound_string; /* the key string returned if an action is not bound */
static Glib::RefPtr<Gtk::UIManager> ui_manager;

View file

@ -0,0 +1,45 @@
/*
* Copyright (C) 2009 Paul Davis <paul@linuxaudiosystems.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef __gtk2_ardour_canvas_noevent_text_h__
#define __gtk2_ardour_canvas_noevent_text_h__
#include <libgnomecanvasmm/text.h>
#include <libgnomecanvasmm/text.h>
namespace Gnome { namespace Canvas {
class NoEventText : public Text
{
public:
NoEventText(Group& parent, double x, double y, const Glib::ustring& text)
: Text (parent, x, y, text) {}
NoEventText(Group& parent)
: Text (parent) {}
double point_vfunc(double, double, int, int, GnomeCanvasItem**) {
/* return a huge value to tell the canvas that we're never the item for an event */
return 9999999999999.0;
}
};
} } /* namespaces */
#endif /* __gtk2_ardour_canvas_noevent_text_h__ */

View file

@ -3329,13 +3329,6 @@ Editor::show_verbose_canvas_cursor_with (const string & txt)
track_canvas->get_pointer (x, y);
track_canvas->window_to_world (x, y, wx, wy);
/* move it away from the mouse pointer to avoid an
infinite loop of enter/leave events.
*/
wx += 20;
wy += 20;
/* don't get too close to the edge */
verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (wx);
verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (wy);

View file

@ -61,6 +61,7 @@
#include "editing.h"
#include "enums.h"
#include "editor_items.h"
#include "canvas-noevent-text.h"
#include "region_selection.h"
#include "canvas.h"
#include "editor_summary.h"
@ -626,7 +627,7 @@ class Editor : public PublicEditor
ArdourCanvas::Canvas* track_canvas;
ArdourCanvas::Text* verbose_canvas_cursor;
ArdourCanvas::NoEventText* verbose_canvas_cursor;
bool verbose_cursor_visible;
void parameter_changed (std::string);

View file

@ -116,7 +116,7 @@ Editor::initialize_canvas ()
Pango::FontDescription* font = get_font_for_style (N_("VerboseCanvasCursor"));
verbose_canvas_cursor = new ArdourCanvas::Text (*track_canvas->root());
verbose_canvas_cursor = new ArdourCanvas::NoEventText (*track_canvas->root());
verbose_canvas_cursor->property_font_desc() = *font;
verbose_canvas_cursor->property_anchor() = ANCHOR_NW;

View file

@ -86,6 +86,8 @@ KeyEditor::unbind ()
unbind_button.set_sensitive (false);
cerr << "trying to unbind\n";
if (i != model->children().end()) {
string path = (*i)[columns.path];
@ -168,24 +170,21 @@ KeyEditor::on_key_release_event (GdkEventKey* ev)
goto out;
}
cerr << "real lkeyval: " << ev->keyval << endl;
possibly_translate_keyval_to_make_legal_accelerator (ev->keyval);
cerr << "using keyval = " << ev->keyval << endl;
bool result = AccelMap::change_entry (path,
ev->keyval,
ModifierType (Keyboard::RelevantModifierKeyMask & ev->state),
true);
cerr << "New binding to " << ev->keyval << " worked: " << result << endl;
if (result) {
bool known;
AccelKey key;
known = ActionManager::lookup_entry (path, key);
if (known) {
(*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
} else {
(*i)[columns.binding] = string();
}
(*i)[columns.binding] = ActionManager::get_key_representation (path, key);
}
}

View file

@ -879,6 +879,14 @@ possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval)
fakekey = GDK_leftarrow;
break;
case GDK_Return:
fakekey = GDK_3270_Enter;
break;
case GDK_KP_Enter:
fakekey = GDK_F35;
break;
default:
break;
}
@ -891,6 +899,42 @@ possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval)
return false;
}
uint32_t
possibly_translate_legal_accelerator_to_real_key (uint32_t keyval)
{
switch (keyval) {
case GDK_nabla:
return GDK_Tab;
break;
case GDK_uparrow:
return GDK_Up;
break;
case GDK_downarrow:
return GDK_Down;
break;
case GDK_rightarrow:
return GDK_Right;
break;
case GDK_leftarrow:
return GDK_Left;
break;
case GDK_3270_Enter:
return GDK_Return;
case GDK_F35:
return GDK_KP_Enter;
break;
}
return keyval;
}
inline guint8
convert_color_channel (guint8 src,

View file

@ -85,6 +85,7 @@ void set_color (Gdk::Color&, int);
bool relay_key_press (GdkEventKey* ev, Gtk::Window* win);
bool key_press_focus_accelerator_handler (Gtk::Window& window, GdkEventKey* ev);
bool possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval);
uint32_t possibly_translate_legal_accelerator_to_real_key (uint32_t keyval);
Glib::RefPtr<Gdk::Pixbuf> get_xpm (std::string);
Glib::ustring get_icon_path (const char*);