Add device name to Insert from iPhone actions

This commit is contained in:
1024jp 2023-11-24 10:47:11 +09:00
parent f841cf8705
commit 8169243a30
2 changed files with 23 additions and 3 deletions

View File

@ -5,6 +5,11 @@ Change Log
4.7.0-beta.2 (unreleased)
--------------------------
### Improvements
- [beta][trivial] Add device name to quick actions related to Continuity Camera.
### Fixes
- [beta] Fix an issue that disabled menu items were listed as the quick action candidates.

View File

@ -112,7 +112,7 @@ extension NSMenuItem {
} else if self.isEnabled, !self.isHidden, let action = self.action, !ActionCommand.unsupportedActions.contains(action) {
[ActionCommand(kind: (action == #selector(ScriptManager.launchScript)) ? .script : .command,
title: self.title, paths: [], shortcut: self.shortcut, action: action, tag: self.tag, representedObject: self.representedObject)]
title: self.actionTitle, paths: [], shortcut: self.shortcut, action: action, tag: self.tag, representedObject: self.representedObject)]
} else {
[]
@ -129,14 +129,29 @@ extension NSMenuItem {
else { return }
switch validator {
case let validator as any NSMenuItemValidation:
validator.validateMenuItem(self)
case let validator as any NSUserInterfaceValidations:
validator.validateUserInterfaceItem(self)
case let validator as any NSMenuItemValidation:
validator.validateMenuItem(self)
default:
break
}
}
/// The title for command action.
private var actionTitle: String {
// append the device name to the title for "Insert from iPhone/iPad" actions
guard
self.action == Selector(("importFromDevice:")),
let siblings = self.menu?.items,
let index = siblings.firstIndex(of: self),
let deviceNameItem = siblings[0..<index].last(where: { !$0.isEnabled && $0.action == Selector(("_importFromDeviceText:")) })
else { return self.title }
return "\(self.title) (\(deviceNameItem.title))"
}
}