diff --git a/MainWindow.axaml b/MainWindow.axaml
index a1b057c..afb5e79 100644
--- a/MainWindow.axaml
+++ b/MainWindow.axaml
@@ -385,9 +385,79 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MainWindow.axaml.cs b/MainWindow.axaml.cs
index c6458c6..db5930c 100644
--- a/MainWindow.axaml.cs
+++ b/MainWindow.axaml.cs
@@ -11,6 +11,9 @@ namespace Logof_Client;
public partial class MainWindow : Window
{
public static MainWindow _instance;
+
+ private Country _selectedCountry;
+ private bool _suppressCountryRefresh = false;
public Uri filePath;
public MainWindow()
@@ -26,6 +29,8 @@ public partial class MainWindow : Window
Global.Load();
Settings.Load();
+ RefreshCountryView();
+
//Thread.Sleep(3000);
//Show();
}
@@ -585,4 +590,133 @@ public partial class MainWindow : Window
if (customer.ID == Settings._instance.customers.current)
customer.sender_address = TbSettingsCustomerSenderAddress.Text;
}
+
+
+ // Country Section
+ private void BtnSettingsRemoveCountry_OnClick(object? sender, RoutedEventArgs e)
+ {
+ if (_selectedCountry != null)
+ {
+ Global._instance.countries.Remove(_selectedCountry);
+ _selectedCountry = null;
+ }
+
+ RefreshCountryView();
+ }
+
+ public void RefreshCountryView()
+ {
+ if (_suppressCountryRefresh) return;
+ try
+ {
+ _suppressCountryRefresh = true;
+
+ Global.Save();
+ var alt_index = LbSettingsAlternatives.SelectedIndex;
+ var country_index = CountryList.SelectedIndex;
+
+ LbSettingsAlternatives.Items.Clear();
+ try
+ {
+ CountryList.Items.Clear();
+ }
+ catch
+ {
+ }
+
+ foreach (var c in Global._instance.countries) CountryList.Items.Add(c.name);
+ try
+ {
+ CountryList.SelectedIndex = country_index;
+ }
+ catch
+ {
+ }
+
+ try
+ {
+ _selectedCountry = Country.GetByName(CountryList.SelectedItems[0].ToString());
+ }
+ catch
+ {
+ _selectedCountry = null;
+ }
+
+ if (_selectedCountry == null) return;
+ //Console.WriteLine("Refreshing alternatives...");
+ foreach (var a in _selectedCountry.alternatives)
+ {
+ LbSettingsAlternatives.Items.Add(a);
+ //Console.WriteLine(a);
+ }
+
+ TbSettingsCountryName.Text = _selectedCountry.name;
+ TbSettingsCountryTranslation.Text = _selectedCountry.translation;
+
+ try
+ {
+ LbSettingsAlternatives.SelectedIndex = alt_index;
+ }
+ catch
+ {
+ }
+ }
+ finally
+ {
+ _suppressCountryRefresh = false;
+ }
+ }
+
+ private void BtnSettingsRemoveSelectedAlternatives_OnClick(object? sender, RoutedEventArgs e)
+ {
+ foreach (var selected in LbSettingsAlternatives.SelectedItems)
+ try
+ {
+ _selectedCountry.alternatives.Remove(selected.ToString());
+ }
+ catch
+ {
+ Console.WriteLine("Error while removing country alternative");
+ }
+
+ RefreshCountryView();
+ }
+
+ private void BtnSettingsNewCountryAlternative_OnClick(object? sender, RoutedEventArgs e)
+ {
+ if (string.IsNullOrWhiteSpace(TbSettingsNewCountryAlternative.Text)) return;
+ _selectedCountry.alternatives.Add(TbSettingsNewCountryAlternative.Text.Trim());
+ RefreshCountryView();
+ }
+
+ private void TbSettingsCountryTranslation_OnTextChanged(object? sender, TextChangedEventArgs e)
+ {
+ if (!string.IsNullOrWhiteSpace(TbSettingsCountryTranslation.Text))
+ {
+ _selectedCountry.translation = TbSettingsCountryTranslation.Text.Trim();
+ RefreshCountryView();
+ }
+ }
+
+ private void TbSettingsCountryName_OnTextChanged(object? sender, TextChangedEventArgs e)
+ {
+ if (!string.IsNullOrWhiteSpace(TbSettingsCountryName.Text))
+ {
+ _selectedCountry.name = TbSettingsCountryName.Text.Trim();
+ RefreshCountryView();
+ }
+ }
+
+ private void BtnSettingsNewCountry_OnClick(object? sender, RoutedEventArgs e)
+ {
+ if (string.IsNullOrWhiteSpace(TbSettingsNewCountry.Text)) return;
+ Global._instance.countries.Add(new Country(TbSettingsNewCountry.Text));
+ RefreshCountryView();
+ }
+
+ private void CountryList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
+ {
+ _selectedCountry = Country.GetByName(CountryList.SelectedItems[0].ToString());
+ RefreshCountryView();
+ }
}
\ No newline at end of file
diff --git a/Settings.cs b/Settings.cs
index a00fe82..936cb6c 100644
--- a/Settings.cs
+++ b/Settings.cs
@@ -62,6 +62,7 @@ public class Global
}
public string config_path { get; set; } = "";
+ public List countries { get; set; } = new();
public static void Save()
{
@@ -144,6 +145,40 @@ public class AddressSets
if (i.ID == ID)
return i;
+ return null;
+ }
+}
+
+public class Country
+{
+ public Country(string name, string translation, List alternatives)
+ {
+ this.name = name;
+ this.translation = translation;
+ this.alternatives = alternatives;
+ }
+
+ public Country(string name)
+ {
+ this.name = name;
+ translation = "";
+ alternatives = new List();
+ }
+
+ public Country()
+ {
+ }
+
+ public string? name { get; set; }
+ public string translation { get; set; }
+ public List alternatives { get; set; }
+
+ public static Country GetByName(string name)
+ {
+ foreach (var country in Global._instance.countries)
+ if (country.name == name)
+ return country;
+
return null;
}
}
\ No newline at end of file