This commit is contained in:
2011-02-08 11:32:53 +00:00
parent 989b5979a9
commit 7105a1cfb7
6 changed files with 1004 additions and 2581 deletions

View File

@@ -19,21 +19,25 @@ namespace Volian.Controls.Library
/// Procedure Item Info - Top ItemInfo
/// </summary>
private ItemInfo _MyProcedureItemInfo;
private E_ViewMode _VwMode = E_ViewMode.Edit;
public E_ViewMode VwMode
{
get { return _VwMode; }
set { _VwMode = value; }
}
// TODO: This is not correct. There should be a dictionary of Section Layouts
/// <summary>
/// Lookup Table to convert ItemInfo.ItemID to RTBItem
/// Lookup Table to convert ItemInfo.ItemID to EditItem
/// </summary>
internal Dictionary<int, RTBItem> _LookupRTBItems;
public RTBItem FindItem(ItemInfo itemInfo)
internal Dictionary<int, EditItem> _LookupEditItems;
public EditItem FindItem(ItemInfo itemInfo)
{
if (itemInfo == null) return null;
if (!_LookupRTBItems.ContainsKey(itemInfo.ItemID)) return null;
return _LookupRTBItems[itemInfo.ItemID];
if (!_LookupEditItems.ContainsKey(itemInfo.ItemID)) return null;
return _LookupEditItems[itemInfo.ItemID];
}
/// <summary>
/// Currently selected RichTextBox
/// </summary>
private StepRTB _SelectedStepRTB = null;
/// <summary>
/// Currently selected ItemInfo
/// </summary>
@@ -53,7 +57,7 @@ namespace Volian.Controls.Library
// Whether panel is in view or edit mode. Toggled from steprtb
// or set based on approval/multi-user (these two will be done
// later.
public E_ViewMode PanelViewEditMode = E_ViewMode.Edit;
//public E_ViewMode PanelViewEditMode = E_ViewMode.Edit;
internal string _LastAdjust="";
private bool _ShowLines = true;
private Graphics _MyGraphics = null;
@@ -61,7 +65,7 @@ namespace Volian.Controls.Library
#endregion
#region Item Events
/// <summary>
/// Occurs when the user clicks tab of a RTBItem
/// Occurs when the user clicks tab of a EditItem
/// </summary>
public event StepPanelEvent ItemClick;
/// <summary>
@@ -75,7 +79,7 @@ namespace Volian.Controls.Library
}
private bool ItemSelectionChangeShown = false; // This keeps OnItemSelectedChanged from being called twice when an item is selected.
/// <summary>
/// Occurs when the selected RTBItem changes
/// Occurs when the selected EditItem changes
/// </summary>
public event ItemSelectedChangedEvent ItemSelectedChanged;
/// <summary>
@@ -101,16 +105,16 @@ namespace Volian.Controls.Library
internal void OnAttachmentClicked(object sender, StepPanelAttachmentEventArgs args)
{
if (AttachmentClicked != null) AttachmentClicked(sender, args);
else MessageBox.Show(args.MyRTBItem.MyItemInfo.MyContent.MyEntry.MyDocument.DocumentTitle, "Unhandled Attachment Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
else MessageBox.Show(args.MyEditItem.MyItemInfo.MyContent.MyEntry.MyDocument.DocumentTitle, "Unhandled Attachment Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
// Edit/View mode change
public event StepPanelModeChangeEvent ModeChange;
internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
{
PanelViewEditMode = args.ViewMode;
ModeChange(sender, args);
}
//public event StepPanelModeChangeEvent ModeChange;
//internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
//{
// PanelViewEditMode = args.ViewMode;
// ModeChange(sender, args);
//}
// various selections from steptabribbon that need to filter up to frmveproms
// such as 'global search', 'bookmarks'
public event StepPanelTabDisplayEvent TabDisplay;
@@ -262,10 +266,10 @@ namespace Volian.Controls.Library
InactiveColor = PanelColor = BackColor;
foreach (Control ctrl in Controls)
{
if (ctrl.GetType() == typeof(RTBItem))
if (ctrl is EditItem)
{
RTBItem rtb = (RTBItem)ctrl;
rtb.BackColor = BackColor;
EditItem ei = (EditItem)ctrl;
ei.BackColor = BackColor;
}
}
}
@@ -278,11 +282,11 @@ namespace Volian.Controls.Library
private void ExpandAsNeeded(ItemInfo myItemInfo)
{
int id = myItemInfo.ItemID;
if (!_LookupRTBItems.ContainsKey(id)) // If the item is not currently displayed
if (!_LookupEditItems.ContainsKey(id)) // If the item is not currently displayed
ExpandAsNeeded((ItemInfo)myItemInfo.ActiveParent); // Expand it's parent
if (_LookupRTBItems.ContainsKey(id)) // Expanding Parent should have added it to _LookupRTBItems
if (_LookupEditItems.ContainsKey(id)) // Expanding Parent should have added it to _LookupEditItems
{
RTBItem itm = _LookupRTBItems[id];
EditItem itm = _LookupEditItems[id];
ItemInfo ii = myItemInfo.ActiveParent as ItemInfo;
if (itm.Visible == false && ii != null)
ExpandAsNeeded((ItemInfo)myItemInfo.ActiveParent);
@@ -309,10 +313,10 @@ namespace Volian.Controls.Library
//this.Scroll += new ScrollEventHandler(DisplayPanel_Scroll);
//// TIMING: DisplayItem.TimeIt("pMyItem Scroll");
Controls.Clear();
_LookupRTBItems = new Dictionary<int, RTBItem>();
_LookupEditItems = new Dictionary<int, EditItem>();
//// TIMING: DisplayItem.TimeIt("pMyItem Clear");
//SuspendLayout();
RTBItem tmpRTBItem = new RTBItem(_MyProcedureItemInfo, this, null, ChildRelation.None, false);
new RTBItem(_MyProcedureItemInfo, this, null, ChildRelation.None, false);
//ResumeLayout();
//// TIMING: DisplayItem.TimeIt("pMyItem End");
}
@@ -328,95 +332,14 @@ namespace Volian.Controls.Library
ExpandAsNeeded(SelectedItemInfo);
}
/// <summary>
/// Get or Set currently selected RichTextBox (StepRTB)
/// Currently selected StepRTB
/// </summary>
public StepRTB SelectedStepRTB
{
get { return _SelectedStepRTB; }
set
{
StepRTB lastRTB = _SelectedStepRTB;
if(value != null)
value.BackColor = ActiveColor; // Set the active color
if (lastRTB == value) return; // Same - No Change
//RHM ToDo: Why doesn't it have focus for copy Step/Paste
if (value != null) value.Focus();
if (lastRTB != null && lastRTB.BeingDisposed == false)
{
//_SelectedStepRTB.BackColor = InactiveColor;
//lastRTB.SetBackColor();
bool shouldDelete = !lastRTB.MyRTBItem.BeingRemoved && lastRTB.Text.Length == 0;
if (shouldDelete)
{
if (lastRTB.MyRTBItem.HasChildren)
{
if (value != null && value.MyItemInfo.HasAncestor(lastRTB.MyItemInfo))
{
shouldDelete = false;
}
else
{
DialogResult result = MessageBox.Show("This step does not have text but has substeps. Do you want to delete it and its substeps?", "Verify Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) shouldDelete = false;
}
}
}
if (shouldDelete)
{
float oldTop = lastRTB.MyRTBItem.Top;
RTBItem newFocus = lastRTB.MyRTBItem.DeleteItem();
float newTop = newFocus.Top;
lastRTB.MyRTBItem.Dispose();
newFocus.SetAllTabs();
// If the step being deleted appears above the step to recieve focus, find another step
// to use so that the steps are positioned properly (vertically)
if (oldTop < newTop)
{
if (newFocus.MyParentRTBItem != null)
{
if (newFocus.Top > newFocus.MyParentRTBItem.Top)
newFocus.MyParentRTBItem.AdjustLocation();
else if (newFocus.MyParentRTBItem.MyPreviousRTBItem != null &&
newFocus.Top > newFocus.MyParentRTBItem.MyPreviousRTBItem.Top)
newFocus.MyParentRTBItem.MyPreviousRTBItem.AdjustLocation();
else if (newFocus.MyParentRTBItem.MyParentRTBItem != null &&
newFocus.Top > newFocus.MyParentRTBItem.MyParentRTBItem.Top)
newFocus.MyParentRTBItem.MyParentRTBItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else if (newFocus.MyPreviousRTBItem != null)
newFocus.MyPreviousRTBItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else
newFocus.AdjustLocation();
}
else
{
lastRTB.SaveText(); // Save any changes to the text
lastRTB.SaveConfig(); // This may be redundant
//int selst = _SelectedStepRTB.SelectionStart;
lastRTB.RTBFillIn(false);
//_SelectedStepRTB.SetSelection(selst, 0);
//_SelectedStepRTB.SelectionStart=selst;
lastRTB.ViewRTB = true;
}
}
_SelectedStepRTB = value;
if (value != null)
{
_SelectedStepRTB.ViewRTB = PanelViewEditMode == E_ViewMode.View;
_SelectedStepRTB.RTBFillIn(PanelViewEditMode != E_ViewMode.View);
if (_SelectedItemInfo.ItemID != value.MyItemInfo.ItemID)
SelectedItemInfo = value.MyItemInfo;
}
if(lastRTB != null)
lastRTB.SetBackColor();
//vlnStackTrace.ShowStack("_DisplayRTB = {0}", _DisplayRTB.MyItem.ItemID);// Show StackTrace
}
}
//private StepRTB _SelectedStepRTB = null;
//public StepRTB SelectedStepRTB
//{
// get { return _SelectedStepRTB; }
// set { _SelectedStepRTB=value;}
//}
/// <summary>
/// Gets or Sets the SelectedItemInfo
/// Activates and Expands as necessary
@@ -431,8 +354,8 @@ namespace Volian.Controls.Library
int id = value.ItemID;
ExpandAsNeeded(value);
// reset the entire step panel if the item isn't found.
if (!_LookupRTBItems.ContainsKey(id)) Reset();
RTBItem itm = _LookupRTBItems[id];
if (!_LookupEditItems.ContainsKey(id)) Reset();
EditItem itm = _LookupEditItems[id];
ItemSelectionChangeShown = false;//OnItemSelectedChanged has not run yet.
itm.ItemSelect();
if (!ItemSelectionChangeShown) OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(itm));
@@ -446,21 +369,100 @@ namespace Volian.Controls.Library
set { _DisplayItemChanging = value; }
}
/// <summary>
/// Returns the SelectedRTBItem
/// Returns the SelectedEditItem
/// </summary>
public RTBItem SelectedRTBItem
private EditItem _SelectedEditItem;
public EditItem SelectedEditItem
{
get { return (_SelectedItemInfo != null) ? _LookupRTBItems[_SelectedItemInfo.ItemID] : null; }
get
{
return _SelectedEditItem;
//return (_SelectedItemInfo != null) ? _LookupEditItems[_SelectedItemInfo.ItemID] : null;
}
set
{
EditItem lastEI = _SelectedEditItem;
if (value != null) value.SetActive(); // Set the active color
if (lastEI == value) return; // Same - No Change
//RHM ToDo: Why doesn't it have focus for copy Step/Paste
if (value != null) value.SetFocus();
if (lastEI != null && lastEI.BeingDisposed == false)
{
bool shouldDelete = !lastEI.BeingRemoved && lastEI.Empty;
if (shouldDelete)
{
if (lastEI.HasChildren)
{
if (value != null && value.MyItemInfo.HasAncestor(lastEI.MyItemInfo))
{
shouldDelete = false;
}
else
{
DialogResult result = MessageBox.Show("This step does not have text but has substeps. Do you want to delete it and its substeps?", "Verify Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) shouldDelete = false;
}
}
}
if (shouldDelete)
{
float oldTop = lastEI.Top;
EditItem newFocus = lastEI.DeleteItem();
float newTop = newFocus.Top;
lastEI.Dispose();
newFocus.SetAllTabs();
// If the step being deleted appears above the step to recieve focus, find another step
// to use so that the steps are positioned properly (vertically)
if (oldTop < newTop)
{
if (newFocus.MyParentEditItem != null)
{
if (newFocus.Top > newFocus.MyParentEditItem.Top)
newFocus.MyParentEditItem.AdjustLocation();
else if (newFocus.MyParentEditItem.MyPreviousEditItem != null &&
newFocus.Top > newFocus.MyParentEditItem.MyPreviousEditItem.Top)
newFocus.MyParentEditItem.MyPreviousEditItem.AdjustLocation();
else if (newFocus.MyParentEditItem.MyParentEditItem != null &&
newFocus.Top > newFocus.MyParentEditItem.MyParentEditItem.Top)
newFocus.MyParentEditItem.MyParentEditItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else if (newFocus.MyPreviousEditItem != null)
newFocus.MyPreviousEditItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else
newFocus.AdjustLocation();
}
else
{
lastEI.SaveContents();
lastEI.RefreshDisplay(false);
}
}
_SelectedEditItem = value;
if (value != null)
{
_SelectedEditItem.RefreshDisplay(true);
if (_SelectedItemInfo.ItemID != value.MyItemInfo.ItemID)
SelectedItemInfo = value.MyItemInfo;
}
if (lastEI != null)
lastEI.IdentifyMe(false);
}
}
/// <summary>
/// Displays the selected RTBItem
/// Displays the selected EditItem
/// </summary>
public void ItemShow()
{
if (_SelectedItemInfo != null && SelectedRTBItem.MyStepRTB.BeingDisposed == false)
if (_SelectedItemInfo != null && SelectedEditItem.BeingDisposed == false)
{
SelectedRTBItem.ItemShow();
OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(SelectedRTBItem));
SelectedEditItem.ItemShow();
OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(SelectedEditItem));
}
}
public new void MouseWheel(MouseEventArgs e)
@@ -675,18 +677,18 @@ namespace Volian.Controls.Library
}
}
/// <summary>
/// Output all of the RTBItem controls to the log
/// Output all of the EditItem controls to the log
/// </summary>
private void ListControls()
{
// Walk through the controls and find the next control for each
if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("'Item','Next'");
foreach (Control control in Controls)
if (control.GetType() == typeof(RTBItem))
if (control is EditItem)
{
RTBItem rtb = (RTBItem)control;
RTBItem nxt = rtb.NextDownRTBItem;
if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("{0},{1}", rtb.MyID, nxt == null ? 0 : nxt.MyID);
EditItem ei = (EditItem)control;
EditItem nxt = ei.NextDownEditItem;
if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("{0},{1}", ei.MyID, nxt == null ? 0 : nxt.MyID);
}
}
#endregion
@@ -724,7 +726,7 @@ namespace Volian.Controls.Library
/// <param name="rtb">StepRTB</param>
/// <param name="position">Point</param>
/// <param name="arrow">E_ArrowKeys</param>
public void CursorMovement(StepRTB rtb, Point position, E_ArrowKeys arrow)
public void CursorMovement(EditItem ei, Point position, E_ArrowKeys arrow)
{
ItemInfo ii = null;
// The following lines are debug to check that the results of moving down and moving up are the same
@@ -733,40 +735,40 @@ namespace Volian.Controls.Library
{
case E_ArrowKeys.Up:
case E_ArrowKeys.CtrlUp:
ii = ArrowUp(rtb.MyItemInfo);
ii = ArrowUp(ei.MyItemInfo);
// The following lines are debug to check that the results of moving down and moving up are the same
//ix = ArrowDown(ii);
//Console.WriteLine("'Up',{0},{1},{2},{3}", rtb.MyItemInfo.ItemID, rtb.MyItemInfo.DBSequence, ii.DBSequence, ix.DBSequence);
if (ii != null) SelectedStepRTB = _LookupRTBItems[ii.ItemID].MyStepRTB;
if (ii != null) SelectedEditItem = _LookupEditItems[ii.ItemID];
break;
case E_ArrowKeys.Down:
case E_ArrowKeys.CtrlDown:
ii = MoveDown(rtb, ii);
ii = MoveDown(ei, ii);
break;
case E_ArrowKeys.Right:
case E_ArrowKeys.CtrlRight:
if (rtb.MyItemInfo.RNOs != null)
SelectedStepRTB = _LookupRTBItems[rtb.MyItemInfo.RNOs[0].ItemID].MyStepRTB;
if (ei.MyItemInfo.RNOs != null)
SelectedEditItem = _LookupEditItems[ei.MyItemInfo.RNOs[0].ItemID];
else
ii = MoveDown(rtb, ii);
ii = MoveDown(ei, ii);
break;
case E_ArrowKeys.Left:
case E_ArrowKeys.CtrlLeft:
if (!rtb.MyItemInfo.IsProcedure)
SelectedStepRTB = _LookupRTBItems[rtb.MyItemInfo.MyParent.ItemID].MyStepRTB;
if (!ei.MyItemInfo.IsProcedure)
SelectedEditItem = _LookupEditItems[ei.MyItemInfo.MyParent.ItemID];
break;
default:
break;
}
}
private ItemInfo MoveDown(StepRTB rtb, ItemInfo ii)
private ItemInfo MoveDown(EditItem ei, ItemInfo ii)
{
ii = ArrowDown(rtb.MyItemInfo);
ii = ArrowDown(ei.MyItemInfo);
// The following lines are debug to check that the results of moving down and moving up are the same
//ix = ArrowUp(ii);
//Console.WriteLine("'Down',{0},{1},{2},{3}", rtb.MyItemInfo.ItemID, rtb.MyItemInfo.DBSequence, ii.DBSequence, ix.DBSequence);
if (ii != null) SelectedStepRTB = _LookupRTBItems[ii.ItemID].MyStepRTB;
if (ii != null) SelectedEditItem = _LookupEditItems[ii.ItemID];
return ii;
}
private ItemInfo ArrowUp(ItemInfo ii)
@@ -831,9 +833,9 @@ namespace Volian.Controls.Library
}
return null;
}
internal void StepCursorKeys(StepRTB rtb, KeyEventArgs keyargs)
internal void StepCursorKeys(EditItem ei, KeyEventArgs keyargs)
{
ItemInfo ii = rtb.MyItemInfo;
ItemInfo ii = ei.MyItemInfo;
if (ii.IsSection || ii.IsProcedure) return;
while (!ii.IsHigh)
{
@@ -857,7 +859,7 @@ namespace Volian.Controls.Library
break;
}
if (ii == null) return;
SelectedStepRTB = _LookupRTBItems[ii.ItemID].MyStepRTB;
SelectedEditItem = _LookupEditItems[ii.ItemID];
}
#endregion
}
@@ -1019,11 +1021,11 @@ namespace Volian.Controls.Library
}
public partial class StepPanelEventArgs
{
private RTBItem _MyRTBItem;
public RTBItem MyRTBItem
private EditItem _MyEditItem;
public EditItem MyEditItem
{
get { return _MyRTBItem; }
set { _MyRTBItem = value; }
get { return _MyEditItem; }
set { _MyEditItem = value; }
}
private MouseEventArgs _MyMouseEventArgs;
public MouseEventArgs MyMouseEventArgs
@@ -1032,9 +1034,9 @@ namespace Volian.Controls.Library
set { _MyMouseEventArgs = value; }
}
public StepPanelEventArgs(RTBItem myRTBItem, MouseEventArgs myMouseEventArgs)
public StepPanelEventArgs(EditItem myEditItem, MouseEventArgs myMouseEventArgs)
{
_MyRTBItem = myRTBItem;
_MyEditItem = myEditItem;
_MyMouseEventArgs = myMouseEventArgs;
}
}
@@ -1046,45 +1048,44 @@ namespace Volian.Controls.Library
get { return _MyItemInfo; }
set { _MyItemInfo = value; }
}
private RTBItem _MyRTBItem = null;
public RTBItem MyRTBItem
private EditItem _MyEditItem = null;
public EditItem MyEditItem
{
get { return _MyRTBItem; }
set { _MyRTBItem = value; }
get { return _MyEditItem; }
set { _MyEditItem = value; }
}
public ItemSelectedChangedEventArgs(ItemInfo myItemInfo)
{
_MyItemInfo = myItemInfo;
}
public ItemSelectedChangedEventArgs(RTBItem myRTBItem)
public ItemSelectedChangedEventArgs(EditItem myEditItem)
{
_MyItemInfo = myRTBItem.MyItemInfo;
_MyRTBItem = myRTBItem;
_MyItemInfo = myEditItem.MyItemInfo;
_MyEditItem = myEditItem;
}
}
public partial class StepPanelAttachmentEventArgs
{
private RTBItem _MyRTBItem;
public RTBItem MyRTBItem
private EditItem _MyEditItem;
public EditItem MyEditItem
{
get { return _MyRTBItem; }
set { _MyRTBItem = value; }
get { return _MyEditItem; }
set { _MyEditItem = value; }
}
public StepPanelAttachmentEventArgs(RTBItem myRTBItem)
public StepPanelAttachmentEventArgs(EditItem myEditItem)
{
_MyRTBItem = myRTBItem;
_MyEditItem = myEditItem;
}
}
public partial class StepPanelLinkEventArgs : EventArgs
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private RTBItem _LinkedRTBItem;
public RTBItem LinkedRTBItem
{
get { return _LinkedRTBItem; }
//set { _LinkedRTBItem = value; }
}
//private EditItem _LinkedEditItem;
//public EditItem LinkedEditItem
//{
// get { return _LinkedEditItem; }
//}
private string _LinkInfoText;
public string LinkInfoText
{
@@ -1095,9 +1096,9 @@ namespace Volian.Controls.Library
{
get { return _MyLinkText;}
}
public StepPanelLinkEventArgs(RTBItem linkedRTBItem, string linkInfoText)
public StepPanelLinkEventArgs(string linkInfoText)
{
_LinkedRTBItem = linkedRTBItem;
//_LinkedEditItem = linkedEditItem;
_LinkInfoText = linkInfoText;
_MyLinkText = new LinkText(_LinkInfoText);
//if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("\r\n LinkInfo '{0}'\r\n", linkInfo.LinkText);