enhanced and cleaned up OS specific path code

improved mouse double click marking
added file list resizing in browser dialog
This commit is contained in:
thrust26 2020-12-25 09:15:58 +01:00
parent 034017923d
commit 1ca00c7a0b
17 changed files with 77 additions and 63 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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++;

View File

@ -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)
{

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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() : "~/";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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<KeyValueRepository> createSettingsRepository() override;

View File

@ -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

View File

@ -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

View File

@ -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";
}

View File

@ -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

View File

@ -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";
}

View File

@ -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