mirror of https://github.com/stella-emu/stella.git
Fix crash when directory doesn't exist in BrowserWidget (fixes #888).
This commit is contained in:
parent
65f8823ba8
commit
859dfc79db
|
@ -43,13 +43,17 @@ void FileListWidget::setDirectory(const FilesystemNode& node,
|
|||
_node = node;
|
||||
|
||||
// We always want a directory listing
|
||||
if(!isDirectory(_node) && _node.hasParent())
|
||||
{
|
||||
_selectedFile = _node.getName();
|
||||
_node = _node.getParent();
|
||||
}
|
||||
else
|
||||
if(_node.isDirectory())
|
||||
_selectedFile = select;
|
||||
else
|
||||
{
|
||||
// Otherwise, keeping going up in the directory name until a valid
|
||||
// one is found
|
||||
while(!_node.isDirectory() && _node.hasParent())
|
||||
_node = _node.getParent();
|
||||
|
||||
_selectedFile = _node.getName();
|
||||
}
|
||||
|
||||
// Initialize history
|
||||
FilesystemNode tmp = _node;
|
||||
|
@ -279,6 +283,22 @@ void FileListWidget::reload()
|
|||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
const FilesystemNode& FileListWidget::selected()
|
||||
{
|
||||
if(_fileList.size() > 0)
|
||||
{
|
||||
_selected = BSPF::clamp(_selected, 0U, static_cast<uInt32>(_fileList.size()-1));
|
||||
return _fileList[_selected];
|
||||
}
|
||||
else
|
||||
{
|
||||
// This should never happen, but we'll error-check out-of-bounds
|
||||
// array access anyway
|
||||
return ourDefaultNode;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
ProgressDialog& FileListWidget::progress()
|
||||
{
|
||||
|
@ -709,3 +729,6 @@ string FileListWidget::getToolTip(const Common::Point& pos) const
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
uInt64 FileListWidget::_QUICK_SELECT_DELAY = 300;
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
FilesystemNode FileListWidget::ourDefaultNode = FilesystemNode("~");
|
||||
|
|
|
@ -99,10 +99,7 @@ class FileListWidget : public StringListWidget
|
|||
void reload();
|
||||
|
||||
/** Gets current node(s) */
|
||||
const FilesystemNode& selected() {
|
||||
_selected = BSPF::clamp(_selected, 0U, static_cast<uInt32>(_fileList.size()-1));
|
||||
return _fileList[_selected];
|
||||
}
|
||||
const FilesystemNode& selected();
|
||||
const FilesystemNode& currentDir() const { return _node; }
|
||||
|
||||
static void setQuickSelectDelay(uInt64 time) { _QUICK_SELECT_DELAY = time; }
|
||||
|
@ -115,7 +112,7 @@ class FileListWidget : public StringListWidget
|
|||
struct HistoryType
|
||||
{
|
||||
FilesystemNode node;
|
||||
string selected;
|
||||
string selected;
|
||||
|
||||
explicit HistoryType(const FilesystemNode& _hnode, const string& _hselected)
|
||||
: node{_hnode}, selected{_hselected} {}
|
||||
|
@ -190,6 +187,8 @@ class FileListWidget : public StringListWidget
|
|||
|
||||
unique_ptr<ProgressDialog> myProgressDialog;
|
||||
|
||||
static FilesystemNode ourDefaultNode;
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
FileListWidget() = delete;
|
||||
|
|
Loading…
Reference in New Issue