From 8537a3f7e406a5fea1d56d44c990ef76514a5199 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Sat, 11 Dec 2021 23:26:21 +0100 Subject: [PATCH] refactored new launcher code a bit --- docs/index.html | 19 ++++++++++++++++-- src/gui/FileListWidget.cxx | 35 ++++++++++++++++++++------------- src/gui/FileListWidget.hxx | 10 ++++++++-- src/gui/LauncherDialog.cxx | 40 +++++++++++++++----------------------- src/gui/LauncherDialog.hxx | 5 ----- 5 files changed, 63 insertions(+), 46 deletions(-) diff --git a/docs/index.html b/docs/index.html index a13b137d8..c9d7a2553 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2267,8 +2267,23 @@ Go to parent directory (also in other file dialogs) - Backspace - Backspace + Backspace, Alt + Up arrow + Backspace, Alt + Up arrow + + + Go to home directory + Alt + Home + Alt + Home + + + Go to previous directory in history + Alt + Left arrow + Alt + Left arrow + + + Go to next directory in history + Alt + Right arrow + Alt + Right arrow Remove from 'Recently Played' or 'Most Popular' folder diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index 954276580..efe911870 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -58,14 +58,9 @@ void FileListWidget::setDirectory(const FilesystemNode& node, _history.clear(); while(tmp.hasParent()) { - if(name.back() == FilesystemNode::PATH_SEPARATOR) - name.pop_back(); - _history.push_back(HistoryType(tmp, name)); + _history.push_back(HistoryType(tmp, fixPath(name))); name = tmp.getName(); - if(name.back() == FilesystemNode::PATH_SEPARATOR) - name.pop_back(); - tmp = tmp.getParent(); } // History is in reverse order; we need to fix that @@ -191,14 +186,19 @@ void FileListWidget::selectParent() string name = _node.getName(); FilesystemNode parent(_node.getParent()); - if(name.back() == FilesystemNode::PATH_SEPARATOR) - name.pop_back(); _currentHistory->selected = selected().getName(); addHistory(parent); - setLocation(parent, name); + setLocation(parent, fixPath(name)); } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FileListWidget::selectHomeDir() +{ + while(hasPrevHistory()) + selectPrevHistory(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FileListWidget::selectPrevHistory() { @@ -233,6 +233,17 @@ bool FileListWidget::hasNextHistory() return _currentHistory != std::prev(_history.end(), 1); } +string& FileListWidget::fixPath(string& path) +{ + if(path.back() == FilesystemNode::PATH_SEPARATOR) + { + path.pop_back(); + if(path.length() == 2 && path.back() == ':') + path.pop_back(); + } + return path; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FileListWidget::addHistory(const FilesystemNode& node) { @@ -241,11 +252,9 @@ void FileListWidget::addHistory(const FilesystemNode& node) _history.pop_back(); string select = selected().getName(); - if(select.back() == FilesystemNode::PATH_SEPARATOR) - select.pop_back(); - _currentHistory->selected = select; + _currentHistory->selected = fixPath(select); - _history.push_back(HistoryType(node, select)); + _history.push_back(HistoryType(node, "..")); _currentHistory = std::prev(_history.end(), 1); //_historyIndex++; } diff --git a/src/gui/FileListWidget.hxx b/src/gui/FileListWidget.hxx index 2c27507c7..f5047253a 100644 --- a/src/gui/FileListWidget.hxx +++ b/src/gui/FileListWidget.hxx @@ -45,7 +45,10 @@ class FileListWidget : public StringListWidget public: enum { ItemChanged = 'FLic', // Entry in the list is changed (single-click, etc) - ItemActivated = 'FLac' // Entry in the list is activated (double-click, etc) + ItemActivated = 'FLac', // Entry in the list is activated (double-click, etc) + kHomeDirCmd = 'homc', // go to Home directory + kPrevDirCmd = 'prvc', // go back in history to previous directory + kNextDirCmd = 'nxtc' // go back in history to next directory }; using IconTypeFilter = std::function; @@ -83,9 +86,11 @@ class FileListWidget : public StringListWidget virtual void selectDirectory(); /** Select parent directory (if applicable) */ void selectParent(); + /** Select to home directory */ + void selectHomeDir(); /** Select previous directory in history (if applicable) */ void selectPrevHistory(); - /** Select next directory in history */ + /** Select next directory in history (if applicable) */ void selectNextHistory(); /** Check if the there is a previous directory in history */ bool hasPrevHistory(); @@ -147,6 +152,7 @@ class FileListWidget : public StringListWidget virtual const Icon* getIcon(int i) const; int iconWidth() const; virtual bool fullPathToolTip() const { return false; } + string& fixPath(string& path); void addHistory(const FilesystemNode& node); protected: diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 3425a548e..ed8da8231 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -228,25 +228,25 @@ void LauncherDialog::addPathWidgets(int& ypos, WidgetArray& wid) const GUI::Icon& upIcon = smallIcon ? GUI::icon_up_small : GUI::icon_up_large; myHomeButton = new ButtonWidget(this, _font, xpos, ypos, - iconWidth + iconGap - 1, lineHeight + 2, homeIcon, kHomeDirCmd); + iconWidth + iconGap - 1, lineHeight + 2, homeIcon, FileListWidget::kHomeDirCmd); myHomeButton->setToolTip("Go back to Stella's ROM directory."); wid.push_back(myHomeButton); xpos = myHomeButton->getRight() + BTN_GAP; myPrevButton = new ButtonWidget(this, _font, xpos, ypos, - iconWidth + iconGap - 1, lineHeight + 2, prevIcon, kPrevDirCmd); + iconWidth + iconGap - 1, lineHeight + 2, prevIcon, FileListWidget::kPrevDirCmd); myPrevButton->setToolTip("Go back in directory history."); wid.push_back(myPrevButton); xpos = myPrevButton->getRight() + BTN_GAP; myNextButton = new ButtonWidget(this, _font, xpos, ypos, - iconWidth + iconGap - 1, lineHeight + 2, nextIcon, kNextDirCmd); + iconWidth + iconGap - 1, lineHeight + 2, nextIcon, FileListWidget::kNextDirCmd); myNextButton->setToolTip("Go forward in directory history."); wid.push_back(myNextButton); xpos = myNextButton->getRight() + BTN_GAP; myUpButton = new ButtonWidget(this, _font, xpos, ypos, - iconWidth + iconGap - 1, lineHeight + 2, upIcon, kParentDirCmd); + iconWidth + iconGap - 1, lineHeight + 2, upIcon, ListWidget::kParentDirCmd); myUpButton->setToolTip("Go Up"); wid.push_back(myUpButton); xpos = myUpButton->getRight() + BTN_GAP; @@ -358,7 +358,7 @@ void LauncherDialog::addButtonWidgets(int& ypos, WidgetArray& wid) xpos += (buttonWidth + 0) / 4 + BUTTON_GAP; myGoUpButton = new ButtonWidget(this, _font, xpos, ypos, (buttonWidth + 1) / 4, buttonHeight, - "Go Up", kParentDirCmd); + "Go Up", ListWidget::kParentDirCmd); wid.push_back(myGoUpButton); xpos += (buttonWidth + 1) / 4 + BUTTON_GAP; @@ -382,7 +382,7 @@ void LauncherDialog::addButtonWidgets(int& ypos, WidgetArray& wid) xpos += (buttonWidth + 1) / 4 + BUTTON_GAP; myGoUpButton = new ButtonWidget(this, _font, xpos, ypos, (buttonWidth + 2) / 4, buttonHeight, - "Go Up", kParentDirCmd); + "Go Up", ListWidget::kParentDirCmd); wid.push_back(myGoUpButton); xpos += (buttonWidth + 2) / 4 + BUTTON_GAP; @@ -774,7 +774,7 @@ void LauncherDialog::handleContextMenu() else if(cmd == "subdirs") sendCommand(kSubDirsCmd, 0, 0); else if(cmd == "homedir") - sendCommand(kHomeDirCmd, 0, 0); + sendCommand(FileListWidget::kHomeDirCmd, 0, 0); else if(cmd == "highscores") openHighScores(); else if(cmd == "reload") @@ -818,19 +818,19 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated) switch(key) { case KBDK_HOME: - sendCommand(kHomeDirCmd, 0, 0); + sendCommand(FileListWidget::kHomeDirCmd, 0, 0); break; case KBDK_LEFT: - sendCommand(kPrevDirCmd, 0, 0); + sendCommand(FileListWidget::kPrevDirCmd, 0, 0); break; case KBDK_RIGHT: - sendCommand(kNextDirCmd, 0, 0); + sendCommand(FileListWidget::kNextDirCmd, 0, 0); break; case KBDK_UP: - sendCommand(kParentDirCmd, 0, 0); + sendCommand(ListWidget::kParentDirCmd, 0, 0); break; case KBDK_DOWN: @@ -1007,23 +1007,22 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, toggleSubDirs(); break; - case kHomeDirCmd: - gotoHomeDir(); + case FileListWidget::kHomeDirCmd: + myList->selectHomeDir(); break; - case kPrevDirCmd: + case FileListWidget::kPrevDirCmd: myList->selectPrevHistory(); break; - case kNextDirCmd: + case FileListWidget::kNextDirCmd: myList->selectNextHistory(); break; - case kParentDirCmd: + case ListWidget::kParentDirCmd: myList->selectParent(); break; - case kLoadROMCmd: if(myList->isDirectory(myList->selected())) { @@ -1314,13 +1313,6 @@ void LauncherDialog::openWhatsNew() myDialog->open(); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LauncherDialog::gotoHomeDir() -{ - while(myList->hasPrevHistory()) - myList->selectPrevHistory(); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::toggleShowAll(bool toggle) { diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index 2a28dc9cc..2ae0521fe 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -174,7 +174,6 @@ class LauncherDialog : public Dialog, CommandSender void showOnlyROMs(bool state); void toggleShowAll(bool toggle = true); void toggleSubDirs(bool toggle = true); - void gotoHomeDir(); void handleContextMenu(); void handleQuit(); void toggleExtensions(); @@ -234,12 +233,8 @@ class LauncherDialog : public Dialog, CommandSender enum { kAllfilesCmd = 'lalf', // show all files (or ROMs only) kSubDirsCmd = 'lred', - kParentDirCmd = 'PARD', kOptionsCmd = 'OPTI', kQuitCmd = 'QUIT', - kHomeDirCmd = 'homc', // go to Home directory - kPrevDirCmd = 'prvc', // go back in history to previous directory - kNextDirCmd = 'nxtc', // go back in history to next directory kReloadCmd = 'relc', kRmAllFav = 'rmaf', kRmAllPop = 'rmap',