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

Commit

Permalink
Merge branch 'dev' into release_branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jjw24 committed Mar 15, 2020
2 parents 0bfa75a + b50f738 commit d769b9e
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Plugins/Wox.Plugin.WebSearch/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public List<Result> Query(Query query)
SubTitle = subtitle,
Score = 6,
IcoPath = searchSource.IconPath,
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
Action = c =>
{
if (_settings.OpenInNewBrowser)
Expand Down Expand Up @@ -137,6 +138,7 @@ private async Task<IEnumerable<Result>> Suggestions(string keyword, string subti
SubTitle = subtitle,
Score = 5,
IcoPath = searchSource.IconPath,
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
Action = c =>
{
if (_settings.OpenInNewBrowser)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Features
**New from this fork:**
- Portable mode
- Drastically improved search experience
- Auto-complete text suggestion
- Search all subfolders and files
- Option to always run CMD or Powershell as administrator
- Run CMD, Powershell and programs as a different user
Expand Down
5 changes: 5 additions & 0 deletions Wox.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public static void UpdatePluginMetadata(List<Result> results, PluginMetadata met
r.PluginDirectory = metadata.PluginDirectory;
r.PluginID = metadata.ID;
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;
}
}

Expand Down
6 changes: 6 additions & 0 deletions Wox.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ public ResourceDictionary GetResourceDictionary()
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.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;
Expand Down
13 changes: 10 additions & 3 deletions Wox.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public class Result
public string Title { 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
{
get { return _icoPath; }
Expand Down Expand Up @@ -53,7 +59,7 @@ public string IcoPath
public IList<int> SubTitleHighlightData { get; set; }

/// <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>
internal Query OriginQuery { get; set; }

Expand Down Expand Up @@ -98,13 +104,14 @@ public override string ToString()
return Title + SubTitle;
}

[Obsolete("Use IContextMenu instead")]

/// <summary>
/// Context menus associate with this result
/// </summary>
[Obsolete("Use IContextMenu instead")]
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)
{
this.Title = Title;
Expand Down
61 changes: 61 additions & 0 deletions Wox/Converters/QuerySuggestionBoxConverter.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
47 changes: 33 additions & 14 deletions Wox/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
xmlns:wox="clr-namespace:Wox"
xmlns:vm="clr-namespace:Wox.ViewModel"
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"
Topmost="True"
SizeToContent="Height"
Expand All @@ -25,6 +27,9 @@
PreviewKeyDown="OnKeyDown"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
d:DataContext="{d:DesignInstance vm:MainViewModel}">
<Window.Resources>
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter"/>
</Window.Resources>
<Window.InputBindings>
<KeyBinding Key="Escape" Command="{Binding EscCommand}"></KeyBinding>
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}"></KeyBinding>
Expand Down Expand Up @@ -55,29 +60,43 @@
</Window.InputBindings>
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" >
<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}"
PreviewDragOver="OnPreviewDragOver"
TextChanged="OnTextChanged"
AllowDrop="True"
Visibility="Visible"
x:Name="QueryTextBox">
<TextBox.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Cut"/>
<MenuItem Command="ApplicationCommands.Copy"/>
<MenuItem Command="ApplicationCommands.Paste"/>
<Separator />
<MenuItem Header="Settings" Click="OnContextMenusForSettingsClick" />
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
Background="Transparent">
<TextBox.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Cut"/>
<MenuItem Command="ApplicationCommands.Copy"/>
<MenuItem Command="ApplicationCommands.Paste"/>
<Separator />
<MenuItem Header="Settings" Click="OnContextMenusForSettingsClick" />
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
</Grid>
<Line x:Name="ProgressBar" HorizontalAlignment="Right"
Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay}"
Y1="0" Y2="0" X2="100" Height="2" Width="752" StrokeThickness="1">
</Line>
<ContentControl>
<wox:ResultListBox DataContext="{Binding Results}" PreviewMouseDown="OnPreviewMouseButtonDown" />
<wox:ResultListBox x:Name="ResultListBox" DataContext="{Binding Results}" PreviewMouseDown="OnPreviewMouseButtonDown" />
</ContentControl>
<ContentControl>
<wox:ResultListBox DataContext="{Binding ContextMenu}" PreviewMouseDown="OnPreviewMouseButtonDown" />
Expand Down
1 change: 1 addition & 0 deletions Wox/Themes/Base.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Setter Property="Height" Value="46" />
<Setter Property="Background" Value="#616161" />
<Setter Property="Foreground" Value="#E3E0E3" />
<Setter Property="CaretBrush" Value="#E3E0E3" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
</Style>
Expand Down
6 changes: 3 additions & 3 deletions Wox/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -210,7 +211,7 @@ public string QueryText
Query();
}
}

/// <summary>
/// we need move cursor to end when we manually changed query
/// but we don't want to move cursor to end when query is updated from TextBox
Expand Down Expand Up @@ -455,7 +456,6 @@ private void RemoveOldQueryResults(Query query)
}
}


private Result ContextMenuTopMost(Result result)
{
Result menu;
Expand Down
1 change: 1 addition & 0 deletions Wox/Wox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Converters\HighlightTextConverter.cs" />
<Compile Include="Helper\SingletonWindowOpener.cs" />
<Compile Include="PublicAPIInstance.cs" />
<Compile Include="Converters\QuerySuggestionBoxConverter.cs" />
<Compile Include="ReportWindow.xaml.cs" />
<Compile Include="ResultListBox.xaml.cs">
<DependentUpon>ResultListBox.xaml</DependentUpon>
Expand Down

0 comments on commit d769b9e

Please sign in to comment.