mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
[KOE-125] Fixed initial focus handling for shared folders dialog. Also no longer automatically opening when user tabs away from dialog.
This commit is contained in:
parent
008c27026d
commit
ac0634c2d3
@ -108,8 +108,9 @@ namespace Acacia.Controls
|
|||||||
_edit.PreviewKeyDown += _edit_PreviewKeyDown;
|
_edit.PreviewKeyDown += _edit_PreviewKeyDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FocusEdit()
|
protected override void OnGotFocus(EventArgs e)
|
||||||
{
|
{
|
||||||
|
// Make the edit active
|
||||||
_edit.Select();
|
_edit.Select();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ namespace Acacia.Controls
|
|||||||
private KBusyIndicator _busyOverlay = null;
|
private KBusyIndicator _busyOverlay = null;
|
||||||
private KBusyIndicator _completeOverlay = null;
|
private KBusyIndicator _completeOverlay = null;
|
||||||
private string _busyText;
|
private string _busyText;
|
||||||
|
private readonly List<Action> _doneActions = new List<Action>();
|
||||||
|
|
||||||
public bool Busy
|
public bool Busy
|
||||||
{
|
{
|
||||||
@ -59,6 +60,21 @@ namespace Acacia.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes the action when no longer busy. If not busy now, the action is executed straight away.
|
||||||
|
/// </summary>
|
||||||
|
public void OnDoneBusy(Action action)
|
||||||
|
{
|
||||||
|
if (!Busy)
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_doneActions.Add(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void RemoveOverlay(KBusyIndicator overlay)
|
private void RemoveOverlay(KBusyIndicator overlay)
|
||||||
{
|
{
|
||||||
Controls.Remove(overlay);
|
Controls.Remove(overlay);
|
||||||
@ -66,6 +82,11 @@ namespace Acacia.Controls
|
|||||||
// And enable the controls
|
// And enable the controls
|
||||||
foreach (Control control in Controls)
|
foreach (Control control in Controls)
|
||||||
control.Enabled = true;
|
control.Enabled = true;
|
||||||
|
|
||||||
|
// Excute any actions
|
||||||
|
foreach (Action action in _doneActions)
|
||||||
|
action();
|
||||||
|
_doneActions.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private KBusyIndicator CreateOverlay(string text, bool showProgress)
|
private KBusyIndicator CreateOverlay(string text, bool showProgress)
|
||||||
|
@ -16,6 +16,13 @@ namespace Acacia.Controls
|
|||||||
{
|
{
|
||||||
#region Drop-down list
|
#region Drop-down list
|
||||||
|
|
||||||
|
protected enum CommitSource
|
||||||
|
{
|
||||||
|
MouseClick,
|
||||||
|
KeyTab,
|
||||||
|
KeyEnter
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Custom list for the drop-down. Performs a few functions:
|
/// Custom list for the drop-down. Performs a few functions:
|
||||||
/// - Prevents grabbing the focus away from the edit when clicked
|
/// - Prevents grabbing the focus away from the edit when clicked
|
||||||
@ -73,7 +80,7 @@ namespace Acacia.Controls
|
|||||||
{
|
{
|
||||||
// Select the item under the mouse and commit
|
// Select the item under the mouse and commit
|
||||||
SelectedIndex = IndexFromPoint(PointToClient(Cursor.Position));
|
SelectedIndex = IndexFromPoint(PointToClient(Cursor.Position));
|
||||||
CommitSelection();
|
CommitSelection(CommitSource.MouseClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DefWndProc(ref Message m)
|
protected override void DefWndProc(ref Message m)
|
||||||
@ -96,8 +103,10 @@ namespace Acacia.Controls
|
|||||||
return new Size(w, ItemHeight * Math.Min(Items.Count, _owner.MaxDropDownItems));
|
return new Size(w, ItemHeight * Math.Min(Items.Count, _owner.MaxDropDownItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CommitSelection()
|
public CommitSource _commitSource;
|
||||||
|
public void CommitSelection(CommitSource source)
|
||||||
{
|
{
|
||||||
|
_commitSource = source;
|
||||||
_committedIndex = SelectedIndex;
|
_committedIndex = SelectedIndex;
|
||||||
base.OnSelectedIndexChanged(new EventArgs());
|
base.OnSelectedIndexChanged(new EventArgs());
|
||||||
}
|
}
|
||||||
@ -167,6 +176,8 @@ namespace Acacia.Controls
|
|||||||
OnSelectedItemChanged();
|
OnSelectedItemChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CommitSource GetCommitSource() { return _list._commitSource; }
|
||||||
|
|
||||||
public DisplayItem SelectedItem
|
public DisplayItem SelectedItem
|
||||||
{
|
{
|
||||||
get { return _selectedItem; }
|
get { return _selectedItem; }
|
||||||
@ -371,7 +382,7 @@ namespace Acacia.Controls
|
|||||||
if (DroppedDown)
|
if (DroppedDown)
|
||||||
{
|
{
|
||||||
if (_list.SelectedIndex >= 0)
|
if (_list.SelectedIndex >= 0)
|
||||||
_list.CommitSelection();
|
_list.CommitSelection(e.KeyCode == Keys.Enter ? CommitSource.KeyEnter : CommitSource.KeyTab);
|
||||||
DroppedDown = false;
|
DroppedDown = false;
|
||||||
}
|
}
|
||||||
e.IsInputKey = e.KeyCode == Keys.Enter;
|
e.IsInputKey = e.KeyCode == Keys.Enter;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
/// Copyright 2016 Kopano b.v.
|
|
||||||
|
using Acacia.Native;
|
||||||
|
/// Copyright 2016 Kopano b.v.
|
||||||
///
|
///
|
||||||
/// This program is free software: you can redistribute it and/or modify
|
/// This program is free software: you can redistribute it and/or modify
|
||||||
/// it under the terms of the GNU Affero General Public License, version 3,
|
/// it under the terms of the GNU Affero General Public License, version 3,
|
||||||
@ -13,7 +15,6 @@
|
|||||||
/// along with this program.If not, see<http://www.gnu.org/licenses/>.
|
/// along with this program.If not, see<http://www.gnu.org/licenses/>.
|
||||||
///
|
///
|
||||||
/// Consult LICENSE file for details
|
/// Consult LICENSE file for details
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@ -137,5 +138,20 @@ namespace Acacia.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Focus
|
||||||
|
|
||||||
|
public static Control GetFocusedControl()
|
||||||
|
{
|
||||||
|
Control focusedControl = null;
|
||||||
|
// To get hold of the focused control:
|
||||||
|
IntPtr focusedHandle = User32.GetFocus();
|
||||||
|
if (focusedHandle != IntPtr.Zero)
|
||||||
|
// Note that if the focused Control is not a .Net control, then this will return null.
|
||||||
|
focusedControl = Control.FromHandle(focusedHandle);
|
||||||
|
return focusedControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@
|
|||||||
this._mainBusyHider.Controls.Add(this._layoutMain);
|
this._mainBusyHider.Controls.Add(this._layoutMain);
|
||||||
resources.ApplyResources(this._mainBusyHider, "_mainBusyHider");
|
resources.ApplyResources(this._mainBusyHider, "_mainBusyHider");
|
||||||
this._mainBusyHider.Name = "_mainBusyHider";
|
this._mainBusyHider.Name = "_mainBusyHider";
|
||||||
|
this._mainBusyHider.TabStop = true;
|
||||||
//
|
//
|
||||||
// _layoutMain
|
// _layoutMain
|
||||||
//
|
//
|
||||||
@ -78,6 +79,7 @@
|
|||||||
this._layoutMain.Controls.Add(this.kTreeFolders, 0, 1);
|
this._layoutMain.Controls.Add(this.kTreeFolders, 0, 1);
|
||||||
this._layoutMain.Controls.Add(this._layoutOptions, 0, 2);
|
this._layoutMain.Controls.Add(this._layoutOptions, 0, 2);
|
||||||
this._layoutMain.Name = "_layoutMain";
|
this._layoutMain.Name = "_layoutMain";
|
||||||
|
this._layoutMain.TabStop = true;
|
||||||
//
|
//
|
||||||
// _layoutSelectUser
|
// _layoutSelectUser
|
||||||
//
|
//
|
||||||
@ -86,6 +88,7 @@
|
|||||||
this._layoutSelectUser.Controls.Add(this.gabLookup, 1, 0);
|
this._layoutSelectUser.Controls.Add(this.gabLookup, 1, 0);
|
||||||
this._layoutSelectUser.Controls.Add(this.buttonOpenUser, 2, 0);
|
this._layoutSelectUser.Controls.Add(this.buttonOpenUser, 2, 0);
|
||||||
this._layoutSelectUser.Name = "_layoutSelectUser";
|
this._layoutSelectUser.Name = "_layoutSelectUser";
|
||||||
|
this._layoutSelectUser.TabStop = true;
|
||||||
//
|
//
|
||||||
// labelSelectUser
|
// labelSelectUser
|
||||||
//
|
//
|
||||||
|
@ -148,14 +148,23 @@ namespace Acacia.Features.SharedFolders
|
|||||||
};
|
};
|
||||||
FocusNode(node);
|
FocusNode(node);
|
||||||
}
|
}
|
||||||
kTreeFolders.Focus();
|
SetInitialFocus(kTreeFolders);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gabLookup.FocusEdit();
|
SetInitialFocus(gabLookup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetInitialFocus(Control control)
|
||||||
|
{
|
||||||
|
// If busy, setting the focus doesn't work, as the control is enabled. Wait until done.
|
||||||
|
BusyHider.OnDoneBusy(() =>
|
||||||
|
{
|
||||||
|
control.Focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void dialogButtons_Apply(object sender, EventArgs e)
|
private void dialogButtons_Apply(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
BusyText = Properties.Resources.SharedFolders_Applying_Label;
|
BusyText = Properties.Resources.SharedFolders_Applying_Label;
|
||||||
|
@ -190,7 +190,7 @@
|
|||||||
<value>260, 23</value>
|
<value>260, 23</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="gabLookup.TabIndex" type="System.Int32, mscorlib">
|
<data name="gabLookup.TabIndex" type="System.Int32, mscorlib">
|
||||||
<value>0</value>
|
<value>1</value>
|
||||||
</data>
|
</data>
|
||||||
<data name=">>gabLookup.Name" xml:space="preserve">
|
<data name=">>gabLookup.Name" xml:space="preserve">
|
||||||
<value>gabLookup</value>
|
<value>gabLookup</value>
|
||||||
@ -286,7 +286,7 @@
|
|||||||
<value>442, 277</value>
|
<value>442, 277</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="kTreeFolders.TabIndex" type="System.Int32, mscorlib">
|
<data name="kTreeFolders.TabIndex" type="System.Int32, mscorlib">
|
||||||
<value>0</value>
|
<value>1</value>
|
||||||
</data>
|
</data>
|
||||||
<data name=">>kTreeFolders.Name" xml:space="preserve">
|
<data name=">>kTreeFolders.Name" xml:space="preserve">
|
||||||
<value>kTreeFolders</value>
|
<value>kTreeFolders</value>
|
||||||
|
@ -249,5 +249,12 @@ namespace Acacia.Native
|
|||||||
public static extern int GetSystemMetrics(SystemMetric nIndex);
|
public static extern int GetSystemMetrics(SystemMetric nIndex);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Focus
|
||||||
|
|
||||||
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)]
|
||||||
|
public static extern IntPtr GetFocus();
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,8 @@ namespace Acacia.UI
|
|||||||
protected override void OnSelectedItemChanged()
|
protected override void OnSelectedItemChanged()
|
||||||
{
|
{
|
||||||
_selectedUser = (GABUser)SelectedItem?.Item;
|
_selectedUser = (GABUser)SelectedItem?.Item;
|
||||||
SelectedUserChanged?.Invoke(this, new SelectedUserEventArgs(_selectedUser, true));
|
// If the tab key was used to select, the user wants to click open
|
||||||
|
SelectedUserChanged?.Invoke(this, new SelectedUserEventArgs(_selectedUser, GetCommitSource() != CommitSource.KeyTab));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user