private void WriteReplacements(hotstring hs) { try { if (hs.replacements == null || hs.replacements.Length == 0) { return; } foreach (var r in hs.replacements) { if (r is inputFixedList) { this.WriteReplacementInputFixedList(r as inputFixedList); } else if (r is inputReplacement) { this.WriteReplacementInputReplacement(r as inputReplacement); } } } catch (Exception) { if (this.ExitReason == ExitCodeEnum.NotSet) { this.ExitReason = ExitCodeEnum.HsWriteReplacements; } throw; } }
private void WriteHotstringSnippCode(hotstring hs) { try { if (string.IsNullOrEmpty(hs.code)) { return; } string strFileName = hs.UniqueName + AppCommon.Instance.DefaultSnippitExt; w.Write(@"varCode"); w.Write(" := GetSnippitInlineText(\""); w.Write(strFileName); w.WriteLine("\")"); w.Write("if (MfString.IsNullOrEmpty("); w.Write("varCode"); w.WriteLine("))"); w.WriteLine(bo); w.Indent++; w.WriteLine(@"return"); w.Indent--; w.WriteLine(bc); } catch (Exception) { if (this.ExitReason == ExitCodeEnum.NotSet) { this.ExitReason = ExitCodeEnum.HsWriteHotstrinPasteCode; } throw; } }
/// <summary> /// Writes Send, SendInput, SendPlay or SendEvent followed by a space /// </summary> /// <param name="hs">The current hotstring</param> private void WriteSendKeyWord(hotstring hs) { switch (hs.Options.SendMethod) { case Library.AHKSnipit.AHKSnipitLib.Enums.HotStringSendEnum.SendInput: w.Write(@"SendInput "); break; case Library.AHKSnipit.AHKSnipitLib.Enums.HotStringSendEnum.SendPlay: w.Write(@"SendPlay "); break; case Library.AHKSnipit.AHKSnipitLib.Enums.HotStringSendEnum.SendEvent: w.Write(@"SendEvent "); break; case Library.AHKSnipit.AHKSnipitLib.Enums.HotStringSendEnum.None: case Library.AHKSnipit.AHKSnipitLib.Enums.HotStringSendEnum.Send: default: w.Write(@"Send "); break; } }
private void WriteHotstringPaste(hotstring hs) { try { if (this.HotstringSet.Contains(hs.trigger) == true) { // hotstring has already been used, most likely in another plugin., will continue with little notice w.WriteLine(); w.Write("; Hotstring '"); w.Write(hs.trigger); w.WriteLine("' was used previously and can not be used again"); w.WriteLine(); return; } this.HotstringSet.Add(hs.trigger); w.Write(":"); w.Write(hs.Options.ToAutoHotkeyString()); w.Write(":"); w.Write(hs.trigger); w.WriteLine("::"); w.WriteLine(bo); w.Indent++; w.WriteLine(@"try"); w.WriteLine(bo); w.Indent++; this.WriteHotstringSnippCode(hs); this.WriteReplacements(hs); w.Write("varTabify := "); w.WriteLine(hs.tabify.ToString().ToLower()); w.Write("varForceClear := "); w.WriteLine(hs.forceclear.ToString().ToLower()); w.Write("PasteSnipText(varCode, \""); w.Write(hs.trigger); w.Write("\","); w.Write("varTabify, "); w.WriteLine("varForceClear)"); if (string.IsNullOrEmpty(hs.sendkeys) == false) { w.WriteLine(@"Sleep, 200"); w.Write(@"send, "); w.WriteLine(hs.sendkeys); } w.WriteLine("return"); w.Indent--; w.WriteLine(bc); w.WriteLine(@"catch e"); w.WriteLine(bo); w.Indent++; w.WriteLine(@"DisplayError(e)"); w.Indent--; w.WriteLine(bc); w.WriteLine("return"); w.Indent--; w.WriteLine(bc); } catch (Exception) { throw; } }
private void WriteHotstringInline(hotstring hs) { try { if (this.HotstringSet.Contains(hs.trigger) == true) { // hotstring has already been used, most likely in another plugin., will continue with little notice w.WriteLine(); w.Write("; Hotstring '"); w.Write(hs.trigger); w.WriteLine("' was used previously and can not be used again"); w.WriteLine(); return; } this.HotstringSet.Add(hs.trigger); bool WriteSingleLine = true; WriteSingleLine &= string.IsNullOrEmpty(hs.sendkeys); WriteSingleLine &= (hs.replacements == null || hs.replacements.Length == 0); string sCode = hs.code.CleanNewLine().Trim(); WriteSingleLine &= sCode.IndexOf(Environment.NewLine) == -1; if (WriteSingleLine == true) { w.Write(":"); w.Write(hs.Options.ToAutoHotkeyString()); w.Write(":"); w.Write(hs.trigger); w.Write("::"); w.WriteLine(sCode); return; } w.Write(":"); var opt = hs.Options; if (opt.HasKey[HotStringOptionsEnum.CaseSensitive.ToString()] == true) { w.Write(HotStringOptionsEnum.CaseSensitive.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.OmitEndChar.ToString()] == true) { w.Write(HotStringOptionsEnum.OmitEndChar.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.TriggerInside.ToString()] == true) { w.Write(HotStringOptionsEnum.TriggerInside.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.AutomaticBackSpaceOff.ToString()] == true) { w.Write(HotStringOptionsEnum.AutomaticBackSpaceOff.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.ResetRecognizer.ToString()] == true) { w.Write(HotStringOptionsEnum.ResetRecognizer.GetMapValue()); } w.Write(":"); w.Write(hs.trigger); w.WriteLine("::"); w.WriteLine(bo); w.Indent++; this.WriteHotstringSnippCode(hs); this.WriteReplacements(hs); this.WriteSendKeyWord(hs); w.Write("%"); w.Write(@"varCode"); w.WriteLine("%"); if (string.IsNullOrEmpty(hs.sendkeys) == false) { this.WriteSendKeyWord(hs); w.WriteLine(hs.sendkeys); } w.WriteLine(@"return"); w.Indent--; w.WriteLine(bc); } catch (Exception) { throw; } }
private void WriteHotstringCode(hotstring hs) { try { if (this.HotstringSet.Contains(hs.trigger) == true) { // hotstring has already been used, most likely in another plugin., will continue with little notice w.WriteLine(); w.Write("; Hotstring '"); w.Write(hs.trigger); w.WriteLine("' was used previously and can not be used again"); w.WriteLine(); return; } this.HotstringSet.Add(hs.trigger); w.Write(":"); // w.Write(hs.Options.ToAutoHotkeyString()); var opt = hs.Options; if (opt.HasKey[HotStringOptionsEnum.CaseSensitive.ToString()] == true) { w.Write(HotStringOptionsEnum.CaseSensitive.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.OmitEndChar.ToString()] == true) { w.Write(HotStringOptionsEnum.OmitEndChar.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.TriggerInside.ToString()] == true) { w.Write(HotStringOptionsEnum.TriggerInside.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.AutomaticBackSpaceOff.ToString()] == true) { w.Write(HotStringOptionsEnum.AutomaticBackSpaceOff.GetMapValue()); } if (opt.HasKey[HotStringOptionsEnum.ResetRecognizer.ToString()] == true) { w.Write(HotStringOptionsEnum.ResetRecognizer.GetMapValue()); } w.Write(":"); w.Write(hs.trigger); w.WriteLine("::"); w.WriteLine(bo); w.Indent++; // string code = hs.code.CleanNewLine(); // w.WriteLine(code); string aLine; StringReader strReader = new StringReader(hs.code); while (true) { aLine = strReader.ReadLine(); if (aLine != null) { w.WriteLine(aLine); } else { break; } } strReader = null; w.WriteLine("return"); w.Indent--; w.Write(bc); w.WriteLine(); } catch (Exception) { if (this.ExitReason == ExitCodeEnum.NoError || this.ExitReason == ExitCodeEnum.NotSet) { this.ExitReason = ExitCodeEnum.HsWriteHotstringCode; } throw; } }