Keyboard shortcut logic

This commit is contained in:
2009-11-17 14:41:08 +00:00
parent 130be66c63
commit 4660abc0b6
4 changed files with 242 additions and 24 deletions

View File

@@ -45,6 +45,8 @@ namespace Volian.Controls.Library
private ItemInfo MyItemInfo
{ get { return _MyStepRTB.MyItemInfo; } }
private DevComponents.DotNetBar.ButtonItem _DefaultContextMenu;
private int _MyLastFormatID = -1;
private StepRTB _MyStepRTB;
public StepRTB MyStepRTB
@@ -60,10 +62,12 @@ namespace Volian.Controls.Library
{
case E_FieldToEdit.StepText:
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMRtfEdit);
_DefaultContextMenu = btnCMRtfEdit;
break;
case E_FieldToEdit.Text:
case E_FieldToEdit.Number:
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMRtfEdit3);
_DefaultContextMenu = btnCMRtfEdit3;
break;
default:
break;
@@ -93,12 +97,13 @@ namespace Volian.Controls.Library
BuildSymbolGallery(sl, galleryContainerSymbolsCM);
BuildSymbolGallery(sl, galleryContainerSymbolsCM3);
}
SetButtonAndMenuEnabling();
SetButtonAndMenuEnabling(true);
_MyLastFormatID = MyItemInfo.ActiveFormat.FormatID;
}
}
}
private void BuildSymbolGallery(SymbolList sl, DevComponents.DotNetBar.GalleryContainer gc)
{
foreach (Symbol sym in sl)
@@ -126,7 +131,7 @@ namespace Volian.Controls.Library
void _MyStepRTB_ModeChange(object sender, StepRTBModeChangeEventArgs args)
{
SetButtonAndMenuEnabling();
SetButtonAndMenuEnabling(true);
}
#endregion
#region Constructor
@@ -169,8 +174,8 @@ namespace Volian.Controls.Library
}
void MyStepRTB_SelectionChanged(object sender, EventArgs e)
{
//Console.WriteLine(string.Format("StepTabRibbon: In MyStepRTB_SelectionChanged, Selected Text = {0}",MyStepRTB.SelectedText));
SetButtonAndMenuEnabling();
//Console.WriteLine(string.Format("StepTabRibbon: In MyStepRTB_SelectionChanged, Selected Text = {0}", MyStepRTB.SelectedText));
SetButtonAndMenuEnabling(false);
}
void btnInsStep_Click(object sender, EventArgs e)
{
@@ -260,7 +265,7 @@ namespace Volian.Controls.Library
btnDelelete.Enabled = btnDelStep.Enabled = setting;
btnInsAftH.Enabled = btnInsBefH.Enabled = setting;
}
private void SetButtonAndMenuEnabling()
private void SetButtonAndMenuEnabling(bool docontextmenus)
{
if (_MyStepRTB.FieldToEdit != E_FieldToEdit.StepText)
return; // No need to change menu that does not get used
@@ -306,9 +311,9 @@ namespace Volian.Controls.Library
btnCMEditTran.Enabled = false;
btnCMEditRO.Enabled = false;
}
SetStepButtonAndMenuEnabling();
SetStepButtonAndMenuEnabling(docontextmenus);
}
private void SetStepButtonAndMenuEnabling()
private void SetStepButtonAndMenuEnabling(bool docontextmenus)
{
btnInsPgBrk.Checked = false;
// see if manual page break - only available on HLS
@@ -360,17 +365,28 @@ namespace Volian.Controls.Library
btnInsTable.SubItems.Clear();
btnInsSubstep.SubItems.Clear();
if (docontextmenus)
{
btnCMInsHLS.SubItems.Clear();
btnCMInsCaution.SubItems.Clear();
btnCMInsNote.SubItems.Clear();
btnCMInsFigure.SubItems.Clear();
btnCMInsTable.SubItems.Clear();
btnCMInsSubStps.SubItems.Clear();
btnCMInsRNO.SubItems.Clear();
}
// if (rno is enabled, set the tag:
if (btnInsRNO.Enabled)
btnInsRNO.Tag = string.Format("{0} {1}", (int)E_FromTypes.RNOs, MyStepItem.MyItemInfo.ActiveFormat.PlantFormat.FormatData.GetIndexFromType("RNOType"));
// add subitems depending on whether parent type is enabled:
if (btnInsHLS.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.HLS, sd, btnInsHLS, 0);
if (btnInsCaut.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Caution, sd, btnInsCaut, (int)E_FromType.Caution);
if (btnInsNote.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Note, sd, btnInsNote, (int)E_FromType.Note);
if (btnInsFig.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Fig, sd, btnInsFig, (int)E_FromType.Table);
if (btnInsTable.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Table, sd, btnInsTable, (int)E_FromType.Table);
if (btnInsSubstep.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Substep, sd, btnInsSubstep, (int)E_FromType.Step);
if (btnInsHLS.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.HLS, sd, btnInsHLS, 0, btnCMInsHLS, docontextmenus);
if (btnInsCaut.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Caution, sd, btnInsCaut, (int)E_FromType.Caution, btnCMInsCaution, docontextmenus);
if (btnInsNote.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Note, sd, btnInsNote, (int)E_FromType.Note, btnCMInsNote, docontextmenus);
if (btnInsFig.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Fig, sd, btnInsFig, (int)E_FromType.Table, btnCMInsFigure, docontextmenus);
if (btnInsTable.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Table, sd, btnInsTable, (int)E_FromType.Table, btnCMInsTable, docontextmenus);
if (btnInsSubstep.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.Substep, sd, btnInsSubstep, (int)E_FromType.Step, btnCMInsSubStps, docontextmenus);
if (btnInsRNO.Enabled) GalleryForSubTypes(MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList.RNO, sd, btnInsRNO, 0, btnCMInsRNO, docontextmenus);
btnInsTrans.Enabled = btnCMTransition.Enabled = btnInsRO.Enabled = btnCMRO.Enabled = true;
}
@@ -382,7 +398,8 @@ namespace Volian.Controls.Library
/// <param name="sdc">StepData: find subtypes related to this</param>
/// <param name="selType">StepData: this should be selected button</param>
/// <param name="btn">DevComponents.DotNetBar.ButtonItem: if items in the gallery, add gallery to this button</param>
private void GalleryForSubTypes(StepData sdc, StepData selType, DevComponents.DotNetBar.ButtonItem btn, int fromtype)
/// <param name="cmbtn">DevComponents.DotNetBar.ButtonItem: if items in the gallery, add btns to context menu</param>
private void GalleryForSubTypes(StepData sdc, StepData selType, DevComponents.DotNetBar.ButtonItem btn, int fromtype, DevComponents.DotNetBar.ButtonItem cmbtn, bool docontextmenus)
{
int cursel = -1;
// The first argument (boolean) in StepGetLevelTypes provides the option to get a complete list of step types
@@ -392,6 +409,7 @@ namespace Volian.Controls.Library
List<StepDataRetval> sdl = MyItemInfo.ActiveFormat.PlantFormat.FormatData.StepGetLevelTypes(getall, sdc, ref cursel, selType.Type, MyItemInfo);
if (sdl != null && sdl.Count > 0)
{
Char kt = 'A'; // start with letter A for KeyTips
foreach (StepDataRetval sdr in sdl)
{
bool addit = true;
@@ -414,22 +432,59 @@ namespace Volian.Controls.Library
bi.Text = sdr.Name;
bi.Tag = string.Format("{0} {1}", fromtype, sdr.Index); // index of type to insert it when button is clicked
bi.Checked = (sd.Type == selType.Type);
if (docontextmenus)
{
DevComponents.DotNetBar.ButtonItem cmbi = new DevComponents.DotNetBar.ButtonItem("cmbtn" + sd.Type, sd.Type);
cmbi.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.TextOnlyAlways;
cmbi.Text = sdr.Name;
cmbi.Tag = string.Format("{0} {1}", fromtype, sdr.Index); // index of type to insert it when button is clicked
cmbi.Checked = (sd.Type == selType.Type);
cmbi.Click += new System.EventHandler(btnInsStep_Click);
cmbtn.SubItems.Add(cmbi);
}
if (MyItemInfo.IsHigh && hlsSubType != -1 && sdr.Index == hlsSubType) bi.Checked = true;
bi.Click += new System.EventHandler(btnInsStep_Click);
// Assign only A-Z to the KeyTips in the list (i.e. assign only the first 24 in the list)
// Note that KeyTips logic support only single characters at this level (can't have 'AA' for example)
if (kt != '0')
{
bi.KeyTips = kt.ToString();
if (kt == 'Z')
kt = '0';
else
kt++;
}
btn.SubItems.Add(bi);
}
}
// if only 1, be sure event exists on button to insert item & if more than 1 remove event because
// we want the drop down to appear.
btn.Click -= new System.EventHandler(btnInsStep_Click);
if (btn.Name != "btnInsRNO")
btn.Click -= new System.EventHandler(btnInsStep_Click);
if (docontextmenus)
cmbtn.Click -= new System.EventHandler(btnInsStep_Click);
if (btn.SubItems.Count == 1)
{
btn.SubItems.Clear();
btn.Tag = string.Format("{0} {1}", fromtype, sdc.Index);
btn.Click += new System.EventHandler(btnInsStep_Click);
if (btn.Name != "btnInsRNO")
{
btn.Tag = string.Format("{0} {1}", fromtype, sdc.Index);
btn.Click += new System.EventHandler(btnInsStep_Click);
}
if (docontextmenus)
{
cmbtn.SubItems.Clear();
DevComponents.DotNetBar.ButtonItem cmbi = new DevComponents.DotNetBar.ButtonItem("cmbtn" + sdc.Type, sdc.Type);
cmbi.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.TextOnlyAlways;
cmbi.Text = btn.Text;
if (btn.Name == "btnInsRNO")
cmbi.Tag = btn.Tag;
else
cmbi.Tag = string.Format("{0} {1}", fromtype, sdc.Index); // index of type to insert it when button is clicked
cmbi.Click += new System.EventHandler(btnInsStep_Click);
cmbtn.SubItems.Add(cmbi);
}
}
//else
// btn.Click -= new System.EventHandler(btnInsStep_Click);
}
}
#endregion
@@ -439,8 +494,9 @@ namespace Volian.Controls.Library
DevComponents.DotNetBar.ButtonItem b = (DevComponents.DotNetBar.ButtonItem)sender;
_MyStepRTB.InsertSymbol(Convert.ToInt32(b.Tag));
}
private void btnInsPgBrk_Click(object sender, EventArgs e)
public void btnInsPgBrk_Click(object sender, EventArgs e)
{
rtabInsert.Select();
if (MyItemInfo.IsProcedure || MyItemInfo.IsSection) return;
// toggle manual page break
@@ -707,9 +763,6 @@ namespace Volian.Controls.Library
private void btnBookmarks_Click(object sender, EventArgs e)
{
//_RibbonControl.KeyTipsEnabled = true;
//SendKeys.Send("{F10}");
StepPanelTabDisplayEventArgs args = new StepPanelTabDisplayEventArgs("Bookmarks");
MyStepItem.MyStepPanel.OnTabDisplay(sender, args);
}
@@ -726,7 +779,7 @@ namespace Volian.Controls.Library
MyStepItem.MyStepPanel.OnTabDisplay(sender, args);
}
private void btnAnnots_Click(object sender, EventArgs e)
public void btnAnnots_Click(object sender, EventArgs e)
{
StepPanelTabDisplayEventArgs args = new StepPanelTabDisplayEventArgs("Annots");
MyStepItem.MyStepPanel.OnTabDisplay(sender, args);
@@ -769,6 +822,56 @@ namespace Volian.Controls.Library
}
}
private void btnCMIns_PopupClose(object sender, EventArgs e)
{
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, _DefaultContextMenu);
}
public void ShortCutContextMenu(string menuName)
{
bool displayMenu = true;
switch (menuName)
{
case "InsHLS":
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsHLS);
break;
case "InsRNO":
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsRNO);
break;
case "InsSubStps":
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsSubStps);
break;
case "InsCaution":
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsCaution);
break;
case "InsNote":
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsNote);
break;
case "InsTable":
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsTable);
break;
case "InsFigure":
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsFigure);
break;
default:
displayMenu = false;
break;
}
if (displayMenu)
{
SendKeys.Send("+{F10}{DOWN}"); // Display Context menu
}
}
private void btnSpell_Click(object sender, EventArgs e)
{
MessageBox.Show("Functionality not available.", "Spell Check");
}
private void btnFindRplDlg_Click(object sender, EventArgs e)
{
MessageBox.Show("Functionality not available.", "Find/Replace");
}
}
public enum E_FieldToEdit { StepText, Text, Number };