Наследование: IEntry, INotifyPropertyChanged
Пример #1
0
 public EditEntry(Entry e)
 {
     InitializeComponent();
     _original = e;
     EntryTitle = _original.Title;
     EntryCommand = _original.Command;
     DataContext = this;
 }
Пример #2
0
        private void tbInput_TextChanged(object sender, TextChangedEventArgs e)
        {
            var input = tbInput.Text;
            autoComplete.Clear();

            if (string.IsNullOrWhiteSpace(input))
            {
                return;
            }

            var auto = entries.Where(x => (x.Title + " " + x.Command).MyStartsWith(input)).ToList();

            //Add running windows to autocomplete
            var running = Process.GetProcesses().Where(p => p.MainWindowTitle.Length > 0);
            foreach (var r in running)
            {
                var entry = entries.FirstOrDefault(x => x.Title.Equals(r.ProcessName));
                if (entry != null && (entry.Title + " " + entry.Command + " " + r.MainWindowTitle).MyStartsWith(input))
                {
                    var autoCompleteEntry = new Entry(r.MainWindowTitle, entry.Command, true) {
                        Background = new SolidColorBrush(Color.FromArgb(100, 100, 140, 250))
                    };

                    auto.Add(autoCompleteEntry);
                }
            }

            auto.Reverse();

            foreach (var entry in auto)
            {
                autoComplete.Add(entry);
            }

            lbAutoComplete.SelectedIndex = 0;
        }
Пример #3
0
        private void tbInput_KeyDown(object sender, KeyEventArgs e)
        {
            var input = tbInput.Text;

            if (e.Key == Key.Enter && !string.IsNullOrWhiteSpace(input))
            {
                if (lbAutoComplete.Items.Count > 0)
                {
                    var entry = (Entry)lbAutoComplete.Items[0];
                    Execute(entry);
                }
                else
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        input = ofd.FileName;
                        var entry = new Entry(System.IO.Path.GetFileName(input), input);
                        AddEntry(entry);
                        Execute(entry);
                    }
                }

                tbInput.Clear();
            }
        }
Пример #4
0
 private static void addNewEntry(string title, string cmd)
 {
     var entry = new Entry(title, cmd);
     MainWindow.Instance().AddEntry(entry);
 }
Пример #5
0
 public void Execute(Entry e)
 {
     try
     {
         e.Execute();
         tbInput.Text = string.Empty;
         WindowState = System.Windows.WindowState.Minimized;
     }
     catch (Exception ex)
     {
         var error = string.Format("{0} ({1})", ex.Message, e.Command);
         System.Windows.MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         if (System.Windows.MessageBox.Show("Do you want to delete the entry?", Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             entries.Remove(e);
         }
     }
 }
Пример #6
0
 public void AddEntry(Entry e, bool showError = true)
 {
     var e2 = entries.FirstOrDefault(x => x.Title.Equals(e.Title, StringComparison.CurrentCultureIgnoreCase));
     if (e2 == null)
     {
         entries.Add(e);
     }
     else if (showError)
     {
         StringBuilder sb = new StringBuilder();
         sb.AppendLine("An entry with the same title/command already exists");
         sb.AppendLine("Title = " + e2.Title + ", " + e.Title);
         sb.AppendLine("Command = " + e2.Command + ", " + e.Command);
         System.Windows.MessageBox.Show(sb.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }