feat: autocompletions
This commit is contained in:
@@ -43,6 +43,9 @@ namespace CarManagerV3.Forms
|
||||
read: () => Properties.Settings.Default.AllowPrerelease,
|
||||
write: v => Properties.Settings.Default.AllowPrerelease = v);
|
||||
|
||||
//TODO: implement refresh settings
|
||||
|
||||
|
||||
lblEnv.Text = lblEnv.Text.Replace("%E%", InstallModeDetector.IsInstalledViaMsi() ? "Installed via MSI" : "Running in portable mode");
|
||||
|
||||
}
|
||||
@@ -60,10 +63,33 @@ namespace CarManagerV3.Forms
|
||||
|
||||
private void saveSettings()
|
||||
{
|
||||
bool requiresRestart = false;
|
||||
foreach (var kvp in settingsMap)
|
||||
{
|
||||
kvp.Value.Save();
|
||||
if (kvp.Value.RequiresRestart())
|
||||
requiresRestart = true;
|
||||
}
|
||||
|
||||
|
||||
Properties.Settings.Default.Save();
|
||||
if(requiresRestart)
|
||||
{
|
||||
DialogResult result = MessageBox.Show(
|
||||
"Some changes you made require a restart to take effect. Do you want to restart now?",
|
||||
"Restart Required",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Information);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
Application.Restart();
|
||||
} else
|
||||
{
|
||||
MessageBox.Show("Please restart the application as soon as possible to ensure all changes take effect.", "Restart Recommended", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void resetSettings()
|
||||
@@ -106,6 +132,7 @@ namespace CarManagerV3.Forms
|
||||
void Load();
|
||||
void Save();
|
||||
void Reset();
|
||||
bool RequiresRestart();
|
||||
}
|
||||
|
||||
internal sealed class SettingBinding<T> : ISettingBinding
|
||||
@@ -115,14 +142,18 @@ namespace CarManagerV3.Forms
|
||||
private readonly Func<T> read;
|
||||
private readonly Action<T> write;
|
||||
private readonly Action<T, T>? onChange;
|
||||
private readonly bool requiresRestart;
|
||||
private bool changeRequiresRestart;
|
||||
|
||||
public SettingBinding(Control control, T defaultValue, Func<T> read, Action<T> write, Action<T, T>? onChange = null)
|
||||
public SettingBinding(Control control, T defaultValue, Func<T> read, Action<T> write, bool requiresRestart = false, Action<T, T>? onChange = null)
|
||||
{
|
||||
this.control = control;
|
||||
this.defaultValue = defaultValue;
|
||||
this.read = read;
|
||||
this.write = write;
|
||||
this.onChange = onChange;
|
||||
this.requiresRestart = requiresRestart;
|
||||
this.changeRequiresRestart = false;
|
||||
}
|
||||
|
||||
public void Load()
|
||||
@@ -140,10 +171,15 @@ namespace CarManagerV3.Forms
|
||||
|
||||
if (onChange != null && !EqualityComparer<T>.Default.Equals(before, after))
|
||||
onChange(before, after);
|
||||
|
||||
if (requiresRestart && !EqualityComparer<T>.Default.Equals(before, after))
|
||||
changeRequiresRestart = true;
|
||||
}
|
||||
|
||||
public void Reset() => write(defaultValue);
|
||||
|
||||
public bool RequiresRestart() => changeRequiresRestart;
|
||||
|
||||
private void ApplyToControl(T value)
|
||||
{
|
||||
switch (control)
|
||||
|
||||
Reference in New Issue
Block a user