Skip to content

Commit c54b678

Browse files
committed
Merge dev
2 parents a4c11df + 7dab5a2 commit c54b678

File tree

14 files changed

+201
-8
lines changed

14 files changed

+201
-8
lines changed

Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
3131
metadata.ActionKeyword = settings.ActionKeywords[0];
3232
}
3333
metadata.Disabled = settings.Disabled;
34+
metadata.Priority = settings.Priority;
3435
}
3536
else
3637
{
@@ -40,7 +41,8 @@ public void UpdatePluginSettings(List<PluginMetadata> metadatas)
4041
Name = metadata.Name,
4142
Version = metadata.Version,
4243
ActionKeywords = metadata.ActionKeywords,
43-
Disabled = metadata.Disabled
44+
Disabled = metadata.Disabled,
45+
Priority = metadata.Priority
4446
};
4547
}
4648
}
@@ -52,6 +54,7 @@ public class Plugin
5254
public string Name { get; set; }
5355
public string Version { get; set; }
5456
public List<string> ActionKeywords { get; set; } // a reference of the action keywords from plugin manager
57+
public int Priority { get; set; }
5558

5659
/// <summary>
5760
/// Used only to save the state of the plugin in settings

Flow.Launcher.Plugin/PluginMetadata.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ internal set
3636
public List<string> ActionKeywords { get; set; }
3737

3838
public string IcoPath { get; set;}
39-
39+
4040
public override string ToString()
4141
{
4242
return Name;
4343
}
4444

45+
[JsonIgnore]
46+
public int Priority { get; set; }
47+
4548
/// <summary>
4649
/// Init time include both plugin load time and init time
4750
/// </summary>

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
<Content Include="Images\*">
6464
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6565
</Content>
66+
<Content Include="Images\*.svg">
67+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
68+
</Content>
6669
</ItemGroup>
6770

6871
<ItemGroup>

Flow.Launcher/Languages/en.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
<system:String x:Key="actionKeywords">Action keyword:</system:String>
4444
<system:String x:Key="currentActionKeywords">Current action keyword:</system:String>
4545
<system:String x:Key="newActionKeyword">New action keyword:</system:String>
46+
<system:String x:Key="currentPriority">Current Priority: </system:String>
47+
<system:String x:Key="newPriority">New Priority: </system:String>
4648
<system:String x:Key="pluginDirectory">Plugin Directory</system:String>
4749
<system:String x:Key="author">Author</system:String>
4850
<system:String x:Key="plugin_init_time">Init time:</system:String>
@@ -104,6 +106,10 @@
104106
</system:String>
105107
<system:String x:Key="releaseNotes">Release Notes</system:String>
106108

109+
<!--Priority Setting Dialog-->
110+
<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>
111+
<system:String x:Key="invalidPriority">Please provide an valid integer for Priority!</system:String>
112+
107113
<!--Action Keyword Setting Dialog-->
108114
<system:String x:Key="oldActionKeywords">Old Action Keyword</system:String>
109115
<system:String x:Key="newActionKeywords">New Action Keyword</system:String>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<Window x:Class="Flow.Launcher.PriorityChangeWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:Flow.Launcher"
7+
Loaded="PriorityChangeWindow_Loaded"
8+
mc:Ignorable="d"
9+
WindowStartupLocation="CenterScreen"
10+
Title="PriorityChangeWindow" Height="250" Width="300">
11+
<Grid>
12+
<Grid.RowDefinitions>
13+
<RowDefinition />
14+
<RowDefinition Height="60"/>
15+
<RowDefinition Height="75"/>
16+
<RowDefinition />
17+
</Grid.RowDefinitions>
18+
<Grid.ColumnDefinitions>
19+
<ColumnDefinition Width="20" />
20+
<ColumnDefinition />
21+
</Grid.ColumnDefinitions>
22+
<TextBlock FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"
23+
HorizontalAlignment="Left" Text="{DynamicResource currentPriority}" />
24+
<TextBlock x:Name="OldPriority" Grid.Row="0" Grid.Column="1" Margin="170 10 10 10" FontSize="14"
25+
VerticalAlignment="Center" HorizontalAlignment="Left" />
26+
27+
<TextBlock FontSize="14" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"
28+
HorizontalAlignment="Left" Text="{DynamicResource newPriority}" />
29+
<StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1">
30+
<TextBox x:Name="tbAction" Margin="140 10 15 10" Width="105" VerticalAlignment="Center" HorizontalAlignment="Left" />
31+
</StackPanel>
32+
33+
<TextBlock Grid.Row="2" Grid.ColumnSpan="1" Grid.Column="1" Foreground="Gray"
34+
Text="{DynamicResource priority_tips}" TextWrapping="Wrap"
35+
Margin="0,0,20,0"/>
36+
37+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="3" Grid.Column="1">
38+
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10 0 10 0" Width="80" Height="30"
39+
Content="{DynamicResource cancel}" />
40+
<Button x:Name="btnDone" Margin="10 0 10 0" Width="80" Height="30" Click="btnDone_OnClick">
41+
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
42+
</Button>
43+
</StackPanel>
44+
</Grid>
45+
</Window>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Flow.Launcher.Core.Plugin;
2+
using Flow.Launcher.Core.Resource;
3+
using Flow.Launcher.Infrastructure.UserSettings;
4+
using Flow.Launcher.Plugin;
5+
using Flow.Launcher.ViewModel;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Text;
9+
using System.Windows;
10+
using System.Windows.Controls;
11+
using System.Windows.Data;
12+
using System.Windows.Documents;
13+
using System.Windows.Input;
14+
using System.Windows.Media;
15+
using System.Windows.Media.Imaging;
16+
using System.Windows.Shapes;
17+
18+
namespace Flow.Launcher
19+
{
20+
/// <summary>
21+
/// Interaction Logic of PriorityChangeWindow.xaml
22+
/// </summary>
23+
public partial class PriorityChangeWindow : Window
24+
{
25+
private readonly PluginPair plugin;
26+
private Settings settings;
27+
private readonly Internationalization translater = InternationalizationManager.Instance;
28+
private readonly PluginViewModel pluginViewModel;
29+
30+
public PriorityChangeWindow(string pluginId, Settings settings, PluginViewModel pluginViewModel)
31+
{
32+
InitializeComponent();
33+
plugin = PluginManager.GetPluginForId(pluginId);
34+
this.settings = settings;
35+
this.pluginViewModel = pluginViewModel;
36+
if (plugin == null)
37+
{
38+
MessageBox.Show(translater.GetTranslation("cannotFindSpecifiedPlugin"));
39+
Close();
40+
}
41+
}
42+
43+
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
44+
{
45+
Close();
46+
}
47+
48+
private void btnDone_OnClick(object sender, RoutedEventArgs e)
49+
{
50+
if (int.TryParse(tbAction.Text.Trim(), out var newPriority))
51+
{
52+
pluginViewModel.ChangePriority(newPriority);
53+
Close();
54+
}
55+
else
56+
{
57+
string msg = translater.GetTranslation("invalidPriority");
58+
MessageBox.Show(msg);
59+
}
60+
61+
}
62+
63+
private void PriorityChangeWindow_Loaded(object sender, RoutedEventArgs e)
64+
{
65+
OldPriority.Text = pluginViewModel.Priority.ToString();
66+
tbAction.Focus();
67+
}
68+
}
69+
}

