Skip to content
This repository was archived by the owner on Feb 12, 2021. It is now read-only.

Commit d769b9e

Browse files
committed
Merge branch 'dev' into release_branch
2 parents 0bfa75a + b50f738 commit d769b9e

File tree

10 files changed

+123
-20
lines changed

10 files changed

+123
-20
lines changed

Plugins/Wox.Plugin.WebSearch/Main.cs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public List<Result> Query(Query query)
7272
SubTitle = subtitle,
7373
Score = 6,
7474
IcoPath = searchSource.IconPath,
75+
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
7576
Action = c =>
7677
{
7778
if (_settings.OpenInNewBrowser)
@@ -137,6 +138,7 @@ private async Task<IEnumerable<Result>> Suggestions(string keyword, string subti
137138
SubTitle = subtitle,
138139
Score = 5,
139140
IcoPath = searchSource.IconPath,
141+
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
140142
Action = c =>
141143
{
142144
if (_settings.OpenInNewBrowser)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Features
2727
**New from this fork:**
2828
- Portable mode
2929
- Drastically improved search experience
30+
- Auto-complete text suggestion
3031
- Search all subfolders and files
3132
- Option to always run CMD or Powershell as administrator
3233
- Run CMD, Powershell and programs as a different user

Wox.Core/Plugin/PluginManager.cs

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ public static void UpdatePluginMetadata(List<Result> results, PluginMetadata met
191191
r.PluginDirectory = metadata.PluginDirectory;
192192
r.PluginID = metadata.ID;
193193
r.OriginQuery = query;
194+
195+
// ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions
196+
// Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level
197+
if (metadata.ActionKeywords.Count == 1)
198+
r.ActionKeywordAssigned = query.ActionKeyword;
194199
}
195200
}
196201

Wox.Core/Resource/Theme.cs

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public ResourceDictionary GetResourceDictionary()
124124
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle)));
125125
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight)));
126126
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch)));
127+
128+
var caretBrushPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Any(x => x.Property.Name == "CaretBrush");
129+
var foregroundPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Where(x => x.Property.Name == "Foreground")
130+
.Select(x => x.Value).FirstOrDefault();
131+
if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling
132+
queryBoxStyle.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue));
127133
}
128134

129135
Style resultItemStyle = dict["ItemTitleStyle"] as Style;

Wox.Plugin/Result.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public class Result
1414
public string Title { get; set; }
1515
public string SubTitle { get; set; }
1616

17+
/// <summary>
18+
/// This holds the action keyword that triggered the result.
19+
/// If result is triggered by global keyword: *, this should be empty.
20+
/// </summary>
21+
public string ActionKeywordAssigned { get; set; }
22+
1723
public string IcoPath
1824
{
1925
get { return _icoPath; }
@@ -53,7 +59,7 @@ public string IcoPath
5359
public IList<int> SubTitleHighlightData { get; set; }
5460

5561
/// <summary>
56-
/// Only resulsts that originQuery match with curren query will be displayed in the panel
62+
/// Only results that originQuery match with current query will be displayed in the panel
5763
/// </summary>
5864
internal Query OriginQuery { get; set; }
5965

@@ -98,13 +104,14 @@ public override string ToString()
98104
return Title + SubTitle;
99105
}
100106

101-
[Obsolete("Use IContextMenu instead")]
107+
102108
/// <summary>
103109
/// Context menus associate with this result
104110
/// </summary>
111+
[Obsolete("Use IContextMenu instead")]
105112
public List<Result> ContextMenu { get; set; }
106113

107-
[Obsolete("Use Object initializers instead")]
114+
[Obsolete("Use Object initializer instead")]
108115
public Result(string Title, string IcoPath, string SubTitle = null)
109116
{
110117
this.Title = Title;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using Wox.Infrastructure.Logger;
5+
using Wox.ViewModel;
6+
7+
namespace Wox.Converters
8+
{
9+
public class QuerySuggestionBoxConverter : IMultiValueConverter
10+
{
11+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
if (values.Length != 2)
14+
{
15+
return string.Empty;
16+
}
17+
18+
// first prop is the current query string
19+
var queryText = (string)values[0];
20+
21+
if (string.IsNullOrEmpty(queryText))
22+
return "Type here to search";
23+
24+
// second prop is the current selected item result
25+
var val = values[1];
26+
if (val == null)
27+
{
28+
return string.Empty;
29+
}
30+
if (!(val is ResultViewModel))
31+
{
32+
return System.Windows.Data.Binding.DoNothing;
33+
}
34+
35+
try
36+
{
37+
var selectedItem = (ResultViewModel)val;
38+
39+
var selectedResult = selectedItem.Result;
40+
var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " ";
41+
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;
42+
43+
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
44+
return string.Empty;
45+
46+
// When user typed lower case and result title is uppercase, we still want to display suggestion
47+
return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
48+
}
49+
catch (Exception e)
50+
{
51+
Log.Exception(nameof(QuerySuggestionBoxConverter), "fail to convert text for suggestion box", e);
52+
return string.Empty;
53+
}
54+
}
55+
56+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
57+
{
58+
throw new NotImplementedException();
59+
}
60+
}
61+
}

Wox/MainWindow.xaml

