예제 #1
0
        /**
         * Handle the result of an executed shortcut
         */
        void HandleShortcutResult(ShortcutResult result)
        {
            // shortcut executed successfully
            if (result.bSuccess)
            {
                if (JRunUI.Properties.Settings.Default.History == null)
                {
                    JRunUI.Properties.Settings.Default.History = new System.Collections.Specialized.StringCollection();
                }
                JRunUI.Properties.Settings.Default.History.Remove(result.Shortcut);
                JRunUI.Properties.Settings.Default.History.Insert(0,result.Shortcut);
                Visibility = System.Windows.Visibility.Hidden;
                Close();
            }

            // shortcut was not found
            else if (result.ThrownException == null)
            {
                // do error flash
                var storyboard = FindResource("ErrorAnimation") as Storyboard;
                var anim1 = storyboard.Children[0];
                var anim2 = storyboard.Children[1];
                Storyboard.SetTargetName(anim1, MainBorder.Name);
                Storyboard.SetTargetName(anim2, txtShortcut.Name);
                storyboard.Begin(this);
            }

            // something went wrong while trying to execute the shortcut
            else
            {
                ShowErrorDialog(result.ThrownException);
            }
        }
예제 #2
0
        /**
         * Update auto complete or execute a shortcut when the user maniplates the text box
         */
        void txtShortcut_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                var text = ((TextBox)sender).Text;

                if (!String.IsNullOrEmpty(text))
                {
                    var result = new ShortcutResult();
                    result.Shortcut = text;

                    var worker = new System.ComponentModel.BackgroundWorker();
                    worker.DoWork += (s, args) => ExecuteShortcut(result);
                    worker.RunWorkerCompleted += (s, args) => HandleShortcutResult(result);
                    worker.RunWorkerAsync();
                }

                ((TextBox)sender).Text = "";
                e.Handled = true;
            }
            else if (e.Key == Key.Tab)
            {
                var text = ((TextBox)sender).Text;

                if (!String.IsNullOrEmpty(text))
                {
                    ((TextBox)sender).SelectionLength = 0;
                    ((TextBox)sender).CaretIndex = text.Length;

                    UpdateAutoComplete((TextBox)sender);
                }
            }
        }
예제 #3
0
 /**
  * Asynchronously execute a named shortcut
  */
 void ExecuteShortcut(ShortcutResult result)
 {
     try
     {
         // try a file system reference first
         if (ShortcutExecutor.ExecuteFileSystem(result.Shortcut, ""))
         {
             result.bSuccess = true;
         }
         // if no luck there, try a shortcut
         else
         {
             result.bSuccess = ShortcutExecutor.ExecuteShortcut(InstanceParams().SetShortcut(result.Shortcut));
         }
     }
     catch (Exception ex)
     {
         result.ThrownException = ex;
     }
 }