mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 18:51:55 +00:00
Fixed [_window makeFirstResponder: aTextField] to actually select the text
in the textfield git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14539 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3e69a4287e
commit
61d022a244
1 changed files with 50 additions and 22 deletions
|
@ -285,36 +285,56 @@ static Class textFieldCellClass;
|
||||||
//
|
//
|
||||||
- (void) mouseDown: (NSEvent*)theEvent
|
- (void) mouseDown: (NSEvent*)theEvent
|
||||||
{
|
{
|
||||||
NSText *t;
|
|
||||||
|
|
||||||
if ([self isSelectable] == NO)
|
if ([self isSelectable] == NO)
|
||||||
return;
|
|
||||||
|
|
||||||
/* This could happen if someone pressed the mouse on the borders. */
|
|
||||||
if (_text_object)
|
|
||||||
{
|
{
|
||||||
|
[super mouseDown: theEvent];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = [_window fieldEditor: YES forObject: self];
|
/* NB: If we're receiving this click from the NSWindow, we expect
|
||||||
|
_text_object to never be nil here, since NSWindow makes the
|
||||||
if ([t superview] != nil)
|
NSTextField the first responder (which invokes its
|
||||||
|
-becomeFirstResponder:, which invokes its -selectText:, which, if
|
||||||
|
it is selectable, sets up the _text_object, then makes the
|
||||||
|
_text_object first responder!) before calling its -mouseDown:.
|
||||||
|
Only the first click should go via here; further clicks will be
|
||||||
|
sent directly by the NSWindow to the _text_object.
|
||||||
|
*/
|
||||||
|
if (_text_object)
|
||||||
{
|
{
|
||||||
if ([t resignFirstResponder] == NO)
|
[_text_object mouseDown: theEvent];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* I suppose you could get here in subclasses which override
|
||||||
|
* -becomeFirstResponder not to select the text. In that case,
|
||||||
|
* we set up the _text_object manually to start editing here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Make sure we have first responder status when we start edit.
|
||||||
|
* This does nothing if we are already first responder; but
|
||||||
|
* (important!) it implicitly should free the fieldEditor if it
|
||||||
|
* was in use by another control.
|
||||||
|
*/
|
||||||
|
if ([_window makeFirstResponder: self])
|
||||||
{
|
{
|
||||||
if ([_window makeFirstResponder: _window] == NO)
|
NSText *t = [_window fieldEditor: YES forObject: self];
|
||||||
return;
|
|
||||||
|
if ([t superview] != nil)
|
||||||
|
{
|
||||||
|
/* Can't take the field editor ... give up. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_text_object = [_cell setUpFieldEditorAttributes: t];
|
||||||
|
[_cell editWithFrame: _bounds
|
||||||
|
inView: self
|
||||||
|
editor: _text_object
|
||||||
|
delegate: self
|
||||||
|
event: theEvent];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// [NSCursor hide];
|
|
||||||
_text_object = [_cell setUpFieldEditorAttributes: t];
|
|
||||||
[_cell editWithFrame: _bounds
|
|
||||||
inView: self
|
|
||||||
editor: _text_object
|
|
||||||
delegate: self
|
|
||||||
event: theEvent];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) acceptsFirstMouse: (NSEvent *)aEvent
|
- (BOOL) acceptsFirstMouse: (NSEvent *)aEvent
|
||||||
|
@ -332,7 +352,15 @@ static Class textFieldCellClass;
|
||||||
|
|
||||||
- (BOOL) becomeFirstResponder
|
- (BOOL) becomeFirstResponder
|
||||||
{
|
{
|
||||||
return [self isSelectable];
|
if ([self acceptsFirstResponder])
|
||||||
|
{
|
||||||
|
[self selectText: self];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL) needsPanelToBecomeKey
|
-(BOOL) needsPanelToBecomeKey
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue