Skip to content

Commit

Permalink
Merge pull request #13 from DrabWeb/tag-list
Browse files Browse the repository at this point in the history
Tag list
  • Loading branch information
DrabWeb authored Jan 15, 2018
2 parents 3c1583a + fdf4996 commit 91ec1cd
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Booru-chan/Booru-chan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
AE329EC81E44C186003812FB /* PreferencesBoorusController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE329EC71E44C186003812FB /* PreferencesBoorusController.swift */; };
AE9A56EE1FD72DFA0099D09E /* BooruWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9A56ED1FD72DFA0099D09E /* BooruWindow.swift */; };
AEA5A2171E13851400599CC5 /* BooruWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEA5A2161E13851400599CC5 /* BooruWindowController.swift */; };
AEC3C1EC200C50A2009AB087 /* TagListCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC3C1EB200C50A2009AB087 /* TagListCellView.swift */; };
AECAB5DD200C20B800673B46 /* BooruPost.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECAB5DC200C20B800673B46 /* BooruPost.swift */; };
AECAB5DF200C20BF00673B46 /* BooruHost.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECAB5DE200C20BF00673B46 /* BooruHost.swift */; };
AECAB5E1200C20C900673B46 /* BooruUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECAB5E0200C20C900673B46 /* BooruUtilities.swift */; };
Expand Down Expand Up @@ -93,6 +94,7 @@
AE75E5161DDE678E00937817 /* Booru-chan-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Booru-chan-Bridging-Header.h"; sourceTree = "<group>"; };
AE9A56ED1FD72DFA0099D09E /* BooruWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruWindow.swift; sourceTree = "<group>"; };
AEA5A2161E13851400599CC5 /* BooruWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BooruWindowController.swift; sourceTree = "<group>"; };
AEC3C1EB200C50A2009AB087 /* TagListCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagListCellView.swift; sourceTree = "<group>"; };
AECAB5DC200C20B800673B46 /* BooruPost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruPost.swift; sourceTree = "<group>"; };
AECAB5DE200C20BF00673B46 /* BooruHost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruHost.swift; sourceTree = "<group>"; };
AECAB5E0200C20C900673B46 /* BooruUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruUtilities.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -342,6 +344,7 @@
isa = PBXGroup;
children = (
AED6F5911FD7514F0036EDE8 /* TagListController.swift */,
AEC3C1EB200C50A2009AB087 /* TagListCellView.swift */,
);
name = Tags;
sourceTree = "<group>";
Expand Down Expand Up @@ -666,6 +669,7 @@
AEDD7F81200C00CC00AD33DE /* Theme.swift in Sources */,
5D3288321CCE80D10029A57F /* BottomActionScrollView.swift in Sources */,
5D88CC151CCC177B001FF12E /* ColouredView.swift in Sources */,
AEC3C1EC200C50A2009AB087 /* TagListCellView.swift in Sources */,
AECAB5DF200C20BF00673B46 /* BooruHost.swift in Sources */,
5DAD293D1CCD6AD400C3C747 /* PostsCollectionViewSelectionBox.swift in Sources */,
AECAB5DD200C20B800673B46 /* BooruPost.swift in Sources */,
Expand Down
81 changes: 81 additions & 0 deletions Booru-chan/Booru-chan/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,84 @@
<subviews>
<visualEffectView blendingMode="behindWindow" material="appearanceBased" state="active" translatesAutoresizingMaskIntoConstraints="NO" id="Dth-iT-dWy">
<rect key="frame" x="0.0" y="0.0" width="450" height="160"/>
<subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="24" horizontalPageScroll="10" verticalLineScroll="24" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="K6F-Iv-KJj">
<rect key="frame" x="0.0" y="0.0" width="450" height="160"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="fUH-A5-neV">
<rect key="frame" x="0.0" y="0.0" width="450" height="160"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" selectionHighlightStyle="none" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" typeSelect="NO" rowHeight="18" rowSizeStyle="automatic" viewBased="YES" id="Xkc-if-CTI">
<rect key="frame" x="0.0" y="0.0" width="450" height="160"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="6"/>
<color key="backgroundColor" white="1" alpha="0.0" colorSpace="deviceWhite"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="" width="447" maxWidth="1000000000" id="SbU-59-80I">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="fw5-Y2-psK">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="TagCell" id="NWX-7N-BZX" customClass="TagListCellView" customModule="Booru_chan" customModuleProvider="target">
<rect key="frame" x="1" y="3" width="447" height="18"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="r4i-Oi-Xzc" userLabel="Check Box">
<rect key="frame" x="2" y="0.0" width="443" height="18"/>
<buttonCell key="cell" type="check" title="tag" bezelStyle="regularSquare" imagePosition="left" inset="2" id="gD9-ig-kim">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="tagToggled:" target="hvN-Q7-urI" id="0Zb-pz-sLe"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="r4i-Oi-Xzc" firstAttribute="leading" secondItem="NWX-7N-BZX" secondAttribute="leading" constant="4" id="Jjp-cW-8bY"/>
<constraint firstAttribute="bottom" secondItem="r4i-Oi-Xzc" secondAttribute="bottom" constant="2" id="RzK-d7-Ll3"/>
<constraint firstAttribute="trailing" secondItem="r4i-Oi-Xzc" secondAttribute="trailing" constant="4" id="gZq-wg-Tyw"/>
<constraint firstItem="r4i-Oi-Xzc" firstAttribute="top" secondItem="NWX-7N-BZX" secondAttribute="top" constant="2" id="hYl-hd-AHU"/>
</constraints>
<connections>
<outlet property="tagNameCheckbox" destination="r4i-Oi-Xzc" id="8iJ-IT-kou"/>
</connections>
</tableCellView>
</prototypeCellViews>
</tableColumn>
</tableColumns>
<connections>
<outlet property="dataSource" destination="hvN-Q7-urI" id="baH-66-dj8"/>
<outlet property="delegate" destination="hvN-Q7-urI" id="ANm-mo-ChE"/>
</connections>
</tableView>
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="00l-Ux-JpJ">
<rect key="frame" x="0.0" y="144" width="450" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="OBC-X8-bWu">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="K6F-Iv-KJj" secondAttribute="bottom" id="3R8-xG-G0e"/>
<constraint firstAttribute="trailing" secondItem="K6F-Iv-KJj" secondAttribute="trailing" id="GtJ-VR-PZa"/>
<constraint firstItem="K6F-Iv-KJj" firstAttribute="top" secondItem="Dth-iT-dWy" secondAttribute="top" id="hlI-hI-25t"/>
<constraint firstItem="K6F-Iv-KJj" firstAttribute="leading" secondItem="Dth-iT-dWy" secondAttribute="leading" id="khE-eo-5a3"/>
</constraints>
</visualEffectView>
</subviews>
<constraints>
Expand All @@ -438,6 +516,9 @@
<constraint firstItem="Dth-iT-dWy" firstAttribute="top" secondItem="Wti-C8-YYQ" secondAttribute="top" id="X3k-hD-7de"/>
</constraints>
</view>
<connections>
<outlet property="tagsTableView" destination="Xkc-if-CTI" id="VGV-GS-ioa"/>
</connections>
</viewController>
<customObject id="2fz-W0-iqj" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
2 changes: 2 additions & 0 deletions Booru-chan/Booru-chan/BooruController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class BooruController: NSSplitViewController, IThemeable {

i.imageSize = p.imageSize;
i.rating = p.rating;
browserController.tagListController.tags = p.tags;
viewerController.display(post: p, progressHandler: { progress in
i.loadingProgress = progress;
});
Expand All @@ -62,6 +63,7 @@ class BooruController: NSSplitViewController, IThemeable {
i.imageSize = nil;
i.rating = nil;
i.loadingProgress = nil;
browserController.tagListController.tags = [];
viewerController.display(post: nil);
}
}
Expand Down
10 changes: 9 additions & 1 deletion Booru-chan/Booru-chan/PostsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class PostsController: NSViewController {
scrollView.onReachedBottom = onReachedBottom;
}
}

