From 109b9ae329a6e1323a6d18018bcdd0c1f8e9197c Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Wed, 2 Mar 2016 07:55:37 +0000 Subject: [PATCH] Prevent crash during group rules removal in some cases (OS X) The crash seems to be caused by animation performed by the rules list and the window in parallel. This commit disables window resize animation until a better solution is devised. Rules list height is now also limited and scrollbar is shown if needed. --- macosx/GroupsPrefsController.h | 2 ++ macosx/GroupsPrefsController.m | 14 +++++++++----- macosx/da.lproj/GroupRules.xib | 3 ++- macosx/de.lproj/GroupRules.xib | 3 ++- macosx/en.lproj/GroupRules.xib | 3 ++- macosx/es.lproj/GroupRules.xib | 3 ++- macosx/fr.lproj/GroupRules.xib | 3 ++- macosx/it.lproj/GroupRules.xib | 3 ++- macosx/nl.lproj/GroupRules.xib | 3 ++- macosx/pt_PT.lproj/GroupRules.xib | 3 ++- macosx/ru.lproj/GroupRules.xib | 3 ++- macosx/tr.lproj/GroupRules.xib | 3 ++- 12 files changed, 31 insertions(+), 15 deletions(-) diff --git a/macosx/GroupsPrefsController.h b/macosx/GroupsPrefsController.h index 7838abf76..dc4277a29 100644 --- a/macosx/GroupsPrefsController.h +++ b/macosx/GroupsPrefsController.h @@ -39,6 +39,8 @@ IBOutlet NSWindow * fGroupRulesSheetWindow; IBOutlet NSPredicateEditor * fRuleEditor; + + IBOutlet NSLayoutConstraint * fRuleEditorHeightConstraint; } - (void) addRemoveGroup: (id) sender; diff --git a/macosx/GroupsPrefsController.m b/macosx/GroupsPrefsController.m index a5bc2916a..6103ec171 100644 --- a/macosx/GroupsPrefsController.m +++ b/macosx/GroupsPrefsController.m @@ -299,12 +299,16 @@ - (void) ruleEditorRowsDidChange: (NSNotification *) notification { - const CGFloat heightDifference = [fRuleEditor numberOfRows] * [fRuleEditor rowHeight] - [fRuleEditor frame].size.height; - NSRect windowFrame = [fRuleEditor window].frame; - windowFrame.size.height += heightDifference; - windowFrame.origin.y -= heightDifference; + NSScrollView * ruleEditorScrollView = [fRuleEditor enclosingScrollView]; - [fRuleEditor.window setFrame: windowFrame display: YES animate: YES]; + const CGFloat rowHeight = [fRuleEditor rowHeight]; + const CGFloat bordersHeight = [ruleEditorScrollView frame].size.height - [ruleEditorScrollView contentSize].height; + + const CGFloat requiredRowCount = [fRuleEditor numberOfRows]; + const CGFloat maxVisibleRowCount = (long)((NSHeight([[[fRuleEditor window] screen] visibleFrame]) * 2 / 3) / rowHeight); + + [fRuleEditorHeightConstraint setConstant: MIN(requiredRowCount, maxVisibleRowCount) * rowHeight + bordersHeight]; + [ruleEditorScrollView setHasVerticalScroller: requiredRowCount > maxVisibleRowCount]; } @end diff --git a/macosx/da.lproj/GroupRules.xib b/macosx/da.lproj/GroupRules.xib index 29f7a84d3..ab50c81b9 100644 --- a/macosx/da.lproj/GroupRules.xib +++ b/macosx/da.lproj/GroupRules.xib @@ -9,6 +9,7 @@ + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - + @@ -187,7 +188,7 @@ Gw - +