Merge branch 'dev'

This commit is contained in:
Jeremy Wu 2020-03-15 21:29:06 +11:00
commit 24cf015b0a
10 changed files with 123 additions and 20 deletions

View file

@ -72,6 +72,7 @@ namespace Wox.Plugin.WebSearch
SubTitle = subtitle, SubTitle = subtitle,
Score = 6, Score = 6,
IcoPath = searchSource.IconPath, IcoPath = searchSource.IconPath,
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
Action = c => Action = c =>
{ {
if (_settings.OpenInNewBrowser) if (_settings.OpenInNewBrowser)
@ -137,6 +138,7 @@ namespace Wox.Plugin.WebSearch
SubTitle = subtitle, SubTitle = subtitle,
Score = 5, Score = 5,
IcoPath = searchSource.IconPath, IcoPath = searchSource.IconPath,
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
Action = c => Action = c =>
{ {
if (_settings.OpenInNewBrowser) if (_settings.OpenInNewBrowser)

View file

@ -27,6 +27,7 @@ Features
**New from this fork:** **New from this fork:**
- Portable mode - Portable mode
- Drastically improved search experience - Drastically improved search experience
- Auto-complete text suggestion
- Search all subfolders and files - Search all subfolders and files
- Option to always run CMD or Powershell as administrator - Option to always run CMD or Powershell as administrator
- Run CMD, Powershell and programs as a different user - Run CMD, Powershell and programs as a different user

View file

@ -191,6 +191,11 @@ namespace Wox.Core.Plugin
r.PluginDirectory = metadata.PluginDirectory; r.PluginDirectory = metadata.PluginDirectory;
r.PluginID = metadata.ID; r.PluginID = metadata.ID;
r.OriginQuery = query; r.OriginQuery = query;
// ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions
// Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level
if (metadata.ActionKeywords.Count == 1)
r.ActionKeywordAssigned = query.ActionKeyword;
} }
} }

View file

@ -124,6 +124,12 @@ namespace Wox.Core.Resource
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch)));
var caretBrushPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Any(x => x.Property.Name == "CaretBrush");
var foregroundPropertyValue = queryBoxStyle.Setters.OfType<Setter>().Where(x => x.Property.Name == "Foreground")
.Select(x => x.Value).FirstOrDefault();
if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling
queryBoxStyle.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue));
} }
Style resultItemStyle = dict["ItemTitleStyle"] as Style; Style resultItemStyle = dict["ItemTitleStyle"] as Style;

View file

