///<summary>Called on KeyUp from various textBoxes in the program to look for a ?abbrev and attempt to substitute. Substitutes the text if found.</summary> public static string Substitute(string text, QuickPasteType type) { //No need to check RemotingRole; no call to db. int typeIndex = QuickPasteCats.GetDefaultType(type); QuickPasteCat quickPasteCatDefault = QuickPasteCats.GetDeepCopy()[typeIndex]; List <QuickPasteNote> listQuickPasteCats = GetDeepCopy(); for (int i = 0; i < listQuickPasteCats.Count; i++) { if (listQuickPasteCats[i].Abbreviation == "") { continue; } if (listQuickPasteCats[i].QuickPasteCatNum != quickPasteCatDefault.QuickPasteCatNum) { continue; } //We have to replace all $ chars with $$ because Regex.Replace allows "Substitutions" in the replacement parameter. //The replacement parameter specifies the string that is to replace each match in input. replacement can consist of any combination of literal //text and substitutions. For example, the replacement pattern a*${test}b inserts the string "a*" followed by the substring that is matched by //the test capturing group, if any, followed by the string "b". //The * character is not recognized as a metacharacter within a replacement pattern. //See https://msdn.microsoft.com/en-us/library/taz3ak2f(v=vs.110).aspx for more information. string quicknote = listQuickPasteCats[i].Note.Replace("$", "$$"); //Techs were complaining about quick notes replacing text that was pasted into text boxes (e.g. when a URL happens to have ?... that matches a quick note abbr). //The easiest way to deal with this is to not allow the regular expression to replace strings that have a non-whitespace character before or after the abbr. //The regex of '...(?<!\S)...' is utilizing an optional space via a lookbehind and visa versa with '...(?!\S)...' as a lookahead. var pattern = @"(?<spaceBefore>(?<!\S))\?" + Regex.Escape(listQuickPasteCats[i].Abbreviation) + @"(?<spaceAfter>(?!\S))"; var replacePattern = "${spaceBefore}" + (quicknote) + "${spaceAfter}"; text = Regex.Replace(text, pattern, replacePattern, RegexOptions.None); } return(text); }
///<summary>Called from FormQuickPaste and from QuickPasteNotes.Substitute(). Returns the index of the default category for the specified type. If user has entered more than one, only one is returned.</summary> public static int GetDefaultType(QuickPasteType type) { //No need to check RemotingRole; no call to db. if (GetCount() == 0) { return(-1); } if (type == QuickPasteType.None) { return(0); //default to first line } string[] types; List <QuickPasteCat> listQuickPasteCats = GetDeepCopy(); for (int i = 0; i < listQuickPasteCats.Count; i++) { if (listQuickPasteCats[i].DefaultForTypes == "") { types = new string[0]; } else { types = listQuickPasteCats[i].DefaultForTypes.Split(','); } for (int j = 0; j < types.Length; j++) { if (((int)type).ToString() == types[j]) { return(i); } } } return(0); }
///<summary>Called from FormQuickPaste and from QuickPasteNotes.Substitute(). Returns the index of the default category for the specified type. If user has entered more than one, only one is returned.</summary> public static int GetDefaultType(QuickPasteType type) { if (List.Length == 0) { return(-1); } if (type == QuickPasteType.None) { return(0); //default to first line } string[] types; for (int i = 0; i < List.Length; i++) { if (List[i].DefaultForTypes == "") { types = new string[0]; } else { types = List[i].DefaultForTypes.Split(','); } for (int j = 0; j < types.Length; j++) { if (((int)type).ToString() == types[j]) { return(i); } } } return(0); }
///<summary>Returns a list of all categories for a single type. Will return an empty list if no type is selected.</summary> public static List <QuickPasteCat> GetCategoriesForType(QuickPasteType type) { //No need to check RemotingRole; no call to db. List <QuickPasteCat> listQuickCats = GetWhere(x => type.In(x.ListDefaultForTypes)); if (listQuickCats.Count == 0) { QuickPasteCat quickCat = GetDeepCopy().FirstOrDefault(); //First category from db by item order if (quickCat != null) { listQuickCats.Add(quickCat); } } return(listQuickCats); }
///<summary>Called on KeyUp from various textBoxes in the program to look for a ?abbrev and attempt to substitute. Substitutes the text if found.</summary> public static string Substitute(string text, QuickPasteType type) { int typeIndex = QuickPasteCats.GetDefaultType(type); for (int i = 0; i < List.Length; i++) { if (List[i].Abbreviation == "") { continue; } if (List[i].QuickPasteCatNum != QuickPasteCats.List[typeIndex].QuickPasteCatNum) { continue; } text = Regex.Replace(text, @"\?" + List[i].Abbreviation, List[i].Note); } return(text); }
///<summary>Called on KeyUp from various textBoxes in the program to look for a ?abbrev and attempt to substitute. Substitutes the text if found.</summary> public static string Substitute(string text, QuickPasteType type) { //No need to check RemotingRole; no call to db. if (List == null) { RefreshCache(); } int typeIndex = QuickPasteCats.GetDefaultType(type); for (int i = 0; i < List.Length; i++) { if (List[i].Abbreviation == "") { continue; } if (List[i].QuickPasteCatNum != QuickPasteCats.List[typeIndex].QuickPasteCatNum) { continue; } text = Regex.Replace(text, @"\?" + List[i].Abbreviation, List[i].Note); } return(text); }
///<summary>Called from FormQuickPaste and from QuickPasteNotes.Substitute(). Returns the index of the default category for the specified type. If user has entered more than one, only one is returned.</summary> public static int GetDefaultType(QuickPasteType type){ //No need to check RemotingRole; no call to db. if(List.Length==0){ return -1; } if(type==QuickPasteType.None){ return 0;//default to first line } string[] types; for(int i=0;i<List.Length;i++){ if(List[i].DefaultForTypes==""){ types=new string[0]; } else{ types=List[i].DefaultForTypes.Split(','); } for(int j=0;j<types.Length;j++){ if(((int)type).ToString()==types[j]){ return i; } } } return 0; }
///<summary>Called on KeyUp from various textBoxes in the program to look for a ?abbrev and attempt to substitute. Substitutes the text if found.</summary> public static string Substitute(string text,QuickPasteType type){ int typeIndex=QuickPasteCats.GetDefaultType(type); for(int i=0;i<List.Length;i++){ if(List[i].Abbreviation==""){ continue; } if(List[i].QuickPasteCatNum!=QuickPasteCats.List[typeIndex].QuickPasteCatNum){ continue; } text=Regex.Replace(text,@"\?"+List[i].Abbreviation,List[i].Note); } return text; }
///<summary>Called on KeyUp from various textBoxes in the program to look for a ?abbrev and attempt to substitute. Substitutes the text if found.</summary> public static string Substitute(string text,QuickPasteType type){ //No need to check RemotingRole; no call to db. if(List==null) { RefreshCache(); } int typeIndex=QuickPasteCats.GetDefaultType(type); for(int i=0;i<List.Length;i++){ if(List[i].Abbreviation==""){ continue; } if(List[i].QuickPasteCatNum!=QuickPasteCats.List[typeIndex].QuickPasteCatNum){ continue; } text=Regex.Replace(text,@"\?"+List[i].Abbreviation,List[i].Note); } return text; }