Centralized actions inside MPDocumetnWindowController

This commit is contained in:
michael starke
2014-10-24 16:18:53 +02:00
parent 675c5f92c8
commit 3a2dff5e07
13 changed files with 112 additions and 87 deletions

View File

@@ -510,7 +510,7 @@
4C26C34A18D8D5A300CF1A1C /* PreviewView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PreviewView.xib; sourceTree = "<group>"; }; 4C26C34A18D8D5A300CF1A1C /* PreviewView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PreviewView.xib; sourceTree = "<group>"; };
4C2724D51778FF1A00FD8456 /* NSUUID+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSUUID+KeePassKit.h"; sourceTree = "<group>"; }; 4C2724D51778FF1A00FD8456 /* NSUUID+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSUUID+KeePassKit.h"; sourceTree = "<group>"; };
4C2724D61778FF1A00FD8456 /* NSUUID+KeePassKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSUUID+KeePassKit.m"; sourceTree = "<group>"; }; 4C2724D61778FF1A00FD8456 /* NSUUID+KeePassKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSUUID+KeePassKit.m"; sourceTree = "<group>"; };
4C2B0B7419F66F6400E48913 /* MPTargetItemResolving.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTargetItemResolving.h; sourceTree = "<group>"; }; 4C2B0B7419F66F6400E48913 /* MPTargetNodeResolving.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTargetNodeResolving.h; sourceTree = "<group>"; };
4C2C8B331787500E009649F3 /* UnprotectedWarningView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = UnprotectedWarningView.xib; sourceTree = "<group>"; }; 4C2C8B331787500E009649F3 /* UnprotectedWarningView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = UnprotectedWarningView.xib; sourceTree = "<group>"; };
4C2E381A16D11FF900037A9D /* 03_ServerTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 03_ServerTemplate.pdf; sourceTree = "<group>"; }; 4C2E381A16D11FF900037A9D /* 03_ServerTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 03_ServerTemplate.pdf; sourceTree = "<group>"; };
4C2E381B16D11FF900037A9D /* 04_KlipperTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 04_KlipperTemplate.pdf; sourceTree = "<group>"; }; 4C2E381B16D11FF900037A9D /* 04_KlipperTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 04_KlipperTemplate.pdf; sourceTree = "<group>"; };
@@ -1683,7 +1683,7 @@
children = ( children = (
4CF6C715176F5183007A811D /* MPServerRequestHandling.h */, 4CF6C715176F5183007A811D /* MPServerRequestHandling.h */,
4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */, 4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */,
4C2B0B7419F66F6400E48913 /* MPTargetItemResolving.h */, 4C2B0B7419F66F6400E48913 /* MPTargetNodeResolving.h */,
); );
name = Protocolls; name = Protocolls;
sourceTree = "<group>"; sourceTree = "<group>";

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment defaultVersion="1080" identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPGroupInspectorViewController"> <customObject id="-2" userLabel="File's Owner" customClass="MPGroupInspectorViewController">
@@ -18,21 +18,18 @@
</connections> </connections>
</customObject> </customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="37" customClass="HNHScrollView"> <scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="37" customClass="HNHScrollView">
<rect key="frame" x="0.0" y="0.0" width="257" height="261"/> <rect key="frame" x="0.0" y="0.0" width="257" height="261"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" id="HjA-kA-fcX"> <clipView key="contentView" id="HjA-kA-fcX">
<rect key="frame" x="0.0" y="0.0" width="257" height="261"/> <rect key="frame" x="0.0" y="0.0" width="257" height="261"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<view translatesAutoresizingMaskIntoConstraints="NO" id="38" customClass="HNHScrollDocumentViewAdapter"> <view translatesAutoresizingMaskIntoConstraints="NO" id="38" customClass="HNHScrollDocumentViewAdapter">
<rect key="frame" x="0.0" y="0.0" width="257" height="261"/> <rect key="frame" x="0.0" y="0.0" width="257" height="261"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="24"> <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="24">
<rect key="frame" x="18" y="242" width="35" height="14"/> <rect key="frame" x="18" y="242" width="35" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Name" id="25"> <textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Name" id="25">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/>
@@ -41,7 +38,6 @@
</textField> </textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="23" customClass="HNHRoundedTextField"> <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="23" customClass="HNHRoundedTextField">
<rect key="frame" x="20" y="212" width="217" height="22"/> <rect key="frame" x="20" y="212" width="217" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="26"> <textFieldCell key="cell" lineBreakMode="truncatingTail" truncatesLastVisibleLine="YES" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="26">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
@@ -53,7 +49,6 @@
</textField> </textField>
<button horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="5"> <button horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="5">
<rect key="frame" x="18" y="184" width="67" height="18"/> <rect key="frame" x="18" y="184" width="67" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="14" id="pWR-o1-KI6"/> <constraint firstAttribute="height" constant="14" id="pWR-o1-KI6"/>
</constraints> </constraints>
@@ -67,7 +62,6 @@
</button> </button>
<button focusRingType="exterior" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4"> <button focusRingType="exterior" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4">
<rect key="frame" x="206" y="183" width="31" height="19"/> <rect key="frame" x="206" y="183" width="31" height="19"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="31" id="l5I-EF-dHs"/> <constraint firstAttribute="width" constant="31" id="l5I-EF-dHs"/>
</constraints> </constraints>
@@ -82,7 +76,6 @@
</button> </button>
<popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="229"> <popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="229">
<rect key="frame" x="18" y="128" width="222" height="26"/> <rect key="frame" x="18" y="128" width="222" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="230"> <popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="230">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/> <font key="font" metaFont="menu"/>
@@ -102,7 +95,6 @@
</popUpButton> </popUpButton>
<popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="240"> <popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="240">
<rect key="frame" x="18" y="73" width="222" height="26"/> <rect key="frame" x="18" y="73" width="222" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="242"> <popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="242">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/> <font key="font" metaFont="menu"/>
@@ -120,7 +112,6 @@
</popUpButton> </popUpButton>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="264"> <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="264">
<rect key="frame" x="18" y="160" width="40" height="14"/> <rect key="frame" x="18" y="160" width="40" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Search" id="265"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Search" id="265">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/>
@@ -129,7 +120,6 @@
</textField> </textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="276"> <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="276">
<rect key="frame" x="18" y="105" width="53" height="14"/> <rect key="frame" x="18" y="105" width="53" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Autotype" id="277"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Autotype" id="277">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/>
@@ -138,7 +128,6 @@
</textField> </textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Fnw-qz-IZU" customClass="HNHRoundedTextField"> <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Fnw-qz-IZU" customClass="HNHRoundedTextField">
<rect key="frame" x="20" y="20" width="217" height="22"/> <rect key="frame" x="20" y="20" width="217" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="VeF-V7-i2I"> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="VeF-V7-i2I">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
@@ -150,7 +139,6 @@
</textField> </textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6Lw-XW-x20"> <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6Lw-XW-x20">
<rect key="frame" x="18" y="50" width="107" height="14"/> <rect key="frame" x="18" y="50" width="107" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Autotype Sequence" id="6FG-UZ-Adh"> <textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Autotype Sequence" id="6FG-UZ-Adh">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/>

