X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fshortcuts.cpp;h=12657410c9b66b35bfc46e53304c1ef699cb4b18;hb=9778e170b43ef3ab1416d84092061ff7d29325e3;hp=047928071d5d3e8812ae758f2502aade3d97bc5a;hpb=6b15695578f07a3f72c4c9475c1a261a3021472a;p=inkscape.git diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp index 047928071..12657410c 100644 --- a/src/shortcuts.cpp +++ b/src/shortcuts.cpp @@ -22,10 +22,14 @@ # include "config.h" #endif +#include + #include #include #include "helper/action.h" +#include "io/sys.h" +#include "io/resource.h" #include "shortcuts.h" #include "verbs.h" #include "xml/node-iterators.h" @@ -34,8 +38,8 @@ using namespace Inkscape; static void sp_shortcut_set(unsigned int const shortcut, Inkscape::Verb *const verb, bool const is_primary); - -static void set_shortcuts_xml(XML::Document const *doc); +static void try_shortcuts_file(char const *filename); +static void read_shortcuts_file(char const *filename); /* Returns true if action was performed */ @@ -56,52 +60,70 @@ sp_shortcut_invoke(unsigned int shortcut, Inkscape::UI::View::View *view) static GHashTable *verbs = NULL; static GHashTable *primary_shortcuts = NULL; -extern char const shortcuts_default_xml[]; - static void sp_shortcut_init() { + using Inkscape::IO::Resource::get_path; + using Inkscape::IO::Resource::SYSTEM; + using Inkscape::IO::Resource::USER; + using Inkscape::IO::Resource::KEYS; + verbs = g_hash_table_new(NULL, NULL); primary_shortcuts = g_hash_table_new(NULL, NULL); - XML::Document *shortcuts=sp_repr_read_mem(shortcuts_default_xml, strlen(shortcuts_default_xml), NULL); - if (shortcuts) { - set_shortcuts_xml(shortcuts); - GC::release(shortcuts); - } else { - g_error("Unable to parse default shortcuts"); + read_shortcuts_file(get_path(SYSTEM, KEYS, "default.xml")); + try_shortcuts_file(get_path(USER, KEYS, "default.xml")); +} + +static void try_shortcuts_file(char const *filename) { + using Inkscape::IO::file_test; + + /* ah, if only we had an exception to catch... (permission, forgiveness) */ + if (file_test(filename, G_FILE_TEST_EXISTS)) { + read_shortcuts_file(filename); } } -static void set_shortcuts_xml(XML::Document const *doc) { +static void read_shortcuts_file(char const *filename) { + XML::Document *doc=sp_repr_read_file(filename, NULL); + if (!doc) { + g_warning("Unable to read keys file %s", filename); + return; + } + XML::Node const *root=doc->root(); - g_return_if_fail(!strcmp(root->name(), "keybindings")); + g_return_if_fail(!strcmp(root->name(), "keys")); XML::NodeConstSiblingIterator iter=root->firstChild(); for ( ; iter ; ++iter ) { bool is_primary; - if (!strcmp(iter->name(), "primary")) { - is_primary = true; - } else if (!strcmp(iter->name(), "secondary")) { - is_primary = false; + if (!strcmp(iter->name(), "bind")) { + is_primary = iter->attribute("display") && strcmp(iter->attribute("display"), "false") && strcmp(iter->attribute("display"), "0"); } else { - g_warning("Unknown key binding type %s", iter->name()); + // some unknown element, do not complain continue; } - gchar const *verb_name=iter->attribute("verb"); + gchar const *verb_name=iter->attribute("action"); if (!verb_name) { - g_warning("Missing verb name for shortcut"); + g_warning("Missing verb name (action= attribute) for shortcut"); continue; } - gchar const *keyval_name=iter->attribute("keyval"); - if (!keyval_name) { - g_warning("Missing keyval for %s", verb_name); + 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 || !*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; } @@ -114,11 +136,11 @@ static void set_shortcuts_xml(XML::Document const *doc) { while (*iter) { size_t length=strcspn(iter, ","); gchar *mod=g_strndup(iter, length); - if (!strcmp(mod, "control")) { + if (!strcmp(mod, "Control") || !strcmp(mod, "Ctrl")) { modifiers |= SP_SHORTCUT_CONTROL_MASK; - } else if (!strcmp(mod, "shift")) { + } else if (!strcmp(mod, "Shift")) { modifiers |= SP_SHORTCUT_SHIFT_MASK; - } else if (!strcmp(mod, "alt")) { + } else if (!strcmp(mod, "Alt")) { modifiers |= SP_SHORTCUT_ALT_MASK; } else { g_warning("Unknown modifier %s for %s", mod, verb_name); @@ -129,10 +151,10 @@ static void set_shortcuts_xml(XML::Document const *doc) { } } - sp_shortcut_set(keyval | modifiers, - Inkscape::Verb::getbyid(verb_name), - is_primary); + sp_shortcut_set(keyval | modifiers, verb, is_primary); } + + GC::release(doc); } /**