private void editIntermissionClockText_GotMouseCapture(object sender, RoutedEventArgs e)
 {
     try
     {
         _currentTextBoxSelected = _TextBoxEnum.IntermissionTime;
         _currentCursorPosition = ((TextBox)sender).CaretIndex;
         Console.WriteLine(_currentCursorPosition);
     }
     catch (Exception exception)
     {
         ErrorViewModel.Save(exception, GetType(), additionalInformation: Logger.Instance.getLoggedMessages());
     }
 }
        private void editIntermissionClockText_GotFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                ClockEditWarning.PlacementTarget = editIntermissionClockText;
                ClockEditWarning.IsOpen = true;

                _currentTextBoxSelected = _TextBoxEnum.IntermissionTime;
                _currentCursorPosition = ((TextBox)sender).CaretIndex;
                Console.WriteLine(_currentCursorPosition);
            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, GetType(), additionalInformation: Logger.Instance.getLoggedMessages());
            }
        }
        /// <summary>
        /// the edit text box for period clock to replace the character in the box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void editPeriodClockText_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Back || e.Key == Key.Delete)
                {
                    e.Handled = true;
                    return;
                }
                chooseCaretIndexPosition(e, editPeriodClockText);
                _currentTextBoxSelected = _TextBoxEnum.PeriodTime;

                if (IsEditTextKey(e))
                {
                    string text = string.Empty;
                    Logger.Instance.logMessage("textbox Length:" + editPeriodClockText.Text, LoggerEnum.message);
                    if (editPeriodClockText.Text.Length > 0 && _currentCursorPosition <= editPeriodClockText.Text.Length)
                        text = editPeriodClockText.Text.Remove(_currentCursorPosition - 1, 1).Insert(_currentCursorPosition - 1, getKeyString(e.Key));

                    if (Clocks.CLOCK_CHECK.IsMatch(text) && GameViewModel.Instance.IsInEditMode)
                    {
                        EditModeModel mode = new EditModeModel();
                        mode.EditModeType = EditModeEnum.jamClockChanged;
                        mode.additionalInformation = Clocks.CLOCK_CHECK.Match(text).Value;
                        GameViewModel.Instance.EditModeItems.Add(mode);
                        GameViewModel.Instance.PeriodClock.changeSecondsOfClock(Convert.ToInt32(Clocks.convertTimeDisplayToSeconds(Clocks.CLOCK_CHECK.Match(text).Value)));
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, GetType(), additionalInformation: _currentCursorPosition + ":" + e.Key + ":" + editPeriodClockText.Text + ":" + Logger.Instance.getLoggedMessages());
            }

            e.Handled = true;
        }
        private void editIntermissionClockText_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {

                ClockEditWarning.IsOpen = false;

                if (_currentTextBoxSelected == _TextBoxEnum.IntermissionTime)
                    _currentTextBoxSelected = _TextBoxEnum.None;
            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, GetType(), additionalInformation: Logger.Instance.getLoggedMessages());
            }
        }
        private void editJamClockText_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Back || e.Key == Key.Delete)
                {
                    e.Handled = true;
                    return;
                }

                //positions the cursor
                chooseCaretIndexPosition(e, editJamClockText);
                _currentTextBoxSelected = _TextBoxEnum.JamTime;

                if (IsEditTextKey(e))
                {
                    string text = "";
                    //check length bedcause of this error
                    //Index and count must refer to a location within the string. Parameter name: count
                    Logger.Instance.logMessage("textbox Length:" + editJamClockText.Text, LoggerEnum.message);
                    if (editJamClockText.Text.Length > 0 && _currentCursorPosition <= editJamClockText.Text.Length)
                        text = editJamClockText.Text.Remove(_currentCursorPosition - 1, 1).Insert(_currentCursorPosition - 1, getKeyString(e.Key));

                    if (Clocks.CLOCK_CHECK.IsMatch(text) && GameViewModel.Instance.IsInEditMode)
                    {
                        EditModeModel mode = new EditModeModel();
                        mode.EditModeType = EditModeEnum.jamClockChanged;
                        mode.additionalInformation = Clocks.CLOCK_CHECK.Match(text).Value;
                        GameViewModel.Instance.EditModeItems.Add(mode);
                        GameViewModel.Instance.CurrentJam.JamClock.changeSecondsOfClock(Convert.ToInt32(Clocks.convertTimeDisplayToSeconds(Clocks.CLOCK_CHECK.Match(text).Value)));
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorViewModel.Save(exception, GetType(), additionalInformation: Logger.Instance.getLoggedMessages());
            }

            e.Handled = true;
        }