View File

@@ -73,9 +73,9 @@
<constraint firstAttribute="width" constant="32" id="3027"/> <constraint firstAttribute="width" constant="32" id="3027"/>
<constraint firstAttribute="height" constant="32" id="3028"/> <constraint firstAttribute="height" constant="32" id="3028"/>
</constraints> </constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSActionTemplate" id="2999"/> <imageCell key="cell" alignment="left" imageScaling="proportionallyUpOrDown" image="NSActionTemplate" id="2999"/>
<connections> <connections>
<action selector="pickIcon:" target="-1" id="IZz-hu-GkW"/> <action selector="pickIcon:" target="-2" id="6wh-Ka-Thl"/>
</connections> </connections>
</imageView> </imageView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="3013"> <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="3013">

View File

@@ -23,6 +23,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "KPKVersion.h" #import "KPKVersion.h"
#import "MPEntrySearchContext.h" #import "MPEntrySearchContext.h"
#import "MPTargetNodeResolving.h"
/** /**
* Posted when a new group was added to the document. * Posted when a new group was added to the document.
@@ -59,7 +60,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@class KPKNode; @class KPKNode;
@class MPEditSession; @class MPEditSession;
@interface MPDocument : NSDocument @interface MPDocument : NSDocument <MPTargetNodeResolving>
@property (nonatomic, readonly, assign) BOOL encrypted; @property (nonatomic, readonly, assign) BOOL encrypted;
@@ -164,6 +165,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
- (KPKEntry *)createEntry:(KPKGroup *)parent; - (KPKEntry *)createEntry:(KPKGroup *)parent;
- (KPKAttribute *)createCustomAttribute:(KPKEntry *)entry; - (KPKAttribute *)createCustomAttribute:(KPKEntry *)entry;
- (void)deleteNode:(KPKNode *)node;
- (void)deleteGroup:(KPKGroup *)group; - (void)deleteGroup:(KPKGroup *)group;
- (void)deleteEntry:(KPKEntry *)entry; - (void)deleteEntry:(KPKEntry *)entry;

View File

@@ -32,7 +32,7 @@
#import "MPConstants.h" #import "MPConstants.h"
#import "MPSavePanelAccessoryViewController.h" #import "MPSavePanelAccessoryViewController.h"
#import "MPTreeDelegate.h" #import "MPTreeDelegate.h"
#import "MPTargetItemResolving.h" #import "MPTargetNodeResolving.h"
#import "DDXMLNode.h" #import "DDXMLNode.h"
@@ -512,7 +512,19 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
return newAttribute; return newAttribute;
} }
- (void)deleteNode:(KPKNode *)node {
if([node asGroup]) {
[self deleteGroup:[node asGroup]];
}
else if([node asEntry]) {
[self deleteEntry:[node asEntry]];
}
}
- (void)deleteEntry:(KPKEntry *)entry { - (void)deleteEntry:(KPKEntry *)entry {
if(!entry) {
return; // Nothing to do;
}
if(self.useTrash) { if(self.useTrash) {
if([self isItemTrashed:entry]) { if([self isItemTrashed:entry]) {
return; // Entry is already trashed return; // Entry is already trashed
@@ -615,11 +627,13 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
} }
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem { - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)anItem {
id target = [NSApp targetForAction:@selector(targetItemForAction)]; id<MPTargetNodeResolving> entryResolver = [NSApp targetForAction:@selector(currentTargetEntry)];
KPKNode *targetNode = [target targetItemForAction]; id<MPTargetNodeResolving> groupResolver = [NSApp targetForAction:@selector(currentTargetGroup)];
KPKEntry *targetEntry = [targetNode asEntry]; id<MPTargetNodeResolving> nodeResolver = [NSApp targetForAction:@selector(currentTargetNode)];
KPKGroup *targetGroup = [targetNode asGroup]; KPKNode *targetNode = [nodeResolver currentTargetNode];
KPKEntry *targetEntry = [entryResolver currentTargetEntry];
KPKGroup *targetGroup = [groupResolver currentTargetGroup];
if(self.encrypted || self.isReadOnly) { return NO; } if(self.encrypted || self.isReadOnly) { return NO; }
BOOL valid = self.selectedItem ? self.selectedItem.isEditable : YES; BOOL valid = self.selectedItem ? self.selectedItem.isEditable : YES;
@@ -640,9 +654,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
valid &= ![self isItemTrashed:self.selectedItem]; valid &= ![self isItemTrashed:self.selectedItem];
break; break;
case MPActionCloneEntry: case MPActionCloneEntry:
//case MPActionCloneEntryWithOptions: valid &= (nil != targetEntry);
valid &= (nil != self.selectedItem);
valid &= self.selectedEntry == self.selectedItem;
break; break;
case MPActionEmptyTrash: case MPActionEmptyTrash:
valid &= ([self.trash.groups count] + [self.trash.entries count]) > 0; valid &= ([self.trash.groups count] + [self.trash.entries count]) > 0;
@@ -720,6 +732,18 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
[self.trash clear]; [self.trash clear];
} }
#pragma mark -
#pragma mark MPTargetNodeResolving
- (KPKEntry *)currentTargetEntry {
return self.selectedEntry;
}
- (KPKGroup *)currentTargetGroup {
return self.selectedGroup;
}
# pragma mark File Watching # pragma mark File Watching
- (void) _watchForFileChanges:(BOOL)watch { - (void) _watchForFileChanges:(BOOL)watch {
} }

View File

@@ -45,8 +45,9 @@
- (IBAction)lock:(id)sender; - (IBAction)lock:(id)sender;
- (IBAction)createGroup:(id)sender; - (IBAction)createGroup:(id)sender;
- (IBAction)createEntry:(id)sender;
- (IBAction)delete:(id)sender;
- (IBAction)pickIcon:(id)sender;
- (IBAction)pickExpiryDate:(id)sender; - (IBAction)pickExpiryDate:(id)sender;
#pragma mark Helper #pragma mark Helper

View File

@@ -24,6 +24,7 @@
#import "MPContextToolbarButton.h" #import "MPContextToolbarButton.h"
#import "KPKTree.h" #import "KPKTree.h"
#import "KPKEntry.h"
#import "KPKCompositeKey.h" #import "KPKCompositeKey.h"
typedef NS_ENUM(NSUInteger, MPAlertContext) { typedef NS_ENUM(NSUInteger, MPAlertContext) {
@@ -326,15 +327,25 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
} }
- (void)createGroup:(id)sender { - (void)createGroup:(id)sender {
[self.outlineViewController createGroup:nil]; id<MPTargetNodeResolving> target = [NSApp targetForAction:@selector(currentTargetGroup)];
KPKGroup *group = [target currentTargetGroup];
MPDocument *document = self.document;
if(!group) {
group = document.root;
}
[document createGroup:group];
} }
- (void)createEntry:(id)sender { - (void)createEntry:(id)sender {
[self.outlineViewController createEntry:nil]; id<MPTargetNodeResolving> target = [NSApp targetForAction:@selector(currentTargetGroup)];
KPKGroup *group = [target currentTargetGroup];
[(MPDocument *)self.document createEntry:group];
} }
- (void)pickIcon:(id)sender { - (void)delete:(id)sender {
[self.inspectorViewController pickIcon:sender]; id<MPTargetNodeResolving> target = [NSApp targetForAction:@selector(currentTargetNode)];
KPKNode *node = [target currentTargetNode];
[self.document deleteNode:node];
} }
- (void)pickExpiryDate:(id)sender { - (void)pickExpiryDate:(id)sender {

View File

@@ -8,7 +8,7 @@
#import "MPViewController.h" #import "MPViewController.h"
#import "MPContextBarViewController.h" #import "MPContextBarViewController.h"
#import "MPTargetItemResolving.h" #import "MPTargetNodeResolving.h"
APPKIT_EXTERN NSString *const MPEntryTableUserNameColumnIdentifier; APPKIT_EXTERN NSString *const MPEntryTableUserNameColumnIdentifier;
APPKIT_EXTERN NSString *const MPEntryTableTitleColumnIdentifier; APPKIT_EXTERN NSString *const MPEntryTableTitleColumnIdentifier;
@@ -32,7 +32,7 @@ typedef NS_ENUM( NSUInteger, MPCopyContentTypeTag) {
@class MPDocumentWindowController; @class MPDocumentWindowController;
@class MPDocument; @class MPDocument;
@interface MPEntryViewController : MPViewController <NSTableViewDelegate, MPTargetItemResolving> @interface MPEntryViewController : MPViewController <NSTableViewDelegate, MPTargetNodeResolving>
@property (weak,readonly) NSTableView *entryTable; @property (weak,readonly) NSTableView *entryTable;
@property (readonly, strong) NSArrayController *entryArrayController; @property (readonly, strong) NSArrayController *entryArrayController;

View File

@@ -340,7 +340,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
} }
#pragma mark MPTargetItemResolving #pragma mark MPTargetItemResolving
- (KPKNode *)targetItemForAction { - (KPKEntry *)currentTargetEntry {
NSInteger activeRow = [self.entryTable clickedRow]; NSInteger activeRow = [self.entryTable clickedRow];
/* Fallback to selection e.g. for toolbar actions */ /* Fallback to selection e.g. for toolbar actions */
if(activeRow < 0 ) { if(activeRow < 0 ) {
@@ -352,6 +352,15 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
return nil; return nil;
} }
- (KPKNode *)currentTargetNode {
KPKEntry *entry = [self currentTargetEntry];
if(entry) {
return entry;
}
MPDocument *document = [[self windowController] document];
return document.selectedItem;
}
#pragma mark MPDocument Notifications #pragma mark MPDocument Notifications
- (void)_didChangeCurrentItem:(NSNotification *)notification { - (void)_didChangeCurrentItem:(NSNotification *)notification {
MPDocument *document = [notification object]; MPDocument *document = [notification object];
@@ -597,21 +606,21 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
#pragma mark Actions #pragma mark Actions
- (void)copyPassword:(id)sender { - (void)copyPassword:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry]; KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry) { if(selectedEntry) {
[self _copyToPasteboard:[selectedEntry.password finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoPassword name:nil]; [self _copyToPasteboard:[selectedEntry.password finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoPassword name:nil];
} }
} }
- (void)copyUsername:(id)sender { - (void)copyUsername:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry]; KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry) { if(selectedEntry) {
[self _copyToPasteboard:[selectedEntry.username finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoUsername name:nil]; [self _copyToPasteboard:[selectedEntry.username finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoUsername name:nil];
} }
} }
- (void)copyCustomAttribute:(id)sender { - (void)copyCustomAttribute:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry]; KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry && [selectedEntry isKindOfClass:[KPKEntry class]]) { if(selectedEntry && [selectedEntry isKindOfClass:[KPKEntry class]]) {
NSUInteger index = [sender tag]; NSUInteger index = [sender tag];
NSAssert((index >= 0) && (index < [selectedEntry.customAttributes count]), @"Index for custom field needs to be valid"); NSAssert((index >= 0) && (index < [selectedEntry.customAttributes count]), @"Index for custom field needs to be valid");
@@ -621,14 +630,14 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
} }
- (void)copyURL:(id)sender { - (void)copyURL:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry]; KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry) { if(selectedEntry) {
[self _copyToPasteboard:[selectedEntry.url finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoURL name:nil]; [self _copyToPasteboard:[selectedEntry.url finalValueForEntry:selectedEntry] overlayInfo:MPOverlayInfoURL name:nil];
} }
} }
- (void)openURL:(id)sender { - (void)openURL:(id)sender {
KPKEntry *selectedEntry = [[self targetItemForAction] asEntry]; KPKEntry *selectedEntry = [[self currentTargetNode] asEntry];
if(selectedEntry && [selectedEntry.url length] > 0) { if(selectedEntry && [selectedEntry.url length] > 0) {
NSURL *webURL = [NSURL URLWithString:[selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSURL *webURL = [NSURL URLWithString:[selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *scheme = [webURL scheme]; NSString *scheme = [webURL scheme];
@@ -650,7 +659,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
} }
- (void)delete:(id)sender { - (void)delete:(id)sender {
KPKEntry *entry = [[self targetItemForAction] asEntry]; KPKEntry *entry = [[self currentTargetNode] asEntry];
if(!entry) { if(!entry) {
return; return;
} }

View File

@@ -80,7 +80,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
- (void)awakeFromNib { - (void)awakeFromNib {
[self.bottomBar setBorderType:HNHBorderTop|HNHBorderHighlight]; [self.bottomBar setBorderType:HNHBorderTop|HNHBorderHighlight];
[[self.noSelectionInfo cell] setBackgroundStyle:NSBackgroundStyleRaised]; [[self.noSelectionInfo cell] setBackgroundStyle:NSBackgroundStyleRaised];
[[self.itemImageView cell] setBackgroundStyle:NSBackgroundStyleRaised]; [[self.itemImageView cell] setBackgroundStyle:NSBackgroundStyleRaised];
[self.tabView bind:NSSelectedIndexBinding toObject:self withKeyPath:@"activeTab" options:nil]; [self.tabView bind:NSSelectedIndexBinding toObject:self withKeyPath:@"activeTab" options:nil];
@@ -304,6 +304,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
[self.itemNameTextField setHidden:NO]; [self.itemNameTextField setHidden:NO];
} }
#pragma mark - #pragma mark -
#pragma mark MPDocument Notifications #pragma mark MPDocument Notifications

View File

@@ -7,14 +7,14 @@
// //
#import "MPViewController.h" #import "MPViewController.h"
#import "MPTargetItemResolving.h" #import "MPTargetNodeResolving.h"
APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection; APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
@class HNHGradientView; @class HNHGradientView;
@class MPDocument; @class MPDocument;
@interface MPOutlineViewController : MPViewController <MPTargetItemResolving, NSOutlineViewDelegate, NSMenuDelegate> @interface MPOutlineViewController : MPViewController <MPTargetNodeResolving, NSOutlineViewDelegate, NSMenuDelegate>
@property (weak) IBOutlet HNHGradientView *bottomBar; @property (weak) IBOutlet HNHGradientView *bottomBar;
@@ -23,8 +23,6 @@ APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
- (void)showOutline; - (void)showOutline;
- (void)regsiterNotificationsForDocument:(MPDocument *)document; - (void)regsiterNotificationsForDocument:(MPDocument *)document;
- (void)createGroup:(id)sender;
- (void)createEntry:(id)sender;
/** /**
* Retrieves the current item for the current mouse location * Retrieves the current item for the current mouse location
* @return Item under mouse. If the mouse isn't inside the view, nil is returned * @return Item under mouse. If the mouse isn't inside the view, nil is returned

View File

@@ -7,22 +7,23 @@
// //
#import "MPOutlineViewController.h" #import "MPOutlineViewController.h"
#import "MPOutlineDataSource.h" #import "MPActionHelper.h"
#import "MPConstants.h"
#import "MPContextMenuHelper.h"
#import "MPDocument.h" #import "MPDocument.h"
#import "MPDocumentWindowController.h" #import "MPDocumentWindowController.h"
#import "MPContextMenuHelper.h"
#import "MPConstants.h"
#import "MPActionHelper.h"
#import "MPIconHelper.h" #import "MPIconHelper.h"
#import "MPNotifications.h" #import "MPNotifications.h"
#import "MPOutlineContextMenuDelegate.h" #import "MPOutlineContextMenuDelegate.h"
#import "MPOutlineDataSource.h"
#import "KPKTree.h" #import "KPKEntry.h"
#import "KPKNode.h"
#import "KPKTimeInfo.h"
#import "KPKGroup.h" #import "KPKGroup.h"
#import "KPKNode+IconImage.h"
#import "KPKMetaData.h" #import "KPKMetaData.h"
#import "KPKNode.h"
#import "KPKNode+IconImage.h"
#import "KPKTimeInfo.h"
#import "KPKTree.h"
#import "KPKUTIs.h" #import "KPKUTIs.h"
#import "HNHGradientView.h" #import "HNHGradientView.h"
@@ -136,17 +137,12 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
#pragma mark Custom Setter/Getter #pragma mark Custom Setter/Getter
- (void)setDatabaseNameWrapper:(NSString *)databaseNameWrapper { - (void)setDatabaseNameWrapper:(NSString *)databaseNameWrapper {
if(![_databaseNameWrapper isEqualToString:databaseNameWrapper]) { if(![_databaseNameWrapper isEqualToString:databaseNameWrapper]) {
if([databaseNameWrapper length] == 0) { _databaseNameWrapper = (databaseNameWrapper.length == 0) ? NSLocalizedString(@"DATABASE", "Default name database") : [databaseNameWrapper copy];
_databaseNameWrapper = NSLocalizedString(@"DATABASE", "Default name database");
}
else {
_databaseNameWrapper= [databaseNameWrapper copy];
}
} }
} }
#pragma mark MPTargetItemResolving #pragma mark MPTargetNodeResolving
- (KPKNode *)targetItemForAction { - (KPKGroup *)currentTargetGroup {
NSInteger row = [self.outlineView clickedRow]; NSInteger row = [self.outlineView clickedRow];
if( row < 0 ) { if( row < 0 ) {
row = [self.outlineView selectedRow]; row = [self.outlineView selectedRow];
@@ -154,6 +150,15 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
return [[self.outlineView itemAtRow:row] representedObject]; return [[self.outlineView itemAtRow:row] representedObject];
} }
- (KPKNode *)currentTargetNode {
KPKGroup *group = [self currentTargetGroup];
if(group) {
return group;
}
MPDocument *document = [[self windowController] document];
return document.selectedItem;
}
#pragma mark Notifications #pragma mark Notifications
- (void)regsiterNotificationsForDocument:(MPDocument *)document { - (void)regsiterNotificationsForDocument:(MPDocument *)document {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document];
@@ -197,24 +202,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
#pragma mark - #pragma mark -
#pragma mark Actions #pragma mark Actions
- (void)createGroup:(id)sender {
KPKGroup *group = [[self targetItemForAction] asGroup];
MPDocument *document = [[self windowController] document];
if(!group) {
group = document.root;
}
[document createGroup:group];
}
- (void)createEntry:(id)sender {
MPDocument *document = [[self windowController] document];
[document createEntry:[[self targetItemForAction] asGroup]];
}
- (void)delete:(id)sender {
[[[self windowController] document] deleteGroup:[[self targetItemForAction] asGroup]];
}
- (void)_doubleClickedGroup:(id)sender { - (void)_doubleClickedGroup:(id)sender {
[[self windowController] showInspector:sender]; [[self windowController] showInspector:sender];
} }
@@ -290,7 +277,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
if(![document validateUserInterfaceItem:menuItem]) { if(![document validateUserInterfaceItem:menuItem]) {
return NO; return NO;
} }
id selected = [[self targetItemForAction] asGroup]; id selected = [[self currentTargetNode] asGroup];
if(!selected) { if(!selected) {
return NO; return NO;
} }

View File

@@ -7,11 +7,15 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class KPKEntry;
@class KPKGroup;
@class KPKNode; @class KPKNode;
@protocol MPTargetItemResolving <NSObject> @protocol MPTargetNodeResolving <NSObject>
@required @optional
- (KPKNode *)targetItemForAction; - (KPKNode *)currentTargetNode;
- (KPKGroup *)currentTargetGroup;
- (KPKEntry *)currentTargetEntry;
@end @end