MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / InitializeMenu

Function InitializeMenu

Applications/Shell/menu.cpp:176–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176void InitializeMenu(){
177 syscall(SYS_GET_VIDEO_MODE, (uintptr_t)&videoInfo,0,0,0,0);
178 menuWindow = new Lemon::GUI::Window("", {240, 300}, WINDOW_FLAGS_NODECORATION | WINDOW_FLAGS_NOSHELL, Lemon::GUI::WindowType::GUI, {0, static_cast<int>(videoInfo.height) - 32 - 300});
179 menuWindow->OnPaint = OnPaint;
180 menuWindow->rootContainer.background = {0, 0, 0, 0};
181
182 categories["Games"] = MenuCategory("Games");
183 categories["Utilities"] = MenuCategory("Utilities");
184 categories["Other"] = MenuCategory("Other");
185
186 {
187 MenuItem item("Terminal...", "Open a Terminal", "terminal.lef", GetItemID());
188 items[item.id] = item;
189 rootItems.push_back(item);
190 }
191
192 {
193 MenuItem item("Run...", "Run", "run.lef", GetItemID());
194 items[item.id] = item;
195 rootItems.push_back(item);
196 }
197
198 int itemsDir = open(itemsPath, O_DIRECTORY);
199 if(itemsDir >= 0){
200 struct dirent** entries = nullptr;
201 int entryCount = scandir(itemsPath, &entries, static_cast<int(*)(const dirent*)>([](const dirent* d) -> int { return strcmp(d->d_name, "..") && strcmp(d->d_name, "."); }), static_cast<int(*)(const dirent**, const dirent**)>([](const dirent** a, const dirent**b) { return strcmp((*a)->d_name, (*b)->d_name); }));
202
203 for(int i = 0; i < entryCount; i++){
204 char* entryPath = new char[strlen(itemsPath) + strlen(entries[i]->d_name) + 1];
205 strcpy(entryPath, itemsPath);
206 strcat(entryPath, entries[i]->d_name);
207
208 CFGParser itemCParser = CFGParser(entryPath);
209 itemCParser.Parse();
210 for(auto& heading : itemCParser.GetItems()){
211 if(!heading.first.compare("Item")){
212 MenuItem item;
213 std::string categoryName;
214 MenuCategory* cat;
215
216 for(auto& cItem : heading.second){
217 if(!cItem.name.compare("name")){
218 item.name = cItem.value;
219 } else if(!cItem.name.compare("comment")){
220 item.comment = cItem.value;
221 } else if(!cItem.name.compare("exec")){
222 item.SetExec(cItem.value);
223 } else if(!cItem.name.compare("categories")){
224 categoryName = cItem.value;
225 }
226 }
227
228 if(!item.name.length() || !item.GetExec().length()){
229 continue; // Zero length name or path
230 }
231 item.id = GetItemID();
232
233 if(!categoryName.length()){

Callers 1

mainFunction · 0.85

Calls 13

MenuCategoryClass · 0.85
GetItemIDFunction · 0.85
strcmpFunction · 0.85
strlenFunction · 0.85
strcpyFunction · 0.85
strcatFunction · 0.85
CFGParserClass · 0.85
SetExecMethod · 0.80
lengthMethod · 0.80
SetLayoutMethod · 0.80
ParseMethod · 0.45
AddWidgetMethod · 0.45

Tested by

no test coverage detected