Using NSSplitview with auto layout instead of delgation

This commit is contained in:
michael starke
2013-05-17 22:09:29 +02:00
parent 73bd260c46
commit 292187d1c4
11 changed files with 105 additions and 66 deletions

View File

@@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1080</int>
<string key="IBDocument.SystemVersion">12C3103</string>
<string key="IBDocument.SystemVersion">12D78</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.34</string>
<string key="IBDocument.HIToolboxVersion">625.00</string>
<string key="IBDocument.AppKitVersion">1187.37</string>
<string key="IBDocument.HIToolboxVersion">626.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">3084</string>
@@ -894,10 +894,10 @@
<string key="filterBar">NSView</string>
<string key="filterDoneButton">NSButton</string>
<string key="filterLabelTextField">NSTextField</string>
<string key="filterSearchField">NSSearchField</string>
<string key="filterTitleButton">NSButton</string>
<string key="filterURLButton">NSButton</string>
<string key="filterUsernameButton">NSButton</string>
<string key="pathBar">NSView</string>
<string key="tableToBottom">NSLayoutConstraint</string>
<string key="tableToTop">NSLayoutConstraint</string>
</dictionary>
@@ -918,6 +918,10 @@
<string key="name">filterLabelTextField</string>
<string key="candidateClassName">NSTextField</string>
</object>
<object class="IBToOneOutletInfo" key="filterSearchField">
<string key="name">filterSearchField</string>
<string key="candidateClassName">NSSearchField</string>
</object>
<object class="IBToOneOutletInfo" key="filterTitleButton">
<string key="name">filterTitleButton</string>
<string key="candidateClassName">NSButton</string>
@@ -930,10 +934,6 @@
<string key="name">filterUsernameButton</string>
<string key="candidateClassName">NSButton</string>
</object>
<object class="IBToOneOutletInfo" key="pathBar">
<string key="name">pathBar</string>
<string key="candidateClassName">NSView</string>
</object>
<object class="IBToOneOutletInfo" key="tableToBottom">
<string key="name">tableToBottom</string>
<string key="candidateClassName">NSLayoutConstraint</string>

View File

@@ -36,6 +36,5 @@
Clears the Search filter
*/
- (void)toggleInspector:(id)sender;
- (void)toggleOutlineView:(id)sender;
@end

View File

