add Explorer plugin's settings page

This commit is contained in:
Jeremy Wu 2020-06-06 22:13:22 +10:00
parent e34bcbd1ba
commit 0ee0fb8d2b
10 changed files with 305 additions and 43 deletions

View file

@ -187,7 +187,7 @@ namespace Flow.Launcher.Plugin.SharedCommands
}
///<summary>
/// Returns the previous level directory if path incomplete.
/// Returns the previous level directory if path incomplete (does not end with '\').
/// Does not check if previous level directory exists.
/// Returns passed in string if is complete path
///</summary>

View file

@ -7,6 +7,7 @@ using System.Windows;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using System.Linq;
using System.Reflection;
@ -192,8 +193,8 @@ namespace Flow.Launcher.Plugin.Explorer
SubTitle = "Path: " + record.FullPath,
Action = _ =>
{
if(!Main.Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x == record.FullPath))
Main.Settings.IndexSearchExcludedSubdirectoryPaths.Add(record.FullPath);
if(!Main.Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath))
Main.Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath });
var pluginDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location.ToString());

View file

@ -4,6 +4,7 @@
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ApplicationIcon />
<StartupObject />

View file

@ -0,0 +1,29 @@
using Newtonsoft.Json;
using System;
using System.Linq;
namespace Flow.Launcher.Plugin.Explorer.Search.FolderLinks
{
[JsonObject(MemberSerialization.OptIn)]
public class FolderLink
{
[JsonProperty]
public string Path { get; set; }
public string Nickname
{
get
{
var path = Path.EndsWith(Constants.DirectorySeperator) ? Path[0..^1] : Path;
if (path.EndsWith(':'))
return path[0..^1] + " Drive";
return path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last()
+ " (" + System.IO.Path.GetDirectoryName(Path) + ")";
}
}
}
}

View file

@ -6,7 +6,7 @@ using System.Linq;
using System.Text;
using System.Windows;
namespace Flow.Launcher.Plugin.Explorer.Search.QuickFolderLinks
namespace Flow.Launcher.Plugin.Explorer.Search.FolderLinks
{
public class QuickFolderAccess
{

View file

@ -1,18 +0,0 @@
using Newtonsoft.Json;
using System;
using System.Linq;
namespace Flow.Launcher.Plugin.Explorer.Search.QuickFolderLinks
{
[JsonObject(MemberSerialization.OptIn)]
public class FolderLink
{
[JsonProperty]
public string Path { get; set; }
public string Nickname =>
Path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last()
+ " (" + System.IO.Path.GetDirectoryName(Path) + ")";
}
}

View file

@ -1,5 +1,5 @@
using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo;
using Flow.Launcher.Plugin.Explorer.Search.QuickFolderLinks;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
using Flow.Launcher.Plugin.SharedCommands;
using System;
@ -28,7 +28,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
{
var querySearch = query.Search;
var quickFolderLinks = quickFolderAccess.FolderList(query, _settings.FolderLinks);
var quickFolderLinks = quickFolderAccess.FolderList(query, _settings.QuickFolderAccessLinks);
if (quickFolderLinks.Count > 0)
return quickFolderLinks;
@ -113,7 +113,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
return false;
if (_settings.IndexSearchExcludedSubdirectoryPaths
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath).StartsWith(x)))
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath).StartsWith(x.Path)))
return false;
return _indexSearch.PathIsIndexed(locationPath);

View file

@ -1,5 +1,4 @@
using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo;
using Flow.Launcher.Plugin.Explorer.Search.QuickFolderLinks;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using Newtonsoft.Json;
using System.Collections.Generic;
@ -11,12 +10,12 @@ namespace Flow.Launcher.Plugin.Explorer
public int MaxResult { get; set; } = 100;
[JsonProperty]
public List<FolderLink> FolderLinks { get; set; } = new List<FolderLink>();
public List<FolderLink> QuickFolderAccessLinks { get; set; } = new List<FolderLink>();
[JsonProperty]
public bool UseWindowsIndexForDirectorySearch { get; set; } = true;
[JsonProperty]
public List<string> IndexSearchExcludedSubdirectoryPaths { get; set; } = new List<string>();
public List<FolderLink> IndexSearchExcludedSubdirectoryPaths { get; set; } = new List<FolderLink>();
}
}
}

View file

