diff --git a/src/gui/FavoritesManager.cxx b/src/gui/FavoritesManager.cxx index 117bcdb23..40b0fb925 100644 --- a/src/gui/FavoritesManager.cxx +++ b/src/gui/FavoritesManager.cxx @@ -43,8 +43,8 @@ void FavoritesManager::load() for(const auto& u : jUser) { const string& path = u.get(); - //FilesystemNode node(path); - //if(node.exists()) + FilesystemNode node(path); + if(node.exists()) addUser(path); } } @@ -60,8 +60,8 @@ void FavoritesManager::load() for(const auto& r : jRecent) { const string& path = r.get(); - //FilesystemNode node(path); - //if(node.exists()) + FilesystemNode node(path); + if(node.exists()) addRecent(path); } } @@ -77,8 +77,8 @@ void FavoritesManager::load() { const string& path = p[0].get(); const uInt32 count = p[1].get(); - //FilesystemNode node(path); - //if(node.exists()) + FilesystemNode node(path); + if(node.exists()) myPopularMap.emplace(path, count); } } diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 2a882560a..ec9b28371 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -212,6 +212,11 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, if(romWidth > 0) romWidth += HBORDER; int listWidth = _w - (romWidth > 0 ? romWidth + fontWidth : 0) - HBORDER * 2; xpos = HBORDER; ypos += lineHeight + VGAP; + + // remember initial ROM directory for returning there via home button + string romDir = getRomDir(); + instance().settings().setValue("startromdir", getRomDir()); + cerr << instance().settings().getString("romdir") << endl; myList = new LauncherFileListWidget(this, _font, xpos, ypos, listWidth, listHeight); myList->setEditable(false); myList->setListMode(FilesystemNode::ListMode::All); @@ -238,9 +243,76 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, // Add textfield to show current directory xpos = HBORDER; ypos += myList->getHeight() + VGAP; + + // Home button + static const uIntArray home_small = { + 0b0000001000000, + 0b0000011100000, + 0b0000110110000, + 0b0001101011000, + 0b0011011101100, + 0b0110111110110, + 0b1101111111011, + 0b1011111111101, + 0b0011110111100, + 0b0011100011100, + 0b0011100011100, + 0b0011100011100, + 0b0011100011100, + 0b0011100011100 + + //0b000000010000000, + //0b000000111000000, + //0b000001101100000, + //0b000011010110000, + //0b000110111011000, + //0b001101111101100, + //0b011011111110110, + //0b110111111111011, + //0b101111111111101, + //0b001111101111100, + //0b001111000111100, + //0b001111000111100, + //0b001111000111100, + //0b001111000111100, + //0b001111000111100, + }; + static const uIntArray home_large = { + 0b0000000001000000000, + 0b0000000011100000000, + 0b0000000110110000000, + 0b0000001101011000000, + 0b0000011011101100000, + 0b0000110111110110000, + 0b0001101111111011000, + 0b0011011111111101100, + 0b0110111111111110110, + 0b1101111111111111011, + 0b1001111111111111001, + 0b0001111100011111000, + 0b0001111000001111000, + 0b0001111000001111000, + 0b0001111000001111000, + 0b0001111000001111000, + 0b0001111000001111000, + 0b0001111000001111000, + 0b0001111000001111000, + 0b0001111000001111000 + }; + const bool smallIcon = lineHeight < 26; + const uIntArray* icon = smallIcon ? &home_small : &home_large; + const int iconWidth = smallIcon ? 13 : 19; + const int iconGap = fontWidth & ~0b1; // make even + + myHomeButton = new ButtonWidget(this, _font, xpos, ypos, iconWidth + iconGap, lineHeight + 2, + icon->data(), iconWidth, int(icon->size()), kHomeDirCmd); + myHomeButton->setToolTip("Go back to Stella's ROM directory."); + wid.push_back(myHomeButton); + xpos = myHomeButton->getRight() + LBL_GAP; + + // Path display lwSelect = _font.getStringWidth("Path") + LBL_GAP; - myDirLabel = new StaticTextWidget(this, _font, xpos, ypos+2, lwSelect, fontHeight, - "Path", TextAlign::Left); + myDirLabel = new StaticTextWidget(this, _font, xpos, ypos+2, lwSelect, fontHeight, "Path"); xpos += lwSelect; myDir = new EditTextWidget(this, _font, xpos, ypos, _w - xpos - HBORDER, lineHeight, ""); myDir->setEditable(false, true); @@ -374,9 +446,7 @@ void LauncherDialog::loadConfig() // Should we use a temporary directory specified on the commandline, or the // default one specified by the settings? Settings& settings = instance().settings(); - const string& tmpromdir = settings.getString("tmpromdir"); - const string& romdir = tmpromdir != "" ? tmpromdir : - settings.getString("romdir"); + const string& romdir = getRomDir(); const string& version = settings.getString("stella.version"); // Show "What's New" message when a new version of Stella is run for the first time @@ -448,6 +518,15 @@ void LauncherDialog::updateUI() loadRomInfo(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string LauncherDialog::getRomDir() +{ + Settings& settings = instance().settings(); + const string& tmpromdir = settings.getString("tmpromdir"); + + return tmpromdir != EmptyString ? tmpromdir : settings.getString("romdir"); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - size_t LauncherDialog::matchWithJoker(const string& str, const string& pattern) { @@ -845,6 +924,20 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, reload(); break; + case kHomeDirCmd: + { + if(myList->currentDir().getPath() != instance().settings().getString("startromdir")) + { + FilesystemNode node(instance().settings().getString("startromdir")); + + if(!myList->isDirectory(node)) + node = FilesystemNode("~"); + + myList->setDirectory(node); + reload(); + } + break; + } case kLoadROMCmd: if(myList->isDirectory(myList->selected())) { @@ -904,7 +997,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, case kRomDirChosenCmd: { - string romDir = instance().settings().getString("romdir"); + const string romDir = instance().settings().getString("romdir"); if(myList->currentDir().getPath() != romDir) { @@ -915,6 +1008,11 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, myList->setDirectory(node); } + if(romDir != instance().settings().getString("startromdir")) + { + instance().settings().setValue("startromdir", romDir); + reload(); + } break; } @@ -961,12 +1059,6 @@ void LauncherDialog::loadRom() instance().frameBuffer().showTextMessage(result, MessagePosition::MiddleCenter, true); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherDialog::setDefaultDir() -{ - instance().settings().setValue("romdir", myList->currentDir().getShortPath()); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::toggleShowAll() { diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index a20e10b62..135171f3f 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -51,7 +51,8 @@ class LauncherDialog : public Dialog enum { kLoadROMCmd = 'STRT', // load currently selected ROM kRomDirChosenCmd = 'romc', // ROM dir chosen - kExtChangedCmd = 'extc' // File extension display changed + kExtChangedCmd = 'extc', // File extension display changed + kHomeDirCmd = 'homc', // goto Home directory }; using FileList = std::unordered_set; @@ -114,6 +115,7 @@ class LauncherDialog : public Dialog void loadConfig() override; void saveConfig() override; void updateUI(); + string getRomDir(); /** Search if string contains pattern including wildcard '*' @@ -156,7 +158,6 @@ class LauncherDialog : public Dialog void loadRomInfo(); void handleContextMenu(); void showOnlyROMs(bool state); - void setDefaultDir(); void toggleShowAll(); void toggleSubDirs(); void toggleExtensions(); @@ -186,6 +187,7 @@ class LauncherDialog : public Dialog StaticTextWidget* myDirLabel{nullptr}; EditTextWidget* myDir{nullptr}; + ButtonWidget* myHomeButton{nullptr}; ButtonWidget* myStartButton{nullptr}; ButtonWidget* myPrevDirButton{nullptr}; ButtonWidget* myOptionsButton{nullptr}; diff --git a/src/gui/LauncherFileListWidget.cxx b/src/gui/LauncherFileListWidget.cxx index 09fca94e8..4eff53b7b 100644 --- a/src/gui/LauncherFileListWidget.cxx +++ b/src/gui/LauncherFileListWidget.cxx @@ -31,7 +31,7 @@ LauncherFileListWidget::LauncherFileListWidget(GuiObject* boss, const GUI::Font& // This widget is special, in that it catches signals and redirects them setTarget(this); myFavorites = make_unique(instance().settings()); - myRomDir = instance().settings().getString("romdir"); + myRomDir = startRomDir(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -124,15 +124,24 @@ void LauncherFileListWidget::addFolder(StringList& list, int& offset, const stri ++offset; } +string LauncherFileListWidget::startRomDir() +{ + string romDir = instance().settings().getString("startromdir"); + FilesystemNode node(romDir); + return node.getPath(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherFileListWidget::extendLists(StringList& list) { // Only show virtual dirs in "romdir". Except if // "romdir" is virtual or "romdir" is a ZIP // Then show virtual dirs in parent dir of "romdir". - if(myRomDir == instance().settings().getString("romdir") + if(myRomDir == startRomDir() && (myInVirtualDir || BSPF::endsWithIgnoreCase(_node.getPath(), ".zip"))) myRomDir = _node.getParent().getPath(); + else + myRomDir = startRomDir(); if(_node.getPath() == myRomDir) { diff --git a/src/gui/LauncherFileListWidget.hxx b/src/gui/LauncherFileListWidget.hxx index 4c70033b0..43ef6412e 100644 --- a/src/gui/LauncherFileListWidget.hxx +++ b/src/gui/LauncherFileListWidget.hxx @@ -66,6 +66,7 @@ class LauncherFileListWidget : public FileListWidget string myRomDir; private: + string startRomDir(); void getChildren(const FilesystemNode::CancelCheck& isCancelled) override; void userFavor(const string& path); void addFolder(StringList& list, int& offset, const string& name, IconType icon); diff --git a/src/gui/UIDialog.cxx b/src/gui/UIDialog.cxx index 62ac637a0..78288f77c 100644 --- a/src/gui/UIDialog.cxx +++ b/src/gui/UIDialog.cxx @@ -549,7 +549,8 @@ void UIDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) case GuiObject::kOKCmd: { bool informPath = myIsGlobal && - myRomPath->getText() != instance().settings().getString("romdir"); + (myRomPath->getText() != instance().settings().getString("romdir") + || myRomPath->getText() != instance().settings().getString("startromdir")); bool informExt = myIsGlobal && myLauncherExtensionsWidget->getState() != instance().settings().getBool("launcherextensions"); saveConfig();