mirror of
https://github.com/libretro/scummvm.git
synced 2024-11-30 21:00:39 +00:00
native directory browser on Mac OS X
svn-id: r12694
This commit is contained in:
parent
cd369ebad2
commit
51733fbe3e
@ -27,6 +27,82 @@
|
||||
|
||||
namespace GUI {
|
||||
|
||||
#ifdef MACOSX
|
||||
/* On Mac OS X, use the native file selector dialog. We could do the same for
|
||||
* other operating systems.
|
||||
*/
|
||||
|
||||
BrowserDialog::BrowserDialog(const char *title)
|
||||
: Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) {
|
||||
_choice = NULL;
|
||||
_titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding());
|
||||
}
|
||||
|
||||
BrowserDialog::~BrowserDialog() {
|
||||
delete _choice;
|
||||
CFRelease(_titleRef);
|
||||
}
|
||||
|
||||
int BrowserDialog::runModal() {
|
||||
NavDialogRef dialogRef;
|
||||
NavDialogCreationOptions options;
|
||||
NavUserAction result;
|
||||
NavReplyRecord reply;
|
||||
OSStatus err;
|
||||
|
||||
delete _choice;
|
||||
_choice = 0;
|
||||
|
||||
// Temporarily show the real mouse
|
||||
ShowCursor();
|
||||
|
||||
err = NavGetDefaultDialogCreationOptions(&options);
|
||||
assert(err == noErr);
|
||||
options.windowTitle = _titleRef;
|
||||
options.message = CFSTR("This is a test!");
|
||||
options.modality = kWindowModalityAppModal;
|
||||
|
||||
err = NavCreateChooseFolderDialog(&options, 0, 0, 0, &dialogRef);
|
||||
assert(err == noErr);
|
||||
|
||||
err = NavDialogRun(dialogRef);
|
||||
assert(err == noErr);
|
||||
|
||||
HideCursor();
|
||||
|
||||
result = NavDialogGetUserAction(dialogRef);
|
||||
|
||||
if (result == kNavUserActionChoose) {
|
||||
err = NavDialogGetReply(dialogRef, &reply);
|
||||
assert(err == noErr);
|
||||
|
||||
if (reply.validRecord && err == noErr) {
|
||||
SInt32 theCount;
|
||||
AECountItems(&reply.selection, &theCount);
|
||||
assert(theCount == 1);
|
||||
|
||||
AEKeyword keyword;
|
||||
FSRef ref;
|
||||
char buf[4096];
|
||||
err = AEGetNthPtr(&reply.selection, 1, typeFSRef, &keyword, NULL, &ref, sizeof(ref), NULL);
|
||||
assert(err == noErr);
|
||||
err = FSRefMakePath(&ref, (UInt8*)buf, sizeof(buf)-1);
|
||||
assert(err == noErr);
|
||||
|
||||
_choice = FilesystemNode::getNodeForPath(buf);
|
||||
}
|
||||
|
||||
err = NavDisposeReply(&reply);
|
||||
assert(err == noErr);
|
||||
}
|
||||
|
||||
NavDialogDispose(dialogRef);
|
||||
|
||||
return (_choice != 0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* 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
|
||||
@ -157,4 +233,6 @@ void BrowserDialog::updateListing() {
|
||||
draw();
|
||||
}
|
||||
|
||||
#endif // MACOSX
|
||||
|
||||
} // End of namespace GUI
|
||||
|
@ -25,6 +25,10 @@
|
||||
#include "common/str.h"
|
||||
#include "common/list.h"
|
||||
|
||||
#ifdef MACOSX
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
class FilesystemNode;
|
||||
class FSList;
|
||||
|
||||
@ -40,20 +44,31 @@ public:
|
||||
BrowserDialog(const char *title);
|
||||
virtual ~BrowserDialog();
|
||||
|
||||
#ifdef MACOSX
|
||||
virtual int runModal();
|
||||
#else
|
||||
virtual void open();
|
||||
virtual void close();
|
||||
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
|
||||
#endif
|
||||
|
||||
FilesystemNode *getResult() { return _choice; };
|
||||
|
||||
|
||||
protected:
|
||||
#ifdef MACOSX
|
||||
CFStringRef _titleRef;
|
||||
#else
|
||||
ListWidget *_fileList;
|
||||
StaticTextWidget*_currentPath;
|
||||
FilesystemNode *_node;
|
||||
FSList *_nodeContent;
|
||||
#endif
|
||||
FilesystemNode *_choice;
|
||||
|
||||
#ifndef MACOSX
|
||||
void updateListing();
|
||||
#endif
|
||||
};
|
||||
|
||||
} // End of namespace GUI
|
||||
|
Loading…
Reference in New Issue
Block a user