Flow.Launcher/SettingWindow.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,14 @@
173173
<TextBlock Text="{Binding PluginPair.Metadata.Description}"
174174
Grid.Row="1" Opacity="0.5" />
175175
<DockPanel Grid.Row="2" Margin="0 10 0 8" HorizontalAlignment="Right">
176-
176+
<TextBlock Text="Priority" Margin="20,0,0,0"/>
177+
<TextBlock Text="{Binding Priority}"
178+
ToolTip="Change Plugin Results Priority"
179+
Margin="5 0 0 0" Cursor="Hand" Foreground="Blue"
180+
MouseUp="OnPluginPriorityClick"/>
177181
<TextBlock Text="{DynamicResource actionKeywords}"
178182
Visibility="{Binding ActionKeywordsVisibility}"
179-
Margin="20 0 0 0"/>
183+
Margin="5 0 0 0"/>
180184
<TextBlock Text="{Binding ActionKeywordsText}"
181185
Visibility="{Binding ActionKeywordsVisibility}"
182186
ToolTip="Change Action Keywords"

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,16 @@ private void OnPluginToggled(object sender, RoutedEventArgs e)
206206
{
207207
var id = viewModel.SelectedPlugin.PluginPair.Metadata.ID;
208208
// used to sync the current status from the plugin manager into the setting to keep consistency after save
209-
settings.PluginSettings.Plugins[id].Disabled = viewModel.SelectedPlugin.PluginPair.Metadata.Disabled;
209+
settings.PluginSettings.Plugins[id].Disabled = viewModel.SelectedPlugin.PluginPair.Metadata.Disabled;
210+
}
211+
212+
private void OnPluginPriorityClick(object sender, MouseButtonEventArgs e)
213+
{
214+
if (e.ChangedButton == MouseButton.Left)
215+
{
216+
PriorityChangeWindow priorityChangeWindow = new PriorityChangeWindow(viewModel.SelectedPlugin.PluginPair.Metadata.ID, settings, viewModel.SelectedPlugin);
217+
priorityChangeWindow.ShowDialog();
218+
}
210219
}
211220

212221
private void OnPluginActionKeywordsClick(object sender, MouseButtonEventArgs e)
@@ -281,5 +290,6 @@ private void OpenPluginFolder(object sender, RoutedEventArgs e)
281290
{
282291
FilesFolders.OpenPath(Path.Combine(DataLocation.DataDirectory(), Constant.Themes));
283292
}
293+
284294
}
285-
}
295+
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,8 @@ public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query o
781781
}
782782
else
783783
{
784-
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5;
784+
var priorityScore = metadata.Priority * 150;
785+
result.Score += _userSelectedRecord.GetSelectedCount(result) * 5 + priorityScore;
785786
}
786787
}
787788

Flow.Launcher/ViewModel/PluginViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public bool PluginState
2626
public string InitilizaTime => PluginPair.Metadata.InitTime.ToString() + "ms";
2727
public string QueryTime => PluginPair.Metadata.AvgQueryTime + "ms";
2828
public string ActionKeywordsText => string.Join(Query.ActionKeywordSeperater, PluginPair.Metadata.ActionKeywords);
29+
public int Priority => PluginPair.Metadata.Priority;
2930

3031
public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword)
3132
{
@@ -34,6 +35,12 @@ public void ChangeActionKeyword(string newActionKeyword, string oldActionKeyword
3435
OnPropertyChanged(nameof(ActionKeywordsText));
3536
}
3637

38+
public void ChangePriority(int newPriority)
39+
{
40+
PluginPair.Metadata.Priority = newPriority;
41+
OnPropertyChanged(nameof(Priority));
42+
}
43+
3744
public bool IsActionKeywordRegistered(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
3845
}
3946
}

0 commit comments

Comments
 (0)