return [NSURL fileURLWithPath:stdStringToCocoa(aPath.str())];
}
+// 10.6 compiler won't accept block-scoped locals in Objective-C++,
+// so making these globals.
+static NSString* completion_path = nil;
+static SGPath completion_sgpath;
+
class CocoaFileDialog::CocoaFileDialogPrivate
{
public:
NSSavePanel* panel;
};
-CocoaFileDialog::CocoaFileDialog(const std::string& aTitle, FGFileDialog::Usage use) :
- FGFileDialog(aTitle, use)
+CocoaFileDialog::CocoaFileDialog(FGFileDialog::Usage use) :
+ FGFileDialog(use)
{
d.reset(new CocoaFileDialogPrivate);
if (use == USE_SAVE_FILE) {
[openPanel setCanChooseDirectories:YES];
}
} // of USE_OPEN_FILE or USE_CHOOSE_DIR -> building NSOpenPanel
+
+ [d->panel retain];
}
CocoaFileDialog::~CocoaFileDialog()
NSWindow* cocoaWindow = nil;
std::vector<osgViewer::GraphicsWindow*> windows;
globals->get_renderer()->getViewer()->getWindows(windows);
+
BOOST_FOREACH(osgViewer::GraphicsWindow* gw, windows) {
// OSG doesn't use RTTI, so no dynamic cast. Let's check the class type
// using OSG's own system, before we blindly static_cast<> and break
[d->panel setNameFieldStringValue:stdStringToCocoa(_placeholder)];
}
- NSMutableArray* extensions = [NSMutableArray arrayWithCapacity:0];
- BOOST_FOREACH(std::string ext, _filterPatterns) {
- if (!simgear::strutils::starts_with(ext, "*.")) {
- SG_LOG(SG_GENERAL, SG_INFO, "can't use pattern on Cococa:" << ext);
- continue;
+ if (_filterPatterns.empty()) {
+ [d->panel setAllowedFileTypes:nil];
+ } else {
+ NSMutableArray* extensions = [NSMutableArray arrayWithCapacity:0];
+ BOOST_FOREACH(std::string ext, _filterPatterns) {
+ if (!simgear::strutils::starts_with(ext, "*.")) {
+ SG_LOG(SG_GENERAL, SG_INFO, "can't use pattern on Cococa:" << ext);
+ continue;
+ }
+ [extensions addObject:stdStringToCocoa(ext.substr(2))];
}
- [extensions addObject:stdStringToCocoa(ext.substr(2))];
- }
- [d->panel setAllowedFileTypes:extensions];
+ [d->panel setAllowedFileTypes:extensions];
+ }
+
[d->panel setTitle:stdStringToCocoa(_title)];
if (_showHidden) {
[d->panel setShowsHiddenFiles:YES];
[d->panel beginSheetModalForWindow:cocoaWindow completionHandler:^(NSInteger result)
{
if (result == NSFileHandlingPanelOKButton) {
- NSString* path = [[d->panel URL] path];
+ completion_path = [[d->panel URL] path];
//NSLog(@"the URL is: %@", d->panel URL]);
- SGPath sgpath([path UTF8String]);
- _callback->onFileDialogDone(this, sgpath);
+ completion_sgpath = ([completion_path UTF8String]);
+ _callback->onFileDialogDone(this, completion_sgpath);
}
}];
}
+
+void CocoaFileDialog::close()
+{
+ [d->panel close];
+}
+