Added first rudimentary search capability

This commit is contained in:
michael starke
2013-02-20 03:36:51 +01:00
parent 7ea037cdc3
commit 73880ca419
17 changed files with 256 additions and 94 deletions

View File

@@ -80,6 +80,7 @@
4CAD748E15B88AC100104512 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAD748D15B88AC100104512 /* libz.dylib */; }; 4CAD748E15B88AC100104512 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAD748D15B88AC100104512 /* libz.dylib */; };
4CB9339916D3A0DD00A13B5D /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 4CB9339716D3A0DD00A13B5D /* Credits.rtf */; }; 4CB9339916D3A0DD00A13B5D /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 4CB9339716D3A0DD00A13B5D /* Credits.rtf */; };
4CBA981815BA0DB600721965 /* MPDatabaseDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBA981715BA0DB600721965 /* MPDatabaseDocument.m */; }; 4CBA981815BA0DB600721965 /* MPDatabaseDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBA981715BA0DB600721965 /* MPDatabaseDocument.m */; };
4CC1AEBE16D4467C006D2AAB /* KdbTree+MPAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC1AEBD16D4467C006D2AAB /* KdbTree+MPAdditions.m */; };
4CC6259115BA1C99002F5B11 /* MPOutlineViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6259015BA1C99002F5B11 /* MPOutlineViewDelegate.m */; }; 4CC6259115BA1C99002F5B11 /* MPOutlineViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6259015BA1C99002F5B11 /* MPOutlineViewDelegate.m */; };
4CD78ABC16D155FF00768A1D /* 07_NotepadTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CD78AB716D155FF00768A1D /* 07_NotepadTemplate.pdf */; }; 4CD78ABC16D155FF00768A1D /* 07_NotepadTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CD78AB716D155FF00768A1D /* 07_NotepadTemplate.pdf */; };
4CD78ABD16D155FF00768A1D /* 08_SocketTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CD78AB816D155FF00768A1D /* 08_SocketTemplate.pdf */; }; 4CD78ABD16D155FF00768A1D /* 08_SocketTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CD78AB816D155FF00768A1D /* 08_SocketTemplate.pdf */; };
@@ -230,6 +231,8 @@
4CB9339816D3A0DD00A13B5D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; }; 4CB9339816D3A0DD00A13B5D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; };
4CBA981615BA0DB600721965 /* MPDatabaseDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseDocument.h; sourceTree = "<group>"; }; 4CBA981615BA0DB600721965 /* MPDatabaseDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseDocument.h; sourceTree = "<group>"; };
4CBA981715BA0DB600721965 /* MPDatabaseDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseDocument.m; sourceTree = "<group>"; }; 4CBA981715BA0DB600721965 /* MPDatabaseDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseDocument.m; sourceTree = "<group>"; };
4CC1AEBC16D4467C006D2AAB /* KdbTree+MPAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KdbTree+MPAdditions.h"; sourceTree = "<group>"; };
4CC1AEBD16D4467C006D2AAB /* KdbTree+MPAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KdbTree+MPAdditions.m"; sourceTree = "<group>"; };
4CC6258F15BA1C99002F5B11 /* MPOutlineViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineViewDelegate.h; sourceTree = "<group>"; }; 4CC6258F15BA1C99002F5B11 /* MPOutlineViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineViewDelegate.h; sourceTree = "<group>"; };
4CC6259015BA1C99002F5B11 /* MPOutlineViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineViewDelegate.m; sourceTree = "<group>"; }; 4CC6259015BA1C99002F5B11 /* MPOutlineViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineViewDelegate.m; sourceTree = "<group>"; };
4CD78AB716D155FF00768A1D /* 07_NotepadTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 07_NotepadTemplate.pdf; sourceTree = "<group>"; }; 4CD78AB716D155FF00768A1D /* 07_NotepadTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 07_NotepadTemplate.pdf; sourceTree = "<group>"; };
@@ -276,6 +279,8 @@
children = ( children = (
4C2C4C2A16D3BE3700D49295 /* KdbGroup+MPAdditions.h */, 4C2C4C2A16D3BE3700D49295 /* KdbGroup+MPAdditions.h */,
4C2C4C2B16D3BE3700D49295 /* KdbGroup+MPAdditions.m */, 4C2C4C2B16D3BE3700D49295 /* KdbGroup+MPAdditions.m */,
4CC1AEBC16D4467C006D2AAB /* KdbTree+MPAdditions.h */,
4CC1AEBD16D4467C006D2AAB /* KdbTree+MPAdditions.m */,
); );
name = KeePassLibAdditions; name = KeePassLibAdditions;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -746,6 +751,7 @@
4CAC6F7816D2B54800D79D5E /* MPMainWindowSplitViewDelegate.m in Sources */, 4CAC6F7816D2B54800D79D5E /* MPMainWindowSplitViewDelegate.m in Sources */,
4C61EA0316D2FD0800AC519E /* MPOutlineViewController.m in Sources */, 4C61EA0316D2FD0800AC519E /* MPOutlineViewController.m in Sources */,
4C2C4C2C16D3BE3700D49295 /* KdbGroup+MPAdditions.m in Sources */, 4C2C4C2C16D3BE3700D49295 /* KdbGroup+MPAdditions.m in Sources */,
4CC1AEBE16D4467C006D2AAB /* KdbTree+MPAdditions.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@@ -18,7 +18,6 @@
<string>NSTableHeaderView</string> <string>NSTableHeaderView</string>
<string>NSTableView</string> <string>NSTableView</string>
<string>NSTextFieldCell</string> <string>NSTextFieldCell</string>
<string>NSUserDefaultsController</string>
</array> </array>
<array key="IBDocument.PluginDependencies"> <array key="IBDocument.PluginDependencies">
<string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -243,6 +242,7 @@
<string key="NSFrame">{{1, 119}, {223, 15}}</string> <string key="NSFrame">{{1, 119}, {223, 15}}</string>
<reference key="NSSuperview" ref="613995671"/> <reference key="NSSuperview" ref="613995671"/>
<reference key="NSWindow"/> <reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:60</string> <string key="NSReuseIdentifierKey">_NS:60</string>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool> <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
<int key="NSsFlags">1</int> <int key="NSsFlags">1</int>
@@ -281,9 +281,6 @@
<double key="NSMaxMagnification">4</double> <double key="NSMaxMagnification">4</double>
<double key="NSMagnification">1</double> <double key="NSMagnification">1</double>
</object> </object>
<object class="NSUserDefaultsController" id="735198371">
<bool key="NSSharedInstance">YES</bool>
</object>
</array> </array>
<object class="IBObjectContainer" key="IBDocument.Objects"> <object class="IBObjectContainer" key="IBDocument.Objects">
<array class="NSMutableArray" key="connectionRecords"> <array class="NSMutableArray" key="connectionRecords">
@@ -341,6 +338,21 @@
</array> </array>
<reference key="parent" ref="0"/> <reference key="parent" ref="0"/>
</object> </object>
<object class="IBObjectRecord">
<int key="objectID">58</int>
<reference key="object" ref="1037276411"/>
<reference key="parent" ref="613995671"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">57</int>
<reference key="object" ref="778100560"/>
<reference key="parent" ref="613995671"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">56</int>
<reference key="object" ref="802411427"/>
<reference key="parent" ref="613995671"/>
</object>
<object class="IBObjectRecord"> <object class="IBObjectRecord">
<int key="objectID">55</int> <int key="objectID">55</int>
<reference key="object" ref="528076956"/> <reference key="object" ref="528076956"/>
@@ -352,37 +364,17 @@
<reference key="parent" ref="613995671"/> <reference key="parent" ref="613995671"/>
</object> </object>
<object class="IBObjectRecord"> <object class="IBObjectRecord">
<int key="objectID">56</int> <int key="objectID">121</int>
<reference key="object" ref="802411427"/> <reference key="object" ref="872321844"/>
<reference key="parent" ref="613995671"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">57</int>
<reference key="object" ref="778100560"/>
<reference key="parent" ref="613995671"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">58</int>
<reference key="object" ref="1037276411"/>
<reference key="parent" ref="613995671"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">115</int>
<reference key="object" ref="735198371"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">117</int>
<reference key="object" ref="673679325"/>
<array class="NSMutableArray" key="children"> <array class="NSMutableArray" key="children">
<reference ref="201181707"/> <reference ref="1023118108"/>
</array> </array>
<reference key="parent" ref="528076956"/> <reference key="parent" ref="528076956"/>
</object> </object>
<object class="IBObjectRecord"> <object class="IBObjectRecord">
<int key="objectID">118</int> <int key="objectID">122</int>
<reference key="object" ref="201181707"/> <reference key="object" ref="1023118108"/>
<reference key="parent" ref="673679325"/> <reference key="parent" ref="872321844"/>
</object> </object>
<object class="IBObjectRecord"> <object class="IBObjectRecord">
<int key="objectID">119</int> <int key="objectID">119</int>
@@ -398,17 +390,17 @@
<reference key="parent" ref="486655598"/> <reference key="parent" ref="486655598"/>
</object> </object>
<object class="IBObjectRecord"> <object class="IBObjectRecord">
<int key="objectID">121</int> <int key="objectID">117</int>
<reference key="object" ref="872321844"/> <reference key="object" ref="673679325"/>
<array class="NSMutableArray" key="children"> <array class="NSMutableArray" key="children">
<reference ref="1023118108"/> <reference ref="201181707"/>
</array> </array>
<reference key="parent" ref="528076956"/> <reference key="parent" ref="528076956"/>
</object> </object>
<object class="IBObjectRecord"> <object class="IBObjectRecord">
<int key="objectID">122</int> <int key="objectID">118</int>
<reference key="object" ref="1023118108"/> <reference key="object" ref="201181707"/>
<reference key="parent" ref="872321844"/> <reference key="parent" ref="673679325"/>
</object> </object>
</array> </array>
</object> </object>
@@ -416,7 +408,6 @@
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="115.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="117.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="117.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="118.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="118.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="119.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="119.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -434,7 +425,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">122</int> <int key="maxID">231</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

@@ -10,9 +10,8 @@
@interface KdbGroup (MPAdditions) @interface KdbGroup (MPAdditions)
+ (KdbGroup *)group; - (NSArray *)childGroups;
+ (KdbGroup *)groupWithName:(NSString *)name;
+ (void)refreshModificationTime; - (NSArray *)childEntries;
@end @end

View File

@@ -10,15 +10,21 @@
@implementation KdbGroup (MPAdditions) @implementation KdbGroup (MPAdditions)
+ (KdbGroup *)group { - (NSArray *)childGroups {
KdbGroup *group = [[KdbGroup alloc] init]; NSMutableArray *childGroups = [NSMutableArray arrayWithCapacity:[self.groups count]];
[group setName:@"Default"]; for(KdbGroup *childGroup in self.groups) {
return [group autorelease]; [childGroups addObjectsFromArray:[childGroup childGroups]];
}
return childGroups;
} }
+ (KdbGroup *)groupWithName:(NSString *)name { - (NSArray *)childEntries {
KdbGroup *group = [KdbGroup group]; NSMutableArray *childEntries = [NSMutableArray arrayWithCapacity:[self.groups count] + [self.entries count]];
[group setName:name]; [childEntries addObjectsFromArray:self.entries];
return group; for( KdbGroup *childGroup in self.groups) {
[childEntries addObjectsFromArray:[childGroup childEntries]];
}
return childEntries;
} }
@end @end

View File

@@ -0,0 +1,17 @@
//
// KdbTree+MPAdditions.h
// MacPass
//
// Created by michael starke on 20.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "Kdb.h"
@interface KdbTree (MPAdditions)
- (NSArray *)allEntries;
- (NSArray *)allGroups;
@end

View File

@@ -0,0 +1,22 @@
//
// KdbTree+MPAdditions.m
// MacPass
//
// Created by michael starke on 20.02.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "KdbTree+MPAdditions.h"
#import "KdbGroup+MPAdditions.h"
@implementation KdbTree (MPAdditions)
- (NSArray *)allGroups {
return [self.root childGroups];
}
- (NSArray *)allEntries {
return [self.root childEntries];
}
@end

View File

@@ -12,5 +12,6 @@
@interface MPAppDelegate : NSObject <NSApplicationDelegate> @interface MPAppDelegate : NSObject <NSApplicationDelegate>
- (IBAction) showMainWindow:(id)sender;
@end @end

View File

@@ -29,6 +29,11 @@
} }
#pragma mark Menu Actions #pragma mark Menu Actions
- (void)showMainWindow:(id)sender {
[self.mainWindowController showMainWindow:sender];
}
- (void)showPreferences:(id)sender { - (void)showPreferences:(id)sender {
if(self.settingsController == nil) { if(self.settingsController == nil) {
self.settingsController = [[[MPSettingsController alloc] init] autorelease]; self.settingsController = [[[MPSettingsController alloc] init] autorelease];

View File

@@ -16,5 +16,6 @@
@property (nonatomic, assign) id<NSOutlineViewDelegate> outlineViewDelegate; @property (nonatomic, assign) id<NSOutlineViewDelegate> outlineViewDelegate;
@property (assign) KdbGroup *activeGroup; @property (assign) KdbGroup *activeGroup;
@property (readonly, retain) NSArrayController *entryArrayController; @property (readonly, retain) NSArrayController *entryArrayController;
@property (nonatomic, retain) NSString *filter;
@end @end

View File

@@ -8,6 +8,9 @@
#import "MPEntryViewController.h" #import "MPEntryViewController.h"
#import "MPOutlineViewDelegate.h" #import "MPOutlineViewDelegate.h"
#import "MPDatabaseController.h"
#import "MPDatabaseDocument.h"
#import "KdbGroup+MPAdditions.h"
NSString *const _MPUserNameColumnIdentifier = @"MPUserNameColumnIdentifier"; NSString *const _MPUserNameColumnIdentifier = @"MPUserNameColumnIdentifier";
NSString *const _MPTitleColumnIdentifier = @"MPTitleColumnIdentifier"; NSString *const _MPTitleColumnIdentifier = @"MPTitleColumnIdentifier";
@@ -16,8 +19,12 @@ NSString *const _MPPasswordColumnIdentifier = @"MPPasswordColumnIdentifier";
@interface MPEntryViewController () @interface MPEntryViewController ()
@property (retain) NSArrayController *entryArrayController; @property (retain) NSArrayController *entryArrayController;
@property (retain) NSArray *filteredEntries;
@property (assign) IBOutlet NSTableView *entryTable; @property (assign) IBOutlet NSTableView *entryTable;
- (BOOL)hasActiveFilter;
- (void)updateFilter;
- (void)didChangeGroupSelectionInOutlineView:(NSNotification *)notification; - (void)didChangeGroupSelectionInOutlineView:(NSNotification *)notification;
@end @end
@@ -59,6 +66,12 @@ NSString *const _MPPasswordColumnIdentifier = @"MPPasswordColumnIdentifier";
} }
- (void)didChangeGroupSelectionInOutlineView:(NSNotification *)notification { - (void)didChangeGroupSelectionInOutlineView:(NSNotification *)notification {
/*
If we have an active search, do not mess with the content
*/
if([self hasActiveFilter]) {
return;
}
MPOutlineViewDelegate *delegate = [notification object]; MPOutlineViewDelegate *delegate = [notification object];
KdbGroup *group = delegate.selectedGroup; KdbGroup *group = delegate.selectedGroup;
if(group) { if(group) {
@@ -69,4 +82,35 @@ NSString *const _MPPasswordColumnIdentifier = @"MPPasswordColumnIdentifier";
} }
} }
- (BOOL)hasActiveFilter {
return ([self.filter length] > 0);
}
- (void)setFilter:(NSString *)filter {
if(_filter != filter) {
[_filter release];
_filter = [filter retain];
[self updateFilter];
}
}
- (void)updateFilter {
MPDatabaseDocument *openDatabase = [MPDatabaseController defaultController].database;
if(openDatabase) {
if([self.filter isEqualToString:@"*"]) {
self.filteredEntries = [openDatabase.root childEntries];
}
else {
NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"SELF.title CONTAINS[cd] %@", self.filter];
self.filteredEntries = [[openDatabase.root childEntries] filteredArrayUsingPredicate:filterPredicate];
}
[self.entryArrayController setContent:self.filteredEntries];
}
else {
[self.entryArrayController setContent:nil];
self.filteredEntries = nil;
}
}
@end @end

