diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp
index ffd5aa94879cf0915261de32b9b1f9f9104905ea..d647d30b3264aebfaf9b01e035f5ce72280dcff5 100644 (file)
--- a/src/shortcuts.cpp
+++ b/src/shortcuts.cpp
#endif
#include <vector>
+#include <cstring>
+#include <string>
#include <gdk/gdkkeys.h>
#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
#include "helper/action.h"
#include "io/sys.h"
bool is_primary;
if (!strcmp(iter->name(), "bind")) {
- if (iter->attribute("display") && strcmp(iter->attribute("display"), "false") && strcmp(iter->attribute("display"), "0")) {
- is_primary = true;
- } else {
- is_primary = false;
- }
+ is_primary = iter->attribute("display") && strcmp(iter->attribute("display"), "false") && strcmp(iter->attribute("display"), "0");
} else {
// some unknown element, do not complain
continue;
continue;
}
- if (Inkscape::Verb::getbyid(verb_name) == NULL) {
+ Inkscape::Verb *verb=Inkscape::Verb::getbyid(verb_name);
+ if (!verb) {
g_warning("Unknown verb name: %s", verb_name);
continue;
}
gchar const *keyval_name=iter->attribute("key");
- if (!keyval_name) {
+ if (!keyval_name || !*keyval_name) {
// that's ok, it's just listed for reference without assignment, skip it
continue;
}
+
guint keyval=gdk_keyval_from_name(keyval_name);
- if (keyval == GDK_VoidSymbol) {
+ if (keyval == GDK_VoidSymbol || keyval == 0) {
g_warning("Unknown keyval %s for %s", keyval_name, verb_name);
continue;
}
}
}
- sp_shortcut_set(keyval | modifiers,
- Inkscape::Verb::getbyid(verb_name),
- is_primary);
+ sp_shortcut_set(keyval | modifiers, verb, is_primary);
}
GC::release(doc);
return (Inkscape::Verb *)(g_hash_table_lookup(verbs, GINT_TO_POINTER(shortcut)));
}
-unsigned int
-sp_shortcut_get_primary(Inkscape::Verb *verb)
+unsigned int sp_shortcut_get_primary(Inkscape::Verb *verb)
{
- if (!primary_shortcuts) sp_shortcut_init();
- return (unsigned int)GPOINTER_TO_INT(g_hash_table_lookup(primary_shortcuts,
- (gpointer)(verb)));
+ unsigned int result = GDK_VoidSymbol;
+ if (!primary_shortcuts) {
+ sp_shortcut_init();
+ }
+ gpointer value = 0;
+ if (g_hash_table_lookup_extended(primary_shortcuts, static_cast<gpointer>(verb), NULL, &value)) {
+ result = static_cast<unsigned int>(GPOINTER_TO_INT(value));
+ }
+ return result;
}
+gchar *sp_shortcut_get_label(unsigned int shortcut)
+{
+ // The comment below was copied from the function sp_ui_shortcut_string in interface.cpp (which was subsequently removed)
+ /* TODO: This function shouldn't exist. Our callers should use GtkAccelLabel instead of
+ * a generic GtkLabel containing this string, and should call gtk_widget_add_accelerator.
+ * Will probably need to change sp_shortcut_invoke callers.
+ *
+ * The existing gtk_label_new_with_mnemonic call can be replaced with
+ * g_object_new(GTK_TYPE_ACCEL_LABEL, NULL) followed by
+ * gtk_label_set_text_with_mnemonic(lbl, str).
+ */
+ gchar *result = 0;
+ if (shortcut != GDK_VoidSymbol) {
+ result = gtk_accelerator_get_label(
+ shortcut & (~SP_SHORTCUT_MODIFIER_MASK), static_cast<GdkModifierType>(
+ ((shortcut & SP_SHORTCUT_SHIFT_MASK) ? GDK_SHIFT_MASK : 0) |
+ ((shortcut & SP_SHORTCUT_CONTROL_MASK) ? GDK_CONTROL_MASK : 0) |
+ ((shortcut & SP_SHORTCUT_ALT_MASK) ? GDK_MOD1_MASK : 0)
+ ));
+ }
+ return result;
+}
/*
Local Variables:
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :