Add Checkbox to edit program source window

1. Add Checkbox to edit program source window
2. Double click item to edit
This commit is contained in:
Vic 2022-10-18 14:51:13 +08:00
parent 8fd9a200b4
commit c56c343ed6
4 changed files with 107 additions and 44 deletions

View file

@ -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">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>
@ -19,7 +19,6 @@
<RowDefinition />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<StackPanel>
<Grid>
@ -53,8 +52,8 @@
</Button>
</Grid>
</StackPanel>
<StackPanel Margin="26,12,26,0">
<StackPanel Margin="0,0,0,12">
<StackPanel Margin="26,0,26,0">
<StackPanel Grid.Row="0" Margin="0,0,0,12">
<TextBlock
Grid.Column="0"
Margin="0,0,0,0"
@ -63,23 +62,69 @@
Text="{DynamicResource flowlauncher_plugin_program_directory}"
TextAlignment="Left" />
</StackPanel>
<StackPanel Margin="0,0,0,10" Orientation="Horizontal">
<TextBox
Name="Directory"
Width="268"
Margin="0,7"
VerticalAlignment="Center" />
<Button
Width="70"
Margin="10"
HorizontalAlignment="Right"
Click="BrowseButton_Click"
Content="{DynamicResource flowlauncher_plugin_program_browse}" />
<StackPanel>
<TextBlock
FontSize="14"
Text="{DynamicResource customeQueryHotkeyTips}"
TextAlignment="Left"
TextWrapping="WrapWithOverflow" />
</StackPanel>
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
<Grid Width="470">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_program_directory}" />
<DockPanel
Grid.Row="0"
Grid.Column="1"
LastChildFill="True">
<Button
Width="70"
Margin="10"
HorizontalAlignment="Right"
Click="BrowseButton_Click"
DockPanel.Dock="Right"
Content="{DynamicResource flowlauncher_plugin_program_browse}" />
<TextBox
Name="tbDirectory"
Margin="10"
VerticalAlignment="Center"
HorizontalAlignment="Stretch" />
</DockPanel>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource enable}" />
<CheckBox x:Name="Chkbox"
Grid.Row="1"
Grid.Column="1"
Margin="10,0"
VerticalAlignment="Center" />
</Grid>
</StackPanel>
</StackPanel>
</StackPanel>
<Border
Grid.Row="1"
Margin="0,14,0,0"
Background="{DynamicResource PopupButtonAreaBGColor}"
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
BorderThickness="0,1,0,0">
@ -87,19 +132,17 @@
<Button
x:Name="btnCancel"
MinWidth="140"
Margin="0,0,5,0"
Margin="10,0,5,0"
Click="BtnCancel_OnClick"
Content="{DynamicResource cancel}" />
<Button
x:Name="btnAdd"
MinWidth="140"
Margin="5,0,0,0"
HorizontalAlignment="Right"
Click="ButtonAdd_OnClick"
Margin="5,0,10,0"
Click="BtnAdd_OnClick"
Content="{DynamicResource flowlauncher_plugin_program_update}"
Style="{DynamicResource AccentButtonStyle}" />
</StackPanel>
</Border>
</Grid>
</Window>
</Window>

View file

@ -9,27 +9,31 @@ namespace Flow.Launcher.Plugin.Program
/// <summary>
/// Interaction logic for AddProgramSource.xaml
/// </summary>
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;

View file

@ -116,6 +116,7 @@
Drop="programSourceView_Drop"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler"
PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp"
MouseDoubleClick="ProgramSourceView_MouseDoubleClick"
SelectionMode="Extended">
<ListView.View>
<GridView>

View file

@ -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();
}
}
}
}
}
}