From 9274a72d5156eebbe2d489e6712498ae936312c3 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 24 Nov 2020 12:50:43 +0100 Subject: [PATCH] added path info to launcher tooltips when displaying sub directories fixed launcher files list when filtering was canceled added persisting 'incl. subdirectories' setting --- src/emucore/FBSurface.cxx | 2 +- src/emucore/Settings.cxx | 2 ++ src/gui/FileListWidget.cxx | 48 +++++++++++++++++++++++++++++------- src/gui/FileListWidget.hxx | 5 ++++ src/gui/LauncherDialog.cxx | 28 +++++++++++---------- src/gui/StringListWidget.hxx | 4 +-- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/src/emucore/FBSurface.cxx b/src/emucore/FBSurface.cxx index bd7a3ad7b..16030b579 100644 --- a/src/emucore/FBSurface.cxx +++ b/src/emucore/FBSurface.cxx @@ -336,7 +336,7 @@ void FBSurface::splitString(const GUI::Font& font, const string& s, int w, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool FBSurface::isWhiteSpace(const char s) const { - const string WHITESPACES = " ,.;:+-*/'([\n"; + const string WHITESPACES = " ,.;:+-*/\\'([\n"; for(size_t i = 0; i < WHITESPACES.length(); ++i) if(s == WHITESPACES[i]) diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index f7fa27ae8..a074f5697 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -145,6 +145,7 @@ Settings::Settings() setPermanent("launcherres", Common::Size(900, 600)); setPermanent("launcherfont", "medium"); setPermanent("launcherroms", "true"); + setPermanent("launchersubdirs", "false"); setPermanent("romviewer", "1"); setPermanent("lastrom", ""); @@ -542,6 +543,7 @@ void Settings::usage() const << " large12|large14|\n" << " large16>\n" << " -launcherroms <1|0> Show only ROMs in the launcher (vs. all files)\n" + << " -launchersubdirs <1|0> Show files from subdirectories too\n" << " -romviewer Show ROM info viewer at given zoom level in ROM\n" << " launcher (use 0 for off)\n" << " -followlauncher <0|1> Default ROM path follows launcher navigation\n" diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index c0a889f1b..6aaa9be1c 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -75,7 +75,7 @@ void FileListWidget::setLocation(const FilesystemNode& node, { progress().resetProgress(); progress().open(); - FilesystemNode::CancelCheck isCancelled = []() { + class FilesystemNode::CancelCheck isCancelled = []() { return myProgressDialog->isCancelled(); }; @@ -96,17 +96,26 @@ void FileListWidget::setLocation(const FilesystemNode& node, _node.getChildren(_fileList, _fsmode, _filter, false, true, isCancelled); } - if(!isCancelled()) - { - // Now fill the list widget with the names from the file list - StringList l; - for(const auto& file : _fileList) - l.push_back(file.getName()); + // Now fill the list widget with the names from the file list, + // even if cancelled + StringList l; + size_t orgLen = node.getShortPath().length(); - setList(l); - setSelected(select); + _dirList.clear(); + for(const auto& file : _fileList) + { + const string path = file.getShortPath(); + + l.push_back(file.getName()); + // display only relative path in tooltip + if(path.length() >= orgLen) + _dirList.push_back(path.substr(orgLen)); + else + _dirList.push_back(path); } + setList(l); + setSelected(select); ListWidget::recalc(); progress().close(); @@ -237,6 +246,27 @@ void FileListWidget::handleCommand(CommandSender* sender, int cmd, int data, int setTarget(this); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string FileListWidget::getToolTip(const Common::Point& pos) const +{ + Common::Rect rect = getEditRect(); + int idx = getToolTipIndex(pos); + + if(idx < 0) + return EmptyString; + + if(_includeSubDirs && _dirList.size() > idx) + return _toolTipText + _dirList[idx]; + + const string value = _list[idx]; + + if(uInt32(_font.getStringWidth(value)) > rect.w()) + return _toolTipText + value; + else + return _toolTipText; +} + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt64 FileListWidget::_QUICK_SELECT_DELAY = 300; diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index 63c39136f..088ed56b3 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -53,6 +53,8 @@ class FileListWidget : public StringListWidget int x, int y, int w, int h); ~FileListWidget() override = default; + string getToolTip(const Common::Point& pos) const override; + /** Determines how to display files/folders; either setDirectory or reload must be called after any of these are called. */ void setListMode(FilesystemNode::ListMode mode) { _fsmode = mode; } @@ -69,6 +71,7 @@ class FileListWidget : public StringListWidget @param node The directory to display. If this is a file, its parent will instead be used, and the file will be selected @param select An optional entry to select (if applicable) + @param recursive Recursively list sub-directories too */ void setDirectory(const FilesystemNode& node, const string& select = EmptyString); @@ -112,6 +115,8 @@ class FileListWidget : public StringListWidget FSList _fileList; bool _includeSubDirs{false}; + StringList _dirList; + Common::FixedStack _history; uInt32 _selected{0}; string _selectedFile; diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 87d0938b4..ca4101601 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -15,9 +15,6 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -// TODO: -// - abort current file list reload when typing - #include "bspf.hxx" #include "Bankswitch.hxx" #include "BrowserDialog.hxx" @@ -90,10 +87,10 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, int lwSelect = font.getStringWidth(lblSelect); int cwAllFiles = font.getStringWidth(lblAllFiles) + CheckboxWidget::prefixSize(font); - int lwFilter = font.getStringWidth(lblFilter); int cwSubDirs = font.getStringWidth(lblSubDirs) + CheckboxWidget::prefixSize(font); + int lwFilter = font.getStringWidth(lblFilter); int lwFound = font.getStringWidth(lblFound); - int wTotal = HBORDER * 2 + lwSelect + cwAllFiles + lwFilter + cwSubDirs + lwFound + int wTotal = HBORDER * 2 + lwSelect + cwAllFiles + cwSubDirs + lwFilter + lwFound + EditTextWidget::calcWidth(font, "123456") + LBL_GAP * 7; bool noSelect = false; @@ -174,13 +171,6 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, xpos - cwSubDirs - lwFilter - cwAllFiles - lwSelect - HBORDER - LBL_GAP * (noSelect ? 5 : 7)); - // Show the subdirectories checkbox - xpos -= cwSubDirs + LBL_GAP; - mySubDirs = new CheckboxWidget(this, font, xpos, ypos, lblSubDirs, kSubDirsCmd); - ostringstream tip; - tip << "Search files in subdirectories too."; - mySubDirs->setToolTip(tip.str()); - // Show the filter input field xpos -= fwFilter + LBL_GAP; myPattern = new EditTextWidget(this, font, xpos, ypos - 2, fwFilter, lineHeight, ""); @@ -191,11 +181,18 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, xpos -= lwFilter + LBL_GAP; new StaticTextWidget(this, font, xpos, ypos, lblFilter); + // Show the subdirectories checkbox + xpos -= cwSubDirs + LBL_GAP * 2; + mySubDirs = new CheckboxWidget(this, font, xpos, ypos, lblSubDirs, kSubDirsCmd); + ostringstream tip; + tip << "Search files in subdirectories too."; + mySubDirs->setToolTip(tip.str()); + // Show the checkbox for all files if(noSelect) xpos = HBORDER; else - xpos -= cwAllFiles + LBL_GAP * 2; + xpos -= cwAllFiles + LBL_GAP; myAllFiles = new CheckboxWidget(this, font, xpos, ypos, lblAllFiles, kAllfilesCmd); myAllFiles->setToolTip("Uncheck to show ROM files only."); @@ -386,6 +383,10 @@ void LauncherDialog::loadConfig() instance().settings().setValue("stella.version", STELLA_VERSION); } + bool subDirs = instance().settings().getBool("launchersubdirs"); + mySubDirs->setState(subDirs); + myList->setIncludeSubDirs(subDirs); + // Assume that if the list is empty, this is the first time that loadConfig() // has been called (and we should reload the list) if(myList->getList().empty()) @@ -408,6 +409,7 @@ void LauncherDialog::loadConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::saveConfig() { + instance().settings().setValue("launchersubdirs", mySubDirs->getState()); if(instance().settings().getBool("followlauncher")) instance().settings().setValue("romdir", myList->currentDir().getShortPath()); } diff --git a/src/gui/StringListWidget.hxx b/src/gui/StringListWidget.hxx index f0bf8544b..668414c4c 100644 --- a/src/gui/StringListWidget.hxx +++ b/src/gui/StringListWidget.hxx @@ -41,6 +41,7 @@ class StringListWidget : public ListWidget void lostFocusWidget() override { setDirty(); } bool hasToolTip() const override { return true; } + int getToolTipIndex(const Common::Point& pos) const; void drawWidget(bool hilite) override; Common::Rect getEditRect() const override; @@ -49,9 +50,6 @@ class StringListWidget : public ListWidget bool _hilite{false}; int _textOfs{0}; - private: - int getToolTipIndex(const Common::Point& pos) const; - private: // Following constructors and assignment operators not supported StringListWidget() = delete;