+33-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
xmlns:wox="clr-namespace:Wox"
55
xmlns:vm="clr-namespace:Wox.ViewModel"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:converters="clr-namespace:Wox.Converters"
9+
mc:Ignorable="d"
810
Title="Wox"
911
Topmost="True"
1012
SizeToContent="Height"
@@ -25,6 +27,9 @@
2527
PreviewKeyDown="OnKeyDown"
2628
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
2729
d:DataContext="{d:DesignInstance vm:MainViewModel}">
30+
<Window.Resources>
31+
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter"/>
32+
</Window.Resources>
2833
<Window.InputBindings>
2934
<KeyBinding Key="Escape" Command="{Binding EscCommand}"></KeyBinding>
3035
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}"></KeyBinding>
@@ -55,29 +60,43 @@
5560
</Window.InputBindings>
5661
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" >
5762
<StackPanel Orientation="Vertical">
58-
<TextBox Style="{DynamicResource QueryBoxStyle}"
63+
<Grid>
64+
<TextBox x:Name="QueryTextSuggestionBox"
65+
Style="{DynamicResource QueryBoxStyle}"
66+
Foreground="LightGray"
67+
IsEnabled="False">
68+
<TextBox.Text>
69+
<MultiBinding Converter="{StaticResource QuerySuggestionBoxConverter}">
70+
<Binding ElementName="QueryTextBox" Path="Text"/>
71+
<Binding ElementName="ResultListBox" Path="SelectedItem"/>
72+
</MultiBinding>
73+
</TextBox.Text>
74+
</TextBox>
75+
<TextBox x:Name="QueryTextBox"
76+
Style="{DynamicResource QueryBoxStyle}"
5977
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
6078
PreviewDragOver="OnPreviewDragOver"
6179
TextChanged="OnTextChanged"
6280
AllowDrop="True"
6381
Visibility="Visible"
64-
x:Name="QueryTextBox">
65-
<TextBox.ContextMenu>
66-
<ContextMenu>
67-
<MenuItem Command="ApplicationCommands.Cut"/>
68-
<MenuItem Command="ApplicationCommands.Copy"/>
69-
<MenuItem Command="ApplicationCommands.Paste"/>
70-
<Separator />
71-
<MenuItem Header="Settings" Click="OnContextMenusForSettingsClick" />
72-
</ContextMenu>
73-
</TextBox.ContextMenu>
74-
</TextBox>
82+
Background="Transparent">
83+
<TextBox.ContextMenu>
84+
<ContextMenu>
85+
<MenuItem Command="ApplicationCommands.Cut"/>
86+
<MenuItem Command="ApplicationCommands.Copy"/>
87+
<MenuItem Command="ApplicationCommands.Paste"/>
88+
<Separator />
89+
<MenuItem Header="Settings" Click="OnContextMenusForSettingsClick" />
90+
</ContextMenu>
91+
</TextBox.ContextMenu>
92+
</TextBox>
93+
</Grid>
7594
<Line x:Name="ProgressBar" HorizontalAlignment="Right"
7695
Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay}"
7796
Y1="0" Y2="0" X2="100" Height="2" Width="752" StrokeThickness="1">
7897
</Line>
7998
<ContentControl>
80-
<wox:ResultListBox DataContext="{Binding Results}" PreviewMouseDown="OnPreviewMouseButtonDown" />
99+
<wox:ResultListBox x:Name="ResultListBox" DataContext="{Binding Results}" PreviewMouseDown="OnPreviewMouseButtonDown" />
81100
</ContentControl>
82101
<ContentControl>
83102
<wox:ResultListBox DataContext="{Binding ContextMenu}" PreviewMouseDown="OnPreviewMouseButtonDown" />

Wox/Themes/Base.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Setter Property="Height" Value="46" />
99
<Setter Property="Background" Value="#616161" />
1010
<Setter Property="Foreground" Value="#E3E0E3" />
11+
<Setter Property="CaretBrush" Value="#E3E0E3" />
1112
<Setter Property="VerticalContentAlignment" Value="Center" />
1213
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
1314
</Style>

Wox/ViewModel/MainViewModel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.Linq;
56
using System.Threading;
@@ -210,7 +211,7 @@ public string QueryText
210211
Query();
211212
}
212213
}
213-
214+
214215
/// <summary>
215216
/// we need move cursor to end when we manually changed query
216217
/// but we don't want to move cursor to end when query is updated from TextBox
@@ -455,7 +456,6 @@ private void RemoveOldQueryResults(Query query)
455456
}
456457
}
457458

458-
459459
private Result ContextMenuTopMost(Result result)
460460
{
461461
Result menu;

Wox/Wox.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<Compile Include="Converters\HighlightTextConverter.cs" />
9494
<Compile Include="Helper\SingletonWindowOpener.cs" />
9595
<Compile Include="PublicAPIInstance.cs" />
96+
<Compile Include="Converters\QuerySuggestionBoxConverter.cs" />
9697
<Compile Include="ReportWindow.xaml.cs" />
9798
<Compile Include="ResultListBox.xaml.cs">
9899
<DependentUpon>ResultListBox.xaml</DependentUpon>

0 commit comments

Comments
 (0)