fix: initial autoresize on about page

This commit is contained in:
relikd
2023-06-17 16:29:58 +02:00
parent a9c3ccc1f7
commit be600b6c5f
2 changed files with 8 additions and 9 deletions

View File

@@ -70,7 +70,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>14811</string> <string>14833</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.news</string> <string>public.app-category.news</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@@ -22,7 +22,7 @@
TabItem(NSImageNameFontPanel, NSLocalizedString(@"Appearance", nil), [SettingsAppearance class]), TabItem(NSImageNameFontPanel, NSLocalizedString(@"Appearance", nil), [SettingsAppearance class]),
TabItem(NSImageNameInfo, NSLocalizedString(@"About", nil), [SettingsAbout class]), TabItem(NSImageNameInfo, NSLocalizedString(@"About", nil), [SettingsAbout class]),
]; ];
[self switchToTab: UserPrefsUInt(Pref_prefSelectedTab)]; self.selectedTabViewItemIndex = -1;
} }
return self; return self;
} }
@@ -38,19 +38,16 @@ static inline NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Clas
/// Safely set selected index without out of bounds exception /// Safely set selected index without out of bounds exception
- (__kindof NSViewController*)switchToTab:(NSUInteger)index { - (__kindof NSViewController*)switchToTab:(NSUInteger)index {
if (index < 0 || index >= self.tabViewItems.count) if (index < 0 || index >= self.tabViewItems.count)
return nil; index = 0;
NSTabViewItem *tab = self.tabViewItems[index];
if (tab.identifier == NSToolbarFlexibleSpaceItemIdentifier)
return nil;
self.selectedTabViewItemIndex = (NSInteger)index; self.selectedTabViewItemIndex = (NSInteger)index;
return [tab viewController]; return [self.tabViewItems[index] viewController];
} }
/// Delegate method, store last selected tab to user preferences /// Delegate method, store last selected tab to user preferences
- (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(nullable NSTabViewItem*)tabViewItem { - (void)tabView:(NSTabView*)tabView didSelectTabViewItem:(nullable NSTabViewItem*)tabViewItem {
[super tabView:tabView didSelectTabViewItem:tabViewItem]; [super tabView:tabView didSelectTabViewItem:tabViewItem];
NSInteger newIndex = self.selectedTabViewItemIndex; NSInteger newIndex = self.selectedTabViewItemIndex;
if (UserPrefsInt(Pref_prefSelectedTab) != newIndex) if (newIndex != -1 && UserPrefsInt(Pref_prefSelectedTab) != newIndex)
UserPrefsSetInt(Pref_prefSelectedTab, newIndex); UserPrefsSetInt(Pref_prefSelectedTab, newIndex);
} }
@@ -65,7 +62,8 @@ static inline NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Clas
w.contentMinSize = NSMakeSize(320, 327); w.contentMinSize = NSMakeSize(320, 327);
w.windowController.shouldCascadeWindows = YES; w.windowController.shouldCascadeWindows = YES;
w.title = [NSString stringWithFormat:NSLocalizedString(@"%@ Preferences", nil), NSProcessInfo.processInfo.processName]; w.title = [NSString stringWithFormat:NSLocalizedString(@"%@ Preferences", nil), NSProcessInfo.processInfo.processName];
w.contentViewController = [PrefTabs new]; PrefTabs *tabController = [PrefTabs new];
w.contentViewController = tabController;
[w.toolbar insertItemWithItemIdentifier:NSToolbarSpaceItemIdentifier atIndex:3]; [w.toolbar insertItemWithItemIdentifier:NSToolbarSpaceItemIdentifier atIndex:3];
[w.toolbar insertItemWithItemIdentifier:NSToolbarFlexibleSpaceItemIdentifier atIndex:4]; [w.toolbar insertItemWithItemIdentifier:NSToolbarFlexibleSpaceItemIdentifier atIndex:4];
w.delegate = w; w.delegate = w;
@@ -76,6 +74,7 @@ static inline NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Clas
} else { } else {
[w setFrameFromString:prevFrame]; [w setFrameFromString:prevFrame];
} }
[tabController switchToTab:UserPrefsUInt(Pref_prefSelectedTab)];
return w; return w;
} }