@@ -41,10 +41,8 @@
@property (retain) MPMainWindowSplitViewDelegate *splitViewDelegate;
- (void)_setContentViewController:(MPViewController *)viewController;
- (void)_setOutlineVisible:(BOOL)isVisible;
/* window reszing and content checks */
- (BOOL)_windowsIsLargeEnoughForInspectorView;
- (void)_resizeWindowForInspectorView;
@end
@@ -57,18 +55,13 @@
_toolbarDelegate = [[MPToolbarDelegate alloc] init];
_outlineViewController = [[MPOutlineViewController alloc] init];
_inspectorTabViewController = [[MPInspectorTabViewController alloc] init];
_splitViewDelegate = [[MPMainWindowSplitViewDelegate alloc] init];
_passwordEditController = [[MPPasswordEditViewController alloc] init];
[[NSBundle mainBundle] loadNibNamed:@"WelcomeView" owner:self topLevelObjects:NULL];
[self.welcomeView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_welcomeView release];
[_toolbar release];
[_passwordInputController release];
@@ -88,10 +81,6 @@
{
[super windowDidLoad];
[[self.welcomeText cell] setBackgroundStyle:NSBackgroundStyleRaised];
CGFloat minWidht = MPMainWindowSplitViewDelegateMinimumContentWidth + MPMainWindowSplitViewDelegateMinimumOutlineWidth + [self.splitView dividerThickness];
[self.window setMinSize:NSMakeSize( minWidht, 400)];
_toolbar = [[NSToolbar alloc] initWithIdentifier:@"MainWindowToolbar"];
[self.toolbar setAllowsUserCustomization:YES];
[self.toolbar setDelegate:self.toolbarDelegate];
@@ -113,14 +102,14 @@
[self.splitView replaceSubview:self.inspectorView with:[self.inspectorTabViewController view]];
[self.inspectorTabViewController updateResponderChain];
[self.splitView adjustSubviews];
[self toggleInspector:nil];
[self _setContentViewController:nil];
[self _setOutlineVisible:NO];
MPDocument *document = [self document];
if(!document.isDecrypted) {
[self showPasswordInput];
}
else {
[self editPassword:nil];
}
}
- (void)_setContentViewController:(MPViewController *)viewController {
@@ -157,36 +146,31 @@
[self.window makeFirstResponder:[viewController reconmendedFirstResponder]];
}
- (void)_setOutlineVisible:(BOOL)isVisible {
self.outlineViewController.isVisible = isVisible;
}
#pragma mark Actions
- (void)toggleInspector:(id)sender {
NSView *inspectorView = [self.splitView subviews][MPSplitViewInspectorViewIndex];
const BOOL collapsed = [self.splitView isSubviewCollapsed:inspectorView];
if(collapsed) {
if( NO == [self _windowsIsLargeEnoughForInspectorView]) {
[self _resizeWindowForInspectorView];
}
CGFloat splitterPosition = [self.splitView frame].size.width - MPMainWindowSplitViewDelegateMinimumInspectorWidth;
[self.splitView setPosition:splitterPosition ofDividerAtIndex:MPSplitViewInspectorDividerIndex];
if(self.inspectorTabViewController) {
[self.inspectorTabViewController toggleVisible];
}
else {
CGFloat splitterPosition = [self.splitView frame].size.width;
[self.splitView setPosition:splitterPosition ofDividerAtIndex:MPSplitViewInspectorDividerIndex];
}
[inspectorView setHidden:!collapsed];
}
- (void)performFindPanelAction:(id)sender {
[self.entryViewController showFilter:sender];
}
- (void)toggleOutlineView:(id)sender {
[self _setOutlineVisible:!self.outlineViewController.isVisible];
}
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
SEL menuAction = [menuItem action];
if(menuAction == @selector(toggleOutlineView:)) {
if(menuAction == @selector(main:)) {
NSView *outlineView = [self.splitView subviews][MPSplitViewOutlineViewIndex];
BOOL outlineIsHidden = [self.splitView isSubviewCollapsed:outlineView];
NSString *title = outlineIsHidden ? NSLocalizedString(@"SHOW_OUTLINE_VIEW", @"") : NSLocalizedString(@"HIDE_OUTLINE_VIEW", @"Hide the Outline View");
@@ -240,24 +224,6 @@
return nil;
}
- (BOOL)_windowsIsLargeEnoughForInspectorView {
return ( MPMainWindowSplitViewDelegateMinimumInspectorWidth
< ([self.splitView frame].size.width
- MPMainWindowSplitViewDelegateMinimumContentWidth
- MPMainWindowSplitViewDelegateMinimumOutlineWidth
- 2 * [self.splitView dividerThickness]) );
}
- (void)_resizeWindowForInspectorView {
NSRect frame = [self.window frame];
NSView *outlinView = [self.splitView subviews][MPSplitViewOutlineViewIndex];
NSView *contentView = [self.splitView subviews][MPSplitViewContentViewIndex];
CGFloat outlineWidth = [self.splitView isSubviewCollapsed:outlinView] ? 0 : [outlinView frame].size.width;
frame.size.width = outlineWidth + [contentView frame].size.width + MPMainWindowSplitViewDelegateMinimumInspectorWidth;
[self.window setFrame:frame display:YES animate:YES];
}
#pragma mark Notifications
- (void)showEntries {
if(!self.entryViewController) {
@@ -265,6 +231,7 @@
}
[self _setContentViewController:self.entryViewController];
[self.outlineViewController showOutline];
[self _setOutlineVisible:YES];
}
@end

View File

@@ -169,6 +169,16 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
[self.entryTable bind:NSSortDescriptorsBinding toObject:self.entryArrayController withKeyPath:@"sortDescriptors" options:nil];
[parentColumn setHidden:YES];
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:[self view]
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:300];
[[self view] addConstraint:widthConstraint];
}
#pragma mark NSTableViewDelgate

View File

@@ -26,6 +26,7 @@
@property (assign) IBOutlet NSButton *openURLButton;
@property (assign) IBOutlet NSButton *showPasswordCreator;
- (void)toggleVisible;
- (IBAction)togglePasswordDisplay:(id)sender;
- (void)hideImagePopup:(id)sender;

View File

