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 @@
@interface AboutViewController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *aboutView;
@property (nonatomic, retain) NSString *fileToEdit;
@end
......@@ -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&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"],
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&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"],
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
......
......@@ -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
#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
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment