libreoffice-online/ios/Mobile/DocumentBrowserViewController.mm
Tor Lillqvist 296e0eb803 More work on template selection for a new document
It took quite some time for me to understand how to do it. Not sure if
this is The Right Way, but at least it now works better.

The trick was to store the importHandler block as a property of the
TemplateCollectionViewController and call it when the right template
has been selected.

There is no need to call the importHandler already in the
documentBrowser:didRequestDocumentCreationWithHandler: instance method
and it would not be possible anyway as there apparently is no way to
have the presentViewController:animated:completion: method work in a
truly modal way, so that it would not return until the selection has
been done.

Change-Id: Ia229500c181844fcd99f1f099b2e6744c22b5266
2018-12-05 22:02:59 +02:00

76 lines
3.3 KiB
Text

// -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*-
//
// This file is part of the LibreOffice project.
//
// 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 "config.h"
#import "DocumentBrowserViewController.h"
#import "Document.h"
#import "DocumentViewController.h"
#import "TemplateCollectionViewController.h"
@interface DocumentBrowserViewController () <UIDocumentBrowserViewControllerDelegate>
@end
@implementation DocumentBrowserViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.allowsDocumentCreation = YES;
self.allowsPickingMultipleItems = NO;
// Update the style of the UIDocumentBrowserViewController
// self.browserUserInterfaceStyle = UIDocumentBrowserUserInterfaceStyleDark;
// self.view.tintColor = [UIColor whiteColor];
// Specify the allowed content types of your application via the Info.plist.
// Do any additional setup after loading the view, typically from a nib.
}
- (void)documentBrowser:(UIDocumentBrowserViewController *)controller didRequestDocumentCreationWithHandler:(void (^)(NSURL * _Nullable, UIDocumentBrowserImportMode))importHandler {
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
TemplateCollectionViewController *templateCollectionViewController = [storyBoard instantiateViewControllerWithIdentifier:@"TemplateCollectionViewController"];
templateCollectionViewController.importHandler = importHandler;
[self presentViewController:templateCollectionViewController animated:YES completion:nil];
}
-(void)documentBrowser:(UIDocumentBrowserViewController *)controller didPickDocumentURLs:(NSArray<NSURL *> *)documentURLs {
NSURL *sourceURL = documentURLs.firstObject;
if (!sourceURL) {
return;
}
// Present the Document View Controller for the first document that was picked.
// If you support picking multiple items, make sure you handle them all.
[self presentDocumentAtURL:sourceURL];
}
- (void)documentBrowser:(UIDocumentBrowserViewController *)controller didImportDocumentAtURL:(NSURL *)sourceURL toDestinationURL:(NSURL *)destinationURL {
// Present the Document View Controller for the new newly created document
[self presentDocumentAtURL:destinationURL];
}
- (void)documentBrowser:(UIDocumentBrowserViewController *)controller failedToImportDocumentAtURL:(NSURL *)documentURL error:(NSError * _Nullable)error {
// Make sure to handle the failed import appropriately, e.g., by presenting an error message to the user.
}
- (void)presentDocumentAtURL:(NSURL *)documentURL {
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
DocumentViewController *documentViewController = [storyBoard instantiateViewControllerWithIdentifier:@"DocumentViewController"];
documentViewController.document = [[Document alloc] initWithFileURL:documentURL];
documentViewController.document->fakeClientFd = -1;
documentViewController.document.viewController = documentViewController;
[self presentViewController:documentViewController animated:YES completion:nil];
}
@end
// vim:set shiftwidth=4 softtabstop=4 expandtab: