macos_gui.mm 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2022 DeepMind Technologies Limited
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <sstream>
  15. #include <string>
  16. #include <Cocoa/Cocoa.h>
  17. std::string GetSavePath(const char* filename) {
  18. NSSavePanel* panel = [NSSavePanel savePanel];
  19. NSURL* userDocumentsDir = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory
  20. inDomains:NSUserDomainMask].firstObject;
  21. [panel setDirectoryURL:userDocumentsDir];
  22. [panel setNameFieldStringValue:[NSString stringWithUTF8String:filename]];
  23. if ([panel runModal] == NSModalResponseOK) {
  24. std::ostringstream s;
  25. s << [panel.URL.path cStringUsingEncoding:NSUTF8StringEncoding];
  26. return s.str();
  27. } else {
  28. return "";
  29. }
  30. }
  31. #ifdef __AVX__
  32. void DisplayErrorDialogBox(const char* title, const char* msg) {
  33. NSAlert *alert = [[[NSAlert alloc] init] autorelease];
  34. [alert setMessageText:[NSString stringWithUTF8String:title]];
  35. [alert setInformativeText:[NSString stringWithUTF8String:msg]];
  36. [alert setAlertStyle:NSAlertStyleCritical];
  37. [alert addButtonWithTitle:@"Exit"];
  38. [alert runModal];
  39. }
  40. #endif