diff --git a/src/debugger/gui/DebuggerDialog.cxx b/src/debugger/gui/DebuggerDialog.cxx index 4403009b8..f7a8987f0 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -259,30 +259,6 @@ void DebuggerDialog::handleCommand(CommandSender* sender, int cmd, loadConfig(); break; - case kSvAccessCmd: - runCommand("saveaccess"); - break; - - case kSvDisCmd: - runCommand("savedis"); - break; - - case kSvRomCmd: - runCommand("saverom"); - break; - - case kSvScriptCmd: - runCommand("save"); - break; - - case kSvSessionCmd: - runCommand("saveses"); - break; - - case kBdCancelCmd: - runCommand(); - break; - case RomWidget::kInvalidateListing: // Only do a full redraw if the disassembly tab is actually showing myRom->invalidate(myRomTab->getActiveTab() == 0); @@ -427,79 +403,63 @@ void DebuggerDialog::createFont() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DebuggerDialog::showBrowser(BrowserType type, const string& defaultName) { - int cmd; - string title; + string title, command; switch(type) { case BrowserType::svAccess: - cmd = kSvAccessCmd; title = "Access Counters"; + command = "saveaccess"; break; case BrowserType::svDis: - cmd = kSvDisCmd; title = "Disassembly"; + command = "savedis"; break; case BrowserType::svRom: - cmd = kSvRomCmd; title = "ROM"; + command = "saverom"; break; case BrowserType::svScript: - cmd = kSvScriptCmd; title = "Workbench"; + command = "save"; break; case BrowserType::svSession: - cmd = kSvSessionCmd; title = "Session"; + command = "saveses"; break; default: - cmd = 0; break; } - if(cmd) + if(command != EmptyString) { - createBrowser("Save " + title + " as"); - - const string path = instance().userDir().getPath() + defaultName; - myBrowser->show(path, BrowserDialog::FileSave, cmd, kBdCancelCmd); + BrowserDialog::show(this, instance().frameBuffer().font(), "Save " + title + " as", + instance().userDir().getPath() + defaultName, + BrowserDialog::Mode::FileSave, + [this, command](bool OK, const FilesystemNode& node) { + if(OK) runCommand(node, command); + else runCommand(node); + }); } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DebuggerDialog::runCommand(const string& command) +void DebuggerDialog::runCommand(const FilesystemNode& node, const string& command) { if(command != EmptyString) { - FilesystemNode dir(myBrowser->getResult()); - - string result = instance().debugger().parser().run(command + " {" + dir.getShortPath() + "}"); + string result = instance().debugger().parser().run(command + " {" + + node.getPath() + "}"); prompt().print(result + '\n'); } prompt().printPrompt(); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void DebuggerDialog::createBrowser(const string& title) -{ - uInt32 w = 0, h = 0; - getDynamicBounds(w, h); - if(w > uInt32(_font.getMaxCharWidth() * 80)) - w = _font.getMaxCharWidth() * 80; - - // Create file browser dialog - if(!myBrowser || uInt32(myBrowser->getWidth()) != w || - uInt32(myBrowser->getHeight()) != h) - myBrowser = make_unique(this, instance().frameBuffer().font(), w, h, title); - else - myBrowser->setTitle(title); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DebuggerDialog::showFatalMessage(const string& msg) { diff --git a/src/debugger/gui/DebuggerDialog.hxx b/src/debugger/gui/DebuggerDialog.hxx index 1a4b4df67..2552f78c1 100644 --- a/src/debugger/gui/DebuggerDialog.hxx +++ b/src/debugger/gui/DebuggerDialog.hxx @@ -21,6 +21,7 @@ class Debugger; class OSystem; class DialogContainer; +class FilesystemNode; class ButtonWidget; class CpuWidget; class PromptWidget; @@ -34,7 +35,6 @@ class TiaZoomWidget; class CartDebugWidget; class CartRamWidget; class OptionsDialog; -class BrowserDialog; namespace GUI { class MessageBox; @@ -124,17 +124,11 @@ class DebuggerDialog : public Dialog kDDUnwindCmd = 'DDuw', kDDRunCmd = 'DDex', kDDExitFatalCmd = 'DDer', - kDDOptionsCmd = 'DDop', - kSvAccessCmd = 'SvAc', - kSvDisCmd = 'SvDs', - kSvRomCmd = 'SvRm', - kSvScriptCmd = 'SvSc', - kSvSessionCmd = 'SvSs', - kBdCancelCmd = 'SvCn' + kDDOptionsCmd = 'DDop' }; - void runCommand(const string& command = EmptyString); - void createBrowser(const string& title); + void runCommand(const FilesystemNode& node, + const string& command = EmptyString); TabWidget *myTab{nullptr}, *myRomTab{nullptr}; @@ -154,7 +148,6 @@ class DebuggerDialog : public Dialog unique_ptr myFatalError; unique_ptr myOptions; - unique_ptr myBrowser; unique_ptr myLFont; // used for labels unique_ptr myNFont; // used for normal text diff --git a/src/gui/BrowserDialog.cxx b/src/gui/BrowserDialog.cxx index 7639dbfd3..02f550b70 100644 --- a/src/gui/BrowserDialog.cxx +++ b/src/gui/BrowserDialog.cxx @@ -26,16 +26,10 @@ #include "Font.hxx" #include "BrowserDialog.hxx" -/* We want to use this as a general directory selector at some point... possible uses - * - to select the data dir for a game - * - to select the place where save games are stored - * - others??? - */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font, int max_w, int max_h, const string& title) - : Dialog(boss->instance(), boss->parent(), font, title), - CommandSender(boss) + : Dialog(boss->instance(), boss->parent(), font, title) { // Set real dimensions _w = max_w; @@ -120,24 +114,42 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font, addFocusWidget(_savePathBox); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void BrowserDialog::show(GuiObject* parent, const GUI::Font& font, + const string& title, const string& startpath, + BrowserDialog::Mode mode, + const Command& command, + const FilesystemNode::NameFilter& namefilter) +{ + uInt32 w = 0, h = 0; + static_cast(parent)->getDynamicBounds(w, h); + if(w > uInt32(font.getMaxCharWidth() * 80)) + w = font.getMaxCharWidth() * 80; + + static unique_ptr ourBrowser = + make_unique(parent, font, w, h, title); + + ourBrowser->show(startpath, mode, command, namefilter); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void BrowserDialog::show(const string& startpath, - BrowserDialog::ListMode mode, int cmd, int cancelCmd, - const string& ext) + BrowserDialog::Mode mode, + const Command& command, + const FilesystemNode::NameFilter& namefilter) { const int fontWidth = _font.getMaxCharWidth(), fontHeight = _font.getFontHeight(), VGAP = fontHeight / 4; _mode = mode; - _cmd = cmd; - _cancelCmd = cancelCmd; - string directory;// = EmptyString; - string fileName;// = EmptyString; + _command = command; + string directory; + string fileName; bool fileSelected = true; // Set start path - if(_mode != Directories) + if(_mode != Mode::Directories) { // split startpath into path and filename FilesystemNode fs = FilesystemNode(startpath); @@ -147,11 +159,9 @@ void BrowserDialog::show(const string& startpath, switch(_mode) { - case FileLoad: + case Mode::FileLoad: _fileList->setListMode(FilesystemNode::ListMode::All); - _fileList->setNameFilter([ext](const FilesystemNode& node) { - return BSPF::endsWithIgnoreCase(node.getName(), ext); - }); + _fileList->setNameFilter(namefilter); _fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop()); _currentPath->setWidth(_savePathBox->getLeft() - _currentPath->getLeft() - fontWidth); @@ -166,11 +176,9 @@ void BrowserDialog::show(const string& startpath, _okWidget->setLabel("Load"); break; - case FileSave: + case Mode::FileSave: _fileList->setListMode(FilesystemNode::ListMode::All); - _fileList->setNameFilter([ext](const FilesystemNode& node) { - return BSPF::endsWithIgnoreCase(node.getName(), ext); - }); + _fileList->setNameFilter(namefilter); _fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop()); _currentPath->setWidth(_savePathBox->getLeft() - _currentPath->getLeft() - fontWidth); @@ -187,7 +195,7 @@ void BrowserDialog::show(const string& startpath, fileSelected = false; break; - case Directories: + case Mode::Directories: _fileList->setListMode(FilesystemNode::ListMode::DirectoriesOnly); _fileList->setNameFilter([](const FilesystemNode&) { return true; }); // TODO: scrollbar affected too! @@ -206,7 +214,7 @@ void BrowserDialog::show(const string& startpath, } // Set start path - if(_mode != Directories) + if(_mode != Mode::Directories) _fileList->setDirectory(FilesystemNode(directory), fileName); else _fileList->setDirectory(FilesystemNode(startpath)); @@ -220,12 +228,12 @@ void BrowserDialog::show(const string& startpath, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const FilesystemNode& BrowserDialog::getResult() const { - if(_mode == FileLoad || _mode == FileSave) + if(_mode == Mode::FileLoad || _mode == Mode::FileSave) { static FilesystemNode node; return node - = FilesystemNode(_fileList->currentDir().getShortPath() + _selected->getText()); + = FilesystemNode(_fileList->currentDir().getPath() + _selected->getText()); } else return _fileList->currentDir(); @@ -240,8 +248,7 @@ void BrowserDialog::handleCommand(CommandSender* sender, int cmd, case kChooseCmd: case FileListWidget::ItemActivated: // Send a signal to the calling class that a selection has been made - // Since we aren't derived from a widget, we don't have a 'data' or 'id' - if(_mode != Directories) + if(_mode != Mode::Directories) { // TODO: check if affected by '-baseDir'and 'basedirinapp' params bool savePath = _savePathBox->getState(); @@ -250,14 +257,13 @@ void BrowserDialog::handleCommand(CommandSender* sender, int cmd, if(savePath) instance().setUserDir(_fileList->currentDir().getShortPath()); } - if(_cmd) sendCommand(_cmd, -1, -1); + _command(true, getResult()); close(); break; case kCloseCmd: // Send a signal to the calling class that the dialog was closed without selection - // Since we aren't derived from a widget, we don't have a 'data' or 'id' - if(_cancelCmd) sendCommand(_cancelCmd, -1, -1); + _command(false, getResult()); close(); break; @@ -300,7 +306,7 @@ void BrowserDialog::updateUI(bool fileSelected) // Enable/disable OK button based on current mode and status bool enable = true; - if(_mode != Directories) + if(_mode != Mode::Directories) enable = !_selected->getText().empty(); _okWidget->setEnabled(enable); diff --git a/src/gui/BrowserDialog.hxx b/src/gui/BrowserDialog.hxx index 8d4b5c2a6..c8c32759c 100644 --- a/src/gui/BrowserDialog.hxx +++ b/src/gui/BrowserDialog.hxx @@ -23,34 +23,62 @@ class ButtonWidget; class EditTextWidget; class FileListWidget; class StaticTextWidget; -class FilesystemNode; #include "Dialog.hxx" #include "Command.hxx" +#include "FSNode.hxx" #include "bspf.hxx" -class BrowserDialog : public Dialog, public CommandSender +class BrowserDialog : public Dialog { public: - enum ListMode { + enum class Mode { FileLoad, // File selector, no input from user FileSave, // File selector, filename changable by user Directories // Directories only, no input from user }; + /** Function which is run when the user clicks OK or Cancel. + Boolean parameter is passed as 'true' when OK is clicked, else 'false'. + FilesystemNode parameter is what is currently selected in the browser. + */ + using Command = std::function; + public: + // NOTE: Do not call this c'tor directly! Use the static show method below + // There is no point in doing so, since the result can't be returned BrowserDialog(GuiObject* boss, const GUI::Font& font, int max_w, int max_h, - const string& title = ""); + const string& title); ~BrowserDialog() override = default; + /** + Place the browser window onscreen, using the given attributes. + + @param parent The parent object of the browser (cannot be nullptr) + @param font The font to use in the browser + @param title The title of the browser window + @param startpath The initial path to select in the browser + @param mode The functionality to use (load/save/display) + @param command The command to run when 'OK' or 'Cancel' is clicked + @param namefilter Filter files/directories in browser display + */ + static void show(GuiObject* parent, const GUI::Font& font, + const string& title, const string& startpath, + BrowserDialog::Mode mode, + const Command& command, + const FilesystemNode::NameFilter& namefilter = { + [](const FilesystemNode&) { return true; }}); + + private: /** Place the browser window onscreen, using the given attributes */ void show(const string& startpath, - BrowserDialog::ListMode mode, int cmd, int cancelCmd = 0, const string& ext = ""); + BrowserDialog::Mode mode, + const Command& command, + const FilesystemNode::NameFilter& namefilter); /** Get resulting file node (called after receiving kChooseCmd) */ const FilesystemNode& getResult() const; - private: void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void updateUI(bool fileSelected); @@ -62,8 +90,9 @@ class BrowserDialog : public Dialog, public CommandSender kHomeDirCmd = 'HODR' }; - int _cmd{0}; - int _cancelCmd{0}; + // Called when the user selects OK (bool is true) or Cancel (bool is false) + // FSNode will be set to whatever is active (basically, getResult()) + Command _command{[](bool, const FilesystemNode&){}}; FileListWidget* _fileList{nullptr}; EditTextWidget* _currentPath{nullptr}; @@ -72,7 +101,7 @@ class BrowserDialog : public Dialog, public CommandSender ButtonWidget* _goUpButton{nullptr}; CheckboxWidget* _savePathBox{nullptr}; - BrowserDialog::ListMode _mode{Directories}; + BrowserDialog::Mode _mode{Mode::Directories}; private: // Following constructors and assignment operators not supported diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index 9a0cb3fe7..24e787c32 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -666,22 +666,6 @@ GameInfoDialog::~GameInfoDialog() { } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void GameInfoDialog::createBrowser(const string& title) -{ - uInt32 w = 0, h = 0; - getDynamicBounds(w, h); - if(w > uInt32(_font.getMaxCharWidth() * 80)) - w = _font.getMaxCharWidth() * 80; - - // Create file browser dialog - if(!myBrowser || uInt32(myBrowser->getWidth()) != w || - uInt32(myBrowser->getHeight()) != h) - myBrowser = make_unique(this, _font, w, h, title); - else - myBrowser->setTitle(title); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void GameInfoDialog::loadConfig() { @@ -1358,7 +1342,7 @@ void GameInfoDialog::setAddressVal(EditTextWidget* addressWidget, EditTextWidget } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void GameInfoDialog::exportCurrentPropertiesToDisk() +void GameInfoDialog::exportCurrentPropertiesToDisk(const FilesystemNode& node) { saveProperties(); stringstream out; @@ -1366,9 +1350,7 @@ void GameInfoDialog::exportCurrentPropertiesToDisk() try { - FilesystemNode propfile(myBrowser->getResult().getShortPath()); - - propfile.write(out); + node.write(out); instance().frameBuffer().showTextMessage("ROM properties exported"); } catch(...) @@ -1393,16 +1375,13 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd, break; case kExportPressed: - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary - createBrowser("Export Properties as"); - - myBrowser->show(instance().userDir().getPath() + myGameFile.getNameWithExt(".pro"), - BrowserDialog::FileSave, kExportChosen); - break; - - case kExportChosen: - exportCurrentPropertiesToDisk(); + BrowserDialog::show(this, _font, "Export Properties as", + instance().userDir().getPath() + + myGameFile.getNameWithExt(".pro"), + BrowserDialog::Mode::FileSave, + [this](bool OK, const FilesystemNode& node) { + if(OK) exportCurrentPropertiesToDisk(node); + }); break; case TabWidget::kTabChangedCmd: diff --git a/src/gui/GameInfoDialog.hxx b/src/gui/GameInfoDialog.hxx index d3af6775e..ffe41e223 100644 --- a/src/gui/GameInfoDialog.hxx +++ b/src/gui/GameInfoDialog.hxx @@ -27,7 +27,6 @@ class RadioButtonGroup; class TabWidget; class SliderWidget; class QuadTariDialog; -class BrowserDialog; #include "Dialog.hxx" #include "Command.hxx" @@ -78,8 +77,7 @@ class GameInfoDialog : public Dialog, public CommandSender // set formatted memory value for given address field void setAddressVal(EditTextWidget* address, EditTextWidget* val, bool isBCD = true, bool zeroBased = false, uInt8 maxVal = 255); - void exportCurrentPropertiesToDisk(); - void createBrowser(const string& title); + void exportCurrentPropertiesToDisk(const FilesystemNode& node); private: TabWidget* myTab{nullptr}; @@ -170,8 +168,6 @@ class GameInfoDialog : public Dialog, public CommandSender StaticTextWidget* myHighScoreNotesLabel{nullptr}; EditTextWidget* myHighScoreNotes{nullptr}; - unique_ptr myBrowser; - enum { kVCenterChanged = 'Vcch', kPhosphorChanged = 'PPch', @@ -184,8 +180,7 @@ class GameInfoDialog : public Dialog, public CommandSender kHiScoresChanged = 'HSch', kPXCenterChanged = 'Pxch', kPYCenterChanged = 'Pych', - kExportPressed = 'Expr', - kExportChosen = 'Exch' + kExportPressed = 'Expr' }; // Game properties for currently loaded ROM diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index cd9d845a8..785394708 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -22,7 +22,6 @@ class ButtonWidget; class CommandSender; class ContextMenu; class DialogContainer; -class BrowserDialog; class OptionsDialog; class HighScoresDialog; class GlobalPropsDialog; @@ -168,7 +167,6 @@ class LauncherDialog : public Dialog unique_ptr myStellaSettingsDialog; unique_ptr myMenu; unique_ptr myGlobalProps; - unique_ptr myRomDir; unique_ptr myWhatsNewDialog; // automatically sized font for ROM info viewer diff --git a/src/gui/LoggerDialog.cxx b/src/gui/LoggerDialog.cxx index 41256ceb1..b5d5ac9a8 100644 --- a/src/gui/LoggerDialog.cxx +++ b/src/gui/LoggerDialog.cxx @@ -89,27 +89,6 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent, addToFocusList(wid); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -LoggerDialog::~LoggerDialog() -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LoggerDialog::createBrowser(const string& title) -{ - uInt32 w = 0, h = 0; - getDynamicBounds(w, h); - if(w > uInt32(_font.getMaxCharWidth() * 80)) - w = _font.getMaxCharWidth() * 80; - - // Create file browser dialog - if(!myBrowser || uInt32(myBrowser->getWidth()) != w || - uInt32(myBrowser->getHeight()) != h) - myBrowser = make_unique(this, _font, w, h, title); - else - myBrowser->setTitle(title); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LoggerDialog::loadConfig() { @@ -136,10 +115,8 @@ void LoggerDialog::saveConfig() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void LoggerDialog::saveLogFile() +void LoggerDialog::saveLogFile(const FilesystemNode& node) { - FilesystemNode node(myBrowser->getResult().getShortPath()); - try { stringstream out; @@ -165,16 +142,12 @@ void LoggerDialog::handleCommand(CommandSender* sender, int cmd, break; case GuiObject::kDefaultsCmd: - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary - createBrowser("Save Log as"); - - myBrowser->show(instance().userDir().getPath() + "stella.log", - BrowserDialog::FileSave, kSaveCmd); - break; - - case kSaveCmd: - saveLogFile(); + BrowserDialog::show(this, _font, "Save Log as", + instance().userDir().getPath() + "stella.log", + BrowserDialog::Mode::FileSave, + [this](bool OK, const FilesystemNode& node) { + if(OK) saveLogFile(node); + }); break; default: diff --git a/src/gui/LoggerDialog.hxx b/src/gui/LoggerDialog.hxx index 4addadb84..8eff3e8e4 100644 --- a/src/gui/LoggerDialog.hxx +++ b/src/gui/LoggerDialog.hxx @@ -22,7 +22,6 @@ class GuiObject; class CheckboxWidget; class PopUpWidget; class StringListWidget; -class BrowserDialog; #include "Dialog.hxx" #include "bspf.hxx" @@ -33,14 +32,12 @@ class LoggerDialog : public Dialog LoggerDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, int max_w, int max_h, bool useLargeFont = true); - ~LoggerDialog() override; + ~LoggerDialog() override = default; private: - void createBrowser(const string& title); - void loadConfig() override; void saveConfig() override; - void saveLogFile(); + void saveLogFile(const FilesystemNode& node); void handleCommand(CommandSender* sender, int cmd, int data, int id) override; @@ -49,13 +46,6 @@ class LoggerDialog : public Dialog PopUpWidget* myLogLevel{nullptr}; CheckboxWidget* myLogToConsole{nullptr}; - unique_ptr myBrowser; - - enum { - kSaveCmd = 'SvLg' - }; - - private: // Following constructors and assignment operators not supported LoggerDialog() = delete; diff --git a/src/gui/RomAuditDialog.cxx b/src/gui/RomAuditDialog.cxx index de7f3f5cd..fb80f4f28 100644 --- a/src/gui/RomAuditDialog.cxx +++ b/src/gui/RomAuditDialog.cxx @@ -37,7 +37,6 @@ RomAuditDialog::RomAuditDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, int max_w, int max_h) : Dialog(osystem, parent, font, "Audit ROMs"), - myFont{font}, myMaxWidth{max_w}, myMaxHeight{max_h} { @@ -186,7 +185,7 @@ void RomAuditDialog::handleCommand(CommandSender* sender, int cmd, msg.push_back("If you're sure you want to proceed with the"); msg.push_back("audit, click 'OK', otherwise click 'Cancel'."); myConfirmMsg = make_unique - (this, myFont, msg, myMaxWidth, myMaxHeight, kConfirmAuditCmd, + (this, _font, msg, myMaxWidth, myMaxHeight, kConfirmAuditCmd, "OK", "Cancel", "ROM Audit", false); } myConfirmMsg->show(); @@ -198,38 +197,20 @@ void RomAuditDialog::handleCommand(CommandSender* sender, int cmd, break; case kChooseAuditDirCmd: - createBrowser("Select ROM Directory to Audit"); - myBrowser->show(myRomPath->getText(), - BrowserDialog::Directories, kAuditDirChosenCmd); + BrowserDialog::show(this, _font, "Select ROM Directory to Audit", + myRomPath->getText(), + BrowserDialog::Mode::Directories, + [this](bool OK, const FilesystemNode& node) { + if(OK) { + myRomPath->setText(node.getShortPath()); + myResults1->setText(""); + myResults2->setText(""); + } + }); break; - case kAuditDirChosenCmd: - { - FilesystemNode dir(myBrowser->getResult()); - myRomPath->setText(dir.getShortPath()); - myResults1->setText(""); - myResults2->setText(""); - break; - } - default: Dialog::handleCommand(sender, cmd, data, 0); break; } } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void RomAuditDialog::createBrowser(const string& title) -{ - uInt32 w = 0, h = 0; - getDynamicBounds(w, h); - if(w > uInt32(_font.getMaxCharWidth() * 80)) - w = _font.getMaxCharWidth() * 80; - - // Create file browser dialog - if(!myBrowser || uInt32(myBrowser->getWidth()) != w || - uInt32(myBrowser->getHeight()) != h) - myBrowser = make_unique(this, myFont, w, h, title); - else - myBrowser->setTitle(title); -} diff --git a/src/gui/RomAuditDialog.hxx b/src/gui/RomAuditDialog.hxx index 3bc2a5969..140256c41 100644 --- a/src/gui/RomAuditDialog.hxx +++ b/src/gui/RomAuditDialog.hxx @@ -23,7 +23,6 @@ class GuiObject; class DialogContainer; class EditTextWidget; class StaticTextWidget; -class BrowserDialog; namespace GUI { class MessageBox; } @@ -42,20 +41,14 @@ class RomAuditDialog : public Dialog private: void loadConfig() override; void auditRoms(); - void createBrowser(const string& title); void handleCommand(CommandSender* sender, int cmd, int data, int id) override; private: enum { kChooseAuditDirCmd = 'RAsl', // audit dir select - kAuditDirChosenCmd = 'RAch', // audit dir changed kConfirmAuditCmd = 'RAcf' // confirm rom audit }; - // Select a new ROM audit path - unique_ptr myBrowser; - const GUI::Font& myFont; - // ROM audit path EditTextWidget* myRomPath{nullptr}; diff --git a/src/gui/SnapshotDialog.cxx b/src/gui/SnapshotDialog.cxx index 28067213c..54dc6997e 100644 --- a/src/gui/SnapshotDialog.cxx +++ b/src/gui/SnapshotDialog.cxx @@ -28,8 +28,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, int max_w, int max_h) - : Dialog(osystem, parent, font, "Snapshot settings"), - myFont{font} + : Dialog(osystem, parent, font, "Snapshot settings") { const int lineHeight = font.getLineHeight(), fontHeight = _font.getFontHeight(), @@ -98,11 +97,6 @@ SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent, addToFocusList(wid); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SnapshotDialog::~SnapshotDialog() -{ -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SnapshotDialog::loadConfig() { @@ -154,15 +148,12 @@ void SnapshotDialog::handleCommand(CommandSender* sender, int cmd, break; case kChooseSnapSaveDirCmd: - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary - createBrowser("Select Snapshot Save Directory"); - myBrowser->show(mySnapSavePath->getText(), - BrowserDialog::Directories, kSnapSaveDirChosenCmd); - break; - - case kSnapSaveDirChosenCmd: - mySnapSavePath->setText(myBrowser->getResult().getShortPath()); + BrowserDialog::show(this, _font, "Select Snapshot Save Directory", + mySnapSavePath->getText(), + BrowserDialog::Mode::Directories, + [this](bool OK, const FilesystemNode& node) { + if(OK) mySnapSavePath->setText(node.getShortPath()); + }); break; case kSnapshotInterval: @@ -177,19 +168,3 @@ void SnapshotDialog::handleCommand(CommandSender* sender, int cmd, break; } } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void SnapshotDialog::createBrowser(const string& title) -{ - uInt32 w = 0, h = 0; - getDynamicBounds(w, h); - if(w > uInt32(_font.getMaxCharWidth() * 80)) - w = _font.getMaxCharWidth() * 80; - - // Create file browser dialog - if(!myBrowser || uInt32(myBrowser->getWidth()) != w || - uInt32(myBrowser->getHeight()) != h) - myBrowser = make_unique(this, myFont, w, h, title); - else - myBrowser->setTitle(title); -} diff --git a/src/gui/SnapshotDialog.hxx b/src/gui/SnapshotDialog.hxx index 6c9a30118..2ddcf6b37 100644 --- a/src/gui/SnapshotDialog.hxx +++ b/src/gui/SnapshotDialog.hxx @@ -25,7 +25,6 @@ class CheckboxWidget; class EditTextWidget; class SliderWidget; class StaticTextWidget; -class BrowserDialog; #include "Dialog.hxx" #include "Command.hxx" @@ -35,7 +34,7 @@ class SnapshotDialog : public Dialog public: SnapshotDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, int max_w, int max_h); - ~SnapshotDialog() override; + ~SnapshotDialog() override = default; private: void loadConfig() override; @@ -43,17 +42,13 @@ class SnapshotDialog : public Dialog void setDefaults() override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; - void createBrowser(const string& title); private: enum { kChooseSnapSaveDirCmd = 'LOss', // snapshot dir (save files) - kSnapSaveDirChosenCmd = 'snsc', // snap chosen (save files) kSnapshotInterval = 'SnIn' // snap chosen (load files) }; - const GUI::Font& myFont; - // Config paths EditTextWidget* mySnapSavePath{nullptr}; @@ -63,8 +58,6 @@ class SnapshotDialog : public Dialog CheckboxWidget* mySnapSingle{nullptr}; CheckboxWidget* mySnap1x{nullptr}; - unique_ptr myBrowser; - private: // Following constructors and assignment operators not supported SnapshotDialog() = delete; diff --git a/src/gui/UIDialog.cxx b/src/gui/UIDialog.cxx index 65c7d927b..4c1831a0b 100644 --- a/src/gui/UIDialog.cxx +++ b/src/gui/UIDialog.cxx @@ -42,7 +42,6 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, GuiObject* boss, int max_w, int max_h) : Dialog(osystem, parent, font, "User interface settings"), CommandSender(boss), - myFont{font}, myIsGlobal{boss != nullptr} { const GUI::Font& ifont = instance().frameBuffer().infoFont(); @@ -91,7 +90,6 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, wid.push_back(myPalettePopup); ypos += lineHeight + VGAP; - // Dialog font items.clear(); VarList::push_back(items, "Small", "small"); // 8x13 @@ -318,11 +316,6 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, #endif } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -UIDialog::~UIDialog() -{ -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void UIDialog::loadConfig() { @@ -584,15 +577,12 @@ void UIDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) break; case kChooseRomDirCmd: - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary - createBrowser("Select ROM Directory"); - myBrowser->show(myRomPath->getText(), - BrowserDialog::Directories, LauncherDialog::kRomDirChosenCmd); - break; - - case LauncherDialog::kRomDirChosenCmd: - myRomPath->setText(myBrowser->getResult().getShortPath()); + BrowserDialog::show(this, _font, "Select ROM Directory", + myRomPath->getText(), + BrowserDialog::Mode::Directories, + [this](bool OK, const FilesystemNode& node) { + if(OK) myRomPath->setText(node.getShortPath()); + }); break; case kRomViewer: @@ -600,15 +590,12 @@ void UIDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) break; case kChooseSnapLoadDirCmd: - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary - createBrowser("Select ROM Info Viewer Image Directory"); - myBrowser->show(mySnapLoadPath->getText(), - BrowserDialog::Directories, kSnapLoadDirChosenCmd); - break; - - case kSnapLoadDirChosenCmd: - mySnapLoadPath->setText(myBrowser->getResult().getShortPath()); + BrowserDialog::show(this, _font, "Select ROM Info Viewer Image Directory", + myRomPath->getText(), + BrowserDialog::Mode::Directories, + [this](bool OK, const FilesystemNode& node) { + if(OK) mySnapLoadPath->setText(node.getShortPath()); + }); break; default: @@ -700,19 +687,3 @@ void UIDialog::handleRomViewer() myOpenBrowserButton->setEnabled(enable); mySnapLoadPath->setEnabled(enable); } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void UIDialog::createBrowser(const string& title) -{ - uInt32 w = 0, h = 0; - getDynamicBounds(w, h); - if(w > uInt32(_font.getMaxCharWidth() * 80)) - w = _font.getMaxCharWidth() * 80; - - // Create file browser dialog - if(!myBrowser || uInt32(myBrowser->getWidth()) != w || - uInt32(myBrowser->getHeight()) != h) - myBrowser = make_unique(this, myFont, w, h, title); - else - myBrowser->setTitle(title); -} diff --git a/src/gui/UIDialog.hxx b/src/gui/UIDialog.hxx index 544f6c764..9ecf9a3c4 100644 --- a/src/gui/UIDialog.hxx +++ b/src/gui/UIDialog.hxx @@ -18,14 +18,15 @@ #ifndef UI_DIALOG_HXX #define UI_DIALOG_HXX -class BrowserDialog; +#include "Dialog.hxx" +#include "bspf.hxx" class UIDialog : public Dialog, public CommandSender { public: UIDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font, GuiObject* boss, int max_w, int max_h); - ~UIDialog() override; + ~UIDialog() override = default; private: void loadConfig() override; @@ -35,7 +36,6 @@ class UIDialog : public Dialog, public CommandSender void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleLauncherSize(); void handleRomViewer(); - void createBrowser(const string& title); private: enum @@ -46,11 +46,9 @@ class UIDialog : public Dialog, public CommandSender kControllerDelay = 'UIcd', kChooseRomDirCmd = 'LOrm', // rom select kRomViewer = 'UIRv', - kChooseSnapLoadDirCmd = 'UIsl', // snapshot dir (load files) - kSnapLoadDirChosenCmd = 'UIsc' // snap chosen (load files) + kChooseSnapLoadDirCmd = 'UIsl' // snapshot dir (load files) }; - const GUI::Font& myFont; TabWidget* myTab{nullptr}; // Launcher options @@ -76,8 +74,6 @@ class UIDialog : public Dialog, public CommandSender SliderWidget* myControllerDelaySlider{nullptr}; SliderWidget* myDoubleClickSlider{nullptr}; - unique_ptr myBrowser; - // Indicates if this dialog is used for global (vs. in-game) settings bool myIsGlobal{false};