From 972cd587f76db4fcb327b26ed9356a18fea336c9 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 9 Apr 2020 20:09:24 -0400 Subject: [PATCH] Don't display "1_", "42_", "001_", etc at the beginning of preset filenames. --- include/system.hpp | 4 +++- src/app/ModuleWidget.cpp | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/system.hpp b/include/system.hpp index 94fbaec2..155a4018 100644 --- a/include/system.hpp +++ b/include/system.hpp @@ -12,7 +12,9 @@ namespace rack { namespace system { -/** Returns a list of all entries (directories, files, symbols) in a directory. */ +/** Returns a list of all entries (directories, files, symbols) in a directory. +Sorted alphabetically. +*/ std::list getEntries(const std::string& path); std::list getEntriesRecursive(const std::string &path, int depth); /** Returns whether the given path is a file. */ diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 1451905b..b0a4d569 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -243,8 +244,13 @@ struct ModulePresetItem : ui::MenuItem { continue; hasPresets = true; + std::string presetName = string::filenameBase(presetFilename); + // Remove "1_", "42_", "001_", etc at the beginning of preset filenames + std::regex r("^\\d*_"); + presetName = std::regex_replace(presetName, r, ""); + ModulePresetPathItem* presetItem = new ModulePresetPathItem; - presetItem->text = string::filenameBase(presetFilename); + presetItem->text = presetName; presetItem->presetPath = presetPath; presetItem->moduleWidget = moduleWidget; menu->addChild(presetItem);