Extracted general settings into separate view controller

This commit is contained in:
Michael Starke
2021-11-24 15:26:45 +01:00
parent 2ec0945a51
commit a40049a425
2 changed files with 63 additions and 14 deletions

View File

@@ -8,15 +8,59 @@
#import "MPGeneralDatabaseSettingsViewController.h"
#import "MPDocument.h"
#import <KeePassKit/KeePassKit.h>
@interface MPGeneralDatabaseSettingsViewController ()
@property (weak) IBOutlet NSTextField *databaseNameTextField;
@property (weak) IBOutlet NSPopUpButton *databaseCompressionPopupButton;
@property (weak) IBOutlet NSTextView *databaseDescriptionTextView;
@property (weak) IBOutlet NSColorWell *databaseColorColorWell;
@property (weak) IBOutlet NSTextField *fileVersionTextField;
@end
@implementation MPGeneralDatabaseSettingsViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
[super viewDidLoad];
}
#pragma mark Private Helper
- (void)_setupView {
MPDocument *document = (MPDocument *)self.view.window.windowController.document;
KPKTree *tree = document.tree;
if(!tree) {
return; // nothing to read from
}
self.databaseNameTextField.stringValue = tree.metaData.databaseName;
self.databaseDescriptionTextView.string = tree.metaData.databaseDescription;
[self.databaseCompressionPopupButton selectItemAtIndex:tree.metaData.compressionAlgorithm];
self.databaseColorColorWell.color = tree.metaData.color ? tree.metaData.color : NSColor.clearColor;
NSData *fileData = [NSData dataWithContentsOfURL:document.fileURL];
if(!fileData) {
self.fileVersionTextField.stringValue = NSLocalizedString(@"UNKNOWN_FORMAT_FILE_NOT_SAVED_YET", "Database format is unknown since the file is not saved yet");
}
else {
KPKFileVersion version = [[KPKFormat sharedFormat] fileVersionForData:fileData];
NSDictionary *nameMappings = @{
@(KPKDatabaseFormatKdb): @"Kdb",
@(KPKDatabaseFormatKdbx): @"Kdbx",
@(KPKDatabaseFormatUnknown): NSLocalizedString(@"UNKNOWN_FORMAT", "Unknown database format.")
};
NSUInteger mayor = (version.version >> 16);
NSUInteger minor = (version.version & 0xFFFF);
self.fileVersionTextField.stringValue = [NSString stringWithFormat:@"%@ (Version %ld.%ld)", nameMappings[@(version.format)], mayor, minor];
}
}
@end

View File

@@ -8,6 +8,11 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPGeneralDatabaseSettingsViewController">
<connections>
<outlet property="databaseColorColorWell" destination="mT4-DP-GXO" id="LfS-qU-wBC"/>
<outlet property="databaseCompressionPopupButton" destination="Dq5-lP-zsS" id="11H-3z-4YL"/>
<outlet property="databaseDescriptionTextView" destination="YXY-Zl-7nu" id="s8Q-Fa-oaw"/>
<outlet property="databaseNameTextField" destination="ufI-vz-Iga" id="LYk-xb-BYQ"/>
<outlet property="fileVersionTextField" destination="7hG-5O-ghC" id="SoE-e8-vh3"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
@@ -33,7 +38,7 @@
<gridCells>
<gridCell row="xmM-rD-5oB" column="7Ct-m6-g6y" id="am5-3Y-3j8">
<textField key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JAh-R7-pLA">
<rect key="frame" x="6" y="188" width="102" height="16"/>
<rect key="frame" x="-2" y="188" width="102" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Database name:" id="03Y-Lj-rRN">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -43,7 +48,7 @@
</gridCell>
<gridCell row="xmM-rD-5oB" column="eQs-KV-hxL" id="IfW-cA-EoE">
<textField key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ufI-vz-Iga">
<rect key="frame" x="114" y="188" width="280" height="16"/>
<rect key="frame" x="106" y="188" width="280" height="16"/>
<constraints>
<constraint firstAttribute="width" constant="280" id="FXj-7O-RqC"/>
</constraints>
@@ -56,7 +61,7 @@
</gridCell>
<gridCell row="EPS-PJ-wZn" column="7Ct-m6-g6y" id="uqN-Dk-NnR">
<textField key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WIS-Jx-S9I">
<rect key="frame" x="30" y="164" width="78" height="16"/>
<rect key="frame" x="22" y="164" width="78" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Description:" id="p9U-Kw-bI5">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -66,7 +71,7 @@
</gridCell>
<gridCell row="EPS-PJ-wZn" column="eQs-KV-hxL" id="Gb7-AY-QQA">
<scrollView key="contentView" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nST-Dm-Qr7">
<rect key="frame" x="114" y="80" width="280" height="100"/>
<rect key="frame" x="106" y="80" width="280" height="100"/>
<clipView key="contentView" drawsBackground="NO" id="Is2-5k-gGr">
<rect key="frame" x="1" y="1" width="278" height="98"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -98,7 +103,7 @@
</gridCell>
<gridCell row="6vV-rV-ITV" column="7Ct-m6-g6y" id="EZb-Cx-iTX">
<textField key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8Dj-om-Zoe">
<rect key="frame" x="20" y="56" width="88" height="16"/>
<rect key="frame" x="12" y="56" width="88" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Compression:" id="5Bm-Nl-53q">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -108,13 +113,13 @@
</gridCell>
<gridCell row="6vV-rV-ITV" column="eQs-KV-hxL" id="T5V-Av-aBB">
<popUpButton key="contentView" verticalHuggingPriority="750" verticalCompressionResistancePriority="749" translatesAutoresizingMaskIntoConstraints="NO" id="Dq5-lP-zsS">
<rect key="frame" x="111" y="52" width="72" height="21"/>
<popUpButtonCell key="cell" type="push" title="None" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="GdG-Qp-e8U">
<rect key="frame" x="103" y="52" width="72" height="21"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="GdG-Qp-e8U">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="8oG-i9-WDa">
<items>
<menuItem title="None" state="on" id="uX3-5x-6i6"/>
<menuItem title="None" id="uX3-5x-6i6"/>
<menuItem title="GZip" tag="1" id="rIh-xx-34B"/>
</items>
</menu>
@@ -123,7 +128,7 @@
</gridCell>
<gridCell row="zYk-Ml-HAt" column="7Ct-m6-g6y" id="DAB-yY-fno">
<textField key="contentView" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jgn-WC-9Qs">
<rect key="frame" x="67" y="24" width="41" height="24"/>
<rect key="frame" x="59" y="24" width="41" height="24"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Color:" id="shK-cG-3dL">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -133,13 +138,13 @@
</gridCell>
<gridCell row="zYk-Ml-HAt" column="eQs-KV-hxL" id="3lH-bt-QOB">
<colorWell key="contentView" translatesAutoresizingMaskIntoConstraints="NO" id="mT4-DP-GXO" customClass="HNHUIColorWell">
<rect key="frame" x="114" y="24" width="100" height="24"/>
<rect key="frame" x="106" y="24" width="100" height="24"/>
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</colorWell>
</gridCell>
<gridCell row="kzN-Ch-gfi" column="7Ct-m6-g6y" id="SII-3r-mjn">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="IX3-zX-Jvu">
<rect key="frame" x="35" y="0.0" width="73" height="16"/>
<rect key="frame" x="27" y="0.0" width="73" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="File format:" id="FgL-0B-JE9">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -149,7 +154,7 @@
</gridCell>
<gridCell row="kzN-Ch-gfi" column="eQs-KV-hxL" id="3Hz-QZ-yB0">
<textField key="contentView" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="7hG-5O-ghC">
<rect key="frame" x="112" y="0.0" width="72" height="16"/>
<rect key="frame" x="104" y="0.0" width="72" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="VersionInfo" id="C2T-fi-WiV">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>