From b976bd95ca0eff50a7a0f067b1a8b16c9b55e278 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Fri, 25 Dec 2020 09:15:58 +0100 Subject: [PATCH] enhanced and cleaned up OS specific path code improved mouse double click marking added file list resizing in browser dialog --- src/common/bspf.hxx | 11 +++++++++++ src/emucore/OSystem.cxx | 7 +++---- src/emucore/OSystem.hxx | 7 +++---- src/gui/BrowserDialog.cxx | 12 ++++++------ src/gui/EditableWidget.cxx | 12 ++++++------ src/gui/ListWidget.cxx | 11 +++++++++++ src/gui/ListWidget.hxx | 1 + src/libretro/OSystemLIBRETRO.cxx | 6 +++--- src/libretro/OSystemLIBRETRO.hxx | 7 +++---- src/macos/OSystemMACOS.cxx | 9 +++------ src/macos/OSystemMACOS.hxx | 7 +++---- src/unix/OSystemUNIX.cxx | 10 ++++------ src/unix/OSystemUNIX.hxx | 7 +++---- src/unix/r77/OSystemR77.cxx | 4 ++-- src/unix/r77/OSystemR77.hxx | 7 +++---- src/windows/OSystemWINDOWS.cxx | 15 +++++++++------ src/windows/OSystemWINDOWS.hxx | 7 +++---- 17 files changed, 77 insertions(+), 63 deletions(-) diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 4a17719ad..44d649869 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -336,6 +336,17 @@ namespace BSPF } #endif } + + inline bool isWhiteSpace(const char s) + { + const string WHITESPACES = " ,.;:+-*&/\\'"; + + for(size_t i = 0; i < WHITESPACES.length(); ++i) + if(s == WHITESPACES[i]) + return true; + + return false; + } } // namespace BSPF #endif diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 72ec65814..f920537b5 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -217,8 +217,8 @@ void OSystem::loadConfig(const Settings::Options& options) { // Get base directory and config file from derived class // It will decide whether it can override its default location - string baseDir, cfgFile, homeDir, unused; - getBaseDirAndConfig(baseDir, cfgFile, homeDir, unused, + string baseDir, cfgFile, homeDir; + getBaseDirAndConfig(baseDir, cfgFile, homeDir, ourOverrideBaseDirWithApp, ourOverrideBaseDir); // Get fully-qualified pathnames, and make directories when needed @@ -239,10 +239,9 @@ void OSystem::loadConfig(const Settings::Options& options) #endif mySettings->setRepository(createSettingsRepository()); - mySettings->load(options); - // TODO: check if affected by '-baseDir'and 'basedirinapp' params + // userDir is NOT affected by '-baseDir'and '-basedirinapp' params string userDir = mySettings->getString("userdir"); if(userDir.empty()) userDir = homeDir; diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 0ce5aef4b..484bf8861 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -463,8 +463,7 @@ class OSystem @param basedir The base directory for all configuration files @param cfgfile The fully qualified pathname of the config file (including the base directory) - @param savedir The default directory to save various other files - @param loaddir The default directory to load various other files + @param homedir The default directory to store various other files @param useappdir A hint that the base dir should be set to the app directory; not all ports can do this, so they are free to ignore it @@ -473,8 +472,8 @@ class OSystem they are free to ignore it */ virtual void getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) = 0; + string& homedir, + bool useappdir, const string& usedir) = 0; protected: // Pointer to the EventHandler object diff --git a/src/gui/BrowserDialog.cxx b/src/gui/BrowserDialog.cxx index d401ed8cb..d56b8558d 100644 --- a/src/gui/BrowserDialog.cxx +++ b/src/gui/BrowserDialog.cxx @@ -126,9 +126,9 @@ void BrowserDialog::show(const string& startpath, const string& ext) { const int fontWidth = _font.getMaxCharWidth(), - //fontHeight = _font.getFontHeight(), - HBORDER = fontWidth * 1.25; - //VGAP = fontHeight / 4; + fontHeight = _font.getFontHeight(), + HBORDER = fontWidth * 1.25, + VGAP = fontHeight / 4; _mode = mode; _cmd = cmd; @@ -153,7 +153,7 @@ void BrowserDialog::show(const string& startpath, _fileList->setNameFilter([ext](const FilesystemNode& node) { return BSPF::endsWithIgnoreCase(node.getName(), ext); }); - //_fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop()); + _fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop()); _currentPath->setWidth(_savePathBox->getLeft() - _currentPath->getLeft() - fontWidth); _savePathBox->setEnabled(true); @@ -172,7 +172,7 @@ void BrowserDialog::show(const string& startpath, _fileList->setNameFilter([ext](const FilesystemNode& node) { return BSPF::endsWithIgnoreCase(node.getName(), ext); }); - //_fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop()); + _fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop()); _currentPath->setWidth(_savePathBox->getLeft() - _currentPath->getLeft() - fontWidth); _savePathBox->setEnabled(true); @@ -192,7 +192,7 @@ void BrowserDialog::show(const string& startpath, _fileList->setListMode(FilesystemNode::ListMode::DirectoriesOnly); _fileList->setNameFilter([](const FilesystemNode&) { return true; }); // TODO: scrollbar affected too! - //_fileList->setHeight(_selected->getBottom() - _fileList->getTop()); + _fileList->setHeight(_selected->getBottom() - _fileList->getTop()); _currentPath->setWidth(_savePathBox->getRight() - _currentPath->getLeft()); _savePathBox->setEnabled(false); diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index 0a76bd7d1..2b37a0ba2 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -657,7 +657,7 @@ bool EditableWidget::killWord(int direction) { while(currentPos > 0) { - if(_editString[currentPos - 1] == ' ') + if(BSPF::isWhiteSpace(_editString[currentPos - 1])) { if(!space) break; @@ -673,7 +673,7 @@ bool EditableWidget::killWord(int direction) { while(currentPos < int(_editString.size())) { - if(currentPos && _editString[currentPos - 1] == ' ') + if(currentPos && BSPF::isWhiteSpace(_editString[currentPos - 1])) { if(!space) break; @@ -709,7 +709,7 @@ bool EditableWidget::moveWord(int direction, bool select) { while (currentPos > 0) { - if (_editString[currentPos - 1] == ' ') + if (BSPF::isWhiteSpace(_editString[currentPos - 1])) { if (!space) break; @@ -728,7 +728,7 @@ bool EditableWidget::moveWord(int direction, bool select) { while (currentPos < int(_editString.size())) { - if (currentPos && _editString[currentPos - 1] == ' ') + if (currentPos && BSPF::isWhiteSpace(_editString[currentPos - 1])) { if (!space) break; @@ -754,14 +754,14 @@ bool EditableWidget::markWord() while(_caretPos + _selectSize < int(_editString.size())) { - if(_editString[_caretPos + _selectSize] == ' ') + if(BSPF::isWhiteSpace(_editString[_caretPos + _selectSize])) break; _selectSize++; } while(_caretPos > 0) { - if(_editString[_caretPos - 1] == ' ') + if(BSPF::isWhiteSpace(_editString[_caretPos - 1])) break; _caretPos--; _selectSize++; diff --git a/src/gui/ListWidget.cxx b/src/gui/ListWidget.cxx index a8c0c37da..ae2551e8f 100644 --- a/src/gui/ListWidget.cxx +++ b/src/gui/ListWidget.cxx @@ -56,6 +56,17 @@ ListWidget::ListWidget(GuiObject* boss, const GUI::Font& font, _w = w - 1; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void ListWidget::setHeight(int h) +{ + Widget::setHeight(h); + if(_useScrollbar) + _scrollBar->setHeight(h); + + _rows = (h - 2) / _lineHeight; + recalc(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::setSelected(int item) { diff --git a/src/gui/ListWidget.hxx b/src/gui/ListWidget.hxx index 1fba03f01..25ea1906f 100644 --- a/src/gui/ListWidget.hxx +++ b/src/gui/ListWidget.hxx @@ -47,6 +47,7 @@ class ListWidget : public EditableWidget int rows() const { return _rows; } int currentPos() const { return _currentPos; } + void setHeight(int h) override; int getSelected() const { return _selectedItem; } void setSelected(int item); diff --git a/src/libretro/OSystemLIBRETRO.cxx b/src/libretro/OSystemLIBRETRO.cxx index 02844de63..4d1578f69 100644 --- a/src/libretro/OSystemLIBRETRO.cxx +++ b/src/libretro/OSystemLIBRETRO.cxx @@ -26,8 +26,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemLIBRETRO::getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) + string& homedir, + bool useappdir, const string& usedir) { - loaddir = savedir = cfgfile = basedir = "." + slash; + basedir = cfgfile = homedir = "." + slash; } diff --git a/src/libretro/OSystemLIBRETRO.hxx b/src/libretro/OSystemLIBRETRO.hxx index 60b1fc4e5..0fdadb8af 100644 --- a/src/libretro/OSystemLIBRETRO.hxx +++ b/src/libretro/OSystemLIBRETRO.hxx @@ -41,8 +41,7 @@ class OSystemLIBRETRO : public OSystem @param basedir The base directory for all configuration files @param cfgfile The fully qualified pathname of the config file (including the base directory) - @param savedir The default directory to save various other files - @param loaddir The default directory to load various other files + @param homedir The default directory to store various other files @param useappdir A hint that the base dir should be set to the app directory; not all ports can do this, so they are free to ignore it @@ -51,8 +50,8 @@ class OSystemLIBRETRO : public OSystem they are free to ignore it */ void getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) override; + string& homedir, + bool useappdir, const string& usedir) override; }; #endif diff --git a/src/macos/OSystemMACOS.cxx b/src/macos/OSystemMACOS.cxx index 9d933da8b..0ba22279e 100644 --- a/src/macos/OSystemMACOS.cxx +++ b/src/macos/OSystemMACOS.cxx @@ -21,8 +21,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemMACOS::getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) + string& homedir, + bool useappdir, const string& usedir) { basedir = "~/Library/Application Support/Stella/"; @@ -31,14 +31,11 @@ void OSystemMACOS::getBaseDirAndConfig(string& basedir, string& cfgfile, if(useappdir) cout << "ERROR: base dir in app folder not supported" << endl; else if(usedir != "") - { basedir = FilesystemNode(usedir).getPath(); - savedir = loaddir = basedir; - } #endif FilesystemNode desktop("~/Desktop/"); - savedir = loaddir = desktop.isDirectory() ? desktop.getShortPath() : "~/"; + homedir = desktop.isDirectory() ? desktop.getShortPath() : "~/"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/macos/OSystemMACOS.hxx b/src/macos/OSystemMACOS.hxx index 89d6638c1..1bfedb011 100644 --- a/src/macos/OSystemMACOS.hxx +++ b/src/macos/OSystemMACOS.hxx @@ -41,8 +41,7 @@ class OSystemMACOS : public OSystem @param basedir The base directory for all configuration files @param cfgfile The fully qualified pathname of the config file (including the base directory) - @param savedir The default directory to save various other files - @param loaddir The default directory to load various other files + @param homedir The default directory to store various other files @param useappdir A hint that the base dir should be set to the app directory; not all ports can do this, so they are free to ignore it @@ -51,8 +50,8 @@ class OSystemMACOS : public OSystem they are free to ignore it */ void getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) override; + string& homedir, + bool useappdir, const string& usedir) override; protected: virtual shared_ptr createSettingsRepository() override; diff --git a/src/unix/OSystemUNIX.cxx b/src/unix/OSystemUNIX.cxx index 6b6ec4df3..2156e0975 100644 --- a/src/unix/OSystemUNIX.cxx +++ b/src/unix/OSystemUNIX.cxx @@ -23,23 +23,21 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemUNIX::getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) + string& homedir, + bool useappdir, const string& usedir) { // Use XDG_CONFIG_HOME if defined, otherwise use the default string configDir = BSPF::getenv("XDG_CONFIG_HOME"); + if(configDir == EmptyString) configDir = "~/.config"; basedir = configDir + "/stella"; - savedir = loaddir = "~/"; + homedir = "~/"; // Check to see if basedir overrides are active if(useappdir) cout << "ERROR: base dir in app folder not supported" << endl; else if(usedir != "") - { basedir = FilesystemNode(usedir).getPath(); - savedir = loaddir = basedir; - } // (Currently) non-documented alternative for using version-specific // config file diff --git a/src/unix/OSystemUNIX.hxx b/src/unix/OSystemUNIX.hxx index b562a3c3d..e9309787e 100644 --- a/src/unix/OSystemUNIX.hxx +++ b/src/unix/OSystemUNIX.hxx @@ -41,8 +41,7 @@ class OSystemUNIX : public OSystem @param basedir The base directory for all configuration files @param cfgfile The fully qualified pathname of the config file (including the base directory) - @param savedir The default directory to save various other files - @param loaddir The default directory to load various other files + @param homedir The default directory to store various other files @param useappdir A hint that the base dir should be set to the app directory; not all ports can do this, so they are free to ignore it @@ -51,8 +50,8 @@ class OSystemUNIX : public OSystem they are free to ignore it */ void getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) override; + string& homedir, + bool useappdir, const string& usedir) override; private: // Following constructors and assignment operators not supported diff --git a/src/unix/r77/OSystemR77.cxx b/src/unix/r77/OSystemR77.cxx index dd692b24f..50da2b086 100644 --- a/src/unix/r77/OSystemR77.cxx +++ b/src/unix/r77/OSystemR77.cxx @@ -19,8 +19,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemR77::getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, bool, const string&) + string& homeDir, bool, const string&) { - basedir = savedir = loaddir = "/mnt/stella"; + basedir = homeDir = "/mnt/stella"; cfgfile = "/mnt/stella/stellarc"; } diff --git a/src/unix/r77/OSystemR77.hxx b/src/unix/r77/OSystemR77.hxx index 58d80d80e..fc7f4efa4 100644 --- a/src/unix/r77/OSystemR77.hxx +++ b/src/unix/r77/OSystemR77.hxx @@ -43,8 +43,7 @@ class OSystemR77 : public OSystem @param basedir The base directory for all configuration files @param cfgfile The fully qualified pathname of the config file (including the base directory) - @param savedir The default directory to save various other files - @param loaddir The default directory to load various other files + @param homedir The default directory to store various other files @param useappdir A hint that the base dir should be set to the app directory; not all ports can do this, so they are free to ignore it @@ -53,8 +52,8 @@ class OSystemR77 : public OSystem they are free to ignore it */ void getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) override; + string& homedir, + bool useappdir, const string& usedir) override; private: // Following constructors and assignment operators not supported diff --git a/src/windows/OSystemWINDOWS.cxx b/src/windows/OSystemWINDOWS.cxx index d1df4f55c..f7b6787fb 100644 --- a/src/windows/OSystemWINDOWS.cxx +++ b/src/windows/OSystemWINDOWS.cxx @@ -23,11 +23,12 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void OSystemWINDOWS::getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) + string& homedir, + bool useappdir, const string& usedir) { HomeFinder homefinder; FilesystemNode appdata(homefinder.getAppDataPath()); + if(appdata.isDirectory()) { basedir = appdata.getShortPath(); @@ -35,8 +36,9 @@ void OSystemWINDOWS::getBaseDirAndConfig(string& basedir, string& cfgfile, basedir += '\\'; basedir += "Stella\\"; } - FilesystemNode defaultLoadSaveDir(homefinder.getDesktopPath()); - savedir = loaddir = defaultLoadSaveDir.getShortPath(); + + FilesystemNode defaultHomeDir(homefinder.getDesktopPath()); + homedir = defaultHomeDir.getShortPath(); // Check to see if basedir overrides are active if(useappdir) @@ -44,12 +46,13 @@ void OSystemWINDOWS::getBaseDirAndConfig(string& basedir, string& cfgfile, char filename[MAX_PATH]; GetModuleFileNameA(NULL, filename, sizeof(filename)); FilesystemNode appdir(filename); + appdir = appdir.getParent(); if(appdir.isDirectory()) - savedir = loaddir = basedir = appdir.getPath(); + basedir = appdir.getPath(); } else if(usedir != "") - savedir = loaddir = basedir = FilesystemNode(usedir).getPath(); + basedir = FilesystemNode(usedir).getPath(); cfgfile = basedir + "stella.ini"; } diff --git a/src/windows/OSystemWINDOWS.hxx b/src/windows/OSystemWINDOWS.hxx index 4995f9f51..b938c3719 100644 --- a/src/windows/OSystemWINDOWS.hxx +++ b/src/windows/OSystemWINDOWS.hxx @@ -41,8 +41,7 @@ class OSystemWINDOWS : public OSystem @param basedir The base directory for all configuration files @param cfgfile The fully qualified pathname of the config file (including the base directory) - @param savedir The default directory to save various other files - @param loaddir The default directory to load various other files + @param homedir The default directory to store various other files @param useappdir A hint that the base dir should be set to the app directory; not all ports can do this, so they are free to ignore it @@ -51,8 +50,8 @@ class OSystemWINDOWS : public OSystem they are free to ignore it */ void getBaseDirAndConfig(string& basedir, string& cfgfile, - string& savedir, string& loaddir, - bool useappdir, const string& usedir) override; + string& homedir, + bool useappdir, const string& usedir) override; private: // Following constructors and assignment operators not supported