Reunify DirBrowserDialog and FileBrowserDialog; implemented file browser mode for OSX, too; fixed some memory leaks in the launcher

svn-id: r17639
This commit is contained in:
Max Horn 2005-04-16 17:55:09 +00:00
parent caf142657d
commit aea451f092
7 changed files with 56 additions and 148 deletions

11
TODO
View file

@ -194,8 +194,8 @@ GUI
Problem: It's not fully clear to me how to "best" deal with global vs. local Problem: It's not fully clear to me how to "best" deal with global vs. local
settings here... settings here...
* Maybe add the ScummVM logo (+typeface?) to the about dialog * Maybe add the ScummVM logo (+typeface?) to the about dialog
* Unify DirBrowserDialog and FileBrowserDialog. * There is currently no way to unset the SoundFont from the GUI, if any was set.
* MacOS X version of FileBrowserDialog, since there is one of DirBrowserDialog. Maybe add a 'clear' button for it? The same holds for other path settings.
Launcher Launcher
======== ========
@ -217,10 +217,9 @@ Plugins
* When building with the fake static plugins: instead of hardcoding the list * When building with the fake static plugins: instead of hardcoding the list
of plugins, plugins should automatically be "hooked in". This can be achieved of plugins, plugins should automatically be "hooked in". This can be achieved
by modifying REGISTER_PLUGIN to insert special code into the plugins. by modifying REGISTER_PLUGIN to insert special code into the plugins.
* Likewise, when building with real dynamic plugins: instead of hardcoding UPDATE: I tried this, but it doesn't really work due to constraints
plugin names and pathes, we should scan in specific locations for all imposed by the way most C++ compilers/linkers out there realize global
available plugins, etc.. For example, try to load all "plugins/lib*.so" constructors.
files. To this end consider special file names for the plugins
* On OSX: Support a plugin build in the bundle target: *.plugin files should * 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 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 needs to search in the plugin dir of the active bundle. So use the

View file

