Keyboard shortcut logic

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

View File

@ -435,6 +435,45 @@ namespace Volian.Controls.Library
{
AddText(txt);
}
private void ToggleCase()
{
char type = 'l';
// do not change case on linked text
RangeStatus rs = FindRangeStatus();
string tmp = null;
if (rs != RangeStatus.NoContainedLinks)
{
int start = SelectionStart;
int ostart = SelectionStart;
int end = SelectionStart + SelectionLength;
bool processed = false;
while (!processed && start <= end)
{
foreach (LinkLocation ll in LinkLocations)
{
if (ll.Start >= start && ll.End <= end)
{
processed = true;
if (start < ll.Start)
{
SelectionStart = start;
SelectionLength = ll.Start - start;
}
start = ll.End + 1;
break;
}
}
}
}
string ostring = SelectedText;
if ((char.IsUpper(ostring, 0) && char.IsUpper(ostring, 1)) ||
(char.IsLower(ostring, 0) && char.IsUpper(ostring, 1))) type = 'l'; // lower case
else if ((char.IsUpper(ostring, 0) && char.IsLower(ostring, 1))) type = 'U'; // upper case
else type = 'T'; // Title case
SetSelectedCase(type);
}
public void SetSelectedCase(char type)
{
// do not change case on linked text
@ -1153,6 +1192,55 @@ namespace Volian.Controls.Library
#region KeyboardHandling
void StepRTB_KeyUp(object sender, KeyEventArgs e)
{
if (e.Control)
{
if (e.Alt)
{
switch (e.KeyCode)
{
case Keys.M:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.btnAnnots_Click(sender, e);
e.Handled = true;
break;
default:
break;
}
}
if (e.Shift)
{
switch (e.KeyCode)
{
case Keys.F:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsFigure");
e.Handled = true;
break;
case Keys.T:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsTable");
e.Handled = true;
break;
case Keys.N:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsNote");
e.Handled = true;
break;
case Keys.C:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsCaution");
e.Handled = true;
break;
case Keys.S:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsSubStps");
e.Handled = true;
break;
case Keys.H:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsHLS");
e.Handled = true;
break;
case Keys.R:
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsRNO");
e.Handled = true;
break;
}
}
}
if (!e.Shift) return;
switch (e.KeyCode)
{
@ -1167,6 +1255,10 @@ namespace Volian.Controls.Library
if (e.Control) // Hardspace - Ctrl+Shift+Space
InsertSymbol(@"\u160?");
break;
case Keys.F3: // shift F3
e.Handled = true;
ToggleCase(); // toggle through Upper, Lower, and Title case
break;
default:
break;
}
@ -1202,6 +1294,11 @@ namespace Volian.Controls.Library
StepRTB_HomeEndPressed(e);
e.Handled = true;
break;
case Keys.Enter:
//Console.WriteLine("Ctrl+Enter - Page Break");
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.btnInsPgBrk_Click(sender, e);
e.Handled = true;
break;
}
}
switch (e.KeyCode)
@ -1363,6 +1460,14 @@ namespace Volian.Controls.Library
// comment on _OverWrite
e.Handled = true;
break;
case Keys.F6:
e.Handled = true;
SendKeys.Send("%H{ESC}");
break;
case Keys.Tab:
e.SuppressKeyPress = true;
e.Handled = true;
break;
}
}
private void StepRTB_HomeEndPressed(KeyEventArgs keyargs)
@ -2067,6 +2172,12 @@ namespace Volian.Controls.Library
DebugPrint(where, ": {0} {1} '{2}'", SelectionStart, SelectionLength, SelectedText);
}
#endregion
private void StepRTB_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if ((e.KeyCode == Keys.Tab) && (!e.Alt && !e.Control))
e.IsInputKey = true;
}
}
public partial class StepRTBModeChangeEventArgs : EventArgs
{

View File

@ -29,6 +29,10 @@ namespace Volian.Controls.Library
private void InitializeComponent()
{
this.SuspendLayout();
//
// StepRTB
//
this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.StepRTB_PreviewKeyDown);
this.ResumeLayout(false);
}

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 };