private async Task ProcessDialog() { var result = await _owner.Dispatcher.InvokeAsync(() => MessageBox.Show(_owner, Content, Title, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No)); ActionComplete?.Invoke(this, new DialogResultEventArgs(result.ToString(), result == MessageBoxResult.Yes || result == MessageBoxResult.OK)); }
private static void HandleHotkeyF9() { if (Settings.Mode == 5 || Settings.Mode == 4) { ActionComplete?.Invoke(MyActions.Paste2, "F9"); } }
private static void HandleHotkeyShiftF12() { if (Settings.Mode == 5) { ActionComplete?.Invoke(MyActions.Paste2, "{Shift}F12"); } }
private static void PastePressed() { if (Program.MyIndex != Program.MyList.Count - 1 || !Program.EndOfListPasted) { Program.EndOfListPasted = Program.MyIndex == Program.MyList.Count - 1; List <string> myList = Program.MyList; string selectedText = ""; try { selectedText = myList[Program.MyIndex]; PasteString(selectedText); Program.MyIndex++; if (Program.MyIndex > myList.Count) { Program.MyIndex = myList.Count; } } catch { } ActionComplete?.Invoke(MyActions.Paste, selectedText); } }
// Complete MUST be called when your action is complete or else the next event won't // happen in the scheduler. Even if there is NO time involved in running your event, you should // still call Complete() public void Complete() { if (IsRunning) { IsRunning = false; ActionComplete?.Invoke(this, EventArgs.Empty); } }
protected virtual void OnActionComplete(Exception ex = null) { if (ActionComplete != null) { ActionComplete.Invoke(this, new ActionCompleteEventArgs() { Exception = ex }); } }
private static void HandleHotkeyF8() { if (Settings.Mode == 2 || Settings.Mode == 5 || Settings.Mode == 4) { ActionComplete?.Invoke(MyActions.Paste2, "F8"); } else if (Settings.Mode == 3) { ActionComplete?.Invoke(MyActions.Run, "F8"); } }
private static void HandleHotkeyF3() { if (Settings.Mode == 1 || Settings.Mode == 2 || Settings.Mode == 3 || Settings.Mode == 4) { EnterPressed(); } else if (Settings.Mode == 5) { ActionComplete?.Invoke(MyActions.Paste2, "F3"); } }
private static void CopyPressed() { int newDataCount = 0; List <string> myList = Program.MyList; newDataCount = myList.Count; try { List <string> data; string temp = Clipboard.GetText(); Clipboard.Clear(); Task.Delay(50).Wait(); SendCTRLC(); Task.Delay(100).Wait(); data = new List <string>(Clipboard.GetText().Split(new string[4] { "\r\n", "\r", "\n", "\t" }, StringSplitOptions.None)); data.RemoveAll(x => x?.Length == 0); if (data.Count > 0) { foreach (string s in data) { myList.Add(s); } if (Settings.SortList) { myList.Sort(); } if (Settings.UniqueList) { myList = myList.Distinct().ToList(); } } Program.MyList = myList; Clipboard.SetText(temp); Program.MyIndex = 0; } catch { // Ignore } newDataCount = newDataCount == 0 ? myList.Count : newDataCount - myList.Count; ActionComplete?.Invoke(MyActions.Copy, newDataCount); }
private void ServiceThread() { var endpoint = new IPEndPoint(IPAddress.Any, 0); var checklist = new List <Socket>(); udp.Client.Blocking = false; while (running) { checklist.Add(udp.Client); Socket.Select(checklist, null, null, 1000000); // 1 sec if (checklist.Count == 0) { continue; } var packet = Encoding.UTF8.GetString(udp.Receive(ref endpoint)); if (!packet.StartsWith("quack!")) { continue; } var lines = new List <string>(); foreach (var x in packet.Split('\n')) { if (x.Trim().Length > 0) { lines.Add(x); } } var cmd = lines[0].Split('!')[1]; if (cmd == "packages-changed") { var dist = lines[1].Split('/')[1]; var pkgs = new List <Tuple <string, uint?, string> >(); for (int i = 2; i < lines.Count; i++) { var s = lines[i].Split(':'); pkgs.Add(new Tuple <string, uint?, string>(s[0], Convert.ToUInt32(s[1]), null)); } PackagesChanged?.Invoke(this, new ServiceMessageEventArgs(packet, dist, pkgs)); } else if (cmd == "packages-available") { string distro = null; var pkgs = new List <Tuple <string, uint?, string> >(); for (int i = 1; i < lines.Count; i++) { if (lines[i].StartsWith("distro/")) { distro = lines[i].Split('/')[1]; continue; } var s = lines[i].Split(':'); uint? rev = null; string group = null; if (s[1] != "virtual") { rev = Convert.ToUInt32(s[1]); } if (s.Length > 2 && s[2].Length > 0) { group = s[2]; } pkgs.Add(new Tuple <string, uint?, string>(s[0], rev, group)); } AvailablePackagesAccepted?.Invoke(this, new ServiceMessageEventArgs(packet, distro, pkgs)); } else if (cmd.StartsWith("dists-")) { var dists = new List <string>(); for (int i = 1; i < lines.Count; i++) { dists.Add(lines[i]); } var e = new ServiceMessageEventArgs(packet, dists); if (cmd == "dists-changed") { DistributionsChanged?.Invoke(this, e); } else { AvailableDistributionsAccepted?.Invoke(this, e); } } else if (cmd == "text") { string text = ""; for (int i = 1; i < lines.Count; i++) { text += lines[i] + "\n"; } if (text.Length > 0) { text = text.Remove(text.Length - 1); TextAccepted?.Invoke(this, new ServiceMessageEventArgs(packet, text)); } } else if (cmd == "wd") { WorkingDirectory = lines[1]; } else if (cmd == "index-changed") { IndexChanged?.Invoke(this, new ServiceMessageEventArgs(packet)); } else if (cmd == "action-update") { ActionProgressUpdated?.Invoke(this, new ServiceMessageEventArgs(packet, lines[1], Convert.ToInt32(lines[2]), Convert.ToInt32(lines[3]))); } else if (cmd == "action-complete") { ActionComplete?.Invoke(this, new ServiceMessageEventArgs(packet, lines[1], 0, 0)); } else if (cmd == "sources-changed") { List <string> sources = new List <string>(); for (int x = 1; x < lines.Count; x++) { sources.Add(lines[x]); } SourcesChanged?.Invoke(this, new ServiceMessageEventArgs(packet, null, sources)); } } udp.Close(); }
public static void HandleFileOpen(string text = null) { int newDataCount = 0; List <string> myList; if (string.IsNullOrWhiteSpace(text)) { myList = Program.MyList; newDataCount = myList.Count; } else { myList = new List <string>(); } try { List <string> data; string temp = Clipboard.GetText(); if (string.IsNullOrWhiteSpace(text)) { Clipboard.Clear(); SendCTRLC(); data = new List <string>(Clipboard.GetText().Split(new string[4] { "\r\n", "\r", "\n", "\t" }, StringSplitOptions.None)); } else { data = new List <string>(text.Split(new string[4] { "\r\n", "\r", "\n", "\t" }, StringSplitOptions.None)); } data.RemoveAll(x => x?.Length == 0); if (data.Count > 0) { foreach (string s in data) { myList.Add(Settings.TrimWS ? s.Trim() : s); } if (Settings.SortList) { myList.Sort(); } if (Settings.UniqueList) { myList = myList.Distinct().ToList(); } } Program.MyList = myList; Clipboard.SetText(temp); Program.MyIndex = 0; } catch { } newDataCount -= myList.Count; ActionComplete?.Invoke(MyActions.Copy, newDataCount); }
private static void HandleHotkeyEscape() { ActionComplete?.Invoke(MyActions.Esc); }
private static void EnterPressed() { Program.SendKeyComm.SendKeyPress("{Enter}"); ActionComplete?.Invoke(MyActions.Enter); }