Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

<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_not_user_added">Please select program sources that you added</system:String>
<system:String x:Key="flowlauncher_plugin_program_duplicate_program_source">Another program source with the same location already exists.</system:String>

<system:String x:Key="flowlauncher_plugin_program_edit_program_source_title">Program Source</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Click="btnEditProgramSource_OnClick"
Content="{DynamicResource flowlauncher_plugin_program_edit}" />
<Button
x:Name="btnDeleteProgramSource"
MinWidth="100"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}"
Click="btnDeleteProgramSource_OnClick"
Content="{DynamicResource flowlauncher_plugin_program_delete}" />
<Button
x:Name="btnAddProgramSource"
MinWidth="100"
Expand Down
72 changes: 47 additions & 25 deletions Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ private void ViewRefresh()
{
btnProgramSourceStatus.Visibility = Visibility.Hidden;
btnEditProgramSource.Visibility = Visibility.Hidden;
btnDeleteProgramSource.Visibility = Visibility.Hidden;
}

if (programSourceView.Items.Count > 0
Expand All @@ -141,6 +142,7 @@ private void ViewRefresh()
{
btnProgramSourceStatus.Visibility = Visibility.Visible;
btnEditProgramSource.Visibility = Visibility.Visible;
btnDeleteProgramSource.Visibility = Visibility.Visible;
}

programSourceView.Items.Refresh();
Expand Down Expand Up @@ -270,8 +272,8 @@ private void programSourceView_Drop(object sender, DragEventArgs e)

if (directoriesToAdd.Count > 0)
{
directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x));
directoriesToAdd.ForEach(x => ProgramSettingDisplayList.Add(x));
directoriesToAdd.ForEach(_settings.ProgramSources.Add);
directoriesToAdd.ForEach(ProgramSettingDisplayList.Add);

ViewRefresh();
ReIndexing();
Expand All @@ -296,24 +298,12 @@ private async void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs

if (selectedItems.Count == 0)
{
string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
var msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
context.API.ShowMsgBox(msg);
return;
}

if (IsAllItemsUserAdded(selectedItems))
{
var msg = string.Format(
context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source"));

if (context.API.ShowMsgBox(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
{
return;
}

DeleteProgramSources(selectedItems);
}
else if (HasMoreOrEqualEnabledItems(selectedItems))
if (HasMoreOrEqualEnabledItems(selectedItems))
{
await ProgramSettingDisplay.SetProgramSourcesStatusAsync(selectedItems, false);

Expand Down Expand Up @@ -341,10 +331,9 @@ private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseBut

private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
{
var headerClicked = e.OriginalSource as GridViewColumnHeader;
ListSortDirection direction;

if (headerClicked != null)
if (e.OriginalSource is GridViewColumnHeader headerClicked)
{
if (headerClicked.Role != GridViewColumnHeaderRole.Padding)
{
Expand Down Expand Up @@ -397,11 +386,7 @@ private void programSourceView_SelectionChanged(object sender, SelectionChangedE
.SelectedItems.Cast<ProgramSource>()
.ToList();

if (IsAllItemsUserAdded(selectedItems))
{
btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_delete");
}
else if (HasMoreOrEqualEnabledItems(selectedItems))
if (HasMoreOrEqualEnabledItems(selectedItems))
{
btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_disable");
}
Expand All @@ -420,15 +405,52 @@ private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventA
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
private async void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var selectedItems = programSourceView
.SelectedItems.Cast<ProgramSource>()
.ToList();

if (selectedItems.Count == 0)
{
var msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
context.API.ShowMsgBox(msg);
return;
}

if (!IsAllItemsUserAdded(selectedItems))
{
var msg1 = context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source_not_user_added");
context.API.ShowMsgBox(msg1);
return;
}

var msg2 = context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source");
if (context.API.ShowMsgBox(msg2, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
{
return;
}

DeleteProgramSources(selectedItems);

if (await selectedItems.IsReindexRequiredAsync())
ReIndexing();

programSourceView.SelectedItems.Clear();

ViewRefresh();
}

private bool IsAllItemsUserAdded(List<ProgramSource> items)
{
return items.All(x => _settings.ProgramSources.Any(y => y.UniqueIdentifier == x.UniqueIdentifier));
}

private void ListView_SizeChanged(object sender, SizeChangedEventArgs e)
{
ListView listView = sender as ListView;
GridView gView = listView.View as GridView;
var listView = sender as ListView;
var gView = listView.View as GridView;

var workingWidth =
listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar
Expand Down
Loading