File: MDialogs.m

package info (click to toggle)
mysql-query-browser 1.1.6-1sarge0
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 36,320 kB
  • ctags: 24,680
  • sloc: pascal: 203,479; xml: 136,561; ansic: 47,502; cpp: 28,926; sh: 12,433; objc: 4,823; java: 1,849; php: 1,485; python: 1,225; sql: 1,128; makefile: 872
file content (135 lines) | stat: -rw-r--r-- 3,294 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
//  MDialogs.m
//  MySQLGUICommon
//
//  Created by Alfredo Kojima on Sat Jul 10 2004.
//  Copyright (c) 2004 MySQL AB. All rights reserved.
//

#import "MDialogs.h"

@implementation MStringRequestSheet

+ (MStringRequestSheet*)sheetWithTitle:(NSString*)title labels:(NSArray*)labels;
{
  return [[[MStringRequestSheet alloc] initWithTitle:title labels:labels] autorelease];
}


- (id)initWithTitle:(NSString*)title labels:(NSArray*)labels
{
  NSRect contentRect;
  
  contentRect= NSMakeRect(0.0, 0.0, 420.0, 128.0+([labels count]-1)*(22.0+8.0));
  
  self= [super initWithContentRect:contentRect 
                         styleMask:NSTitledWindowMask
                           backing:NSBackingStoreBuffered 
                             defer:YES];
  if (self)
  {
    NSView *contentView= [[NSView alloc] initWithFrame:contentRect];
	id w;
	unsigned int i;
	
    [self setContentView:contentView];
    [contentView release];
    [self setHasShadow:YES];
    
	w= [[NSTextField alloc] initWithFrame:NSMakeRect(17.0, contentRect.size.height-34.0, 387.0, 17.0)];
    [w setStringValue:title];
    [contentView addSubview:w];
    [w release];
	[w setFont:[NSFont boldSystemFontOfSize:[NSFont systemFontSize]]];
    [w setAlignment:NSCenterTextAlignment];
    [w setEditable:NO];
    [w setDrawsBackground:NO];
    [w setBordered:NO];

	form= [[NSForm alloc] initWithFrame:NSMakeRect(20.0, 59.0, 
												   380.0, 22+([labels count]-1)*(22.0+8.0))];
	[form setCellSize:NSMakeSize([form cellSize].width, 22.0)];
	[contentView addSubview:form];
	[form release];
	for (i= 0; i < [labels count]; i++)
	{
	  [form addEntry:[labels objectAtIndex:i]];
	}
    w= [[NSButton alloc] initWithFrame:NSMakeRect(316.0, 11.0, 90.0, 32.0)];
    [contentView addSubview:w];
    [w setTitle:@"OK"];
    [w release];
    [w setAction:@selector(ok:)];
    [w setTarget:self];
    [[w cell] setBezelStyle:NSRoundedBezelStyle];
    [self setDefaultButtonCell:[w cell]];
    
    w= [[NSButton alloc] initWithFrame:NSMakeRect(224.0, 11.0, 90.0, 32.0)];
    [contentView addSubview:w];
    [w setTitle:@"Cancel"];
    [w release];
    [w setAction:@selector(cancel:)];
    [w setTarget:self];
    [[w cell] setBezelStyle:NSRoundedBezelStyle];
  }
  return self;
}


- (void)cancel:(id)sender
{
  [NSApp endSheet:self];
  canceled= YES;
}

- (void)ok:(id)sender
{
  [NSApp endSheet:self];
  canceled= NO;
}

- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
  [NSApp abortModal];
  [sheet orderOut:self];
}

- (BOOL)acceptsFirstResponder
{
  return YES;
}

- (NSArray*)runModal:(NSWindow*)window
{
  NSMutableArray *array;
  
  [NSApp beginSheet:self
     modalForWindow:window
      modalDelegate:self
     didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
        contextInfo:self];

  [NSApp runModalForWindow:self];

  if (canceled)
    return nil;
  else
  {
	unsigned int i;
	array= [NSMutableArray arrayWithCapacity:[form numberOfRows]];
	
	for (i= 0; i < [form numberOfRows]; i++)
	  [array addObject:[[form cellAtIndex:i] stringValue]];
    return array;
  }
}

- (void)setDefaultValues:(NSArray*)array
{
  unsigned int i;
  
  for (i= 0; i < [form numberOfRows]; i++)
	[[form cellAtIndex:i] setStringValue:[array objectAtIndex:i]];
}

@end