Merge branch 'FixProgramPluginSettings' into FixProgramUID

This commit is contained in:
Vic 2022-10-25 14:20:01 +08:00
commit 184aa57db9
6 changed files with 130 additions and 62 deletions

View file

@ -5,12 +5,12 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{DynamicResource flowlauncher_plugin_program_directory}" Title="{DynamicResource flowlauncher_plugin_program_directory}"
Width="400" Width="530"
Background="{DynamicResource PopuBGColor}" Background="{DynamicResource PopuBGColor}"
Foreground="{DynamicResource PopupTextColor}" Foreground="{DynamicResource PopupTextColor}"
ResizeMode="NoResize"
SizeToContent="Height" SizeToContent="Height"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen">
mc:Ignorable="d">
<WindowChrome.WindowChrome> <WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" /> <WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome> </WindowChrome.WindowChrome>
@ -19,7 +19,6 @@
<RowDefinition /> <RowDefinition />
<RowDefinition Height="80" /> <RowDefinition Height="80" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0"> <StackPanel Grid.Row="0">
<StackPanel> <StackPanel>
<Grid> <Grid>
@ -53,33 +52,78 @@
</Button> </Button>
</Grid> </Grid>
</StackPanel> </StackPanel>
<StackPanel Margin="26,12,26,0"> <StackPanel Margin="26,0,26,0">
<StackPanel Margin="0,0,0,12"> <StackPanel Grid.Row="0" Margin="0,0,0,12">
<TextBlock <TextBlock
Grid.Column="0" Grid.Column="0"
Margin="0,0,0,0" Margin="0,0,0,0"
FontSize="20" FontSize="20"
FontWeight="SemiBold" FontWeight="SemiBold"
Text="{DynamicResource flowlauncher_plugin_program_directory}" Text="{DynamicResource flowlauncher_plugin_program_edit_program_source_title}"
TextAlignment="Left" /> TextAlignment="Left" />
</StackPanel> </StackPanel>
<StackPanel Margin="0,0,0,10" Orientation="Horizontal"> <StackPanel>
<TextBox <TextBlock
Name="Directory" FontSize="14"
Width="268" Text="{DynamicResource flowlauncher_plugin_program_edit_program_source_tips}"
Margin="0,7" TextAlignment="Left"
VerticalAlignment="Center" /> TextWrapping="WrapWithOverflow" />
<Button </StackPanel>
Width="70"
Margin="10" <StackPanel Margin="0,10,0,0" Orientation="Horizontal">
HorizontalAlignment="Right" <Grid Width="470">
Click="BrowseButton_Click" <Grid.RowDefinitions>
Content="{DynamicResource flowlauncher_plugin_program_browse}" /> <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"
HorizontalAlignment="Right"
Click="BrowseButton_Click"
DockPanel.Dock="Right"
Content="{DynamicResource flowlauncher_plugin_program_browse}" />
<TextBox
Name="Directory"
Margin="10"
VerticalAlignment="Center"
HorizontalAlignment="Stretch" />
</DockPanel>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_program_enabled}" />
<CheckBox x:Name="Chkbox"
Grid.Row="1"
Grid.Column="1"
Margin="10,0"
VerticalAlignment="Center" />
</Grid>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<Border <Border
Grid.Row="1" Grid.Row="1"
Margin="0,14,0,0"
Background="{DynamicResource PopupButtonAreaBGColor}" Background="{DynamicResource PopupButtonAreaBGColor}"
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}" BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
BorderThickness="0,1,0,0"> BorderThickness="0,1,0,0">
@ -87,19 +131,17 @@
<Button <Button
x:Name="btnCancel" x:Name="btnCancel"
MinWidth="140" MinWidth="140"
Margin="0,0,5,0" Margin="10,0,5,0"
Click="BtnCancel_OnClick" Click="BtnCancel_OnClick"
Content="{DynamicResource cancel}" /> Content="{DynamicResource cancel}" />
<Button <Button
x:Name="btnAdd"
MinWidth="140" MinWidth="140"
Margin="5,0,0,0" Margin="5,0,10,0"
HorizontalAlignment="Right" Click="BtnAdd_OnClick"
Click="ButtonAdd_OnClick"
Content="{DynamicResource flowlauncher_plugin_program_update}" Content="{DynamicResource flowlauncher_plugin_program_update}"
Style="{DynamicResource AccentButtonStyle}" /> Style="{DynamicResource AccentButtonStyle}" />
</StackPanel> </StackPanel>
</Border> </Border>
</Grid> </Grid>
</Window>
</Window>