@ -6,7 +6,48 @@
xmlns:viewModels="clr-namespace:Flow.Launcher.Plugin.Explorer.ViewModels"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<UserControl.Resources>
<DataTemplate x:Key="ListViewTemplateFolderLinks">
<TextBlock
Text="{Binding Nickname, Mode=OneTime}"
Margin="0,5,0,5" />
</DataTemplate>
<DataTemplate x:Key="ListViewTemplateExcludedPaths">
<TextBlock
Text="{Binding Nickname, Mode=OneTime}"
Margin="0,5,0,5" />
</DataTemplate>
</UserControl.Resources>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<ScrollViewer Margin="20 35 0 0" HorizontalScrollBarVisibility="Hidden" Grid.Row="0" VerticalScrollBarVisibility="Auto">
<StackPanel>
<Expander Name="expFolderLinks" Header="Quick Folder Access Paths"
Expanded="expFolderLinks_Click" Collapsed="expFolderLinks_Click">
<ListView
x:Name="lbxFolderLinks" AllowDrop="True"
Drop="lbxFolders_Drop"
DragEnter="lbxFolders_DragEnter"
ItemTemplate="{StaticResource ListViewTemplateFolderLinks}"/>
</Expander>
<Expander x:Name="expExcludedPaths" Header="Index Search Excluded Paths"
Expanded="expExcludedPaths_Click" Collapsed="expExcludedPaths_Click"
Margin="0 10 0 0">
<ListView
x:Name="lbxExcludedPaths" AllowDrop="True"
Drop="lbxFolders_Drop"
DragEnter="lbxFolders_DragEnter"
ItemTemplate="{StaticResource ListViewTemplateExcludedPaths}"/>
</Expander>
</StackPanel>
</ScrollViewer>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnDelete" Click="btnDelete_Click" Width="100" Margin="10" Content="{DynamicResource flowlauncher_plugin_folder_delete}"/>
<Button x:Name="btnEdit" Click="btnEdit_Click" Width="100" Margin="10" Content="{DynamicResource flowlauncher_plugin_folder_edit}"/>
<Button x:Name="btnAdd" Click="btnAdd_Click" Width="100" Margin="10" Content="{DynamicResource flowlauncher_plugin_folder_add}"/>
</StackPanel>
</Grid>
</UserControl>

View file

