MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / refresh

Method refresh

source/frontend/StarSongbookInterface.cpp:62–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void SongbookInterface::refresh(bool reloadFiles) {
63 if (reloadFiles) {
64 m_files = Root::singleton().assets()->scanExtension(".abc").values();
65 eraseWhere(m_files, [](String& song) {
66 if (!song.beginsWith(SongPathPrefix, String::CaseInsensitive)) {
67 Logger::warn("Song '{}' isn't in {}, ignoring", song, SongPathPrefix);
68 return true;
69 }
70 return false;
71 });
72 sort(m_files, [](String const& a, String const& b) -> bool { return b.compare(a, String::CaseInsensitive) > 0; });
73 }
74 auto& search = fetchChild<TextBoxWidget>("search")->getText();
75 if (m_lastSearch != search || reloadFiles) {
76 m_lastSearch = search;
77 auto songList = fetchChild<ListWidget>("songs.list");
78 songList->clear();
79 if (search.empty()) {
80 for (size_t i = 0; i != m_files.size(); ++i) {
81 auto widget = songList->addItem();
82 widget->setData(i);
83 auto songName = widget->fetchChild<LabelWidget>("songName");
84 String const& song = m_files[i];
85 songName->setText(song.substr(SongPathPrefix.size(), song.size() - (SongPathPrefix.size() + 4)));
86 widget->show();
87 }
88 } else {
89 for (size_t i = 0; i != m_files.size(); ++i) {
90 StringView song = m_files[i];
91 song = song.substr(SongPathPrefix.size(), song.size() - (SongPathPrefix.size() + 4));
92 auto find = song.find(search, 0, String::CaseInsensitive);
93 if (find != NPos) {
94 auto widget = songList->addItem();
95 widget->setData(i);
96 String text = "";
97 size_t last = 0;
98 do {
99 text += strf("^#bbb;{}^#7f7;{}", song.substr(last, find - last), song.substr(find, search.size()));
100 last = find + search.size();
101 find = song.find(search, last, String::CaseInsensitive);
102 } while (find != NPos);
103 auto songName = widget->fetchChild<LabelWidget>("songName");
104 songName->setText(text + strf("^#bbb;{}", song.substr(last)));
105 widget->show();
106 }
107 }
108 }
109 }
110}
111
112}

Callers

nothing calls this directly

Calls 15

singletonClass · 0.85
eraseWhereFunction · 0.85
strfFunction · 0.85
assetsMethod · 0.80
getTextMethod · 0.80
addItemMethod · 0.80
sortFunction · 0.50
valuesMethod · 0.45
beginsWithMethod · 0.45
compareMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected