mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
multi delete and reactive menus in pack manager
This commit is contained in:
5 files changed
+67
-24
No files matched your search
@@ -408,16 +408,13 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A94693D62FEF0A4200E56AC5 /* TabbedContentView.swift */,
|
||||
A9D53AE92FFB0272001C1BB9 /* EmojiPackManagerController.swift */,
|
||||
A9D53AEC2FFB0E83001C1BB9 /* EmojiPackListView.swift */,
|
||||
A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */,
|
||||
A9C52F712F89A85F00078588 /* ShareSheet.swift */,
|
||||
A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */,
|
||||
A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */,
|
||||
A9B37EAB2FFBD69200531FA1 /* EmojiPacks */,
|
||||
A94F3E632F9E384D00FA6995 /* TableView */,
|
||||
A94F3E642F9E385300FA6995 /* CollectionView */,
|
||||
A9C52F712F89A85F00078588 /* ShareSheet.swift */,
|
||||
A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */,
|
||||
A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */,
|
||||
A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */,
|
||||
A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */,
|
||||
A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */,
|
||||
);
|
||||
path = UIKit;
|
||||
sourceTree = "<group>";
|
||||
@@ -550,6 +547,17 @@
|
||||
path = Cachet;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9B37EAB2FFBD69200531FA1 /* EmojiPacks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9D53AE92FFB0272001C1BB9 /* EmojiPackManagerController.swift */,
|
||||
A9D53AEC2FFB0E83001C1BB9 /* EmojiPackListView.swift */,
|
||||
A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */,
|
||||
A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */,
|
||||
);
|
||||
path = EmojiPacks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9B9A82D2EB2CCBE004C9245 /* StickerSlackTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
||||
File renamed without changes.
File renamed without changes.
+51
-16
@@ -11,11 +11,11 @@ import UniformTypeIdentifiers
|
||||
|
||||
class EmojiPackListView: UITableViewController {
|
||||
var emojiHoarder: EmojiHoarder
|
||||
var multiDeleteButton: UIBarButtonItem!
|
||||
|
||||
init(emojiHoarder: EmojiHoarder) {
|
||||
self.emojiHoarder = emojiHoarder
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
self.tableView.allowsMultipleSelectionDuringEditing = true
|
||||
super.init(style: .insetGrouped)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@@ -23,8 +23,12 @@ class EmojiPackListView: UITableViewController {
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
self.tableView.allowsMultipleSelectionDuringEditing = true
|
||||
self.navigationItem.title = "Packs"
|
||||
|
||||
self.multiDeleteButton = UIBarButtonItem(image: UIImage(systemName: "trash"), style: .plain, target: self, action: #selector(multiDelete))
|
||||
self.setToolbarItems([multiDeleteButton], animated: true)
|
||||
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(refresh),
|
||||
@@ -73,27 +77,45 @@ class EmojiPackListView: UITableViewController {
|
||||
|
||||
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
guard let pack = self.packFor(indexPath: indexPath) else { return nil }
|
||||
let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { action in
|
||||
self.delete(indexPath)
|
||||
}
|
||||
let duplicate = UIAction(title: "Duplicate", image: UIImage(systemName: "plus.square.fill.on.square.fill")) { action in
|
||||
self.dup(indexPath)
|
||||
}
|
||||
let share = UIAction(title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { action in
|
||||
self.share(indexPath)
|
||||
}
|
||||
let menu = UIMenu(children: [share, duplicate, delete])
|
||||
|
||||
return UIContextMenuConfiguration(identifier: nil) {
|
||||
return EmojiCollectionView(hoarder: self.emojiHoarder, items: pack.items, width: 50, style: .plain)
|
||||
} actionProvider: { suggestedActions in
|
||||
return menu
|
||||
if let selectedRows = self.tableView.indexPathsForSelectedRows,
|
||||
selectedRows.contains(indexPath) {
|
||||
let multiDelete = UIAction(
|
||||
title: "Delete \(selectedRows.count) pack\(selectedRows.count.plural)",
|
||||
image: UIImage(systemName: "trash"),
|
||||
attributes: .destructive
|
||||
) { action in
|
||||
self.multiDelete()
|
||||
}
|
||||
return UIContextMenuConfiguration(identifier: nil) {
|
||||
return EmojiCollectionView(hoarder: self.emojiHoarder, items: pack.items, width: 50, style: .plain)
|
||||
} actionProvider: { suggestedActions in
|
||||
return UIMenu(children: [multiDelete])
|
||||
}
|
||||
} else {
|
||||
let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { action in
|
||||
self.delete(indexPath)
|
||||
}
|
||||
let duplicate = UIAction(title: "Duplicate", image: UIImage(systemName: "plus.square.fill.on.square.fill")) { action in
|
||||
self.dup(indexPath)
|
||||
}
|
||||
let share = UIAction(title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { action in
|
||||
self.share(indexPath)
|
||||
}
|
||||
let menu = UIMenu(children: [share, duplicate, delete])
|
||||
|
||||
return UIContextMenuConfiguration(identifier: nil) {
|
||||
return EmojiCollectionView(hoarder: self.emojiHoarder, items: pack.items, width: 50, style: .plain)
|
||||
} actionProvider: { suggestedActions in
|
||||
return menu
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||
guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return nil }
|
||||
let pack = emojiHoarder.emojiPacks[indexPath.row]
|
||||
|
||||
let delete = UIContextualAction(style: .destructive, title: "Delete") { contextualAction, view, closure in
|
||||
self.delete(indexPath)
|
||||
}
|
||||
@@ -111,6 +133,11 @@ class EmojiPackListView: UITableViewController {
|
||||
return UISwipeActionsConfiguration(actions: [delete, share, dupButton])
|
||||
}
|
||||
|
||||
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||
super.setEditing(editing, animated: animated)
|
||||
self.navigationController?.setToolbarHidden(!editing, animated: true)
|
||||
}
|
||||
|
||||
@objc func addPack() {
|
||||
emojiHoarder.newEmojiPack()
|
||||
self.tableView.insertRows(
|
||||
@@ -129,6 +156,14 @@ class EmojiPackListView: UITableViewController {
|
||||
self.tableView.deleteRows(at: [indexPath], with: .automatic)
|
||||
}
|
||||
|
||||
@objc func multiDelete() {
|
||||
guard let selectedRows = self.tableView.indexPathsForSelectedRows else { return }
|
||||
for indexPath in selectedRows {
|
||||
guard let pack = packFor(indexPath: indexPath) else { continue }
|
||||
delete(indexPath)
|
||||
}
|
||||
}
|
||||
|
||||
func dup(_ indexPath: IndexPath) {
|
||||
guard let pack = packFor(indexPath: indexPath) else { return }
|
||||
|
||||