Added better handling of responder chain in NSSplitViewController.

This allows for the removal of a lot of redirection in the MPDocumentWindowController
This commit is contained in:
Michael Starke
2022-03-15 15:21:45 +01:00
parent d746fdd5c8
commit 5547aad7c3
11 changed files with 135 additions and 55 deletions

View File

@@ -307,6 +307,8 @@
4CE88B9717BA651C0042E078 /* contextTriangleTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CE88B9617BA651C0042E078 /* contextTriangleTemplate.pdf */; };
4CEE46DD181C301D006BF1E5 /* MPAutotypeDaemon.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE46DC181C301D006BF1E5 /* MPAutotypeDaemon.m */; };
4CEED1C617D7BD0E007180F1 /* NSError+Messages.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CEED1C517D7BD0E007180F1 /* NSError+Messages.m */; };
4CF13A9727E0D5D800E3297A /* MPNodeTagViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF13A9527E0D5D800E3297A /* MPNodeTagViewController.m */; };
4CF13A9827E0D5D800E3297A /* MPNodeTagViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CF13A9627E0D5D800E3297A /* MPNodeTagViewController.xib */; };
4CF29BF417879D0000851B60 /* 26_FileSaveTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CF29BF317879D0000851B60 /* 26_FileSaveTemplate.pdf */; };
4CF5BE6D1BF33E3000048505 /* NSApplication+MPAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF5BE6C1BF33E3000048505 /* NSApplication+MPAdditions.m */; };
4CF6653820E67A140008A25C /* PluginDataView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CF6653A20E67A140008A25C /* PluginDataView.xib */; };
@@ -939,6 +941,9 @@
4CEE46DC181C301D006BF1E5 /* MPAutotypeDaemon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeDaemon.m; sourceTree = "<group>"; };
4CEED1C417D7BD0E007180F1 /* NSError+Messages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Messages.h"; sourceTree = "<group>"; };
4CEED1C517D7BD0E007180F1 /* NSError+Messages.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Messages.m"; sourceTree = "<group>"; };
4CF13A9427E0D5D800E3297A /* MPNodeTagViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPNodeTagViewController.h; sourceTree = "<group>"; };
4CF13A9527E0D5D800E3297A /* MPNodeTagViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPNodeTagViewController.m; sourceTree = "<group>"; };
4CF13A9627E0D5D800E3297A /* MPNodeTagViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MPNodeTagViewController.xib; sourceTree = "<group>"; };
4CF14962224B623700D1CE1C /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = Base; path = Base.lproj/Credits.rtf; sourceTree = "<group>"; };
4CF29BF317879D0000851B60 /* 26_FileSaveTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 26_FileSaveTemplate.pdf; sourceTree = "<group>"; };
4CF5BE6B1BF33E3000048505 /* NSApplication+MPAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSApplication+MPAdditions.h"; sourceTree = "<group>"; };
@@ -1547,6 +1552,9 @@
4C98A6C927CFAB1800CD912F /* MPNodeIconViewController.h */,
4C98A6CA27CFAB1900CD912F /* MPNodeIconViewController.m */,
4C98A6CB27CFAB1900CD912F /* MPNodeIconViewController.xib */,
4CF13A9427E0D5D800E3297A /* MPNodeTagViewController.h */,
4CF13A9527E0D5D800E3297A /* MPNodeTagViewController.m */,
4CF13A9627E0D5D800E3297A /* MPNodeTagViewController.xib */,
);
name = Inspector;
sourceTree = "<group>";
@@ -2253,6 +2261,7 @@
4C52A88E1788628B00868229 /* 06_BlockDeviceTemplate.pdf in Resources */,
4C52A88F1788628B00868229 /* 13_KeysTemplate.pdf in Resources */,
4C3826C61AD04D8E007D7D67 /* 59_DevelopmentTemplate.pdf in Resources */,
4CF13A9827E0D5D800E3297A /* MPNodeTagViewController.xib in Resources */,
4C52A8901788628B00868229 /* 18_DisplayTemplate.pdf in Resources */,
4C52A892178863B000868229 /* 68_PhoneTemplate.pdf in Resources */,
6021FE7718E15FF300C3BC51 /* DatePickingView.xib in Resources */,
@@ -2403,6 +2412,7 @@
4C569DA117652BFE00595B62 /* MPEntryTableDataSource.m in Sources */,
4CD034AA1BFE113B003C002C /* MPPlugin.m in Sources */,
4CA2335A176DBFE100F0B6AC /* MPLockDaemon.m in Sources */,
4CF13A9727E0D5D800E3297A /* MPNodeTagViewController.m in Sources */,
4C77C84118E240E000D1C42B /* DDHotKey+MacPassAdditions.m in Sources */,
4C89B71019B4B4A300DC0A6A /* MPTreeDelegate.m in Sources */,
4C88C66918D9F8D600F43852 /* MPTemporaryFileStorageCenter.m in Sources */,

View File

