Merge pull request #1897 from onesounds/GuideForBookmarkPlugin

Custom Browser managing UI Improvement in Bookmarks Plugin
This commit is contained in:
VictoriousRaptor 2023-02-15 12:26:51 +08:00 committed by GitHub
commit d3025a6966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 218 additions and 102 deletions

View file

@ -11,6 +11,7 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@ -66,12 +67,8 @@
<Target Name="CopyDLLs" AfterTargets="Build">
<Message Text="Executing CopyDLLs task" Importance="High" />
<Copy
SourceFiles="$(TargetDir)\runtimes\win-x64\native\SQLite.Interop.dll"
DestinationFolder="$(TargetDir)\x64" />
<Copy
SourceFiles="$(TargetDir)\runtimes\win-x86\native\SQLite.Interop.dll"
DestinationFolder="$(TargetDir)\x86" />
<Copy SourceFiles="$(TargetDir)\runtimes\win-x64\native\SQLite.Interop.dll" DestinationFolder="$(TargetDir)\x64" />
<Copy SourceFiles="$(TargetDir)\runtimes\win-x86\native\SQLite.Interop.dll" DestinationFolder="$(TargetDir)\x86" />
</Target>
<Target Name="DeleteRuntimesFolder" AfterTargets="CopyDLLs">

View file

@ -20,7 +20,11 @@
<system:String x:Key="flowlauncher_plugin_browserbookmark_browserName">Browser Name</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory">Data Directory Path</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_addBrowserBookmark">Add</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_editBrowserBookmark">Edit</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_removeBrowserBookmark">Delete</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_browseBrowserBookmark">Browse</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_others">Others</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_browserEngine">Browser Engine</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_guideMessage01">If you are not using Chrome, Firefox or Edge, or you are using their portable version, you need to add bookmarks data directory and select correct browser engine to make this plugin work.</system:String>
<system:String x:Key="flowlauncher_plugin_browserbookmark_guideMessage02">For example: Brave's engine is Chromium; and its default bookmarks data location is: "%LOCALAPPDATA%\BraveSoftware\Brave-Browser\UserData". For Firefox engine, the bookmarks directory is the userdata folder contains the places.sqlite file.</system:String>
</ResourceDictionary>

View file

@ -17,16 +17,16 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
{
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu, IDisposable
{
private PluginInitContext context;
private static PluginInitContext context;
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
private Settings _settings { get; set; }
private static List<Bookmark> cachedBookmarks = new List<Bookmark>();
private static Settings _settings;
public void Init(PluginInitContext context)
{
this.context = context;
Main.context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
cachedBookmarks = BookmarkLoader.LoadAllBookmarks(_settings);
@ -136,6 +136,11 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
}
public void ReloadData()
{
ReloadAllBookmarks();
}
public static void ReloadAllBookmarks()
{
cachedBookmarks.Clear();

View file

@ -7,7 +7,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="clr-namespace:Flow.Launcher.Infrastructure.UI;assembly=Flow.Launcher.Infrastructure"
Title="{DynamicResource flowlauncher_plugin_browserbookmark_bookmarkDataSetting}"
Width="520"
Width="550"
Background="{DynamicResource PopuBGColor}"
Foreground="{DynamicResource PopupTextColor}"
KeyDown="WindowKeyDown"
@ -39,7 +39,7 @@
</Grid.ColumnDefinitions>
<Button
Grid.Column="4"
Click="ConfirmCancelEditCustomBrowser"
Click="CancelEditCustomBrowser"
Style="{StaticResource TitleBarCloseButtonStyle}">
<Path
Width="46"
@ -71,8 +71,8 @@
TextAlignment="Left" />
</StackPanel>
<StackPanel Margin="0,10,0,20" Orientation="Horizontal">
<Grid Width="444" HorizontalAlignment="Stretch">
<StackPanel Margin="0,0,0,20" Orientation="Horizontal">
<Grid Width="474" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
@ -81,17 +81,45 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
<StackPanel
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="5,0,0,20">
<TextBlock
Margin="0,0,0,4"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_guideMessage01}"
TextWrapping="WrapWithOverflow" />
<TextBlock
Margin="0,4,0,4"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_guideMessage02}"
TextWrapping="WrapWithOverflow" />
<TextBlock
Margin="0,4,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_guideMessage03}"
TextWrapping="WrapWithOverflow" />
</StackPanel>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="5,0,20,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_browserName}" />
<TextBox
Grid.Row="0"
Grid.Row="1"
Grid.Column="1"
Width="120"
Height="34"
@ -100,7 +128,7 @@
VerticalAlignment="Center"
Text="{Binding Name}" />
<TextBlock
Grid.Row="1"
Grid.Row="2"
Grid.Column="0"
Margin="5,10,20,0"
HorizontalAlignment="Left"
@ -108,7 +136,7 @@
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_browserEngine}" />
<ComboBox
Grid.Row="1"
Grid.Row="2"
Grid.Column="1"
Width="120"
Height="34"
@ -116,24 +144,35 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
ItemsSource="{Binding Source={ui:EnumBindingSource {x:Type local:BrowserType}}}"
SelectedItem="{Binding BrowserType}">
</ComboBox>
SelectedItem="{Binding BrowserType}" />
<TextBlock
Grid.Row="2"
Grid.Row="3"
Grid.Column="0"
Margin="5,10,20,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory}" />
<TextBox
Grid.Row="2"
<DockPanel
Grid.Row="3"
Grid.Column="1"
Height="34"
Margin="5,10,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Text="{Binding DataDirectoryPath}" />
LastChildFill="True">
<Button
Height="34"
MinWidth="100"
Margin="5,10,0,0"
VerticalContentAlignment="Stretch"
Click="OnSelectPathClick"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_browseBrowserBookmark}"
DockPanel.Dock="Right" />
<TextBox
Name="PathTextBox"
Height="34"
Margin="5,10,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Text="{Binding DataDirectoryPath}" />
</DockPanel>
</Grid>
</StackPanel>
</StackPanel>
@ -148,13 +187,13 @@
x:Name="btnCancel"
MinWidth="145"
Margin="0,0,5,0"
Click="ConfirmCancelEditCustomBrowser"
Click="CancelEditCustomBrowser"
Content="{DynamicResource cancel}" />
<Button
Name="btnConfirm"
MinWidth="145"
Margin="5,0,0,0"
Click="ConfirmCancelEditCustomBrowser"
Click="ConfirmEditCustomBrowser"
Style="{StaticResource AccentButtonStyle}">
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
</Button>

View file

@ -1,7 +1,7 @@
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Forms;
namespace Flow.Launcher.Plugin.BrowserBookmark.Views
{
@ -22,29 +22,36 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
BrowserType = browser.BrowserType,
};
}
private void ConfirmCancelEditCustomBrowser(object sender, RoutedEventArgs e)
private void ConfirmEditCustomBrowser(object sender, RoutedEventArgs e)
{
if (DataContext is CustomBrowser editBrowser && e.Source is Button button)
{
if (button.Name == "btnConfirm")
{
currentCustomBrowser.Name = editBrowser.Name;
currentCustomBrowser.DataDirectoryPath = editBrowser.DataDirectoryPath;
currentCustomBrowser.BrowserType = editBrowser.BrowserType;
Close();
}
}
CustomBrowser editBrowser = (CustomBrowser)DataContext;
currentCustomBrowser.Name = editBrowser.Name;
currentCustomBrowser.DataDirectoryPath = editBrowser.DataDirectoryPath;
currentCustomBrowser.BrowserType = editBrowser.BrowserType;
DialogResult = true;
Close();
}
private void WindowKeyDown(object sender, KeyEventArgs e)
private void CancelEditCustomBrowser(object sender, RoutedEventArgs e)
{
Close();
}
private void WindowKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
ConfirmCancelEditCustomBrowser(sender, e);
ConfirmEditCustomBrowser(sender, e);
}
}
private void OnSelectPathClick(object sender, RoutedEventArgs e)
{
var dialog = new FolderBrowserDialog();
dialog.ShowDialog();
CustomBrowser editBrowser = (CustomBrowser)DataContext;
editBrowser.DataDirectoryPath = dialog.SelectedPath;
}
}
}

View file

