diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index 73671476c..423a5c902 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -121,7 +121,6 @@ void FilesystemNode::setName(const string& name) _realNode->setName(name); } - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& FilesystemNode::getPath() const { diff --git a/src/gui/BrowserDialog.cxx b/src/gui/BrowserDialog.cxx index 701a4a5c8..c153b45bd 100644 --- a/src/gui/BrowserDialog.cxx +++ b/src/gui/BrowserDialog.cxx @@ -114,7 +114,7 @@ void BrowserDialog::show(const string& startpath, switch(_mode) { case FileLoad: - _fileList->setFileListMode(FilesystemNode::ListMode::All); + _fileList->setListMode(FilesystemNode::ListMode::All); _fileList->setFileExtension(ext); _selected->setEditable(false); _selected->clearFlags(Widget::FLAG_INVISIBLE); @@ -122,7 +122,7 @@ void BrowserDialog::show(const string& startpath, break; case FileSave: - _fileList->setFileListMode(FilesystemNode::ListMode::All); + _fileList->setListMode(FilesystemNode::ListMode::All); _fileList->setFileExtension(ext); _selected->setEditable(false); // FIXME - disable user input for now _selected->clearFlags(Widget::FLAG_INVISIBLE); @@ -130,7 +130,7 @@ void BrowserDialog::show(const string& startpath, break; case Directories: - _fileList->setFileListMode(FilesystemNode::ListMode::DirectoriesOnly); + _fileList->setListMode(FilesystemNode::ListMode::DirectoriesOnly); _selected->setEditable(false); _selected->setFlags(Widget::FLAG_INVISIBLE); _type->setFlags(Widget::FLAG_INVISIBLE); @@ -138,7 +138,7 @@ void BrowserDialog::show(const string& startpath, } // Set start path - _fileList->setLocation(FilesystemNode(startpath)); + _fileList->setDirectory(FilesystemNode(startpath)); updateUI(); @@ -193,7 +193,7 @@ void BrowserDialog::handleCommand(CommandSender* sender, int cmd, break; case kBaseDirCmd: - _fileList->setLocation(FilesystemNode(instance().baseDir())); + _fileList->setDirectory(FilesystemNode(instance().baseDir())); break; case FileListWidget::ItemChanged: diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index 451c57d5a..5b7ea922b 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -39,11 +39,11 @@ FileListWidget::FileListWidget(GuiObject* boss, const GUI::Font& font, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void FileListWidget::setLocation(const FilesystemNode& node, string select) +void FileListWidget::setDirectory(const FilesystemNode& node, string select) { _node = node; - // Generally, we always want a directory listing + // We always want a directory listing if(!_node.isDirectory() && _node.hasParent()) { select = _node.getName(); @@ -55,7 +55,7 @@ void FileListWidget::setLocation(const FilesystemNode& node, string select) _fileList.reserve(512); _node.getChildren(_fileList, _fsmode); - // Now fill the list widget with the contents of the GameList + // Now fill the list widget with the names from the file list StringList l; for(const auto& file: _fileList) l.push_back(file.getName()); @@ -66,13 +66,26 @@ void FileListWidget::setLocation(const FilesystemNode& node, string select) ListWidget::recalc(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FileListWidget::setLocation(const FilesystemNode& node, string select) +{ + setDirectory(node, select); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FileListWidget::selectParent() { if(_node.hasParent()) { - const string& curr = " [" + _node.getName() + "]"; - setLocation(_node.getParent(), curr); + // Make sure 'selected' has the proper directory naming scheme + string select = _node.getName(); + if(select.back() == '/' || select.back() == '\\') + { + select.pop_back(); + select = " [" + select + "]"; + } + + setLocation(_node.getParent(), select); } } @@ -93,8 +106,8 @@ void FileListWidget::handleCommand(CommandSender* sender, int cmd, int data, int break; case ListWidget::kSelectionChangedCmd: - cmd = ItemChanged; _selected = data; + cmd = ItemChanged; break; case ListWidget::kActivatedCmd: @@ -103,7 +116,7 @@ void FileListWidget::handleCommand(CommandSender* sender, int cmd, int data, int if(selected().isDirectory()) { cmd = ItemChanged; - setLocation(selected()); + setLocation(selected(), ""); } else cmd = ItemActivated; diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index 38c5fd6e0..aa3f26daa 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -21,6 +21,7 @@ class CommandSender; #include "FSNode.hxx" +#include "LinkedObjectPool.hxx" #include "StringListWidget.hxx" /** @@ -32,9 +33,8 @@ class CommandSender; can query the selected() and/or currentDir() methods to determine the current state. - Note that for the current implementation, the ItemActivated signal is - not sent when activating a directory (instead the code descends into - the directory). + Note that the ItemActivated signal is not sent when activating a + directory; instead the selection descends into the directory. */ class FileListWidget : public StringListWidget { @@ -50,11 +50,17 @@ class FileListWidget : public StringListWidget virtual ~FileListWidget() = default; /** Determines how to display files/folders */ - void setFileListMode(FilesystemNode::ListMode mode) { _fsmode = mode; } - void setFileExtension(const string& ext) { _extension = ext; } + void setListMode(FilesystemNode::ListMode mode) { _fsmode = mode; } + void setFileExtension(const string& ext) { _extension = ext; } // TODO - re-implement this - /** Set current location (file or directory) */ - void setLocation(const FilesystemNode& node, string select = ""); + /** + Set initial directory, and optionally select the given item. + + @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) + */ + void setDirectory(const FilesystemNode& node, string select = ""); /** Select parent directory (if applicable) */ void selectParent(); @@ -67,6 +73,9 @@ class FileListWidget : public StringListWidget const FilesystemNode& currentDir() const { return _node; } private: + /** Very similar to setDirectory(), but also updates the history */ + void setLocation(const FilesystemNode& node, string select); + void handleCommand(CommandSender* sender, int cmd, int data, int id) override; private: @@ -74,6 +83,8 @@ class FileListWidget : public StringListWidget FilesystemNode _node; FSList _fileList; + Common::LinkedObjectPool _history; + string _extension; uInt32 _selected; diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index b90d8c99a..3e81fb64d 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -49,6 +49,34 @@ - connect to 'matchPattern' - create lambda filter to pass these to FileListWidget */ +#if 0 + // TODO - rough contents of lambda filter + FSList files; + files.reserve(2048); + myCurrentNode.getChildren(files, FilesystemNode::ListMode::All); + + // Add '[..]' to indicate previous folder + if(myCurrentNode.hasParent()) + myGameList->appendGame(" [..]", "", "", true); + + // Now add the directory entries + bool domatch = myPattern && myPattern->getText() != ""; + for(const auto& f: files) + { + bool isDir = f.isDirectory(); + const string& name = isDir ? (" [" + f.getName() + "]") : f.getName(); + + // Do we want to show only ROMs or all files? + if(!isDir && myShowOnlyROMs && !Bankswitch::isValidRomName(f)) + continue; + + // Skip over files that don't match the pattern in the 'pattern' textbox + if(domatch && !isDir && !matchPattern(name, myPattern->getText())) + continue; + + myGameList->appendGame(name, f.getPath(), "", isDir); + } +#endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, @@ -151,7 +179,7 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, myList = new FileListWidget(this, font, xpos, ypos, listWidth, _h - 43 - bheight - fontHeight - lineHeight); myList->setEditable(false); - myList->setFileListMode(FilesystemNode::ListMode::All); + myList->setListMode(FilesystemNode::ListMode::All); wid.push_back(myList); // Add ROM info area (if enabled) @@ -292,8 +320,8 @@ void LauncherDialog::loadConfig() if(!(node.exists() && node.isDirectory())) node = FilesystemNode("~"); - myList->setLocation(node); - updateUI(instance().settings().getString("lastrom")); + myList->setDirectory(node, instance().settings().getString("lastrom")); + updateUI(); } Dialog::setFocus(getFocusList()[mySelectedItem]); @@ -302,7 +330,7 @@ void LauncherDialog::loadConfig() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherDialog::updateUI(const string& nameToSelect) +void LauncherDialog::updateUI() { // Only hilite the 'up' button if there's a parent directory if(myPrevDirButton) @@ -316,86 +344,10 @@ void LauncherDialog::updateUI(const string& nameToSelect) buf << (myList->getList().size() - 1) << " items found"; myRomCount->setLabel(buf.str()); - // Restore last selection - if(nameToSelect != "") - myList->setSelected(nameToSelect); - // Update ROM info UI item loadRomInfo(); } -#if 0 -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherDialog::updateListing(const string& nameToSelect) -{ - // Start with empty list - myGameList->clear(); - myDir->setText(""); - - loadDirListing(); - - // Only hilite the 'up' button if there's a parent directory - if(myPrevDirButton) - myPrevDirButton->setEnabled(myCurrentNode.hasParent()); - - // Show current directory - myDir->setText(myCurrentNode.getShortPath()); - - // Now fill the list widget with the contents of the GameList - StringList l; - for(uInt32 i = 0; i < myGameList->size(); ++i) - l.push_back(myGameList->name(i)); - - myList->setList(l); - - // Indicate how many files were found - ostringstream buf; - buf << (myGameList->size() - 1) << " items found"; - myRomCount->setLabel(buf.str()); - - // Restore last selection - const string& find = - nameToSelect == "" ? instance().settings().getString("lastrom") : nameToSelect; - myList->setSelected(find); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherDialog::loadDirListing() -{ - if(!myCurrentNode.isDirectory()) - return; - - FSList files; - files.reserve(2048); - myCurrentNode.getChildren(files, FilesystemNode::ListMode::All); - - // Add '[..]' to indicate previous folder - if(myCurrentNode.hasParent()) - myGameList->appendGame(" [..]", "", "", true); - - // Now add the directory entries - bool domatch = myPattern && myPattern->getText() != ""; - for(const auto& f: files) - { - bool isDir = f.isDirectory(); - const string& name = isDir ? (" [" + f.getName() + "]") : f.getName(); - - // Do we want to show only ROMs or all files? - if(!isDir && myShowOnlyROMs && !Bankswitch::isValidRomName(f)) - continue; - - // Skip over files that don't match the pattern in the 'pattern' textbox - if(domatch && !isDir && !matchPattern(name, myPattern->getText())) - continue; - - myGameList->appendGame(name, f.getPath(), "", isDir); - } - - // Sort the list by rom name (since that's what we see in the listview) - myGameList->sortByName(); -} -#endif - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::loadRomInfo() { @@ -580,13 +532,8 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, case kLoadROMCmd: case FileListWidget::ItemActivated: - { - if(currentNode().isDirectory()) - myList->setLocation(currentNode()); - else - loadRom(); + loadRom(); break; - } case kOptionsCmd: openSettings(); @@ -610,7 +557,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, FilesystemNode node(instance().settings().getString("romdir")); if(!(node.exists() && node.isDirectory())) node = FilesystemNode("~"); - myList->setLocation(node); + myList->setDirectory(node); break; } diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index 8942805c2..91b2c4fbb 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -95,7 +95,7 @@ class LauncherDialog : public Dialog Event::Type getJoyAxisEvent(int stick, int axis, int value) override; void loadConfig() override; - void updateUI(const string& nameToSelect = ""); + void updateUI(); void loadRom(); void loadRomInfo(); diff --git a/src/gui/RomAuditDialog.cxx b/src/gui/RomAuditDialog.cxx index 6155ce61e..c62176f0f 100644 --- a/src/gui/RomAuditDialog.cxx +++ b/src/gui/RomAuditDialog.cxx @@ -126,7 +126,6 @@ void RomAuditDialog::auditRoms() "Auditing ROM files ..."); progress.setRange(0, int(files.size()) - 1, 5); - // Create a entry for the GameList for each file Properties props; int renamed = 0, notfound = 0; for(uInt32 idx = 0; idx < files.size(); ++idx)