diff --git a/Src/XCore/xWindow.cs b/Src/XCore/xWindow.cs index 4ea71324ab..e9fc439175 100644 --- a/Src/XCore/xWindow.cs +++ b/Src/XCore/xWindow.cs @@ -1535,6 +1535,11 @@ protected override void WndProc(ref Message m) base.WndProc(ref m); } + public void HandleKeyDown(KeyEventArgs e) + { + OnKeyDown(e); + } + protected override void OnKeyDown(KeyEventArgs e) { if (!e.Handled && e.KeyCode == Keys.Tab && (e.Modifiers & Keys.Control) == Keys.Control) diff --git a/Src/xWorks/FwXWindow.cs b/Src/xWorks/FwXWindow.cs index 5b6d166290..d68c5d33ff 100644 --- a/Src/xWorks/FwXWindow.cs +++ b/Src/xWorks/FwXWindow.cs @@ -622,10 +622,15 @@ public bool OnEditCut(object arg) { CheckDisposed(); - if (m_viewHelper.ActiveView != null) + ActiveViewHelper viewHelper = m_viewHelper; + if (arg is ActiveViewHelper helper) + { + viewHelper = helper; + } + if (viewHelper.ActiveView != null) { using (new DataUpdateMonitor(this, "EditCut")) - return m_viewHelper.ActiveView.EditingHelper.CutSelection(); + return viewHelper.ActiveView.EditingHelper.CutSelection(); } return false; } @@ -641,8 +646,13 @@ public bool OnEditCopy(object arg) { CheckDisposed(); - if (m_viewHelper.ActiveView != null) - return m_viewHelper.ActiveView.EditingHelper.CopySelection(); + ActiveViewHelper viewHelper = m_viewHelper; + if (arg is ActiveViewHelper helper) + { + viewHelper = helper; + } + if (viewHelper.ActiveView != null) + return viewHelper.ActiveView.EditingHelper.CopySelection(); return false; } @@ -657,7 +667,12 @@ public bool OnEditPaste(object arg) { CheckDisposed(); - if (m_viewHelper.ActiveView != null) + ActiveViewHelper viewHelper = m_viewHelper; + if (arg is ActiveViewHelper helper) + { + viewHelper = helper; + } + if (viewHelper.ActiveView != null) { string stUndo, stRedo; ResourceHelper.MakeUndoRedoLabels("kstidEditPaste", out stUndo, out stRedo); @@ -665,7 +680,7 @@ public bool OnEditPaste(object arg) Cache.ServiceLocator.GetInstance(), stUndo, stRedo)) using (new DataUpdateMonitor(this, "EditPaste")) { - if (m_viewHelper.ActiveView.EditingHelper.PasteClipboard(Cache)) + if (viewHelper.ActiveView.EditingHelper.PasteClipboard(Cache)) undoHelper.RollBack = false; } return true; @@ -825,12 +840,17 @@ public bool OnEditSelectAll(object arg) { CheckDisposed(); - if (m_viewHelper.ActiveView != null) + ActiveViewHelper viewHelper = m_viewHelper; + if (arg is ActiveViewHelper helper) + { + viewHelper = helper; + } + if (viewHelper.ActiveView != null) { try { EnableBulkLoadingDisableIdleProcessing(true); - m_viewHelper.ActiveView.EditingHelper.SelectAll(); + viewHelper.ActiveView.EditingHelper.SelectAll(); } finally { diff --git a/Src/xWorks/PopupToolWindow.cs b/Src/xWorks/PopupToolWindow.cs index c439f67eb6..31600f1e9d 100644 --- a/Src/xWorks/PopupToolWindow.cs +++ b/Src/xWorks/PopupToolWindow.cs @@ -1,3 +1,4 @@ +using SIL.FieldWorks.Common.RootSites; using SIL.LCModel; using SIL.Utils; using System; @@ -18,6 +19,7 @@ public Control MainControl private PropertyTable m_propertyTable; private RecordClerk m_recordClerk; + protected ActiveViewHelper m_viewHelper; public PopupToolWindow() { @@ -40,6 +42,8 @@ private void InitializeComponent() this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; this.Text = "Popup Tool Window"; this.WindowState = System.Windows.Forms.FormWindowState.Normal; + this.KeyPreview = true; + this.KeyDown += new KeyEventHandler(PopupToolWindow_KeyDown); this.Deactivate += new System.EventHandler(PopupToolWindow_Deactivate); this.Activated += new System.EventHandler(PopupToolWindow_Activated); this.ResumeLayout(false); @@ -64,6 +68,32 @@ private void PopupToolWindow_Activated(object sender, EventArgs e) } } + private void PopupToolWindow_KeyDown(object sender, KeyEventArgs e) + { + FwXWindow fwXWindow = Owner as FwXWindow; + if (e.KeyCode == Keys.A && e.Control) + { + fwXWindow?.OnEditSelectAll(m_viewHelper); + } + if (e.KeyCode == Keys.C && e.Control) + { + fwXWindow?.OnEditCopy(m_viewHelper); + } + else if (e.KeyCode == Keys.V && e.Control) + { + fwXWindow?.OnEditPaste(m_viewHelper); + } + else if (e.KeyCode == Keys.X && e.Control) + { + fwXWindow?.OnEditCut(m_viewHelper); + } + else + { + // e.g. Control-Z. + fwXWindow?.HandleKeyDown(e); + } + } + private IxCoreColleague MainContentControlAsIxCoreColleague { get { return m_mainContentControl as IxCoreColleague; } @@ -116,6 +146,8 @@ public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode toolNod { this.Text = toolNode.Attributes["label"].Value; } + m_viewHelper = new ActiveViewHelper(this); + this.Show(); this.BringToFront(); this.Activate();