- Make the Cocoa IWAD picker behave like the others: Double-clicking an entry starts

it, as does pressing Return, and pressing Escape is equivalent to the Cancel button.



SVN r2526 (trunk)
This commit is contained in:
Randy Heit 2010-08-13 00:08:51 +00:00
parent a27304baac
commit 4f03442a7a

View file

@ -115,6 +115,7 @@ static const char* const tableHeaders[NUM_COLUMNS] = { "IWAD", "Game" };
} }
- (void)buttonPressed:(id) sender; - (void)buttonPressed:(id) sender;
- (void)doubleClicked:(id) sender;
- (void)makeLabel:(NSTextField *)label:(const char*) str; - (void)makeLabel:(NSTextField *)label:(const char*) str;
- (int)pickIWad:(WadStuff *)wads:(int) numwads:(bool) showwin:(int) defaultiwad; - (int)pickIWad:(WadStuff *)wads:(int) numwads:(bool) showwin:(int) defaultiwad;
@end @end
@ -130,6 +131,15 @@ static const char* const tableHeaders[NUM_COLUMNS] = { "IWAD", "Game" };
[app stopModal]; [app stopModal];
} }
- (void)doubleClicked:(id) sender;
{
if ([sender clickedRow] >= 0)
{
[window orderOut:self];
[app stopModal];
}
}
// Apparently labels in Cocoa are uneditable text fields, so lets make this a // Apparently labels in Cocoa are uneditable text fields, so lets make this a
// little more automated. // little more automated.
- (void)makeLabel:(NSTextField *)label:(const char*) str - (void)makeLabel:(NSTextField *)label:(const char*) str
@ -148,18 +158,18 @@ static const char* const tableHeaders[NUM_COLUMNS] = { "IWAD", "Game" };
app = [NSApplication sharedApplication]; app = [NSApplication sharedApplication];
id windowTitle = [NSString stringWithCString:GAMESIG " " DOTVERSIONSTR ": Select an IWAD to use"]; id windowTitle = [NSString stringWithCString:GAMESIG " " DOTVERSIONSTR ": Select an IWAD to use"];
NSRect frame = NSMakeRect(0, 0, 400, 450); NSRect frame = NSMakeRect(0, 0, 440, 450);
window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]; window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
[window setTitle:windowTitle]; [window setTitle:windowTitle];
NSTextField *description = [[NSTextField alloc] initWithFrame:NSMakeRect(22, 379, 372, 50)]; NSTextField *description = [[NSTextField alloc] initWithFrame:NSMakeRect(22, 379, 412, 50)];
[self makeLabel:description:"ZDoom found more than one IWAD\nSelect from the list below to determine which one to use:"]; [self makeLabel:description:"ZDoom found more than one IWAD\nSelect from the list below to determine which one to use:"];
[[window contentView] addSubview:description]; [[window contentView] addSubview:description];
[description release]; [description release];
// Commented out version would account for an additional parameters box. // Commented out version would account for an additional parameters box.
//NSScrollView *iwadScroller = [[NSScrollView alloc] initWithFrame:NSMakeRect(20, 103, 362, 288)]; //NSScrollView *iwadScroller = [[NSScrollView alloc] initWithFrame:NSMakeRect(20, 103, 412, 288)];
NSScrollView *iwadScroller = [[NSScrollView alloc] initWithFrame:NSMakeRect(20, 50, 362, 341)]; NSScrollView *iwadScroller = [[NSScrollView alloc] initWithFrame:NSMakeRect(20, 50, 412, 341)];
NSTableView *iwadTable = [[NSTableView alloc] initWithFrame:[iwadScroller bounds]]; NSTableView *iwadTable = [[NSTableView alloc] initWithFrame:[iwadScroller bounds]];
IWADTableData *tableData = [[IWADTableData alloc] init:wads:numwads]; IWADTableData *tableData = [[IWADTableData alloc] init:wads:numwads];
for(int i = 0;i < NUM_COLUMNS;i++) for(int i = 0;i < NUM_COLUMNS;i++)
@ -177,6 +187,8 @@ static const char* const tableHeaders[NUM_COLUMNS] = { "IWAD", "Game" };
[iwadScroller setHasVerticalScroller:YES]; [iwadScroller setHasVerticalScroller:YES];
[iwadTable setDataSource:tableData]; [iwadTable setDataSource:tableData];
[iwadTable sizeToFit]; [iwadTable sizeToFit];
[iwadTable setDoubleAction:@selector(doubleClicked:)];
[iwadTable setTarget:self];
NSIndexSet *selection = [[NSIndexSet alloc] initWithIndex:defaultiwad]; NSIndexSet *selection = [[NSIndexSet alloc] initWithIndex:defaultiwad];
[iwadTable selectRowIndexes:selection byExtendingSelection:NO]; [iwadTable selectRowIndexes:selection byExtendingSelection:NO];
[selection release]; [selection release];
@ -198,18 +210,20 @@ static const char* const tableHeaders[NUM_COLUMNS] = { "IWAD", "Game" };
[dontAsk setState:(showwin ? NSOffState : NSOnState)]; [dontAsk setState:(showwin ? NSOffState : NSOnState)];
[[window contentView] addSubview:dontAsk];*/ [[window contentView] addSubview:dontAsk];*/
okButton = [[NSButton alloc] initWithFrame:NSMakeRect(196, 12, 96, 32)]; okButton = [[NSButton alloc] initWithFrame:NSMakeRect(236, 12, 96, 32)];
[okButton setTitle:[NSString stringWithCString:"OK"]]; [okButton setTitle:[NSString stringWithCString:"OK"]];
[okButton setBezelStyle:NSRoundedBezelStyle]; [okButton setBezelStyle:NSRoundedBezelStyle];
[okButton setAction:@selector(buttonPressed:)]; [okButton setAction:@selector(buttonPressed:)];
[okButton setTarget:self]; [okButton setTarget:self];
[okButton setKeyEquivalent:@"\r"];
[[window contentView] addSubview:okButton]; [[window contentView] addSubview:okButton];
cancelButton = [[NSButton alloc] initWithFrame:NSMakeRect(292, 12, 96, 32)]; cancelButton = [[NSButton alloc] initWithFrame:NSMakeRect(332, 12, 96, 32)];
[cancelButton setTitle:[NSString stringWithCString:"Cancel"]]; [cancelButton setTitle:[NSString stringWithCString:"Cancel"]];
[cancelButton setBezelStyle:NSRoundedBezelStyle]; [cancelButton setBezelStyle:NSRoundedBezelStyle];
[cancelButton setAction:@selector(buttonPressed:)]; [cancelButton setAction:@selector(buttonPressed:)];
[cancelButton setTarget:self]; [cancelButton setTarget:self];
[cancelButton setKeyEquivalent:@"\033"];
[[window contentView] addSubview:cancelButton]; [[window contentView] addSubview:cancelButton];
[window center]; [window center];