From 66dee47edc78b01021f8a3dca8ffa5c576d4d4b3 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Tue, 6 Dec 2022 20:34:40 +0800 Subject: [PATCH 01/10] Refactor AddProgramSource dialog --- .../AddProgramSource.xaml | 9 +- .../AddProgramSource.xaml.cs | 85 ++-------- .../ViewModels/AddProgramSourceViewModel.cs | 149 ++++++++++++++++++ .../Views/ProgramSetting.xaml.cs | 7 +- 4 files changed, 173 insertions(+), 77 deletions(-) create mode 100644 Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml index b1a8744fda1..73a9190ac79 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml @@ -4,7 +4,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vm="clr-namespace:Flow.Launcher.Plugin.Program.ViewModels" + mc:Ignorable="d" Title="{DynamicResource flowlauncher_plugin_program_directory}" + d:DataContext="{d:DesignInstance vm:AddProgramSourceViewModel}" Width="Auto" Height="276" Background="{DynamicResource PopuBGColor}" @@ -98,11 +101,14 @@ HorizontalAlignment="Stretch" Click="BrowseButton_Click" Content="{DynamicResource flowlauncher_plugin_program_browse}" + IsEnabled="{Binding IsCustomSource}" DockPanel.Dock="Right" /> @@ -119,6 +125,7 @@ Grid.Row="1" Grid.Column="1" Margin="10,0" + IsChecked="{Binding Enabled, Mode=TwoWay}" VerticalAlignment="Center" /> @@ -142,7 +149,7 @@ MinWidth="140" Margin="5,0,10,0" Click="BtnAdd_OnClick" - Content="{DynamicResource flowlauncher_plugin_program_update}" + Content="{Binding AddBtnText, Mode=TwoWay}" Style="{DynamicResource AccentButtonStyle}" /> diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs index e88c9b988d1..ae6c5197e04 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs @@ -1,8 +1,5 @@ using System.Windows; -using System.Windows.Forms; -using Flow.Launcher.Plugin.Program.Views.Models; -using Flow.Launcher.Plugin.Program.Views; -using System.Linq; +using Flow.Launcher.Plugin.Program.ViewModels; namespace Flow.Launcher.Plugin.Program { @@ -11,41 +8,18 @@ namespace Flow.Launcher.Plugin.Program /// public partial class AddProgramSource : Window { - private PluginInitContext _context; - private ProgramSource _editing; - private Settings _settings; - private bool update; + private readonly AddProgramSourceViewModel ViewModel; - public AddProgramSource(PluginInitContext context, Settings settings) + public AddProgramSource(AddProgramSourceViewModel viewModel) { + ViewModel = viewModel; + DataContext = viewModel; InitializeComponent(); - _context = context; - _settings = settings; - Directory.Focus(); - Chkbox.IsChecked = true; - update = false; - btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add"); - } - - public AddProgramSource(PluginInitContext context, Settings settings, ProgramSource source) - { - InitializeComponent(); - _context = context; - _editing = source; - _settings = settings; - update = true; - Chkbox.IsChecked = _editing.Enabled; - Directory.Text = _editing.Location; } private void BrowseButton_Click(object sender, RoutedEventArgs e) { - var dialog = new FolderBrowserDialog(); - DialogResult result = dialog.ShowDialog(); - if (result == System.Windows.Forms.DialogResult.OK) - { - Directory.Text = dialog.SelectedPath; - } + ViewModel.Browse(); } private void BtnCancel_OnClick(object sender, RoutedEventArgs e) @@ -55,53 +29,16 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e) private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { - string path = Directory.Text; - bool modified = false; - if (!System.IO.Directory.Exists(path)) - { - System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path")); - return; - } - if (!update) + var status = ViewModel.AddOrUpdate(); + if (status == null) { - if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase))) - { - var source = new ProgramSource(path); - modified = true; - _settings.ProgramSources.Insert(0, source); - ProgramSetting.ProgramSettingDisplayList.Add(source); - } - else - { - System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); - return; - } + return; // Invalid } else { - // Separate checks to avoid changing UniqueIdentifier of UWP - if (!_editing.Location.Equals(path, System.StringComparison.OrdinalIgnoreCase)) - { - if (ProgramSetting.ProgramSettingDisplayList - .Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase))) - { - // Check if the new location is used - // No need to check win32 or uwp, just override them - System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); - return; - } - modified = true; - _editing.Location = path; // Changes UniqueIdentifier internally - } - if (_editing.Enabled != Chkbox.IsChecked) - { - modified = true; - _editing.Enabled = Chkbox.IsChecked ?? true; - } + DialogResult = status ?? false; + Close(); } - - DialogResult = modified; - Close(); } } } diff --git a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs new file mode 100644 index 00000000000..92981b1fdf9 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs @@ -0,0 +1,149 @@ +using System; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using Flow.Launcher.Plugin.Program.Views; +using Flow.Launcher.Plugin.Program.Views.Models; + +namespace Flow.Launcher.Plugin.Program.ViewModels +{ + public class AddProgramSourceViewModel : BaseModel + { + private readonly Settings Settings; + + private bool enabled = true; + public bool Enabled + { + get => enabled; + set + { + enabled = value; + OnPropertyChanged(nameof(Enabled)); + } + } + + private string location = string.Empty; + public string Location + { + get => location; + set + { + location = value; + OnPropertyChanged(nameof(Location)); + } + } + + public ProgramSource Source { get; init; } + public IPublicAPI API { get; init; } + public string AddBtnText { get; init; } + private bool LocationModified = false; + private bool StatusModified = false; + public bool IsCustomSource { get; init; } = true; + public bool IsNotCustomSource => !IsCustomSource; + + public AddProgramSourceViewModel(PluginInitContext context, Settings settings) + { + API = context.API; + Settings = settings; + AddBtnText = API.GetTranslation("flowlauncher_plugin_program_add"); + } + + public AddProgramSourceViewModel(PluginInitContext context, Settings settings, ProgramSource programSource) : this(context, settings) + { + Source = programSource; + enabled = Source.Enabled; + location = Source.Location; + AddBtnText = API.GetTranslation("flowlauncher_plugin_program_update"); + IsCustomSource = Settings.ProgramSources.Any(x => x.UniqueIdentifier == Source.UniqueIdentifier); + + this.PropertyChanged += (_, args) => + { + switch (args.PropertyName) + { + case nameof(Location): + LocationModified = true; + break; + case nameof(Enabled): + StatusModified = true; + break; + } + }; + } + + public void Browse() + { + var dialog = new FolderBrowserDialog(); + DialogResult result = dialog.ShowDialog(); + if (result == DialogResult.OK) + { + Location = dialog.SelectedPath; + } + } + + public bool? AddProgramSource() + { + if (!Directory.Exists(Location)) + { + System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_invalid_path")); + return null; + } + else if (DuplicateSource(Location)) + { + System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); + return null; + } + else + { + var source = new ProgramSource(Location, Enabled); + Settings.ProgramSources.Insert(0, source); + ProgramSetting.ProgramSettingDisplayList.Add(source); + return true; + } + } + + public bool? UpdateProgramSource() + { + // Separate checks to avoid changing UniqueIdentifier of UWP when changing Enabled + if (LocationModified) + { + if (!Directory.Exists(Location)) + { + System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_invalid_path")); + return null; + } + else if (DuplicateSource(Location)) + { + // No need to check win32 or uwp, just override them + System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); + return null; + } + else + { + Source.Location = Location; // Changes UniqueIdentifier internally + } + } + if (StatusModified) + { + Source.Enabled = Enabled; + } + return StatusModified || LocationModified; + } + + public bool? AddOrUpdate() + { + if (Source == null) + { + return AddProgramSource(); + } + else + { + return UpdateProgramSource(); + } + } + + public static bool DuplicateSource(string location) + { + return ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(location, StringComparison.OrdinalIgnoreCase)); + } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs index b8c2bca2245..377ef5cf3a1 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs @@ -9,6 +9,7 @@ using Flow.Launcher.Plugin.Program.Programs; using System.ComponentModel; using System.Windows.Data; +using Flow.Launcher.Plugin.Program.ViewModels; namespace Flow.Launcher.Plugin.Program.Views { @@ -135,7 +136,8 @@ private async void ReIndexing() private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e) { - var add = new AddProgramSource(context, _settings); + var vm = new AddProgramSourceViewModel(context, _settings); + var add = new AddProgramSource(vm); if (add.ShowDialog() ?? false) { ReIndexing(); @@ -170,7 +172,8 @@ private void EditProgramSource(ProgramSource selectedProgramSource) } else { - var add = new AddProgramSource(context, _settings, selectedProgramSource); + var vm = new AddProgramSourceViewModel(context, _settings, selectedProgramSource); + var add = new AddProgramSource(vm); if (add.ShowDialog() ?? false) { if (selectedProgramSource.Enabled) From bfb29e384d81337247f51406f846550f03390181 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Tue, 6 Dec 2022 22:47:27 +0800 Subject: [PATCH 02/10] Fix Hashcode --- .../Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs index 571dc00174e..93c33e9ad18 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs @@ -83,7 +83,7 @@ public bool Equals(IProgram program) public override int GetHashCode() { - return HashCode.Combine(UniqueIdentifier); + return uniqueIdentifier.GetHashCode(); } } } From cca10ca5a015c6d7aebd747474a99a518230e3e7 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Tue, 6 Dec 2022 22:54:12 +0800 Subject: [PATCH 03/10] Move show msgbox to view --- .../AddProgramSource.xaml.cs | 14 +++++------ .../ViewModels/AddProgramSourceViewModel.cs | 23 ++++++++----------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs index ae6c5197e04..c41e9f68898 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs @@ -30,15 +30,15 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e) private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { var status = ViewModel.AddOrUpdate(); - if (status == null) + bool modified = status.Item1; + string msg = status.Item2; + if (modified == false && msg != null) { - return; // Invalid - } - else - { - DialogResult = status ?? false; - Close(); + MessageBox.Show(msg); // Invalid + return; } + DialogResult = modified; + Close(); } } } diff --git a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs index 92981b1fdf9..c47525fde2f 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs @@ -80,42 +80,37 @@ public void Browse() } } - public bool? AddProgramSource() + public (bool, string) AddProgramSource() { if (!Directory.Exists(Location)) { - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_invalid_path")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_invalid_path")); } else if (DuplicateSource(Location)) { - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); } else { var source = new ProgramSource(Location, Enabled); Settings.ProgramSources.Insert(0, source); ProgramSetting.ProgramSettingDisplayList.Add(source); - return true; + return (true, null); } } - public bool? UpdateProgramSource() + public (bool, string) UpdateProgramSource() { // Separate checks to avoid changing UniqueIdentifier of UWP when changing Enabled if (LocationModified) { if (!Directory.Exists(Location)) { - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_invalid_path")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_invalid_path")); } else if (DuplicateSource(Location)) { - // No need to check win32 or uwp, just override them - System.Windows.MessageBox.Show(API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); - return null; + return (false, API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source")); } else { @@ -126,10 +121,10 @@ public void Browse() { Source.Enabled = Enabled; } - return StatusModified || LocationModified; + return (StatusModified || LocationModified, null); } - public bool? AddOrUpdate() + public (bool, string) AddOrUpdate() { if (Source == null) { From 1990226c716227b21797a2ea4113a9f52be9024d Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Wed, 7 Dec 2022 00:35:41 +0800 Subject: [PATCH 04/10] Fix item can't be unselected after editing Location --- .../Views/ProgramSetting.xaml.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs index 377ef5cf3a1..086c9ecb3be 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs @@ -174,6 +174,10 @@ private void EditProgramSource(ProgramSource selectedProgramSource) { var vm = new AddProgramSourceViewModel(context, _settings, selectedProgramSource); var add = new AddProgramSource(vm); + int selectedIndex = programSourceView.SelectedIndex; + // https://stackoverflow.com/questions/16789360/wpf-listbox-items-with-changing-hashcode + // Or it can't be unselected after changing Location + programSourceView.UnselectAll(); if (add.ShowDialog() ?? false) { if (selectedProgramSource.Enabled) @@ -188,6 +192,7 @@ private void EditProgramSource(ProgramSource selectedProgramSource) } ReIndexing(); } + programSourceView.SelectedIndex = selectedIndex; } } From 7bc4cfb9648e46ae85a2f99672a07fce258feb10 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Wed, 7 Dec 2022 00:48:42 +0800 Subject: [PATCH 05/10] Hide Browse Button when editing win32 or uwp --- Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml index 73a9190ac79..94eba077447 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml @@ -18,6 +18,9 @@ + + + @@ -101,7 +104,7 @@ HorizontalAlignment="Stretch" Click="BrowseButton_Click" Content="{DynamicResource flowlauncher_plugin_program_browse}" - IsEnabled="{Binding IsCustomSource}" + Visibility="{Binding IsCustomSource, Converter={StaticResource BooleanToVisibilityConverter}}" DockPanel.Dock="Right" /> Date: Wed, 7 Dec 2022 01:09:26 +0800 Subject: [PATCH 06/10] Remove LocationConverter --- .../LocationConverter.cs | 33 ------------------- .../ViewModels/AddProgramSourceViewModel.cs | 1 - .../Views/ProgramSetting.xaml | 3 +- 3 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 Plugins/Flow.Launcher.Plugin.Program/LocationConverter.cs diff --git a/Plugins/Flow.Launcher.Plugin.Program/LocationConverter.cs b/Plugins/Flow.Launcher.Plugin.Program/LocationConverter.cs deleted file mode 100644 index 41384aa8379..00000000000 --- a/Plugins/Flow.Launcher.Plugin.Program/LocationConverter.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Globalization; -using System.Windows.Data; -using System.Windows.Markup; - -namespace Flow.Launcher.Plugin.Program -{ - public class LocationConverter : MarkupExtension, IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - var text = value as string; - if (string.IsNullOrEmpty(text)) - { - return string.Empty; - } - else - { - return text; - } - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return this; - } - } -} diff --git a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs index c47525fde2f..4d653ddb202 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs @@ -101,7 +101,6 @@ public void Browse() public (bool, string) UpdateProgramSource() { - // Separate checks to avoid changing UniqueIdentifier of UWP when changing Enabled if (LocationModified) { if (!Directory.Exists(Location)) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml index 3f9e7196c21..2bc70a90a37 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:program="clr-namespace:Flow.Launcher.Plugin.Program" Height="520" DataContext="{Binding RelativeSource={RelativeSource Self}}" mc:Ignorable="d"> @@ -172,7 +171,7 @@ - + From e720e4facd574224723966b1ada2da11db08b162 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Wed, 7 Dec 2022 13:58:20 +0800 Subject: [PATCH 07/10] mark modified in setters --- .../ViewModels/AddProgramSourceViewModel.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs index 4d653ddb202..b7d1bddbb17 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs @@ -18,7 +18,7 @@ public bool Enabled set { enabled = value; - OnPropertyChanged(nameof(Enabled)); + StatusModified = true; } } @@ -29,7 +29,7 @@ public string Location set { location = value; - OnPropertyChanged(nameof(Location)); + LocationModified = true; } } @@ -55,19 +55,6 @@ public AddProgramSourceViewModel(PluginInitContext context, Settings settings, P location = Source.Location; AddBtnText = API.GetTranslation("flowlauncher_plugin_program_update"); IsCustomSource = Settings.ProgramSources.Any(x => x.UniqueIdentifier == Source.UniqueIdentifier); - - this.PropertyChanged += (_, args) => - { - switch (args.PropertyName) - { - case nameof(Location): - LocationModified = true; - break; - case nameof(Enabled): - StatusModified = true; - break; - } - }; } public void Browse() From 0afcf7eafe24acd9d22eed8678637770ba73f3c3 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Wed, 7 Dec 2022 14:01:12 +0800 Subject: [PATCH 08/10] Use auto deconstructor and rename return value --- .../Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs | 4 +--- .../ViewModels/AddProgramSourceViewModel.cs | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs index c41e9f68898..be8b768bd8f 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs @@ -29,9 +29,7 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e) private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { - var status = ViewModel.AddOrUpdate(); - bool modified = status.Item1; - string msg = status.Item2; + var (modified, msg) = ViewModel.AddOrUpdate(); if (modified == false && msg != null) { MessageBox.Show(msg); // Invalid diff --git a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs index b7d1bddbb17..ffe9b2dcea4 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs @@ -67,7 +67,7 @@ public void Browse() } } - public (bool, string) AddProgramSource() + public (bool modified, string message) AddProgramSource() { if (!Directory.Exists(Location)) { @@ -86,7 +86,7 @@ public void Browse() } } - public (bool, string) UpdateProgramSource() + public (bool modified, string message) UpdateProgramSource() { if (LocationModified) { @@ -110,7 +110,7 @@ public void Browse() return (StatusModified || LocationModified, null); } - public (bool, string) AddOrUpdate() + public (bool modified, string message) AddOrUpdate() { if (Source == null) { From 25e4b501cb0df5d17e8b028abdd5bad05f6f0060 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sun, 11 Dec 2022 18:16:15 +0800 Subject: [PATCH 09/10] Use default binding mode --- Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml index 94eba077447..612fd7b2042 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml @@ -152,7 +152,7 @@ MinWidth="140" Margin="5,0,10,0" Click="BtnAdd_OnClick" - Content="{Binding AddBtnText, Mode=TwoWay}" + Content="{Binding AddBtnText}" Style="{DynamicResource AccentButtonStyle}" /> From ae8955bf41a56a24f90bbeb9d5ca85a4fd31b40e Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Mon, 12 Dec 2022 14:40:52 -0600 Subject: [PATCH 10/10] fix path not changed in the textbox --- .../ViewModels/AddProgramSourceViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs index ffe9b2dcea4..1bb1ca13c80 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/ViewModels/AddProgramSourceViewModel.cs @@ -30,6 +30,7 @@ public string Location { location = value; LocationModified = true; + OnPropertyChanged(); } }