@@ -50,12 +50,12 @@
</segmentedCell>
</segmentedControl>
<tabView drawsBackground="NO" type="noTabsNoBorder" initialItem="110" translatesAutoresizingMaskIntoConstraints="NO" id="83">
<rect key="frame" x="0.0" y="60" width="273" height="407"/>
<rect key="frame" x="0.0" y="0.0" width="273" height="467"/>
<font key="font" metaFont="system"/>
<tabViewItems>
<tabViewItem label="General" identifier="1" id="110">
<view key="view" id="111">
<rect key="frame" x="0.0" y="0.0" width="273" height="407"/>
<rect key="frame" x="0.0" y="0.0" width="273" height="467"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
</tabViewItem>
@@ -240,16 +240,6 @@
</tabViewItem>
</tabViewItems>
</tabView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ESJ-wu-D4P">
<rect key="frame" x="108" y="13" width="58" height="32"/>
<buttonCell key="cell" type="push" title="Edit" alternateTitle="Done" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="hJ8-Kw-czh">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleEdit:" target="-2" id="Odr-gt-fBV"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="83" firstAttribute="leading" secondItem="3" secondAttribute="leading" id="85"/>
@@ -258,9 +248,7 @@
<constraint firstAttribute="centerX" secondItem="82" secondAttribute="centerX" id="90"/>
<constraint firstItem="83" firstAttribute="top" secondItem="3" secondAttribute="top" constant="26" id="279"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="82" secondAttribute="trailing" constant="20" symbolic="YES" id="4df-0Y-ggz"/>
<constraint firstAttribute="bottom" secondItem="ESJ-wu-D4P" secondAttribute="bottom" constant="20" symbolic="YES" id="OGC-4z-9MD"/>
<constraint firstItem="ESJ-wu-D4P" firstAttribute="centerX" secondItem="3" secondAttribute="centerX" id="bEP-z8-ndT"/>
<constraint firstItem="ESJ-wu-D4P" firstAttribute="top" secondItem="83" secondAttribute="bottom" constant="20" symbolic="YES" id="wQY-dE-8bJ"/>
<constraint firstAttribute="bottom" secondItem="83" secondAttribute="bottom" id="Lc3-ap-AJQ"/>
<constraint firstItem="82" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="3" secondAttribute="leading" constant="20" symbolic="YES" id="zU6-5h-Swa"/>
</constraints>
<point key="canvasLocation" x="-457.5" y="-1614.5"/>
@@ -277,7 +265,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IpW-b2-jWu" customClass="HNHUITextField">
<rect key="frame" x="22" y="48" width="247" height="21"/>
<rect key="frame" x="20" y="48" width="251" height="21"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="Hml-NR-AeS">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>

View File

@@ -106,4 +106,25 @@
[NSUserDefaults.standardUserDefaults setBool:!inspector.collapsed forKey:kMPSettingsKeyShowInspector];
}
- (id)supplementalTargetForAction:(SEL)action sender:(id)sender {
NSLog(@"First Responder:%@",self.view.window.firstResponder);
NSLog(@"Looking for target for action:%@", NSStringFromSelector(action));
for(NSViewController *childViewController in self.childViewControllers) {
if([childViewController respondsToSelector:action]) {
NSLog(@"Found target:%@ for action:%@", childViewController, NSStringFromSelector(action));
return childViewController;
}
else {
id target = [childViewController supplementalTargetForAction:action sender:sender];
if(!target) {
NSLog(@"No target for action:%@", NSStringFromSelector(action));
continue;
}
NSLog(@"Found supplemental target:%@ for action:%@", target, NSStringFromSelector(action));
return target;
}
}
return [super supplementalTargetForAction:action sender:sender];
}
@end

View File

@@ -441,16 +441,6 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
}];
}
- (void)pickExpiryDate:(id)sender {
// FIXME: use propert responder chain
[self.splitViewController.inspectorViewController pickExpiryDate:sender];
}
- (void)showPluginData:(id)sender {
// FIXME: use propert responder chain
[self.splitViewController.inspectorViewController showPluginData:sender];
}
- (void)toggleInspector:(id)sender {
[self.splitViewController toggleInspector:sender];
}
@@ -497,32 +487,6 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword);
[self.splitViewController.outlineViewController selectGroup:targetEntries.lastObject.parent];
}
#pragma mark -
#pragma mark Actions forwarded to MPEntryViewController
- (void)copyUsername:(id)sender {
[self.splitViewController.entryViewController copyUsername:sender];
}
- (void)copyPassword:(id)sender {
[self.splitViewController.entryViewController copyPassword:sender];
}
- (void)copyCustomAttribute:(id)sender {
[self.splitViewController.entryViewController copyCustomAttribute:sender];
}
- (void)copyAsReference:(id)sender {
[self.splitViewController.entryViewController copyAsReference:sender];
}
- (void)copyURL:(id)sender {
[self.splitViewController.entryViewController copyURL:sender];
}
- (void)openURL:(id)sender {
[self.splitViewController.entryViewController openURL:sender];
}
#pragma mark Validation
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
return ([self.document validateMenuItem:menuItem]);

View File

