Skip to content

Commit

Permalink
Limit max entries shown in MSFS 2020 preset combo box (#1810)
Browse files Browse the repository at this point in the history
* Limit max entries shown in preset combo box
* max items 1500
  • Loading branch information
Koseng authored Aug 11, 2024
1 parent 6d91e67 commit 752e707
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
3 changes: 1 addition & 2 deletions UI/Panels/Config/HubHopPresetPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 30 additions & 14 deletions UI/Panels/Config/HubHopPresetPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
using MobiFlight.InputConfig;
using MobiFlight.OutputConfig;
using MobiFlight.UI.Forms;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MobiFlight.UI.Panels.Config
Expand Down Expand Up @@ -432,6 +425,12 @@ private void PresetComboBox_SelectedIndexChanged(object sender, EventArgs e)
if ((sender as ComboBox).SelectedItem == null) return;
Msfs2020HubhopPreset selectedItem = (sender as ComboBox).SelectedItem as Msfs2020HubhopPreset;

if (selectedItem.id == "Load all")
{
UpdatePresetComboBoxValues(loadAllItems: true);
return;
}

Msfs2020HubhopPreset selectedPreset = FilteredPresetList.Items.Find(x => x.id == selectedItem.id);
if (selectedPreset == null) return;
DescriptionTextBox.Text = selectedPreset?.description?.ToCRLF();
Expand Down Expand Up @@ -583,13 +582,14 @@ private void FilteredPresetListChanged()
UpdateValues(SystemComboBox, FilteredPresetList.AllSystems(hubhopType).ToArray());
}

UpdatePresetComboBoxValues();
UpdatePresetComboBoxValues(loadAllItems: false);
}

private void UpdatePresetComboBoxValues()
private void UpdatePresetComboBoxValues(bool loadAllItems)
{
String SelectedValue = null;
Msfs2020HubhopPreset selectedPreset = null;
int maxItemsCombobox = 1500;

PresetComboBox.SelectedIndexChanged -= PresetComboBox_SelectedIndexChanged;
if (PresetComboBox.SelectedIndex > 0)
Expand All @@ -601,20 +601,37 @@ private void UpdatePresetComboBoxValues()
FilteredPresetList.Items.Add(selectedPreset);
}
}

PresetComboBox.DataSource = null;
PresetComboBox.DataSource = FilteredPresetList.Items;
if (!loadAllItems && FilteredPresetList.Items.Count > maxItemsCombobox)
{
var MatchesFound = FilteredPresetList.Items.Count - 1;
var presetItems = FilteredPresetList.Items.GetRange(0, maxItemsCombobox);
presetItems.Add(new Msfs2020HubhopPreset()
{
label = "====== Load all items ======",
id = "Load all",
code = "",
description = "Load all items."
});

PresetComboBox.DataSource = presetItems;
}
else
{
PresetComboBox.DataSource = FilteredPresetList.Items;
}

PresetComboBox.ValueMember = "id";
PresetComboBox.DisplayMember = "label";

if (SelectedValue != null)
{
{
PresetComboBox.SelectedValue = SelectedValue;

// we didn't find the preset within the current
// list
if (PresetComboBox.SelectedValue == null)
PresetComboBox.SelectedIndex = 0;
PresetComboBox.SelectedIndex = 0;
}
else
{
Expand All @@ -625,7 +642,6 @@ private void UpdatePresetComboBoxValues()

PresetComboBox.SelectedIndexChanged += PresetComboBox_SelectedIndexChanged;
}

private void UpdateValues(ComboBox cb, String[] valueList)
{
String SelectedValue = null;
Expand Down

0 comments on commit 752e707

Please sign in to comment.