multi delete and reactive menus in pack manager

This commit is contained in:
Nihaal Sharma committed 2026-07-06 13:40:13 +01:00
1 parent 5ec3c3c214
commit eb65849d3f
5 files changed
+67 -24

No files matched your search

+16 -8
View File
@@ -408,16 +408,13 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
A94693D62FEF0A4200E56AC5 /* TabbedContentView.swift */, A94693D62FEF0A4200E56AC5 /* TabbedContentView.swift */,
A9D53AE92FFB0272001C1BB9 /* EmojiPackManagerController.swift */, A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */,
A9D53AEC2FFB0E83001C1BB9 /* EmojiPackListView.swift */, A9C52F712F89A85F00078588 /* ShareSheet.swift */,
A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */,
A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */,
A9B37EAB2FFBD69200531FA1 /* EmojiPacks */,
A94F3E632F9E384D00FA6995 /* TableView */, A94F3E632F9E384D00FA6995 /* TableView */,
A94F3E642F9E385300FA6995 /* CollectionView */, A94F3E642F9E385300FA6995 /* CollectionView */,
A9C52F712F89A85F00078588 /* ShareSheet.swift */,
A9FB3EE22FA7AB3A00030E2A /* UIKitGifView.swift */,
A9E8C78E2FF71D8C009A38B5 /* DownloadedViewController.swift */,
A9E8C7A12FF7B815009A38B5 /* EmojiPackDetailViewController.swift */,
A9E8C7A42FF7C34A009A38B5 /* EmojiPackDetailViewRepresentable.swift */,
A9E8C7A72FF95FEC009A38B5 /* SearchViewController.swift */,
); );
path = UIKit; path = UIKit;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -550,6 +547,17 @@
path = Cachet; path = Cachet;
sourceTree = "<group>"; 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 */ = { A9B9A82D2EB2CCBE004C9245 /* StickerSlackTests */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@@ -11,11 +11,11 @@ import UniformTypeIdentifiers
class EmojiPackListView: UITableViewController { class EmojiPackListView: UITableViewController {
var emojiHoarder: EmojiHoarder var emojiHoarder: EmojiHoarder
var multiDeleteButton: UIBarButtonItem!
init(emojiHoarder: EmojiHoarder) { init(emojiHoarder: EmojiHoarder) {
self.emojiHoarder = emojiHoarder self.emojiHoarder = emojiHoarder
super.init(nibName: nil, bundle: nil) super.init(style: .insetGrouped)
self.tableView.allowsMultipleSelectionDuringEditing = true
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
@@ -23,8 +23,12 @@ class EmojiPackListView: UITableViewController {
} }
override func viewDidLoad() { override func viewDidLoad() {
self.tableView.allowsMultipleSelectionDuringEditing = true
self.navigationItem.title = "Packs" 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( NotificationCenter.default.addObserver(
self, self,
selector: #selector(refresh), selector: #selector(refresh),
@@ -73,27 +77,45 @@ class EmojiPackListView: UITableViewController {
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
guard let pack = self.packFor(indexPath: indexPath) else { return nil } 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) { if let selectedRows = self.tableView.indexPathsForSelectedRows,
return EmojiCollectionView(hoarder: self.emojiHoarder, items: pack.items, width: 50, style: .plain) selectedRows.contains(indexPath) {
} actionProvider: { suggestedActions in let multiDelete = UIAction(
return menu 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? { override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return nil } guard emojiHoarder.emojiPacks.indices.contains(indexPath.row) else { return nil }
let pack = emojiHoarder.emojiPacks[indexPath.row] let pack = emojiHoarder.emojiPacks[indexPath.row]
let delete = UIContextualAction(style: .destructive, title: "Delete") { contextualAction, view, closure in let delete = UIContextualAction(style: .destructive, title: "Delete") { contextualAction, view, closure in
self.delete(indexPath) self.delete(indexPath)
} }
@@ -111,6 +133,11 @@ class EmojiPackListView: UITableViewController {
return UISwipeActionsConfiguration(actions: [delete, share, dupButton]) 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() { @objc func addPack() {
emojiHoarder.newEmojiPack() emojiHoarder.newEmojiPack()
self.tableView.insertRows( self.tableView.insertRows(
@@ -129,6 +156,14 @@ class EmojiPackListView: UITableViewController {
self.tableView.deleteRows(at: [indexPath], with: .automatic) 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) { func dup(_ indexPath: IndexPath) {
guard let pack = packFor(indexPath: indexPath) else { return } guard let pack = packFor(indexPath: indexPath) else { return }
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.