Revision: 14539
http://sourceforge.net/p/skim-app/code/14539
Author: hofman
Date: 2024-10-10 15:52:40 +0000 (Thu, 10 Oct 2024)
Log Message:
-----------
Determine widths fo table once when showing the table, separate from getting
new transitions. Set transitions in initializer rather than windowDidLoad.
Modified Paths:
--------------
trunk/SKPresentationOptionsSheetController.m
Modified: trunk/SKPresentationOptionsSheetController.m
===================================================================
--- trunk/SKPresentationOptionsSheetController.m 2024-10-10 14:10:29 UTC
(rev 14538)
+++ trunk/SKPresentationOptionsSheetController.m 2024-10-10 15:52:40 UTC
(rev 14539)
@@ -69,7 +69,7 @@
#define MAX_PAGE_COLUMN_WIDTH 100.0
-#define TABLE_OFFSET 8.0
+#define TABLE_OFFSET 28.0
#define BOX_OFFSET 20.0
static char *SKTransitionPropertiesObservationContext;
@@ -79,6 +79,10 @@
#pragma mark -
+@interface SKPresentationOptionsSheetController ()
+- (NSArray *)makeTransitions:(NSArray *)properties;
+@end
+
@implementation SKPresentationOptionsSheetController
@synthesize notesDocumentPopUpButton, tableView, stylePopUpButton, okButton,
cancelButton, previewButton, tableWidthConstraint, boxLeadingConstraint,
arrayController, separate, transition, transitions, undoManager;
@@ -88,9 +92,21 @@
self = [super init];
if (self) {
controller = aController;
- separate = NO;
+
+ SKTransitionController *transitionController = [controller
transitionControllerCreating:NO];
+
transition = [[SKLabeledTransitionInfo alloc] init];
- transitions = @[transition];
+ if (transitionController)
+ [transition setInfo:[transitionController transition]];
+ if ([transitionController pageTransitions]) {
+ transitions = [self makeTransitions:[transitionController
pageTransitions]];
+ separate = YES;
+ } else {
+ transitions = @[transition];
+ separate = NO;
+ }
+
+ [self startObservingTransitions:transitions];
}
return self;
}
@@ -132,13 +148,6 @@
}
- (NSArray *)makeTransitions:(NSArray *)properties {
- // determine the table width by getting the largest page label
- NSTableColumn *tableColumn = [tableView
tableColumnWithIdentifier:PAGE_COLUMNID];
- id cell = [[tableColumn dataCell] copy];
- CGFloat labelWidth = 0.0;
-
- [cell setFont:[[NSFontManager sharedFontManager] convertFont:[cell font]
toHaveTrait:NSBoldFontMask]];
-
NSMutableArray *array = [NSMutableArray array];
NSEnumerator *ptEnum = [properties objectEnumerator];
SKThumbnail *tn = nil;
@@ -153,47 +162,59 @@
[info setThumbnail:tn];
[info setToThumbnail:next];
[array addObject:info];
- [cell setStringValue:[info label] ?: @""];
- labelWidth = fmax(labelWidth, [cell cellSize].width);
}
tn = next;
}
- labelWidth = fmin(ceil(labelWidth), MAX_PAGE_COLUMN_WIDTH);
- [tableColumn setMinWidth:labelWidth];
- [tableColumn setMaxWidth:labelWidth];
- [tableColumn setWidth:labelWidth];
-
- NSScrollView *scrollView = [tableView enclosingScrollView];
- CGFloat width = [[[tableView tableColumns] valueForKeyPath:@"@sum.width"]
doubleValue] + NSWidth([scrollView frame]) - [scrollView contentSize].width +
3.0 * [tableView intercellSpacing].width;
- [tableWidthConstraint setConstant:width];
-
return array;
}
-- (void)toggleTableAnimating:(BOOL)animate {
+- (void)showHideTableView {
+ if (separate && [tableView tag] == 0) {
+ // determine the table width by getting the largest page label
+ NSTableColumn *tableColumn = [tableView
tableColumnWithIdentifier:PAGE_COLUMNID];
+ id cell = [[tableColumn dataCell] copy];
+ CGFloat labelWidth = 0.0;
+
+ [cell setFont:[[NSFontManager sharedFontManager] convertFont:[cell
font] toHaveTrait:NSBoldFontMask]];
+
+ for (SKLabeledTransitionInfo *info in transitions) {
+ [cell setStringValue:[info label] ?: @""];
+ labelWidth = fmax(labelWidth, [cell cellSize].width);
+ }
+
+ labelWidth = fmin(ceil(labelWidth), MAX_PAGE_COLUMN_WIDTH);
+ [tableColumn setMinWidth:labelWidth];
+ [tableColumn setMaxWidth:labelWidth];
+ [tableColumn setWidth:labelWidth];
+
+ NSScrollView *scrollView = [tableView enclosingScrollView];
+ CGFloat width = [[[tableView tableColumns]
valueForKeyPath:@"@sum.width"] doubleValue] + NSWidth([scrollView frame]) -
[scrollView contentSize].width + 3.0 * [tableView intercellSpacing].width;
+ [tableWidthConstraint setConstant:width];
+
+ // we use this to know we have set the widths
+ [tableView setTag:1];
+ }
+
NSWindow *window = [self window];
+ BOOL isSheet = [window sheetParent] != nil;
+ CGFloat width = separate ? [tableWidthConstraint constant] + TABLE_OFFSET
: BOX_OFFSET;
- NSView *scrollView = [tableView enclosingScrollView];
- BOOL hidden = separate == NO;
- CGFloat width = BOX_OFFSET;
-
- if (separate)
- width += [tableWidthConstraint constant] + TABLE_OFFSET;
-
- if (animate && [NSView shouldShowSlideAnimation]) {
+ if (isSheet && [NSView shouldShowSlideAnimation]) {
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
[[boxLeadingConstraint animator] setConstant:width];
- [[scrollView animator] setHidden:hidden];
+ [[[tableView enclosingScrollView] animator] setHidden:separate
== NO];
}
completionHandler:^{
- NSRect frame = [window frame];
- [window setFrameOrigin:NSMakePoint(NSMidX([[controller window]
frame]) - 0.5 * NSWidth(frame), NSMinY(frame))];
+ if (isSheet) {
+ NSRect frame = [window frame];
+ [window setFrameOrigin:NSMakePoint(NSMidX([[controller
window] frame]) - 0.5 * NSWidth(frame), NSMinY(frame))];
+ }
}];
} else {
[boxLeadingConstraint setConstant:width];
- [scrollView setHidden:hidden];
- if (animate == NO) {
+ [[tableView enclosingScrollView] setHidden:separate == NO];
+ if (isSheet) {
NSRect frame = [window frame];
[window setFrameOrigin:NSMakePoint(NSMidX([[controller window]
frame]) - 0.5 * NSWidth(frame), NSMinY(frame))];
}
@@ -219,13 +240,6 @@
[[notesDocumentPopUpButton itemAtIndex:1] setRepresentedObject:[controller
document]];
[[notesDocumentPopUpButton itemAtIndex:2] setRepresentedObject:[controller
document]];
- SKTransitionController *transitionController = [controller
transitionControllerCreating:NO];
- NSArray *pageTransitions = [transitionController pageTransitions];
- SKTransitionInfo *info = [transitionController transition];
- if (info)
- [transition setInfo:info];
- [self startObservingTransitions:transitions];
-
if (@available(macOS 11.0, *))
[tableView setStyle:NSTableViewStylePlain];
@@ -239,16 +253,7 @@
[tableView setDoubleAction:@selector(preview:)];
- if (pageTransitions) {
- [self willChangeValueForKey:SEPARATE_KEY];
- separate = YES;
- [self didChangeValueForKey:SEPARATE_KEY];
- [self setTransitions:[self makeTransitions:pageTransitions]];
- [self toggleTableAnimating:NO];
- } else {
- // collapse the table, it is already hidden
- [boxLeadingConstraint setConstant:BOX_OFFSET];
- }
+ [self showHideTableView];
// set the current notes document and observe changes for the popup
[self handleDocumentsDidChangeNotification:nil];
@@ -424,11 +429,6 @@
}];
}
-- (void)updateTransitions:(NSArray *)newTransitions {
- [[[self undoManager] prepareWithInvocationTarget:self]
updateTransitions:transitions];
- [self setTransitions:newTransitions];
-}
-
- (void)setSeparate:(BOOL)newSeparate {
if (separate != newSeparate) {
separate = newSeparate;
@@ -435,23 +435,14 @@
[[SKImageToolTipWindow sharedToolTipWindow] orderOut:nil];
- NSWindow *window = [self window];
- id firstResponder = [window firstResponder];
- NSTextView *editor = nil;
- if ([firstResponder isKindOfClass:[NSTextView class]]) {
- editor = firstResponder;
- if ([editor isFieldEditor])
- firstResponder = [firstResponder delegate];
- }
- if ([arrayController commitEditing] &&
- editor && [window firstResponder] != editor)
- [window makeFirstResponder:firstResponder];
+ [arrayController commitEditing];
// undo or redo will include updateTransitions: in the same group
if ([[self undoManager] isUndoing] == NO && [[self undoManager]
isRedoing] == NO)
- [self updateTransitions:separate ? [self makeTransitions:nil] :
@[transition]];
- [self toggleTableAnimating:YES];
+ [self setTransitions:separate ? [self makeTransitions:nil] :
@[transition]];
+ [self showHideTableView];
+
[[[self undoManager] prepareWithInvocationTarget:self]
setSeparate:separate == NO];
}
}
@@ -458,6 +449,7 @@
- (void)setTransitions:(NSArray *)newTransitions {
if (transitions != newTransitions) {
+ [[[self undoManager] prepareWithInvocationTarget:self]
setTransitions:transitions];
[self stopObservingTransitions:transitions];
transitions = [newTransitions copy];
[self startObservingTransitions:transitions];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit