private async void editEnvConfig_Click(object sender, RoutedEventArgs e) { QuickCommand qc = this.commandsList.SelectedItem as QuickCommand; EnvEditor envEditor = new EnvEditor(this, dialogSettings, qc); await this.ShowMetroDialogAsync(envEditor); }
private async void edit_Click(object sender, RoutedEventArgs e) { QuickCommand qc = this.commandsList.SelectedItem as QuickCommand; var dialog = new CmdEditor(this, dialogSettings, qc); dialog.AddedNewQuickCommand += Qle_AddedNewQuickCommand; await this.ShowMetroDialogAsync(dialog); }
private bool startProcess(QuickCommand qc, bool asAdmin) { ProcessStartInfo startInfo = new ProcessStartInfo(qc.ExpandedPath, qc.Command); startInfo.UseShellExecute = true; if (asAdmin) { startInfo.Verb = "runas"; } string workingDir = qc.ExpandedWorkDirectory; if (workingDir.Length == 0) { workingDir = FileUtil.getDirectoryOfFile(qc.ExpandedPath); } startInfo.WorkingDirectory = workingDir; if (qc.QuickCommandEnvConfigs != null) { foreach (var o in qc.QuickCommandEnvConfigs) { startInfo.EnvironmentVariables[o.EnvKey] = o.ExpandedEnvValue; } if (qc.QuickCommandEnvConfigs.Count > 0) { startInfo.UseShellExecute = false; } } try { Process.Start(startInfo); Dispatcher.BeginInvoke(new Action(() => { statusLabel.Content = "Started \"" + qc.Alias + "\" at " + DateTime.Now.ToString(); }), DispatcherPriority.Background); return(true); } catch (System.ComponentModel.Win32Exception e) { Trace.TraceError(e.StackTrace); if (e.NativeErrorCode != 1223) // if it is not canceled by the user // see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1000-1299- { Dispatcher.BeginInvoke(new Action(() => { statusLabel.Content = "Started \"" + qc.Alias + "\" failed: \"" + e.Message + "\" at " + DateTime.Now.ToString(); ShowWindowNormal(); DialogUtil.showError(this, e.Message); }), DispatcherPriority.Background); } } return(false); }
private void openWorkingDir_Click(object sender, RoutedEventArgs e) { QuickCommand qc = this.commandsList.SelectedItem as QuickCommand; try { System.Diagnostics.Process.Start("explorer.exe", qc.ExpandedWorkDirectory); } catch (System.ComponentModel.Win32Exception exception) { DialogUtil.showError(this, exception.Message); } }
private async void delete_Click(object sender, RoutedEventArgs e) { QuickCommand qc = this.commandsList.SelectedItem as QuickCommand; MessageDialogResult result = await DialogUtil.ShowYesNo("Delete confirmation", this, "Are you sure to delete the selected quick commands?"); if (result == MessageDialogResult.Affirmative) { dbContext.QuickCommandEnvConfigs.RemoveRange(qc.QuickCommandEnvConfigs); dbContext.QuickCommands.Remove(qc); dbContext.SaveChanges(); quickCommands.Remove(qc); } }
private bool StartProcess(QuickCommand qc, bool asAdmin) { statusLabel.Content = "Starting \"" + qc.Alias + "\""; bool isCtrlKeyPressed = (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control; ThreadPool.QueueUserWorkItem(delegate { startProcess(qc, asAdmin); }); if (!isCtrlKeyPressed) { this.WindowState = System.Windows.WindowState.Minimized; } return(false); }
public CmdEditor(MetroWindow parent, MetroDialogSettings mySettings, QuickCommand command) : base(parent, mySettings) { InitializeComponent(); this.parent = parent; if (command == null) { QCommand = new QuickCommand(true); Title = "Create Quick Command"; } else { QCommand = QuickCommand.Copy(command); Title = "Edit Quick Command"; } DataContext = this; DefaultCMDDropDownMenuItemCommand = new SimpleCommand(o => true, x => { DefaultQuickCommandSelected(x); }); }
public EnvEditor(MetroWindow parent, MetroDialogSettings mySettings, QuickCommand quickCommand) : base(parent, mySettings) { InitializeComponent(); quickCommands.Clear(); quickCommands.CollectionChanged += QuickCommands_CollectionChanged; if (quickCommand.QuickCommandEnvConfigs != null) { foreach (var o in quickCommand.QuickCommandEnvConfigs) { o.BindingEnvs = quickCommands; quickCommands.Add(o); } } this.envGrid.DataContext = this; this.parent = parent; this.quickCommand = quickCommand; }
private void Save_Click(object sender, RoutedEventArgs e) { if (QCommand.Error != null) { DialogUtil.showError(this.parent, QCommand.Error); } else { try { var dbContext = QuickCommandContext.Instance; QuickCommand qc = dbContext.QuickCommands.SingleOrDefault(b => b.UUID == QCommand.UUID); if (qc != null) { qc.Alias = QCommand.Alias; qc.Path = QCommand.Path; qc.Command = QCommand.Command; qc.WorkDirectory = QCommand.WorkDirectory; qc.CustomIcon = QCommand.CustomIcon; dbContext.SaveChanges(); } else { dbContext.QuickCommands.Add(QCommand); dbContext.SaveChanges(); if (AddedNewQuickCommand != null) { AddedNewQuickCommand(QCommand); } } parent.HideMetroDialogAsync(this); } catch (Exception ee) { Trace.TraceError(ee.Message); Trace.TraceError(ee.StackTrace); DialogUtil.showError(parent, ee.Message); } } }
private async void Refresh_Click(object sender, RoutedEventArgs e) { QuickCommand qc = this.commandsList.SelectedItem as QuickCommand; await dbContext.Entry(qc).ReloadAsync(); }
// for details view only private void startAdmin_Click(object sender, RoutedEventArgs e) { QuickCommand qc = ((System.Windows.Controls.Button)sender).Tag as QuickCommand; StartProcess(qc, true); }