Created
November 11, 2014 14:07
-
-
Save nariakiiwatani/ecffbac4bd21417784c3 to your computer and use it in GitHub Desktop.
Combobox dialog for Cocoa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Dialog.h" | |
#include <Cocoa/Cocoa.h> | |
std::string systemComboBoxSelector(const std::string &question, const std::vector<std::string> &list) | |
{ | |
NSAlert *alert = [[[NSAlert alloc] init] autorelease]; | |
[alert addButtonWithTitle:@"OK"]; | |
// [alert addButtonWithTitle:@"Cancel"]; | |
[alert setMessageText:[NSString stringWithCString:question.c_str() | |
encoding:NSUTF8StringEncoding]]; | |
// create combo box | |
NSComboBox* box = [[NSComboBox alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0,0,300,25))]; | |
for(auto name : list) { | |
[box addItemWithObjectValue:[NSString stringWithCString:name.c_str() encoding:NSUTF8StringEncoding]]; | |
} | |
if(!list.empty()) { | |
[box selectItemAtIndex:0]; | |
} | |
[alert setAccessoryView:box]; | |
NSInteger returnCode = [alert runModal]; | |
std::string text = ""; | |
if ( returnCode == NSAlertFirstButtonReturn ) | |
text = [[box stringValue] UTF8String]; | |
return text; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <string> | |
#include <vector> | |
std::string systemComboBoxSelector(const std::string &question, const std::vector<std::string> &list); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment