Somil55/merge wpf to master (#3840)

* Basic WPF searchbox working

* Updated key navigation and removed coldstart for searhbox

* refactored and added code back in commented

* Removed XAML Island references

* Basic searchbox+listview working

* Getting a bit more back

* got color there

* Result list bit better now

* Added image loader for WPF Image

* Partially got the context menus rendering again

* adjusting coldstart to load, control will load with main form

* getting context menus back

* mouse over works now

* Click now works, started to remove Win.XAML references

* being a bit more forcusful on focus

* Shadow text is not aligned

* fixing focus if listbox was used

* small tweak to fix shadow text

* inputs don't work but gotta figure out why.  commenting out

* preview text

* adding back in delay

* fixed height issue

* Applied the correct context button styles

* Created custom ItemContainerStyle to fix the blue highlights behind the command buttons

* Applied the correct highlight / mouseover styling

* Removed vertical scrollbar in listview

* fixed for alt-space prompt

* Fixed right click focus issue

* Somil55/wpf modifier keys (#3378)

* Removed DPI change as it was not required

* Global key hooks for context menu items

* Updated Key for shell, folder and indexer plugin

* Updated key mapping for indexer plugin

* Somil55/wpf context menu selection (#3389)

* Removed DPI change as it was not required

* Global key hooks for context menu items

* Updated Key for shell, folder and indexer plugin

* Updated key mapping for indexer plugin

* Add trigger to selection on tabbing

* Minor shadow adjustments so its more similiar to default shell shadow. Added intro/outro animations

* Added UWP-like scrollbar style for the results list

* Fixed formating and naming

* Removed Powerlauncher UI project

* Update PowerToys.sln

* Commented out scrollbar and fade in/out animations

* Added missing features from UWP branch

* Fixed formatting for Product.wxs

* Add dragging to WPF window

Co-authored-by: Clint Rutkas <clint@rutkas.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
This commit is contained in:
Divyansh Srivastava
2020-06-01 12:35:37 -07:00
committed by GitHub
parent 5680a34ec1
commit 397b1533f0
92 changed files with 933 additions and 1815 deletions

View File

@@ -3,29 +3,18 @@ using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Helper;
using Wox.Infrastructure.UserSettings;
using Wox.ViewModel;
using Screen = System.Windows.Forms.Screen;
using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.MessageBox;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using Windows.System;
using System.Threading.Tasks;
using System.Windows.Media;
using Windows.UI.Xaml.Data;
using System.Diagnostics;
using Mages.Core.Runtime.Converters;
using System.Runtime.InteropServices;
using Microsoft.PowerLauncher.Telemetry;
using System.Timers;
using Microsoft.PowerToys.Telemetry;
using System.Windows.Controls;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Timers;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace PowerLauncher
{
@@ -38,20 +27,17 @@ namespace PowerLauncher
private Settings _settings;
private MainViewModel _viewModel;
private bool _isTextSetProgramatically;
const int ROW_HEIGHT = 75;
const int MAX_LIST_HEIGHT = 300;
bool isDPIChanged = false;
bool _deletePressed = false;
Timer _firstDeleteTimer = new Timer();
#endregion
public MainWindow(Settings settings, MainViewModel mainVM)
public MainWindow(Settings settings, MainViewModel mainVM) : this()
{
DataContext = mainVM;
_viewModel = mainVM;
_settings = settings;
InitializeComponent();
_firstDeleteTimer.Elapsed += CheckForFirstDelete;
@@ -68,7 +54,6 @@ namespace PowerLauncher
}
}
public MainWindow()
{
InitializeComponent();
@@ -79,15 +64,9 @@ namespace PowerLauncher
_viewModel.Save();
}
private void OnInitialized(object sender, EventArgs e)
{
}
private void OnLoaded(object sender, System.Windows.RoutedEventArgs _)
private void OnLoaded(object sender, RoutedEventArgs _)
{
WindowsInteropHelper.DisableControlBox(this);
InitializePosition();
SearchBox.QueryTextBox.DataContext = _viewModel;
@@ -95,60 +74,48 @@ namespace PowerLauncher
SearchBox.QueryTextBox.TextChanged += QueryTextBox_TextChanged;
SearchBox.QueryTextBox.Focus();
ListBox.DataContext = _viewModel;
ListBox.SuggestionsList.SelectionChanged += SuggestionsList_SelectionChanged;
ListBox.SuggestionsList.PreviewMouseLeftButtonUp += SuggestionsList_PreviewMouseLeftButtonUp;
_viewModel.PropertyChanged += ViewModel_PropertyChanged;
}
private void QueryTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
private void SuggestionsList_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (this._isTextSetProgramatically)
var result = ((FrameworkElement)e.OriginalSource).DataContext;
if (result != null)
{
var textBox = ((TextBox)sender);
textBox.SelectionStart = textBox.Text.Length;
var resultVM = result as ResultViewModel;
this._isTextSetProgramatically = false;
}
else
{
var text = ((TextBox)sender).Text;
if (text == string.Empty)
//This may be null if the tapped item was one of the context buttons (run as admin etc).
if (resultVM != null)
{
SearchBox.AutoCompleteTextBlock.Text = String.Empty;
_viewModel.Results.SelectedItem = resultVM;
_viewModel.OpenResultCommand.Execute(null);
}
_viewModel.QueryText = text;
var latestTimeOfTyping = DateTime.Now;
Task.Run(() => DelayedCheck(latestTimeOfTyping, text));
s_lastTimeOfTyping = latestTimeOfTyping;
}
}
private void InitializePosition()
{
Top = WindowTop();
Left = WindowLeft();
_settings.WindowTop = Top;
_settings.WindowLeft = Left;
}
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(MainViewModel.MainWindowVisibility))
{
if (Visibility == Visibility.Visible)
if (Visibility == System.Windows.Visibility.Visible)
{
_deletePressed = false;
_firstDeleteTimer.Start();
Activate();
//(this.FindResource("IntroStoryboard") as Storyboard).Begin();
UpdatePosition();
SearchBox.QueryTextBox.Focus();
_settings.ActivateTimes++;
if (!_viewModel.LastQuerySelected)
{
_viewModel.LastQuerySelected = true;
}
// to select the text so that the user can continue to type
if (!String.IsNullOrEmpty(SearchBox.QueryTextBox.Text))
{
SearchBox.QueryTextBox.SelectAll();
@@ -171,42 +138,20 @@ namespace PowerLauncher
if (e.ChangedButton == MouseButton.Left) DragMove();
}
private void OnDrop(object sender, DragEventArgs e)
private void InitializePosition()
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Note that you can have more than one file.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files[0].ToLower().EndsWith(".wox"))
{
PluginManager.InstallPlugin(files[0]);
}
else
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidWoxPluginFileFormat"));
}
}
e.Handled = false;
}
private void OnPreviewDragOver(object sender, DragEventArgs e)
{
e.Handled = true;
Top = WindowTop();
Left = WindowLeft();
_settings.WindowTop = Top;
_settings.WindowLeft = Left;
}
private void OnDeactivated(object sender, EventArgs e)
{
if (_settings.HideWhenDeactivated)
{
if (isDPIChanged)
{
isDPIChanged = false;
InitializePosition();
}
else
{
Hide();
}
//(this.FindResource("OutroStoryboard") as Storyboard).Begin();
Hide();
}
}
@@ -218,19 +163,9 @@ namespace PowerLauncher
Top = _settings.WindowTop;
}
else
{
double prevTop = Top;
double prevLeft = Left;
{
Top = WindowTop();
Left = WindowLeft();
if (prevTop != Top || prevLeft != Left)
{
isDPIChanged = true;
}
else
{
isDPIChanged = false;
}
}
}
@@ -250,78 +185,21 @@ namespace PowerLauncher
private double WindowLeft()
{
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
var dpi1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
var dpi2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
var left = (dpi2.X - this.Width) / 2 + dpi1.X;
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
return left;
}
/// <summary>
/// Calculates Y co-ordinate of main window top left corner
/// </summary>
/// <returns>Y co-ordinate of main window top left corner</returns>
private double WindowTop()
{
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
var dpi1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
var dpi2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
var top = (dpi2.Y - this.SearchBox.Height) / 4 + dpi1.Y;
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
var top = (dip2.Y - this.SearchBox.ActualHeight) / 4 + dip1.Y;
return top;
}
private void UserControl_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "SolidBorderBrush")
{
if (_resultList != null)
{
Windows.UI.Xaml.Media.SolidColorBrush borderBrush = _resultList.SolidBorderBrush as Windows.UI.Xaml.Media.SolidColorBrush;
Color borderColor = Color.FromArgb(borderBrush.Color.A, borderBrush.Color.R, borderBrush.Color.G, borderBrush.Color.B);
SolidColorBrush solidBorderBrush = new SolidColorBrush(borderColor);
this.SearchBoxBorder.BorderBrush = solidBorderBrush;
this.SearchBoxBorder.Background = solidBorderBrush;
this.ListBoxBorder.BorderBrush = solidBorderBrush;
this.ListBoxBorder.Background = solidBorderBrush;
}
}
else if(e.PropertyName == "PrimaryTextColor")
{
if (_resultList != null)
{
Windows.UI.Xaml.Media.SolidColorBrush primaryTextBrush = _resultList.PrimaryTextColor as Windows.UI.Xaml.Media.SolidColorBrush;
Color primaryTextColor = Color.FromArgb(primaryTextBrush.Color.A, primaryTextBrush.Color.R, primaryTextBrush.Color.G, primaryTextBrush.Color.B);
SolidColorBrush solidPrimaryTextBrush = new SolidColorBrush(primaryTextColor);
this.SearchBox.QueryTextBox.Foreground = solidPrimaryTextBrush;
this.SearchBox.QueryTextBox.CaretBrush = solidPrimaryTextBrush;
this.SearchBox.AutoCompleteTextBlock.Foreground = solidPrimaryTextBrush;
this.SearchBox.SearchLogo.Foreground = solidPrimaryTextBrush;
}
}
}
private UI.ResultList _resultList = null;
private void WindowsXamlHostListView_ChildChanged(object sender, EventArgs ev)
{
if (sender == null) return;
var host = (WindowsXamlHost)sender;
_resultList = (UI.ResultList)host.Child;
_resultList.DataContext = _viewModel;
_resultList.Tapped += SuggestionsList_Tapped;
_resultList.SuggestionsList.Loaded += SuggestionsList_Loaded;
_resultList.SuggestionsList.SelectionChanged += SuggestionsList_SelectionChanged;
_resultList.SuggestionsList.ContainerContentChanging += SuggestionList_UpdateListSize;
_resultList.PropertyChanged += UserControl_PropertyChanged;
}
private void SuggestionsList_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
_viewModel.ColdStartFix();
}
private void _launcher_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab && Keyboard.IsKeyDown(Key.LeftShift))
@@ -358,51 +236,28 @@ namespace PowerLauncher
_viewModel.SelectPrevPageCommand.Execute(null);
e.Handled = true;
}
else if( e.Key == Key.Back)
else if (e.Key == Key.Back)
{
_deletePressed = true;
}
else
{
_viewModel.HandleContextMenu(e.Key, Keyboard.Modifiers);
}
}
private void UpdateTextBoxToSelectedItem()
{
var itemText = _viewModel?.Results?.SelectedItem?.ToString() ?? null;
if (!String.IsNullOrEmpty(itemText))
if (!string.IsNullOrEmpty(itemText))
{
_viewModel.ChangeQueryText(itemText);
}
}
private void SuggestionsList_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
private void SuggestionsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var result = ((Windows.UI.Xaml.FrameworkElement)e.OriginalSource).DataContext;
if (result != null)
{
var resultVM = result as ResultViewModel;
//This may be null if the tapped item was one of the context buttons (run as admin etc).
if (resultVM != null)
{
_viewModel.Results.SelectedItem = resultVM;
_viewModel.OpenResultCommand.Execute(null);
}
}
}
/* Note: This function has been added because a white-background was observed when the list resized,
* when the number of elements were lesser than the maximum capacity of the list (ie. 4).
* Binding Height/MaxHeight Properties did not solve this issue.
*/
private void SuggestionList_UpdateListSize(object sender, Windows.UI.Xaml.Controls.ContainerContentChangingEventArgs e)
{
int count = _viewModel?.Results?.Results.Count ?? 0;
int displayCount = Math.Min(count, _settings.MaxResultsToShow);
_resultList.Height = displayCount * ROW_HEIGHT;
}
private void SuggestionsList_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)
{
Windows.UI.Xaml.Controls.ListView listview = (Windows.UI.Xaml.Controls.ListView)sender;
ListView listview = (ListView)sender;
_viewModel.Results.SelectedItem = (ResultViewModel) listview.SelectedItem;
if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
{
@@ -416,12 +271,11 @@ namespace PowerLauncher
private const int millisecondsToWait = 100;
private static DateTime s_lastTimeOfTyping;
private string ListView_FirstItem(String input)
{
if (!String.IsNullOrEmpty(input))
if (!string.IsNullOrEmpty(input))
{
String selectedItem = _viewModel.Results?.SelectedItem?.ToString();
string selectedItem = _viewModel.Results?.SelectedItem?.ToString();
int selectedIndex = _viewModel.Results.SelectedIndex;
if (selectedItem != null && selectedIndex == 0)
{
@@ -432,12 +286,29 @@ namespace PowerLauncher
}
}
return String.Empty;
return string.Empty;
}
private void QueryTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_isTextSetProgramatically)
{
var textBox = ((TextBox)sender);
textBox.SelectionStart = textBox.Text.Length;
_isTextSetProgramatically = false;
}
else
{
var text = ((TextBox)sender).Text;
if (text == string.Empty)
{
SearchBox.AutoCompleteTextBlock.Text = string.Empty;
}
_viewModel.QueryText = text;
var latestTimeOfTyping = DateTime.Now;
private void QueryTextBox_TextChangedProgramatically(object sender, Windows.UI.Xaml.Controls.TextChangedEventArgs e)
{
Task.Run(() => DelayedCheck(latestTimeOfTyping, text));
s_lastTimeOfTyping = latestTimeOfTyping;
}
}
private async Task DelayedCheck(DateTime latestTimeOfTyping, string text)
@@ -451,27 +322,23 @@ namespace PowerLauncher
}));
}
}
private void WindowsXamlHost_PreviewMouseDown(object sender, MouseButtonEventArgs e)
private void ListBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
// if (sender != null && e.OriginalSource != null)
// {
// //var r = (ResultListBox)sender;
// //var d = (DependencyObject)e.OriginalSource;
// //var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem;
// //var result = (ResultViewModel)item?.DataContext;
// //if (result != null)
// //{
// // if (e.ChangedButton == MouseButton.Left)
// // {
// // _viewModel.OpenResultCommand.Execute(null);
// // }
// // else if (e.ChangedButton == MouseButton.Right)
// // {
// // _viewModel.LoadContextMenuCommand.Execute(null);
// // }
// //}
// }
if (e.ChangedButton == MouseButton.Right)
{
e.Handled = true;
}
}
private void Window_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Changed");
}
private void OutroStoryboard_Completed(object sender, EventArgs e)
{
Hide();
}
}
}
}