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

View File

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

View File

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

View File

@@ -169,6 +169,16 @@ NSString *const _toggleFilterUsernameButton = @"SearchUsername";
[self.entryTable bind:NSSortDescriptorsBinding toObject:self.entryArrayController withKeyPath:@"sortDescriptors" options:nil]; [self.entryTable bind:NSSortDescriptorsBinding toObject:self.entryArrayController withKeyPath:@"sortDescriptors" options:nil];
[parentColumn setHidden:YES]; [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 #pragma mark NSTableViewDelgate

View File

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

View File

@@ -16,13 +16,17 @@
#import "KdbLib.h" #import "KdbLib.h"
#import "KdbEntry+Undo.h" #import "KdbEntry+Undo.h"
@interface MPInspectorTabViewController () @interface MPInspectorTabViewController () {
BOOL _visible;
}
@property (assign) NSUInteger selectedTabIndex; @property (assign) NSUInteger selectedTabIndex;
@property (assign, nonatomic) KdbEntry *selectedEntry; @property (assign, nonatomic) KdbEntry *selectedEntry;
@property (assign, nonatomic) KdbGroup *selectedGroup; @property (assign, nonatomic) KdbGroup *selectedGroup;
@property (assign) BOOL showsEntry; @property (assign) BOOL showsEntry;
@property (retain) NSPopover *iconPopup; @property (retain) NSPopover *iconPopup;
@property (retain) NSLayoutConstraint *showConstraint;
@property (retain) NSLayoutConstraint *hideConstraint;
- (void)_didChangeSelectedEntry:(NSNotification *)notification; - (void)_didChangeSelectedEntry:(NSNotification *)notification;
- (void)_didChangeSelectedGroup:(NSNotification *)notification; - (void)_didChangeSelectedGroup:(NSNotification *)notification;
@@ -79,9 +83,33 @@
name:MPOutlineViewDidChangeGroupSelection name:MPOutlineViewDidChangeGroupSelection
object:nil]; 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]; [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 { - (void)_updateContent {
if(self.showsEntry && self.selectedEntry) { if(self.showsEntry && self.selectedEntry) {
[self _showEntry]; [self _showEntry];

View File

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

View File

@@ -20,6 +20,8 @@
@property (retain) MPOutlineDataSource *datasource; @property (retain) MPOutlineDataSource *datasource;
@property (retain) MPOutlineViewDelegate *outlineDelegate; @property (retain) MPOutlineViewDelegate *outlineDelegate;
@property (retain) NSMenu *menu; @property (retain) NSMenu *menu;
@property (retain) NSLayoutConstraint *showConstraint;
@property (retain) NSLayoutConstraint *hideConstraint;
- (void)_didUpdateData:(NSNotification *)notification; - (void)_didUpdateData:(NSNotification *)notification;
@@ -37,6 +39,7 @@
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { if (self) {
_isVisible = YES;
self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease]; self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease];
self.datasource = [[[MPOutlineDataSource alloc] init] autorelease]; self.datasource = [[[MPOutlineDataSource alloc] init] autorelease];
@@ -45,7 +48,7 @@
name:MPDocumentDidAddGroupNotification name:MPDocumentDidAddGroupNotification
object:[[self windowController] document]]; object:[[self windowController] document]];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didUpdateData:) selector:@selector(_didUpdateData:)
name:MPDocumentDidDelteGroupNotification name:MPDocumentDidDelteGroupNotification
@@ -70,6 +73,24 @@
[self.outlineView setDelegate:self.outlineDelegate]; [self.outlineView setDelegate:self.outlineDelegate];
[self.outlineView setMenu:[self _contextMenu]]; [self.outlineView setMenu:[self _contextMenu]];
[self.outlineView setAllowsEmptySelection:YES]; [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 { - (void)showOutline {
@@ -82,6 +103,16 @@
[self.outlineView deselectAll:nil]; [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 *)_contextMenu {
NSMenu *menu = [[NSMenu alloc] init]; NSMenu *menu = [[NSMenu alloc] init];
NSArray *items = [(MPAppDelegate *)[NSApp delegate] contextMenuItemsWithItems:MPContextMenuMinimal]; NSArray *items = [(MPAppDelegate *)[NSApp delegate] contextMenuItemsWithItems:MPContextMenuMinimal];

View File

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

View File

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

View File

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