2022-03-31 09:19:57 -05:00
|
|
|
// -*- 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]);
|
|
|
|
}
|
|
|
|
|
2022-04-05 06:27:19 -05:00
|
|
|
static DocumentViewController *newDocumentViewControllerFor(NSURL *url, bool readOnly) {
|
2022-03-31 09:19:57 -05:00
|
|
|
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
|
|
|
DocumentViewController *documentViewController = [storyBoard instantiateViewControllerWithIdentifier:@"DocumentViewController"];
|
|
|
|
documentViewController.document = [[CODocument alloc] initWithFileURL:url];
|
|
|
|
documentViewController.document->fakeClientFd = -1;
|
2022-04-05 06:27:19 -05:00
|
|
|
documentViewController.document->readOnly = readOnly;
|
2022-03-31 09:19:57 -05:00
|
|
|
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) {
|
2022-04-05 06:27:19 -05:00
|
|
|
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL, !context.options.openInPlace);
|
2022-03-31 09:19:57 -05:00
|
|
|
[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) {
|
2022-04-05 06:27:19 -05:00
|
|
|
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL, !context.options.openInPlace);
|
2022-03-31 09:19:57 -05:00
|
|
|
[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:
|