mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-20 11:49:22 +00:00
Removed required method for editors
node icon editor now uses bindings again
This commit is contained in:
@@ -27,8 +27,11 @@
|
||||
#import "MPIconHelper.h"
|
||||
|
||||
@interface NSImage (MPTintedImage)
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSImage (MPTintedImage)
|
||||
|
||||
- (NSImage *)imageWithTintColor:(NSColor *)tintColor {
|
||||
/* only tint templated images! */
|
||||
if(NO == self.template) {
|
||||
@@ -42,6 +45,7 @@
|
||||
image.template = NO;
|
||||
return image;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKNode (IconImage)
|
||||
|
||||
@@ -235,10 +235,6 @@ NSString *nameForDefaultKey(NSString *key) {
|
||||
self.actionButton.hidden = YES;
|
||||
}
|
||||
|
||||
- (void)commitChanges {
|
||||
// to nothing
|
||||
}
|
||||
|
||||
- (void)objectDidBeginEditing:(id<NSEditor>)editor {
|
||||
[self.view.window.windowController.document objectDidBeginEditing:editor];
|
||||
[super objectDidBeginEditing:editor];
|
||||
|
||||
@@ -20,7 +20,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@protocol MPInspectorEditor <NSObject>
|
||||
@required
|
||||
@property (nonatomic) BOOL isEditor;
|
||||
- (void)commitChanges;
|
||||
@end
|
||||
|
||||
/// NodeInspectorEditors require the represented object to be a KPKNode
|
||||
|
||||
@@ -59,10 +59,6 @@
|
||||
[self _updateValues];
|
||||
}
|
||||
|
||||
- (void)commitChanges {
|
||||
// write back expiration changes
|
||||
}
|
||||
|
||||
- (void)_updateValues {
|
||||
self.view.hidden = !self.representedTimeInfo.expires;
|
||||
self.expiredCheckButton.state = HNHUIStateForBool(self.representedTimeInfo.expires);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#import "KPKNode+IconImage.h"
|
||||
|
||||
@interface MPNodeIconViewController ()
|
||||
@property (strong) IBOutlet NSImageView *imageView;
|
||||
@property (strong) IBOutlet NSButton *imageButton;
|
||||
@property (strong) IBOutlet NSTextField *textField;
|
||||
@property (copy) NSUUID *iconUUID;
|
||||
@property NSUInteger iconId;
|
||||
@@ -25,40 +25,15 @@
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.imageView.cell.backgroundStyle = NSBackgroundStyleRaised;
|
||||
self.textField.placeholderString = NSLocalizedString(@"NO_TITLE", @"Fallback to items with no title");
|
||||
}
|
||||
|
||||
- (void)setRepresentedObject:(id)representedObject {
|
||||
if(self.representedNode) {
|
||||
KPKNode *node = self.representedNode;
|
||||
if(node.asEntry) {
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKWillChangeEntryNotification object:self.representedObject];
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKDidChangeEntryNotification object:self.representedObject];
|
||||
}
|
||||
else if(node.asGroup) {
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKWillChangeGroupNotification object:self.representedObject];
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self name:KPKDidChangeGroupNotification object:self.representedObject];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Inconsitant state for notification handling");
|
||||
}
|
||||
}
|
||||
super.representedObject = representedObject;
|
||||
if(self.representedNode) {
|
||||
KPKNode *node = self.representedNode;
|
||||
if(node.asEntry) {
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_willChangeNode:) name:KPKWillChangeEntryNotification object:self.representedObject];
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didChangeNode:) name:KPKDidChangeEntryNotification object:self.representedObject];
|
||||
}
|
||||
else if(node.asGroup) {
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_willChangeNode:) name:KPKWillChangeGroupNotification object:self.representedObject];
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didChangeNode:) name:KPKDidChangeGroupNotification object:self.representedObject];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Inconsitant state for notification handling");
|
||||
}
|
||||
}
|
||||
//self.imageView.cell.backgroundStyle = NSBackgroundStyleRaised;
|
||||
[self.imageButton bind:NSImageBinding
|
||||
toObject:self
|
||||
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconImage))]
|
||||
options:@{NSConditionallySetsEnabledBindingOption: @NO}];
|
||||
[self.textField bind:NSValueBinding
|
||||
toObject:self
|
||||
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))]
|
||||
options:@{NSNullPlaceholderBindingOption:NSLocalizedString(@"NO_TITLE", @"Fallback to items with no title")}];
|
||||
[self _updateValueAndEditing];
|
||||
}
|
||||
|
||||
@@ -75,24 +50,7 @@
|
||||
}
|
||||
|
||||
- (void)_updateValueAndEditing {
|
||||
self.imageView.enabled = self.isEditor;
|
||||
self.iconUUID = self.representedNode.iconUUID;
|
||||
self.iconId = self.representedNode.iconId;
|
||||
self.imageView.image = self.representedNode.iconImage;
|
||||
self.textField.stringValue = self.representedNode.title.length > 0 ? self.representedNode.title : @"";
|
||||
}
|
||||
|
||||
- (void)commitChanges {
|
||||
self.representedNode.iconUUID = self.iconUUID;
|
||||
self.representedNode.iconId = self.iconId;
|
||||
}
|
||||
|
||||
- (void)_willChangeNode:(NSNotification *)notification {
|
||||
|
||||
}
|
||||
|
||||
- (void)_didChangeNode:(NSNotification *)notification {
|
||||
[self _updateValueAndEditing];
|
||||
self.imageButton.enabled = self.isEditor;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="MPNodeIconViewController">
|
||||
<connections>
|
||||
<outlet property="imageView" destination="7kO-Kv-UI5" id="rTv-Pp-R1I"/>
|
||||
<outlet property="imageButton" destination="EO8-71-AW8" id="kgk-Bm-Hwv"/>
|
||||
<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>
|
||||
@@ -20,14 +19,6 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="495" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<subviews>
|
||||
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="7kO-Kv-UI5">
|
||||
<rect key="frame" x="0.0" y="0.0" width="32" height="32"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="32" id="VD7-b8-cKP"/>
|
||||
<constraint firstAttribute="height" constant="32" id="g13-f2-0hR"/>
|
||||
</constraints>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" id="09t-w3-euN"/>
|
||||
</imageView>
|
||||
<textField horizontalHuggingPriority="249" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="xou-fD-adZ">
|
||||
<rect key="frame" x="38" y="8" width="406" height="16"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="aKF-2z-5ob">
|
||||
@@ -38,24 +29,38 @@
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0HE-hi-9Hm">
|
||||
<rect key="frame" x="443" 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"/>
|
||||
<buttonCell key="cell" type="push" title="Edit" alternateTitle="Done" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ueF-MQ-zDV">
|
||||
<behavior key="behavior" 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>
|
||||
<button translatesAutoresizingMaskIntoConstraints="NO" id="EO8-71-AW8">
|
||||
<rect key="frame" x="0.0" y="0.0" width="32" height="32"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="32" id="TEp-1p-b6O"/>
|
||||
<constraint firstAttribute="width" constant="32" id="vue-ta-TCV"/>
|
||||
</constraints>
|
||||
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" imagePosition="only" alignment="center" imageScaling="proportionallyUpOrDown" inset="2" id="hbo-qV-oVP">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="pickIcon:" target="-1" id="8Ad-dS-w36"/>
|
||||
</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="EO8-71-AW8" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="AxG-ML-ibN"/>
|
||||
<constraint firstItem="xou-fD-adZ" firstAttribute="centerY" secondItem="Hz6-mo-xeY" secondAttribute="centerY" id="EYw-Zm-iiO"/>
|
||||
<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" constant="1" 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 firstItem="xou-fD-adZ" firstAttribute="leading" secondItem="EO8-71-AW8" secondAttribute="trailing" constant="8" symbolic="YES" id="TFI-Xr-6JG"/>
|
||||
<constraint firstItem="EO8-71-AW8" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="bYm-Dz-12l"/>
|
||||
<constraint firstAttribute="bottom" secondItem="EO8-71-AW8" secondAttribute="bottom" id="uhZ-Es-YcW"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="231.5" y="-13.5"/>
|
||||
</customView>
|
||||
|
||||
Reference in New Issue
Block a user