mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-19 00:19:22 +00:00
Added custom MPTabViewController to resize window to tab sizes on change
This commit is contained in:
@@ -189,6 +189,7 @@
|
||||
4C7B637F1C0CB57300D7038C /* KeePassKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4C7B63791C0CB55600D7038C /* KeePassKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
4C7B63801C0CB57300D7038C /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4C7B637A1C0CB55600D7038C /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
4C7BD07619FE94C900C7AA5C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4C7BD07519FE94C900C7AA5C /* Assets.xcassets */; };
|
||||
4C7D9D5424ABE6FD00907034 /* MPTabViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C7D9D5324ABE6FD00907034 /* MPTabViewController.m */; };
|
||||
4C7F8B681A10B68400CCB83D /* WelcomeView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C7F8B6A1A10B68400CCB83D /* WelcomeView.xib */; };
|
||||
4C80304A1E2FBAA300133E4C /* MPTestKeyMapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8030491E2FBAA300133E4C /* MPTestKeyMapper.m */; };
|
||||
4C81867D216664C70068DAFB /* MPPluginRepositoryItemVersionInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C81867C216664C70068DAFB /* MPPluginRepositoryItemVersionInfo.m */; };
|
||||
@@ -671,6 +672,8 @@
|
||||
4C7B63791C0CB55600D7038C /* KeePassKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = KeePassKit.framework; path = Carthage/Build/Mac/KeePassKit.framework; sourceTree = "<group>"; };
|
||||
4C7B637A1C0CB55600D7038C /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Carthage/Build/Mac/Sparkle.framework; sourceTree = "<group>"; };
|
||||
4C7BD07519FE94C900C7AA5C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
4C7D9D5224ABE6FD00907034 /* MPTabViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPTabViewController.h; sourceTree = "<group>"; };
|
||||
4C7D9D5324ABE6FD00907034 /* MPTabViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPTabViewController.m; sourceTree = "<group>"; };
|
||||
4C7F8B691A10B68400CCB83D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/WelcomeView.xib; sourceTree = "<group>"; };
|
||||
4C7F8B741A10B69300CCB83D /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/WelcomeView.strings; sourceTree = "<group>"; };
|
||||
4C7F8B761A10B69400CCB83D /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/WelcomeView.strings"; sourceTree = "<group>"; };
|
||||
@@ -1671,6 +1674,8 @@
|
||||
4C20E4BE23E4753A00807FAE /* MPDocumentSplitViewController.h */,
|
||||
4C20E4BF23E4753A00807FAE /* MPDocumentSplitViewController.m */,
|
||||
4C20E4C023E4753A00807FAE /* DocumentSplitView.xib */,
|
||||
4C7D9D5224ABE6FD00907034 /* MPTabViewController.h */,
|
||||
4C7D9D5324ABE6FD00907034 /* MPTabViewController.m */,
|
||||
);
|
||||
name = "View Controller";
|
||||
sourceTree = "<group>";
|
||||
@@ -2191,6 +2196,7 @@
|
||||
4C0949591FD6B89B004F2971 /* NSUserNotification+MPAdditions.m in Sources */,
|
||||
4C2057EE23CDF6F900C731EC /* MPPathCell.m in Sources */,
|
||||
4C3B42871F935316007B04FD /* MPDayCountFormatter.m in Sources */,
|
||||
4C7D9D5424ABE6FD00907034 /* MPTabViewController.m in Sources */,
|
||||
3C0CDECF21CFEDD200B2A10B /* NSTextView+MPTouchBarExtension.m in Sources */,
|
||||
4C57AE1417BA422B00CA4F34 /* MPSegmentedContextCell.m in Sources */,
|
||||
4CE2961518429AA5005F01CE /* MPAutotypeKeyPress.m in Sources */,
|
||||
|
||||
@@ -338,7 +338,7 @@
|
||||
<constraint firstAttribute="trailing" secondItem="wD1-ag-7V5" secondAttribute="trailing" constant="20" id="ccK-FL-7Wx"/>
|
||||
<constraint firstItem="465" firstAttribute="top" secondItem="888" secondAttribute="bottom" constant="6" id="wyH-HB-i2U"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-535" y="-327"/>
|
||||
<point key="canvasLocation" x="-535" y="-327.5"/>
|
||||
</customView>
|
||||
</objects>
|
||||
</document>
|
||||
|
||||
@@ -29,10 +29,11 @@
|
||||
#import "MPWorkflowPreferencesController.h"
|
||||
#import "MPUpdatePreferencesController.h"
|
||||
#import "MPPluginPreferencesController.h"
|
||||
#import "MPTabViewController.h"
|
||||
|
||||
@interface MPPreferencesWindowController ()
|
||||
|
||||
@property (strong) NSTabViewController *tabViewController;
|
||||
@property (strong) MPTabViewController *tabViewController;
|
||||
|
||||
@end
|
||||
|
||||
@@ -45,7 +46,7 @@
|
||||
-(id)init {
|
||||
self = [super initWithWindow:nil];
|
||||
if(self) {
|
||||
_tabViewController = [[NSTabViewController alloc] init];
|
||||
_tabViewController = [[MPTabViewController alloc] init];
|
||||
_tabViewController.tabStyle = NSTabViewControllerTabStyleToolbar;
|
||||
_tabViewController.transitionOptions = NSViewControllerTransitionNone | NSViewControllerTransitionAllowUserInteraction;
|
||||
|
||||
@@ -84,6 +85,7 @@
|
||||
[(id<MPPreferencesTab>)item.viewController willShowTab];
|
||||
}
|
||||
self.tabViewController.selectedTabViewItemIndex = index;
|
||||
|
||||
if([item.viewController respondsToSelector:@selector(didShowTab)]) {
|
||||
[(id<MPPreferencesTab>)item.viewController didShowTab];
|
||||
}
|
||||
@@ -146,4 +148,6 @@
|
||||
[self.tabViewController addTabViewItem:item];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
17
MacPass/MPTabViewController.h
Normal file
17
MacPass/MPTabViewController.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// MPTabViewController.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 30.06.20.
|
||||
// Copyright © 2020 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MPTabViewController : NSTabViewController
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
58
MacPass/MPTabViewController.m
Normal file
58
MacPass/MPTabViewController.m
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// MPTabViewController.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 30.06.20.
|
||||
// Copyright © 2020 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPTabViewController.h"
|
||||
|
||||
@interface MPTabViewController ()
|
||||
@property (strong) NSMutableDictionary<NSString *, NSValue*> *tabViewSizes;
|
||||
@end
|
||||
|
||||
@implementation MPTabViewController
|
||||
|
||||
- (instancetype)initWithNibName:(NSNibName)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
||||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
||||
if(self) {
|
||||
_tabViewSizes = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if(self) {
|
||||
_tabViewSizes = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem {
|
||||
[super tabView:tabView didSelectTabViewItem:tabViewItem];
|
||||
[self _resizeWindowToFitTabView:tabViewItem];
|
||||
}
|
||||
|
||||
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem {
|
||||
[super tabView:tabView willSelectTabViewItem:tabViewItem];
|
||||
if(tabViewItem.view) {
|
||||
self.tabViewSizes[tabViewItem.identifier] = @(tabViewItem.view.frame.size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)_resizeWindowToFitTabView:(NSTabViewItem *)tabViewItem {
|
||||
NSSize size = self.tabViewSizes[tabViewItem.identifier].sizeValue;
|
||||
NSWindow *window = self.view.window;
|
||||
|
||||
NSRect contentRect = NSMakeRect(0, 0, size.width, size.height);
|
||||
NSRect contentFrame = [window frameRectForContentRect:contentRect];
|
||||
CGFloat toolbarHeight = CGRectGetHeight(window.frame) - CGRectGetHeight(contentFrame);
|
||||
NSPoint newOrigin = NSMakePoint(CGRectGetMinX(window.frame), CGRectGetMinY(window.frame) + toolbarHeight);
|
||||
NSRect newFrame = NSMakeRect(newOrigin.x,newOrigin.y, CGRectGetWidth(contentFrame), CGRectGetHeight(contentFrame));
|
||||
[window setFrame:newFrame display:NO animate:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -15,13 +15,13 @@
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
|
||||
<rect key="contentRect" x="196" y="240" width="400" height="700"/>
|
||||
<rect key="contentRect" x="196" y="240" width="530" height="508"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
|
||||
<view key="contentView" id="2">
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="700"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="530" height="508"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</view>
|
||||
<point key="canvasLocation" x="-81" y="-210"/>
|
||||
<point key="canvasLocation" x="-16" y="-306"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
||||
|
||||
Reference in New Issue
Block a user