From 580aacf1a083522f279fbe29215485c97e875d56 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 12 Jun 2014 11:10:09 +0000
Subject: [PATCH] add cancel in actionsheet

---
 contrib/mobile/iOS/Onelab/Parameter.mm                | 6 ++++++
 contrib/mobile/iOS/Onelab/ParametersViewController.mm | 8 ++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/contrib/mobile/iOS/Onelab/Parameter.mm b/contrib/mobile/iOS/Onelab/Parameter.mm
index 9def2186d8..cd7b27e0ef 100644
--- a/contrib/mobile/iOS/Onelab/Parameter.mm
+++ b/contrib/mobile/iOS/Onelab/Parameter.mm
@@ -67,6 +67,8 @@
   std::vector<std::string> choices = string[0].getChoices();
   for(int i=0;i<choices.size();i++)
     [popupSelectValue addButtonWithTitle:[NSString stringWithFormat:@"%s", choices[i].c_str()]];
+  [popupSelectValue addButtonWithTitle:@"Cancel"];
+  [popupSelectValue setCancelButtonIndex:popupSelectValue.numberOfButtons - 1];
   [popupSelectValue showInView:button];
 }
 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
@@ -74,6 +76,7 @@
   std::vector<onelab::string> string;
   onelab::server::instance()->get(string,[name UTF8String]);
   if(string.size() < 1) return;
+  if(buttonIndex > string[0].getChoices().size() - 1) return; // cancel
   std::string selected = string[0].getChoices()[buttonIndex];
   string[0].setValue(selected);
   onelab::server::instance()->set(string[0]);
@@ -129,6 +132,8 @@
   std::vector<double> choices = number[0].getChoices();
   for(int i=0;i<choices.size();i++)
     [popupSelectValue addButtonWithTitle:[NSString stringWithFormat:@"%s", number[0].getValueLabel(choices[i]).c_str()]];
+  [popupSelectValue addButtonWithTitle:@"Cancel"];
+  [popupSelectValue setCancelButtonIndex:popupSelectValue.numberOfButtons - 1];
   [popupSelectValue showInView:button];
 }
 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
@@ -136,6 +141,7 @@
   std::vector<onelab::number> number;
   onelab::server::instance()->get(number,[name UTF8String]);
   if(number.size() < 1) return;
+  if(buttonIndex > number[0].getChoices().size() - 1) return; // cancel
   double selected = number[0].getChoices()[buttonIndex];
   number[0].setValue(selected);
   onelab::server::instance()->set(number[0]);
diff --git a/contrib/mobile/iOS/Onelab/ParametersViewController.mm b/contrib/mobile/iOS/Onelab/ParametersViewController.mm
index c0a295398d..47cc9ae16b 100644
--- a/contrib/mobile/iOS/Onelab/ParametersViewController.mm
+++ b/contrib/mobile/iOS/Onelab/ParametersViewController.mm
@@ -108,13 +108,13 @@
     ParameterNumberCheckbox *param = [[ParameterNumberCheckbox alloc] initWithNumber:p];
     [section addObject:param];
   }
-  else if(p.getStep() == 0) { // text box
-    ParameterNumberTextbox *param = [[ParameterNumberTextbox alloc] initWithNumber:p];
-    [section addObject:param];
-  }
   else if(p.getStep() == 1) { // stepper
     ParameterNumberStepper *param = [[ParameterNumberStepper alloc] initWithNumber:p];
     [section addObject:param];
+  }
+	else if(p.getMin() == p.getMax()) { // text box, since no range
+    ParameterNumberTextbox *param = [[ParameterNumberTextbox alloc] initWithNumber:p];
+    [section addObject:param];
   }
   else {
     ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p];
-- 
GitLab