Skip to content

Commit bae1e10

Browse files
committed
#4322 Upload>Model button is sometimes disabled on MacOS
1 parent 449a5a1 commit bae1e10

File tree

2 files changed

+59
-21
lines changed

2 files changed

+59
-21
lines changed

indra/newview/llfilepicker_mac.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
std::unique_ptr<std::vector<std::string>> doLoadDialog(const std::vector<std::string>* allowed_types,
4343
unsigned int flags);
4444

45+
// doLoadDialogModeless if window does not exists creates a modeless
46+
// window, if it does exist, creates a 'sheet' that does not block
47+
// thead but blocks window interractions
4548
void doLoadDialogModeless(const std::vector<std::string>* allowed_types,
4649
unsigned int flags,
4750
void (*callback)(bool, std::vector<std::string>&, void*),

indra/newview/llfilepicker_mac.mm

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,38 +114,73 @@ void doLoadDialogModeless(const std::vector<std::string>* allowed_types,
114114

115115
@autoreleasepool
116116
{
117-
// Note: might need to return and save this panel
118-
// so that it does not close immediately
119117
NSOpenPanel *panel = init_panel(allowed_types,flags);
118+
NSWindow *mainWindow = [NSApp mainWindow];
120119

121-
[panel beginWithCompletionHandler:^(NSModalResponse result)
120+
if (mainWindow)
122121
{
123-
std::vector<std::string> outfiles;
124-
if (result == NSModalResponseOK)
122+
[panel beginSheetModalForWindow:mainWindow
123+
completionHandler:^(NSModalResponse result)
125124
{
126-
NSArray *filesToOpen = [panel URLs];
127-
int i, count = [filesToOpen count];
128-
129-
if (count > 0)
125+
std::vector<std::string> outfiles;
126+
if (result == NSModalResponseOK)
130127
{
131-
132-
for (i=0; i<count; i++) {
133-
NSString *aFile = [[filesToOpen objectAtIndex:i] path];
134-
std::string *afilestr = new std::string([aFile UTF8String]);
135-
outfiles.push_back(*afilestr);
128+
NSArray *filesToOpen = [panel URLs];
129+
int i, count = [filesToOpen count];
130+
131+
if (count > 0)
132+
{
133+
134+
for (i=0; i<count; i++) {
135+
NSString *aFile = [[filesToOpen objectAtIndex:i] path];
136+
std::string *afilestr = new std::string([aFile UTF8String]);
137+
outfiles.push_back(*afilestr);
138+
}
139+
callback(true, outfiles, userdata);
140+
}
141+
else // no valid result
142+
{
143+
callback(false, outfiles, userdata);
136144
}
137-
callback(true, outfiles, userdata);
138145
}
139-
else // no valid result
146+
else // cancel
140147
{
141148
callback(false, outfiles, userdata);
142149
}
143-
}
144-
else // cancel
150+
}];
151+
}
152+
else
153+
{
154+
//present as modeless window
155+
[panel beginWithCompletionHandler:^(NSModalResponse result)
145156
{
146-
callback(false, outfiles, userdata);
147-
}
148-
}];
157+
std::vector<std::string> outfiles;
158+
if (result == NSModalResponseOK)
159+
{
160+
NSArray *filesToOpen = [panel URLs];
161+
int i, count = [filesToOpen count];
162+
163+
if (count > 0)
164+
{
165+
166+
for (i=0; i<count; i++) {
167+
NSString *aFile = [[filesToOpen objectAtIndex:i] path];
168+
std::string *afilestr = new std::string([aFile UTF8String]);
169+
outfiles.push_back(*afilestr);
170+
}
171+
callback(true, outfiles, userdata);
172+
}
173+
else // no valid result
174+
{
175+
callback(false, outfiles, userdata);
176+
}
177+
}
178+
else // cancel
179+
{
180+
callback(false, outfiles, userdata);
181+
}
182+
}];
183+
}
149184
}
150185
}
151186

0 commit comments

Comments
 (0)