diff --git a/PROMS/Volian.Controls.Library/DisplayText.cs b/PROMS/Volian.Controls.Library/DisplayText.cs index 0b0adad8..f6edef6b 100644 --- a/PROMS/Volian.Controls.Library/DisplayText.cs +++ b/PROMS/Volian.Controls.Library/DisplayText.cs @@ -34,7 +34,7 @@ namespace VEPROMS.CSLA.Library set { _textFont = value; } } public string StartText; - public string OriginalText; // compare for save to see if change. + public string OriginalText; // compare for save to see if change for links. private FormatInfo _MyFormat; #endregion #region Constructors @@ -66,8 +66,9 @@ namespace VEPROMS.CSLA.Library // 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 "); - + text = text.Replace("\r\n", @"\par "); + if (text.IndexOf(@"\line") > -1) + MessageBox.Show("Found rtf line"); text = text.Replace(@"\line", @"\par"); // add colors around links: @@ -140,56 +141,46 @@ namespace VEPROMS.CSLA.Library return false; } - // remove rtf codes that aren't defining attributes, symbols, or links string modtext = RtfToDbText(rtb.Rtf); - - if (modtext != OriginalText) + // if there are links, we'll need to do extra processing to see if + // there were additions, deletions or modifications. + bool haslinks = ((modtext.IndexOf(@" -1) || (OriginalText != null && OriginalText != "" && OriginalText.IndexOf(@" -1)); + if (haslinks) { - // if there are links, we'll need to do extra processing to see if - // there were additions, deletions or modifications. - bool haslinks = ((modtext.IndexOf(@" -1) || (OriginalText != null && OriginalText != "" && OriginalText.IndexOf(@" -1)); - if (haslinks) - { - // Get all links in original list - RtfToDisplayTextElements(OriginalText); - List origList = GetLinkList(DisplayTextElementList); - // now get new text into displaytext elements for comparison for links: - RtfToDisplayTextElements(rtb.Rtf); + // Get all links in original list + RtfToDisplayTextElements(OriginalText); + List 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(); - } - else + // 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(); + + // if new transitions/ros, we need to 'fix' the string in the embedded link to contain the + // transition or usage record. + Dictionary ctReplacements = BuildCtReplacements(itm.MyContent.ContentTransitions); + Dictionary roUsgReplacements = BuildRoUsgReplacements(itm.MyContent.ContentRoUsages); + itm.Save(); + if (ctReplacements.Count > 0) { - itm.MyContent.Text = modtext; + itm.MyContent.Text = FixCtReplacements(itm.MyContent.Text, ctReplacements); itm.Save(); } - - if (haslinks) + if (roUsgReplacements.Count > 0) { - // if new transitions/ros, we need to 'fix' the string in the embedded link to contain the - // transition or usage record. - Dictionary ctReplacements = BuildCtReplacements(itm.MyContent.ContentTransitions); - Dictionary roUsgReplacements = BuildRoUsgReplacements(itm.MyContent.ContentRoUsages); + itm.MyContent.Text = FixRoUsgReplacements(itm.MyContent.Text, roUsgReplacements); 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; + modtext = itm.MyContent.Text; } else - return true; // no text changed, but did not fail so return true. + { + itm.MyContent.Text = modtext; + itm.Save(); + } + OriginalText = modtext; } catch (Exception ex) { @@ -515,7 +506,7 @@ namespace VEPROMS.CSLA.Library if (m.Value == @"\line") return m.Value; break; case 'p': - if (m.Value == @"\par") return @"\par"; + if (m.Value == @"\par") return "\r\n"; //if (m.Value == @"\protect") // return m.Value; //if (m.Value == @"\protect0") @@ -546,6 +537,7 @@ namespace VEPROMS.CSLA.Library retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces 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, @"\\par ", "\r\n"); retval = Regex.Replace(retval, @"\\[^ \\?]+", new MatchEvaluator(ReplaceRTFClause)); // take backslash xyz and evaluates them // remove a space if there is one as the first character or the last character if (retval[0]==' ')retval = retval.Remove(0, 1);