From dcec3611de87e4845ab6ec32be220b7aff6960df Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Tue, 18 Oct 2022 19:28:12 +0800 Subject: [PATCH] Fix button text issue --- .../AddProgramSource.xaml | 2 +- .../AddProgramSource.xaml.cs | 3 +- .../Languages/en.xaml | 4 +- .../Flow.Launcher.Plugin.Program/Settings.cs | 11 ++++++ .../Views/ProgramSetting.xaml | 3 +- .../Views/ProgramSetting.xaml.cs | 39 ++++++++----------- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml index a286eb485..af62a8f64 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml @@ -59,7 +59,7 @@ Margin="0,0,0,0" FontSize="20" FontWeight="SemiBold" - Text="{DynamicResource flowlauncher_plugin_program_edit_program_source}" + Text="{DynamicResource flowlauncher_plugin_program_edit_program_source_title}" TextAlignment="Left" /> diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs index 3442a1a22..49e066754 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs @@ -24,14 +24,15 @@ namespace Flow.Launcher.Plugin.Program tbDirectory.Focus(); Chkbox.IsChecked = true; update = false; + btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add"); } public AddProgramSource(Settings.ProgramSource source, Settings settings) { + InitializeComponent(); _updating = source; _settings = settings; update = true; - InitializeComponent(); Chkbox.IsChecked = _updating.Enabled; tbDirectory.Text = _updating.Location; } diff --git a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml index 101f75bc9..0da7e83b3 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml @@ -34,10 +34,10 @@ Please select a program source Are you sure you want to delete the selected program sources? - Edit Program Source + Program Source Edit directory and status of this program source. - OK + Update Flow Launcher will only index files that end with the following suffixes. (Each suffix should split by ';' ) Successfully updated file suffixes File suffixes can't be empty diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs index d97ddd993..3fd6a2206 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Windows.Input; namespace Flow.Launcher.Plugin.Program { @@ -41,6 +42,16 @@ namespace Flow.Launcher.Plugin.Program public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; } public bool Enabled { get; set; } = true; public string UniqueIdentifier { get; set; } + + public override bool Equals(object obj) + { + return obj is ProgramSource other && other.UniqueIdentifier.ToLower() == this.UniqueIdentifier.ToLower(); + } + + public override int GetHashCode() + { + return HashCode.Combine(UniqueIdentifier.ToLower()); + } } public class DisabledProgramSource : ProgramSource { } diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml index fa2d4551f..b3c17be28 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml @@ -116,7 +116,8 @@ Drop="programSourceView_Drop" GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler" PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp" - MouseDoubleClick="ProgramSourceView_MouseDoubleClick" + MouseDoubleClick="programSourceView_MouseDoubleClick" + SelectionChanged="programSourceView_SelectionChanged" SelectionMode="Extended"> diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs index dcfdd1185..79082da56 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs @@ -235,18 +235,14 @@ namespace Flow.Launcher.Plugin.Program.Views .SelectedItems.Cast() .ToList(); - if (selectedItems.Count() == 0) + if (selectedItems.Count == 0) { string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source"); MessageBox.Show(msg); return; } - if (selectedItems - .Where(t1 => !_settings - .ProgramSources - .Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)) - .Count() == 0) + if (IsAllItemsUserAdded(selectedItems)) { var msg = string.Format(context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source")); @@ -257,7 +253,7 @@ namespace Flow.Launcher.Plugin.Program.Views DeleteProgramSources(selectedItems); } - else if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems)) + else if (HasMoreOrEqualEnabledItems(selectedItems)) { ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false); @@ -329,42 +325,36 @@ namespace Flow.Launcher.Plugin.Program.Views dataView.Refresh(); } - private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(List selectedItems) + private static bool HasMoreOrEqualEnabledItems(List items) { - return selectedItems.Where(x => x.Enabled).Count() >= selectedItems.Where(x => !x.Enabled).Count(); + return items.Where(x => x.Enabled).Count() >= items.Count / 2; } - private void Row_OnClick(object sender, RoutedEventArgs e) + private void programSourceView_SelectionChanged(object sender, SelectionChangedEventArgs e) { var selectedItems = programSourceView .SelectedItems.Cast() .ToList(); - if (selectedItems - .Where(t1 => !_settings - .ProgramSources - .Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)) - .Count() == 0) + if (IsAllItemsUserAdded(selectedItems)) { btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_delete"); - return; } - - if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems)) + else if (HasMoreOrEqualEnabledItems(selectedItems)) { - btnProgramSourceStatus.Content = "Disable"; // todo + btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_disable"); } else { - btnProgramSourceStatus.Content = "Enable"; + btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_enable"); } } - private void ProgramSourceView_MouseDoubleClick(object sender, MouseButtonEventArgs e) + private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource; if (selectedProgramSource != null) - { + { var add = new AddProgramSource(selectedProgramSource, _settings); if (add.ShowDialog() ?? false) { @@ -372,5 +362,10 @@ namespace Flow.Launcher.Plugin.Program.Views } } } + + private bool IsAllItemsUserAdded(List items) + { + return items.All(x => _settings.ProgramSources.Any(y => y == x)); + } } }