[Scummvm-cvs-logs] CVS: scummvm/gui browser.cpp,1.28,1.29 browser.h,1.17,1.18 launcher.cpp,1.113,1.114 launcher.h,1.22,1.23 options.cpp,1.74,1.75 options.h,1.27,1.28

Max Horn fingolfin at users.sourceforge.net
Sat Apr 16 10:56:44 CEST 2005


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22665

Modified Files:
	browser.cpp browser.h launcher.cpp launcher.h options.cpp 
	options.h 
Log Message:
Reunify DirBrowserDialog and FileBrowserDialog; implemented file browser mode for OSX, too; fixed some memory leaks in the launcher

Index: browser.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- browser.cpp	10 Apr 2005 14:49:57 -0000	1.28
+++ browser.cpp	16 Apr 2005 17:55:08 -0000	1.29
@@ -40,16 +40,17 @@
  * 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 @@
 //	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 @@
  * - 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 @@
 	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 @@
 	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 @@
 			}
 			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::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 @@
 	draw();
 }
 
+#endif	// MACOSX
+
 } // End of namespace GUI

Index: browser.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- browser.h	10 Apr 2005 14:33:44 -0000	1.17
+++ browser.h	16 Apr 2005 17:55:08 -0000	1.18
@@ -34,16 +34,14 @@
 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 @@
 	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

Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- launcher.cpp	13 Apr 2005 00:11:41 -0000	1.113
+++ launcher.cpp	16 Apr 2005 17:55:08 -0000	1.114
@@ -370,16 +370,17 @@
 
 	// 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 @@
 
 	// 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 @@
 	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) {

Index: launcher.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- launcher.h	10 Apr 2005 14:33:44 -0000	1.22
+++ launcher.h	16 Apr 2005 17:55:09 -0000	1.23
@@ -28,7 +28,7 @@
 
 namespace GUI {
 
-class DirBrowserDialog;
+class BrowserDialog;
 class ListWidget;
 
 class LauncherDialog : public Dialog {
@@ -47,7 +47,7 @@
 	Widget			*_removeButton;
 	StringList		_domains;
 	GameDetector 	&_detector;
-	DirBrowserDialog	*_browser;
+	BrowserDialog	*_browser;
 
 	void updateListing();
 	void updateButtons();

Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- options.cpp	13 Apr 2005 00:11:42 -0000	1.74
+++ options.cpp	16 Apr 2005 17:55:09 -0000	1.75
@@ -499,8 +499,8 @@
 	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 @@
 			// 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 @@
 			// User made his choice...
 			FilesystemNode dir(_dirBrowser->getResult());
 			_extraPath->setLabel(dir.path());
+			draw();
 		}
 		break;
 	case kChooseSoundFontCmd:
@@ -586,6 +588,7 @@
 			// User made his choice...
 			FilesystemNode file(_fileBrowser->getResult());
 			_soundFont->setLabel(file.path());
+			draw();
 		}
 		break;
 #ifdef _WIN32_WCE

Index: options.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- options.h	13 Apr 2005 00:11:42 -0000	1.27
+++ options.h	16 Apr 2005 17:55:09 -0000	1.28
@@ -32,8 +32,7 @@
 
 namespace GUI {
 
-class DirBrowserDialog;
-class FileBrowserDialog; 
+class BrowserDialog;
 class CheckboxWidget;
 class PopUpWidget;
 class SliderWidget;
@@ -120,8 +119,8 @@
 	void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 
 protected:
-	DirBrowserDialog *_dirBrowser;
-	FileBrowserDialog *_fileBrowser;
+	BrowserDialog *_dirBrowser;
+	BrowserDialog *_fileBrowser;
 #ifdef _WIN32_WCE
 	CEKeysDialog *_keysDialog;
 #endif





More information about the Scummvm-git-logs mailing list