@@ -16,13 +16,17 @@
#import "KdbLib.h"
#import "KdbEntry+Undo.h"
@interface MPInspectorTabViewController ()
@interface MPInspectorTabViewController () {
BOOL _visible;
}
@property (assign) NSUInteger selectedTabIndex;
@property (assign, nonatomic) KdbEntry *selectedEntry;
@property (assign, nonatomic) KdbGroup *selectedGroup;
@property (assign) BOOL showsEntry;
@property (retain) NSPopover *iconPopup;
@property (retain) NSLayoutConstraint *showConstraint;
@property (retain) NSLayoutConstraint *hideConstraint;
- (void)_didChangeSelectedEntry:(NSNotification *)notification;
- (void)_didChangeSelectedGroup:(NSNotification *)notification;
@@ -79,9 +83,33 @@
name:MPOutlineViewDidChangeGroupSelection
object:nil];
self.showConstraint = [NSLayoutConstraint constraintWithItem:[self view] attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:300];
self.hideConstraint = [NSLayoutConstraint constraintWithItem:[self view] attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:0];
[self.view addConstraint:self.showConstraint];
[self _clearContent];
}
- (void)toggleVisible {
const BOOL isVisible = [[self view] frame].size.width > 0;
NSLayoutConstraint *add = isVisible ? self.hideConstraint : self.showConstraint;
NSLayoutConstraint *remove = isVisible ? self.showConstraint : self.hideConstraint;
[[self view] removeConstraint:remove];
[[self view] addConstraint:add];
[[self view] layout];
}
- (void)_updateContent {
if(self.showsEntry && self.selectedEntry) {
[self _showEntry];

View File

@@ -13,6 +13,7 @@
@interface MPOutlineViewController : MPViewController
@property (retain, readonly) MPOutlineViewDelegate *outlineDelegate;
@property (assign, nonatomic) BOOL isVisible;
- (void)clearSelection;
- (void)showOutline;

View File

@@ -20,6 +20,8 @@
@property (retain) MPOutlineDataSource *datasource;
@property (retain) MPOutlineViewDelegate *outlineDelegate;
@property (retain) NSMenu *menu;
@property (retain) NSLayoutConstraint *showConstraint;
@property (retain) NSLayoutConstraint *hideConstraint;
- (void)_didUpdateData:(NSNotification *)notification;
@@ -37,6 +39,7 @@
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_isVisible = YES;
self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease];
self.datasource = [[[MPOutlineDataSource alloc] init] autorelease];
@@ -45,7 +48,7 @@
name:MPDocumentDidAddGroupNotification
object:[[self windowController] document]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didUpdateData:)
name:MPDocumentDidDelteGroupNotification
@@ -70,6 +73,24 @@
[self.outlineView setDelegate:self.outlineDelegate];
[self.outlineView setMenu:[self _contextMenu]];
[self.outlineView setAllowsEmptySelection:YES];
self.showConstraint = [NSLayoutConstraint constraintWithItem:[self view]
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:200];
self.hideConstraint = [NSLayoutConstraint constraintWithItem:[self view]
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:0];
[[self view] addConstraint:self.showConstraint];
}
- (void)showOutline {
@@ -82,6 +103,16 @@
[self.outlineView deselectAll:nil];
}
- (void)setIsVisible:(BOOL)isVisible {
if(_isVisible == isVisible) {
return; // nichts zu tun
}
[[self view] removeConstraint:(isVisible ? self.hideConstraint : self.showConstraint)];
[[self view] addConstraint:(isVisible ? self.showConstraint : self.hideConstraint)];
_isVisible = isVisible;
}
- (NSMenu *)_contextMenu {
NSMenu *menu = [[NSMenu alloc] init];
NSArray *items = [(MPAppDelegate *)[NSApp delegate] contextMenuItemsWithItems:MPContextMenuMinimal];

View File

@@ -46,7 +46,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>6AE</string>
<string>6E0</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>

View File

@@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1080</int>
<string key="IBDocument.SystemVersion">12C60</string>
<string key="IBDocument.SystemVersion">12D78</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.34</string>
<string key="IBDocument.HIToolboxVersion">625.00</string>
<string key="IBDocument.AppKitVersion">1187.37</string>
<string key="IBDocument.HIToolboxVersion">626.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="NS.object.0">3084</string>
@@ -759,7 +759,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">194</int>
<int key="maxID">195</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">

View File

@@ -43,7 +43,7 @@
<string key="NSClassName">NSApplication</string>
</object>
<object class="NSCustomView" id="1005">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">268</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="NSTextField" id="660673733">
@@ -252,6 +252,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{209, 50}, {74, 32}}</string>
<reference key="NSSuperview" ref="1005"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSHuggingPriority">{250, 250}</string>
<bool key="NSEnabled">YES</bool>
@@ -273,6 +274,7 @@
</object>
</array>
<string key="NSFrameSize">{362, 268}</string>
<reference key="NSSuperview"/>
<reference key="NSNextKeyView" ref="204058255"/>
<string key="NSClassName">NSView</string>
</object>