View file

@ -9,11 +9,12 @@ namespace Flow.Launcher.Plugin.Program
/// <summary> /// <summary>
/// Interaction logic for AddProgramSource.xaml /// Interaction logic for AddProgramSource.xaml
/// </summary> /// </summary>
public partial class AddProgramSource public partial class AddProgramSource : Window
{ {
private PluginInitContext _context; private PluginInitContext _context;
private ProgramSource _editing; private ProgramSource _editing;
private Settings _settings; private Settings _settings;
private bool update;
public AddProgramSource(PluginInitContext context, Settings settings) public AddProgramSource(PluginInitContext context, Settings settings)
{ {
@ -21,15 +22,19 @@ namespace Flow.Launcher.Plugin.Program
_context = context; _context = context;
_settings = settings; _settings = settings;
Directory.Focus(); Directory.Focus();
Chkbox.IsChecked = true;
update = false;
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
} }
public AddProgramSource(ProgramSource edit, Settings settings) public AddProgramSource(ProgramSource edit, Settings settings)
{ {
_editing = edit;
_settings = settings;
InitializeComponent(); InitializeComponent();
Directory.Text = _editing.Location; _updating = source;
_settings = settings;
update = true;
Chkbox.IsChecked = _updating.Enabled;
Directory.Text = _updating.Location;
} }
private void BrowseButton_Click(object sender, RoutedEventArgs e) private void BrowseButton_Click(object sender, RoutedEventArgs e)
@ -47,19 +52,19 @@ namespace Flow.Launcher.Plugin.Program
Close(); Close();
} }
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e) private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{ {
string s = Directory.Text; string path = Directory.Text;
if (!System.IO.Directory.Exists(s)) if (!System.IO.Directory.Exists(path))
{ {
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path")); System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path"));
return; return;
} }
if (_editing == null) if (!update)
{ {
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(Directory.Text, System.StringComparison.InvariantCultureIgnoreCase))) if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.InvariantCultureIgnoreCase)))
{ {
var source = new ProgramSource(Directory.Text); var source = new ProgramSource(path);
_settings.ProgramSources.Insert(0, source); _settings.ProgramSources.Insert(0, source);
ProgramSetting.ProgramSettingDisplayList.Add(source); ProgramSetting.ProgramSettingDisplayList.Add(source);
@ -67,7 +72,8 @@ namespace Flow.Launcher.Plugin.Program
} }
else else
{ {
_editing.Location = Directory.Text; _updating.Location = path;
_updating.Enabled = Chkbox.IsChecked ?? true; // Fixme, need to add to disabled source if not custom source
} }
DialogResult = true; DialogResult = true;

View file

@ -9,6 +9,7 @@
<system:String x:Key="flowlauncher_plugin_program_add">Add</system:String> <system:String x:Key="flowlauncher_plugin_program_add">Add</system:String>
<system:String x:Key="flowlauncher_plugin_program_name">Name</system:String> <system:String x:Key="flowlauncher_plugin_program_name">Name</system:String>
<system:String x:Key="flowlauncher_plugin_program_enable">Enable</system:String> <system:String x:Key="flowlauncher_plugin_program_enable">Enable</system:String>
<system:String x:Key="flowlauncher_plugin_program_enabled">Enabled</system:String>
<system:String x:Key="flowlauncher_plugin_program_disable">Disable</system:String> <system:String x:Key="flowlauncher_plugin_program_disable">Disable</system:String>
<system:String x:Key="flowlauncher_plugin_program_location">Location</system:String> <system:String x:Key="flowlauncher_plugin_program_location">Location</system:String>
<system:String x:Key="flowlauncher_plugin_program_all_programs">All Programs</system:String> <system:String x:Key="flowlauncher_plugin_program_all_programs">All Programs</system:String>
@ -34,7 +35,10 @@
<system:String x:Key="flowlauncher_plugin_program_pls_select_program_source">Please select a program source</system:String> <system:String x:Key="flowlauncher_plugin_program_pls_select_program_source">Please select a program source</system:String>
<system:String x:Key="flowlauncher_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String> <system:String x:Key="flowlauncher_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String>
<system:String x:Key="flowlauncher_plugin_program_update">OK</system:String> <system:String x:Key="flowlauncher_plugin_program_edit_program_source_title">Program Source</system:String>
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_tips">Edit directory and status of this program source.</system:String>
<system:String x:Key="flowlauncher_plugin_program_update">Update</system:String>
<system:String x:Key="flowlauncher_plugin_program_only_index_tip">Flow Launcher will only index files that end with the following suffixes. (Each suffix should split by ';' )</system:String> <system:String x:Key="flowlauncher_plugin_program_only_index_tip">Flow Launcher will only index files that end with the following suffixes. (Each suffix should split by ';' )</system:String>
<system:String x:Key="flowlauncher_plugin_program_update_file_suffixes">Successfully updated file suffixes</system:String> <system:String x:Key="flowlauncher_plugin_program_update_file_suffixes">Successfully updated file suffixes</system:String>
<system:String x:Key="flowlauncher_plugin_program_suffixes_cannot_empty">File suffixes can't be empty</system:String> <system:String x:Key="flowlauncher_plugin_program_suffixes_cannot_empty">File suffixes can't be empty</system:String>

View file

@ -191,12 +191,17 @@ namespace Flow.Launcher.Plugin.Program
return; return;
if (_uwps.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)) if (_uwps.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
{
_uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier) _uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false; .Enabled = false;
}
if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)) if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
{
_win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier) _win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false; .Enabled = false;
}
_settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete)); _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
} }

View file

@ -116,6 +116,8 @@
Drop="programSourceView_Drop" Drop="programSourceView_Drop"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler" GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler"
PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp" PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp"
MouseDoubleClick="programSourceView_MouseDoubleClick"
SelectionChanged="programSourceView_SelectionChanged"
SelectionMode="Extended"> SelectionMode="Extended">
<ListView.View> <ListView.View>
<GridView> <GridView>
@ -126,7 +128,7 @@
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>
<GridViewColumn Header="{DynamicResource flowlauncher_plugin_program_enable}"> <GridViewColumn Header="{DynamicResource flowlauncher_plugin_program_enabled}">
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBlock <TextBlock

View file

@ -36,6 +36,7 @@ namespace Flow.Launcher.Plugin.Program.Views
_settings.EnableDescription = value; _settings.EnableDescription = value;
} }
} }
public bool HideAppsPath public bool HideAppsPath
{ {
get => _settings.HideAppsPath; get => _settings.HideAppsPath;
@ -232,18 +233,14 @@ namespace Flow.Launcher.Plugin.Program.Views
.SelectedItems.Cast<ProgramSource>() .SelectedItems.Cast<ProgramSource>()
.ToList(); .ToList();
if (selectedItems.Count() == 0) if (selectedItems.Count == 0)
{ {
string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source"); string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
MessageBox.Show(msg); MessageBox.Show(msg);
return; return;
} }
if (selectedItems if (IsAllItemsUserAdded(selectedItems))
.Where(t1 => !_settings
.ProgramSources
.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
.Count() == 0)
{ {
var msg = string.Format(context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source")); var msg = string.Format(context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source"));
@ -254,7 +251,7 @@ namespace Flow.Launcher.Plugin.Program.Views
DeleteProgramSources(selectedItems); DeleteProgramSources(selectedItems);
} }
else if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems)) else if (HasMoreOrEqualEnabledItems(selectedItems))
{ {
ProgramSettingDisplay.SetProgramSourcesStatus(selectedItems, false); ProgramSettingDisplay.SetProgramSourcesStatus(selectedItems, false);
@ -326,35 +323,47 @@ namespace Flow.Launcher.Plugin.Program.Views
dataView.Refresh(); dataView.Refresh();
} }
private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(List<ProgramSource> selectedItems) private static bool HasMoreOrEqualEnabledItems(List<ProgramSource> 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 var selectedItems = programSourceView
.SelectedItems.Cast<ProgramSource>() .SelectedItems.Cast<ProgramSource>()
.ToList(); .ToList();
if (selectedItems if (IsAllItemsUserAdded(selectedItems))
.Where(t1 => !_settings
.ProgramSources
.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
.Count() == 0)
{ {
btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_delete"); btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_delete");
return;
} }
else if (HasMoreOrEqualEnabledItems(selectedItems))
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
{ {
btnProgramSourceStatus.Content = "Disable"; btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_disable");
} }
else else
{ {
btnProgramSourceStatus.Content = "Enable"; btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_enable");
} }
} }
private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (selectedProgramSource != null)
{
var add = new AddProgramSource(selectedProgramSource, _settings);
if (add.ShowDialog() ?? false)
{
ReIndexing();
}
}
}
private bool IsAllItemsUserAdded(List<ProgramSource> items)
{
return items.All(x => _settings.ProgramSources.Any(y => y.UniqueIdentifier == x.UniqueIdentifier));
}
} }
} }