Skip to content

Commit 8439038

Browse files
committed
feat(UI): hide macro ordering prefix [closes #96]
1 parent ccdc7e5 commit 8439038

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/UI/Screens/File/FilePresenter.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,33 @@
99
#include "UI/Screens/Home/HomeView.h"
1010
#include "i18n/i18n.h"
1111
#include "utils/StorageHelper.h"
12+
#include <cctype>
1213

1314
namespace UI
1415
{
1516
static std::string s_emptyStr = "";
1617

18+
static std::string_view stripMacroDisplayPrefix(std::string_view name)
19+
{
20+
if (name.empty() || !std::isdigit(static_cast<unsigned char>(name.front())))
21+
{
22+
return name;
23+
}
24+
25+
size_t prefixEnd = 0;
26+
while (prefixEnd < name.size() && std::isdigit(static_cast<unsigned char>(name[prefixEnd])))
27+
{
28+
prefixEnd++;
29+
}
30+
31+
if (prefixEnd == 0 || prefixEnd >= name.size() || name[prefixEnd] != '_')
32+
{
33+
return name;
34+
}
35+
36+
return name.substr(prefixEnd + 1);
37+
}
38+
1739
static OM::Directories::DirectoryType getBaseFolderType(FilePresenter::BaseFolder folder)
1840
{
1941
ZoneScoped;
@@ -29,6 +51,16 @@ namespace UI
2951
}
3052
}
3153

54+
std::string_view FilePresenter::getDisplayName(std::string_view name, BaseFolder baseFolder)
55+
{
56+
if (baseFolder != BaseFolder::MACROS)
57+
{
58+
return name;
59+
}
60+
61+
return stripMacroDisplayPrefix(name);
62+
}
63+
3264
std::string_view FilePresenter::getBaseFolderPath() const
3365
{
3466
ZoneScoped;
@@ -131,7 +163,7 @@ namespace UI
131163
}
132164
else if (m_gcodePath.starts_with(OM::Directories::GetMacrosDirectory()))
133165
{
134-
m_view->confirmRunMacro(item->GetName().c_str());
166+
m_view->confirmRunMacro(getDisplayName(item->GetName(), m_baseFolder));
135167
}
136168
}
137169

@@ -187,7 +219,7 @@ namespace UI
187219
continue;
188220
}
189221

190-
item->m_filename = file->GetName();
222+
item->m_filename = getDisplayName(file->GetName(), m_baseFolder);
191223
item->m_date = file->GetDate();
192224
#if SHOW_FILE_ITEM_SIZE
193225
item->m_size = file->GetReadableSize();

src/UI/Screens/File/FilePresenter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace UI
2121

2222
// Actions
2323
void setBaseFolder(BaseFolder folder) { m_baseFolder = folder; }
24+
static std::string_view getDisplayName(std::string_view name, BaseFolder baseFolder);
2425
std::string_view getBaseFolderPath() const;
2526
void setFolder(std::string_view folder);
2627
void itemClicked(const size_t index);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* test_fileview.cpp
3+
*
4+
* Created on: 2026-03-12
5+
* Author: Andy Everitt
6+
*/
7+
8+
#include "Debug.h"
9+
#include "UI/Screens/File/FileView.h"
10+
#include "test_utils/UiTestSuite.h"
11+
#include <gtest/gtest.h>
12+
13+
using namespace UI;
14+
15+
class TestFilePresenter : public TestSuite
16+
{
17+
public:
18+
TestFilePresenter() {}
19+
};
20+
21+
TEST(TestFilePresenter, MacroDisplayNameRemovesNumericPrefix)
22+
{
23+
EXPECT_EQ(FilePresenter::getDisplayName("12_Preheat.g", FilePresenter::BaseFolder::MACROS), "Preheat.g");
24+
EXPECT_EQ(FilePresenter::getDisplayName("001_Home All.g", FilePresenter::BaseFolder::MACROS), "Home All.g");
25+
EXPECT_EQ(FilePresenter::getDisplayName("Preheat.g", FilePresenter::BaseFolder::MACROS), "Preheat.g");
26+
EXPECT_EQ(FilePresenter::getDisplayName("12Preheat.g", FilePresenter::BaseFolder::MACROS), "12Preheat.g");
27+
EXPECT_EQ(FilePresenter::getDisplayName("12_Preheat.g", FilePresenter::BaseFolder::GCODES), "12_Preheat.g");
28+
}

0 commit comments

Comments
 (0)