From c56c343ed6c7fbfae717dc6cce7a55e8f2a952a3 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 14:51:13 +0800
Subject: [PATCH] Add Checkbox to edit program source window
1. Add Checkbox to edit program source window
2. Double click item to edit
---
.../AddProgramSource.xaml | 93 ++++++++++++++-----
.../AddProgramSource.xaml.cs | 38 ++++----
.../Views/ProgramSetting.xaml | 1 +
.../Views/ProgramSetting.xaml.cs | 19 +++-
4 files changed, 107 insertions(+), 44 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
index 9230eb062..b1e21a3e3 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
@@ -5,12 +5,12 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{DynamicResource flowlauncher_plugin_program_directory}"
- Width="400"
+ Width="530"
Background="{DynamicResource PopuBGColor}"
Foreground="{DynamicResource PopupTextColor}"
+ ResizeMode="NoResize"
SizeToContent="Height"
- WindowStartupLocation="CenterScreen"
- mc:Ignorable="d">
+ WindowStartupLocation="CenterScreen">
@@ -19,7 +19,6 @@
-
@@ -53,8 +52,8 @@
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -87,19 +132,17 @@
-
-
-
+
\ No newline at end of file
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 045d363b3..3442a1a22 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -9,27 +9,31 @@ namespace Flow.Launcher.Plugin.Program
///
/// Interaction logic for AddProgramSource.xaml
///
- public partial class AddProgramSource
+ public partial class AddProgramSource : Window
{
private PluginInitContext _context;
- private Settings.ProgramSource _editing;
+ private Settings.ProgramSource _updating;
private Settings _settings;
+ private bool update;
public AddProgramSource(PluginInitContext context, Settings settings)
{
InitializeComponent();
_context = context;
_settings = settings;
- Directory.Focus();
+ tbDirectory.Focus();
+ Chkbox.IsChecked = true;
+ update = false;
}
- public AddProgramSource(Settings.ProgramSource edit, Settings settings)
+ public AddProgramSource(Settings.ProgramSource source, Settings settings)
{
- _editing = edit;
+ _updating = source;
_settings = settings;
-
+ update = true;
InitializeComponent();
- Directory.Text = _editing.Location;
+ Chkbox.IsChecked = _updating.Enabled;
+ tbDirectory.Text = _updating.Location;
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
@@ -38,7 +42,7 @@ namespace Flow.Launcher.Plugin.Program
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
- Directory.Text = dialog.SelectedPath;
+ tbDirectory.Text = dialog.SelectedPath;
}
}
@@ -47,22 +51,23 @@ namespace Flow.Launcher.Plugin.Program
Close();
}
- private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
+ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
- string s = Directory.Text;
- if (!System.IO.Directory.Exists(s))
+ string path = tbDirectory.Text;
+ if (!System.IO.Directory.Exists(path))
{
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path"));
return;
}
- if (_editing == null)
+ if (!update)
{
- if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == Directory.Text))
+ if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == path))
{
var source = new ProgramSource
{
- Location = Directory.Text,
- UniqueIdentifier = Directory.Text
+ Location = path,
+ UniqueIdentifier = path,
+ Enabled = Chkbox.IsChecked ?? true
};
_settings.ProgramSources.Insert(0, source);
@@ -71,7 +76,8 @@ namespace Flow.Launcher.Plugin.Program
}
else
{
- _editing.Location = Directory.Text;
+ _updating.Location = path;
+ _updating.Enabled = Chkbox.IsChecked ?? true;
}
DialogResult = true;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
index f07879465..fa2d4551f 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
@@ -116,6 +116,7 @@
Drop="programSourceView_Drop"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler"
PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp"
+ MouseDoubleClick="ProgramSourceView_MouseDoubleClick"
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 1a31e8c28..dcfdd1185 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -352,12 +352,25 @@ namespace Flow.Launcher.Plugin.Program.Views
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
{
- btnProgramSourceStatus.Content = "Disable";
+ btnProgramSourceStatus.Content = "Disable"; // todo
}
else
{
btnProgramSourceStatus.Content = "Enable";
}
}
+
+ 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)
+ {
+ ReIndexing();
+ }
+ }
+ }
}
-}
\ No newline at end of file
+}