From f174c3a1a1a8a4fb611c7d3dee1fb1bd389b9d70 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 10 Sep 2022 00:55:28 +0200 Subject: [PATCH] Implement file import sorting --- gtk2_ardour/sfdb_ui.cc | 19 +++++++++++++++++++ gtk2_ardour/sfdb_ui.h | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index 477cfe45ef..5649e52ed9 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -1440,10 +1440,29 @@ SoundFileBrowser::get_paths () vector filenames = chooser.get_filenames(); vector::iterator i; + std::map im; + for (i = filenames.begin(); i != filenames.end(); ++i) { GStatBuf buf; if ((!g_stat((*i).c_str(), &buf)) && S_ISREG(buf.st_mode)) { results.push_back (*i); + im[*i] = buf.st_mtime; + } + } + if (sort_order () == FileMtime) { + results.clear (); + std::multimap im2; + std::transform (im.begin (), im.end (), + std::inserter (im2, im2.begin ()), + [](std::pairi) {return std::pair(i.second, i.first);}); + + for (auto const& i : im2) { + results.push_back (i.second); + } + } else if (sort_order () == FileName) { + results.clear (); + for (auto const& i : im) { + results.push_back (i.first); } } diff --git a/gtk2_ardour/sfdb_ui.h b/gtk2_ardour/sfdb_ui.h index 7f75e584b0..1a155acf47 100644 --- a/gtk2_ardour/sfdb_ui.h +++ b/gtk2_ardour/sfdb_ui.h @@ -272,6 +272,16 @@ protected: void on_show(); bool on_key_press_event (GdkEventKey*); virtual void do_something(int action); + + enum SortOrder { + SelectionOrder, + FileName, + FileMtime + }; + + virtual SortOrder sort_order () const { + return SelectionOrder; + } }; class SoundFileChooser : public SoundFileBrowser