Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the git_askpass command #97

Open
wants to merge 1 commit into
base: experimental
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions gitx_askpasswd_main.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ @interface GAPAppDelegate : NSObject
{
NSPanel* mPasswordPanel;
NSSecureTextField* mPasswordField;
NSString* mTitle;
}

- (id) initWithTitle:(NSString*) title;
-(NSPanel*) passwordPanel;

-(IBAction) doOKButton: (id)sender;
Expand All @@ -35,6 +37,17 @@ -(IBAction) doCancelButton: (id)sender;

@implementation GAPAppDelegate


- (id) initWithTitle:(NSString*) title
{
self = [super init];
if (self != nil) {
mTitle = title;
}
return self;
}


-(NSPanel*) passwordPanel
{
if( !mPasswordPanel )
Expand Down Expand Up @@ -67,7 +80,7 @@ -(NSPanel*) passwordPanel
[okButton setBordered: YES];
[okButton setBezelStyle: NSRoundedBezelStyle];
[[mPasswordPanel contentView] addSubview: okButton];

// Cancel:
NSRect cancelBox = box;
cancelBox.origin.x = NSMinX( okBox ) -CANCELBUTTONWIDTH -6;
Expand Down Expand Up @@ -109,7 +122,7 @@ -(NSPanel*) passwordPanel
[passwordLabel setBordered: NO];
[passwordLabel setBezeled: NO];
[passwordLabel setDrawsBackground: NO];
[passwordLabel setStringValue: @"Please enter your password:"]; // +++ Localize.
[passwordLabel setStringValue: mTitle]; // +++ Localize.
[[mPasswordPanel contentView] addSubview: passwordLabel];

// GitX icon:
Expand Down Expand Up @@ -153,14 +166,21 @@ int main( int argc, const char** argv )
{
// close stderr to stop cocoa log messages from being picked up by GitX
close(STDERR_FILENO);

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

ProcessSerialNumber myPSN = { 0, kCurrentProcess };
TransformProcessType( &myPSN, kProcessTransformToForegroundApplication );

NSApplication *app = [NSApplication sharedApplication];
GAPAppDelegate *appDel = [[GAPAppDelegate alloc] init];

NSString * title = nil;
if (argc > 1) {
title = [NSString stringWithFormat:@"Please enter your %@", [[NSString stringWithUTF8String:argv[1]] lowercaseString]];
} else {
title = @"Please enter your password:";
}

GAPAppDelegate *appDel = [[GAPAppDelegate alloc] initWithTitle:title];
[app setDelegate: appDel];
NSWindow *passPanel = [appDel passwordPanel];

Expand Down