C2019-025_Ability-to-Toggle-Replace-Words

This commit is contained in:
2025-01-24 10:12:43 -05:00
parent 37626d8f45
commit 71130bd26b
24 changed files with 1598 additions and 887 deletions

View File

@@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
using System.Drawing;
using Volian.Base.Library;
using JR.Utils.GUI.Forms;
//using VEPROMS.colorReplaceWords;
// This was moved from volian.controls.library
namespace VEPROMS.CSLA.Library
@@ -46,6 +47,60 @@ namespace VEPROMS.CSLA.Library
return string.Empty;
}
}
private string ShwRplWords(ItemInfo _MyItemInfo)
{
//if (_Initalizing) return "N";
//_MyItemInfo.
SectionConfig sc = _MyItemInfo.MyConfig as SectionConfig;
if (sc == null) return "N";
return sc.Section_ShwRplWords;
}
private bool ShwRplWdsIndex(ItemInfo _MyItemInfo)
{
StepConfig sc = _MyItemInfo.MyConfig as StepConfig;
int setting = sc.Step_ShwRplWdsIndex;
switch (setting)
{
case 3:
return false;
break;
case 2:
return true;
break;
case 1:
case 0:
//SectionConfig sc2 = _MyItemInfo.ActiveParent.MyConfig as SectionConfig;
SectionConfig sc2 = _MyItemInfo.ActiveSection.MyConfig as SectionConfig;
if (sc2 == null || sc2.Section_ShwRplWords == "Y")
{
return true;
}
else
{
return false;
}
break;
default:
return false;
break;
}
//int setting = sc.Step_ShwRplWdsIndex;
//if (setting == 3) return false;
//if (setting == 2) return true;
//if (setting == 1 || setting == 0)
//{
// SectionConfig sc2 = _MyItemInfo.ActiveParent.MyConfig as SectionConfig;
// if (sc2.Section_ShwRplWords == "Y")
// {
// return true;
// }
// else
// {
// return false;
// }
//}
//return false; // if Step_ShwRplWdsIndex = 0
}
private Item _MyItem;
private string EditText
{
@@ -357,9 +412,37 @@ namespace VEPROMS.CSLA.Library
// But don't do ReplaceWords if the TurnOffReplaceWords format flag is set
if (wordsShouldBeReplaced && !_MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.TurnOffReplaceWords)
{
//string stf = _MyItemInfo.SectionConfig.Section_ShwRplWords;
//ItemInfoList stf = _MyItemInfo.MyPrevious.Sections//SectionConfig.Section_ShwRplWords;
//_MyItemInfo.SectionConfig.Section_ShwRplWords;
//string str = _MyItemInfo.MyConfig.Section_ShwRplWords;
//epMode
int profileDepth1 = ProfileTimer.Push(">>>> DoReplaceWords2");
text = DoReplaceWords2(text);
if (_MyItemInfo.IsSection)
{
string ShwRplWrds = ShwRplWords(_MyItemInfo);
if (ShwRplWrds == "Y")
{
text = DoReplaceWords2(text, epMode);
}
}
if (_MyItemInfo.IsStep)
{
bool ShwRplWrds = ShwRplWdsIndex(_MyItemInfo);
if (ShwRplWrds == true)
{
text = DoReplaceWords2(text, epMode);
}
}
if (_MyItemInfo.IsFolder || _MyItemInfo.IsProcedure)
{
text = DoReplaceWords2(text, epMode);
}
ProfileTimer.Pop(profileDepth1);
}
if (_MyItemInfo != null && ROsShouldBeAdjusted) // B2017-019 - added check for ROsShouldBeAdjusted so that these token are not "cooked" on property pages
@@ -2101,7 +2184,7 @@ namespace VEPROMS.CSLA.Library
return (bool) _ProcessReplaceWords;
}
}
private string DoReplaceWords2(string Text)
private string DoReplaceWords2(string Text, E_EditPrintMode epMode)
{
if(!ProcessReplaceWords) return Text;
// F2021-053: BNPP Alarm - need ability to have super/sub scripts in the text of Alarm Tables (ROs).
@@ -2162,6 +2245,12 @@ namespace VEPROMS.CSLA.Library
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is
//RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase & RegexOptions.Singleline : RegexOptions.None & RegexOptions.Singleline;
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
//if (Volian.Controls.Library.Properties.Settings.Default.cbShwRplWrdsColor)
//{
// replaceWord = $@"\cf2{replaceWord}\cf0";
// // with = $@"\cf2{with}\cf0 ";
//}
// if first or last character in replaceword is a non-word character, for example, ',', ')', or '.',
// don't use the \W, i.e. don't bother to look for a non-word character.
string wordMatchBeg = Regex.IsMatch(replaceWord.Substring(0, 1), @"\W") ? "" : @"(?<=\W|^)";
@@ -2188,7 +2277,7 @@ namespace VEPROMS.CSLA.Library
}
//ProfileTimer.Pop(profileDepth);
//int profileDepth5 = ProfileTimer.Push(">>>> DoReplaceWords2.ReplaceMatches");
Text = myMatches.ReplaceMatches();
Text = myMatches.ReplaceMatches(epMode);
//ProfileTimer.Pop(profileDepth5);
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
return Text;
@@ -2480,7 +2569,8 @@ namespace VEPROMS.CSLA.Library
if (str.Length == index && str == text.Substring(0, str.Length)) return true;
return false;
}
public string ReplaceMatches()
public string ReplaceMatches(E_EditPrintMode epMode)
{
int offset = 0;
string text = _Text;
@@ -2572,6 +2662,11 @@ namespace VEPROMS.CSLA.Library
with = with.Replace(@"\ul ", "");
with = with.Replace(@"\ulnone ", "");
}
//if (Properties.Settings.Default.cbShwRplWrdsColor && !(epMode == E_EditPrintMode.Print))
if (Properties.Settings.Default.cbShwRplWrdsColor && !(epMode == E_EditPrintMode.Print))
{
with = $@"\cf2{with}\cf0 ";
}
text = text.Substring(0, offset + foundMatch.MyMatch.Index) + with + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length);
//offset += foundMatch.MyWord.ReplaceWith.Length - foundMatch.MyMatch.Length;