From 159db6ac4f8b1b35a69465e70c43ccad6124186d Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Sun, 14 Jan 2018 23:44:01 -0400 Subject: [PATCH 1/2] Basic functionality for the tag list. --- .../Booru-chan.xcodeproj/project.pbxproj | 4 + .../Booru-chan/Base.lproj/Main.storyboard | 81 +++++++++++++++++++ Booru-chan/Booru-chan/BooruController.swift | 2 + Booru-chan/Booru-chan/PostsController.swift | 11 ++- Booru-chan/Booru-chan/TagListCellView.swift | 16 ++++ Booru-chan/Booru-chan/TagListController.swift | 51 ++++++++++++ 6 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 Booru-chan/Booru-chan/TagListCellView.swift diff --git a/Booru-chan/Booru-chan.xcodeproj/project.pbxproj b/Booru-chan/Booru-chan.xcodeproj/project.pbxproj index 1ed8a6c..8e5a84f 100644 --- a/Booru-chan/Booru-chan.xcodeproj/project.pbxproj +++ b/Booru-chan/Booru-chan.xcodeproj/project.pbxproj @@ -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 */; }; @@ -93,6 +94,7 @@ AE75E5161DDE678E00937817 /* Booru-chan-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Booru-chan-Bridging-Header.h"; sourceTree = ""; }; AE9A56ED1FD72DFA0099D09E /* BooruWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruWindow.swift; sourceTree = ""; }; AEA5A2161E13851400599CC5 /* BooruWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BooruWindowController.swift; sourceTree = ""; }; + AEC3C1EB200C50A2009AB087 /* TagListCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagListCellView.swift; sourceTree = ""; }; AECAB5DC200C20B800673B46 /* BooruPost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruPost.swift; sourceTree = ""; }; AECAB5DE200C20BF00673B46 /* BooruHost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruHost.swift; sourceTree = ""; }; AECAB5E0200C20C900673B46 /* BooruUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooruUtilities.swift; sourceTree = ""; }; @@ -342,6 +344,7 @@ isa = PBXGroup; children = ( AED6F5911FD7514F0036EDE8 /* TagListController.swift */, + AEC3C1EB200C50A2009AB087 /* TagListCellView.swift */, ); name = Tags; sourceTree = ""; @@ -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 */, diff --git a/Booru-chan/Booru-chan/Base.lproj/Main.storyboard b/Booru-chan/Booru-chan/Base.lproj/Main.storyboard index c6f6ff8..1cf948d 100644 --- a/Booru-chan/Booru-chan/Base.lproj/Main.storyboard +++ b/Booru-chan/Booru-chan/Base.lproj/Main.storyboard @@ -429,6 +429,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -438,6 +516,9 @@ + + + diff --git a/Booru-chan/Booru-chan/BooruController.swift b/Booru-chan/Booru-chan/BooruController.swift index 682abf8..27db706 100644 --- a/Booru-chan/Booru-chan/BooruController.swift +++ b/Booru-chan/Booru-chan/BooruController.swift @@ -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; }); @@ -62,6 +63,7 @@ class BooruController: NSSplitViewController, IThemeable { i.imageSize = nil; i.rating = nil; i.loadingProgress = nil; + browserController.tagListController.tags = []; viewerController.display(post: nil); } } diff --git a/Booru-chan/Booru-chan/PostsController.swift b/Booru-chan/Booru-chan/PostsController.swift index 106b9ee..f7274fc 100644 --- a/Booru-chan/Booru-chan/PostsController.swift +++ b/Booru-chan/Booru-chan/PostsController.swift @@ -18,12 +18,17 @@ class PostsController: NSViewController { } } + //todo: call onSelect when deselecting all items var onSelect: (([BooruPost]) -> Void)? var onReachedBottom: (() -> Void)? { didSet { scrollView.onReachedBottom = onReachedBottom; } } + + private func sendOnSelect() { + onSelect?(collectionView.selectionIndexes.map { items[$0] }); + } } extension PostsController: NSCollectionViewDataSource { @@ -48,6 +53,10 @@ extension PostsController: NSCollectionViewDataSource { extension PostsController: NSCollectionViewDelegate { func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set) { - onSelect?(collectionView.selectionIndexes.map { items[$0] }); + sendOnSelect(); + } + + func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set) { + sendOnSelect(); } } diff --git a/Booru-chan/Booru-chan/TagListCellView.swift b/Booru-chan/Booru-chan/TagListCellView.swift new file mode 100644 index 0000000..46d8ca4 --- /dev/null +++ b/Booru-chan/Booru-chan/TagListCellView.swift @@ -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); + } +} diff --git a/Booru-chan/Booru-chan/TagListController.swift b/Booru-chan/Booru-chan/TagListController.swift index 09018ac..be146d3 100644 --- a/Booru-chan/Booru-chan/TagListController.swift +++ b/Booru-chan/Booru-chan/TagListController.swift @@ -9,4 +9,55 @@ 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; + } } From fdf4996256aaf7246b86f91bc6330308eac5c17d Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Sun, 14 Jan 2018 23:55:08 -0400 Subject: [PATCH 2/2] Cleanup. --- Booru-chan/Booru-chan/PostsController.swift | 1 - Booru-chan/Booru-chan/TagListController.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/Booru-chan/Booru-chan/PostsController.swift b/Booru-chan/Booru-chan/PostsController.swift index f7274fc..bc1a5ea 100644 --- a/Booru-chan/Booru-chan/PostsController.swift +++ b/Booru-chan/Booru-chan/PostsController.swift @@ -18,7 +18,6 @@ class PostsController: NSViewController { } } - //todo: call onSelect when deselecting all items var onSelect: (([BooruPost]) -> Void)? var onReachedBottom: (() -> Void)? { didSet { diff --git a/Booru-chan/Booru-chan/TagListController.swift b/Booru-chan/Booru-chan/TagListController.swift index be146d3..eb4f7d2 100644 --- a/Booru-chan/Booru-chan/TagListController.swift +++ b/Booru-chan/Booru-chan/TagListController.swift @@ -48,7 +48,6 @@ extension TagListController: NSTableViewDataSource { } 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];