Archived
1
Fork 0

When editing tags from home, open in a new window on macOS

This commit is contained in:
redstrate 2020-05-24 22:14:26 -04:00
parent 96e654dc34
commit 46276860ce
3 changed files with 64 additions and 41 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Q6f-oJ-eRP"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Q6f-oJ-eRP">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="collection view cell content view" minToolsVersion="11.0"/> <capability name="collection view cell content view" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@ -168,14 +168,14 @@
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<prototypes> <prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="tagCell" id="c7T-0r-L5w" customClass="TagViewCell" customModule="Gallery" customModuleProvider="target"> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="tagCell" id="c7T-0r-L5w" customClass="TagViewCell" customModule="Gallery" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="382" height="47.5"/> <rect key="frame" x="0.0" y="28" width="382" height="47"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="c7T-0r-L5w" id="WjD-Nb-tif"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="c7T-0r-L5w" id="WjD-Nb-tif">
<rect key="frame" x="0.0" y="0.0" width="382" height="47.5"/> <rect key="frame" x="0.0" y="0.0" width="382" height="47"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cei-95-iOR"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cei-95-iOR">
<rect key="frame" x="20" y="13" width="342" height="21.5"/> <rect key="frame" x="20" y="13" width="342" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
@ -467,11 +467,11 @@
<point key="canvasLocation" x="1747.5" y="497"/> <point key="canvasLocation" x="1747.5" y="497"/>
</scene> </scene>
</scenes> </scenes>
<resources>
<image name="pencil" catalog="system" width="64" height="56"/>
<image name="square.and.arrow.up" catalog="system" width="56" height="64"/>
</resources>
<inferredMetricsTieBreakers> <inferredMetricsTieBreakers>
<segue reference="s4Q-Cr-1uF"/> <segue reference="s4Q-Cr-1uF"/>
</inferredMetricsTieBreakers> </inferredMetricsTieBreakers>
<resources>
<image name="pencil" catalog="system" width="128" height="113"/>
<image name="square.and.arrow.up" catalog="system" width="115" height="128"/>
</resources>
</document> </document>

View file

@ -167,7 +167,6 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
func makeContextMenu(post: NSManagedObject) -> UIMenu { func makeContextMenu(post: NSManagedObject) -> UIMenu {
let newWindow = UIAction(title: "Open in New Window", image: UIImage(systemName: "plus.square.on.square")) { action in let newWindow = UIAction(title: "Open in New Window", image: UIImage(systemName: "plus.square.on.square")) { action in
let activity = NSUserActivity(activityType: "post") let activity = NSUserActivity(activityType: "post")
activity.userInfo = ["name": post.value(forKey: "name") as! String] activity.userInfo = ["name": post.value(forKey: "name") as! String]
activity.isEligibleForHandoff = true activity.isEligibleForHandoff = true
@ -191,10 +190,18 @@ class PostCollectionView: UICollectionView, UICollectionViewDataSource, UICollec
} }
let editTags = UIAction(title: "Tags", image: UIImage(systemName: "tag")) { action in let editTags = UIAction(title: "Tags", image: UIImage(systemName: "tag")) { action in
#if targetEnvironment(macCatalyst)
let activity = NSUserActivity(activityType: "tags")
activity.userInfo = ["name": post.value(forKey: "name") as! String]
activity.isEligibleForHandoff = true
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity, options: nil, errorHandler: nil)
#else
let viewController = EditTagsViewController.loadFromStoryboard() let viewController = EditTagsViewController.loadFromStoryboard()
viewController!.post = post as? Post viewController!.post = post as? Post
self.viewController?.present(viewController!, animated: true) self.viewController?.present(viewController!, animated: true)
#endif
} }
let info = UIAction(title: "Info", image: UIImage(systemName: "info.circle")) { action in let info = UIAction(title: "Info", image: UIImage(systemName: "info.circle")) { action in

View file

@ -31,13 +31,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
(UIApplication.shared.delegate as? AppDelegate)?.saveContext() (UIApplication.shared.delegate as? AppDelegate)?.saveContext()
} }
func configure(window: UIWindow?, with activity: NSUserActivity) -> Bool { func getPostFromActivity(activity: NSUserActivity ) -> Post? {
if activity.activityType == "post" {
if let photoID = activity.userInfo?["name"] as? String { if let photoID = activity.userInfo?["name"] as? String {
if let photoDetailViewController = PostViewController.loadFromStoryboard() {
guard let appDelegate = guard let appDelegate =
UIApplication.shared.delegate as? AppDelegate else { UIApplication.shared.delegate as? AppDelegate else {
return false return nil
} }
let managedContext = appDelegate.persistentContainer.viewContext let managedContext = appDelegate.persistentContainer.viewContext
@ -50,11 +48,20 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
do { do {
let result = try managedContext.fetch(request) let result = try managedContext.fetch(request)
guard let object = result[0] as? NSManagedObject else { return result[0] as? Post;
return false } catch _ as NSError {
return nil
}
} }
photoDetailViewController.post = object return nil
}
func configure(window: UIWindow?, with activity: NSUserActivity) -> Bool {
if activity.activityType == "post" {
if let post = getPostFromActivity(activity: activity) {
if let photoDetailViewController = PostViewController.loadFromStoryboard() {
photoDetailViewController.post = post
photoDetailViewController.isPopup = true photoDetailViewController.isPopup = true
if let navigationController = window?.rootViewController as? UINavigationController { if let navigationController = window?.rootViewController as? UINavigationController {
@ -62,8 +69,17 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
return true return true
} }
} catch _ as NSError { }
return false }
} else if activity.activityType == "tags" {
if let post = getPostFromActivity(activity: activity) {
if let editTagsController = EditTagsViewController.loadFromStoryboard() {
editTagsController.post = post
if let navigationController = window?.rootViewController as? UINavigationController {
navigationController.pushViewController(editTagsController, animated: false)
return true
} }
} }
} }