@@ -235,5 +235,9 @@ NSString *nameForDefaultKey(NSString *key) {
[super objectDidEndEditing:editor];
}
- (void)commitEditingWithDelegate:(nullable id)delegate didCommitSelector:(nullable SEL)didCommitSelector contextInfo:(nullable void *)contextInfo {
[super commitEditingWithDelegate:delegate didCommitSelector:didCommitSelector contextInfo:contextInfo];
}
@end

View File

@@ -81,6 +81,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
}
- (void)awakeFromNib {
// TODO: Convert to NSTabViewController?
self.noSelectionInfo.cell.backgroundStyle = NSBackgroundStyleRaised;
self.itemImageView.cell.backgroundStyle = NSBackgroundStyleRaised;
[self.tabView bind:NSSelectedIndexBinding toObject:self withKeyPath:NSStringFromSelector(@selector(activeTab)) options:nil];
@@ -105,6 +106,10 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
[groupTabView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[groupView]|" options:0 metrics:nil views:views]];
groupTabItem.initialFirstResponder = groupView;
[self addChildViewController:self.entryViewController];
[self addChildViewController:self.groupViewController];
[self.view layout];}
- (void)registerNotificationsForDocument:(MPDocument *)document {
@@ -217,4 +222,20 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
}
- (id)supplementalTargetForAction:(SEL)action sender:(id)sender {
for(NSViewController *childViewController in self.childViewControllers) {
if([childViewController respondsToSelector:action]) {
return childViewController;
}
else {
id target = [childViewController supplementalTargetForAction:action sender:sender];
if(!target) {
continue;
}
return target;
}
}
return [super supplementalTargetForAction:action sender:sender];
}
@end

View File

@@ -8,6 +8,7 @@
#import "MPNodeIconViewController.h"
#import <KeePassKit/KeePassKit.h>
#import "MPEntryInspectorViewController.h"
#import "KPKNode+IconImage.h"

View File

@@ -10,6 +10,7 @@
<connections>
<outlet property="imageView" destination="7kO-Kv-UI5" id="rTv-Pp-R1I"/>
<outlet property="textField" destination="xou-fD-adZ" id="n93-XV-5dq"/>
<outlet property="toggleEditButton" destination="0HE-hi-9Hm" id="ufa-av-vtf"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
@@ -27,22 +28,34 @@
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" id="09t-w3-euN"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="xou-fD-adZ">
<rect key="frame" x="38" y="8" width="439" height="16"/>
<textField horizontalHuggingPriority="249" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="xou-fD-adZ">
<rect key="frame" x="38" y="8" width="407" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="aKF-2z-5ob">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0HE-hi-9Hm">
<rect key="frame" x="444" y="-1" width="58" height="32"/>
<buttonCell key="cell" type="push" title="Edit" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ueF-MQ-zDV">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="toggleEdit:" target="-1" id="cBO-qZ-fN3"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="xou-fD-adZ" firstAttribute="centerY" secondItem="7kO-Kv-UI5" secondAttribute="centerY" id="0C4-8O-cQb"/>
<constraint firstItem="0HE-hi-9Hm" firstAttribute="centerY" secondItem="Hz6-mo-xeY" secondAttribute="centerY" id="4rk-Ut-1ch"/>
<constraint firstAttribute="bottom" secondItem="7kO-Kv-UI5" secondAttribute="bottom" id="DhE-aA-Ovp"/>
<constraint firstItem="xou-fD-adZ" firstAttribute="leading" secondItem="7kO-Kv-UI5" secondAttribute="trailing" constant="8" symbolic="YES" id="Elf-Iw-tmF"/>
<constraint firstItem="0HE-hi-9Hm" firstAttribute="leading" secondItem="xou-fD-adZ" secondAttribute="trailing" constant="8" symbolic="YES" id="J5A-t9-uim"/>
<constraint firstAttribute="trailing" secondItem="0HE-hi-9Hm" secondAttribute="trailing" id="QL9-uh-tCj"/>
<constraint firstItem="7kO-Kv-UI5" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="axe-Q2-16O"/>
<constraint firstItem="7kO-Kv-UI5" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="nCQ-tS-CIv"/>
<constraint firstAttribute="trailing" secondItem="xou-fD-adZ" secondAttribute="trailing" constant="20" symbolic="YES" id="qYf-Ov-k32"/>
</constraints>
<point key="canvasLocation" x="231.5" y="-13.5"/>
</customView>

View File

@@ -0,0 +1,17 @@
//
// MPNodeTagViewController.h
// MacPass
//
// Created by Michael Starke on 15.03.22.
// Copyright © 2022 HicknHack Software GmbH. All rights reserved.
//
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@interface MPNodeTagViewController : NSViewController
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,22 @@
//
// MPNodeTagViewController.m
// MacPass
//
// Created by Michael Starke on 15.03.22.
// Copyright © 2022 HicknHack Software GmbH. All rights reserved.
//
#import "MPNodeTagViewController.h"
@interface MPNodeTagViewController ()
@end
@implementation MPNodeTagViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
}
@end

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11134" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11134"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPNodeTagViewController">
<connections>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
</objects>
</document>