From aea451f092a90bdc28bc8bd82508ec40b9920868 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 16 Apr 2005 17:55:09 +0000 Subject: Reunify DirBrowserDialog and FileBrowserDialog; implemented file browser mode for OSX, too; fixed some memory leaks in the launcher svn-id: r17639 --- TODO | 11 +++-- gui/browser.cpp | 120 +++++++++++-------------------------------------------- gui/browser.h | 32 ++------------- gui/launcher.cpp | 23 ++++++----- gui/launcher.h | 4 +- gui/options.cpp | 7 +++- gui/options.h | 7 ++-- 7 files changed, 56 insertions(+), 148 deletions(-) diff --git a/TODO b/TODO index 54590fd1fa..4bb2be12f2 100644 --- a/TODO +++ b/TODO @@ -194,8 +194,8 @@ GUI Problem: It's not fully clear to me how to "best" deal with global vs. local settings here... * Maybe add the ScummVM logo (+typeface?) to the about dialog -* Unify DirBrowserDialog and FileBrowserDialog. -* MacOS X version of FileBrowserDialog, since there is one of DirBrowserDialog. +* There is currently no way to unset the SoundFont from the GUI, if any was set. + Maybe add a 'clear' button for it? The same holds for other path settings. Launcher ======== @@ -217,10 +217,9 @@ Plugins * When building with the fake static plugins: instead of hardcoding the list of plugins, plugins should automatically be "hooked in". This can be achieved by modifying REGISTER_PLUGIN to insert special code into the plugins. -* Likewise, when building with real dynamic plugins: instead of hardcoding - plugin names and pathes, we should scan in specific locations for all - available plugins, etc.. For example, try to load all "plugins/lib*.so" - files. To this end consider special file names for the plugins + UPDATE: I tried this, but it doesn't really work due to constraints + imposed by the way most C++ compilers/linkers out there realize global + constructors. * On OSX: Support a plugin build in the bundle target: *.plugin files should be put into ScummVM.app/Contents/PlugIns/; this also means that the loader needs to search in the plugin dir of the active bundle. So use the diff --git a/gui/browser.cpp b/gui/browser.cpp index 389e346090..bb8336229f 100644 --- a/gui/browser.cpp +++ b/gui/browser.cpp @@ -40,16 +40,17 @@ enum { * other operating systems. */ -DirBrowserDialog::DirBrowserDialog(const char *title) +BrowserDialog::BrowserDialog(const char *title, bool dirBrowser) : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) { _titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()); + _isDirBrowser = dirBrowser; } -DirBrowserDialog::~DirBrowserDialog() { +BrowserDialog::~BrowserDialog() { CFRelease(_titleRef); } -int DirBrowserDialog::runModal() { +int BrowserDialog::runModal() { NavDialogRef dialogRef; WindowRef windowRef = 0; NavDialogCreationOptions options; @@ -72,7 +73,10 @@ int DirBrowserDialog::runModal() { // options.message = CFSTR("Select your game directory"); options.modality = kWindowModalityAppModal; - err = NavCreateChooseFolderDialog(&options, 0, 0, 0, &dialogRef); + if (_isDirBrowser) + err = NavCreateChooseFolderDialog(&options, 0, 0, 0, &dialogRef); + else + err = NavCreateChooseFileDialog(&options, 0, 0, 0, 0, 0, &dialogRef); assert(err == noErr); windowRef = NavDialogGetWindow(dialogRef); @@ -126,10 +130,11 @@ int DirBrowserDialog::runModal() { * - others??? */ -DirBrowserDialog::DirBrowserDialog(const char *title) +BrowserDialog::BrowserDialog(const char *title, bool dirBrowser) : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) { + _isDirBrowser = dirBrowser; _fileList = NULL; _currentPath = NULL; @@ -151,7 +156,7 @@ DirBrowserDialog::DirBrowserDialog(const char *title) addButton(_w - (kButtonWidth+10), _h - 24, "Choose", kChooseCmd, 0); } -void DirBrowserDialog::open() { +void BrowserDialog::open() { // If no node has been set, or the last used one is now invalid, // go back to the root/default dir. if (!_node.isValid()) { @@ -165,9 +170,10 @@ void DirBrowserDialog::open() { Dialog::open(); } -void DirBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { +void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { - case kChooseCmd: { + case kChooseCmd: + if (_isDirBrowser) { // If nothing is selected in the list widget, choose the current dir. // Else, choose the dir that is selected. int selection = _fileList->getSelected(); @@ -178,87 +184,7 @@ void DirBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 d } setResult(1); close(); - } - break; - case kGoUpCmd: - _node = _node.getParent(); - updateListing(); - break; - case kListItemActivatedCmd: - case kListItemDoubleClickedCmd: - _node = _nodeContent[data]; - updateListing(); - break; - default: - Dialog::handleCommand(sender, cmd, data); - } -} - -void DirBrowserDialog::updateListing() { - // Update the path display - _currentPath->setLabel(_node.path()); - - // Read in the data from the file system - _nodeContent = _node.listDir(); - _nodeContent.sort(); - - // Populate the ListWidget - Common::StringList list; - int size = _nodeContent.size(); - for (int i = 0; i < size; i++) { - list.push_back(_nodeContent[i].displayName()); - } - _fileList->setList(list); - _fileList->scrollTo(0); - - // Finally, redraw - draw(); -} - -#endif // MACOSX - -FileBrowserDialog::FileBrowserDialog(const char *title) - : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) - { - - _fileList = NULL; - _currentPath = NULL; - - // Headline - TODO: should be customizable during creation time - new StaticTextWidget(this, 10, 8, _w - 2 * 10, kLineHeight, title, kTextAlignCenter); - - // Current path - TODO: handle long paths ? - _currentPath = new StaticTextWidget(this, 10, 20, _w - 2 * 10, kLineHeight, - "DUMMY", kTextAlignLeft); - - // Add file list - _fileList = new ListWidget(this, 10, 34, _w - 2 * 10, _h - 34 - 24 - 10); - _fileList->setNumberingMode(kListNumberingOff); - _fileList->setEditable(false); - - // Buttons - addButton(10, _h - 24, "Go up", kGoUpCmd, 0); - addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0); - addButton(_w - (kButtonWidth+10), _h - 24, "Choose", kChooseCmd, 0); -} - -void FileBrowserDialog::open() { - // If no node has been set, or the last used one is now invalid, - // go back to the root/default dir. - if (!_node.isValid()) { - _node = FilesystemNode(); - } - - // Alway refresh file list - updateListing(); - - // Call super implementation - Dialog::open(); -} - -void FileBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { - switch (cmd) { - case kChooseCmd: { + } else { int selection = _fileList->getSelected(); if (selection < 0) break; @@ -292,26 +218,26 @@ void FileBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 } } -void FileBrowserDialog::updateListing() { +void BrowserDialog::updateListing() { // Update the path display _currentPath->setLabel(_node.path()); // Read in the data from the file system - _nodeContent = _node.listDir(AbstractFilesystemNode::kListAll); + if (_isDirBrowser) + _nodeContent = _node.listDir(AbstractFilesystemNode::kListDirectoriesOnly); + else + _nodeContent = _node.listDir(AbstractFilesystemNode::kListAll); _nodeContent.sort(); // Populate the ListWidget Common::StringList list; int size = _nodeContent.size(); - int i; - - for (i = 0; i < size; i++) { - if (_nodeContent[i].isDirectory()) + for (int i = 0; i < size; i++) { + if (!_isDirBrowser && _nodeContent[i].isDirectory()) list.push_back(_nodeContent[i].displayName() + "/"); else list.push_back(_nodeContent[i].displayName()); } - _fileList->setList(list); _fileList->scrollTo(0); @@ -319,4 +245,6 @@ void FileBrowserDialog::updateListing() { draw(); } +#endif // MACOSX + } // End of namespace GUI diff --git a/gui/browser.h b/gui/browser.h index 46b3512fe7..215fa797d0 100644 --- a/gui/browser.h +++ b/gui/browser.h @@ -34,16 +34,14 @@ namespace GUI { class ListWidget; class StaticTextWidget; -// TODO: Common parent class for DirBrowserDialog and FileBrowserDialog - -class DirBrowserDialog : public Dialog { +class BrowserDialog : public Dialog { typedef Common::String String; typedef Common::StringList StringList; public: - DirBrowserDialog(const char *title); + BrowserDialog(const char *title, bool dirBrowser); #ifdef MACOSX - ~DirBrowserDialog(); + ~BrowserDialog(); virtual int runModal(); #else virtual void open(); @@ -62,35 +60,13 @@ protected: FSList _nodeContent; #endif FilesystemNode _choice; + bool _isDirBrowser; #ifndef MACOSX void updateListing(); #endif }; -// TODO: MACOSX version - -class FileBrowserDialog : public Dialog { - typedef Common::String String; - typedef Common::StringList StringList; -public: - FileBrowserDialog(const char *title); - - virtual void open(); - virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); - - const FilesystemNode &getResult() { return _choice; } - -protected: - ListWidget *_fileList; - StaticTextWidget *_currentPath; - FilesystemNode _node; - FSList _nodeContent; - FilesystemNode _choice; - - void updateListing(); -}; - } // End of namespace GUI #endif diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 67b562dfd8..d9aa0a5789 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -370,16 +370,17 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat // Change path for the game case kCmdGameBrowser: { - DirBrowserDialog *_browser = new DirBrowserDialog("Select additional game directory"); - if (_browser->runModal() > 0) { + BrowserDialog browser("Select additional game directory", true); + if (browser.runModal() > 0) { // User made his choice... - FilesystemNode dir(_browser->getResult()); + FilesystemNode dir(browser.getResult()); // TODO: Verify the game can be found in the new directory... Best // done with optional specific gameid to pluginmgr detectgames? // FSList files = dir.listDir(FilesystemNode::kListFilesOnly); _gamePathWidget->setLabel(dir.path()); + draw(); } draw(); break; @@ -387,22 +388,24 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat // Change path for extra game data (eg, using sword cutscenes when playing via CD) case kCmdExtraBrowser: { - DirBrowserDialog *_browser = new DirBrowserDialog("Select additional game directory"); - if (_browser->runModal() > 0) { + BrowserDialog browser("Select additional game directory", true); + if (browser.runModal() > 0) { // User made his choice... - FilesystemNode dir(_browser->getResult()); + FilesystemNode dir(browser.getResult()); _extraPathWidget->setLabel(dir.path()); + draw(); } draw(); break; } // Change path for stored save game (perm and temp) data case kCmdSaveBrowser: { - DirBrowserDialog *_browser = new DirBrowserDialog("Select directory for saved games"); - if (_browser->runModal() > 0) { + BrowserDialog browser("Select directory for saved games", true); + if (browser.runModal() > 0) { // User made his choice... - FilesystemNode dir(_browser->getResult()); + FilesystemNode dir(browser.getResult()); _savePathWidget->setLabel(dir.path()); + draw(); } draw(); break; @@ -470,7 +473,7 @@ LauncherDialog::LauncherDialog(GameDetector &detector) updateButtons(); // Create file browser dialog - _browser = new DirBrowserDialog("Select directory with game data"); + _browser = new BrowserDialog("Select directory with game data", true); } void LauncherDialog::selectGame(const String &name) { diff --git a/gui/launcher.h b/gui/launcher.h index 90c51b657d..ba6cfa5210 100644 --- a/gui/launcher.h +++ b/gui/launcher.h @@ -28,7 +28,7 @@ class GameDetector; namespace GUI { -class DirBrowserDialog; +class BrowserDialog; class ListWidget; class LauncherDialog : public Dialog { @@ -47,7 +47,7 @@ protected: Widget *_removeButton; StringList _domains; GameDetector &_detector; - DirBrowserDialog *_browser; + BrowserDialog *_browser; void updateListing(); void updateButtons(); diff --git a/gui/options.cpp b/gui/options.cpp index 1544730c89..4f093a62bc 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -499,8 +499,8 @@ GlobalOptionsDialog::GlobalOptionsDialog(GameDetector &detector) addButton(_w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0); // Create file browser dialogs - _dirBrowser = new DirBrowserDialog("Select directory for savegames"); - _fileBrowser = new FileBrowserDialog("Select SoundFont"); + _dirBrowser = new BrowserDialog("Select directory for savegames", true); + _fileBrowser = new BrowserDialog("Select SoundFont", false); #ifdef _WIN32_WCE _keysDialog = new CEKeysDialog(); @@ -571,6 +571,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 // User made his choice... FilesystemNode dir(_dirBrowser->getResult()); _savePath->setLabel(dir.path()); + draw(); // TODO - we should check if the directory is writeable before accepting it } break; @@ -579,6 +580,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 // User made his choice... FilesystemNode dir(_dirBrowser->getResult()); _extraPath->setLabel(dir.path()); + draw(); } break; case kChooseSoundFontCmd: @@ -586,6 +588,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 // User made his choice... FilesystemNode file(_fileBrowser->getResult()); _soundFont->setLabel(file.path()); + draw(); } break; #ifdef _WIN32_WCE diff --git a/gui/options.h b/gui/options.h index cbe6817be1..954b14892f 100644 --- a/gui/options.h +++ b/gui/options.h @@ -32,8 +32,7 @@ class GameDetector; namespace GUI { -class DirBrowserDialog; -class FileBrowserDialog; +class BrowserDialog; class CheckboxWidget; class PopUpWidget; class SliderWidget; @@ -120,8 +119,8 @@ public: void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); protected: - DirBrowserDialog *_dirBrowser; - FileBrowserDialog *_fileBrowser; + BrowserDialog *_dirBrowser; + BrowserDialog *_fileBrowser; #ifdef _WIN32_WCE CEKeysDialog *_keysDialog; #endif -- cgit v1.2.3