diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index 1243841b3..272fc396c 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -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(_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("~"); diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index be03b1e60..b59dfb041 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -99,10 +99,7 @@ class FileListWidget : public StringListWidget void reload(); /** Gets current node(s) */ - const FilesystemNode& selected() { - _selected = BSPF::clamp(_selected, 0U, static_cast(_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 myProgressDialog; + static FilesystemNode ourDefaultNode; + private: // Following constructors and assignment operators not supported FileListWidget() = delete;