Re: Problem with NSOutlineView::shouldSelectItem: and NSRunCriticalAlertPanel
Re: Problem with NSOutlineView::shouldSelectItem: and NSRunCriticalAlertPanel
- Subject: Re: Problem with NSOutlineView::shouldSelectItem: and NSRunCriticalAlertPanel
- From: Blake Hodgetts <email@hidden>
- Date: Fri, 5 Dec 2003 17:51:38 -0800
(Please respond by email as I am not currently subscribed to this list.)
I am having a problem with the NSOutlineView method "shouldSelectItem:".
I have a condition in my code where, within my delegate implementation of
"shouldSelectItem:", I need to warn the user that certain changes to the
current selection will be lost if the selection is changed. Therefore, if a
"dirty" flag is set, within shouldSelectItem I prompt the user via a dialog
to either discard the changes, or cancel the selection. Depending on the
response to the dialog, I want "shouldSelectItem:" to return either "NO" or
"YES".
The code looks like this ("dirty" is a class member):
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
if (dirty)
{
changeOK = (NSRunCriticalAlertPanel(@"Discard Changes?",
@"Changing selections will discard changes made to the
selection.
Proceed?",
@"Cancel",
@"Discard Changes",
NIL)
== NSAlertAlternateReturn);
}
if (changeOK)
resetValues = YES;
else
return NO;
[...]
return YES;
}
The problem is that when this runs, it returns back through the stack to
[NSOutlineView _userCanSelectRow:], then to [NSTableView
-userSelectRow:byExtendingSelection:] and then to [NSTableView mouseDown:].
From there it returns to shouldSelectItem, with the same item that was
selected before, causing a loop that I can't find a way to avoid,
continually re-displaying the alert panel.
It seems as if running the alert panel somehow prevents the mouse click
that initiated the selection attempt from getting cleared off of the event
queue, so it just gets submitted over and over again.
What's worse is, once this has happened, the mouseclick NEVER gets cleared
off the event queue. I tried putting in a loop catcher that would
immediately return NO from shouldSelectItem: if it found that a flag was
set following the alert panel. Although the alert panel runs only once, the
program loops endlessly through shouldSelectItem returning NO and the
selection is never cancelled.
If the alert panel is not run, then the selection cancels as expected.
Any assistance is greatly appreciated. Please respond via email as I am not
currently subscribed to this list.
--blake
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.