Using background color attribute on entries to dispaly colorized images

This commit is contained in:
michael starke
2017-11-10 16:44:17 +01:00
parent a5161190d3
commit 6e73a390bb
6 changed files with 51 additions and 15 deletions

View File

@@ -1,3 +1,3 @@
github "sparkle-project/Sparkle" ~> 1.18.1
github "MacPass/KeePassKit" ~> 1.5.1
github "MacPass/KeePassKit" ~> 1.6
github "mstarke/HNHUi" ~> 1.4.1

View File

@@ -1,3 +1,3 @@
github "MacPass/KeePassKit" "1.5.1"
github "MacPass/KeePassKit" "1.6"
github "mstarke/HNHUi" "1.4.1"
github "sparkle-project/Sparkle" "1.18.1"

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13196" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13196"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13529"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -16,17 +16,17 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="1">
<rect key="frame" x="0.0" y="0.0" width="400" height="340"/>
<rect key="frame" x="0.0" y="0.0" width="400" height="400"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<scrollView wantsLayer="YES" focusRingType="none" borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="57" customClass="HNHUIScrollView">
<rect key="frame" x="10" y="50" width="380" height="270"/>
<rect key="frame" x="10" y="50" width="380" height="330"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="Gwf-zs-lPT">
<rect key="frame" x="0.0" y="0.0" width="380" height="270"/>
<rect key="frame" x="0.0" y="0.0" width="380" height="330"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView focusRingType="none" selectable="YES" id="58" customClass="MPCollectionView">
<rect key="frame" x="0.0" y="0.0" width="380" height="270"/>
<rect key="frame" x="0.0" y="0.0" width="380" height="330"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="primaryBackgroundColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
<connections>
@@ -40,7 +40,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="60">
<rect key="frame" x="364" y="0.0" width="16" height="240"/>
<rect key="frame" x="364" y="0.0" width="16" height="268"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
@@ -55,7 +55,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8kv-BJ-IEk">
<rect key="frame" x="149" y="18" width="108" height="25"/>
<rect key="frame" x="153" y="18" width="104" height="25"/>
<buttonCell key="cell" type="roundTextured" title="Download Icon" bezelStyle="texturedRounded" imagePosition="left" alignment="center" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="iaf-XW-XUo">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -65,7 +65,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="His-4A-hcY">
<rect key="frame" x="85" y="18" width="56" height="25"/>
<rect key="frame" x="89" y="18" width="56" height="25"/>
<buttonCell key="cell" type="roundTextured" title="Cancel" bezelStyle="texturedRounded" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="1kM-cI-P1o">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@@ -80,15 +80,15 @@
<constraint firstAttribute="trailing" secondItem="101" secondAttribute="trailing" constant="20" symbolic="YES" id="108"/>
<constraint firstAttribute="trailing" secondItem="57" secondAttribute="trailing" constant="10" id="110"/>
<constraint firstItem="57" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="10" id="111"/>
<constraint firstItem="101" firstAttribute="top" secondItem="57" secondAttribute="bottom" constant="8" symbolic="YES" id="112"/>
<constraint firstItem="His-4A-hcY" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="1" secondAttribute="leading" constant="20" symbolic="YES" id="69a-Sb-jSj"/>
<constraint firstItem="8kv-BJ-IEk" firstAttribute="baseline" secondItem="101" secondAttribute="baseline" id="Knp-g8-7FQ"/>
<constraint firstItem="8kv-BJ-IEk" firstAttribute="leading" secondItem="His-4A-hcY" secondAttribute="trailing" constant="8" symbolic="YES" id="MZ0-p6-6MH"/>
<constraint firstItem="57" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" symbolic="YES" id="N2b-Nx-SZC"/>
<constraint firstItem="101" firstAttribute="top" secondItem="57" secondAttribute="bottom" constant="8" symbolic="YES" id="WT3-Nh-FrW"/>
<constraint firstItem="His-4A-hcY" firstAttribute="baseline" secondItem="101" secondAttribute="baseline" id="fq3-rS-gvQ"/>
<constraint firstItem="57" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" symbolic="YES" id="iuz-pK-yXC"/>
<constraint firstItem="101" firstAttribute="leading" secondItem="8kv-BJ-IEk" secondAttribute="trailing" constant="8" symbolic="YES" id="nvi-CZ-a6L"/>
</constraints>
<point key="canvasLocation" x="-447" y="15"/>
<point key="canvasLocation" x="-1175" y="-7"/>
</customView>
<collectionViewItem id="61" customClass="MPCollectionViewItem">
<connections>

View File

@@ -26,6 +26,24 @@
#import "MPIconHelper.h"
@interface NSImage (MPTintedImage)
@end
@implementation NSImage (MPTintedImage)
- (NSImage *)imageWithTintColor:(NSColor *)tintColor {
/* only tint tempated images! */
if(NO == self.template) {
return self;
}
NSImage *image = [self copy];
[image lockFocus];
[tintColor set];
NSRectFillUsingOperation(NSMakeRect(0, 0, image.size.width, image.size.height), NSCompositingOperationSourceAtop);
[image unlockFocus];
image.template = NO;
return image;
}
@end
@implementation KPKNode (IconImage)
+ (NSSet *)keyPathsForValuesAffectingIconImage {
@@ -36,6 +54,7 @@
});
return [NSSet setWithArray:@[NSStringFromSelector(@selector(iconUUID)),
NSStringFromSelector(@selector(iconId)),
NSStringFromSelector(@selector(backgroundColor)),
expireDateKeyPath
]];
}
@@ -49,6 +68,10 @@
if(self.icon) {
return self.icon.image;
}
if(self.asEntry.backgroundColor) {
return [[MPIconHelper icon:(MPIconType)self.iconId] imageWithTintColor:self.asEntry.backgroundColor];
}
return [MPIconHelper icon:(MPIconType)self.iconId];
}
@end

View File

@@ -264,7 +264,6 @@ NSString *const _MPTableSecurCellView = @"PasswordCell";
KPKEntry *entry = self.entryArrayController.arrangedObjects[topRow];
entry.parent.lastTopVisibleEntry = entry.uuid;
}
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {

View File

@@ -35,6 +35,8 @@ typedef NS_ENUM(NSInteger, MPIconDownloadStatus) {
@interface MPIconSelectViewController () <NSCollectionViewDelegate>
/* UI properties */
@property (weak) IBOutlet NSColorWell *foregroundColorWell;
@property (weak) IBOutlet NSColorWell *backgroundColorWell;
@property (weak) IBOutlet MPCollectionView *iconCollectionView;
@property (weak) IBOutlet NSButton *imageButton;
@property (weak) IBOutlet NSButton *downloadIconButton;
@@ -63,6 +65,18 @@ typedef NS_ENUM(NSInteger, MPIconDownloadStatus) {
[menu addItem:[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DELETE", @"") action:@selector(deleteIcon:) keyEquivalent:@""]];
self.iconCollectionView.menu = menu;
KPKEntry *entry = [self.representedObject asEntry];
if(entry) {
self.foregroundColorWell.enabled = YES;
self.foregroundColorWell.color = entry.foregroundColor ? entry.foregroundColor : NSColor.clearColor;
self.backgroundColorWell.enabled = YES;
self.backgroundColorWell.color = entry.backgroundColor ? entry.backgroundColor : NSColor.clearColor;
}
else {
self.foregroundColorWell.enabled = NO;
self.backgroundColorWell.enabled = NO;
}
[self _updateCollectionViewContent];
}