[Cocoapsql-developer] commit; queryView and Submit button behavior; window title
Status: Alpha
Brought to you by:
alkirkus
From: Olaf v. O. <ol...@ad...> - 2002-05-30 21:09:51
|
- By replacing the queryScrollView's NSTextView with my subclass PSQLTextView, I enabled the use of the (queryScrollView-) NSTextView's becomeFirstResponder and resignFirstResponder for the purpous of registering when the View becoms and resings FirstResponder. With these 'notifications' I am able to set and reset the commitButton's keyequivalent properly so that the commitButton looks like the default button only when the view is FirstResponder. To have the submitButton actually act on RETURN or ENTER when the queryView is FirstResponder we need to send the button a performClick from within the - (void)textDidEndEditing:(NSNotification *)aNotification. => Modified the MainMenu.nib: Submitt button now has no keyequivalent (when first displaying the window) => Added PSQTextView to the project => Added to PSQLController.m #import "PSQLTextView.h" => Added to PSQLControler: /* gets invoked by the custom subclass PSQLTextView Therefore this file needs to be the delegate of the View */ -(void)psqlTextViewDidBecomeFirstResponder:(id)sender { if (sender == querySpace) [submitButton setKeyEquivalent:@"\r"]; } /* gets invoked by the custom subclass PSQLTextView Therefore this file needs to be the delegate of the View */ -(void)psqlTextViewDidResignFirstResponder:(id)sender { if (sender == querySpace) [submitButton setKeyEquivalent:@""]; } Added to the beginning of the -(void)awakeFromNib /* replacing the querySpace ScrollView's TextView with an instance of PSQLTextView to receive psqlTextViewDidBecomeFirstResponder and psqlTextViewDidResignFirstResponder messages */ id queryScrollView = [querySpace enclosingScrollView]; NSSize queryScrollViewSize = [queryScrollView contentSize]; // replace NSScrollView's NSTextView with MyTextView querySpace = [[PSQLTextView alloc] initWithFrame:NSMakeRect(0,0, queryScrollViewSize.width, queryScrollViewSize.height)]; [querySpace setMinSize:NSMakeSize(0.0,queryScrollViewSize.height)]; [querySpace setMaxSize:NSMakeSize(1e7,1e7)]; [querySpace setVerticallyResizable:YES]; [querySpace setHorizontallyResizable:NO]; [querySpace setAutoresizingMask:NSViewWidthSizable]; [queryScrollView setDocumentView:querySpace]; [querySpace release]; // as theScrollView retains the TextView [querySpace setDelegate:[mainWindow delegate]]; // restore the delegate connection /* end of replacing the querySpace TextView */ --- => Added to PSQLController - (void)textDidEndEditing:(NSNotification *)aNotification{ /* the querySpace TextView does end editing on RETURN or ENTER while (in awakeFromNib) the view's FieldEditor is set to YES ([querySpace setFieldEditor:YES])*/ NSEvent *event = [NSApp currentEvent]; if( [aNotification object]== querySpace ){ //fire the Window's default button's action on RETURN or ENTER if ( ([event keyCode] == 36 |[event keyCode] == 76) || [event type] == NSKeyUp) { [submitButton performClick:self]; // stay in the TextView for new queries to enter and execute: [mainWindow makeFirstResponder:querySpace]; } } } --- => Added to the end of -(void) doConnect [self setWindowTitle]; => Added to the end of -(void) doDisconnect{ if([connection connected]) [self setWindowTitle] => Added to the end of -(void)awakeFromNib [self setWindowTitle] => Added to PSQLControler: -(void)setWindowTitle { NSString *titleAdd; if([connection connected]) titleAdd = [NSString stringWithFormat:@"%@",@"(Connected)"]; else titleAdd = [NSString stringWithFormat:@"%@",@"(Not Connected)"]; if([[status dbName] isEqualToString:@""]) [mainWindow setTitle:@"(No Database Name)"]; else [mainWindow setTitle:[NSString stringWithFormat:@"%@ at host %@ %@",[status dbName],[status hostName],titleAdd]]; } |