From 75d34b7742c2e9861167fd55a1885128947e511a Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 9 Jul 2017 00:41:47 +0200 Subject: Hackest regression: We can not exlude the shortcuts file default.xml from the list of shortcut files - it's the default and selected by default! (the exlusion in the original code was targeted at the default.xml file in the profile directory only, as only the user's modifications are stored there and it's not a complete shortcut map) Also properly sort the entries in the dropdown (default.xml first, rest of shortcut files alphabetically) --- src/shortcuts.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/shortcuts.cpp') diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp index e7343c5e4..e22fe2dae 100644 --- a/src/shortcuts.cpp +++ b/src/shortcuts.cpp @@ -217,7 +217,12 @@ Inkscape::XML::Document *sp_shortcut_create_template_file(char const *filename) void sp_shortcut_get_file_names(std::vector *names, std::vector *paths) { using namespace Inkscape::IO::Resource; - for(auto &filename: get_filenames(KEYS, {".xml"}, {"default.xml", "inkscape.xml"})) { + std::vector filenames = get_filenames(SYSTEM, KEYS, {".xml"}); + std::vector filenames_user = get_filenames(USER, KEYS, {".xml"}, {"default.xml"}); // exclude default.xml as it only includes the user's modifications + filenames.insert(filenames.end(), filenames_user.begin(), filenames_user.end()); + + std::vector> names_and_paths; + for(auto &filename: filenames) { Glib::ustring label = Glib::path_get_basename(filename); XML::Document *doc = sp_repr_read_file(filename.c_str(), NULL); @@ -226,21 +231,40 @@ void sp_shortcut_get_file_names(std::vector *names, std::vectorroot(); if (!strcmp(root->name(), "keys")) { gchar const *name=root->attribute("name"); if (name) { label = Glib::ustring(name) + " (" + label + ")"; } - paths->push_back(filename.c_str()); - names->push_back(label.c_str()); + std::pair name_and_path; + name_and_path = std::make_pair(label, filename); + names_and_paths.push_back(name_and_path); } else { g_warning("Not a shortcut keys file %s", filename.c_str()); } Inkscape::GC::release(doc); } - + + // sort by name + std::sort(names_and_paths.begin(), names_and_paths.end(), + [](std::pair& pair1, std::pair& pair2) { + return Glib::path_get_basename(pair1.first).compare(Glib::path_get_basename(pair2.first)) < 0; + }); + auto it_default = std::find_if(names_and_paths.begin(), names_and_paths.end(), + [](std::pair& pair) { + return !Glib::path_get_basename(pair.second).compare("default.xml"); + }); + if (it_default != names_and_paths.end()) { + std::rotate(names_and_paths.begin(), it_default, it_default+1); + } + + // transform pairs to output vectors + std::transform(names_and_paths.begin(),names_and_paths.end(), std::back_inserter(*names), + [](const std::pair& pair) { return pair.first; }); + std::transform(names_and_paths.begin(),names_and_paths.end(), std::back_inserter(*paths), + [](const std::pair& pair) { return pair.second; }); } Glib::ustring sp_shortcut_get_file_path() -- cgit v1.2.3