summaryrefslogtreecommitdiffstats
path: root/src/shortcuts.cpp
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-07-08 22:41:47 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-07-08 22:41:47 +0000
commit75d34b7742c2e9861167fd55a1885128947e511a (patch)
tree705cf45b79ec02088838a1ce049fe5fb3b545f67 /src/shortcuts.cpp
parentReplace deprecated SHGetSpecialFolderLocation with SHGetFolderLocation (diff)
downloadinkscape-75d34b7742c2e9861167fd55a1885128947e511a.tar.gz
inkscape-75d34b7742c2e9861167fd55a1885128947e511a.zip
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)
Diffstat (limited to 'src/shortcuts.cpp')
-rw-r--r--src/shortcuts.cpp34
1 files changed, 29 insertions, 5 deletions
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<Glib::ustring> *names, std::vector<Glib::ustring> *paths) {
using namespace Inkscape::IO::Resource;
- for(auto &filename: get_filenames(KEYS, {".xml"}, {"default.xml", "inkscape.xml"})) {
+ std::vector<Glib::ustring> filenames = get_filenames(SYSTEM, KEYS, {".xml"});
+ std::vector<Glib::ustring> 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<std::pair<Glib::ustring, Glib::ustring>> 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<Glib::ustring> *names, std::vector<G
continue;
}
- // Get the "key name" from the root element of each files
+ // Get the "key name" from the root element of each file
XML::Node *root=doc->root();
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<Glib::ustring, Glib::ustring> 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<Glib::ustring, Glib::ustring>& pair1, std::pair<Glib::ustring, Glib::ustring>& 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<Glib::ustring, Glib::ustring>& 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<Glib::ustring, Glib::ustring>& pair) { return pair.first; });
+ std::transform(names_and_paths.begin(),names_and_paths.end(), std::back_inserter(*paths),
+ [](const std::pair<Glib::ustring, Glib::ustring>& pair) { return pair.second; });
}
Glib::ustring sp_shortcut_get_file_path()