summaryrefslogtreecommitdiff
path: root/platform/ios/Classes/MuLibraryController.m
diff options
context:
space:
mode:
authorPaul Gardiner <paul.gardiner@artifex.com>2014-01-09 14:45:00 +0000
committerPaul Gardiner <paul.gardiner@artifex.com>2014-01-09 14:45:43 +0000
commitd7ea5f971b84a138697546cbdba8ad76f1bb760e (patch)
treea7eaf2ef7e043d14a039877a46db315993022cb0 /platform/ios/Classes/MuLibraryController.m
parent7faadb8537042ac310e64274d5164fa7f2d05199 (diff)
downloadmupdf-d7ea5f971b84a138697546cbdba8ad76f1bb760e.tar.xz
iOS: save changes on returning to the library
Also change the way the back button works, using an explicit action, rather than relying on the navigation controller. Doing so allowed an alert dialog to be displayed asking if document changes should be discarded or saved. It also allowed the word-based button to be replaced by an icon-based one, which saves space (important for iPod and iPhone). We may want to also save on other occasions, but this at least provides some way to do so.
Diffstat (limited to 'platform/ios/Classes/MuLibraryController.m')
-rw-r--r--platform/ios/Classes/MuLibraryController.m22
1 files changed, 14 insertions, 8 deletions
diff --git a/platform/ios/Classes/MuLibraryController.m b/platform/ios/Classes/MuLibraryController.m
index 7f21b303..f5e93351 100644
--- a/platform/ios/Classes/MuLibraryController.m
+++ b/platform/ios/Classes/MuLibraryController.m
@@ -153,19 +153,23 @@ static void showAlert(NSString *msg, NSString *filename)
- (void) openDocument: (NSString*)nsfilename
{
- char filename[PATH_MAX];
+ NSString *nspath = [[NSArray arrayWithObjects:NSHomeDirectory(), @"Documents", nsfilename, nil]
+ componentsJoinedByString:@"/"];
+ _filePath = malloc(strlen([nspath UTF8String])+1);
+ if (_filePath == NULL) {
+ showAlert(@"Out of memory in openDocument", nsfilename);
+ return;
+ }
- dispatch_sync(queue, ^{});
+ strcpy(_filePath, [nspath UTF8String]);
- strcpy(filename, [NSHomeDirectory() UTF8String]);
- strcat(filename, "/Documents/");
- strcat(filename, [nsfilename UTF8String]);
+ dispatch_sync(queue, ^{});
- printf("open document '%s'\n", filename);
+ printf("open document '%s'\n", _filePath);
_filename = [nsfilename retain];
[doc release];
- doc = [[MuDocRef alloc] initWithFilename:filename];
+ doc = [[MuDocRef alloc] initWithFilename:_filePath];
if (!doc) {
showAlert(@"Cannot open document", nsfilename);
return;
@@ -206,18 +210,20 @@ static void showAlert(NSString *msg, NSString *filename)
- (void) onPasswordOkay
{
- MuDocumentController *document = [[MuDocumentController alloc] initWithFilename: _filename document: doc];
+ MuDocumentController *document = [[MuDocumentController alloc] initWithFilename: _filename path:_filePath document: doc];
if (document) {
[self setTitle: @"Library"];
[[self navigationController] pushViewController: document animated: YES];
[document release];
}
[_filename release];
+ free(_filePath);
}
- (void) onPasswordCancel
{
[_filename release];
+ free(_filePath);
printf("close document (password cancel)\n");
}