Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit max entries shown in MSFS 2020 preset combo box #1810

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
DocMoebiuz marked this conversation as resolved.
Show resolved Hide resolved

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
Loading