aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorMax Horn2005-04-16 17:55:09 +0000
committerMax Horn2005-04-16 17:55:09 +0000
commitaea451f092a90bdc28bc8bd82508ec40b9920868 (patch)
tree54e7afc9cd5318b5d7413482509299fe5a0351bd /gui
parentcaf142657dad21aa80a09387e34786591b2088ed (diff)
downloadscummvm-rg350-aea451f092a90bdc28bc8bd82508ec40b9920868.tar.gz
scummvm-rg350-aea451f092a90bdc28bc8bd82508ec40b9920868.tar.bz2
scummvm-rg350-aea451f092a90bdc28bc8bd82508ec40b9920868.zip
Reunify DirBrowserDialog and FileBrowserDialog; implemented file browser mode for OSX, too; fixed some memory leaks in the launcher
svn-id: r17639
Diffstat (limited to 'gui')
-rw-r--r--gui/browser.cpp120
-rw-r--r--gui/browser.h32
-rw-r--r--gui/launcher.cpp23
-rw-r--r--gui/launcher.h4
-rw-r--r--gui/options.cpp7
-rw-r--r--gui/options.h7
6 files changed, 51 insertions, 142 deletions
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