Unified and simplified IconSelection

This commit is contained in:
michael starke
2017-09-08 11:54:23 +02:00
parent ccb402cde6
commit 892f3596b6
2 changed files with 20 additions and 66 deletions

View File

@@ -8,7 +8,6 @@
<customObject id="-2" userLabel="File's Owner" customClass="MPIconSelectViewController">
<connections>
<outlet property="iconCollectionView" destination="58" id="77"/>
<outlet property="typeSelectionButton" destination="QWR-lI-xJr" id="U95-Gu-0UQ"/>
<outlet property="view" destination="1" id="56"/>
</connections>
</customObject>
@@ -19,13 +18,13 @@
<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="240"/>
<rect key="frame" x="10" y="50" width="380" height="270"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="Gwf-zs-lPT">
<rect key="frame" x="0.0" y="0.0" width="380" height="240"/>
<rect key="frame" x="0.0" y="0.0" width="380" height="270"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<collectionView focusRingType="none" id="58">
<rect key="frame" x="0.0" y="0.0" width="380" height="240"/>
<rect key="frame" x="0.0" y="0.0" width="380" height="270"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="primaryBackgroundColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
<connections>
@@ -38,7 +37,7 @@
<rect key="frame" x="1" y="144" width="233" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="60">
<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"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
@@ -53,19 +52,6 @@
<action selector="useDefault:" target="-2" id="129"/>
</connections>
</button>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="QWR-lI-xJr">
<rect key="frame" x="134" y="296" width="132" height="25"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="texturedSquare" trackingMode="selectOne" id="0BD-eH-GR9">
<font key="font" metaFont="system"/>
<segments>
<segment label="Built in"/>
<segment label="Custom" selected="YES" tag="1"/>
</segments>
</segmentedCell>
<connections>
<action selector="toggleIcons:" target="-2" id="mke-RW-XXE"/>
</connections>
</segmentedControl>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8kv-BJ-IEk">
<rect key="frame" x="153" y="18" width="104" height="25"/>
<buttonCell key="cell" type="roundTextured" title="Download Icon" bezelStyle="texturedRounded" alignment="center" lineBreakMode="truncatingTail" enabled="NO" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="iaf-XW-XUo">
@@ -91,13 +77,11 @@
<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="57" firstAttribute="top" secondItem="QWR-lI-xJr" secondAttribute="bottom" constant="8" symbolic="YES" id="DIj-jT-MV1"/>
<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="QWR-lI-xJr" firstAttribute="top" secondItem="1" secondAttribute="top" constant="20" symbolic="YES" id="agZ-dA-Otd"/>
<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"/>
<constraint firstItem="QWR-lI-xJr" firstAttribute="centerX" secondItem="1" secondAttribute="centerX" id="vp8-Zm-JHV"/>
</constraints>
<point key="canvasLocation" x="-43" y="90"/>
</customView>

View File

@@ -24,18 +24,11 @@
#import "MPIconHelper.h"
#import "MPDocument.h"
typedef NS_ENUM(NSUInteger, MPIconeSelectionType) {
MPIconSelectionDefault,
MPIconSelectionCustom
};
@interface MPIconSelectViewController () <NSCollectionViewDelegate>
/* UI properties */
@property (weak) IBOutlet NSCollectionView *iconCollectionView;
@property (weak) IBOutlet NSButton *imageButton;
@property (weak) IBOutlet NSSegmentedControl *typeSelectionButton;
@property MPIconeSelectionType selectionType;
@end
@@ -46,37 +39,16 @@ typedef NS_ENUM(NSUInteger, MPIconeSelectionType) {
}
- (void)viewDidLoad {
KPKNode *node = self.representedObject;
if(!node.iconUUID) {
self.selectionType = MPIconSelectionDefault;
}
else {
self.selectionType = MPIconSelectionCustom;
}
self.typeSelectionButton.selectedSegment = self.selectionType;
self.iconCollectionView.backgroundColors = @[NSColor.clearColor];
self.iconCollectionView.selectable = YES;
self.iconCollectionView.allowsMultipleSelection = NO;
self.iconCollectionView.delegate = self;
[self.iconCollectionView registerForDraggedTypes:@[(NSString *)kUTTypeURL, (NSString *)kUTTypeFileURL]];
[self _updateContent];
}
- (void)_updateContent {
//[self.iconCollectionView registerForDraggedTypes:@[(NSString *)kUTTypeURL, (NSString *)kUTTypeFileURL]];
MPDocument *document = [NSDocumentController sharedDocumentController].currentDocument;
switch(self.selectionType) {
case MPIconSelectionCustom:
self.iconCollectionView.content = document.tree.metaData.customIcons;
break;
case MPIconSelectionDefault:
default:
self.iconCollectionView.content = [MPIconHelper databaseIcons];
}
}
- (IBAction)toggleIcons:(id)sender {
self.selectionType = self.typeSelectionButton.selectedSegment;
[self _updateContent];
self.iconCollectionView.content = document.tree.metaData.customIcons;
self.iconCollectionView.content = [[MPIconHelper databaseIcons] arrayByAddingObjectsFromArray:document.tree.metaData.customIcons];
}
- (IBAction)useDefault:(id)sender {
@@ -101,19 +73,17 @@ typedef NS_ENUM(NSUInteger, MPIconeSelectionType) {
- (void)_selectIcon:(KPKIcon *)icon {
KPKNode *node = self.representedObject;
NSUInteger iconIndex = [self.iconCollectionView.content indexOfObject:icon];
[self.observer willChangeModelProperty];
switch(self.selectionType) {
case MPIconSelectionCustom:
node.iconUUID = icon.uuid;
break;
default:
case MPIconSelectionDefault: {
NSUInteger iconIndex = [self.iconCollectionView.content indexOfObject:icon];
NSInteger newIconId = ((NSNumber *)[MPIconHelper databaseIconTypes][iconIndex]).integerValue;
node.iconId = newIconId;
node.iconUUID = nil;
break;
}
/* Icon is Custom Icon */
if(iconIndex >= [MPIconHelper databaseIcons].count) {
node.iconUUID = icon.uuid;
}
else {
NSInteger newIconId = ((NSNumber *)[MPIconHelper databaseIconTypes][iconIndex]).integerValue;
node.iconId = newIconId;
node.iconUUID = nil;
}
[self.observer didChangeModelProperty];
[self.view.window performClose:nil];