@ -40,16 +40,17 @@ enum {
* other operating systems. * other operating systems.
*/ */
DirBrowserDialog::DirBrowserDialog(const char *title) BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
: Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) { : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) {
_titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()); _titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding());
_isDirBrowser = dirBrowser;
} }
DirBrowserDialog::~DirBrowserDialog() { BrowserDialog::~BrowserDialog() {
CFRelease(_titleRef); CFRelease(_titleRef);
} }
int DirBrowserDialog::runModal() { int BrowserDialog::runModal() {
NavDialogRef dialogRef; NavDialogRef dialogRef;
WindowRef windowRef = 0; WindowRef windowRef = 0;
NavDialogCreationOptions options; NavDialogCreationOptions options;
@ -72,7 +73,10 @@ int DirBrowserDialog::runModal() {
// options.message = CFSTR("Select your game directory"); // options.message = CFSTR("Select your game directory");
options.modality = kWindowModalityAppModal; 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); assert(err == noErr);
windowRef = NavDialogGetWindow(dialogRef); windowRef = NavDialogGetWindow(dialogRef);
@ -126,10 +130,11 @@ int DirBrowserDialog::runModal() {
* - others??? * - others???
*/ */
DirBrowserDialog::DirBrowserDialog(const char *title) BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
: Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10)
{ {
_isDirBrowser = dirBrowser;
_fileList = NULL; _fileList = NULL;
_currentPath = NULL; _currentPath = NULL;
@ -151,7 +156,7 @@ DirBrowserDialog::DirBrowserDialog(const char *title)
addButton(_w - (kButtonWidth+10), _h - 24, "Choose", kChooseCmd, 0); 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, // If no node has been set, or the last used one is now invalid,
// go back to the root/default dir. // go back to the root/default dir.
if (!_node.isValid()) { if (!_node.isValid()) {
@ -165,9 +170,10 @@ void DirBrowserDialog::open() {
Dialog::open(); Dialog::open();
} }
void DirBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) { switch (cmd) {
case kChooseCmd: { case kChooseCmd:
if (_isDirBrowser) {
// If nothing is selected in the list widget, choose the current dir. // If nothing is selected in the list widget, choose the current dir.
// Else, choose the dir that is selected. // Else, choose the dir that is selected.
int selection = _fileList->getSelected(); int selection = _fileList->getSelected();
@ -178,87 +184,7 @@ void DirBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 d
} }
setResult(1); setResult(1);
close(); close();
} } else {
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: {
int selection = _fileList->getSelected(); int selection = _fileList->getSelected();
if (selection < 0) if (selection < 0)
break; break;
@ -292,26 +218,26 @@ void FileBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32
} }
} }
void FileBrowserDialog::updateListing() { void BrowserDialog::updateListing() {
// Update the path display // Update the path display
_currentPath->setLabel(_node.path()); _currentPath->setLabel(_node.path());
// Read in the data from the file system // 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(); _nodeContent.sort();
// Populate the ListWidget // Populate the ListWidget
Common::StringList list; Common::StringList list;
int size = _nodeContent.size(); int size = _nodeContent.size();
int i; for (int i = 0; i < size; i++) {
if (!_isDirBrowser && _nodeContent[i].isDirectory())
for (i = 0; i < size; i++) {
if (_nodeContent[i].isDirectory())
list.push_back(_nodeContent[i].displayName() + "/"); list.push_back(_nodeContent[i].displayName() + "/");
else else
list.push_back(_nodeContent[i].displayName()); list.push_back(_nodeContent[i].displayName());
} }
_fileList->setList(list); _fileList->setList(list);
_fileList->scrollTo(0); _fileList->scrollTo(0);
@ -319,4 +245,6 @@ void FileBrowserDialog::updateListing() {
draw(); draw();
} }
#endif // MACOSX
} // End of namespace GUI } // End of namespace GUI

View file

@ -34,16 +34,14 @@ namespace GUI {
class ListWidget; class ListWidget;
class StaticTextWidget; class StaticTextWidget;
// TODO: Common parent class for DirBrowserDialog and FileBrowserDialog class BrowserDialog : public Dialog {
class DirBrowserDialog : public Dialog {
typedef Common::String String; typedef Common::String String;
typedef Common::StringList StringList; typedef Common::StringList StringList;
public: public:
DirBrowserDialog(const char *title); BrowserDialog(const char *title, bool dirBrowser);
#ifdef MACOSX #ifdef MACOSX
~DirBrowserDialog(); ~BrowserDialog();
virtual int runModal(); virtual int runModal();
#else #else
virtual void open(); virtual void open();
@ -62,35 +60,13 @@ protected:
FSList _nodeContent; FSList _nodeContent;
#endif #endif
FilesystemNode _choice; FilesystemNode _choice;
bool _isDirBrowser;
#ifndef MACOSX #ifndef MACOSX
void updateListing(); void updateListing();
#endif #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 } // End of namespace GUI
#endif #endif

View file

@ -370,16 +370,17 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
// Change path for the game // Change path for the game
case kCmdGameBrowser: { case kCmdGameBrowser: {
DirBrowserDialog *_browser = new DirBrowserDialog("Select additional game directory"); BrowserDialog browser("Select additional game directory", true);
if (_browser->runModal() > 0) { if (browser.runModal() > 0) {
// User made his choice... // User made his choice...
FilesystemNode dir(_browser->getResult()); FilesystemNode dir(browser.getResult());
// TODO: Verify the game can be found in the new directory... Best // TODO: Verify the game can be found in the new directory... Best
// done with optional specific gameid to pluginmgr detectgames? // done with optional specific gameid to pluginmgr detectgames?
// FSList files = dir.listDir(FilesystemNode::kListFilesOnly); // FSList files = dir.listDir(FilesystemNode::kListFilesOnly);
_gamePathWidget->setLabel(dir.path()); _gamePathWidget->setLabel(dir.path());
draw();
} }
draw(); draw();
break; 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) // Change path for extra game data (eg, using sword cutscenes when playing via CD)
case kCmdExtraBrowser: { case kCmdExtraBrowser: {
DirBrowserDialog *_browser = new DirBrowserDialog("Select additional game directory"); BrowserDialog browser("Select additional game directory", true);
if (_browser->runModal() > 0) { if (browser.runModal() > 0) {
// User made his choice... // User made his choice...
FilesystemNode dir(_browser->getResult()); FilesystemNode dir(browser.getResult());
_extraPathWidget->setLabel(dir.path()); _extraPathWidget->setLabel(dir.path());
draw();
} }
draw(); draw();
break; break;
} }
// Change path for stored save game (perm and temp) data // Change path for stored save game (perm and temp) data
case kCmdSaveBrowser: { case kCmdSaveBrowser: {
DirBrowserDialog *_browser = new DirBrowserDialog("Select directory for saved games"); BrowserDialog browser("Select directory for saved games", true);
if (_browser->runModal() > 0) { if (browser.runModal() > 0) {
// User made his choice... // User made his choice...
FilesystemNode dir(_browser->getResult()); FilesystemNode dir(browser.getResult());
_savePathWidget->setLabel(dir.path()); _savePathWidget->setLabel(dir.path());
draw();
} }
draw(); draw();
break; break;
@ -470,7 +473,7 @@ LauncherDialog::LauncherDialog(GameDetector &detector)
updateButtons(); updateButtons();
// Create file browser dialog // 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) { void LauncherDialog::selectGame(const String &name) {

View file

@ -28,7 +28,7 @@ class GameDetector;
namespace GUI { namespace GUI {
class DirBrowserDialog; class BrowserDialog;
class ListWidget; class ListWidget;
class LauncherDialog : public Dialog { class LauncherDialog : public Dialog {
@ -47,7 +47,7 @@ protected:
Widget *_removeButton; Widget *_removeButton;
StringList _domains; StringList _domains;
GameDetector &_detector; GameDetector &_detector;
DirBrowserDialog *_browser; BrowserDialog *_browser;
void updateListing(); void updateListing();
void updateButtons(); void updateButtons();

View file

@ -499,8 +499,8 @@ GlobalOptionsDialog::GlobalOptionsDialog(GameDetector &detector)
addButton(_w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0); addButton(_w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0);
// Create file browser dialogs // Create file browser dialogs
_dirBrowser = new DirBrowserDialog("Select directory for savegames"); _dirBrowser = new BrowserDialog("Select directory for savegames", true);
_fileBrowser = new FileBrowserDialog("Select SoundFont"); _fileBrowser = new BrowserDialog("Select SoundFont", false);
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
_keysDialog = new CEKeysDialog(); _keysDialog = new CEKeysDialog();
@ -571,6 +571,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
// User made his choice... // User made his choice...
FilesystemNode dir(_dirBrowser->getResult()); FilesystemNode dir(_dirBrowser->getResult());
_savePath->setLabel(dir.path()); _savePath->setLabel(dir.path());
draw();
// TODO - we should check if the directory is writeable before accepting it // TODO - we should check if the directory is writeable before accepting it
} }
break; break;
@ -579,6 +580,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
// User made his choice... // User made his choice...
FilesystemNode dir(_dirBrowser->getResult()); FilesystemNode dir(_dirBrowser->getResult());
_extraPath->setLabel(dir.path()); _extraPath->setLabel(dir.path());
draw();
} }
break; break;
case kChooseSoundFontCmd: case kChooseSoundFontCmd:
@ -586,6 +588,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
// User made his choice... // User made his choice...
FilesystemNode file(_fileBrowser->getResult()); FilesystemNode file(_fileBrowser->getResult());
_soundFont->setLabel(file.path()); _soundFont->setLabel(file.path());
draw();
} }
break; break;
#ifdef _WIN32_WCE #ifdef _WIN32_WCE

View file

@ -32,8 +32,7 @@ class GameDetector;
namespace GUI { namespace GUI {
class DirBrowserDialog; class BrowserDialog;
class FileBrowserDialog;
class CheckboxWidget; class CheckboxWidget;
class PopUpWidget; class PopUpWidget;
class SliderWidget; class SliderWidget;
@ -120,8 +119,8 @@ public:
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected: protected:
DirBrowserDialog *_dirBrowser; BrowserDialog *_dirBrowser;
FileBrowserDialog *_fileBrowser; BrowserDialog *_fileBrowser;
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
CEKeysDialog *_keysDialog; CEKeysDialog *_keysDialog;
#endif #endif