This commit is contained in:
Kathy Ruffing 2011-02-14 15:51:02 +00:00
parent 1456d43132
commit e389cbd5be

View File

@ -2661,6 +2661,93 @@ namespace Volian.Controls.Library
}
#endregion
#region
public string DoNewLinkInGridCell()
{
// first find the new link and determine whether it's RO or transition.
int indx = Rtf.IndexOf(@"#Link:ReferencedObject:<NewID>");
if (indx>0)
{
Match mro = Regex.Match(Rtf.Substring(indx,Rtf.Length-indx), @"([A-Za-z]*):(.*)\[END>");
string linkstr = mro.Groups[2].Value;
string[] roparts = linkstr.Split(" ".ToCharArray());
ContentRoUsage rousg = null;
int oldid = -1;
using (Item itm = MyItemInfo.Get())
{
using (RODb rodb = RODb.GetJustRoDb(Convert.ToInt32(roparts[2])))
{
rousg = itm.MyContent.ContentRoUsages.Add(roparts[1], rodb);
}
oldid = rousg.ROUsageID;
Rtf = Rtf.Replace("<NewID>", string.Format("<CROUSGID={0}>", rousg.ROUsageID));
itm.Save();
Rtf = Rtf.Replace(string.Format("<CROUSGID={0}>", oldid), rousg.ROUsageID.ToString());
itm.Save();
}
}
Match mt = Regex.Match(Rtf, "Transition.*:.* <NewID>");
if (mt.Length > 0)
{
indx = mt.Index;
Match m = Regex.Match(Rtf.Substring(indx, Rtf.Length - indx), @"([A-Za-z]*):(.*)\[END>");
bool isSingleTran = true;
if (Rtf.Substring(indx,16).IndexOf("TransitionRange")>=0) isSingleTran = false;
string linkstr = m.Groups[2].Value;
string[] tparts = linkstr.Split(" ".ToCharArray());
int type = System.Convert.ToInt32(tparts[0]);
int tr1 = System.Convert.ToInt32(tparts[2]); // tparts[2] is token for tranid
int tr2 = tr1;
if (tparts.Length > 3)
tr2 = System.Convert.ToInt32(tparts[3]); // tparts[3] is token for rangeid
bool dispose1 = false;
Item itm1 = null;
bool dispose2 = false;
Item itm2 = null;
using (Item itm = MyItemInfo.Get())
{
if (itm.ItemID == tr1)
itm1 = itm; // a transition that points to itself should not dispose
else
{
dispose1 = true;
itm1 = Item.Get(tr1);
}
if (itm.ItemID == tr2)
itm2 = itm; // a transition that points to itself should not dispose
else if (tr1 == tr2)
itm2 = itm1; // if both destinations are the same only dispose the first one
else
{
dispose2 = true;
itm2 = Item.Get(tr2);
}
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;
if (isSingleTran)
ct.IsRange = 0;
else if (tr1 != tr2)
ct.IsRange = 1;
else
ct.IsRange = 2;
int oldidt = ct.TransitionID;
Rtf = Rtf.Replace("<NewID>", string.Format("<CTID={0}>", ct.TransitionID));
itm.Save();
Rtf = Rtf.Replace(string.Format("<CTID={0}>", oldidt), ct.TransitionID.ToString());
itm.Save();
}
if (dispose2) itm2.Dispose();
if (dispose1) itm1.Dispose();
}
return Rtf;
}
#endregion
#region Debug
private bool _ShowDebug = false;
public bool ShowDebug