From b1da81e65f663507679ebe265e9f83fc6c20b728 Mon Sep 17 00:00:00 2001 From: Kathy Date: Fri, 24 Jul 2009 11:54:20 +0000 Subject: [PATCH] --- PROMS/Volian.Controls.Library/DSOTabPanel.cs | 29 +++++- PROMS/Volian.Controls.Library/StepItem.cs | 4 + .../StepItem.designer.cs | 1 + PROMS/Volian.Controls.Library/StepPanel.cs | 18 +++- PROMS/Volian.Controls.Library/StepRTB.cs | 94 ++++++++++++++----- 5 files changed, 119 insertions(+), 27 deletions(-) diff --git a/PROMS/Volian.Controls.Library/DSOTabPanel.cs b/PROMS/Volian.Controls.Library/DSOTabPanel.cs index ad5f62bb..575c3f89 100644 --- a/PROMS/Volian.Controls.Library/DSOTabPanel.cs +++ b/PROMS/Volian.Controls.Library/DSOTabPanel.cs @@ -75,6 +75,7 @@ namespace Volian.Controls.Library { get { return _MyDSOFramer.IsDirty; } } + public E_ViewMode PanelViewEditMode = E_ViewMode.Edit; #endregion //private frmPG _frm = null; #region Constructors @@ -231,6 +232,12 @@ namespace Volian.Controls.Library /// void _MyDSOFramer_OnSaveCompleted(object sender, AxDSOFramer._DFramerCtlEvents_OnSaveCompletedEvent e) { + // Unfortunately, the only way to handle view mode for DSO Framer is to not save. + if (PanelViewEditMode == E_ViewMode.View) + { + MessageBox.Show("Currently in VIEW mode,\r\n cannot Save " + _MyDisplayTabItem.Tooltip); + return; + } MyDSOFile.FullName = GetReflectiveProperty(_MyDSOFramer.ActiveDocument, "FullName"); MyDSOFile.SaveFile(); } @@ -245,7 +252,7 @@ namespace Volian.Controls.Library { this.Enter -= new EventHandler(DSOTabPanel_Enter); this.Leave -= new EventHandler(DSOTabPanel_Leave); - SaveDirty(); + // SaveDirty(); // SaveDirty happens in CloseDSO(bool) } catch (Exception ex) { @@ -264,6 +271,19 @@ namespace Volian.Controls.Library { if (IgnoreEnter) return; _MyTransparentPanel.SendToBack(); + + // Set whether this worddoc is in view/edit mode by checking whether the + // procedure is in view/edit mode (based on the steppanel. This occurs on + // the enter event so that the mode is determined any time this panel becomes + // active. + // find steptabpanel and its view/edit. If it doesn't have a steptabpanel + // use default - edit. Later when we have ownership, need to use that. + PanelViewEditMode = E_ViewMode.Edit; // default to edit + if (MyDisplayTabItem.MyItemInfo != null) // lib doc with no associated active procedure defaults to edit + { + StepTabPanel stpanel = _MyDisplayTabControl.GetProcedureTabPanel(MyDisplayTabItem.MyItemInfo); + PanelViewEditMode = (stpanel==null)? E_ViewMode.Edit : stpanel.MyStepPanel.PanelViewEditMode; + } try { _MyDSOFramer.EventsEnabled = true; @@ -313,7 +333,12 @@ namespace Volian.Controls.Library { if (_MyDSOFramer.IsDirty) { - // TODO: Should be based upon Item rather than Document. + // Unfortunately, the only way to handle view mode for DSO Framer is to not save. + if (PanelViewEditMode == E_ViewMode.View) + { + MessageBox.Show("Currently in VIEW mode,\r\n cannot Save " + _MyDisplayTabItem.Tooltip); + return false; + } //if (MessageBox.Show("Save changes to " + _MyDisplayTabItem.MyItemInfo.TabTitle + "\r\n" + _MyDisplayTabItem.MyItemInfo.TabToolTip, "Document has Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) if (MessageBox.Show("Save changes to " + _MyDisplayTabItem.Text + "\r\n" + _MyDisplayTabItem.Tooltip, "Document has Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) return SaveDSO(); diff --git a/PROMS/Volian.Controls.Library/StepItem.cs b/PROMS/Volian.Controls.Library/StepItem.cs index 9e0d1025..2e5492ae 100644 --- a/PROMS/Volian.Controls.Library/StepItem.cs +++ b/PROMS/Volian.Controls.Library/StepItem.cs @@ -1365,6 +1365,10 @@ namespace Volian.Controls.Library { _MyStepPanel.CursorMovement(sender as StepRTB, args.CursorLocation, args.Key); } + private void _MyStepRTB_ModeChange(object sender, StepRTBModeChangeEventArgs args) + { + _MyStepPanel.OnModeChange(sender as StepRTB, args); + } #endregion // Event Handlers #region Private Methods /// diff --git a/PROMS/Volian.Controls.Library/StepItem.designer.cs b/PROMS/Volian.Controls.Library/StepItem.designer.cs index a3884716..47747db9 100644 --- a/PROMS/Volian.Controls.Library/StepItem.designer.cs +++ b/PROMS/Volian.Controls.Library/StepItem.designer.cs @@ -74,6 +74,7 @@ namespace Volian.Controls.Library this._MyStepRTB.CursorKeyPress += new Volian.Controls.Library.StepRTBCursorKeysEvent(this._MyStepRTB_CursorKeyPress); this._MyStepRTB.CursorMovement += new Volian.Controls.Library.StepRTBCursorMovementEvent(this._MyStepRTB_CursorMovement); this._MyStepRTB.LinkModifyRO += new Volian.Controls.Library.StepRTBLinkEvent(this._StepRTB_LinkModifyRO); + this._MyStepRTB.ModeChange += new Volian.Controls.Library.StepRTBModeChangeEvent(this._MyStepRTB_ModeChange); // // _MyvlnExpander // diff --git a/PROMS/Volian.Controls.Library/StepPanel.cs b/PROMS/Volian.Controls.Library/StepPanel.cs index 94341c94..7fd7bdb1 100644 --- a/PROMS/Volian.Controls.Library/StepPanel.cs +++ b/PROMS/Volian.Controls.Library/StepPanel.cs @@ -57,6 +57,10 @@ namespace Volian.Controls.Library private Color _TabColor = Color.White; private Color _PanelColor = Color.White; #endif + // 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; internal string _LastAdjust=""; private bool _ShowLines = true; private Graphics _MyGraphics = null; @@ -106,6 +110,14 @@ namespace Volian.Controls.Library if (AttachmentClicked != null) AttachmentClicked(sender, args); else MessageBox.Show(args.MyStepItem.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); + } #endregion #region Link Events /// @@ -312,8 +324,8 @@ namespace Volian.Controls.Library _SelectedStepRTB = value; if (value != null) { - _SelectedStepRTB.ViewRTB = false; - _SelectedStepRTB.RTBFillIn(true); + _SelectedStepRTB.ViewRTB = PanelViewEditMode == E_ViewMode.View; + _SelectedStepRTB.RTBFillIn(PanelViewEditMode != E_ViewMode.View); if (_SelectedItemInfo.ItemID != value.MyItemInfo.ItemID) SelectedItemInfo = value.MyItemInfo; } @@ -945,6 +957,7 @@ namespace Volian.Controls.Library _MyStepItem = myStepItem; } } + public partial class StepPanelLinkEventArgs : EventArgs { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); @@ -977,4 +990,5 @@ namespace Volian.Controls.Library public delegate void StepPanelLinkEvent(object sender, StepPanelLinkEventArgs args); public delegate void StepPanelAttachmentEvent(object sender, StepPanelAttachmentEventArgs args); public delegate void StepRTBLinkEvent(object sender, StepPanelLinkEventArgs args); + public delegate void StepPanelModeChangeEvent(object sender, StepRTBModeChangeEventArgs args); } diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index 07dce600..fc449e0b 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -12,9 +12,11 @@ using VEPROMS.CSLA.Library; namespace Volian.Controls.Library { + public delegate void StepRTBEvent(object sender, EventArgs args); public delegate void StepRTBCursorKeysEvent(object sender, KeyEventArgs args); public delegate void StepRTBCursorMovementEvent(object sender, StepRTBCursorMovementEventArgs args); + public delegate void StepRTBModeChangeEvent(object sender, StepRTBModeChangeEventArgs args); //public delegate void StepRTBMouseWheelEvent(object sender, MouseEventArgs args); public partial class StepRTB : RichTextBox , IStepRTB { @@ -44,6 +46,13 @@ namespace Volian.Controls.Library { if (CursorMovement != null) CursorMovement(sender, args); } + public event StepRTBModeChangeEvent ModeChange; + private void OnModeChange(object sender, StepRTBModeChangeEventArgs args) + { + //_MyModeChangeEventArgs = args; + if (ModeChange != null) ModeChange(sender, args); + else MessageBox.Show("StepRTB - no mode change defined"); + } //public event StepRTBMouseWheelEvent MouseWheel; //private void OnMouseWheel(object sender, MouseEventArgs args) //{ @@ -91,7 +100,12 @@ namespace Volian.Controls.Library get { return _MyStepItem; } set { _MyStepItem = value; } } - private bool _IsDirty = false; + // _IsDirty compares the original rtf to the current rtf from the + // richtextbox to see if a change was made. + private bool _IsDirty + { + get { return _origRTF != Rtf; } + } private bool _InitializingRTB; private IContainer _Container = null; private string _MyClassName=string.Empty; @@ -128,10 +142,11 @@ namespace Volian.Controls.Library if (value != null) { RTBFillIn(!ViewRTB); + //ViewRTB = MyStepItem.MyStepPanel.PanelViewEditMode == E_ViewMode.View; } } } - + private string _origRTF; public void RTBFillIn(bool edit) { _InitializingRTB = true; @@ -156,9 +171,10 @@ namespace Volian.Controls.Library RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT); AddRtfText(vlntxt.StartText); AddRtfStyles(); + // set readonly based on initial modes, however, these may change if + // user selected view mode. ReadOnly = !(EpMode == E_EditPrintMode.Edit && VwMode == E_ViewMode.Edit); - _InitializingRTB = false; - _IsDirty = false; + if (!ReadOnly && !edit) ReadOnly = true; ClearUndo(); RightMargin = Width; // figure out if needs outlined, depends on table/figure type @@ -184,7 +200,9 @@ namespace Volian.Controls.Library indchar++; } AddEventHandlers(); - } + } + _origRTF = Rtf; + _InitializingRTB = false; _MyItemInfo.MyConfig.PropertyChanged += new PropertyChangedEventHandler(MyConfig_PropertyChanged); } private bool _ProcessKeystrokes = true; @@ -356,15 +374,21 @@ namespace Volian.Controls.Library } #endregion #region ApplicationSupport - public void ToggleViewEdit() + public void ToggleEditView() { - ItemInfo tmp = MyItemInfo; - MyItemInfo = null; + SaveText(); + //ItemInfo tmp = MyItemInfo; + //MyItemInfo = null; ReadOnly = !ReadOnly; EpMode = ReadOnly ? E_EditPrintMode.Print : E_EditPrintMode.Edit; VwMode = ReadOnly ? E_ViewMode.View : E_ViewMode.Edit; + ViewRTB = ReadOnly; Clear(); - MyItemInfo = tmp; + RTBFillIn(!ViewRTB); + //MyItemInfo = tmp; + SelectionStart = 0; + SelectionLength = 0; + OnModeChange(this, new StepRTBModeChangeEventArgs(ViewRTB?E_ViewMode.View:E_ViewMode.Edit)); } public void InsertRO(string value, string link) { @@ -482,16 +506,14 @@ namespace Volian.Controls.Library public void SaveText() { if (ReadOnly) return; + if (ViewRTB) return; if (!_IsDirty) return; - if (_IsDirty) + bool success = _origDisplayText.Save((RichTextBox)this); + if (success) { - bool success = _origDisplayText.Save((RichTextBox)this); - if (success) - { - FindAllLinks(); - _IsDirty = false; - ClearUndo(); - } + FindAllLinks(); + _origRTF = Rtf; + ClearUndo(); } } public void SaveConfig() @@ -793,10 +815,14 @@ namespace Volian.Controls.Library if (LinkModifyRO != null) LinkModifyRO(sender, args); } #endregion - #region TextOrContents + #region TextAndContentsEvents void StepRTB_TextChanged(object sender, EventArgs e) { - _IsDirty = true; + if (_InitializingRTB) return; + // Was setting _IsDirty to true here, but this was getting called from + // 'dotnetbar' when text was NOT Changed. So _IsDirty was made into + // a property and compared original rtf versus current richtextbox's + // rtf. FindAllLinks(); } void StepRTB_ContentsResized(object sender, ContentsResizedEventArgs e) @@ -1449,8 +1475,8 @@ namespace Volian.Controls.Library { string str = Text; _LinkLocations = new List(); - MatchCollection matches = Regex.Matches(str, ""); - MatchCollection matchesRtf = Regex.Matches(Rtf, ""); + MatchCollection matches = Regex.Matches(str, @"", RegexOptions.Singleline); + MatchCollection matchesRtf = Regex.Matches(Rtf, "", RegexOptions.Singleline); LinkLocation thisLink = null; for (int i = 0; i < matches.Count; i++) //each (Match match in matches) { @@ -1881,7 +1907,14 @@ namespace Volian.Controls.Library lastIndex = m.Index + m.Length; // Calculate the beginning of the remaining text } sb.Append(line.Substring(lastIndex)); // Append the text following the last link - return sb.ToString(); + string result = sb.ToString(); + MatchCollection mcEnd = Regex.Matches(line, @"#Link.*?\[END>"); + result = result.Replace(@" 0) + { + result = result.Substring(0, mcEnd[0].Index - 1) + result.Substring(mcEnd[0].Index + mcEnd[0].Length); + } + return result; } private void ReplaceLinesInTable(bool withBorder) { @@ -1892,7 +1925,9 @@ namespace Volian.Controls.Library string lineAbove = RemoveLinkComments(Lines[row-1]); string lineBelow = RemoveLinkComments(Lines[row+1]); int rowOffset = GetFirstCharIndexFromLine(row); - MatchCollection matchCollection = Regex.Matches(line, @""); + MatchCollection matchCollection = Regex.Matches(line, @""); //, RegexOptions.Singleline); + if (matchCollection.Count == 0) matchCollection = Regex.Matches(line, @""); Match match = matchCollection.Count > 0 ? matchCollection[0] : null; int matchOffset = 0; for (int col = 1; col < rowWidth - 1; col++) @@ -1969,6 +2004,19 @@ namespace Volian.Controls.Library } #endregion } + public partial class StepRTBModeChangeEventArgs : EventArgs + { + private E_ViewMode _ViewMode; + public E_ViewMode ViewMode + { + get { return _ViewMode; } + set { _ViewMode = value; } + } + public StepRTBModeChangeEventArgs(E_ViewMode vmode) + { + _ViewMode = vmode; + } + } public class StepRTBCursorMovementEventArgs { private Point _CursorLocation;