void PickInvokeTimerTick(object sender, EventArgs e) { InvokeCommand invokeCommand = null; while (invokesToProcess.TryDequeue(out invokeCommand)) { performInvoke(invokeCommand); } }
void CommandsComboBoxSelectedIndexChanged(object sender, EventArgs e) { if (commandsComboBox.SelectedIndex != -1) { if (commandsDict.ContainsKey(commandsComboBox.Text)) { InvokeCommand invoke = commandsDict[commandsComboBox.Text]; string tooltip = (invoke.hotkey == null) ? invoke.description : invoke.description + "\rHotkey: " + invoke.hotkey; commandToolTips.SetToolTip(LaunchCustomCommandButton, tooltip); } } }
void LaunchCustomCommandButtonClick(object sender, EventArgs e) { int selectedIndex = commandsComboBox.SelectedIndex; if (selectedIndex != -1) { string prevcommandstr = commandsComboBox.Text; string prevpropertystr = PropertiesComboBox.Text; string type = invokerSettings.environmentSettings.ContainsKey(currentEnvSettings.type) ? currentEnvSettings.type : "default"; InvokeCommand invoke = invokerSettings.environmentSettings[type].invokes[selectedIndex]; invokesToProcess.Enqueue(invoke); comoboBoxRefreshed(commandsComboBox, prevcommandstr); comoboBoxRefreshed(PropertiesComboBox, prevpropertystr); } }
void enableInvoke(InvokeCommand invoke, int commandNumber) { commandsComboBox.Items.Add(invoke.name); if ((invoke.hotkey == null) && !string.IsNullOrEmpty(invoke.hotkeyString)) { invoke.hotkey = new HotKey(invoke.hotkeyString); } if ((invoke.hotkey != null) && string.IsNullOrEmpty(invoke.hotkeyString)) { invoke.hotkeyString = invoke.hotkey.ToString(); } if (invoke.enableButton) { Button commandButton = new Button(); commandsFlowLayoutPanel.Controls.Add(commandButton); //commandButton.Location = new System.Drawing.Point(3, 3); commandButton.Name = "commandButton" + (commandNumber + 1); commandButton.AutoSize = true; commandButton.TabIndex = commandNumber + 1; commandButton.Text = invoke.name; commandButton.UseVisualStyleBackColor = true; commandButton.Click += LaunchCustomCommandUIButtonClick; commandButtons.Add(commandButton); string tooltip = (invoke.hotkey == null) ? invoke.description : invoke.description + "\rHotkey: " + invoke.hotkey; commandToolTips.SetToolTip(commandButton, tooltip); commandButtonInvokeDict.Add(commandButton, invoke); } commandsDict.Add(invoke.name, invoke); }
void performInvoke(InvokeCommand invoke) { lock (invokeLock) { foreach (ExecDetails command in invoke.commands) { switch (command.type) { case "run": Process process = ((command.args != null) && !string.IsNullOrEmpty(command.args[0])) ? Process.Start(replaceProperties(command.path), replaceProperties(string.Join(" ", command.args))) : Process.Start(replaceProperties(command.path)); if (command.waitForExit) { waitForProcessExit(process); } break; case "exec": process = new Process(); process.StartInfo.UseShellExecute = command.shell; process.StartInfo.FileName = replaceProperties(command.path); process.StartInfo.Arguments = replaceProperties(string.Join(" ", command.args)); process.StartInfo.CreateNoWindow = command.hideWindow; if (!string.IsNullOrEmpty(command.workingDir) && Directory.Exists(command.workingDir)) { process.StartInfo.WorkingDirectory = command.workingDir; } if (command.saveOutput) { process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.UseShellExecute = false; } foreach (KeyValuePair <string, string> kvp in command.env) { process.StartInfo.EnvironmentVariables.Add(replaceProperties(kvp.Key), replaceProperties(kvp.Value)); } process.Start(); if (command.saveOutput) { string output = process.StandardOutput.ReadToEnd(); string err = process.StandardError.ReadToEnd(); waitForProcessExit(process); if (string.IsNullOrEmpty(command.outputProperty)) { command.outputProperty = "exec.out"; } execProperties[replaceProperties(command.outputProperty)] = output + err; } else { if (command.waitForExit) { waitForProcessExit(process); } } break; case "reloadSettings": reloadSettings(); break; case "OpenSettingsFile": OpenSettingsFile(); break; case "OpenEnvSettingsFile": OpenEnvSettingsFile(); break; case "toggleShowInvokerWindow": toggleShowWindow(); break; case "toggleClipBoardCapture": ToggleClipBoardCapture(); break; case "copyNextToClipBoard": copyNextToClipBoard(); break; case "copyFromClipBoard": copyFromClipBoard(); break; case "clearClipBoard": clearClipBoard(); break; case "exportClipBoard": string directory = (!string.IsNullOrEmpty(command.workingDir) && Directory.Exists(command.workingDir)) ? command.workingDir : InvokerSettingDirectory; exportClipBoard(directory); break; default: MessageBox.Show(replaceProperties(command.comments), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } } }