/// <summary>
 /// Display "Invalid Insert Value" message box and set focus to specified control if passed
 /// </summary>
 /// <param name="message"></param>
 /// <param name="ctrl"></param>
 void InvalidValueMessageBox(string message)
 {
     #if ON_OS_MAC
       var messageBox = new MonoMac.AppKit.NSAlert()
       {
     MessageText = Rhino.UI.LOC.STR("Invalid Insert Value"),
     InformativeText = message,
     AlertStyle = MonoMac.AppKit.NSAlertStyle.Informational
       };
       messageBox.AddButton ("OK");
       messageBox.RunModal();
       messageBox.Dispose();
       #endif
       #if ON_OS_WINDOWS
       System.Windows.MessageBox.Show(Window,
                              message,
                              Rhino.UI.LOC.STR("Invalid Insert Value"),
                              System.Windows.MessageBoxButton.OK,
                              System.Windows.MessageBoxImage.Exclamation);
       #endif
 }
        internal bool OkayToClose()
        {
            //
              // Make sure the block name has a value
              //
              if (string.IsNullOrWhiteSpace(blockName))
              {
            InvalidValueMessageBox(Rhino.UI.LOC.STR("Please enter a block name to insert"));
            return false;
              }
              CommandArgs.BlockName = blockName;

              if (ExistingInstanceDefinitions.Length > 0 && CommandArgs.UpdateType == InstanceDefinitionUpdateType.Linked || CommandArgs.UpdateType == InstanceDefinitionUpdateType.LinkedAndEmbedded)
              {
            // Linked or Linked and embedded instance definition and there is currently one more instance definitions that reference this archive
            foreach (var def in ExistingInstanceDefinitions)
            {
              if (CommandArgs.FileNameOptionsMatch(def))
              {
            // This definition has the exact same parameters as the new one so just use it
            CommandArgs.FromInstanceDefinition(def);
            // Done here so bail
            return true;
              }
            }
              }

              CommandArgs.NeedToDisplayOptionsForm = false;

              //
              // Check to see if there is currently a block with this name
              //
              InstanceDefinition found = CommandArgs.FindInstanceDefintion(CommandArgs.BlockName);
              if (found != null)
              {
            // Display overwrite warning message box
            bool? dialogResult = null;
            var msg = string.Format(Rhino.UI.LOC.STR("The \"{0}\" block definition already exists. Do you want to replace it?"), CommandArgs.BlockName);
            var rc = 2;
            #if ON_OS_WINDOWS
            var result = System.Windows.MessageBox.Show(Window,
                                                    msg,
                                                    Rhino.UI.LOC.STR("Redefine Block"),
                                                    System.Windows.MessageBoxButton.YesNoCancel,
                                                    System.Windows.MessageBoxImage.Question);
            // Move this above the MessageBox.Show when it is hooked up on the Mac,
            // leving the above code to make sure it gets replaced with Mac code
            // before continuing.
            if (result == System.Windows.MessageBoxResult.Yes)
              rc = 0;
            else if (result == System.Windows.MessageBoxResult.No)
              rc = 1;
            else
              rc = 2;
            #endif
            #if ON_OS_MAC
            var messageBox = new MonoMac.AppKit.NSAlert()
            {
              MessageText = Rhino.UI.LOC.STR("Overwrite Block Definiton"),
              InformativeText = msg,
              AlertStyle = MonoMac.AppKit.NSAlertStyle.Informational
            };
            messageBox.AddButton("Yes");
            messageBox.AddButton("No");
            messageBox.AddButton("Cancel");
            var result = messageBox.RunModal();
            messageBox.Dispose();
            if (result == (long)MonoMac.AppKit.NSAlertButtonReturn.First)
              rc = 0; // yes
            else if (result == (long)MonoMac.AppKit.NSAlertButtonReturn.Second)
              rc = 1; // no
            else
              rc = 2; // cancel
            #endif
            switch (rc)
            {
              case 1: // No
            dialogResult = false;
            break;
              case 0: // Yes
            dialogResult = true;
            break;
              default: // 2 Cancel
            dialogResult = null;
            break;
            }
            if (dialogResult == false)
              return false; // Cancel the closing operation and return to the options dialog
            else if (dialogResult == true)
              CommandArgs.BlockId = found.Id; // Set the block ID to the block being overwritten
            else
              Window.DialogResult = false; // Cancel and close the options dialog
            Window.DialogResult = dialogResult;
            return true;
              }
              return true;
        }