Skip to content

Commit

Permalink
Copy Image context menu (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amzd authored Jan 10, 2025
1 parent c01c406 commit 1d6b016
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1724,8 +1724,11 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
replyToMessage(at: indexPath)
}

private func copyToClipboard(at indexPath: IndexPath) {
copyToClipboard(ids: [self.messageIds[indexPath.row]])
private func copyTextToClipboard(at indexPath: IndexPath) {
copyTextToClipboard(ids: [self.messageIds[indexPath.row]])
}
private func copyImageToClipboard(at indexPath: IndexPath) {
copyImagesToClipboard(ids: [self.messageIds[indexPath.row]])
}

private func cancelSearch() {
Expand Down Expand Up @@ -1945,7 +1948,7 @@ extension ChatViewController {
image = UIImage(named: "ic_forward_white_36pt")
}
children.append(
UIAction.menuAction(localizationKey: "forward", image: image, indexPath: indexPath, action: { self.forward(at: $0 ) })
UIAction.menuAction(localizationKey: "forward", image: image, indexPath: indexPath, action: forward)
)

if let link = isLinkTapped(indexPath: indexPath, point: point) {
Expand All @@ -1957,14 +1960,19 @@ extension ChatViewController {
} else if let text = message.text, !text.isEmpty {
let copyTitle = message.file == nil ? "global_menu_edit_copy_desktop" : "menu_copy_text_to_clipboard"
children.append(
UIAction.menuAction(localizationKey: copyTitle, systemImageName: "doc.on.doc", indexPath: indexPath, action: { self.copyToClipboard(at: $0 ) })
UIAction.menuAction(localizationKey: copyTitle, systemImageName: "doc.on.doc", indexPath: indexPath, action: copyTextToClipboard)
)
}
if message.image != nil {
children.append(
UIAction.menuAction(localizationKey: "menu_copy_image_to_clipboard", systemImageName: "photo.on.rectangle", indexPath: indexPath, action: copyImageToClipboard)
)
}

children.append(contentsOf: [
UIAction.menuAction(localizationKey: "info", systemImageName: "info", indexPath: indexPath, action: { self.info(at: $0 ) }),
UIAction.menuAction(localizationKey: "info", systemImageName: "info", indexPath: indexPath, action: info),
UIMenu(options: [.displayInline], children: [
UIAction.menuAction(localizationKey: "menu_more_options", systemImageName: "checkmark.circle", indexPath: indexPath, action: { self.selectMore(at: $0 ) }),
UIAction.menuAction(localizationKey: "menu_more_options", systemImageName: "checkmark.circle", indexPath: indexPath, action: selectMore),
])
])

Expand Down Expand Up @@ -2165,7 +2173,7 @@ extension ChatViewController {
view.image = UIImage(named: traitCollection.userInterfaceStyle == .light ? "background_light" : "background_dark")
}

private func copyToClipboard(ids: [Int]) {
private func copyTextToClipboard(ids: [Int]) {
var stringsToCopy = ""
if ids.count > 1 {
let sortedIds = ids.sorted()
Expand Down Expand Up @@ -2202,6 +2210,12 @@ extension ChatViewController {
}
UIPasteboard.general.string = stringsToCopy
}

func copyImagesToClipboard(ids: [Int]) {
let images = ids.map(dcContext.getMessage).compactMap(\.image)
guard !images.isEmpty else { return }
UIPasteboard.general.images = images
}
}

// MARK: - BaseMessageCellDelegate
Expand Down Expand Up @@ -2453,7 +2467,7 @@ extension ChatViewController: ChatEditingDelegate {
func onCopyPressed() {
if let rows = tableView.indexPathsForSelectedRows {
let ids = rows.compactMap { messageIds[$0.row] }
copyToClipboard(ids: ids)
copyTextToClipboard(ids: ids)
setEditing(isEditing: false)
}
}
Expand Down

0 comments on commit 1d6b016

Please sign in to comment.