When opening an attachment from the Mail app make sure it is opened read-only
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: Ifd7d824d4f73cbf458f8597cd0974cf171b35be7pull/4601/head
parent
6d37e4c004
commit
4b7ecde829
|
@ -18,6 +18,7 @@
|
|||
int fakeClientFd;
|
||||
NSURL *copyFileURL;
|
||||
unsigned appDocId;
|
||||
bool readOnly;
|
||||
}
|
||||
|
||||
@property (weak) DocumentViewController *viewController;
|
||||
|
|
|
@ -74,7 +74,7 @@ static std::atomic<unsigned> appDocIdCounter(1);
|
|||
DocumentData::allocate(appDocId).coDocument = self;
|
||||
components.queryItems = @[ [NSURLQueryItem queryItemWithName:@"file_path" value:[copyFileURL absoluteString]],
|
||||
[NSURLQueryItem queryItemWithName:@"closebutton" value:@"1"],
|
||||
[NSURLQueryItem queryItemWithName:@"permission" value:@"edit"],
|
||||
[NSURLQueryItem queryItemWithName:@"permission" value:(readOnly ? @"readonly" : @"edit")],
|
||||
[NSURLQueryItem queryItemWithName:@"lang" value:app_locale],
|
||||
[NSURLQueryItem queryItemWithName:@"appdocid" value:[NSString stringWithFormat:@"%u", appDocId]],
|
||||
[NSURLQueryItem queryItemWithName:@"userinterfacemode" value:([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? @"notebookbar" : @"classic")],
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
DocumentViewController *documentViewController = [storyBoard instantiateViewControllerWithIdentifier:@"DocumentViewController"];
|
||||
documentViewController.document = [[CODocument alloc] initWithFileURL:documentURL];
|
||||
documentViewController.document->fakeClientFd = -1;
|
||||
documentViewController.document->readOnly = false;
|
||||
documentViewController.document.viewController = documentViewController;
|
||||
[self presentViewController:documentViewController animated:YES completion:nil];
|
||||
}
|
||||
|
|
|
@ -16,11 +16,12 @@ static UIViewController *bottomPresentedViewController(UIViewController *vc) {
|
|||
return bottomPresentedViewController([vc presentedViewController]);
|
||||
}
|
||||
|
||||
static DocumentViewController *newDocumentViewControllerFor(NSURL *url) {
|
||||
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;
|
||||
|
@ -37,7 +38,7 @@ static DocumentViewController *newDocumentViewControllerFor(NSURL *url) {
|
|||
return;
|
||||
|
||||
for (UIOpenURLContext* context in connectionOptions.URLContexts) {
|
||||
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL);
|
||||
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL, !context.options.openInPlace);
|
||||
[windowScene.windows[0].rootViewController presentViewController:documentViewController animated:NO completion:nil];
|
||||
}
|
||||
if ([connectionOptions.URLContexts count] > 0)
|
||||
|
@ -52,7 +53,7 @@ static DocumentViewController *newDocumentViewControllerFor(NSURL *url) {
|
|||
return;
|
||||
|
||||
for (UIOpenURLContext* context in URLContexts) {
|
||||
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL);
|
||||
DocumentViewController *documentViewController = newDocumentViewControllerFor(context.URL, !context.options.openInPlace);
|
||||
[bottomPresentedViewController(windowScene.windows[0].rootViewController) presentViewController:documentViewController animated:NO completion:nil];
|
||||
}
|
||||
if ([URLContexts count] > 0)
|
||||
|
|
Loading…
Reference in New Issue