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

model files can now be edited by hand

parent 2da2739c
No related branches found
No related tags found
No related merge requests found
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
@interface AboutViewController : UIViewController <UIWebViewDelegate> @interface AboutViewController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *aboutView; @property (weak, nonatomic) IBOutlet UIWebView *aboutView;
@property (nonatomic, retain) NSString *fileToEdit;
@end @end
...@@ -35,6 +35,15 @@ ...@@ -35,6 +35,15 @@
// 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){
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&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,
...@@ -44,14 +53,17 @@ ...@@ -44,14 +53,17 @@
GETDP_DATE, GETDP_DATE,
GETDP_CONFIG_OPTIONS] GETDP_CONFIG_OPTIONS]
baseURL:[[NSBundle mainBundle] bundleURL]]; baseURL:[[NSBundle mainBundle] bundleURL]];
}
}
/* This is how we could load a file, edit it and get the modified text back: -(void)saveFile
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]];
NSString *text = [self.aboutView stringByEvaluatingJavaScriptFromString: NSString *text = [self.aboutView stringByEvaluatingJavaScriptFromString:
@"document.body.innerText"]; @"document.body.innerText"];
*/ NSLog(@"Saving file %@", self.fileToEdit);
NSError *error;
[text writeToFile:self.fileToEdit atomically:YES
encoding:NSUTF8StringEncoding error:&error];
} }
- (void)didReceiveMemoryWarning - (void)didReceiveMemoryWarning
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
NSMutableString *currentElementValue; NSMutableString *currentElementValue;
NSString *currentDir; NSString *currentDir;
NSString *selectedModel; NSString *selectedModel;
NSString *currentFileToEdit;
} }
@property (nonatomic, retain) EAGLView *glView; @property (nonatomic, retain) EAGLView *glView;
@property (nonatomic, retain) UIActionSheet *longPressActionSheet;
@property (nonatomic, retain) UIActionSheet *editFilesActionSheet;
@end @end
#import "AppDelegate.h" #import "AppDelegate.h"
#import "ModelListController.h" #import "ModelListController.h"
#import "AboutViewController.h"
#import "Utils.h" #import "Utils.h"
#import "Model.h" #import "Model.h"
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
-(void)showAbout -(void)showAbout
{ {
currentFileToEdit = nil;
[self performSegueWithIdentifier:@"showAboutSegue" sender:self]; [self performSegueWithIdentifier:@"showAboutSegue" sender:self];
} }
...@@ -115,8 +117,7 @@ ...@@ -115,8 +117,7 @@
animations:^{ appDelegate.window.rootViewController = appDelegate.splitViewController; } animations:^{ appDelegate.window.rootViewController = appDelegate.splitViewController; }
completion:nil]; completion:nil];
} }
else else{
{
[self performSegueWithIdentifier:@"showModelSegue" sender:self]; [self performSegueWithIdentifier:@"showModelSegue" sender:self];
} }
} }
...@@ -127,22 +128,22 @@ ...@@ -127,22 +128,22 @@
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;
UIActionSheet *actionSheet;
if([[models objectAtIndex:indexPath.row] getUrl]) 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]; 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
actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open", @"Remove", @"Clear results", @"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];
actionSheet.tag = indexPath.row; self.longPressActionSheet.tag = indexPath.row;
[actionSheet 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){
switch (buttonIndex) { switch (buttonIndex) {
case 4: case 5:
[[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]];
break; break;
case 3: case 4:
{ {
NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile];
NSString *modelPath = [modelFile stringByDeletingLastPathComponent]; NSString *modelPath = [modelFile stringByDeletingLastPathComponent];
...@@ -151,6 +152,30 @@ ...@@ -151,6 +152,30 @@
[self attachFilesToEmail:modelFiles filePath:modelPath]; [self attachFilesToEmail:modelFiles filePath:modelPath];
} }
break; 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: case 2:
{ {
NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile]; NSString *modelFile = [[models objectAtIndex:actionSheet.tag] getFile];
...@@ -182,6 +207,14 @@ ...@@ -182,6 +207,14 @@
break; 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 - (void)attachFilesToEmail:(NSArray*)files filePath:(NSString*)path
{ {
...@@ -314,5 +347,9 @@ ...@@ -314,5 +347,9 @@
ModelViewController *modelViewController = [segue destinationViewController]; ModelViewController *modelViewController = [segue destinationViewController];
modelViewController.initialModel = selectedModel; modelViewController.initialModel = selectedModel;
} }
else if ([[segue identifier] isEqualToString:@"showAboutSegue"]) {
AboutViewController *aboutViewController = [segue destinationViewController];
aboutViewController.fileToEdit = currentFileToEdit;
}
} }
@end @end
...@@ -35,11 +35,11 @@ ...@@ -35,11 +35,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.3.1</string> <string>1.3.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.3.1.7</string> <string>1.3.2.1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UIFileSharingEnabled</key> <key>UIFileSharingEnabled</key>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment