mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
Use the server combobox's item list for autocompletion suggestions.
This fixes occasional crash when typing in the combobox. Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
parent
e4cecfb1bd
commit
e582ae1e24
2
XenAdmin/Dialogs/AddServerDialog.Designer.cs
generated
2
XenAdmin/Dialogs/AddServerDialog.Designer.cs
generated
@ -100,7 +100,7 @@ namespace XenAdmin.Dialogs
|
||||
//
|
||||
resources.ApplyResources(this.ServerNameComboBox, "ServerNameComboBox");
|
||||
this.ServerNameComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
|
||||
this.ServerNameComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
|
||||
this.ServerNameComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
|
||||
this.tableLayoutPanelType.SetColumnSpan(this.ServerNameComboBox, 2);
|
||||
this.ServerNameComboBox.Name = "ServerNameComboBox";
|
||||
this.ServerNameComboBox.TextChanged += new System.EventHandler(this.TextFields_TextChanged);
|
||||
|
@ -31,6 +31,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
using XenAdmin.Core;
|
||||
@ -58,7 +59,10 @@ namespace XenAdmin.Dialogs
|
||||
_changedPass = changedPass;
|
||||
|
||||
InitializeComponent();
|
||||
PopulateXenServerHosts();
|
||||
|
||||
var history = Settings.GetServerHistory().ToArray();
|
||||
Array.Sort(history, StringUtility.NaturalCompare);
|
||||
ServerNameComboBox.Items.AddRange(history.Where(s => s != null).Cast<object>().ToArray());
|
||||
|
||||
if (connection != null)
|
||||
{
|
||||
@ -68,25 +72,6 @@ namespace XenAdmin.Dialogs
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateXenServerHosts()
|
||||
{
|
||||
AutoCompleteStringCollection history = Settings.GetServerHistory();
|
||||
|
||||
string[] historyArray = new string[history.Count];
|
||||
history.CopyTo(historyArray, 0);
|
||||
Array.Sort(historyArray, StringUtility.NaturalCompare);
|
||||
foreach (string serverName in historyArray)
|
||||
{
|
||||
if (serverName != null)
|
||||
ServerNameComboBox.Items.Add(serverName);
|
||||
}
|
||||
|
||||
// Use a clone as the auto-complete source because of CA-38715
|
||||
AutoCompleteStringCollection historyClone = new AutoCompleteStringCollection();
|
||||
historyClone.AddRange(historyArray);
|
||||
ServerNameComboBox.AutoCompleteCustomSource = historyClone;
|
||||
}
|
||||
|
||||
private void OnCachePopulated(IXenConnection conn)
|
||||
{
|
||||
var handler = CachePopulated;
|
||||
|
6
XenAdmin/Properties/Settings.Designer.cs
generated
6
XenAdmin/Properties/Settings.Designer.cs
generated
@ -12,7 +12,7 @@ namespace XenAdmin.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
@ -39,9 +39,9 @@ namespace XenAdmin.Properties {
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
|
||||
public global::System.Windows.Forms.AutoCompleteStringCollection ServerHistory {
|
||||
public string[] ServerHistory {
|
||||
get {
|
||||
return ((global::System.Windows.Forms.AutoCompleteStringCollection)(this["ServerHistory"]));
|
||||
return ((string[])(this["ServerHistory"]));
|
||||
}
|
||||
set {
|
||||
this["ServerHistory"] = value;
|
||||
|
@ -5,7 +5,7 @@
|
||||
<Setting Name="ToolbarsEnabled" Roaming="true" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="ServerHistory" Roaming="true" Type="System.Windows.Forms.AutoCompleteStringCollection" Scope="User">
|
||||
<Setting Name="ServerHistory" Roaming="true" Type="System.String[]" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="SaveSession" Roaming="true" Type="System.Boolean" Scope="User">
|
||||
|
@ -560,23 +560,24 @@ namespace XenAdmin
|
||||
return Properties.Settings.Default.RequirePass && Program.MainPassword != null ? EncryptionUtils.EncryptString(entryStr, Program.MainPassword) : EncryptionUtils.Protect(entryStr);
|
||||
}
|
||||
|
||||
public static AutoCompleteStringCollection GetServerHistory()
|
||||
public static string[] GetServerHistory()
|
||||
{
|
||||
if (Properties.Settings.Default.ServerHistory == null)
|
||||
Properties.Settings.Default.ServerHistory = new AutoCompleteStringCollection();
|
||||
Properties.Settings.Default.ServerHistory = Array.Empty<string>();
|
||||
|
||||
return Properties.Settings.Default.ServerHistory;
|
||||
}
|
||||
|
||||
public static void UpdateServerHistory(string hostnameWithPort)
|
||||
{
|
||||
AutoCompleteStringCollection history = GetServerHistory();
|
||||
var history = new List<string>(GetServerHistory());
|
||||
|
||||
if (!history.Contains(hostnameWithPort))
|
||||
{
|
||||
while (history.Count >= 20)
|
||||
history.RemoveAt(0);
|
||||
history.Add(hostnameWithPort);
|
||||
Properties.Settings.Default.ServerHistory = history;
|
||||
Properties.Settings.Default.ServerHistory = history.ToArray();
|
||||
TrySaveSettings();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user