@ -14,6 +14,12 @@ namespace Wox.Plugin
public string Title { get; set; } public string Title { get; set; }
public string SubTitle { get; set; } public string SubTitle { get; set; }
/// <summary>
/// This holds the action keyword that triggered the result.
/// If result is triggered by global keyword: *, this should be empty.
/// </summary>
public string ActionKeywordAssigned { get; set; }
public string IcoPath public string IcoPath
{ {
get { return _icoPath; } get { return _icoPath; }
@ -53,7 +59,7 @@ namespace Wox.Plugin
public IList<int> SubTitleHighlightData { get; set; } public IList<int> SubTitleHighlightData { get; set; }
/// <summary> /// <summary>
/// Only resulsts that originQuery match with curren query will be displayed in the panel /// Only results that originQuery match with current query will be displayed in the panel
/// </summary> /// </summary>
internal Query OriginQuery { get; set; } internal Query OriginQuery { get; set; }
@ -98,13 +104,14 @@ namespace Wox.Plugin
return Title + SubTitle; return Title + SubTitle;
} }
[Obsolete("Use IContextMenu instead")]
/// <summary> /// <summary>
/// Context menus associate with this result /// Context menus associate with this result
/// </summary> /// </summary>
[Obsolete("Use IContextMenu instead")]
public List<Result> ContextMenu { get; set; } public List<Result> ContextMenu { get; set; }
[Obsolete("Use Object initializers instead")] [Obsolete("Use Object initializer instead")]
public Result(string Title, string IcoPath, string SubTitle = null) public Result(string Title, string IcoPath, string SubTitle = null)
{ {
this.Title = Title; this.Title = Title;

View file

@ -0,0 +1,61 @@
using System;
using System.Globalization;
using System.Windows.Data;
using Wox.Infrastructure.Logger;
using Wox.ViewModel;
namespace Wox.Converters
{
public class QuerySuggestionBoxConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length != 2)
{
return string.Empty;
}
// first prop is the current query string
var queryText = (string)values[0];
if (string.IsNullOrEmpty(queryText))
return "Type here to search";
// second prop is the current selected item result
var val = values[1];
if (val == null)
{
return string.Empty;
}
if (!(val is ResultViewModel))
{
return System.Windows.Data.Binding.DoNothing;
}
try
{
var selectedItem = (ResultViewModel)val;
var selectedResult = selectedItem.Result;
var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " ";
var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title;
if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase))
return string.Empty;
// When user typed lower case and result title is uppercase, we still want to display suggestion
return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length);
}
catch (Exception e)
{
Log.Exception(nameof(QuerySuggestionBoxConverter), "fail to convert text for suggestion box", e);
return string.Empty;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View file

@ -4,7 +4,9 @@
xmlns:wox="clr-namespace:Wox" xmlns:wox="clr-namespace:Wox"
xmlns:vm="clr-namespace:Wox.ViewModel" xmlns:vm="clr-namespace:Wox.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="clr-namespace:Wox.Converters"
mc:Ignorable="d"
Title="Wox" Title="Wox"
Topmost="True" Topmost="True"
SizeToContent="Height" SizeToContent="Height"
@ -25,6 +27,9 @@
PreviewKeyDown="OnKeyDown" PreviewKeyDown="OnKeyDown"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
d:DataContext="{d:DesignInstance vm:MainViewModel}"> d:DataContext="{d:DesignInstance vm:MainViewModel}">
<Window.Resources>
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter"/>
</Window.Resources>
<Window.InputBindings> <Window.InputBindings>
<KeyBinding Key="Escape" Command="{Binding EscCommand}"></KeyBinding> <KeyBinding Key="Escape" Command="{Binding EscCommand}"></KeyBinding>
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}"></KeyBinding> <KeyBinding Key="F1" Command="{Binding StartHelpCommand}"></KeyBinding>
@ -55,29 +60,43 @@
</Window.InputBindings> </Window.InputBindings>
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" > <Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" >
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<TextBox Style="{DynamicResource QueryBoxStyle}" <Grid>
<TextBox x:Name="QueryTextSuggestionBox"
Style="{DynamicResource QueryBoxStyle}"
Foreground="LightGray"
IsEnabled="False">
<TextBox.Text>
<MultiBinding Converter="{StaticResource QuerySuggestionBoxConverter}">
<Binding ElementName="QueryTextBox" Path="Text"/>
<Binding ElementName="ResultListBox" Path="SelectedItem"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
<TextBox x:Name="QueryTextBox"
Style="{DynamicResource QueryBoxStyle}"
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
PreviewDragOver="OnPreviewDragOver" PreviewDragOver="OnPreviewDragOver"
TextChanged="OnTextChanged" TextChanged="OnTextChanged"
AllowDrop="True" AllowDrop="True"
Visibility="Visible" Visibility="Visible"
x:Name="QueryTextBox"> Background="Transparent">
<TextBox.ContextMenu> <TextBox.ContextMenu>
<ContextMenu> <ContextMenu>
<MenuItem Command="ApplicationCommands.Cut"/> <MenuItem Command="ApplicationCommands.Cut"/>
<MenuItem Command="ApplicationCommands.Copy"/> <MenuItem Command="ApplicationCommands.Copy"/>
<MenuItem Command="ApplicationCommands.Paste"/> <MenuItem Command="ApplicationCommands.Paste"/>
<Separator /> <Separator />
<MenuItem Header="Settings" Click="OnContextMenusForSettingsClick" /> <MenuItem Header="Settings" Click="OnContextMenusForSettingsClick" />
</ContextMenu> </ContextMenu>
</TextBox.ContextMenu> </TextBox.ContextMenu>
</TextBox> </TextBox>
</Grid>
<Line x:Name="ProgressBar" HorizontalAlignment="Right" <Line x:Name="ProgressBar" HorizontalAlignment="Right"
Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay}" Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay}"
Y1="0" Y2="0" X2="100" Height="2" Width="752" StrokeThickness="1"> Y1="0" Y2="0" X2="100" Height="2" Width="752" StrokeThickness="1">
</Line> </Line>
<ContentControl> <ContentControl>
<wox:ResultListBox DataContext="{Binding Results}" PreviewMouseDown="OnPreviewMouseButtonDown" /> <wox:ResultListBox x:Name="ResultListBox" DataContext="{Binding Results}" PreviewMouseDown="OnPreviewMouseButtonDown" />
</ContentControl> </ContentControl>
<ContentControl> <ContentControl>
<wox:ResultListBox DataContext="{Binding ContextMenu}" PreviewMouseDown="OnPreviewMouseButtonDown" /> <wox:ResultListBox DataContext="{Binding ContextMenu}" PreviewMouseDown="OnPreviewMouseButtonDown" />

View file

@ -8,6 +8,7 @@
<Setter Property="Height" Value="46" /> <Setter Property="Height" Value="46" />
<Setter Property="Background" Value="#616161" /> <Setter Property="Background" Value="#616161" />
<Setter Property="Foreground" Value="#E3E0E3" /> <Setter Property="Foreground" Value="#E3E0E3" />
<Setter Property="CaretBrush" Value="#E3E0E3" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" /> <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
</Style> </Style>

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -455,7 +456,6 @@ namespace Wox.ViewModel
} }
} }
private Result ContextMenuTopMost(Result result) private Result ContextMenuTopMost(Result result)
{ {
Result menu; Result menu;

View file

@ -93,6 +93,7 @@
<Compile Include="Converters\HighlightTextConverter.cs" /> <Compile Include="Converters\HighlightTextConverter.cs" />
<Compile Include="Helper\SingletonWindowOpener.cs" /> <Compile Include="Helper\SingletonWindowOpener.cs" />
<Compile Include="PublicAPIInstance.cs" /> <Compile Include="PublicAPIInstance.cs" />
<Compile Include="Converters\QuerySuggestionBoxConverter.cs" />
<Compile Include="ReportWindow.xaml.cs" /> <Compile Include="ReportWindow.xaml.cs" />
<Compile Include="ResultListBox.xaml.cs"> <Compile Include="ResultListBox.xaml.cs">
<DependentUpon>ResultListBox.xaml</DependentUpon> <DependentUpon>ResultListBox.xaml</DependentUpon>