@ -1,27 +1,236 @@
using Flow.Launcher.Plugin.Explorer.ViewModels;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using DataFormats = System.Windows.DataFormats;
using DragDropEffects = System.Windows.DragDropEffects;
using DragEventArgs = System.Windows.DragEventArgs;
using MessageBox = System.Windows.MessageBox;
namespace Flow.Launcher.Plugin.Explorer.Views
{
/// <summary>
/// Interaction logic for ExplorerSettings.xaml
/// </summary>
public partial class ExplorerSettings : UserControl
public partial class ExplorerSettings
{
public ExplorerSettings()
{
InitializeComponent();
lbxFolderLinks.ItemsSource = Main.Settings.QuickFolderAccessLinks;
lbxExcludedPaths.ItemsSource = Main.Settings.IndexSearchExcludedSubdirectoryPaths;
RefreshView();
}
public void RefreshView()
{
lbxFolderLinks.Items.SortDescriptions.Add(new SortDescription("Path", ListSortDirection.Ascending));
lbxExcludedPaths.Items.SortDescriptions.Add(new SortDescription("Path", ListSortDirection.Ascending));
btnDelete.Visibility = Visibility.Hidden;
btnEdit.Visibility = Visibility.Hidden;
btnAdd.Visibility = Visibility.Hidden;
if (expFolderLinks.IsExpanded || expExcludedPaths.IsExpanded)
{
btnAdd.Visibility = Visibility.Visible;
if ((lbxFolderLinks.Items.Count == 0 && lbxExcludedPaths.Items.Count == 0)
&& btnDelete.Visibility == Visibility.Visible
&& btnEdit.Visibility == Visibility.Visible)
{
btnDelete.Visibility = Visibility.Hidden;
btnEdit.Visibility = Visibility.Hidden;
}
if (expFolderLinks.IsExpanded
&& lbxFolderLinks.Items.Count > 0
&& btnDelete.Visibility == Visibility.Hidden
&& btnEdit.Visibility == Visibility.Hidden)
{
btnDelete.Visibility = Visibility.Visible;
btnEdit.Visibility = Visibility.Visible;
}
if (expExcludedPaths.IsExpanded
&& lbxExcludedPaths.Items.Count > 0
&& btnDelete.Visibility == Visibility.Hidden
&& btnEdit.Visibility == Visibility.Hidden)
{
btnDelete.Visibility = Visibility.Visible;
btnEdit.Visibility = Visibility.Visible;
}
}
lbxFolderLinks.Items.Refresh();
lbxExcludedPaths.Items.Refresh();
}
private void expFolderLinks_Click(object sender, RoutedEventArgs e)
{
if (expFolderLinks.IsExpanded)
expFolderLinks.Height = 235;
if (!expFolderLinks.IsExpanded)
expFolderLinks.Height = Double.NaN;
if (expExcludedPaths.IsExpanded)
expExcludedPaths.IsExpanded = false;
RefreshView();
}
private void expExcludedPaths_Click(object sender, RoutedEventArgs e)
{
if (expExcludedPaths.IsExpanded)
expFolderLinks.Height = Double.NaN;
if (expFolderLinks.IsExpanded)
expFolderLinks.IsExpanded = false;
RefreshView();
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
var selectedRow = lbxFolderLinks.SelectedItem as FolderLink?? lbxExcludedPaths.SelectedItem as FolderLink;
if (selectedRow != null)
{
string msg = string.Format(Main.Context.API.GetTranslation("flowlauncher_plugin_folder_delete_folder_link"), selectedRow.Path);
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
if (expFolderLinks.IsExpanded)
Main.Settings.QuickFolderAccessLinks.Remove(selectedRow);
if (expExcludedPaths.IsExpanded)
Main.Settings.IndexSearchExcludedSubdirectoryPaths.Remove(selectedRow);
RefreshView();
}
}
else
{
string warning = Main.Context.API.GetTranslation("flowlauncher_plugin_folder_select_folder_link_warning");
MessageBox.Show(warning);
}
}
private void btnEdit_Click(object sender, RoutedEventArgs e)
{
var selectedRow = lbxFolderLinks.SelectedItem as FolderLink ?? lbxExcludedPaths.SelectedItem as FolderLink;
if (selectedRow != null)
{
var folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.SelectedPath = selectedRow.Path;
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
if (expFolderLinks.IsExpanded)
{
var link = Main.Settings.QuickFolderAccessLinks.First(x => x.Path == selectedRow.Path);
link.Path = folderBrowserDialog.SelectedPath;
}
if (expExcludedPaths.IsExpanded)
{
var link = Main.Settings.IndexSearchExcludedSubdirectoryPaths.First(x => x.Path == selectedRow.Path);
link.Path = folderBrowserDialog.SelectedPath;
}
}
RefreshView();
}
else
{
string warning = Main.Context.API.GetTranslation("flowlauncher_plugin_folder_select_folder_link_warning");
MessageBox.Show(warning);
}
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
var folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
var newFolderLink = new FolderLink
{
Path = folderBrowserDialog.SelectedPath
};
AddFolderLink(newFolderLink);
}
RefreshView();
}
private void lbxFolders_Drop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files != null && files.Count() > 0)
{
if (expFolderLinks.IsExpanded && Main.Settings.QuickFolderAccessLinks == null)
Main.Settings.QuickFolderAccessLinks = new List<FolderLink>();
foreach (string s in files)
{
if (Directory.Exists(s))
{
var newFolderLink = new FolderLink
{
Path = s
};
AddFolderLink(newFolderLink);
}
RefreshView();
}
}
}
private void AddFolderLink(FolderLink newFolderLink)
{
if (expFolderLinks.IsExpanded
&& !Main.Settings.QuickFolderAccessLinks.Any(x => x.Path == newFolderLink.Path))
{
if (Main.Settings.QuickFolderAccessLinks == null)
Main.Settings.QuickFolderAccessLinks = new List<FolderLink>();
Main.Settings.QuickFolderAccessLinks.Add(newFolderLink);
}
if (expExcludedPaths.IsExpanded
&& !Main.Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == newFolderLink.Path))
{
if (Main.Settings.IndexSearchExcludedSubdirectoryPaths == null)
Main.Settings.IndexSearchExcludedSubdirectoryPaths = new List<FolderLink>();
Main.Settings.IndexSearchExcludedSubdirectoryPaths.Add(newFolderLink);
}
}
private void lbxFolders_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effects = DragDropEffects.Link;
}
else
{
e.Effects = DragDropEffects.None;
}
}
}
}