From d7c7c94a7e0cabd39ec35c840a851655e40cec67 Mon Sep 17 00:00:00 2001
From: Patrick Simpson
Date: Thu, 29 Jun 2017 18:27:48 +0200
Subject: [PATCH] Implemented GABLookupControl using new combo box
---
.../Controls/KAbstractComboBox.cs | 21 +-
.../AcaciaZPushPlugin/Controls/KComboBox.cs | 64 +++-
.../Controls/KComboBoxCustomDraw.cs | 2 +-
.../SharedFoldersDialog.Designer.cs | 49 +--
.../SharedFolders/SharedFoldersDialog.resx | 241 +++++++-------
.../AcaciaZPushPlugin/UI/GABLookupControl.cs | 300 ++++++++----------
.../AcaciaZPushPlugin/ZPush/GABUser.cs | 15 +-
7 files changed, 362 insertions(+), 330 deletions(-)
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs
index 96a95d0..7d7fd52 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs
@@ -59,15 +59,24 @@ namespace Acacia.Controls
}
}
+ protected int _settingText = 0;
override public string Text
{
get { return _edit.Text; }
set
{
- _edit.Text = value;
- // Set the cursor after the text
- _edit.Select(_edit.Text.Length, 0);
+ ++_settingText;
+ try
+ {
+ _edit.Text = value;
+ // Set the cursor after the text
+ _edit.Select(_edit.Text.Length, 0);
+ }
+ finally
+ {
+ --_settingText;
+ }
}
}
@@ -327,12 +336,6 @@ namespace Acacia.Controls
DropControl.MaximumSize = DropControl.MinimumSize = new Size(width, height);
_dropDown.Control.Bounds = _dropDown.ControlHost.Bounds;
- System.Diagnostics.Trace.WriteLine(string.Format(
- "Layout: {0}, host: {1}, control: {2}",
- height,
- _dropDown.ControlHost.Bounds,
- _dropDown.Control.Bounds
- ));
}
protected abstract int GetDropDownHeightMax();
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs
index 309b49c..00aa0eb 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs
@@ -27,6 +27,7 @@ namespace Acacia.Controls
{
private readonly KComboBox _owner;
private int _committedIndex = -1;
+ public int ItemWidth { get; set; }
public DropList(KComboBox owner, bool ownerDraw)
{
@@ -91,7 +92,8 @@ namespace Acacia.Controls
{
// Preferred size is simply the size of the (maximum) number of items
Size prefSize = base.GetPreferredSize(proposedSize);
- return new Size(prefSize.Width, ItemHeight * Math.Min(Items.Count, _owner.MaxDropDownItems));
+ int w = Math.Max(prefSize.Width, ItemWidth);
+ return new Size(w, ItemHeight * Math.Min(Items.Count, _owner.MaxDropDownItems));
}
public void CommitSelection()
@@ -162,18 +164,41 @@ namespace Acacia.Controls
Text = "";
_selectedItem = null;
}
+ OnSelectedItemChanged();
}
- public void BeginUpdate()
+ public DisplayItem SelectedItem
{
- _list.BeginUpdate();
+ get { return _selectedItem; }
}
- public void EndUpdate()
+ public void Select(object data)
{
- _list.EndUpdate();
+ _list.SelectedIndex = -1;
+ Text = null;
+ _selectedItem = null;
+ if (data != null)
+ {
+ foreach (DisplayItem item in DisplayItems)
+ {
+ if (item.Item.Equals(data))
+ {
+ _list.SelectedItem = item;
+ _selectedItem = item;
+ break;
+ }
+ }
+ }
}
+ public event EventHandler SelectedItemChanged;
+
+ protected virtual void OnSelectedItemChanged()
+ {
+ SelectedItemChanged?.Invoke(this, new EventArgs());
+ }
+
+
///
/// Wrapper for list items to use custom string formatting
///
@@ -213,11 +238,14 @@ namespace Acacia.Controls
if (_dataSource != value)
{
_dataSource = value;
+ _displayItemCache.Clear();
UpdateItems();
}
}
}
+ private readonly Dictionary