View File

@@ -13,6 +13,8 @@
@interface MPMainWindowController : NSWindowController @interface MPMainWindowController : NSWindowController
- (void)showEntries; - (void)showEntries;
- (void)showMainWindow:(id)sender;
- (void)performFindPanelAction:(id)sender;
/* /*
Sets the content View controller Sets the content View controller
@param viewController - use nil to reset to welcome screen @param viewController - use nil to reset to welcome screen

View File

@@ -38,7 +38,7 @@
-(id)init { -(id)init {
self = [super initWithWindowNibName:@"MainWindow" owner:self]; self = [super initWithWindowNibName:@"MainWindow" owner:self];
if( self ) { if( self ) {
_toolbarDelegate = [[MPToolbarDelegate alloc] init]; _toolbarDelegate = [[MPToolbarDelegate alloc] init];
_outlineViewController = [[MPOutlineViewController alloc] init]; _outlineViewController = [[MPOutlineViewController alloc] init];
_splitViewDelegate = [[MPMainWindowSplitViewDelegate alloc] init]; _splitViewDelegate = [[MPMainWindowSplitViewDelegate alloc] init];
@@ -115,6 +115,14 @@
#pragma mark Actions #pragma mark Actions
- (void)performFindPanelAction:(id)sender {
[self.window makeFirstResponder:[self.toolbarDelegate.searchItem view]];
}
- (void)showMainWindow:(id)sender {
[self showWindow:self.window];
}
- (void)openDocument:(id)sender { - (void)openDocument:(id)sender {
if(!self.passwordInputController) { if(!self.passwordInputController) {
@@ -135,6 +143,11 @@
}]; }];
} }
- (void)updateFilter:(id)sender {
NSSearchField *searchField = sender;
self.entryViewController.filter = [searchField stringValue];
}
#pragma mark Notifications #pragma mark Notifications
- (void)didOpenDocument:(NSNotification *)notification { - (void)didOpenDocument:(NSNotification *)notification {

View File

@@ -9,7 +9,6 @@
#import "MPMainWindowSplitViewDelegate.h" #import "MPMainWindowSplitViewDelegate.h"
const CGFloat MPMainWindowSplitViewDelegateMinimumOutlineWidth = 150.0; const CGFloat MPMainWindowSplitViewDelegateMinimumOutlineWidth = 150.0;
const CGFloat MPMainWindowSplitViewDelegateMaximumOutlineWidth = 400.0;
const CGFloat MPMainWindowSplitViewDelegateMinimumContentWidth = 400.0; const CGFloat MPMainWindowSplitViewDelegateMinimumContentWidth = 400.0;
@interface MPMainWindowSplitViewDelegate () @interface MPMainWindowSplitViewDelegate ()
@@ -29,6 +28,10 @@ const CGFloat MPMainWindowSplitViewDelegateMinimumContentWidth = 400.0;
return [splitView subviews][1]; return [splitView subviews][1];
} }
- (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview {
return (subview == [self leftView:splitView]);
}
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex { - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex {
return (proposedMinimumPosition < MPMainWindowSplitViewDelegateMinimumOutlineWidth) ? MPMainWindowSplitViewDelegateMinimumOutlineWidth : proposedMinimumPosition; return (proposedMinimumPosition < MPMainWindowSplitViewDelegateMinimumOutlineWidth) ? MPMainWindowSplitViewDelegateMinimumOutlineWidth : proposedMinimumPosition;
} }
@@ -45,18 +48,12 @@ const CGFloat MPMainWindowSplitViewDelegateMinimumContentWidth = 400.0;
NSView *leftView = [self leftView:splitView]; NSView *leftView = [self leftView:splitView];
NSView *rightView = [self rightView:splitView]; NSView *rightView = [self rightView:splitView];
CGFloat leftRelativeWidth = [leftView frame].size.width / oldSize.width; CGFloat leftWidth = [leftView isHidden] ? 0.0 : [leftView frame].size.width;
CGFloat newLeftWidth = floor(newSize.width * leftRelativeWidth); NSRect newRightFrame = NSMakeRect(leftWidth + dividierThickness, 0, newSize.width - leftWidth - dividierThickness, newSize.height);
NSRect newLeftFrame = NSMakeRect(0, 0, leftWidth, newSize.height);
if( newLeftWidth < MPMainWindowSplitViewDelegateMinimumOutlineWidth && newSize.width > MPMainWindowSplitViewDelegateMinimumOutlineWidth ) { if(NO == [leftView isHidden]) {
newLeftWidth = MPMainWindowSplitViewDelegateMinimumOutlineWidth; [leftView setFrame:newLeftFrame];
} }
if( newLeftWidth > MPMainWindowSplitViewDelegateMaximumOutlineWidth ) {
newLeftWidth = MPMainWindowSplitViewDelegateMaximumOutlineWidth;
}
NSRect newLeftFrame = NSMakeRect(0, 0, newLeftWidth, newSize.height);
NSRect newRightFrame = NSMakeRect(newLeftWidth + dividierThickness, 0, newSize.width - newLeftWidth - dividierThickness, newSize.height);
[leftView setFrame:newLeftFrame];
[rightView setFrame:newRightFrame]; [rightView setFrame:newRightFrame];
}; };

View File

@@ -8,6 +8,10 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class MPMainWindowController;
@interface MPToolbarDelegate : NSObject <NSToolbarDelegate> @interface MPToolbarDelegate : NSObject <NSToolbarDelegate>
@property (assign) NSToolbarItem *searchItem;
@end @end

View File

@@ -8,12 +8,14 @@
#import "MPToolbarDelegate.h" #import "MPToolbarDelegate.h"
#import "MPIconHelper.h" #import "MPIconHelper.h"
#import "MPMainWindowController.h"
NSString *const MPToolbarItemAddGroup = @"AddGroup"; NSString *const MPToolbarItemAddGroup = @"AddGroup";
NSString *const MPToolbarItemAddEntry = @"AddEntry"; NSString *const MPToolbarItemAddEntry = @"AddEntry";
NSString *const MPToolbarItemEdit = @"Edit"; NSString *const MPToolbarItemEdit = @"Edit";
NSString *const MPToolbarItemDelete =@"Delete"; NSString *const MPToolbarItemDelete =@"Delete";
NSString *const MPToolbarItemAction = @"Action"; NSString *const MPToolbarItemAction = @"Action";
NSString *const MPToolbarItemSearch = @"Search";
@interface MPToolbarDelegate() @interface MPToolbarDelegate()
@@ -30,7 +32,7 @@ NSString *const MPToolbarItemAction = @"Action";
{ {
self = [super init]; self = [super init];
if (self) { if (self) {
self.toolbarIdentifiers = @[ MPToolbarItemAddEntry, MPToolbarItemDelete, MPToolbarItemEdit, MPToolbarItemAddGroup, MPToolbarItemAction ]; self.toolbarIdentifiers = @[ MPToolbarItemAddEntry, MPToolbarItemDelete, MPToolbarItemEdit, MPToolbarItemAddGroup, MPToolbarItemAction, NSToolbarFlexibleSpaceItemIdentifier, MPToolbarItemSearch ];
self.toolbarItems = [NSMutableDictionary dictionaryWithCapacity:[self.toolbarItems count]]; self.toolbarItems = [NSMutableDictionary dictionaryWithCapacity:[self.toolbarItems count]];
self.toolbarImages = [self createToolbarImages]; self.toolbarImages = [self createToolbarImages];
} }
@@ -40,9 +42,23 @@ NSString *const MPToolbarItemAction = @"Action";
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag { - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
NSToolbarItem *item = self.toolbarItems[ itemIdentifier ]; NSToolbarItem *item = self.toolbarItems[ itemIdentifier ];
if( !item ) { if( !item ) {
item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier]; item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
NSButton *button; [item setAction:@selector(toolbarItemPressed:)];
if([itemIdentifier isEqualToString:MPToolbarItemAction]) { self.toolbarItems[itemIdentifier] = item;
NSString *label = NSLocalizedString(itemIdentifier, @"");
[item setLabel:label];
[item release];
if([itemIdentifier isEqualToString:MPToolbarItemSearch]) {
NSSearchField *searchfield = [[NSSearchField alloc] initWithFrame:NSMakeRect(0, 0, 70, 32)];
[item setView:searchfield];
[searchfield setAction:@selector(updateFilter:)];
[[searchfield cell] setSendsSearchStringImmediately:YES];
[searchfield release];
self.searchItem = item;
}
else if([itemIdentifier isEqualToString:MPToolbarItemAction]) {
NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 50, 32) pullsDown:YES]; NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 50, 32) pullsDown:YES];
[[popupButton cell] setBezelStyle:NSTexturedRoundedBezelStyle]; [[popupButton cell] setBezelStyle:NSTexturedRoundedBezelStyle];
[[popupButton cell] setImageScaling:NSImageScaleProportionallyDown]; [[popupButton cell] setImageScaling:NSImageScaleProportionallyDown];
@@ -51,9 +67,9 @@ NSString *const MPToolbarItemAction = @"Action";
Built menu Built menu
*/ */
NSMenu *menu = [NSMenu allocWithZone:[NSMenu menuZone]]; NSMenu *menu = [NSMenu allocWithZone:[NSMenu menuZone]];
NSMenuItem *item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"" action:NULL keyEquivalent:@""]; NSMenuItem *menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"" action:NULL keyEquivalent:@""];
[item setImage:self.toolbarImages[itemIdentifier]]; [menuItem setImage:self.toolbarImages[itemIdentifier]];
[menu addItem:item]; [menu addItem:menuItem];
[menu addItemWithTitle:@"Foo" action:NULL keyEquivalent:@""]; [menu addItemWithTitle:@"Foo" action:NULL keyEquivalent:@""];
[menu addItemWithTitle:@"Bar" action:NULL keyEquivalent:@""]; [menu addItemWithTitle:@"Bar" action:NULL keyEquivalent:@""];
[popupButton setMenu:menu]; [popupButton setMenu:menu];
@@ -61,12 +77,15 @@ NSString *const MPToolbarItemAction = @"Action";
/* /*
Cleanup Cleanup
*/ */
[item release]; [menuItem release];
[menu release]; [menu release];
button = popupButton; [popupButton sizeToFit];
[item setView:popupButton];
[popupButton release];
} }
else { else {
button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 32, 32)]; NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 32, 32)];
[[button cell] setBezelStyle:NSTexturedRoundedBezelStyle]; [[button cell] setBezelStyle:NSTexturedRoundedBezelStyle];
[[button cell] setImageScaling:NSImageScaleProportionallyDown]; [[button cell] setImageScaling:NSImageScaleProportionallyDown];
[button setTitle:@""]; [button setTitle:@""];
@@ -74,20 +93,11 @@ NSString *const MPToolbarItemAction = @"Action";
NSImage *image = self.toolbarImages[itemIdentifier]; NSImage *image = self.toolbarImages[itemIdentifier];
[button setImage:image]; [button setImage:image];
[button setImagePosition:NSImageOnly]; [button setImagePosition:NSImageOnly];
[button sizeToFit];
[item setView:button];
[button release];
} }
[button sizeToFit];
NSString *label = NSLocalizedString(itemIdentifier, @"");
[item setLabel:label];
[item setView:button];
[item setAction:@selector(toolbarItemPressed:)];
self.toolbarItems[itemIdentifier] = item;
[item release];
[button release];
return item; return item;
} }