private func sendOnSelect() {
onSelect?(collectionView.selectionIndexes.map { items[$0] });
}
}

extension PostsController: NSCollectionViewDataSource {
Expand All @@ -48,6 +52,10 @@ extension PostsController: NSCollectionViewDataSource {

extension PostsController: NSCollectionViewDelegate {
func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
onSelect?(collectionView.selectionIndexes.map { items[$0] });
sendOnSelect();
}

func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>) {
sendOnSelect();
}
}
16 changes: 16 additions & 0 deletions Booru-chan/Booru-chan/TagListCellView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TagListCellView.swift
// Booru-chan
//
// Created by Ushio on 2018-01-14.
//

import Cocoa

class TagListCellView: NSTableCellView {
@IBOutlet weak var tagNameCheckbox: NSButton!

override func mouseDown(with event: NSEvent) {
tagNameCheckbox.mouseDown(with: event);
}
}
50 changes: 50 additions & 0 deletions Booru-chan/Booru-chan/TagListController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,54 @@ import Cocoa

class TagListController: NSViewController {

@IBOutlet private weak var tagsTableView: NSTableView!

var onTagChecked: ((String) -> Void)?
var onTagUnchecked: ((String) -> Void)?

// called by every tag cell, decides the initial state of the checkbox, true = on, false = off
var getTagState: ((String) -> Bool) = { tag in
return false;
};

var tags: [String] = [] {
didSet {
tagsTableView.reloadData();
}
}

@IBAction func tagToggled(_ sender: NSButton!) {
let t = tags[sender.tag];

switch sender.state {
case .on:
onTagChecked?(t);
break;
case .off:
onTagUnchecked?(t);
break;
default:
break;
}
}
}

extension TagListController: NSTableViewDataSource {
func numberOfRows(in aTableView: NSTableView) -> Int {
return tags.count;
}
}

extension TagListController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "TagCell"), owner: nil) as? TagListCellView {
let t = tags[row];
cell.tagNameCheckbox.title = t;
cell.tagNameCheckbox.state = getTagState(t) ? .on : .off;
cell.tagNameCheckbox.tag = row;
return cell;
}

return nil;
}
}

0 comments on commit 91ec1cd

Please sign in to comment.