16
16
#define CANCELBUTTONHEIGHT 24.0
17
17
#define PASSHEIGHT 22.0
18
18
#define PASSLABELHEIGHT 16.0
19
+ #define WINDOWAUTOSAVENAME @" GitXAskPasswordWindowFrame"
19
20
20
21
21
- @interface GAPAppDelegate : NSObject < NSApplicationDelegate >
22
+ @interface GAPAppDelegate : NSObject
22
23
{
23
24
NSPanel * mPasswordPanel;
24
25
NSSecureTextField * mPasswordField;
@@ -34,38 +35,31 @@ -(IBAction) doCancelButton: (id)sender;
34
35
35
36
@implementation GAPAppDelegate
36
37
37
- -(void ) dealloc
38
- {
39
- [mPasswordPanel release ];
40
- mPasswordPanel = nil ;
41
-
42
- [mPasswordField release ];
43
- mPasswordField = nil ;
44
-
45
- [super dealloc ];
46
- }
47
-
48
38
-(NSPanel *) passwordPanel
49
39
{
50
40
if ( !mPasswordPanel )
51
41
{
52
- NSRect box = NSMakeRect ( 100 , 100 , 250 , 100 );
42
+ NSRect box = NSMakeRect ( 100 , 100 , 400 , 134 );
53
43
mPasswordPanel = [[NSPanel alloc ] initWithContentRect: box
54
- styleMask: NSTitledWindowMask
55
- backing: NSBackingStoreBuffered defer: NO ];
44
+ styleMask: NSTitledWindowMask
45
+ backing: NSBackingStoreBuffered defer: NO ];
56
46
[mPasswordPanel setHidesOnDeactivate: NO ];
57
47
[mPasswordPanel setLevel: NSFloatingWindowLevel ];
58
- [mPasswordPanel center ];
48
+ [mPasswordPanel setTitle: @" GitX SSH Remote Login" ];
49
+ if (![mPasswordPanel setFrameUsingName: WINDOWAUTOSAVENAME]) {
50
+ [mPasswordPanel center ];
51
+ [mPasswordPanel setFrameAutosaveName: WINDOWAUTOSAVENAME];
52
+ }
59
53
60
54
box.origin = NSZeroPoint ; // Only need local coords from now on.
61
55
62
56
// OK:
63
- NSRect okBox = box;
64
- okBox.origin .x = NSMaxX ( box ) -OKBUTTONWIDTH -10 ;
57
+ NSRect okBox = box;
58
+ okBox.origin .x = NSMaxX ( box ) -OKBUTTONWIDTH -20 ;
65
59
okBox.size .width = OKBUTTONWIDTH;
66
- okBox.origin .y += 10 ;
60
+ okBox.origin .y += 20 ;
67
61
okBox.size .height = OKBUTTONHEIGHT;
68
- NSButton * okButton = [[[ NSButton alloc ] initWithFrame: okBox] autorelease ];
62
+ NSButton * okButton = [[NSButton alloc ] initWithFrame: okBox];
69
63
[okButton setTarget: self ];
70
64
[okButton setAction: @selector (doOKButton: )];
71
65
[okButton setTitle: @" OK" ]; // +++ Localize.
@@ -78,22 +72,22 @@ -(NSPanel*) passwordPanel
78
72
NSRect cancelBox = box;
79
73
cancelBox.origin .x = NSMinX ( okBox ) -CANCELBUTTONWIDTH -6 ;
80
74
cancelBox.size .width = CANCELBUTTONWIDTH;
81
- cancelBox.origin .y += 10 ;
75
+ cancelBox.origin .y += 20 ;
82
76
cancelBox.size .height = CANCELBUTTONHEIGHT;
83
- okButton = [[[ NSButton alloc ] initWithFrame: cancelBox] autorelease ];
84
- [okButton setTarget: self ];
85
- [okButton setAction: @selector (doCancelButton: )];
86
- [okButton setTitle: @" Cancel" ]; // +++ Localize.
87
- [okButton setBordered: YES ];
88
- [okButton setBezelStyle: NSRoundedBezelStyle ];
89
- [[mPasswordPanel contentView ] addSubview: okButton ];
77
+ NSButton *cancleButton = [[NSButton alloc ] initWithFrame: cancelBox];
78
+ [cancleButton setTarget: self ];
79
+ [cancleButton setAction: @selector (doCancelButton: )];
80
+ [cancleButton setTitle: @" Cancel" ]; // +++ Localize.
81
+ [cancleButton setBordered: YES ];
82
+ [cancleButton setBezelStyle: NSRoundedBezelStyle ];
83
+ [[mPasswordPanel contentView ] addSubview: cancleButton ];
90
84
91
85
// Password field:
92
- NSRect passBox = box;
93
- passBox.origin .y = NSMaxY (okBox) + 12 ;
86
+ NSRect passBox = box;
87
+ passBox.origin .y = NSMaxY (okBox) + 24 ;
94
88
passBox.size .height = PASSHEIGHT;
95
- passBox.origin .x += 12 ;
96
- passBox.size .width -= 12 * 2 ;
89
+ passBox.origin .x += 104 ;
90
+ passBox.size .width -= 104 + 20 ;
97
91
mPasswordField = [[NSSecureTextField alloc ] initWithFrame: passBox];
98
92
[mPasswordField setSelectable: YES ];
99
93
[mPasswordField setEditable: YES ];
@@ -104,19 +98,32 @@ -(NSPanel*) passwordPanel
104
98
[[mPasswordPanel contentView ] addSubview: mPasswordField];
105
99
106
100
// Password label:
107
- NSRect passLabelBox = box;
108
- passLabelBox.origin .y = NSMaxY (passBox) + 6 ;
101
+ NSRect passLabelBox = box;
102
+ passLabelBox.origin .y = NSMaxY (passBox) + 8 ;
109
103
passLabelBox.size .height = PASSLABELHEIGHT;
110
- passLabelBox.origin .x += 12 ;
111
- passLabelBox.size .width -= 12 * 2 ;
112
- NSTextField * passwordLabel = [[[ NSTextField alloc ] initWithFrame: passLabelBox] autorelease ];
104
+ passLabelBox.origin .x += 100 ;
105
+ passLabelBox.size .width -= 100 + 20 ;
106
+ NSTextField * passwordLabel = [[NSTextField alloc ] initWithFrame: passLabelBox];
113
107
[passwordLabel setSelectable: YES ];
114
108
[passwordLabel setEditable: NO ];
115
109
[passwordLabel setBordered: NO ];
116
110
[passwordLabel setBezeled: NO ];
117
111
[passwordLabel setDrawsBackground: NO ];
118
112
[passwordLabel setStringValue: @" Please enter your password:" ]; // +++ Localize.
119
113
[[mPasswordPanel contentView ] addSubview: passwordLabel];
114
+
115
+ // GitX icon:
116
+ NSRect gitxIconBox = box;
117
+ gitxIconBox.origin .y = NSMaxY (box) - 78 ;
118
+ gitxIconBox.size .height = 64 ;
119
+ gitxIconBox.origin .x += 20 ;
120
+ gitxIconBox.size .width = 64 ;
121
+ NSImageView *gitxIconView = [[NSImageView alloc ] initWithFrame: gitxIconBox];
122
+ [gitxIconView setEditable: NO ];
123
+ NSString *gitxIconPath = [[[NSBundle mainBundle ] bundlePath ] stringByAppendingPathComponent: @" gitx.icns" ];
124
+ NSImage *gitxIcon = [[NSImage alloc ] initWithContentsOfFile: gitxIconPath];
125
+ [gitxIconView setImage: gitxIcon];
126
+ [[mPasswordPanel contentView ] addSubview: gitxIconView];
120
127
}
121
128
122
129
return mPasswordPanel;
@@ -126,14 +133,16 @@ -(NSPanel*) passwordPanel
126
133
-(IBAction ) doOKButton : (id )sender
127
134
{
128
135
printf ( " %s \n " , [[mPasswordField stringValue ] UTF8String ] );
129
- [[NSApplication sharedApplication ] terminate: self ];
136
+ [[NSApplication sharedApplication ] stopModalWithCode: 0 ];
130
137
}
131
138
132
139
140
+ // TODO: Need to find out how to get SSH to cancel.
141
+ // When the user cancels the window it is opened again for however
142
+ // many times the remote server allows failed attempts.
133
143
-(IBAction ) doCancelButton : (id )sender
134
144
{
135
- printf (" \n " );
136
- [[NSApplication sharedApplication ] terminate: self ];
145
+ [[NSApplication sharedApplication ] stopModalWithCode: 1 ];
137
146
}
138
147
139
148
@end
@@ -142,18 +151,25 @@ -(IBAction) doCancelButton: (id)sender
142
151
143
152
int main ( int argc, const char ** argv )
144
153
{
154
+ // close stderr to stop cocoa log messages from being picked up by GitX
155
+ close (STDERR_FILENO);
156
+
157
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
158
+
145
159
ProcessSerialNumber myPSN = { 0 , kCurrentProcess };
146
160
TransformProcessType ( &myPSN, kProcessTransformToForegroundApplication );
147
161
148
- NSApplication * app = [NSApplication sharedApplication ];
149
- GAPAppDelegate * appDel = [[GAPAppDelegate alloc ] init ];
162
+ NSApplication * app = [NSApplication sharedApplication ];
163
+ GAPAppDelegate * appDel = [[GAPAppDelegate alloc ] init ];
150
164
[app setDelegate: appDel];
151
- NSWindow * passPanel = [appDel passwordPanel ];
165
+ NSWindow * passPanel = [appDel passwordPanel ];
152
166
153
167
[app activateIgnoringOtherApps: YES ];
154
168
[passPanel makeKeyAndOrderFront: nil ];
155
- [app runModalForWindow: passPanel];
169
+ NSInteger code = [app runModalForWindow: passPanel];
170
+
171
+ [defaults synchronize ];
156
172
157
- return 0 ;
173
+ return code ;
158
174
}
159
175
0 commit comments