2019-10-15 05:05:21 +08:00
|
|
|
using System.Collections.Generic;
|
2019-09-07 13:58:13 +08:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2016-05-06 04:15:13 +08:00
|
|
|
using System.Threading.Tasks;
|
2014-08-10 22:22:54 +08:00
|
|
|
using System.Windows;
|
2014-03-29 14:42:43 +08:00
|
|
|
using System.Windows.Controls;
|
2019-09-07 13:58:13 +08:00
|
|
|
using System.Windows.Input;
|
2019-09-08 20:16:47 +08:00
|
|
|
using Wox.Plugin.Program.Views.Models;
|
|
|
|
using Wox.Plugin.Program.Views.Commands;
|
2016-08-20 08:17:28 +08:00
|
|
|
using Wox.Plugin.Program.Programs;
|
2019-09-12 05:42:42 +08:00
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Windows.Data;
|
2014-03-29 14:42:43 +08:00
|
|
|
|
2019-09-08 20:16:47 +08:00
|
|
|
namespace Wox.Plugin.Program.Views
|
2014-03-29 14:42:43 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Interaction logic for ProgramSetting.xaml
|
|
|
|
/// </summary>
|
|
|
|
public partial class ProgramSetting : UserControl
|
|
|
|
{
|
2015-01-06 23:24:11 +08:00
|
|
|
private PluginInitContext context;
|
2016-04-21 08:53:21 +08:00
|
|
|
private Settings _settings;
|
2019-09-12 05:42:42 +08:00
|
|
|
private GridViewColumnHeader _lastHeaderClicked;
|
|
|
|
private ListSortDirection _lastDirection;
|
|
|
|
|
2019-09-08 20:16:47 +08:00
|
|
|
internal static List<ProgramSource> ProgramSettingDisplayList { get; set; }
|
2015-01-06 23:24:11 +08:00
|
|
|
|
2019-09-08 20:16:47 +08:00
|
|
|
public ProgramSetting(PluginInitContext context, Settings settings, Win32[] win32s, UWP.Application[] uwps)
|
2014-03-29 14:42:43 +08:00
|
|
|
{
|
2015-01-06 23:24:11 +08:00
|
|
|
this.context = context;
|
2014-03-29 14:42:43 +08:00
|
|
|
InitializeComponent();
|
|
|
|
Loaded += Setting_Loaded;
|
2016-03-28 10:09:57 +08:00
|
|
|
_settings = settings;
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2019-09-08 20:16:47 +08:00
|
|
|
ProgramSettingDisplayList = _settings.ProgramSources.LoadProgramSources();
|
|
|
|
programSourceView.ItemsSource = ProgramSettingDisplayList;
|
|
|
|
|
2016-03-28 10:09:57 +08:00
|
|
|
StartMenuEnabled.IsChecked = _settings.EnableStartMenuSource;
|
|
|
|
RegistryEnabled.IsChecked = _settings.EnableRegistrySource;
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
|
2014-08-10 22:22:54 +08:00
|
|
|
private void ReIndexing()
|
2014-03-29 14:42:43 +08:00
|
|
|
{
|
|
|
|
programSourceView.Items.Refresh();
|
2016-05-06 04:15:13 +08:00
|
|
|
Task.Run(() =>
|
2014-08-10 22:22:54 +08:00
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Visible; });
|
2016-05-07 10:55:09 +08:00
|
|
|
Main.IndexPrograms();
|
2016-01-07 05:34:42 +08:00
|
|
|
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Hidden; });
|
2014-08-10 22:22:54 +08:00
|
|
|
});
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2018-12-22 14:07:42 +08:00
|
|
|
var add = new AddProgramSource(context, _settings);
|
2015-05-02 22:17:42 +08:00
|
|
|
if(add.ShowDialog() ?? false)
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
ReIndexing();
|
2015-05-02 22:17:42 +08:00
|
|
|
}
|
2019-09-06 06:06:51 +08:00
|
|
|
|
|
|
|
programSourceView.Items.Refresh();
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
|
2014-07-10 23:16:46 +08:00
|
|
|
if (selectedProgramSource != null)
|
2014-03-29 14:42:43 +08:00
|
|
|
{
|
2015-01-06 23:24:11 +08:00
|
|
|
string msg = string.Format(context.API.GetTranslation("wox_plugin_program_delete_program_source"), selectedProgramSource.Location);
|
|
|
|
|
|
|
|
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
2014-07-10 23:06:50 +08:00
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
_settings.ProgramSources.Remove(selectedProgramSource);
|
2014-08-10 22:22:54 +08:00
|
|
|
ReIndexing();
|
2014-07-10 23:06:50 +08:00
|
|
|
}
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 23:24:11 +08:00
|
|
|
string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
|
|
|
|
MessageBox.Show(msg);
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
|
2014-07-10 23:16:46 +08:00
|
|
|
if (selectedProgramSource != null)
|
2014-03-29 14:42:43 +08:00
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
var add = new AddProgramSource(selectedProgramSource, _settings);
|
2015-05-02 22:17:42 +08:00
|
|
|
if (add.ShowDialog() ?? false)
|
2014-08-10 22:22:54 +08:00
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
ReIndexing();
|
2014-08-10 22:22:54 +08:00
|
|
|
}
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 23:24:11 +08:00
|
|
|
string msg = context.API.GetTranslation("wox_plugin_program_pls_select_program_source");
|
|
|
|
MessageBox.Show(msg);
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-12 23:07:54 +08:00
|
|
|
|
|
|
|
private void btnReindex_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
ReIndexing();
|
|
|
|
}
|
2014-08-13 23:16:45 +08:00
|
|
|
|
|
|
|
private void BtnProgramSuffixes_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
ProgramSuffixes p = new ProgramSuffixes(context, _settings);
|
2014-08-13 23:16:45 +08:00
|
|
|
p.ShowDialog();
|
|
|
|
}
|
2015-01-09 10:23:48 +08:00
|
|
|
|
|
|
|
private void programSourceView_DragEnter(object sender, DragEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
{
|
|
|
|
e.Effects = DragDropEffects.Link;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e.Effects = DragDropEffects.None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void programSourceView_Drop(object sender, DragEventArgs e)
|
|
|
|
{
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
|
|
|
|
|
if (files != null && files.Length > 0)
|
|
|
|
{
|
|
|
|
foreach (string s in files)
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
if (Directory.Exists(s))
|
2015-01-09 10:23:48 +08:00
|
|
|
{
|
2016-08-20 08:17:28 +08:00
|
|
|
_settings.ProgramSources.Add(new Settings.ProgramSource
|
2015-01-09 10:23:48 +08:00
|
|
|
{
|
2016-08-20 06:24:21 +08:00
|
|
|
Location = s
|
2015-01-09 10:23:48 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
ReIndexing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-02 21:47:03 +08:00
|
|
|
|
|
|
|
private void StartMenuEnabled_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
_settings.EnableStartMenuSource = StartMenuEnabled.IsChecked ?? false;
|
2015-05-02 21:47:03 +08:00
|
|
|
ReIndexing();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RegistryEnabled_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
_settings.EnableRegistrySource = RegistryEnabled.IsChecked ?? false;
|
2015-05-02 21:47:03 +08:00
|
|
|
ReIndexing();
|
|
|
|
}
|
2019-09-06 06:06:51 +08:00
|
|
|
|
|
|
|
private void btnLoadAllProgramSource_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2019-09-08 20:16:47 +08:00
|
|
|
ProgramSettingDisplayList.LoadAllApplications();
|
2019-09-06 06:06:51 +08:00
|
|
|
|
|
|
|
programSourceView.Items.Refresh();
|
|
|
|
}
|
2019-09-07 13:58:13 +08:00
|
|
|
|
2019-10-15 05:05:21 +08:00
|
|
|
private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2019-10-15 19:39:55 +08:00
|
|
|
var selectedItems = programSourceView
|
|
|
|
.SelectedItems.Cast<ProgramSource>()
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
|
2019-10-15 05:05:21 +08:00
|
|
|
{
|
2019-10-15 19:39:55 +08:00
|
|
|
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false);
|
|
|
|
|
|
|
|
ProgramSettingDisplayList.StoreDisabledInSettings();
|
2019-10-15 05:05:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-15 19:39:55 +08:00
|
|
|
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, true);
|
|
|
|
|
|
|
|
ProgramSettingDisplayList.RemoveDisabledFromSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedItems.IsReindexRequired())
|
|
|
|
ReIndexing();
|
2019-10-15 05:05:21 +08:00
|
|
|
|
|
|
|
programSourceView.SelectedItems.Clear();
|
|
|
|
|
|
|
|
programSourceView.Items.Refresh();
|
|
|
|
}
|
|
|
|
|
2019-09-07 13:58:13 +08:00
|
|
|
private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
|
{
|
|
|
|
programSourceView.SelectedItems.Clear();
|
|
|
|
}
|
2019-09-12 05:42:42 +08:00
|
|
|
|
|
|
|
private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
var headerClicked = e.OriginalSource as GridViewColumnHeader;
|
|
|
|
ListSortDirection direction;
|
|
|
|
|
|
|
|
if (headerClicked != null)
|
|
|
|
{
|
|
|
|
if (headerClicked.Role != GridViewColumnHeaderRole.Padding)
|
|
|
|
{
|
|
|
|
if (headerClicked != _lastHeaderClicked)
|
|
|
|
{
|
|
|
|
direction = ListSortDirection.Ascending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_lastDirection == ListSortDirection.Ascending)
|
|
|
|
{
|
|
|
|
direction = ListSortDirection.Descending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
direction = ListSortDirection.Ascending;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var columnBinding = headerClicked.Column.DisplayMemberBinding as Binding;
|
|
|
|
var sortBy = columnBinding?.Path.Path ?? headerClicked.Column.Header as string;
|
|
|
|
|
|
|
|
Sort(sortBy, direction);
|
|
|
|
|
|
|
|
_lastHeaderClicked = headerClicked;
|
|
|
|
_lastDirection = direction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Sort(string sortBy, ListSortDirection direction)
|
|
|
|
{
|
2019-10-15 19:39:55 +08:00
|
|
|
var dataView = CollectionViewSource.GetDefaultView(programSourceView.ItemsSource);
|
2019-09-12 05:42:42 +08:00
|
|
|
|
|
|
|
dataView.SortDescriptions.Clear();
|
|
|
|
SortDescription sd = new SortDescription(sortBy, direction);
|
|
|
|
dataView.SortDescriptions.Add(sd);
|
|
|
|
dataView.Refresh();
|
|
|
|
}
|
2019-10-15 05:05:21 +08:00
|
|
|
|
2019-10-15 19:39:55 +08:00
|
|
|
private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled()
|
2019-10-15 05:05:21 +08:00
|
|
|
{
|
|
|
|
var selectedItems = programSourceView
|
|
|
|
.SelectedItems.Cast<ProgramSource>()
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
return selectedItems.Where(x => x.Enabled).Count() >= selectedItems.Where(x => !x.Enabled).Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Row_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2019-10-15 19:39:55 +08:00
|
|
|
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled())
|
2019-10-15 05:05:21 +08:00
|
|
|
{
|
|
|
|
btnProgramSourceStatus.Content = "Disable";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
btnProgramSourceStatus.Content = "Enable";
|
|
|
|
}
|
|
|
|
}
|
2014-03-29 14:42:43 +08:00
|
|
|
}
|
2014-08-10 22:22:54 +08:00
|
|
|
}
|