summaryrefslogtreecommitdiff
path: root/indra/newview/llfilepicker_mac.mm
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2023-05-17 18:05:05 +0300
committerAndrey Lihatskiy <alihatskiy@productengine.com>2023-05-17 18:05:05 +0300
commit033b04f3883a0cc9024f45b5e9a0d792cf6dbb77 (patch)
treeac49627e31aabda8aaa4b21c74c5aee2b2ea46e8 /indra/newview/llfilepicker_mac.mm
parent07dc391ab76a8860d04bfb001cdc686cd576663d (diff)
parent5a70639b7992842a9f74ec81b11bac56608b8f2e (diff)
Merge branch 'main' into DRTVWR-582-maint-U
# Conflicts: # indra/newview/llagentlistener.cpp # indra/newview/llcommanddispatcherlistener.cpp # indra/newview/llfilepicker_mac.mm # indra/newview/llworldmapview.cpp
Diffstat (limited to 'indra/newview/llfilepicker_mac.mm')
-rw-r--r--indra/newview/llfilepicker_mac.mm158
1 files changed, 86 insertions, 72 deletions
diff --git a/indra/newview/llfilepicker_mac.mm b/indra/newview/llfilepicker_mac.mm
index bca5b10c8a..4dd8bea4e1 100644
--- a/indra/newview/llfilepicker_mac.mm
+++ b/indra/newview/llfilepicker_mac.mm
@@ -71,31 +71,36 @@ NSOpenPanel *init_panel(const std::vector<std::string>* allowed_types, unsigned
return panel;
}
-std::unique_ptr<std::vector<std::string>> doLoadDialog(const std::vector<std::string>* allowed_types,
+std::unique_ptr<std::vector<std::string>> doLoadDialog(const std::vector<std::string>* allowed_types,
unsigned int flags)
{
- int result;
+ std::unique_ptr<std::vector<std::string>> outfiles;
- NSOpenPanel *panel = init_panel(allowed_types,flags);
-
- result = [panel runModal];
-
- std::unique_ptr<std::vector<std::string>> outfiles = nullptr;
+ @autoreleasepool
+ {
+ int result;
+ //Aura TODO: We could init a small window and release it at the end of this routine
+ //for a modeless interface.
- if (result == NSOKButton)
- {
- NSArray *filesToOpen = [panel URLs];
- int count = [filesToOpen count];
+ NSOpenPanel *panel = init_panel(allowed_types,flags);
- if (count > 0)
+ result = [panel runModal];
+
+ if (result == NSOKButton)
{
- outfiles = std::make_unique<std::vector<std::string>>();
- }
-
- for (int i=0; i<count; i++) {
- NSString *aFile = [filesToOpen objectAtIndex:i];
- std::string afilestr = [[aFile stringByStandardizingPath] UTF8String];
- outfiles->push_back(std::move(afilestr));
+ NSArray *filesToOpen = [panel URLs];
+ int i, count = [filesToOpen count];
+
+ if (count > 0)
+ {
+ outfiles.reset(new std::vector<std::string>);
+ }
+
+ for (i=0; i<count; i++) {
+ NSString *aFile = [[filesToOpen objectAtIndex:i] path];
+ std::string afilestr = std::string([aFile UTF8String]);
+ outfiles->push_back(afilestr);
+ }
}
}
return outfiles;
@@ -106,11 +111,14 @@ void doLoadDialogModeless(const std::vector<std::string>* allowed_types,
void (*callback)(bool, std::vector<std::string> &, void*),
void *userdata)
{
- // Note: might need to return and save this panel
- // so that it does not close immediately
- NSOpenPanel *panel = init_panel(allowed_types,flags);
+
+ @autoreleasepool
+ {
+ // Note: might need to return and save this panel
+ // so that it does not close immediately
+ NSOpenPanel *panel = init_panel(allowed_types,flags);
- [panel beginWithCompletionHandler:^(NSModalResponse result)
+ [panel beginWithCompletionHandler:^(NSModalResponse result)
{
std::vector<std::string> outfiles;
if (result == NSOKButton)
@@ -138,6 +146,7 @@ void doLoadDialogModeless(const std::vector<std::string>* allowed_types,
callback(false, outfiles, userdata);
}
}];
+ }
}
std::unique_ptr<std::string> doSaveDialog(const std::string* file,
@@ -146,29 +155,32 @@ std::unique_ptr<std::string> doSaveDialog(const std::string* file,
const std::string* extension,
unsigned int flags)
{
- NSSavePanel *panel = [NSSavePanel savePanel];
-
- NSString *extensionns = [NSString stringWithCString:extension->c_str() encoding:[NSString defaultCStringEncoding]];
- NSArray *fileType = [extensionns componentsSeparatedByString:@","];
-
- //[panel setMessage:@"Save Image File"];
- [panel setTreatsFilePackagesAsDirectories: ( flags & F_NAV_SUPPORT ) ];
- [panel setCanSelectHiddenExtension:true];
- [panel setAllowedFileTypes:fileType];
- NSString *fileName = [NSString stringWithCString:file->c_str() encoding:[NSString defaultCStringEncoding]];
-
- std::unique_ptr<std::string> outfile = nullptr;
- NSURL* url = [NSURL fileURLWithPath:fileName];
- [panel setNameFieldStringValue: fileName];
- [panel setDirectoryURL: url];
- if([panel runModal] ==
- NSFileHandlingPanelOKButton)
- {
- NSURL* url = [panel URL];
- NSString* p = [url path];
- outfile = std::make_unique<std::string>( [p UTF8String] );
- // write the file
- }
+ std::unique_ptr<std::string> outfile;
+ @autoreleasepool
+ {
+ NSSavePanel *panel = [NSSavePanel savePanel];
+
+ NSString *extensionns = [NSString stringWithCString:extension->c_str() encoding:[NSString defaultCStringEncoding]];
+ NSArray *fileType = [extensionns componentsSeparatedByString:@","];
+
+ //[panel setMessage:@"Save Image File"];
+ [panel setTreatsFilePackagesAsDirectories: ( flags & F_NAV_SUPPORT ) ];
+ [panel setCanSelectHiddenExtension:true];
+ [panel setAllowedFileTypes:fileType];
+ NSString *fileName = [NSString stringWithCString:file->c_str() encoding:[NSString defaultCStringEncoding]];
+
+ NSURL* url = [NSURL fileURLWithPath:fileName];
+ [panel setNameFieldStringValue: fileName];
+ [panel setDirectoryURL: url];
+ if([panel runModal] ==
+ NSFileHandlingPanelOKButton)
+ {
+ NSURL* url = [panel URL];
+ NSString* p = [url path];
+ outfile.reset(new std::string([p UTF8String]));
+ // write the file
+ }
+ }
return outfile;
}
@@ -180,38 +192,40 @@ void doSaveDialogModeless(const std::string* file,
void (*callback)(bool, std::string&, void*),
void *userdata)
{
- NSSavePanel *panel = [NSSavePanel savePanel];
+ @autoreleasepool {
+ NSSavePanel *panel = [NSSavePanel savePanel];
- NSString *extensionns = [NSString stringWithCString:extension->c_str() encoding:[NSString defaultCStringEncoding]];
- NSArray *fileType = [extensionns componentsSeparatedByString:@","];
+ NSString *extensionns = [NSString stringWithCString:extension->c_str() encoding:[NSString defaultCStringEncoding]];
+ NSArray *fileType = [extensionns componentsSeparatedByString:@","];
- //[panel setMessage:@"Save Image File"];
- [panel setTreatsFilePackagesAsDirectories: ( flags & F_NAV_SUPPORT ) ];
- [panel setCanSelectHiddenExtension:true];
- [panel setAllowedFileTypes:fileType];
- NSString *fileName = [NSString stringWithCString:file->c_str() encoding:[NSString defaultCStringEncoding]];
+ //[panel setMessage:@"Save Image File"];
+ [panel setTreatsFilePackagesAsDirectories: ( flags & F_NAV_SUPPORT ) ];
+ [panel setCanSelectHiddenExtension:true];
+ [panel setAllowedFileTypes:fileType];
+ NSString *fileName = [NSString stringWithCString:file->c_str() encoding:[NSString defaultCStringEncoding]];
- NSURL* url = [NSURL fileURLWithPath:fileName];
- [panel setNameFieldStringValue: fileName];
- [panel setDirectoryURL: url];
+ NSURL* url = [NSURL fileURLWithPath:fileName];
+ [panel setNameFieldStringValue: fileName];
+ [panel setDirectoryURL: url];
- [panel beginWithCompletionHandler:^(NSModalResponse result)
- {
- if (result == NSOKButton)
- {
- NSURL* url = [panel URL];
- NSString* p = [url path];
- std::string outfile([p UTF8String]);
+ [panel beginWithCompletionHandler:^(NSModalResponse result)
+ {
+ if (result == NSOKButton)
+ {
+ NSURL* url = [panel URL];
+ NSString* p = [url path];
+ std::string outfile([p UTF8String]);
- callback(true, outfile, userdata);
- }
- else // cancel
- {
- std::string outfile;
- callback(false, outfile, userdata);
- }
- }];
+ callback(true, outfile, userdata);
+ }
+ else // cancel
+ {
+ std::string outfile;
+ callback(false, outfile, userdata);
+ }
+ }];
+ }
}
#endif