From 568ee4ceac49c012a4dd1d5ef3d837374d5adfe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Wed, 18 Aug 2021 09:27:12 -0700 Subject: [PATCH] Cleanup. --- examples/common/entry/dialog_darwin.mm | 77 ++++++++++++++------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/examples/common/entry/dialog_darwin.mm b/examples/common/entry/dialog_darwin.mm index f08b45794..a1c2599ce 100644 --- a/examples/common/entry/dialog_darwin.mm +++ b/examples/common/entry/dialog_darwin.mm @@ -21,57 +21,60 @@ class Split { public: Split(const bx::StringView& _str, char _ch) - : m_str(_str) - , m_token(_str.getPtr(), bx::strFind(_str, _ch).getPtr() ) - , m_ch(_ch) + : m_str(_str) + , m_token(_str.getPtr(), bx::strFind(_str, _ch).getPtr() ) + , m_ch(_ch) { } - + bx::StringView next() { bx::StringView result = m_token; m_token = bx::strTrim( - bx::StringView(m_token.getTerm()+1 - , bx::strFind(bx::StringView(m_token.getTerm()+1, m_str.getTerm() ), m_ch).getPtr() ) - , " \t\n" - ); + bx::StringView(m_token.getTerm()+1, bx::strFind(bx::StringView(m_token.getTerm()+1, m_str.getTerm() ), m_ch).getPtr()) + , " \t\n" + ); return result; } - + bool isDone() const { return m_token.isEmpty(); } - + private: const bx::StringView& m_str; bx::StringView m_token; char m_ch; }; - bool openFileSelectionDialog( - bx::FilePath& _inOutFilePath - , FileSelectionDialogType::Enum _type - , const bx::StringView& _title - , const bx::StringView& _filter - ) + bx::FilePath& _inOutFilePath + , FileSelectionDialogType::Enum _type + , const bx::StringView& _title + , const bx::StringView& _filter + ) { NSMutableArray* fileTypes = [NSMutableArray arrayWithCapacity:10]; - + for (bx::LineReader lr(_filter); !lr.isDone();) { const bx::StringView line = lr.next(); const bx::StringView sep = bx::strFind(line, '|'); - + 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(); - - if ( token.getLength() >= 3 && token.getPtr()[0] == '*' - && token.getPtr()[1] == '.' && bx::isAlphaNum(token.getPtr()[2]) ) + + if (token.getLength() >= 3 + && 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]; [fileTypes addObject: extension]; @@ -79,11 +82,14 @@ bool openFileSelectionDialog( } } } - + __block NSString* fileName = nil; - void (^invokeDialog)(void) = ^{ + + void (^invokeDialog)(void) = + ^{ NSSavePanel* panel = nil; - if ( FileSelectionDialogType::Open == _type) + + if (FileSelectionDialogType::Open == _type) { NSOpenPanel* openPanel = [NSOpenPanel openPanel]; openPanel.canChooseFiles = TRUE; @@ -103,12 +109,14 @@ bool openFileSelectionDialog( if ([panel runModal] == NSModalResponseOK) { NSURL* url = [panel URL]; + if (nil != url) { fileName = [url path]; [fileName retain]; } } + [panel close]; }; @@ -121,23 +129,24 @@ bool openFileSelectionDialog( bx::Semaphore semaphore; bx::Semaphore* psemaphore = &semaphore; - CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop], - kCFRunLoopCommonModes, - ^{ - invokeDialog(); - psemaphore->post(); - }); + CFRunLoopPerformBlock( + [[NSRunLoop mainRunLoop] getCFRunLoop] + , kCFRunLoopCommonModes + , ^{ + invokeDialog(); + psemaphore->post(); + }); semaphore.wait(); } - if ( fileName != nil ) + if (fileName != nil) { _inOutFilePath.set([fileName UTF8String]); [fileName release]; return true; } - + return false; } -#endif +#endif // BX_PLATFORM_OSX