From 331007daf93a64a88f7e064400b72a89a6f87417 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Thu, 11 Apr 2019 00:37:57 +0200 Subject: Ask user whether to reassign already used shortcuts Fixes https://gitlab.com/inkscape/inkscape/issues/182 --- src/ui/dialog/inkscape-preferences.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 2b1a23571..0c89a2257 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -2137,7 +2137,26 @@ void InkscapePreferences::onKBTreeEdited (const Glib::ustring& path, guint accel } unsigned int const new_shortcut_id = sp_shortcut_get_from_gdk_event(accel_key, accel_mods, hardware_keycode); - if (new_shortcut_id) { + if (new_shortcut_id && (new_shortcut_id != current_shortcut_id)) { + // check if there is currently a verb assigned to this shortcut; if yes ask if the shortcut should be reassigned + Inkscape::Verb *current_verb = sp_shortcut_get_verb(new_shortcut_id); + if (current_verb) { + Glib::ustring verb_name = _(current_verb->get_name()); + Glib::ustring::size_type pos = 0; + while ((pos = verb_name.find('_', pos)) != verb_name.npos) { // strip mnemonics + verb_name.erase(pos, 1); + } + Glib::ustring message = Glib::ustring::compose(_("Keyboard shortcut \"%1\"\nis already assigned to \"%2\""), + sp_shortcut_get_label(new_shortcut_id), verb_name); + Gtk::MessageDialog dialog(message, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, true); + dialog.set_title(_("Reassign shortcut?")); + dialog.set_secondary_text(_("Are you sure you want to reassign this shortcut?")); + dialog.set_transient_for(*dynamic_cast(get_toplevel())); + int response = dialog.run(); + if (response != Gtk::RESPONSE_YES) { + return; + } + } // Delete current shortcut if it existed sp_shortcut_delete_from_file(id.c_str(), current_shortcut_id); -- cgit v1.2.3