28 std::vector<std::pair<std::string, Glib::ustring>> output;
30 auto recent_manager = Gtk::RecentManager::get_default();
32 auto recent_files = recent_manager->get_items();
35 std::erase_if(recent_files, [](
auto const &recent_file) ->
bool {
38 recent_file->has_application(g_get_prgname()) ||
39 recent_file->has_application(
"org.inkscape.Inkscape") ||
40 recent_file->has_application(
"inkscape") ||
41 recent_file->has_application(
"inkscape.exe");
50 auto sort_comparator_uri =
51 [](
auto const a,
auto const b) ->
bool {
return a->get_uri_display() < b->get_uri_display(); };
52 std::sort (recent_files.begin(), recent_files.end(), sort_comparator_uri);
54 auto unique_comparator_uri =
55 [](
auto const a,
auto const b) ->
bool {
return a->get_uri_display() == b->get_uri_display(); };
56 auto it_u = std::unique (recent_files.begin(), recent_files.end(), unique_comparator_uri);
57 recent_files.erase(it_u, recent_files.end());
60 std::sort(std::begin(recent_files), std::end(recent_files), [](
auto const &a,
auto const &b) ->
bool {
62 return a->get_modified().compare(b->get_modified()) > 0;
66 if (max_files && recent_files.size() > max_files) {
67 recent_files.resize(max_files);
77std::map<Glib::ustring, std::string>
getShortenedPathMap(std::vector<Glib::RefPtr<Gtk::RecentInfo>>
const &recent_files)
80 std::map<Glib::ustring, std::string> shortened_path_map;
81 std::vector<Glib::RefPtr<Gtk::RecentInfo>> copy = recent_files;
82 for (
auto recent_file : copy) {
83 shortened_path_map[recent_file->get_uri_display()] = recent_file->get_display_name();
87 auto equal_comparator = [](
auto const a,
auto const b) ->
bool {
return a->get_display_name() == b->get_display_name(); };
88 auto it = copy.begin();
90 while (it != (copy.end() - 1)) {
91 it = std::adjacent_find(it, copy.end(), equal_comparator);
92 if (it != copy.end()) {
95 std::vector<Glib::ustring> display_uris;
96 display_uris.emplace_back(( * it )->get_uri_display());
97 display_uris.emplace_back(( *(it+1))->get_uri_display());
99 std::vector<std::vector<std::string>> path_parts;
104 auto max_size = std::min(path_parts[0].
size(), path_parts[1].
size());
106 for (; i < max_size; ++i) {
107 if (path_parts[0][i] != path_parts[1][i]) {
111 assert(i < max_size);
114 for (
int j = 0; j < 2; j++) {
116 auto display_uri = display_uris[j];
118 auto size = path_parts[j].size();
122 shortened_path_map[display_uri] = display_uri;
123 }
else if (i ==
size - 1) {
125 shortened_path_map[display_uri] = path_parts[j].back();
126 }
else if (i ==
size - 2) {
129 shortened_path_map[display_uri] =
130 Glib::ustring::compose (
"..%1%2%3%4",
132 path_parts[j][
size-2],
134 path_parts[j][
size-1]);
137 shortened_path_map[display_uri] =
138 Glib::ustring::compose (
"%1%2%3..%4%5",
143 path_parts[j][
size-1]);
145 shortened_path_map[display_uri] =
146 Glib::ustring::compose (
"..%1%2%3..%4%5",
151 path_parts[j][
size-1]);
163 return shortened_path_map;