public void SetNewAbbreviation(string shortForm, string fullForm, string genderForm, string pluralForm, string genderPluralForm)
 {
     DataContext = _currentVm = new AddSimpleAbbreviationViewModel(_repositories, shortForm, fullForm, genderForm, pluralForm, genderPluralForm);
     if (!string.IsNullOrEmpty(fullForm))
     {
         MainButton.Focus();
     }
 }
        private void MainTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(MainTextBox.Text))
                    {
                        this.start    = this.end = DateTime.Now;
                        this.notified = true;

                        Settings.Default.LastTimeSpan = TimeSpan.Zero;

                        MainTextBox.Template = (ControlTemplate)Resources["ValidTextBoxTemplate"];
                        MainButton.Focus();
                        return;
                    }

                    object o = FromString(MainTextBox.Text);

                    if (o is DateTime)
                    {
                        start    = DateTime.Now;
                        end      = (DateTime)o;
                        notified = false;

                        Settings.Default.LastTimeSpan = TimeSpan.Zero;

                        MainTextBox.Template = (ControlTemplate)Resources["ValidTextBoxTemplate"];
                        MainButton.Focus();
                    }
                    else if (o is TimeSpan)
                    {
                        TimeSpan ts = (TimeSpan)o;

                        start    = DateTime.Now;
                        end      = start.Add(ts);
                        notified = false;

                        Settings.Default.LastTimeSpan = ts;

                        MainTextBox.Template = (ControlTemplate)Resources["ValidTextBoxTemplate"];
                        MainButton.Focus();
                    }
                }
                catch (Exception)
                {
                    MainTextBox.Template = (ControlTemplate)Resources["InvalidTextBoxTemplate"];
                }
            }
            else if (e.Key == Key.Escape)
            {
                MainTextBox.Template = (ControlTemplate)Resources["ValidTextBoxTemplate"];
                MainButton.Focus();
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            try
            {
                string exePath   = Assembly.GetExecutingAssembly().Location;
                string exeDir    = new FileInfo(exePath).DirectoryName;
                string soundsDir = System.IO.Path.Combine(exeDir, "Sounds");
                foreach (string soundFilePath in Directory.GetFiles(soundsDir, "*.wav"))
                {
                    MenuItem soundMenuItem = new MenuItem();
                    soundMenuItem.Header      = System.IO.Path.GetFileNameWithoutExtension(soundFilePath);
                    soundMenuItem.Tag         = System.IO.Path.GetFileName(soundFilePath);
                    soundMenuItem.IsCheckable = true;
                    soundMenuItem.Click      += new RoutedEventHandler(SoundMenuItem_Click);

                    MainContextMenu.Items.Insert(MainContextMenu.Items.Count - 2, soundMenuItem);
                }
            }
            catch (Exception)
            {
            }

            UpdateSoundMenuItems();

            AlwaysOnTopMenuItem.IsChecked          = Settings.Default.AlwaysOnTop;
            ScaleInterfaceMenuItem.IsChecked       = Settings.Default.ScaleInterface;
            LoopNotificationMenuItem.IsChecked     = Settings.Default.LoopNotification;
            LoopTimerMenuItem.IsChecked            = Settings.Default.LoopTimer;
            CloseOnFinishMenuItem.IsChecked        = Settings.Default.CloseOnFinish;
            FlashOnFinishMenuItem.IsChecked        = Settings.Default.FlashOnFinish;
            PopupOnFinishMenuItem.IsChecked        = Settings.Default.PopupOnFinish;
            RememberTimerOnCloseMenuItem.IsChecked = Settings.Default.RememberTimerOnClose;
            ShowTimerInTrayMenuItem.IsChecked      = Settings.Default.ShowTimerInTray;

            Topmost = Settings.Default.AlwaysOnTop;

            if (Settings.Default.LoopTimer)
            {
                Settings.Default.LoopNotification  = false;
                LoopNotificationMenuItem.IsChecked = false;

                Settings.Default.CloseOnFinish  = false;
                CloseOnFinishMenuItem.IsChecked = false;
            }

            if (Settings.Default.CloseOnFinish)
            {
                Settings.Default.LoopNotification  = false;
                LoopNotificationMenuItem.IsChecked = false;

                Settings.Default.LoopTimer  = false;
                LoopTimerMenuItem.IsChecked = false;
            }

            if (Settings.Default.WindowSettingsSaved)
            {
                try
                {
                    Height      = Settings.Default.WindowHeight;
                    Width       = Settings.Default.WindowWidth;
                    Left        = Settings.Default.WindowLeft;
                    Top         = Settings.Default.WindowTop;
                    WindowState = Settings.Default.WindowState;
                }
                catch (Exception)
                {
                }
            }

            string args = (string)Application.Current.Properties["Args"];

            if (!string.IsNullOrEmpty(args))
            {
                try
                {
                    if (Regex.IsMatch(args, "(^|\\s+)-startMinimized($|\\s+)", RegexOptions.IgnoreCase))
                    {
                        args = Regex.Replace(args, "(^|\\s+)-startMinimized($|\\s+)", string.Empty, RegexOptions.IgnoreCase);
                        if (Settings.Default.ShowTimerInTray)
                        {
                            Hide();
                        }
                        else
                        {
                            WindowState = System.Windows.WindowState.Minimized;
                        }
                    }

                    if (Regex.IsMatch(args, "(^|\\s+)-closeWhenDone($|\\s+)", RegexOptions.IgnoreCase))
                    {
                        args = Regex.Replace(args, "(^|\\s+)-closeWhenDone($|\\s+)", string.Empty, RegexOptions.IgnoreCase);
                        closeOnFinishThisTime = true;
                    }

                    object o = FromString(args);

                    if (o is DateTime)
                    {
                        start    = DateTime.Now;
                        end      = (DateTime)o;
                        notified = false;

                        Settings.Default.LastTimeSpan = TimeSpan.Zero;

                        MainTextBox.Template = (ControlTemplate)Resources["ValidTextBoxTemplate"];
                        MainButton.Focus();
                    }
                    else if (o is TimeSpan)
                    {
                        TimeSpan ts = (TimeSpan)o;

                        start    = DateTime.Now;
                        end      = start.Add(ts);
                        notified = false;

                        Settings.Default.LastTimeSpan = ts;

                        MainTextBox.Template = (ControlTemplate)Resources["ValidTextBoxTemplate"];
                        MainButton.Focus();
                    }

                    StartTimer();
                }
                catch (Exception)
                {
                    MainTextBox.Template = (ControlTemplate)Resources["InvalidTextBoxTemplate"];
                }
            }
            else if (Settings.Default.RememberTimerOnClose && Settings.Default.TimerRunning && Settings.Default.CurrentStart != DateTime.MinValue && Settings.Default.CurrentEnd != DateTime.MinValue && DateTime.Now > Settings.Default.CurrentStart && DateTime.Now < Settings.Default.CurrentEnd)
            {
                start    = Settings.Default.CurrentStart;
                end      = Settings.Default.CurrentEnd;
                notified = false;

                MainTextBox.Template = (ControlTemplate)Resources["ValidTextBoxTemplate"];
                MainButton.Focus();

                StartTimer();
            }

            interopHelper = new WindowInteropHelper(this);

            UpdateNotifyIcon();
        }