1
0
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:
Patrick Simpson 2017-06-30 15:26:45 +02:00
parent 008c27026d
commit ac0634c2d3
9 changed files with 80 additions and 11 deletions

View File

@ -108,8 +108,9 @@ namespace Acacia.Controls
_edit.PreviewKeyDown += _edit_PreviewKeyDown;
}
public void FocusEdit()
protected override void OnGotFocus(EventArgs e)
{
// Make the edit active
_edit.Select();
}

View File

@ -33,6 +33,7 @@ namespace Acacia.Controls
private KBusyIndicator _busyOverlay = null;
private KBusyIndicator _completeOverlay = null;
private string _busyText;
private readonly List<Action> _doneActions = new List<Action>();
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)
{
Controls.Remove(overlay);
@ -66,6 +82,11 @@ namespace Acacia.Controls
// And enable the controls
foreach (Control control in Controls)
control.Enabled = true;
// Excute any actions
foreach (Action action in _doneActions)
action();
_doneActions.Clear();
}
private KBusyIndicator CreateOverlay(string text, bool showProgress)

View File

@ -16,6 +16,13 @@ namespace Acacia.Controls
{
#region Drop-down list
protected enum CommitSource
{
MouseClick,
KeyTab,
KeyEnter
}
/// <summary>
/// Custom list for the drop-down. Performs a few functions:
/// - 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
SelectedIndex = IndexFromPoint(PointToClient(Cursor.Position));
CommitSelection();
CommitSelection(CommitSource.MouseClick);
}
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));
}
public void CommitSelection()
public CommitSource _commitSource;
public void CommitSelection(CommitSource source)
{
_commitSource = source;
_committedIndex = SelectedIndex;
base.OnSelectedIndexChanged(new EventArgs());
}
@ -167,6 +176,8 @@ namespace Acacia.Controls
OnSelectedItemChanged();
}
protected CommitSource GetCommitSource() { return _list._commitSource; }
public DisplayItem SelectedItem
{
get { return _selectedItem; }
@ -371,7 +382,7 @@ namespace Acacia.Controls
if (DroppedDown)
{
if (_list.SelectedIndex >= 0)
_list.CommitSelection();
_list.CommitSelection(e.KeyCode == Keys.Enter ? CommitSource.KeyEnter : CommitSource.KeyTab);
DroppedDown = false;
}
e.IsInputKey = e.KeyCode == Keys.Enter;

View File

@ -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
/// 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/>.
///
/// Consult LICENSE file for details
using System;
using System.Collections.Generic;
using System.Drawing;
@ -137,5 +138,20 @@ namespace Acacia.Controls
}
#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
}
}

View File

@ -70,6 +70,7 @@
this._mainBusyHider.Controls.Add(this._layoutMain);
resources.ApplyResources(this._mainBusyHider, "_mainBusyHider");
this._mainBusyHider.Name = "_mainBusyHider";
this._mainBusyHider.TabStop = true;
//
// _layoutMain
//
@ -78,6 +79,7 @@
this._layoutMain.Controls.Add(this.kTreeFolders, 0, 1);
this._layoutMain.Controls.Add(this._layoutOptions, 0, 2);
this._layoutMain.Name = "_layoutMain";
this._layoutMain.TabStop = true;
//
// _layoutSelectUser
//
@ -86,6 +88,7 @@
this._layoutSelectUser.Controls.Add(this.gabLookup, 1, 0);
this._layoutSelectUser.Controls.Add(this.buttonOpenUser, 2, 0);
this._layoutSelectUser.Name = "_layoutSelectUser";
this._layoutSelectUser.TabStop = true;
//
// labelSelectUser
//

View File

@ -148,14 +148,23 @@ namespace Acacia.Features.SharedFolders
};
FocusNode(node);
}
kTreeFolders.Focus();
SetInitialFocus(kTreeFolders);
}
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)
{
BusyText = Properties.Resources.SharedFolders_Applying_Label;

View File

@ -190,7 +190,7 @@
<value>260, 23</value>
</data>
<data name="gabLookup.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
<value>1</value>
</data>
<data name="&gt;&gt;gabLookup.Name" xml:space="preserve">
<value>gabLookup</value>
@ -286,7 +286,7 @@
<value>442, 277</value>
</data>
<data name="kTreeFolders.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
<value>1</value>
</data>
<data name="&gt;&gt;kTreeFolders.Name" xml:space="preserve">
<value>kTreeFolders</value>

View File

@ -249,5 +249,12 @@ namespace Acacia.Native
public static extern int GetSystemMetrics(SystemMetric nIndex);
#endregion
#region Focus
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)]
public static extern IntPtr GetFocus();
#endregion
}
}

View File

@ -163,7 +163,8 @@ namespace Acacia.UI
protected override void OnSelectedItemChanged()
{
_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