diff options
-rw-r--r-- | platform/ios/Classes/MuDocumentController.h | 2 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.m | 59 | ||||
-rw-r--r-- | platform/ios/MuPDF.xcodeproj/project.pbxproj | 4 |
3 files changed, 58 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 diff --git a/platform/ios/MuPDF.xcodeproj/project.pbxproj b/platform/ios/MuPDF.xcodeproj/project.pbxproj index 0d2b2abd..de6c3f89 100644 --- a/platform/ios/MuPDF.xcodeproj/project.pbxproj +++ b/platform/ios/MuPDF.xcodeproj/project.pbxproj @@ -62,6 +62,7 @@ DAD47D301832615900E173A0 /* ic_underline.png in Resources */ = {isa = PBXBuildFile; fileRef = DAD47D2D1832615900E173A0 /* ic_underline.png */; }; DAD72802183E53F0005C14FA /* MuAnnotSelectView.m in Sources */ = {isa = PBXBuildFile; fileRef = DAD72801183E53F0005C14FA /* MuAnnotSelectView.m */; }; DAD72804183E6F33005C14FA /* ic_trash.png in Resources */ = {isa = PBXBuildFile; fileRef = DAD72803183E6F33005C14FA /* ic_trash.png */; }; + DADF824D1905242800855662 /* ic_share.png in Resources */ = {isa = PBXBuildFile; fileRef = DADF824C1905241900855662 /* ic_share.png */; }; DAF81D5B18800D1800B0F028 /* TapImage.m in Sources */ = {isa = PBXBuildFile; fileRef = DAF81D5A18800D1800B0F028 /* TapImage.m */; }; DAFF997B187C12430081C756 /* MuChoiceFieldController.m in Sources */ = {isa = PBXBuildFile; fileRef = DAFF9979187C12430081C756 /* MuChoiceFieldController.m */; }; DAFF997C187C12430081C756 /* MuChoiceFieldController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DAFF997A187C12430081C756 /* MuChoiceFieldController.xib */; }; @@ -156,6 +157,7 @@ DAD72801183E53F0005C14FA /* MuAnnotSelectView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MuAnnotSelectView.m; path = Classes/MuAnnotSelectView.m; sourceTree = "<group>"; }; DAD72803183E6F33005C14FA /* ic_trash.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ic_trash.png; path = "../android/res/drawable-ldpi/ic_trash.png"; sourceTree = "<group>"; }; DADD8D6917EB24C000C49E0B /* MuPageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MuPageView.h; path = Classes/MuPageView.h; sourceTree = "<group>"; }; + DADF824C1905241900855662 /* ic_share.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ic_share.png; path = "../android/res/drawable-ldpi/ic_share.png"; sourceTree = "<group>"; }; DAF81D5918800D1800B0F028 /* TapImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TapImage.h; path = Classes/TapImage.h; sourceTree = "<group>"; }; DAF81D5A18800D1800B0F028 /* TapImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TapImage.m; path = Classes/TapImage.m; sourceTree = "<group>"; }; DAFF9978187C12430081C756 /* MuChoiceFieldController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MuChoiceFieldController.h; path = Classes/MuChoiceFieldController.h; sourceTree = "<group>"; }; @@ -226,6 +228,7 @@ 968E1E461779A54F0050CEA3 /* Resources */ = { isa = PBXGroup; children = ( + DADF824C1905241900855662 /* ic_share.png */, DA7AAA3A18E45FA300A577E3 /* ic_annotation.png */, DA32FC7218E33CC7001D7902 /* ic_print.png */, DAD72803183E6F33005C14FA /* ic_trash.png */, @@ -410,6 +413,7 @@ DACD12271833CDA600D4B9C5 /* ic_check.png in Resources */, DA442E2D183B796F008EF49B /* ic_pen.png in Resources */, DAD72804183E6F33005C14FA /* ic_trash.png in Resources */, + DADF824D1905242800855662 /* ic_share.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; |