@ -1,67 +1,83 @@
<UserControl
x:Class="Flow.Launcher.Plugin.BrowserBookmark.Views.SettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="500"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d">
x:Class="Flow.Launcher.Plugin.BrowserBookmark.Views.SettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="500"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d">
<Grid Margin="60,0,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<StackPanel Margin="0,10,0,10" Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="10" Text="{DynamicResource flowlauncher_plugin_browserbookmark_loadBrowserFrom}"/>
<CheckBox Margin="0,0,15,0"
Content="Chrome"
IsChecked="{Binding Settings.LoadChromeBookmark}"/>
<CheckBox Margin="0,0,15,0"
Content="Edge"
IsChecked="{Binding Settings.LoadEdgeBookmark}"/>
<CheckBox Margin="0,0,15,0"
Content="Firefox"
IsChecked="{Binding Settings.LoadFirefoxBookmark}"/>
<TextBlock Margin="10" Text="{DynamicResource flowlauncher_plugin_browserbookmark_loadBrowserFrom}" />
<CheckBox
Margin="0,0,15,0"
Content="Chrome"
IsChecked="{Binding LoadChromeBookmark}" />
<CheckBox
Margin="0,0,15,0"
Content="Edge"
IsChecked="{Binding LoadEdgeBookmark}" />
<CheckBox
Margin="0,0,15,0"
Content="Firefox"
IsChecked="{Binding LoadFirefoxBookmark}" />
<Button
Margin="0,0,15,0"
Click="Others_Click"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_others}"/>
Margin="0,0,15,0"
Click="Others_Click"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_others}" />
</StackPanel>
<StackPanel Name="CustomBrowsersList" Visibility="Collapsed">
<ListView
Name="CustomBrowsers"
Height="auto"
Margin="10"
BorderBrush="DarkGray"
BorderThickness="1"
ItemsSource="{Binding Settings.CustomChromiumBrowsers}"
MouseDoubleClick="MouseDoubleClickOnSelectedCustomBrowser"
SelectedItem="{Binding SelectedCustomBrowser}"
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}">
Name="CustomBrowsers"
Height="auto"
Margin="10"
BorderBrush="DarkGray"
BorderThickness="1"
ItemsSource="{Binding Settings.CustomChromiumBrowsers}"
MouseDoubleClick="MouseDoubleClickOnSelectedCustomBrowser"
SelectedItem="{Binding SelectedCustomBrowser}"
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name, Mode=OneWay}"
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserName}"/>
<GridViewColumn DisplayMemberBinding="{Binding DataDirectoryPath, Mode=OneWay}"
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory}"/>
<GridViewColumn DisplayMemberBinding="{Binding BrowserType, Mode=OneWay}"
Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserEngine}"/>
<GridViewColumn DisplayMemberBinding="{Binding Name, Mode=OneWay}" Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserName}" />
<GridViewColumn DisplayMemberBinding="{Binding DataDirectoryPath, Mode=OneWay}" Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserBookmarkDataDirectory}" />
<GridViewColumn DisplayMemberBinding="{Binding BrowserType, Mode=OneWay}" Header="{DynamicResource flowlauncher_plugin_browserbookmark_browserEngine}" />
</GridView>
</ListView.View>
</ListView>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button
MinWidth="130"
Margin="10"
Click="NewCustomBrowser"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_addBrowserBookmark}"/>
MinWidth="130"
Margin="10"
Click="NewCustomBrowser"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_addBrowserBookmark}" />
<Button
MinWidth="120"
Margin="10"
Click="DeleteCustomBrowser"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_removeBrowserBookmark}"/>
MinWidth="130"
Margin="10"
Click="EditCustomBrowser"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_editBrowserBookmark}">
<Button.Style>
<Style BasedOn="{StaticResource DefaultButtonStyle}" TargetType="Button">
<Setter Property="IsEnabled" Value="true" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=CustomBrowsers, Path=SelectedItems.Count}" Value="0">
<Setter Property="IsEnabled" Value="false" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button
MinWidth="120"
Margin="10"
Click="DeleteCustomBrowser"
Content="{DynamicResource flowlauncher_plugin_browserbookmark_removeBrowserBookmark}" />
</StackPanel>
</StackPanel>
</StackPanel>

View file

@ -2,16 +2,46 @@
using Flow.Launcher.Plugin.BrowserBookmark.Models;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows.Controls;
using System.Threading.Tasks;
namespace Flow.Launcher.Plugin.BrowserBookmark.Views
{
public partial class SettingsControl : INotifyPropertyChanged
{
public Settings Settings { get; }
public CustomBrowser SelectedCustomBrowser { get; set; }
public bool LoadChromeBookmark
{
get => Settings.LoadChromeBookmark;
set
{
Settings.LoadChromeBookmark = value;
_ = Task.Run(() => Main.ReloadAllBookmarks());
}
}
public bool LoadFirefoxBookmark
{
get => Settings.LoadFirefoxBookmark;
set
{
Settings.LoadFirefoxBookmark = value;
_ = Task.Run(() => Main.ReloadAllBookmarks());
}
}
public bool LoadEdgeBookmark
{
get => Settings.LoadEdgeBookmark;
set
{
Settings.LoadEdgeBookmark = value;
_ = Task.Run(() => Main.ReloadAllBookmarks());
}
}
public bool OpenInNewBrowserWindow
{
get => Settings.OpenInNewBrowserWindow;
@ -42,6 +72,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
})
{
Settings.CustomChromiumBrowsers.Add(newBrowser);
_ = Task.Run(() => Main.ReloadAllBookmarks());
}
}
@ -50,16 +81,15 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
if (CustomBrowsers.SelectedItem is CustomBrowser selectedCustomBrowser)
{
Settings.CustomChromiumBrowsers.Remove(selectedCustomBrowser);
_ = Task.Run(() => Main.ReloadAllBookmarks());
}
}
private void MouseDoubleClickOnSelectedCustomBrowser(object sender, MouseButtonEventArgs e)
{
if (SelectedCustomBrowser is null)
return;
var window = new CustomBrowserSettingWindow(SelectedCustomBrowser);
window.ShowDialog();
EditSelectedCustomBrowser();
}
private void Others_Click(object sender, RoutedEventArgs e)
{
@ -70,5 +100,23 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
else
CustomBrowsersList.Visibility = Visibility.Collapsed;
}
private void EditCustomBrowser(object sender, RoutedEventArgs e)
{
EditSelectedCustomBrowser();
}
private void EditSelectedCustomBrowser()
{
if (SelectedCustomBrowser is null)
return;
var window = new CustomBrowserSettingWindow(SelectedCustomBrowser);
var result = window.ShowDialog() ?? false;
if (result)
{
_ = Task.Run(() => Main.ReloadAllBookmarks());
}
}
}
}