-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose the start minimized setting in the settings button
- Loading branch information
Showing
19 changed files
with
143 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
YMouseButtonControl.Core/DataAccess/Models/Implementations/Setting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 35 additions & 5 deletions
40
YMouseButtonControl.Core/ViewModels/Implementations/Dialogs/GlobalSettingsDialogViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,57 @@ | ||
using System; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
using ReactiveUI; | ||
using YMouseButtonControl.Core.DataAccess.Models.Implementations; | ||
using YMouseButtonControl.Core.Profiles.Implementations; | ||
using YMouseButtonControl.Core.Profiles.Interfaces; | ||
using YMouseButtonControl.Core.ViewModels.Interfaces.Dialogs; | ||
|
||
namespace YMouseButtonControl.Core.ViewModels.Implementations.Dialogs; | ||
|
||
public class GlobalSettingsDialogViewModel : DialogBase, IGlobalSettingsDialogViewModel | ||
{ | ||
private readonly ISettingsService _settingsService; | ||
private Setting _startMinimized; | ||
private readonly ObservableAsPropertyHelper<bool>? _applyIsExec; | ||
|
||
public GlobalSettingsDialogViewModel(ISettingsService settingsService) | ||
{ | ||
_settingsService = settingsService; | ||
|
||
_startMinimized = | ||
_settingsService.GetSetting("StartMinimized") | ||
settingsService.GetSetting("StartMinimized") | ||
?? throw new Exception($"Error retrieving StartMinimized setting"); | ||
|
||
var startMinimizedChanged = this.WhenAnyValue( | ||
x => x.StartMinimized.Value, | ||
selector: val => | ||
{ | ||
var curVal = settingsService.GetSetting("StartMinimized"); | ||
if (curVal is null) | ||
{ | ||
return true; | ||
} | ||
|
||
return curVal.Value != val; | ||
} | ||
); | ||
|
||
var applyIsExecObs = this.WhenAnyValue(x => x.AppIsExec); | ||
var canSave = startMinimizedChanged.Merge(applyIsExecObs); | ||
ApplyCommand = ReactiveCommand.Create( | ||
() => | ||
{ | ||
settingsService.UpdateSetting(StartMinimized.Id, StartMinimized.Value!); | ||
}, | ||
canSave | ||
); | ||
_applyIsExec = ApplyCommand.IsExecuting.ToProperty(this, x => x.AppIsExec); | ||
} | ||
|
||
public Setting StartMinimized | ||
{ | ||
get => _startMinimized; | ||
set => this.RaiseAndSetIfChanged(ref _startMinimized, value); | ||
} | ||
|
||
public ReactiveCommand<Unit, Unit> ApplyCommand { get; init; } | ||
|
||
public bool AppIsExec => _applyIsExec?.Value ?? false; | ||
} |
2 changes: 1 addition & 1 deletion
2
YMouseButtonControl.Core/ViewModels/Interfaces/Dialogs/IGlobalSettingsDialogViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Globalization; | ||
using Avalonia.Data.Converters; | ||
|
||
namespace YMouseButtonControl.Converters; | ||
|
||
public class SettingValueConverter : IValueConverter | ||
{ | ||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
if (value is not string) | ||
{ | ||
return null; | ||
} | ||
|
||
if (value is not string valStr) | ||
{ | ||
return null; | ||
} | ||
return bool.Parse(valStr); | ||
} | ||
|
||
public object? ConvertBack( | ||
object? value, | ||
Type targetType, | ||
object? parameter, | ||
CultureInfo culture | ||
) | ||
{ | ||
return value?.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters