4b7ecde829
Luckily the UISceneOpenURLOptions has a property openInPlace that seems to be good to use for this. If openInPlace is false, that means we should open the document read-only. This is a stopgap fix to avoid the situation where the user does changes to a document that is an attachment in an email message. Those changes won't be saved anywhere they could be found later. Better to keep the document read-only. The ideal solution would be to ask the user right away where they want an editable copy of the document to be stored. Later. Signed-off-by: Tor Lillqvist <tml@iki.fi> Change-Id: Ifd7d824d4f73cbf458f8597cd0974cf171b35be7
65 lines
2.7 KiB
Text
65 lines
2.7 KiB
Text
// -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*-
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#import "DocumentBrowserViewController.h"
|
|
#import "DocumentViewController.h"
|
|
#import "SceneDelegate.h"
|
|
|
|
static UIViewController *bottomPresentedViewController(UIViewController *vc) {
|
|
if ([vc presentedViewController] == nil)
|
|
return vc;
|
|
return bottomPresentedViewController([vc presentedViewController]);
|
|
}
|
|
|
|
static DocumentViewController *newDocumentViewControllerFor(NSURL *url, bool readOnly) {
|
|
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
|
DocumentViewController *documentViewController = [storyBoard instantiateViewControllerWithIdentifier:@"DocumentViewController"];
|
|
documentViewController.document = [[CODocument alloc] initWithFileURL:url];
|
|
documentViewController.document->fakeClientFd = -1;
|
|
documentViewController.document->readOnly = readOnly;
|
|
documentViewController.document.viewController = documentViewController;
|
|
|
|
return documentViewController;
|
|
}
|
|
|
|
@implementation SceneDelegate
|
|
|
|
// Nothing needed so far, the window property in the .h file is enough.
|
|
|
|
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
|
|
UIWindowScene *windowScene = (UIWindowScene *) scene;
|
|
|
|
if (!windowScene)
|
|
return;
|
|
|
|
for (UIOpenURLContext* context in connectionOptions.URLContexts) {
|
|
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL, !context.options.openInPlace);
|
|
[windowScene.windows[0].rootViewController presentViewController:documentViewController animated:NO completion:nil];
|
|
}
|
|
if ([connectionOptions.URLContexts count] > 0)
|
|
[windowScene.windows[0] makeKeyAndVisible];
|
|
}
|
|
|
|
|
|
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
|
|
UIWindowScene *windowScene = (UIWindowScene *) scene;
|
|
|
|
if (!windowScene)
|
|
return;
|
|
|
|
for (UIOpenURLContext* context in URLContexts) {
|
|
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL, !context.options.openInPlace);
|
|
[bottomPresentedViewController(windowScene.windows[0].rootViewController) presentViewController:documentViewController animated:NO completion:nil];
|
|
}
|
|
if ([URLContexts count] > 0)
|
|
[windowScene.windows[0] makeKeyAndVisible];
|
|
}
|
|
|
|
@end
|
|
|
|
// vim:set shiftwidth=4 softtabstop=4 expandtab:
|