diff --git a/contrib/mobile/iOS/Onelab/AboutViewController.h b/contrib/mobile/iOS/Onelab/AboutViewController.h index 8df8225255c6ebaf639754553e291ec745987a1f..7dc42f359742c8099ba1c6def3f90001158723ae 100644 --- a/contrib/mobile/iOS/Onelab/AboutViewController.h +++ b/contrib/mobile/iOS/Onelab/AboutViewController.h @@ -3,5 +3,6 @@ @interface AboutViewController : UIViewController <UIWebViewDelegate> @property (weak, nonatomic) IBOutlet UIWebView *aboutView; +@property (nonatomic, retain) NSString *fileToEdit; @end diff --git a/contrib/mobile/iOS/Onelab/AboutViewController.mm b/contrib/mobile/iOS/Onelab/AboutViewController.mm index 8089e72cdb913f6956400049ab2c51213f090b51..91d0b0def421337c77ba31d5cd692a55d81c031c 100644 --- a/contrib/mobile/iOS/Onelab/AboutViewController.mm +++ b/contrib/mobile/iOS/Onelab/AboutViewController.mm @@ -35,23 +35,35 @@ // Do any additional setup after loading the view. self.aboutView.delegate = self; self.aboutView.dataDetectorTypes = UIDataDetectorTypeNone; - [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<html><head><style type=\"text/css\"><!--body { background-color: #FFFFFF; color: #252525; margin: 35px 10px 35px 10px; padding: 0; font-family: helvetica-neue,sans-serif; font-size: 1em; }--></style></head><body><center><p><!--img width=32 src=\"icon_onelab.png\"--></p><h3>Onelab/Mobile</h3>Version %@<p>Copyright (C) 2014-2016 Christophe Geuzaine and Maxime Graulich, University of Liège</p><p>Visit <a href=\"http://onelab.info/\">http://onelab.info/</a> for more information</p><p style=\"padding-top: 35px;\">This version of Onelab/Mobile contains:</p><h3>Gmsh</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2016 Christophe Geuzaine and Jean-François Remacle</p><p><a href=\"http://geuz.org/gmsh/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/gmsh/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://gmsh.info/\">http://gmsh.info</a> for more information</p><h3>GetDP</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2016 Patrick Dular and Christophe Geuzaine, University of Liège</p><p><a href=\"http://geuz.org/getdp/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/getdp/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://getdp.info\">http://getdp.info</a> for more information</p></center></body>", - [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], - GMSH_VERSION, - GMSH_DATE, - GMSH_CONFIG_OPTIONS, - GETDP_VERSION, - GETDP_DATE, - GETDP_CONFIG_OPTIONS] - baseURL:[[NSBundle mainBundle] bundleURL]]; + + if(self.fileToEdit){ + NSData *fileData = [NSData dataWithContentsOfFile:self.fileToEdit]; + NSString* aStr = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; + [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<html><body><pre contenteditable=\"true\">%@</pre></body></html>", aStr] baseURL:[[NSBundle mainBundle] bundleURL]]; + UIBarButtonItem *save = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveFile)]; + [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: save, nil]]; + } + else{ + [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<html><head><style type=\"text/css\"><!--body { background-color: #FFFFFF; color: #252525; margin: 35px 10px 35px 10px; padding: 0; font-family: helvetica-neue,sans-serif; font-size: 1em; }--></style></head><body><center><p><!--img width=32 src=\"icon_onelab.png\"--></p><h3>Onelab/Mobile</h3>Version %@<p>Copyright (C) 2014-2016 Christophe Geuzaine and Maxime Graulich, University of Liège</p><p>Visit <a href=\"http://onelab.info/\">http://onelab.info/</a> for more information</p><p style=\"padding-top: 35px;\">This version of Onelab/Mobile contains:</p><h3>Gmsh</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2016 Christophe Geuzaine and Jean-François Remacle</p><p><a href=\"http://geuz.org/gmsh/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/gmsh/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://gmsh.info/\">http://gmsh.info</a> for more information</p><h3>GetDP</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2016 Patrick Dular and Christophe Geuzaine, University of Liège</p><p><a href=\"http://geuz.org/getdp/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/getdp/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://getdp.info\">http://getdp.info</a> for more information</p></center></body>", + [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], + GMSH_VERSION, + GMSH_DATE, + GMSH_CONFIG_OPTIONS, + GETDP_VERSION, + GETDP_DATE, + GETDP_CONFIG_OPTIONS] + baseURL:[[NSBundle mainBundle] bundleURL]]; + } +} - /* This is how we could load a file, edit it and get the modified text back: - NSData *fileData = [NSData dataWithContentsOfFile:@"my/path/to/magnet.pro"]; - NSString* aStr = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; - [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<html><body><pre contenteditable=\"true\">%@</pre></body></html>", aStr] baseURL:[[NSBundle mainBundle] bundleURL]]; +-(void)saveFile +{ NSString *text = [self.aboutView stringByEvaluatingJavaScriptFromString: @"document.body.innerText"]; - */ + NSLog(@"Saving file %@", self.fileToEdit); + NSError *error; + [text writeToFile:self.fileToEdit atomically:YES + encoding:NSUTF8StringEncoding error:&error]; } - (void)didReceiveMemoryWarning diff --git a/contrib/mobile/iOS/Onelab/ModelListController.h b/contrib/mobile/iOS/Onelab/ModelListController.h index 0461b62b40fc8d7251e5513e98b3908db99d8d8b..6ac41aadb1b4f1b39e6f5bfae9a3842c6b568d2f 100644 --- a/contrib/mobile/iOS/Onelab/ModelListController.h +++ b/contrib/mobile/iOS/Onelab/ModelListController.h @@ -10,6 +10,10 @@ NSMutableString *currentElementValue; NSString *currentDir; NSString *selectedModel; + NSString *currentFileToEdit; } @property (nonatomic, retain) EAGLView *glView; +@property (nonatomic, retain) UIActionSheet *longPressActionSheet; +@property (nonatomic, retain) UIActionSheet *editFilesActionSheet; + @end diff --git a/contrib/mobile/iOS/Onelab/ModelListController.mm b/contrib/mobile/iOS/Onelab/ModelListController.mm index b23577a9d53f97a46b63936a8268293faee52442..78f31fadf2ed4a13a2b18fdb00d28c5c765f105a 100644 --- a/contrib/mobile/iOS/Onelab/ModelListController.mm +++ b/contrib/mobile/iOS/Onelab/ModelListController.mm @@ -1,5 +1,6 @@ #import "AppDelegate.h" #import "ModelListController.h" +#import "AboutViewController.h" #import "Utils.h" #import "Model.h" @@ -37,6 +38,7 @@ -(void)showAbout { + currentFileToEdit = nil; [self performSegueWithIdentifier:@"showAboutSegue" sender:self]; } @@ -115,10 +117,9 @@ animations:^{ appDelegate.window.rootViewController = appDelegate.splitViewController; } completion:nil]; } - else - { - [self performSegueWithIdentifier:@"showModelSegue" sender:self]; - } + else{ + [self performSegueWithIdentifier:@"showModelSegue" sender:self]; + } } -(void)handleLongPress:(UILongPressGestureRecognizer *)sender @@ -127,60 +128,92 @@ if(sender.state == UIGestureRecognizerStateCancelled) return; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p]; if(indexPath == nil) return; - UIActionSheet *actionSheet; - if([[models objectAtIndex:indexPath.row] getUrl]) - actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"Email model files", @"Visit model website", nil]; + if([[models objectAtIndex:indexPath.row] getUrl]) + self.longPressActionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"Edit model files", @"Email model files", @"Visit model website", nil]; else - actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"Email model files", nil]; - actionSheet.tag = indexPath.row; - [actionSheet showInView:self.view]; + self.longPressActionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"Edit model files", @"Email model files", nil]; + self.longPressActionSheet.tag = indexPath.row; + [self.longPressActionSheet showInView:self.view]; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { - switch (buttonIndex) { - case 4: - [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; - break; - case 3: - { - NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; - NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; - // TODO: would probably be better to email a zip archive? (this ignores subdirectories) - [self attachFilesToEmail:modelFiles filePath:modelPath]; - } - break; - case 2: - { - NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; - NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; - for (NSString *obj in modelFiles){ - NSString *extension = [obj pathExtension]; - if([extension isEqualToString:@"msh"] || - [extension isEqualToString:@"pre"] || - [extension isEqualToString:@"res"] || - [extension isEqualToString:@"pos"]){ - NSString *file = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:obj]; - NSLog(@"Removing file %@", file); - [[NSFileManager defaultManager] removeItemAtPath:file error:nil]; - } + if(actionSheet == self.longPressActionSheet){ + switch (buttonIndex) { + case 5: + [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; + break; + case 4: + { + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; + // TODO: would probably be better to email a zip archive? (this ignores subdirectories) + [self attachFilesToEmail:modelFiles filePath:modelPath]; } + break; + case 3: + { + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; + self.editFilesActionSheet = [[UIActionSheet alloc] initWithTitle:@"Model files" delegate:self + cancelButtonTitle: nil + destructiveButtonTitle: nil + otherButtonTitles: nil]; + for(NSString *file in modelFiles) { + NSString *extension = [file pathExtension]; + if([extension isEqualToString:@"txt"] || + [extension isEqualToString:@"geo"] || + [extension isEqualToString:@"pro"] || + [extension isEqualToString:@"dat"]){ + [self.editFilesActionSheet addButtonWithTitle:file]; + } + } + [self.editFilesActionSheet addButtonWithTitle:@"Cancel"]; + self.editFilesActionSheet.cancelButtonIndex = [modelFiles count]; + self.editFilesActionSheet.tag = actionSheet.tag; + [self.editFilesActionSheet showInView:self.view]; + } + break; + case 2: + { + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; + for (NSString *obj in modelFiles){ + NSString *extension = [obj pathExtension]; + if([extension isEqualToString:@"msh"] || + [extension isEqualToString:@"pre"] || + [extension isEqualToString:@"res"] || + [extension isEqualToString:@"pos"]){ + NSString *file = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:obj]; + NSLog(@"Removing file %@", file); + [[NSFileManager defaultManager] removeItemAtPath:file error:nil]; + } + } + } + break; + case 1: + { + NSString *file = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *path = [file stringByDeletingLastPathComponent]; + [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; + [self refreshList]; + } + break; + case 0: + [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]]; + break; } - break; - case 1: - { - NSString *file = [[models objectAtIndex:actionSheet.tag] getFile]; - NSString *path = [file stringByDeletingLastPathComponent]; - [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; - [self refreshList]; - } - break; - case 0: - [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]]; - break; - } + } + else{ + NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; + NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; + currentFileToEdit = [[modelPath stringByAppendingString:@"/"] + stringByAppendingString:[actionSheet buttonTitleAtIndex:buttonIndex]]; + [self performSegueWithIdentifier:@"showAboutSegue" sender:self]; + } } - (void)attachFilesToEmail:(NSArray*)files filePath:(NSString*)path @@ -314,5 +347,9 @@ ModelViewController *modelViewController = [segue destinationViewController]; modelViewController.initialModel = selectedModel; } + else if ([[segue identifier] isEqualToString:@"showAboutSegue"]) { + AboutViewController *aboutViewController = [segue destinationViewController]; + aboutViewController.fileToEdit = currentFileToEdit; + } } @end diff --git a/contrib/mobile/iOS/Onelab/Onelab-Info.plist b/contrib/mobile/iOS/Onelab/Onelab-Info.plist index 6ee524ebe6a804ea181a2e322f48e48b8b494d04..f89623936e42fd998f88d3d9fc452941870fe7af 100644 --- a/contrib/mobile/iOS/Onelab/Onelab-Info.plist +++ b/contrib/mobile/iOS/Onelab/Onelab-Info.plist @@ -35,11 +35,11 @@ <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> - <string>1.3.1</string> + <string>1.3.2</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> - <string>1.3.1.7</string> + <string>1.3.2.1</string> <key>LSRequiresIPhoneOS</key> <true/> <key>UIFileSharingEnabled</key>