File: ServicesParameterWindowController.m

package info (click to toggle)
terminal.app 0.9.4+cvs20051125-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 460 kB
  • ctags: 106
  • sloc: objc: 6,098; makefile: 42; sh: 13
file content (166 lines) | stat: -rw-r--r-- 3,645 bytes parent folder | download | duplicates (9)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
copyright 2002 Alexander Malmberg <alexander@malmberg.org>

This file is a part of Terminal.app. Terminal.app is free software; you
can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; version 2
of the License. See COPYING or main.m for more information.
*/

#include <Foundation/NSString.h>
#include <Foundation/NSBundle.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSTextField.h>
#include <AppKit/NSPanel.h>
#include <AppKit/NSButton.h>
#include <GNUstepGUI/GSVbox.h>
#include <GNUstepGUI/GSHbox.h>

#include "ServicesParameterWindowController.h"

#include "autokeyviewchain.h"


@implementation TerminalServicesParameterWindowController


-(void) _cancel: (id)sender
{
	[NSApp stopModalWithCode: NSRunAbortedResponse];
}

-(void) _ok: (id)sender
{
	[NSApp stopModalWithCode: NSRunStoppedResponse];
}


- initWithCommandline: (NSString *)cmdline
	selectRange: (NSRange)r
	service: (NSString *)service_name
{
	NSWindow *win;

	win=[[NSPanel alloc] initWithContentRect: NSMakeRect(100,100,380,100)
		styleMask: NSTitledWindowMask|NSResizableWindowMask
		backing: NSBackingStoreRetained
		defer: YES];
	if (!(self=[super initWithWindow: win])) return nil;

	{
		GSVbox *vbox;

		vbox=[[GSVbox alloc] init];
		[vbox setBorder: 4];
		[vbox setDefaultMinYMargin: 4];

		{
			NSButton *b;
			GSHbox *hbox;

			hbox=[[GSHbox alloc] init];
			[hbox setDefaultMinXMargin: 4];
			[hbox setAutoresizingMask: NSViewMinXMargin];

			b=[[NSButton alloc] init];
			[b setTitle: _(@"Cancel")];
			[b setTarget: self];
			[b setAction: @selector(_cancel:)];
			[b sizeToFit];
			[hbox addView: b];
			[b release];

			b=[[NSButton alloc] init];
			[b setTitle: _(@"OK")];
			[b setKeyEquivalent: @"\r"];
			[b setTarget: self];
			[b setAction: @selector(_ok:)];
			[b sizeToFit];
			[hbox addView: b];
			[b release];

			[vbox addView: hbox  enablingYResizing: NO];
			[hbox release];
		}

		{
			NSTextField *f;

			tf_cmdline=f=[[NSTextField alloc] init];
			[f setAutoresizingMask: NSViewWidthSizable];
			[f sizeToFit];
			[f setStringValue: cmdline];
			[vbox addView: f  enablingYResizing: NO];
			DESTROY(f);

			f=[[NSTextField alloc] init];
			[f setAutoresizingMask: NSViewMaxXMargin];
			[f setStringValue: _(@"Command line:")];
			[f setEditable: NO];
			[f setDrawsBackground: NO];
			[f setBordered: NO];
			[f setBezeled: NO];
			[f setSelectable: NO];
			[f sizeToFit];
			[f setAutoresizingMask: 0];
			[vbox addView: f  enablingYResizing: NO];
			DESTROY(f);

			[tf_cmdline setTarget: self];
			[tf_cmdline setAction: @selector(_ok:)];
		}

		[win setContentView: vbox];
		[vbox release];
	}
	[win setDelegate: self];
	[win setTitle:
		[NSString stringWithFormat: _(@"Parameter for service %@"),
			service_name]];

	[win autoSetupKeyViewChain];
	[win makeFirstResponder: tf_cmdline];
/*	if (r.length)
	{
		NSText *t=[win fieldEditor: NO  forObject: tf_cmdline];
		printf("t=%@ r=%@\n",[t text],NSStringFromRange(r));
		[t setSelectedRange: r];
	}*/

	[win release];

	return self;
}


-(NSString *) _cmdline
{
	return [[[tf_cmdline stringValue] retain] autorelease];
}


+(NSString *) getCommandlineFrom: (NSString *)cmdline
	selectRange: (NSRange)r
	service: (NSString *)service_name
{
	TerminalServicesParameterWindowController *wc;
	NSString *s;
	int result;

	wc=[[self alloc] initWithCommandline: cmdline
		selectRange: r
		service: service_name];
	[wc showWindow: self];
	result=[NSApp runModalForWindow: [wc window]];
	s=[wc _cmdline];
	[wc close];
	DESTROY(wc);

	if (result==NSRunStoppedResponse)
		return s;
	else
		return nil;
}

@end