diff options
author | Paul Gardiner <paul.gardiner@artifex.com> | 2014-04-24 10:04:20 +0100 |
---|---|---|
committer | Paul Gardiner <paul.gardiner@artifex.com> | 2014-04-24 10:05:42 +0100 |
commit | 4c0d6fe09c9f96419e5e622f8e22e5ab1eb6735a (patch) | |
tree | 791320ec970a5390916c1a89a4f0089b4032a9dd /platform/ios/Classes | |
parent | 0b5c38d26a822ec8b3e82ec24da6c0b92e4aa0bd (diff) | |
download | mupdf-4c0d6fe09c9f96419e5e622f8e22e5ab1eb6735a.tar.xz |
iOS: add support for sharing documents with other apps
Diffstat (limited to 'platform/ios/Classes')
-rw-r--r-- | platform/ios/Classes/MuDocumentController.h | 2 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.m | 59 |
2 files changed, 54 insertions, 7 deletions
diff --git a/platform/ios/Classes/MuDocumentController.h b/platform/ios/Classes/MuDocumentController.h index 29a9ac1a..094c247d 100644 --- a/platform/ios/Classes/MuDocumentController.h +++ b/platform/ios/Classes/MuDocumentController.h @@ -38,7 +38,7 @@ enum UISearchBar *searchBar; UIBarButtonItem *nextButton, *prevButton, *cancelButton, *searchButton, *outlineButton, *linkButton; UIBarButtonItem *moreButton; - UIBarButtonItem *printButton, *annotButton; + UIBarButtonItem *shareButton, *printButton, *annotButton; UIBarButtonItem *highlightButton, *underlineButton, *strikeoutButton; UIBarButtonItem *inkButton; UIBarButtonItem *tickButton; diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m index 9893b211..3e95b505 100644 --- a/platform/ios/Classes/MuDocumentController.m +++ b/platform/ios/Classes/MuDocumentController.m @@ -15,6 +15,11 @@ #define MIN_SCALE (1.0) #define MAX_SCALE (5.0) +static NSString *const AlertTitle = @"Save Document?"; +// Correct functioning of the app relies on CloseAlertMessage and ShareAlertMessage differing +static NSString *const CloseAlertMessage = @"Changes have been made to the document that will be lost if not saved"; +static NSString *const ShareAlertMessage = @"Your changes will not be shared unless the document is first saved"; + static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_outline *outline, int level) { char indent[8*4+1]; @@ -251,6 +256,7 @@ static void saveDoc(char *current_path, fz_document *doc) reflowButton = [self resourceBasedButton:@"ic_reflow" withAction:@selector(onToggleReflow:)]; moreButton = [self resourceBasedButton:@"ic_more" withAction:@selector(onMore:)]; annotButton = [self resourceBasedButton:@"ic_annotation" withAction:@selector(onAnnot:)]; + shareButton = [self resourceBasedButton:@"ic_share" withAction:@selector(onShare:)]; printButton = [self resourceBasedButton:@"ic_print" withAction:@selector(onPrint:)]; highlightButton = [self resourceBasedButton:@"ic_highlight" withAction:@selector(onHighlight:)]; underlineButton = [self resourceBasedButton:@"ic_underline" withAction:@selector(onUnderline:)]; @@ -281,13 +287,18 @@ static void saveDoc(char *current_path, fz_document *doc) [slider release]; slider = nil; [sliderWrapper release]; sliderWrapper = nil; [reflowButton release]; reflowButton = nil; + [backButton release]; backButton = nil; [moreButton release]; moreButton = nil; [searchBar release]; searchBar = nil; [outlineButton release]; outlineButton = nil; + [linkButton release]; linkButton = nil; [searchButton release]; searchButton = nil; [cancelButton release]; cancelButton = nil; [prevButton release]; prevButton = nil; [nextButton release]; nextButton = nil; + [shareButton release]; shareButton = nil; + [printButton release]; printButton = nil; + [annotButton release]; annotButton = nil; [highlightButton release]; highlightButton = nil; [underlineButton release]; underlineButton = nil; [strikeoutButton release]; strikeoutButton = nil; @@ -448,7 +459,7 @@ static void saveDoc(char *current_path, fz_document *doc) - (void) showMoreMenu { - [[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObjects:printButton, annotButton, nil]]; + [[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObjects:annotButton, printButton, shareButton, nil]]; [[self navigationItem] setLeftBarButtonItem:cancelButton]; barmode = BARMODE_MORE; @@ -511,6 +522,28 @@ static void saveDoc(char *current_path, fz_document *doc) } } +- (void) shareDocument +{ + NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filePath]]; + UIActivityViewController *cont = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObject:url] applicationActivities:nil]; + [self presentViewController:cont animated:YES completion:nil]; +} + +- (void) onShare: (id)sender +{ + pdf_document *idoc = pdf_specifics(doc); + if (idoc && pdf_has_unsaved_changes(idoc)) + { + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:AlertTitle message:ShareAlertMessage delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save and Share", nil]; + [alertView show]; + [alertView release]; + } + else + { + [self shareDocument]; + } +} + - (void) textSelectModeOn { [[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObject:tickButton]]; @@ -664,9 +697,10 @@ static void saveDoc(char *current_path, fz_document *doc) if (idoc && pdf_has_unsaved_changes(idoc)) { UIAlertView *saveAlert = [[UIAlertView alloc] - initWithTitle:@"Save changes?" message:nil delegate:self + initWithTitle:AlertTitle message:CloseAlertMessage delegate:self cancelButtonTitle:@"Discard" otherButtonTitles:@"Save", nil]; [saveAlert show]; + [saveAlert release]; } else { @@ -676,11 +710,24 @@ static void saveDoc(char *current_path, fz_document *doc) - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - if (buttonIndex == 1) - saveDoc(filePath, doc); + if ([CloseAlertMessage isEqualToString:alertView.message]) + { + if (buttonIndex == 1) + saveDoc(filePath, doc); - [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES]; - [[self navigationController] popViewControllerAnimated:YES]; + [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES]; + [[self navigationController] popViewControllerAnimated:YES]; + } + + if ([ShareAlertMessage isEqualToString:alertView.message]) + { + [alertView dismissWithClickedButtonIndex:buttonIndex animated:NO]; + if (buttonIndex == 1) + { + saveDoc(filePath, doc); + [self shareDocument]; + } + } } - (void) resetSearch |