internal AutotextTrigger(ActionTriggers triggers, Action <AutotextTriggerArgs> action, string text, TAFlags flags, TAPostfix postfixType, string postfixChars) : base(triggers, action, true) { this.text = text; this.flags = flags; this.postfixType = postfixType; this.postfixChars = postfixChars; if (flags == 0 && postfixType == 0 && postfixChars == null) { _paramsString = text; } else { using (new Util.StringBuilder_(out var b)) { b.Append(text); if (flags != 0) { b.Append(" (").Append(flags.ToString()).Append(')'); } if (postfixType != 0) { b.Append(" postfixType=").Append(postfixType.ToString()); } if (postfixChars != null) { b.Append(" postfixChars=").Append(postfixChars); } _paramsString = b.ToString(); } } //AOutput.Write(this); }
/// <summary> /// Adds an autotext trigger. /// </summary> /// <param name="text">The action runs when the user types this text and a postfix character or key. By default case-insensitive.</param> /// <param name="flags">Options. If omitted or null, uses <see cref="DefaultFlags"/>. Some flags are used by <see cref="AutotextTriggerArgs.Replace"/>.</param> /// <param name="postfixType">Postfix type (character, key, any or none). If omitted or null, uses <see cref="DefaultPostfixType"/>; default - a non-word character or the Ctrl key.</param> /// <param name="postfixChars">Postfix characters used when postfix type is <b>Char</b> or <b>CharOrKey</b> (default). If omitted or null, uses <see cref="DefaultPostfixChars"/>; default - non-word characters.</param> /// <exception cref="ArgumentException"> /// - Text is empty or too long. Can be 1 - 100 characters. /// - Postfix characters contains letters or digits. /// </exception> /// <exception cref="InvalidOperationException">Cannot add triggers after <c>Triggers.Run</c> was called, until it returns.</exception> /// <example>See <see cref="ActionTriggers"/>.</example> public Action <AutotextTriggerArgs> this[string text, TAFlags? flags = null, TAPostfix? postfixType = null, string postfixChars = null] { set { _triggers.ThrowIfRunning_(); int len = text.Lenn(); if (len < 1 || len > 100) { throw new ArgumentException("Text length must be 1 - 100."); } if (text.IndexOf('\n') >= 0) { text = text.RegexReplace(@"\r?\n", "\r"); len = text.Length; } TAFlags fl = flags ?? DefaultFlags; bool matchCase = 0 != (fl & TAFlags.MatchCase); if (!matchCase) { text = text.Lower(); } var t = new AutotextTrigger(_triggers, value, text, fl, postfixType ?? DefaultPostfixType, _CheckPostfixChars(postfixChars) ?? DefaultPostfixChars); //create dictionary key from 1-4 last characters lowercase int k = 0; for (int i = len - 1, j = 0; i >= 0 && j <= 24; i--, j += 8) { var c = text[i]; if (matchCase) { c = char.ToLowerInvariant(c); } k |= (byte)c << j; } //AOutput.Write((uint)k); t.DictAdd(_d, k); _lastAdded = t; } }
internal AutotextTrigger(ActionTriggers triggers, Action <AutotextTriggerArgs> action, string text, TAFlags flags, TAPostfix postfixType, string postfixChars, (string, int) source)