Re: How to make key shortcuts and mouse click trigger controlTextDidEndEditing: - [SOLVED]
Re: How to make key shortcuts and mouse click trigger controlTextDidEndEditing: - [SOLVED]
- Subject: Re: How to make key shortcuts and mouse click trigger controlTextDidEndEditing: - [SOLVED]
- From: James Housley <email@hidden>
- Date: Sun, 6 Mar 2005 06:54:46 -0500
On Mar 5, 2005, at 12:57 PM, James Housley wrote:
I am still new at this, but I think I have most of this figured out.
My program is a front end to creating a file. I have a mix of
NSTextField, NSTextViews and some assorted buttons. Currently the
program is NSDocument based, and so far that seems right but I haven't
full decided. I have a backing structure that contains the real
contents because the there is a table view that lists the entry for
editing.
When editing one of the NSTextViews and pressing Apple-S or File->Save
the file is correctly saved and documentIsEdited is cleared just fine.
When editing one of the NSTextFields I have captured
controlTextDidBeginEditing: and controlTextDidEndEditing: and store
the values fine and feed into the undo manager without a problem when
you leave the field be clicking on one of the buttons or other fields.
To make this simple, if the only editing that is done is in a
NSTextField and File->Save or Apple-S is pressed
controlTextDidEndEditing: is not triggered.
Since I do get controlTextDidBeginEditing: I tried forcing
controlTextDidEndEditing: with a notification and that works, except
after the file is saved, which calls [self
updateChangeCount:NSChangeCleared], the change is still active and the
document is still shown as being saved.
How do I solve this. I am really have to avoid an "Apply" button. Do
I...
1) Subclass NSTextField and override keyDown:/keyUp: to look for the
short cut command and trigger the controlTextDidEndEditing there? But
what about the toolbar and menu options?
2) Create custom NSTextViews that are a single line without scroll
bars? But I would still want to capture keys so that
Return/Tab/Shitf-Tab would work and send the user to the next field.
That doesn't sound nice.
3) Is there a better control to use?
4) Something I haven't even thought of.
Here are the steps that I did to solve the issue.
1) Use [[self window] makeFirstResponeder:nil] to force end of editing
of and fields.
2) I did convert from NSDocument to NSObject. Partly because it is
more correct for me and partly because it seemed to make it a little
easier to take over control of the undo manager.
3) Since it is now an NSObject I needed to capture
NSUndoManagerDidUndoChangeNotification,
NSUndoManagerDidRedoChangeNotification, and
NSUndoManagerWillCloseUndoGroupNotification to increment and decrement
my changed count and set and clear document is edited on the window
(since it is a NSObject).
These steps got me to where I was before I converted to NSObject.
4) The three previously mentioned undo notifications weren't coming
until after the current pass through the run loop the above only got me
a small step towards where I wanted to be. But capturing
NSUndoManagerDidOpenUndoGroupNotification and just calling
setDocumentEdidted caused the change to be noticed before other
operations. So when saving for example, it was seen that there were
changes.
I do not call [[self undoManager] removeAllActions] on save because
that is kind of rude, I think. But I do call this on openDocument: and
newDocument: because that seems logical.
Hopefully this might help others.
I do want to thank those for replying, because they certianly help
nudge me into the right directions.
Jim
--
/"\ ASCII Ribbon Campaign .
\ / - NO HTML/RTF in e-mail .
X - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
email@hidden http://www.FreeBSD.org The Power to Serve
email@hidden http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
good with ketchup.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden