This commit is contained in:
parent
16c18eef17
commit
509b79481a
@ -1136,7 +1136,7 @@ namespace Volian.Controls.Library
|
||||
// to name button use unicode rather than desc, desc may have spaces or odd chars
|
||||
btnCM.Name = "btnCM" + sym.Unicode.ToString();
|
||||
btnCM.Tooltip = sym.Desc;
|
||||
btnCM.Tag = string.Format(@"\u{0}", sym.Unicode);
|
||||
btnCM.Tag = string.Format(@"{0}", sym.Unicode);
|
||||
btnCM.FontBold = true;
|
||||
btnCM.Click += new System.EventHandler(btnSym_Click);
|
||||
galSymbols.SubItems.Add(btnCM);
|
||||
|
@ -189,6 +189,7 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
else
|
||||
{
|
||||
_MyStepTypeInd.Clear();
|
||||
foreach (StepDataRetval sdr in sdl)
|
||||
{
|
||||
listBoxStepTypes.Items.Add(sdr.Name);
|
||||
|
@ -33,24 +33,24 @@ namespace VEPROMS.CSLA.Library
|
||||
get { return _textFont; }
|
||||
set { _textFont = value; }
|
||||
}
|
||||
public string StartText;
|
||||
public string OriginalText; // compare for save to see if change.
|
||||
public string OriginalConfigText;
|
||||
private FormatInfo _MyFormat;
|
||||
#endregion
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// DisplayText constructor:
|
||||
/// Creates a DisplayText object that converts the database text into a list of
|
||||
/// displayTextElement elements.
|
||||
/// Creates a DisplayText object that converts the database text into rtf text
|
||||
/// Arguments are:
|
||||
/// ItemInfo itemInfo - the item whose text will be resolved
|
||||
/// E_EditPrintMode ep_mode - edit or print.
|
||||
/// E_ViewMode vw_mode - view or edit.
|
||||
/// bool noEdit - flags whether to edit or not (used to set data in
|
||||
/// rtb as resolved replacewords for non-active rtb.
|
||||
/// </summary>
|
||||
public DisplayText(ItemInfo itemInfo, E_EditPrintMode epMode, E_ViewMode vwMode, bool noEdit)
|
||||
{
|
||||
_MyItemInfo = itemInfo;
|
||||
DisplayTextElementList = new List<displayTextElement>();
|
||||
OriginalText = itemInfo.MyContent.Text;
|
||||
TextFont = GetItemFont();
|
||||
string text = _MyItemInfo.MyContent.Text;
|
||||
@ -63,33 +63,47 @@ namespace VEPROMS.CSLA.Library
|
||||
// adjust formatting of exponents
|
||||
if (!_MyFormat.PlantFormat.FormatData.SectData.StepSectionData.FortranFormatNumbers && (epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View || noEdit)) text = DoFortranFormat(text);
|
||||
|
||||
// as a precaution, convert any \~ to \u160?. This is for Hard spaces.. see the commentary in the
|
||||
// as a precaution, convert any \~ to \u160?. This is for Hard spaces. see the commentary in the
|
||||
// save portion of this code for an explanation.
|
||||
text = text.Replace(@"\~", @"\u160?");
|
||||
text = text.Replace(@"\r\n", @"\par ");
|
||||
// replace the dash/hyphen or whatever you want to call it, with a hard hyphen. The 16-bit program
|
||||
// treated the dash/hyphen as such. Translate back on any data saves.
|
||||
if (itemInfo.ItemID == 1275)
|
||||
Console.WriteLine("here");
|
||||
// text = text.Replace(@"-", @"\u8209?");
|
||||
|
||||
// displayTextElement List items are created for anything that is handled differently in RTB, i.e.
|
||||
// symbols, ros, trans, text.
|
||||
int startIndex = 0;
|
||||
int index = -1;
|
||||
while ((index = FindTokenChar(text, startIndex))>-1)
|
||||
text = text.Replace(@"\line", @"\par");
|
||||
|
||||
// add colors around links:
|
||||
text = Regex.Replace(text, @"(<START\].*?\\v0) ", @"$1\cf1 ");
|
||||
//text = Regex.Replace(text, @"<START]\b0\v0 ", @"<START]\b0\v0\cf1 ");
|
||||
int indxcf = text.IndexOf("cf1");
|
||||
while (indxcf != -1)
|
||||
{
|
||||
// Do any 'plain' text that preceeds the token.
|
||||
if (index > startIndex) DoTextElement(text, startIndex, index);
|
||||
if (text[index + 1] == 'v')
|
||||
index = DoLink(text, index);
|
||||
else
|
||||
index = DoSymbol(text, startIndex, index);
|
||||
startIndex = index; // +1;
|
||||
if (startIndex >= text.Length) break;
|
||||
int indxend = text.IndexOf(@"\v", indxcf);
|
||||
text = text.Insert(indxend, @"\cf0 ");
|
||||
indxcf = text.IndexOf(@"cf1", indxend);
|
||||
}
|
||||
// Add any remaining text.
|
||||
if (startIndex < text.Length) DoTextElement(text, startIndex, index);
|
||||
|
||||
// Now put symbol (for fixed fonts) or unicode font (proportional) around symbols
|
||||
// These fonts are VESymbFix & Arial Unicode MS respectively, and the font table
|
||||
// is actually defined in the StepRTB code.
|
||||
int indxsym = text.IndexOf(@"\u");
|
||||
while (indxsym != -1)
|
||||
{
|
||||
int incrindx = 3;
|
||||
if (text[indxsym + 2] != 'l')
|
||||
{
|
||||
text = text.Insert(indxsym, @"\f1 ");
|
||||
int indxendsym = text.IndexOfAny(@"\ ?".ToCharArray(),indxsym+5);
|
||||
if (indxendsym == -1) // must be end of line:
|
||||
text = text.Insert(text.Length-1,@"\f0 ");
|
||||
else
|
||||
{
|
||||
if (text[indxendsym]=='?') indxendsym++;
|
||||
text = text.Insert(indxendsym, @"\f0 "); // TODO: do I need a space??
|
||||
}
|
||||
incrindx = 5;
|
||||
}
|
||||
indxsym = text.IndexOf(@"\u",indxsym + incrindx);
|
||||
}
|
||||
StartText = text;
|
||||
}
|
||||
|
||||
private string DoFortranFormat(string text)
|
||||
@ -117,38 +131,60 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
try
|
||||
{
|
||||
List<displayLinkElement> origList = GetLinkList(DisplayTextElementList);
|
||||
// massage string to store in DisplayTextElementList...
|
||||
RtfToDisplayTextElements(rtb);
|
||||
// take the list & convert to data in the format to save to the database.
|
||||
string modtext = DteToString();
|
||||
Item itm = _MyItemInfo.Get();
|
||||
// check for different text, i.e. text from this itm doesn't match
|
||||
// original text, a change occurred in database, but not from this user.
|
||||
if (OriginalText != itm.MyContent.Text)
|
||||
{
|
||||
Console.WriteLine("Save Failed because text changed outside of this edit session.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove rtf codes that aren't defining attributes, symbols, or links
|
||||
string modtext = RtfToDbText(rtb.Rtf);
|
||||
|
||||
if (modtext != OriginalText)
|
||||
{
|
||||
Item itm = _MyItemInfo.Get();
|
||||
// check for different text, i.e. text from this itm doesn't match
|
||||
// original text.
|
||||
if (OriginalText != itm.MyContent.Text)
|
||||
// if there are links, we'll need to do extra processing to see if
|
||||
// there were additions, deletions or modifications.
|
||||
bool haslinks = ((modtext.IndexOf(@"<START]") > -1) || (OriginalText != null && OriginalText != "" && OriginalText.IndexOf(@"<START]") > -1));
|
||||
if (haslinks)
|
||||
{
|
||||
Console.WriteLine("Save Failed because text changed outside of this edit session.");
|
||||
return false;
|
||||
// Get all links in original list
|
||||
RtfToDisplayTextElements(OriginalText);
|
||||
List<displayLinkElement> origList = GetLinkList(DisplayTextElementList);
|
||||
// now get new text into displaytext elements for comparison for links:
|
||||
RtfToDisplayTextElements(rtb.Rtf);
|
||||
|
||||
// Compare ro/transition lists and delete or add any to the item for any ros/transitions that have been
|
||||
// added/deleted or modified.
|
||||
ProcessRoTranChanges(itm, origList);
|
||||
itm.MyContent.Text = DteToString();
|
||||
}
|
||||
// Compare ro/transition lists and delete or add any to the item for any ros/transitions that have been
|
||||
// added/deleted or modified.
|
||||
ProcessRoTranChanges(itm, origList);
|
||||
itm.MyContent.Text = DteToString();
|
||||
Dictionary<int, ContentTransition> ctReplacements = BuildCtReplacements(itm.MyContent.ContentTransitions);
|
||||
Dictionary<int, ContentRoUsage> roUsgReplacements = BuildRoUsgReplacements(itm.MyContent.ContentRoUsages);
|
||||
itm.Save();
|
||||
if (ctReplacements.Count > 0)
|
||||
else
|
||||
{
|
||||
itm.MyContent.Text = FixCtReplacements(itm.MyContent.Text, ctReplacements);
|
||||
itm.MyContent.Text = modtext;
|
||||
itm.Save();
|
||||
}
|
||||
if (roUsgReplacements.Count > 0)
|
||||
|
||||
if (haslinks)
|
||||
{
|
||||
itm.MyContent.Text = FixRoUsgReplacements(itm.MyContent.Text, roUsgReplacements);
|
||||
// if new transitions/ros, we need to 'fix' the string in the embedded link to contain the
|
||||
// transition or usage record.
|
||||
Dictionary<int, ContentTransition> ctReplacements = BuildCtReplacements(itm.MyContent.ContentTransitions);
|
||||
Dictionary<int, ContentRoUsage> roUsgReplacements = BuildRoUsgReplacements(itm.MyContent.ContentRoUsages);
|
||||
itm.Save();
|
||||
if (ctReplacements.Count > 0)
|
||||
{
|
||||
itm.MyContent.Text = FixCtReplacements(itm.MyContent.Text, ctReplacements);
|
||||
itm.Save();
|
||||
}
|
||||
if (roUsgReplacements.Count > 0)
|
||||
{
|
||||
itm.MyContent.Text = FixRoUsgReplacements(itm.MyContent.Text, roUsgReplacements);
|
||||
itm.Save();
|
||||
}
|
||||
modtext = itm.MyContent.Text;
|
||||
}
|
||||
OriginalText = modtext;
|
||||
}
|
||||
@ -162,7 +198,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private string DteToString()
|
||||
{
|
||||
StringBuilder sret = new StringBuilder();
|
||||
@ -187,7 +222,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
private Dictionary<int, ContentRoUsage> BuildRoUsgReplacements(ContentRoUsages contentRoUsages)
|
||||
{
|
||||
Dictionary<int, ContentRoUsage> retval = new Dictionary<int, ContentRoUsage>();
|
||||
@ -205,7 +239,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
private Dictionary<int, ContentTransition> BuildCtReplacements(ContentTransitions contentTransitions)
|
||||
{
|
||||
Dictionary<int, ContentTransition> retval = new Dictionary<int, ContentTransition>();
|
||||
@ -356,35 +389,18 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
return retList;
|
||||
}
|
||||
private void RtfToDisplayTextElements(RichTextBox rtb)
|
||||
private void RtfToDisplayTextElements(string text)
|
||||
{
|
||||
// For hardspaces, the windows richtextbox does some 'quirky' things:
|
||||
// A unicode representation of \u160? is sent INTO the rtb. Coming out,
|
||||
// that \u160? was translated to a \~ (by the underlying windows rtb).
|
||||
// Note that if the \~ is sent to the rtb, it is treated as a regular space,
|
||||
// i.e. no longer a hardspace, and actually is converted to a regular space.
|
||||
// SO, on the way out, convert any \~ to \u160?
|
||||
string noExtraRtfStr = rtb.Rtf.Replace(@"\~", @"\u160?");
|
||||
// get original text into displaytext elements for comparison for links:
|
||||
if (DisplayTextElementList == null)
|
||||
DisplayTextElementList = new List<displayTextElement>();
|
||||
else
|
||||
DisplayTextElementList.Clear();
|
||||
|
||||
// Check for two links in a row & if found, add separating rtf comment
|
||||
// commands (these get removed in the richtextbox:
|
||||
noExtraRtfStr = noExtraRtfStr.Replace(@"[END><START]", @"[END>\v0 \v <START]");
|
||||
if (text == null || text == "") return;
|
||||
|
||||
// GetFontTable returns a non-negative number font number in the
|
||||
// font table for the unicode font, if it is used (otherwise -1)
|
||||
//int unicodeFont = GetFontTable(rtb.Rtf);
|
||||
string noExtraRtfStr = RtfToDbText(text);
|
||||
|
||||
// strip off all rtf commands...
|
||||
noExtraRtfStr = StripRtfCommands(noExtraRtfStr);
|
||||
|
||||
// Also, set back the hard dash to a regular dash... Do this after the removal
|
||||
// of other rtf commands though since the \u8209 was surrounded by font commands
|
||||
// that, without there removal first, was also removing the dash. There is no
|
||||
// space after the unicode character with a "?" ending it! and this is the only
|
||||
// way it is entered (either thru a string replace or thru data entry).
|
||||
noExtraRtfStr = noExtraRtfStr.Replace(@"\u8209?", @"-");
|
||||
|
||||
DisplayTextElementList.Clear();
|
||||
int startIndex = 0;
|
||||
int index = -1;
|
||||
while ((index = FindTokenChar(noExtraRtfStr, startIndex)) > -1)
|
||||
@ -402,56 +418,31 @@ namespace VEPROMS.CSLA.Library
|
||||
// Add any remaining text.
|
||||
if (startIndex < noExtraRtfStr.Length) DoTextElement(noExtraRtfStr, startIndex, index);
|
||||
}
|
||||
private int SaveTextElement(string data, int startIndex, int index)
|
||||
private string RtfToDbText(string text)
|
||||
{
|
||||
displayTextElement vte = new displayTextElement();
|
||||
vte.Type = E_TextElementType.Text;
|
||||
int len = (index == -1) ? data.Length - startIndex : index - startIndex;
|
||||
vte.Text = data.Substring(startIndex, len);
|
||||
DisplayTextElementList.Add(vte);
|
||||
return index;
|
||||
}
|
||||
private int SaveSymbolTE(string data, int startIndex)
|
||||
{
|
||||
displayLinkElement vte = new displayLinkElement();
|
||||
vte.Type = E_TextElementType.Symbol;
|
||||
// symbols are just the unicode/rtf command, no font associated with it
|
||||
// by the time it gets here... A symbol can be represented by \'xy or \uxyz?
|
||||
// if the \'xy is used the length of the symbol number will always be two,
|
||||
// otherwise find the index of the '?' to find the end.
|
||||
int endindx = -1;
|
||||
if (data[startIndex + 1] == '\'') endindx = startIndex + 3;
|
||||
else endindx = data.IndexOf("?", startIndex);
|
||||
if (endindx == -1) return startIndex; // not found - error
|
||||
vte.Text = data.Substring(startIndex, endindx - startIndex + 1);
|
||||
DisplayTextElementList.Add(vte);
|
||||
if (endindx+1<data.Length && data[endindx + 1] != ' ') return endindx;
|
||||
return endindx + 1; // add one to get past the space that was added after a symbol (to end the font cmd)
|
||||
}
|
||||
private int GetFontTable(string rtf)
|
||||
{
|
||||
dicRtfFontTable = new Dictionary<int, string>();
|
||||
// return unicode (symbol) font number, if it exists, to expedite finding
|
||||
// the font for symbols.
|
||||
int unicodeFont = -1;
|
||||
int bindx = rtf.IndexOf(@"{\fonttbl");
|
||||
if (bindx < -1) return -1;
|
||||
int eindx = rtf.IndexOf("}}", bindx);
|
||||
// get font table string and then do regular expressions to get font number
|
||||
// with font name.
|
||||
string tbl = rtf.Substring(bindx + 9, eindx - bindx - 8);
|
||||
tbl = tbl.Replace("{", "<");
|
||||
tbl = tbl.Replace("}", ">");
|
||||
string pat = @"(?:<\\f)([0-9]+)(?:[\S]+ )([\w ]+)";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (Match m in Regex.Matches(tbl, pat))
|
||||
{
|
||||
int num = Convert.ToInt32(m.Result("${1}"));
|
||||
string nam = m.Result("${2}");
|
||||
dicRtfFontTable.Add(num, nam);
|
||||
if ((unicodeFont == -1) && (nam == "Arial Unicode MS")) unicodeFont = num;
|
||||
}
|
||||
return unicodeFont;
|
||||
// For hardspaces, the windows richtextbox does some 'quirky' things:
|
||||
// A unicode representation of \u160? is sent INTO the rtb. Coming out,
|
||||
// that \u160? was translated to a \~ (by the underlying windows rtb).
|
||||
// Note that if the \~ is sent to the rtb, it is treated as a regular space,
|
||||
// i.e. no longer a hardspace, and actually is converted to a regular space.
|
||||
// SO, on the way out, convert any \~ to \u160?
|
||||
string noExtraRtfStr = text.Replace(@"\~", @"\u160?");
|
||||
|
||||
// Check for two links in a row & if found, add separating rtf comment
|
||||
// commands (these get removed in the richtextbox:
|
||||
noExtraRtfStr = noExtraRtfStr.Replace(@"[END><START]", @"[END>\v0 \v <START]");
|
||||
|
||||
// GetFontTable returns a non-negative number font number in the
|
||||
// font table for the unicode font, if it is used (otherwise -1)
|
||||
//int unicodeFont = GetFontTable(rtb.Rtf);
|
||||
|
||||
// strip off all rtf commands...
|
||||
noExtraRtfStr = StripRtfCommands(noExtraRtfStr);
|
||||
|
||||
// the indent character was translated in the richtextbox, change it back:
|
||||
if (noExtraRtfStr.IndexOf(@"\'05") > -1) noExtraRtfStr = noExtraRtfStr.Replace(@"\'05", "\x05");
|
||||
|
||||
return noExtraRtfStr;
|
||||
}
|
||||
private string RemoveRtfStyles(string rtf)
|
||||
{
|
||||
@ -524,11 +515,12 @@ namespace VEPROMS.CSLA.Library
|
||||
if (m.Value == @"\line") return m.Value;
|
||||
break;
|
||||
case 'p':
|
||||
if (m.Value == @"\par") return "\r\n";
|
||||
if (m.Value == @"\par") return @"\par";
|
||||
//if (m.Value == @"\protect")
|
||||
// return m.Value;
|
||||
//if (m.Value == @"\protect0")
|
||||
// return m.Value;
|
||||
if (m.Value.Length>=6 && m.Value.Substring(0,6) == "\\par\r\n") return m.Value.Replace("\r\n", " ");
|
||||
break;
|
||||
case 'f': // handle fonts separately because they may or may not have a space after them
|
||||
if (m.Value[2]>='0' && m.Value[2]<='9')return m.Value;
|
||||
@ -542,6 +534,12 @@ namespace VEPROMS.CSLA.Library
|
||||
// are rtf so were getting removed and/or not handled correctly.
|
||||
string retval = rtf.Replace(@"\{", @"(![");
|
||||
retval = retval.Replace(@"\}", @"(!]");
|
||||
|
||||
// remove carriage return/newlines after \par commands (these are introduced by rtb
|
||||
// for hard returns, goes into rtb as \par and comes out as \par\r\n):
|
||||
retval = Regex.Replace(retval, @"\\par\r\n([^\\.*?])", "\\par $1");
|
||||
retval = Regex.Replace(retval, @"\\par\r\n([\\.*?])", "\\par$1");
|
||||
|
||||
retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
|
||||
retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
|
||||
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
||||
@ -549,10 +547,13 @@ namespace VEPROMS.CSLA.Library
|
||||
retval = Regex.Replace(retval, @"\\f[0-9] ", ""); // remove font command with ending space
|
||||
retval = Regex.Replace(retval, @"\\f[0-9]", ""); // remove font command without ending space
|
||||
retval = Regex.Replace(retval, @"\\[^ \\?]+", new MatchEvaluator(ReplaceRTFClause)); // take backslash xyz and evaluates them
|
||||
// remove a space if there is one as the first character..
|
||||
// remove a space if there is one as the first character or the last character
|
||||
if (retval[0]==' ')retval = retval.Remove(0, 1);
|
||||
// remove \r\n at end of string - this was added with the \par at the end of string by the rtf box
|
||||
retval = retval.TrimEnd(' ');
|
||||
// remove \r\n and \par at end of string.
|
||||
if (retval.Substring(retval.Length - 2, 2) == "\r\n") retval = retval.Remove(retval.Length - 2, 2);
|
||||
if (retval.Substring(retval.Length - 4, 4) == @"\par") retval = retval.Remove(retval.Length - 4, 4);
|
||||
|
||||
if (retval.Length == 0) return "";
|
||||
if (retval.Substring(retval.Length - 2, 2) == @"\v") retval = retval.Remove(retval.Length - 2, 2);
|
||||
retval = RemoveRtfStyles(retval);
|
||||
@ -592,16 +593,6 @@ namespace VEPROMS.CSLA.Library
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// There were two links in a row, very special case, handle here...
|
||||
//if (TwoLinksInARow)
|
||||
//{
|
||||
// int tindx = txt.IndexOf("<START]", startIndex);
|
||||
// if (tindx > 0)
|
||||
// {
|
||||
// TwoLinksInARow = false;
|
||||
// return tindx;
|
||||
// }
|
||||
//}
|
||||
int indx = txt.IndexOf('\\', startIndex);
|
||||
if (indx < 0) return indx;
|
||||
// see if symbol (but not underline) or another rtf command: has a 'u'
|
||||
@ -623,18 +614,6 @@ namespace VEPROMS.CSLA.Library
|
||||
DisplayTextElementList.Add(vte);
|
||||
return index+1;
|
||||
}
|
||||
private string CreateLink(E_TextElementType type, string linktxt)
|
||||
{
|
||||
string retlink = "";
|
||||
if (type == E_TextElementType.ReferencedObject)
|
||||
retlink = "#Link:ReferencedObject:" + linktxt;
|
||||
else if (type == E_TextElementType.Transition)
|
||||
retlink = "#Link:Transition:" + linktxt;
|
||||
else
|
||||
retlink = "#Link:TransitionRange:" + linktxt;
|
||||
|
||||
return retlink;
|
||||
}
|
||||
private int DoLink(string text, int startIndex)
|
||||
{
|
||||
int retval = -1;
|
||||
@ -645,7 +624,6 @@ namespace VEPROMS.CSLA.Library
|
||||
retval = DoTran(text, startIndex);
|
||||
return retval;
|
||||
}
|
||||
//bool TwoLinksInARow = false;
|
||||
private int DoRO(string text, int index)
|
||||
{
|
||||
displayLinkElement vte = new displayLinkElement();
|
||||
@ -677,7 +655,6 @@ namespace VEPROMS.CSLA.Library
|
||||
vte.Type = (text[linkindx+16]=='R')?E_TextElementType.TransitionRange:E_TextElementType.Transition;
|
||||
return DoLinkElements(text, index, vte);
|
||||
}
|
||||
|
||||
private int DoLinkElements(string text, int index, displayLinkElement vte)
|
||||
{
|
||||
// Find the 'end comment' for the <START], can't count characters
|
||||
@ -708,27 +685,12 @@ namespace VEPROMS.CSLA.Library
|
||||
int endToken = (endLinkIndx == endLinkIndxE)?endLinkIndx+3:text.IndexOf(@"[END>", endLinkIndx + 3); // get past end of link
|
||||
int endComment = text.IndexOf(@"\v0", endToken);
|
||||
|
||||
//// if the above is at end of string, don't bother with looking for another
|
||||
//// <START]
|
||||
//int startToken = -1;
|
||||
//if (endLinkIndxE + 4 + 7 < text.Length) // is there enough length of text for another link?
|
||||
// startToken = text.IndexOf(@"<START]", endLinkIndxE + 4);
|
||||
int rettoken = 0;
|
||||
//if (startToken == -1 || endLinkIndxV > startToken) // don't worry about two links in a row....
|
||||
//{
|
||||
int retlen = 4;
|
||||
if (endComment + 3 == text.Length) retlen = 3;
|
||||
else if (text[endComment + 3] == '\\') retlen = 3;
|
||||
vte.TextAndLink = text.Substring(index, endComment - index + retlen);
|
||||
rettoken = endComment + retlen;
|
||||
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// TwoLinksInARow = true;
|
||||
// vte.TextAndLink = text.Substring(index, startToken - index) + @"\v0 ";
|
||||
// rettoken = endComment + 5; // 5 for "\v0 "
|
||||
//}
|
||||
int retlen = 4;
|
||||
if (endComment + 3 == text.Length) retlen = 3;
|
||||
else if (text[endComment + 3] == '\\') retlen = 3;
|
||||
vte.TextAndLink = text.Substring(index, endComment - index + retlen);
|
||||
rettoken = endComment + retlen;
|
||||
if (vte.Type != E_TextElementType.ReferencedObject) vte.TextAndLink = vte.TextAndLink = vte.TextAndLink.Replace("(Resolved Transition Text)", tmptxt);
|
||||
DisplayTextElementList.Add(vte);
|
||||
return rettoken;
|
||||
@ -751,12 +713,12 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region ReplaceWords
|
||||
private ReplaceStr _rs;
|
||||
private string ReplaceIt(Match m)
|
||||
{
|
||||
string s = m.ToString();
|
||||
string t = s.Replace(_rs.ReplaceWord, _rs.ReplaceWith);
|
||||
return m.ToString().Replace(_rs.ReplaceWord, _rs.ReplaceWith);
|
||||
}
|
||||
//private string ReplaceIt(Match m)
|
||||
//{
|
||||
// string s = m.ToString();
|
||||
// string t = s.Replace(_rs.ReplaceWord, _rs.ReplaceWith);
|
||||
// return m.ToString().Replace(_rs.ReplaceWord, _rs.ReplaceWith);
|
||||
//}
|
||||
private string DoReplaceWords(string Text)
|
||||
{
|
||||
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
|
115
PROMS/Volian.Controls.Library/LinkText.cs
Normal file
115
PROMS/Volian.Controls.Library/LinkText.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
public partial class LinkText
|
||||
{
|
||||
public LinkText(string linkInfoText)
|
||||
{
|
||||
_LinkInfoText = linkInfoText;
|
||||
}
|
||||
public void ParseLink()
|
||||
{
|
||||
if (_MyParsedLinkType == ParsedLinkType.NotParsed)
|
||||
{
|
||||
if (_LinkInfoText == null) return;
|
||||
// First parse the string
|
||||
_LinkInfoText = _LinkInfoText.Replace(@"\v ", "");
|
||||
// for tran : "2, #, #, # and 4#Link:TransitionRange:2 10 173 166"
|
||||
Match m = Regex.Match(_LinkInfoText, @"(.*)[#]Link:([A-Za-z]*):(.*)");
|
||||
_MyValue = m.Groups[1].Value;
|
||||
_MyLink = "#Link:" + m.Groups[2].Value + ":" + m.Groups[3].Value;
|
||||
switch (m.Groups[2].Value)
|
||||
{
|
||||
case "ReferencedObject":
|
||||
_MyParsedLinkType = ParsedLinkType.ReferencedObject;
|
||||
string[] subs = m.Groups[3].Value.Split(" ".ToCharArray());
|
||||
if (subs[0] == "<NewID>")
|
||||
_MyRoUsageInfo = null;
|
||||
else
|
||||
{
|
||||
int roUsageid = Convert.ToInt32(subs[0]);
|
||||
_MyRoUsageInfo = RoUsageInfo.Get(roUsageid);
|
||||
}
|
||||
break;
|
||||
case "Transition":
|
||||
case "TransitionRange":
|
||||
_MyParsedLinkType = (ParsedLinkType)Enum.Parse(_MyParsedLinkType.GetType(), m.Groups[2].Value);
|
||||
if (m.Groups[3].Value.Split(" ".ToCharArray())[1] == "<NewID>")
|
||||
_MyTransitionInfo = null;
|
||||
else
|
||||
{
|
||||
int transitionID = Convert.ToInt32(m.Groups[3].Value.Split(" ".ToCharArray())[1]);
|
||||
_MyTransitionInfo = TransitionInfo.Get(transitionID);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private string _LinkInfoText;
|
||||
public string LinkInfoText
|
||||
{
|
||||
get { return _LinkInfoText; }
|
||||
}
|
||||
private TransitionInfo _MyTransitionInfo = null;
|
||||
public TransitionInfo MyTransitionInfo
|
||||
{
|
||||
get { ParseLink(); return _MyTransitionInfo; }
|
||||
}
|
||||
public ItemInfo MyTranToItemInfo
|
||||
{
|
||||
get { ParseLink(); return _MyTransitionInfo.MyItemToID; }
|
||||
}
|
||||
public ItemInfo MyTranRangeItemInfo
|
||||
{
|
||||
get { ParseLink(); return _MyTransitionInfo.MyItemRangeID; }
|
||||
}
|
||||
private string _MyValue = null;
|
||||
//public string MyValue
|
||||
//{
|
||||
// get { ParseLink(); return _MyValue; }
|
||||
//}
|
||||
private string _MyLink = null;
|
||||
//public string MyLink
|
||||
//{
|
||||
// get { ParseLink(); return _MyLink; }
|
||||
//}
|
||||
private RoUsageInfo _MyRoUsageInfo;
|
||||
public RoUsageInfo MyRoUsageInfo
|
||||
{
|
||||
get { ParseLink(); return _MyRoUsageInfo; }
|
||||
}
|
||||
//private string _Roid = null; // TODO: need to return Referenced Object rather than just roid
|
||||
//public string Roid
|
||||
//{
|
||||
// get { ParseLink(); return _Roid; }
|
||||
//}
|
||||
//private string _RoUsageid = null; // TODO: need to return Referenced Object rather than just roid
|
||||
//public string RoUsageid
|
||||
//{
|
||||
// get { ParseLink(); return _RoUsageid; }
|
||||
//}
|
||||
//private string _RoDbid = null; // TODO: need to return Referenced Object rather than just roid
|
||||
//public string RoDbid
|
||||
//{
|
||||
// get { ParseLink(); return _RoDbid; }
|
||||
//}
|
||||
private ParsedLinkType _MyParsedLinkType = ParsedLinkType.NotParsed;
|
||||
//public ParsedLinkType MyParsedLinkType
|
||||
//{
|
||||
// get { ParseLink(); return _MyParsedLinkType; }
|
||||
//}
|
||||
|
||||
}
|
||||
#region enums
|
||||
public enum ParsedLinkType : int
|
||||
{
|
||||
NotParsed = 0,
|
||||
Transition = 1,
|
||||
TransitionRange = 2,
|
||||
ReferencedObject = 3
|
||||
}
|
||||
#endregion
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user