mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #276 from taooceros/PluginPriority
Add Plugin Priority Settings
This commit is contained in:
commit
96fc1346a9
11 changed files with 159 additions and 10 deletions
|
|
@ -31,6 +31,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
metadata.ActionKeyword = settings.ActionKeywords[0];
|
||||
}
|
||||
metadata.Disabled = settings.Disabled;
|
||||
metadata.Priority = settings.Priority;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -40,7 +41,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
Name = metadata.Name,
|
||||
Version = metadata.Version,
|
||||
ActionKeywords = metadata.ActionKeywords,
|
||||
Disabled = metadata.Disabled
|
||||
Disabled = metadata.Disabled,
|
||||
Priority = metadata.Priority
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -52,6 +54,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
public List<string> ActionKeywords { get; set; } // a reference of the action keywords from plugin manager
|
||||
public int Priority { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used only to save the state of the plugin in settings
|
||||
|
|
|
|||
|
|
@ -36,12 +36,15 @@ namespace Flow.Launcher.Plugin
|
|||
public List<string> ActionKeywords { get; set; }
|
||||
|
||||
public string IcoPath { get; set;}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public int Priority { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Init time include both plugin load time and init time
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@
|
|||
<system:String x:Key="actionKeywords">Action keyword:</system:String>
|
||||
<system:String x:Key="currentActionKeywords">Current action keyword:</system:String>
|
||||
<system:String x:Key="newActionKeyword">New action keyword:</system:String>
|
||||
<system:String x:Key="currentPriority">Current Priority: </system:String>
|
||||
<system:String x:Key="newPriority">New Priority: </system:String>
|
||||
<system:String x:Key="pluginDirectory">Plugin Directory</system:String>
|
||||
<system:String x:Key="author">Author</system:String>
|
||||
<system:String x:Key="plugin_init_time">Init time:</system:String>
|
||||
|
|
@ -104,6 +106,10 @@
|
|||
</system:String>
|
||||
<system:String x:Key="releaseNotes">Release Notes</system:String>
|
||||
|
||||
<!--Priority Setting Dialog-->
|
||||
<system:String x:Key="priority_tips">Greater the number, the higher the result will be ranked. Try setting it as 5. If you want the results to be lower than any other plugin's, provide a negative number</system:String>
|
||||
<system:String x:Key="invalidPriority">Please provide an valid integer for Priority!</system:String>
|
||||
|
||||
<!--Action Keyword Setting Dialog-->
|
||||
<system:String x:Key="oldActionKeywords">Old Action Keyword</system:String>
|
||||
<system:String x:Key="newActionKeywords">New Action Keyword</system:String>
|
||||
|
|
|
|||
45
Flow.Launcher/PriorityChangeWindow.xaml
Normal file
45
Flow.Launcher/PriorityChangeWindow.xaml
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<Window x:Class="Flow.Launcher.PriorityChangeWindow"
|
||||
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"
|
||||
xmlns:local="clr-namespace:Flow.Launcher"
|
||||
Loaded="PriorityChangeWindow_Loaded"
|
||||
mc:Ignorable="d"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="PriorityChangeWindow" Height="250" Width="300">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="60"/>
|
||||
<RowDefinition Height="75"/>
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left" Text="{DynamicResource currentPriority}" />
|
||||
<TextBlock x:Name="OldPriority" Grid.Row="0" Grid.Column="1" Margin="170 10 10 10" FontSize="14"
|
||||
VerticalAlignment="Center" HorizontalAlignment="Left" />
|
||||
|
||||
<TextBlock FontSize="14" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Left" Text="{DynamicResource newPriority}" />
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1">
|
||||
<TextBox x:Name="tbAction" Margin="140 10 15 10" Width="105" VerticalAlignment="Center" HorizontalAlignment="Left" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.ColumnSpan="1" Grid.Column="1" Foreground="Gray"
|
||||
Text="{DynamicResource priority_tips}" TextWrapping="Wrap"
|
||||
Margin="0,0,20,0"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="3" Grid.Column="1">
|
||||
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="30"
|
||||
Content="{DynamicResource cancel}" />
|
||||
<Button x:Name="btnDone" Margin="10 0 10 0" Width="80" Height="30" Click="btnDone_OnClick">
|
||||
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
69
Flow.Launcher/PriorityChangeWindow.xaml.cs
Normal file
69
Flow.Launcher/PriorityChangeWindow.xaml.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
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.Shapes;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction Logic of PriorityChangeWindow.xaml
|
||||
/// </summary>
|
||||
public partial class PriorityChangeWindow : Window
|
||||
{
|
||||
private readonly PluginPair plugin;
|
||||
private Settings settings;
|
||||
private readonly Internationalization translater = InternationalizationManager.Instance;
|
||||
private readonly PluginViewModel pluginViewModel;
|
||||
|
||||
public PriorityChangeWindow(string pluginId, Settings settings, PluginViewModel pluginViewModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
plugin = PluginManager.GetPluginForId(pluginId);
|
||||
this.settings = settings;
|
||||
this.pluginViewModel = pluginViewModel;
|
||||
if (plugin == null)
|
||||
{
|
||||
MessageBox.Show(translater.GetTranslation("cannotFindSpecifiedPlugin"));
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnDone_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (int.TryParse(tbAction.Text.Trim(), out var newPriority))
|
||||
{
|
||||
pluginViewModel.ChangePriority(newPriority);
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
string msg = translater.GetTranslation("invalidPriority");
|
||||
MessageBox.Show(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void PriorityChangeWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OldPriority.Text = pluginViewModel.Priority.ToString();
|
||||
tbAction.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,10 +173,14 @@
|
|||
<TextBlock Text="{Binding PluginPair.Metadata.Description}"
|
||||
Grid.Row="1" Opacity="0.5" />
|
||||
<DockPanel Grid.Row="2" Margin="0 10 0 8" HorizontalAlignment="Right">
|
||||
|
||||
<TextBlock Text="Priority" Margin="20,0,0,0"/>
|
||||
<TextBlock Text="{Binding Priority}"
|
||||
ToolTip="Change Plugin Results Priority"
|
||||
Margin="5 0 0 0" Cursor="Hand" Foreground="Blue"
|
||||
MouseUp="OnPluginPriorityClick"/>
|
||||
<TextBlock Text="{DynamicResource actionKeywords}"
|
||||
Visibility="{Binding ActionKeywordsVisibility}"
|
||||
Margin="20 0 0 0"/>
|
||||
Margin="5 0 0 0"/>
|
||||
<TextBlock Text="{Binding ActionKeywordsText}"
|
||||
Visibility="{Binding ActionKeywordsVisibility}"
|
||||
ToolTip="Change Action Keywords"
|
||||
|
|
|
|||
|
|
@ -206,7 +206,16 @@ namespace Flow.Launcher
|
|||
{
|
||||
var id = viewModel.SelectedPlugin.PluginPair.Metadata.ID;
|
||||
// used to sync the current status from the plugin manager into the setting to keep consistency after save
|
||||
settings.PluginSettings.Plugins[id].Disabled = viewModel.SelectedPlugin.PluginPair.Metadata.Disabled;
|
||||
settings.PluginSettings.Plugins[id].Disabled = viewModel.SelectedPlugin.PluginPair.Metadata.Disabled;
|
||||
}
|
||||
|
||||
private void OnPluginPriorityClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
PriorityChangeWindow priorityChangeWindow = new PriorityChangeWindow(viewModel.SelectedPlugin.PluginPair.Metadata.ID, settings, viewModel.SelectedPlugin);
|
||||
priorityChangeWindow.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPluginActionKeywordsClick(object sender, MouseButtonEventArgs e)
|
||||
|
|
@ -281,5 +290,6 @@ namespace Flow.Launcher
|
|||
{
|
||||
FilesFolders.OpenPath(Path.Combine(DataLocation.DataDirectory(), Constant.Themes));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ namespace Flow.Launcher.ViewModel
|
|||
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||
UpdateResultView(results, plugin.Metadata, query);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception("MainViewModel", $"Exception when querying the plugin {plugin.Metadata.Name}", e, "QueryResults");
|
||||
}
|
||||
|
|
@ -431,7 +431,7 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
|
||||
|
||||
// this should happen once after all queries are done so progress bar should continue
|
||||
// until the end of all querying
|
||||
|
|
@ -687,7 +687,8 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
else
|
||||
{
|
||||
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5;
|
||||
var priorityScore = metadata.Priority * 50;
|
||||
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5 + priorityScore;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ namespace Flow.Launcher.ViewModel
|
|||
public string InitilizaTime => PluginPair.Metadata.InitTime.ToString() + "ms";
|
||||
public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms";
|
||||
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, PluginPair.Metadata.ActionKeywords);
|
||||
public int Priority => PluginPair.Metadata.Priority;
|
||||
|
||||
public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)
|
||||
{
|
||||
|
|
@ -34,6 +35,12 @@ namespace Flow.Launcher.ViewModel
|
|||
OnPropertyChanged(nameof(ActionKeywordsText));
|
||||
}
|
||||
|
||||
public void ChangePriority(int newPriority)
|
||||
{
|
||||
PluginPair.Metadata.Priority = newPriority;
|
||||
OnPropertyChanged(nameof(Priority));
|
||||
}
|
||||
|
||||
public bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ namespace Flow.Launcher.ViewModel
|
|||
var id = vm.PluginPair.Metadata.ID;
|
||||
|
||||
Settings.PluginSettings.Plugins[id].Disabled = vm.PluginPair.Metadata.Disabled;
|
||||
Settings.PluginSettings.Plugins[id].Priority = vm.Priority;
|
||||
}
|
||||
|
||||
PluginManager.Save();
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace Flow.Launcher.Plugin.Caculator
|
|||
};
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue