Skip to content
Snippets Groups Projects
Commit 5fd9042f authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

fix "Cancel"

parent 50642a61
Branches
Tags
No related merge requests found
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
self.aboutView.delegate = self; self.aboutView.delegate = self;
self.aboutView.dataDetectorTypes = UIDataDetectorTypeNone; self.aboutView.dataDetectorTypes = UIDataDetectorTypeNone;
if(self.fileToEdit){ if(self.fileToEdit){
NSData *fileData = [NSData dataWithContentsOfFile:self.fileToEdit]; NSData *fileData = [NSData dataWithContentsOfFile:self.fileToEdit];
NSString* aStr = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; NSString* aStr = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
...@@ -45,13 +45,13 @@ ...@@ -45,13 +45,13 @@
} }
else{ 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&egrave;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&ccedil;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&egrave;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>", [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&egrave;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&ccedil;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&egrave;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"], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
GMSH_VERSION, GMSH_VERSION,
GMSH_DATE, GMSH_DATE,
GMSH_CONFIG_OPTIONS, GMSH_CONFIG_OPTIONS,
GETDP_VERSION, GETDP_VERSION,
GETDP_DATE, GETDP_DATE,
GETDP_CONFIG_OPTIONS] GETDP_CONFIG_OPTIONS]
baseURL:[[NSBundle mainBundle] bundleURL]]; baseURL:[[NSBundle mainBundle] bundleURL]];
} }
} }
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
-(void)saveFile -(void)saveFile
{ {
NSString *text = [self.aboutView stringByEvaluatingJavaScriptFromString: NSString *text = [self.aboutView stringByEvaluatingJavaScriptFromString:
@"document.body.innerText"]; @"document.body.innerText"];
NSLog(@"Saving file %@", self.fileToEdit); NSLog(@"Saving file %@", self.fileToEdit);
NSError *error; NSError *error;
[text writeToFile:self.fileToEdit atomically:YES [text writeToFile:self.fileToEdit atomically:YES
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
NSMutableString *currentElementValue; NSMutableString *currentElementValue;
NSString *currentDir; NSString *currentDir;
NSString *selectedModel; NSString *selectedModel;
NSString *currentFileToEdit; NSString *currentFileToEdit;
} }
@property (nonatomic, retain) EAGLView *glView; @property (nonatomic, retain) EAGLView *glView;
@property (nonatomic, retain) UIActionSheet *longPressActionSheet; @property (nonatomic, retain) UIActionSheet *longPressActionSheet;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
-(void)showAbout -(void)showAbout
{ {
currentFileToEdit = nil; currentFileToEdit = nil;
[self performSegueWithIdentifier:@"showAboutSegue" sender:self]; [self performSegueWithIdentifier:@"showAboutSegue" sender:self];
} }
...@@ -118,8 +118,8 @@ ...@@ -118,8 +118,8 @@
completion:nil]; completion:nil];
} }
else{ else{
[self performSegueWithIdentifier:@"showModelSegue" sender:self]; [self performSegueWithIdentifier:@"showModelSegue" sender:self];
} }
} }
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
...@@ -128,154 +128,154 @@ ...@@ -128,154 +128,154 @@
if(sender.state == UIGestureRecognizerStateCancelled) return; if(sender.state == UIGestureRecognizerStateCancelled) return;
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if(indexPath == nil) return; if(indexPath == nil) return;
if([[models objectAtIndex:indexPath.row] getUrl]) 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]; 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 else
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 = [[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.tag = indexPath.row;
[self.longPressActionSheet showInView:self.view]; [self.longPressActionSheet showInView:self.view];
} }
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{ {
if(actionSheet == self.longPressActionSheet){ if(actionSheet == self.longPressActionSheet){
switch (buttonIndex) { switch (buttonIndex) {
case 5: case 5:
[[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]];
break; break;
case 4: case 4:
{ {
NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile];
NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; NSString *modelPath = [modelFile stringByDeletingLastPathComponent];
NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL];
// TODO: would probably be better to email a zip archive? (this ignores subdirectories) // TODO: would probably be better to email a zip archive? (this ignores subdirectories)
[self attachFilesToEmail:modelFiles filePath:modelPath]; [self attachFilesToEmail:modelFiles filePath:modelPath];
} }
break; break;
case 3: case 3:
{ {
NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile];
NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; NSString *modelPath = [modelFile stringByDeletingLastPathComponent];
NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL];
self.editFilesActionSheet = [[UIActionSheet alloc] initWithTitle:@"Model files" delegate:self self.editFilesActionSheet = [[UIActionSheet alloc] initWithTitle:@"Model files" delegate:self
cancelButtonTitle: nil cancelButtonTitle: nil
destructiveButtonTitle: nil destructiveButtonTitle: nil
otherButtonTitles: nil]; otherButtonTitles: nil];
for(NSString *file in modelFiles) { for(NSString *file in modelFiles) {
NSString *extension = [file pathExtension]; NSString *extension = [file pathExtension];
if([extension isEqualToString:@"txt"] || if([extension isEqualToString:@"txt"] ||
[extension isEqualToString:@"geo"] || [extension isEqualToString:@"geo"] ||
[extension isEqualToString:@"pro"] || [extension isEqualToString:@"pro"] ||
[extension isEqualToString:@"dat"]){ [extension isEqualToString:@"dat"]){
[self.editFilesActionSheet addButtonWithTitle:file]; [self.editFilesActionSheet addButtonWithTitle:file];
} }
} }
[self.editFilesActionSheet addButtonWithTitle:@"Cancel"]; self.editFilesActionSheet.cancelButtonIndex = [self.editFilesActionSheet addButtonWithTitle:@"Cancel"];
self.editFilesActionSheet.cancelButtonIndex = [modelFiles count];
self.editFilesActionSheet.tag = actionSheet.tag; self.editFilesActionSheet.tag = actionSheet.tag;
[self.editFilesActionSheet showInView:self.view]; [self.editFilesActionSheet showInView:self.view];
} }
break; break;
case 2: case 2:
{ {
NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile];
NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; NSString *modelPath = [modelFile stringByDeletingLastPathComponent];
NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL]; NSArray *modelFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:modelPath error:NULL];
for (NSString *obj in modelFiles){ for (NSString *obj in modelFiles){
NSString *extension = [obj pathExtension]; NSString *extension = [obj pathExtension];
if([extension isEqualToString:@"msh"] || if([extension isEqualToString:@"msh"] ||
[extension isEqualToString:@"pre"] || [extension isEqualToString:@"pre"] ||
[extension isEqualToString:@"res"] || [extension isEqualToString:@"res"] ||
[extension isEqualToString:@"pos"]){ [extension isEqualToString:@"pos"]){
NSString *file = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:obj]; NSString *file = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:obj];
NSLog(@"Removing file %@", file); NSLog(@"Removing file %@", file);
[[NSFileManager defaultManager] removeItemAtPath:file error:nil]; [[NSFileManager defaultManager] removeItemAtPath:file error:nil];
} }
} }
} }
break; break;
case 1: case 1:
{ {
NSString *file = [[models objectAtIndex:actionSheet.tag] getFile]; NSString *file = [[models objectAtIndex:actionSheet.tag] getFile];
NSString *path = [file stringByDeletingLastPathComponent]; NSString *path = [file stringByDeletingLastPathComponent];
[[NSFileManager defaultManager] removeItemAtPath:path error:nil]; [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
[self refreshList]; [self refreshList];
} }
break; break;
case 0: case 0:
[self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]]; [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]];
break; break;
} }
} }
else{ else{
NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; if(buttonIndex != actionSheet.cancelButtonIndex){
NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile];
currentFileToEdit = [[modelPath stringByAppendingString:@"/"] NSString *modelPath = [modelFile stringByDeletingLastPathComponent];
stringByAppendingString:[actionSheet buttonTitleAtIndex:buttonIndex]]; NSString *file = [actionSheet buttonTitleAtIndex:buttonIndex];
[self performSegueWithIdentifier:@"showAboutSegue" sender:self]; currentFileToEdit = [[modelPath stringByAppendingString:@"/"] stringByAppendingString:file];
} [self performSegueWithIdentifier:@"showAboutSegue" sender:self];
}
}
} }
- (void)attachFilesToEmail:(NSArray*)files filePath:(NSString*)path - (void)attachFilesToEmail:(NSArray*)files filePath:(NSString*)path
{ {
if([MFMailComposeViewController canSendMail] == NO) return; if([MFMailComposeViewController canSendMail] == NO) return;
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self; mc.mailComposeDelegate = self;
[mc setSubject:@"My ONELAB model"]; [mc setSubject:@"My ONELAB model"];
// Add attachments // Add attachments
for (NSString *file in files){ for (NSString *file in files){
NSString *extension = [file pathExtension]; NSString *extension = [file pathExtension];
NSString *filePath = [[path stringByAppendingString:@"/"] stringByAppendingString:file]; NSString *filePath = [[path stringByAppendingString:@"/"] stringByAppendingString:file];
NSData *fileData = [NSData dataWithContentsOfFile:filePath]; NSData *fileData = [NSData dataWithContentsOfFile:filePath];
if(fileData){ if(fileData){
NSString *mimeType; NSString *mimeType;
if ([extension isEqualToString:@"jpg"]) { if ([extension isEqualToString:@"jpg"]) {
mimeType = @"image/jpeg"; mimeType = @"image/jpeg";
} }
else if([extension isEqualToString:@"png"]) { else if([extension isEqualToString:@"png"]) {
mimeType = @"image/png"; mimeType = @"image/png";
} }
else if([extension isEqualToString:@"doc"]) { else if([extension isEqualToString:@"doc"]) {
mimeType = @"application/msword"; mimeType = @"application/msword";
} }
else if([extension isEqualToString:@"ppt"]) { else if([extension isEqualToString:@"ppt"]) {
mimeType = @"application/vnd.ms-powerpoint"; mimeType = @"application/vnd.ms-powerpoint";
} }
else if([extension isEqualToString:@"html"]) { else if([extension isEqualToString:@"html"]) {
mimeType = @"text/html"; mimeType = @"text/html";
} }
else if([extension isEqualToString:@"pdf"]) { else if([extension isEqualToString:@"pdf"]) {
mimeType = @"application/pdf"; mimeType = @"application/pdf";
} }
else{ else{
mimeType = @"text/plain"; mimeType = @"text/plain";
} }
[mc addAttachmentData:fileData mimeType:@"" fileName:file];
}
}
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
[mc addAttachmentData:fileData mimeType:@"" fileName:file];
}
}
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
} }
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{ {
switch (result){ switch (result){
case MFMailComposeResultCancelled: NSLog(@"Mail cancelled"); break; case MFMailComposeResultCancelled: NSLog(@"Mail cancelled"); break;
case MFMailComposeResultSaved: NSLog(@"Mail saved"); break; case MFMailComposeResultSaved: NSLog(@"Mail saved"); break;
case MFMailComposeResultSent: NSLog(@"Mail sent"); break; case MFMailComposeResultSent: NSLog(@"Mail sent"); break;
case MFMailComposeResultFailed: NSLog(@"Mail sent failure: %@", [error localizedDescription]); break; case MFMailComposeResultFailed: NSLog(@"Mail sent failure: %@", [error localizedDescription]); break;
default: break; default: break;
} }
// Close the Mail Interface // Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL]; [self dismissViewControllerAnimated:YES completion:NULL];
} }
- (BOOL) parseInfosFile:(NSString *)file - (BOOL) parseInfosFile:(NSString *)file
{ {
NSData *xmlFile = [[NSFileManager defaultManager] contentsAtPath:file]; NSData *xmlFile = [[NSFileManager defaultManager] contentsAtPath:file];
...@@ -347,9 +347,9 @@ ...@@ -347,9 +347,9 @@
ModelViewController *modelViewController = [segue destinationViewController]; ModelViewController *modelViewController = [segue destinationViewController];
modelViewController.initialModel = selectedModel; modelViewController.initialModel = selectedModel;
} }
else if ([[segue identifier] isEqualToString:@"showAboutSegue"]) { else if ([[segue identifier] isEqualToString:@"showAboutSegue"]) {
AboutViewController *aboutViewController = [segue destinationViewController]; AboutViewController *aboutViewController = [segue destinationViewController];
aboutViewController.fileToEdit = currentFileToEdit; aboutViewController.fileToEdit = currentFileToEdit;
} }
} }
@end @end
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
[_progressIndicator stopAnimating]; [_progressIndicator stopAnimating];
[_progressIndicator setHidden:YES]; [_progressIndicator setHidden:YES];
if(_errors.count > 0) { if(_errors.count > 0) {
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Gmsh/GetDP error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil];
[_errorAlert show]; [_errorAlert show];
} }
} }
...@@ -328,9 +328,9 @@ ...@@ -328,9 +328,9 @@
} }
else [_errors removeLastObject]; else [_errors removeLastObject];
if(_errors.count > 1) if(_errors.count > 1)
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Gmsh/GetDP error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil];
else else
_errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Gmsh/GetDP error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles: nil]; _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles: nil];
[_errorAlert show]; [_errorAlert show];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment