Correct cursor position after RO Insert

Correct dispose logic for transition destination ITEMs
Correct cursor position after Transition Insert
Correct logic to parse Transition Link Token
Correct Save Config to dispose of ITEM
Removed debug vlnStackTrace
This commit is contained in:
Rich
2010-09-27 16:12:46 +00:00
parent fb3ed8d053
commit dc7eb108cb
6 changed files with 104 additions and 81 deletions

View File

@@ -294,8 +294,7 @@ namespace Volian.Controls.Library
}
// If the previous character is a comma or a space then don't add a Hard Space
if (ind > 1 && (str[ind - 2] == ',' || str[ind - 2] == ' ')) return str;
if (ind == -1)
return str;
if (ind <= 0) return str;
return str.Substring(0,ind - 1) + @"\u160?" + str.Substring(ind);
}
private bool StepTransition(int TransId)
@@ -561,18 +560,31 @@ namespace Volian.Controls.Library
string[] tparts = linkstr.Split(" ".ToCharArray());
int type = System.Convert.ToInt32(tparts[0]);
int tr1 = System.Convert.ToInt32(tparts[2]); // tparts[1] is token for tranid
Item itm1 = Item.Get(tr1);
bool dispose1 = false;
Item itm1 = null;
bool dispose2 = false;
Item itm2 = null;
if (itm.ItemID != tr1)
{
dispose1 = true;
itm1 = Item.Get(tr1);
}
else
itm1 = itm; // a transition that points to itself should not dispose
if (dte.Type == E_TextElementType.TransitionRange)
{
dispose2 = true;
itm2 = Item.Get(System.Convert.ToInt32(tparts[3]));
}
else
itm2 = itm1;
ContentTransition ct = itm.MyContent.ContentTransitions.Add(itm1, itm2);
//Console.WriteLine("CT {0},{1},{2},{3}", ct.TransitionID, itm.ItemID, itm.MyContent.MyContentUnique, itm.MyContent.ContentTransitions.Count);
ct.TranType = type;
l_dte.Link = l_dte.Link.Replace("<NewID>", string.Format("<CTID={0}>", ct.TransitionID));
l_dte.TextAndLink = l_dte.TextAndLink.Replace("<NewID>", string.Format("<CTID={0}>", ct.TransitionID));
if (dispose2) itm2.Dispose();
if (dispose1) itm1.Dispose();
}
}
}
@@ -597,32 +609,33 @@ namespace Volian.Controls.Library
}
private void RtfToDisplayTextElements(string text)
{
// get original text into displaytext elements for comparison for links:
if (DisplayTextElementList == null)
DisplayTextElementList = new List<displayTextElement>();
else
DisplayTextElementList.Clear();
// get original text into displaytext elements for comparison for links:
if (DisplayTextElementList == null)
DisplayTextElementList = new List<displayTextElement>();
else
DisplayTextElementList.Clear();
if (text == null || text == "") return;
if (text == null || text == "") return;
string noExtraRtfStr = text;
int startIndex = 0;
int index = -1;
string noExtraRtfStr = text;
int startIndex = 0;
int index = -1;
noExtraRtfStr = noExtraRtfStr.Replace(@"><", @">\v0 \v <");
while ((index = FindTokenChar(noExtraRtfStr, startIndex)) > -1)
{
// Do any 'plain' text that preceeds the token.
if (index > startIndex) DoTextElement(noExtraRtfStr, startIndex, index);
while ((index = FindTokenChar(noExtraRtfStr, startIndex)) > -1)
{
// Do any 'plain' text that preceeds the token.
if (index > startIndex) DoTextElement(noExtraRtfStr, startIndex, index);
if (noExtraRtfStr[index + 1] == 'v')
index = DoLink(noExtraRtfStr, index);
else
index = DoSymbol(noExtraRtfStr, startIndex, index);
startIndex = index; // +1;
if (startIndex >= noExtraRtfStr.Length) break;
}
// Add any remaining text.
if (startIndex < noExtraRtfStr.Length) DoTextElement(noExtraRtfStr, startIndex, index);
if (noExtraRtfStr[index + 1] == 'v')
index = DoLink(noExtraRtfStr, index);
else
index = DoSymbol(noExtraRtfStr, startIndex, index);
startIndex = index; // +1;
if (startIndex >= noExtraRtfStr.Length) break;
}
// Add any remaining text.
if (startIndex < noExtraRtfStr.Length) DoTextElement(noExtraRtfStr, startIndex, index);
}
private string RtfToDbText(string text)
{
@@ -1076,6 +1089,7 @@ namespace Volian.Controls.Library
if (m.Success) return m.Groups[1].ToString()[0];
return '\0';
}
private int DoLinkElements(string text, int index, displayLinkElement vte)
{
// Find the 'end comment' for this <START], can't count characters
@@ -1092,7 +1106,7 @@ namespace Volian.Controls.Library
// Now get the link part. It can be terminated by a '\v0' or an [END>
int endLinkIndxV = text.IndexOf(@"\v0 ", linkIndx);
if (endLinkIndxV == -1) endLinkIndxV = text.IndexOf(@"\v0", linkIndx); // at end of string
int endLinkIndxE = text.IndexOf(@"[END>", linkIndx);
int endLinkIndxE = text.IndexOf(@"[END>", linkIndx);
int endLinkIndx = (endLinkIndxV < endLinkIndxE) ? endLinkIndxV : endLinkIndxE;
vte.Link = text.Substring(linkIndx + 6, endLinkIndx - linkIndx - 6); // 6 for #Link:
@@ -1111,7 +1125,7 @@ namespace Volian.Controls.Library
// Now get the entire text & link. Account for various ending possibilities:
// ends with '\v0\'; ends with '\v0 '; ends with '\v0' (end of string);
// ends with '[END>' if two in a row - will have <START]
int endToken = (endLinkIndx == endLinkIndxE) ? endLinkIndx + 3 : text.IndexOf(@"[END>", endLinkIndx + 3); // get past end of link
int endToken = (endLinkIndx == endLinkIndxE)?endLinkIndx+3:text.IndexOf(@"[END>", endLinkIndx + 3); // get past end of link
int endComment = text.IndexOf(@"\v0", endToken);
int rettoken = 0;
@@ -1131,7 +1145,6 @@ namespace Volian.Controls.Library
DisplayTextElementList.Add(vte);
return rettoken;
}
private int DoSymbol(string text, int startIndex, int index)
{
displayTextElement vte = new displayTextElement();