Cleanup.
This commit is contained in:
parent
8f60971dd6
commit
568ee4ceac
@ -21,9 +21,9 @@ class Split
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Split(const bx::StringView& _str, char _ch)
|
Split(const bx::StringView& _str, char _ch)
|
||||||
: m_str(_str)
|
: m_str(_str)
|
||||||
, m_token(_str.getPtr(), bx::strFind(_str, _ch).getPtr() )
|
, m_token(_str.getPtr(), bx::strFind(_str, _ch).getPtr() )
|
||||||
, m_ch(_ch)
|
, m_ch(_ch)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,10 +31,9 @@ public:
|
|||||||
{
|
{
|
||||||
bx::StringView result = m_token;
|
bx::StringView result = m_token;
|
||||||
m_token = bx::strTrim(
|
m_token = bx::strTrim(
|
||||||
bx::StringView(m_token.getTerm()+1
|
bx::StringView(m_token.getTerm()+1, bx::strFind(bx::StringView(m_token.getTerm()+1, m_str.getTerm() ), m_ch).getPtr())
|
||||||
, bx::strFind(bx::StringView(m_token.getTerm()+1, m_str.getTerm() ), m_ch).getPtr() )
|
, " \t\n"
|
||||||
, " \t\n"
|
);
|
||||||
);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,13 +48,12 @@ private:
|
|||||||
char m_ch;
|
char m_ch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool openFileSelectionDialog(
|
bool openFileSelectionDialog(
|
||||||
bx::FilePath& _inOutFilePath
|
bx::FilePath& _inOutFilePath
|
||||||
, FileSelectionDialogType::Enum _type
|
, FileSelectionDialogType::Enum _type
|
||||||
, const bx::StringView& _title
|
, const bx::StringView& _title
|
||||||
, const bx::StringView& _filter
|
, const bx::StringView& _filter
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
NSMutableArray* fileTypes = [NSMutableArray arrayWithCapacity:10];
|
NSMutableArray* fileTypes = [NSMutableArray arrayWithCapacity:10];
|
||||||
|
|
||||||
@ -66,12 +64,17 @@ bool openFileSelectionDialog(
|
|||||||
|
|
||||||
if (!sep.isEmpty() )
|
if (!sep.isEmpty() )
|
||||||
{
|
{
|
||||||
for (Split split(bx::strTrim(bx::StringView(sep.getPtr()+1, line.getTerm() ), " "), ' '); !split.isDone();)
|
for (Split split(bx::strTrim(bx::StringView(sep.getPtr()+1, line.getTerm() ), " "), ' ')
|
||||||
|
; !split.isDone()
|
||||||
|
;
|
||||||
|
)
|
||||||
{
|
{
|
||||||
const bx::StringView token = split.next();
|
const bx::StringView token = split.next();
|
||||||
|
|
||||||
if ( token.getLength() >= 3 && token.getPtr()[0] == '*'
|
if (token.getLength() >= 3
|
||||||
&& token.getPtr()[1] == '.' && bx::isAlphaNum(token.getPtr()[2]) )
|
&& token.getPtr()[0] == '*'
|
||||||
|
&& token.getPtr()[1] == '.'
|
||||||
|
&& bx::isAlphaNum(token.getPtr()[2]) )
|
||||||
{
|
{
|
||||||
NSString* extension = [[NSString alloc] initWithBytes:token.getPtr()+2 length:token.getLength()-2 encoding:NSASCIIStringEncoding];
|
NSString* extension = [[NSString alloc] initWithBytes:token.getPtr()+2 length:token.getLength()-2 encoding:NSASCIIStringEncoding];
|
||||||
[fileTypes addObject: extension];
|
[fileTypes addObject: extension];
|
||||||
@ -81,9 +84,12 @@ bool openFileSelectionDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
__block NSString* fileName = nil;
|
__block NSString* fileName = nil;
|
||||||
void (^invokeDialog)(void) = ^{
|
|
||||||
|
void (^invokeDialog)(void) =
|
||||||
|
^{
|
||||||
NSSavePanel* panel = nil;
|
NSSavePanel* panel = nil;
|
||||||
if ( FileSelectionDialogType::Open == _type)
|
|
||||||
|
if (FileSelectionDialogType::Open == _type)
|
||||||
{
|
{
|
||||||
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
|
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
|
||||||
openPanel.canChooseFiles = TRUE;
|
openPanel.canChooseFiles = TRUE;
|
||||||
@ -103,12 +109,14 @@ bool openFileSelectionDialog(
|
|||||||
if ([panel runModal] == NSModalResponseOK)
|
if ([panel runModal] == NSModalResponseOK)
|
||||||
{
|
{
|
||||||
NSURL* url = [panel URL];
|
NSURL* url = [panel URL];
|
||||||
|
|
||||||
if (nil != url)
|
if (nil != url)
|
||||||
{
|
{
|
||||||
fileName = [url path];
|
fileName = [url path];
|
||||||
[fileName retain];
|
[fileName retain];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[panel close];
|
[panel close];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,16 +129,17 @@ bool openFileSelectionDialog(
|
|||||||
bx::Semaphore semaphore;
|
bx::Semaphore semaphore;
|
||||||
bx::Semaphore* psemaphore = &semaphore;
|
bx::Semaphore* psemaphore = &semaphore;
|
||||||
|
|
||||||
CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop],
|
CFRunLoopPerformBlock(
|
||||||
kCFRunLoopCommonModes,
|
[[NSRunLoop mainRunLoop] getCFRunLoop]
|
||||||
^{
|
, kCFRunLoopCommonModes
|
||||||
invokeDialog();
|
, ^{
|
||||||
psemaphore->post();
|
invokeDialog();
|
||||||
});
|
psemaphore->post();
|
||||||
|
});
|
||||||
semaphore.wait();
|
semaphore.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fileName != nil )
|
if (fileName != nil)
|
||||||
{
|
{
|
||||||
_inOutFilePath.set([fileName UTF8String]);
|
_inOutFilePath.set([fileName UTF8String]);
|
||||||
[fileName release];
|
[fileName release];
|
||||||
@ -140,4 +149,4 @@ bool openFileSelectionDialog(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // BX_PLATFORM_OSX
|
||||||
|
Loading…
Reference in New Issue
Block a user