View File

@@ -21,7 +21,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>B9</string> <string>F7</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

@@ -759,6 +759,25 @@
<reference key="NSOnImage" ref="35465992"/> <reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/> <reference key="NSMixedImage" ref="502551668"/>
</object> </object>
<object class="NSMenuItem" id="964160035">
<reference key="NSMenu" ref="835318025"/>
<bool key="NSIsDisabled">YES</bool>
<bool key="NSIsSeparator">YES</bool>
<string key="NSTitle"/>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="174162306">
<reference key="NSMenu" ref="835318025"/>
<string key="NSTitle">Show Main Window</string>
<string key="NSKeyEquiv">0</string>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="299356726"> <object class="NSMenuItem" id="299356726">
<reference key="NSMenu" ref="835318025"/> <reference key="NSMenu" ref="835318025"/>
<bool key="NSIsDisabled">YES</bool> <bool key="NSIsDisabled">YES</bool>
@@ -1227,6 +1246,14 @@
</object> </object>
<int key="connectionID">1175</int> <int key="connectionID">1175</int>
</object> </object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">showMainWindow:</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="174162306"/>
</object>
<int key="connectionID">1178</int>
</object>
</array> </array>
<object class="IBMutableOrderedSet" key="objectRecords"> <object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects"> <array key="orderedObjects">
@@ -1620,6 +1647,8 @@
<reference ref="625202149"/> <reference ref="625202149"/>
<reference ref="575023229"/> <reference ref="575023229"/>
<reference ref="1011231497"/> <reference ref="1011231497"/>
<reference ref="964160035"/>
<reference ref="174162306"/>
</array> </array>
<reference key="parent" ref="713487014"/> <reference key="parent" ref="713487014"/>
</object> </object>
@@ -1843,6 +1872,16 @@
<reference key="object" ref="738670835"/> <reference key="object" ref="738670835"/>
<reference key="parent" ref="963351320"/> <reference key="parent" ref="963351320"/>
</object> </object>
<object class="IBObjectRecord">
<int key="objectID">1176</int>
<reference key="object" ref="964160035"/>
<reference key="parent" ref="835318025"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">1177</int>
<reference key="object" ref="174162306"/>
<reference key="parent" ref="835318025"/>
</object>
</array> </array>
</object> </object>
<dictionary class="NSMutableDictionary" key="flattenedProperties"> <dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -1850,6 +1889,8 @@
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="112.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="112.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="1176.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="1177.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="124.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="124.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="125.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="125.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="126.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string> <string key="126.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1944,24 +1985,27 @@
<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">1175</int> <int key="maxID">1178</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">
<object class="IBPartialClassDescription"> <object class="IBPartialClassDescription">
<string key="className">MPAppDelegate</string> <string key="className">MPAppDelegate</string>
<string key="superclassName">NSObject</string> <string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="actions"> <dictionary class="NSMutableDictionary" key="actions">
<string key="NS.key.0">showPreferences:</string> <string key="showMainWindow:">id</string>
<string key="NS.object.0">id</string> <string key="showPreferences:">id</string>
</object> </dictionary>
<object class="NSMutableDictionary" key="actionInfosByName"> <dictionary class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">showPreferences:</string> <object class="IBActionInfo" key="showMainWindow:">
<object class="IBActionInfo" key="NS.object.0"> <string key="name">showMainWindow:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="showPreferences:">
<string key="name">showPreferences:</string> <string key="name">showPreferences:</string>
<string key="candidateClassName">id</string> <string key="candidateClassName">id</string>
</object> </object>
</object> </dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier"> <object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string> <string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/MPAppDelegate.h</string> <string key="minorKey">./Classes/MPAppDelegate.h</string>