From 667965deb096dfddee663701627eb0364f350a9a Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 28 Aug 2011 23:37:12 +0000 Subject: - Disable and re-enable table view double click actions when opening and closing sheets for a window; this addresses beeping when editing cells using the field editor sheet. --- Source/SPTableView.m | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Source/SPTableView.m b/Source/SPTableView.m index 9139bb79..e135e16b 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -37,6 +37,8 @@ @interface SPTableView (PrivateAPI) - (void)_doubleClickAction; +- (void)_disableDoubleClickAction:(NSNotification *)notification; +- (void)_enableDoubleClickAction:(NSNotification *)notification; @end @@ -60,6 +62,23 @@ [super awakeFromNib]; } +/** + * Track window changes, in order to add listeners for when sheets are shown + * or hidden; this allows the double-click action to be disabled while sheets + * are open, preventing beeps when using the field editor on double-click. + */ +- (void) viewWillMoveToWindow:(NSWindow *)aWindow { + NSNotificationCenter *notifier = [NSNotificationCenter defaultCenter]; + + [notifier removeObserver:self name:NSWindowWillBeginSheetNotification object:nil]; + [notifier removeObserver:self name:NSWindowDidEndSheetNotification object:nil]; + + if (aWindow) { + [notifier addObserver:self selector:@selector(_disableDoubleClickAction:) name:NSWindowWillBeginSheetNotification object:aWindow]; + [notifier addObserver:self selector:@selector(_enableDoubleClickAction:) name:NSWindowDidEndSheetNotification object:aWindow]; + } +} + #pragma mark - /** @@ -238,4 +257,23 @@ } } +/** + * When a sheet is opened on this window, disable the double-click action. + * This prevents beeping when a double-click results in a rejected cell edit but + * opens a sheet such as the field editor sheet. + */ +- (void)_disableDoubleClickAction:(NSNotification *)notification +{ + [super setDoubleAction:NULL]; +} + +/** + * Restore the double-click action after the sheet is closed. + */ +- (void)_enableDoubleClickAction:(NSNotification *)notification +{ + [super setDoubleAction:@selector(_doubleClickAction)]; +} + + @end -- cgit v1.2.3