Esempio n. 1
0
 /// <summary>Easy to use bool getter.</summary>
 /// <param name="prompt">Command prompt.</param>
 /// <param name="acceptNothing">If true, the user can press enter.</param>
 /// <param name="offPrompt">The 'false/off' message.</param>
 /// <param name="onPrompt">The 'true/on' message.</param>
 /// <param name="boolValue">Default bool value set to this and returned here.</param>
 /// <returns>The getter result based on user choice.
 /// <para>Commands.Result.Success - got value.</para>
 /// <para>Commands.Result.Nothing - user pressed enter.</para>
 /// <para>Commands.Result.Cancel - user cancelled value getting.</para>
 /// </returns>
 public static Commands.Result GetBool(string prompt, bool acceptNothing, string offPrompt, string onPrompt, ref bool boolValue)
 {
   Commands.Result result = Commands.Result.Failure;
   using (Rhino.Input.Custom.GetOption get = new Rhino.Input.Custom.GetOption())
   {
     get.SetCommandPrompt(prompt);
     get.AcceptNothing(acceptNothing);
     if (acceptNothing)
       get.SetDefaultString(boolValue ? onPrompt : offPrompt);
     int onValue = get.AddOption(onPrompt);
     int offValue = get.AddOption(offPrompt);
     get.Get();
     result = get.CommandResult();
     if (result == Commands.Result.Success && get.Result() == GetResult.Option)
     {
       Rhino.Input.Custom.CommandLineOption option = get.Option();
       if (null != option)
       {
         if (option.Index == onValue)
           boolValue = true;
         else if (option.Index == offValue)
           boolValue = false;
       }
     }
   }
   return result;
 }