This commit is contained in:
Kathy Ruffing 2011-03-01 13:26:22 +00:00
parent e96d73f919
commit 287707438e
2 changed files with 150 additions and 41 deletions

View File

@ -18,6 +18,7 @@ namespace Volian.Controls.Library
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
MyItemInfo.MyContent.Changed -= new VEPROMS.CSLA.Library.ContentInfoEvent(MyContent_Changed);
} }
#region Component Designer generated code #region Component Designer generated code

View File

@ -29,7 +29,6 @@ namespace Volian.Controls.Library
* 3) When data migration of tables, need to include the font if there is a symbol. Move * 3) When data migration of tables, need to include the font if there is a symbol. Move
* AddFontTable from StepRTB.cs to a place accessible, such as volian.base. And then * AddFontTable from StepRTB.cs to a place accessible, such as volian.base. And then
* in data migration, will need to know if a font is fixed. * in data migration, will need to know if a font is fixed.
* 4) KBR Paste step crashes. Look at when doing insert.
*/ */
#region Fields #region Fields
public VlnFlexGrid MyFlexGrid public VlnFlexGrid MyFlexGrid
@ -76,6 +75,11 @@ namespace Volian.Controls.Library
if (MyStepPanel.DisplayItemChanging) return; if (MyStepPanel.DisplayItemChanging) return;
MyStepRTB.MyItemInfo = MyItemInfo; // should be in vlnFlexGrid MyStepRTB.MyItemInfo = MyItemInfo; // should be in vlnFlexGrid
MyStepPanel.SelectedEditItem = this; MyStepPanel.SelectedEditItem = this;
if (MyFlexGrid.IsRoTable)
{
MyFlexGrid.Cols.Fixed = MyFlexGrid.Cols.Count;
MyFlexGrid.Rows.Fixed = MyFlexGrid.Rows.Count;
}
} }
void MyFlexGrid_KeyDown(object sender, KeyEventArgs e) void MyFlexGrid_KeyDown(object sender, KeyEventArgs e)
{ {
@ -189,7 +193,15 @@ namespace Volian.Controls.Library
void MyStepRTB_DoSaveContents(object sender, EventArgs args) void MyStepRTB_DoSaveContents(object sender, EventArgs args)
{ {
if (MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0) // Only if a Cell is Selected if (MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0) // Only if a Cell is Selected
MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col] = MyStepRTB.Rtf = MyStepRTB.DoNewLinkInGridCell(); {
int row = MyFlexGrid.Row;
int col = MyFlexGrid.Col;
SaveContents();
MyStepRTB.Rtf = MyStepRTB.DoNewLinkInGridCell();
MyFlexGrid.Row = row;
MyFlexGrid.Col = col;
MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col] = MyStepRTB.Rtf;
}
SaveContents(); SaveContents();
} }
void MyStepRTB_VisibleChanged(object sender, EventArgs e) void MyStepRTB_VisibleChanged(object sender, EventArgs e)
@ -254,14 +266,12 @@ namespace Volian.Controls.Library
InitializeComponent(); InitializeComponent();
SetupEventHandlers(); SetupEventHandlers();
SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, null); SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, null);
//RefreshDisplay(true); //TODO: is the argument true?
} }
public GridItem(ItemInfo itemInfo, StepPanel myStepPanel, EditItem myParentEditItem, ChildRelation myChildRelation, bool expand, EditItem nextEditItem) public GridItem(ItemInfo itemInfo, StepPanel myStepPanel, EditItem myParentEditItem, ChildRelation myChildRelation, bool expand, EditItem nextEditItem)
{ {
InitializeComponent(); InitializeComponent();
SetupEventHandlers(); SetupEventHandlers();
SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, nextEditItem); SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, nextEditItem);
//RefreshDisplay(true); //TODO: is the argument true?
} }
private void SetupEventHandlers() private void SetupEventHandlers()
{ {
@ -286,6 +296,20 @@ namespace Volian.Controls.Library
this.MyStepRTB.KeyDown += new KeyEventHandler(MyStepRTB_KeyDown); this.MyStepRTB.KeyDown += new KeyEventHandler(MyStepRTB_KeyDown);
this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange); this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange);
this.MyStepRTB.GotFocus += new EventHandler(MyStepRTB_GotFocus); this.MyStepRTB.GotFocus += new EventHandler(MyStepRTB_GotFocus);
this.MyStepRTB.RoInsert += new StepRTBRoEvent(MyStepRTB_RoInsert);
}
void MyStepRTB_RoInsert(object sender, StepRTBRoEventArgs args)
{
if (MyFlexGrid.IsRoTable)
{
MyFlexGrid.Clear();
ConvertTableToGrid(args.RawValText);
MyFlexGrid.RODbId = args.RODbID;
MyFlexGrid.ROID = args.ROID;
SaveContents();
}
else
MyStepRTB.UpdateStepRtb(args.LinkText, args.ValText);
} }
void MyStepRTB_GotFocus(object sender, EventArgs e) void MyStepRTB_GotFocus(object sender, EventArgs e)
{ {
@ -374,45 +398,68 @@ namespace Volian.Controls.Library
int w = MyFlexGrid.Cols.Count; int w = MyFlexGrid.Cols.Count;
int h = MyFlexGrid.Rows.Count; int h = MyFlexGrid.Rows.Count;
while (r < h) string srchtxt = MyFlexGrid.GetSearchableText();
// find the rousages within the grid cell. If this is an ro table, there will only be one usage
// if it is a modify and there will be no usages if it is new (the usage gets created on the save)
if (!MyFlexGrid.IsRoTable)
{ {
CellRange cr = MyFlexGrid.GetMergedRange(r, c); while (r < h)
if (cr.r1 == r && cr.c1 == c)
{ {
// see if there are any links and save these so that any deleted ROs or transitions in the CellRange cr = MyFlexGrid.GetMergedRange(r, c);
// steprtb can have associated usages/transitions records removed from the database. if (cr.r1 == r && cr.c1 == c)
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
MatchCollection matches = Regex.Matches((string)MyFlexGrid[r, c], lookFor);
for (int i = matches.Count - 1; i >= 0; i--)
{ {
Match m = matches[i]; if (MyFlexGrid[r, c] != null)
if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString() == "ReferencedObject")
{ {
Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline); // see if there are any links and save these so that any deleted ROs or transitions in the
Match myMatch = regRefObj.Match(m.Value); // steprtb can have associated usages/transitions records removed from the database.
if (myMatch.Success) string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
MatchCollection matches = Regex.Matches((string)MyFlexGrid[r, c], lookFor);
for (int i = matches.Count - 1; i >= 0; i--)
{ {
int usgid = int.Parse(myMatch.Groups[1].Value); Match m = matches[i];
RtfRoUsageList.Add(usgid); if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString() == "ReferencedObject")
} {
} Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline);
if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString().StartsWith("Transition")) Match myMatch = regRefObj.Match(m.Value);
{ if (myMatch.Success)
Regex regRefObj = new Regex(@"\#Link\:Transition[a-zA-Z]*\:([0-9]*) ([0-9]*) ([0-9]*)", RegexOptions.Singleline); {
Match myMatch = regRefObj.Match(m.Value); int usgid = int.Parse(myMatch.Groups[1].Value);
if (myMatch.Success) RtfRoUsageList.Add(usgid);
{ }
int tid = int.Parse(myMatch.Groups[2].Value); }
RtfTransList.Add(tid); if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString().StartsWith("Transition"))
{
Regex regRefObj = new Regex(@"\#Link\:Transition[a-zA-Z]*\:([0-9]*) ([0-9]*) ([0-9]*)", RegexOptions.Singleline);
Match myMatch = regRefObj.Match(m.Value);
if (myMatch.Success)
{
int tid = int.Parse(myMatch.Groups[2].Value);
RtfTransList.Add(tid);
}
}
} }
} }
} }
c = c + 1;
if (c == w)
{
c = 0;
r = r + 1;
}
} }
c = c + 1; }
if (c == w) else
{
// new roid is in flexgrid.roid. Compare to previous, if there was a previous. If there
// is a modify RO, then need to delete the existing rousage record because a new usage
// record will get created that contains the selected ROID.
Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline);
Match myMatch = regRefObj.Match(MyItemInfo.MyContent.Text);
if (myMatch.Success)
{ {
c = 0; int usgid = int.Parse(myMatch.Groups[1].Value);
r = r + 1; RoUsageInfo rui = RoUsageInfo.Get(usgid);
if (rui.ROID == MyFlexGrid.ROID)RtfRoUsageList.Add(usgid);
} }
} }
// compare ro usages & transitions from database and list from grid contents // compare ro usages & transitions from database and list from grid contents
@ -435,24 +482,62 @@ namespace Volian.Controls.Library
foreach (int dt in delTrans) Transition.Delete(dt); foreach (int dt in delTrans) Transition.Delete(dt);
} }
// now save the resulting Xml text, and the searchable text. bool success = FinishSave(srchtxt);
bool success = FinishSave(MyFlexGrid.GetSearchableText()); if (success && !MyFlexGrid.IsRoTable)
if (success)
{ {
MyStepRTB.FindAllLinks(); MyStepRTB.FindAllLinks();
MyStepRTB.OrigRTF = MyStepRTB.Rtf; MyStepRTB.OrigRTF = MyStepRTB.Rtf;
MyStepRTB.ClearUndo(); MyStepRTB.ClearUndo();
} }
} }
private string DoLinkForRoTable()
{
// if no ro has been defined yet, just return null
if (MyFlexGrid.ROID == null) return null;
ContentRoUsage rousg = null;
using (Item itm = MyItemInfo.Get())
{
using (RODb rodb = RODb.GetJustRoDb(MyFlexGrid.RODbId))
{
string padroid = (MyFlexGrid.ROID.Length <= 12) ? MyFlexGrid.ROID + "0000" : MyFlexGrid.ROID;
rousg = itm.MyContent.ContentRoUsages.Add(MyFlexGrid.ROID, rodb);
}
itm.Save();
}
MyItemInfo.MyContent.RefreshContentRoUsages();
return string.Format(@"#Link:ReferencedObject:{0} {1} {2}", rousg.ROUsageID, MyFlexGrid.ROID, MyFlexGrid.RODbId);
}
private void ConvertTableToGrid(string valtext)
{
VE_Font vefont = this.MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Table.Font;
Font GridFont = new Font(vefont.Family, (float)vefont.Size);
MyFlexGrid.Font = GridFont;
MyFlexGrid.ParseTableFromText(valtext);
MyFlexGrid.AutoSizeCols();
MyFlexGrid.AutoSizeRows();
MyFlexGrid.MakeRTFcells();
}
private bool FinishSave(string searchableText) private bool FinishSave(string searchableText)
{ {
// Just in case if the grid was in a mode to change sizes, clear out that setting
// in the grid:
MyFlexGrid.Cols.Fixed = 0;
MyFlexGrid.Rows.Fixed = 0;
string xml = MyFlexGrid.GetXMLData(); string xml = MyFlexGrid.GetXMLData();
using (Item itm = MyItemInfo.Get()) using (Item itm = MyItemInfo.Get())
{ {
itm.MyContent.MyGrid.Data = xml; itm.MyContent.MyGrid.Data = xml;
itm.MyContent.Text = searchableText; // if this is the initial save of an ro table, then the 'DoLinkForRoTable' will
// what about the 'config' for ro tables. // create the usage for it. this code gets run on modify of the ro table and also
// on exit of the griditem. We don't want to save the ro usage again, if it's already
// been saved.
if (MyFlexGrid.IsRoTable && MyFlexGrid.ROID != null && itm.MyContent.ContentRoUsageCount < 1)
{
searchableText = string.Format(@"\v<START]\v0 {0} \v {1}[END>\v0 ", searchableText, DoLinkForRoTable());
itm.MyContent.Text = searchableText;
}
if (!MyFlexGrid.IsRoTable)itm.MyContent.Text = searchableText;
itm.Save(); itm.Save();
MyItemInfo.MyContent.MyGrid.ResetContent(itm.MyContent.MyGrid); MyItemInfo.MyContent.MyGrid.ResetContent(itm.MyContent.MyGrid);
} }
@ -481,7 +566,14 @@ namespace Volian.Controls.Library
MyFlexGrid.Focus(); MyFlexGrid.Focus();
ScrollToCenter(); ScrollToCenter();
} }
public override StepRTB MyStepRTB { get { return MyFlexGrid.TableCellEditor; } } public StepRTB DisplayRoStepRTB;
public override StepRTB MyStepRTB
{
get
{
return MyFlexGrid.TableCellEditor;
}
}
public override DialogResult ReplaceText(string rpltxt, string fndstr, bool caseSensitive, bool matchWholeWord, bool reverse, bool prompt, IWin32Window fndrpldlg) public override DialogResult ReplaceText(string rpltxt, string fndstr, bool caseSensitive, bool matchWholeWord, bool reverse, bool prompt, IWin32Window fndrpldlg)
{ {
int r = MyFlexGrid.Row; int r = MyFlexGrid.Row;
@ -756,10 +848,26 @@ namespace Volian.Controls.Library
public override void SetupHeader(ItemInfo itemInfo) { ;} // tables do not have headers public override void SetupHeader(ItemInfo itemInfo) { ;} // tables do not have headers
public override void ShowExpanded() {;} public override void ShowExpanded() {;}
public override void SetText() public override void SetText()
{ {
// if this is an RO Table, regenerate xml. This is done in the case that
// the rotable was updated by the ro editor.
//if (MyFlexGrid.IsRoTable) RefreshGridData();
RefreshDisplay(false); RefreshDisplay(false);
IdentifyMe(false); IdentifyMe(false);
} }
private void RefreshGridData()
{
string ROID = MyFlexGrid.ROID;
int rodbid = MyFlexGrid.RODbId;
MyFlexGrid.Clear();
ROFSTLookup MyROFSTLookup = MyItemInfo.MyDocVersion.DocVersionAssociations[0].MyROFst.ROFSTLookup;
ConvertTableToGrid(MyROFSTLookup.GetRoValue(ROID));
MyFlexGrid.RODbId = rodbid;
MyFlexGrid.ROID = ROID;
MyFlexGrid.IsRoTable = true;
SaveContents();
}
public override void SetExpandAndExpander(ItemInfo itemInfo) { CanExpand = false; } // can't expand a table public override void SetExpandAndExpander(ItemInfo itemInfo) { CanExpand = false; } // can't expand a table
#endregion #endregion
} }