whitespace forced changes (#6002)

This commit is contained in:
Clint Rutkas
2020-08-17 10:00:56 -07:00
committed by GitHub
parent 649e7e103d
commit d055ba1c3b
129 changed files with 14175 additions and 14175 deletions

View File

@@ -1,213 +1,213 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Windows;
using ManagedCommon;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Telemetry;
using PowerLauncher.Helper;
using PowerLauncher.ViewModel;
using Wox;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Infrastructure;
using Wox.Infrastructure.Http;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace PowerLauncher
{
public partial class App : IDisposable, ISingleInstanceApp
{
public static PublicAPIInstance API { get; private set; }
private readonly Alphabet _alphabet = new Alphabet();
private const string Unique = "PowerLauncher_Unique_Application_Mutex";
private static bool _disposed = false;
private static int _powerToysPid;
private Settings _settings;
private MainViewModel _mainVM;
private MainWindow _mainWindow;
private ThemeManager _themeManager;
private SettingWindowViewModel _settingsVM;
private StringMatcher _stringMatcher;
private SettingsWatcher _settingsWatcher;
[STAThread]
public static void Main(string[] args)
{
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
if (args?.Length > 0)
{
_ = int.TryParse(args[0], out _powerToysPid);
}
using (var application = new App())
{
application.InitializeComponent();
application.Run();
}
}
}
private void OnStartup(object sender, StartupEventArgs e)
{
RunnerHelper.WaitForPowerToysRunner(_powerToysPid, () =>
{
try
{
Dispose();
}
finally
{
Environment.Exit(0);
}
});
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();
Stopwatch.Normal("|App.OnStartup|Startup cost", () =>
{
Log.Info("|App.OnStartup|Begin PowerToys Run startup ----------------------------------------------------");
Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}");
RegisterAppDomainExceptions();
RegisterDispatcherUnhandledException();
_themeManager = new ThemeManager(this);
ImageLoader.Initialize(_themeManager.GetCurrentTheme());
_settingsVM = new SettingWindowViewModel();
_settings = _settingsVM.Settings;
_alphabet.Initialize(_settings);
_stringMatcher = new StringMatcher(_alphabet);
StringMatcher.Instance = _stringMatcher;
_stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;
PluginManager.LoadPlugins(_settings.PluginSettings);
_mainVM = new MainViewModel(_settings);
_mainWindow = new MainWindow(_settings, _mainVM);
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet, _themeManager);
PluginManager.InitializePlugins(API);
Current.MainWindow = _mainWindow;
Current.MainWindow.Title = Constant.ExeFileName;
// happlebao todo temp fix for instance code logic
// load plugin before change language, because plugin language also needs be changed
InternationalizationManager.Instance.Settings = _settings;
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
// main windows needs initialized before theme change because of blur settings
Http.Proxy = _settings.Proxy;
RegisterExitEvents();
_settingsWatcher = new SettingsWatcher(_settings);
_mainVM.MainWindowVisibility = Visibility.Visible;
_mainVM.ColdStartFix();
_themeManager.ThemeChanged += OnThemeChanged;
Log.Info("|App.OnStartup|End PowerToys Run startup ---------------------------------------------------- ");
bootTime.Stop();
PowerToysTelemetry.Log.WriteEvent(new LauncherBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
// [Conditional("RELEASE")]
// check update every 5 hours
// check updates on startup
});
}
private void RegisterExitEvents()
{
AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose();
Current.Exit += (s, e) => Dispose();
Current.SessionEnding += (s, e) => Dispose();
}
/// <summary>
/// Callback when windows theme is changed.
/// </summary>
/// <param name="oldTheme">Previous Theme</param>
/// <param name="newTheme">Current Theme</param>
private void OnThemeChanged(Theme oldTheme, Theme newTheme)
{
ImageLoader.UpdateIconPath(newTheme);
_mainVM.Query();
}
/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private void RegisterDispatcherUnhandledException()
{
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
}
/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterAppDomainExceptions()
{
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
}
public void OnSecondAppStarted()
{
Current.MainWindow.Visibility = Visibility.Visible;
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
Stopwatch.Normal("|App.OnExit|Exit cost", () =>
{
Log.Info("|App.OnExit| Start PowerToys Run Exit---------------------------------------------------- ");
if (disposing)
{
_themeManager.ThemeChanged -= OnThemeChanged;
API.SaveAppAllSettings();
PluginManager.Dispose();
_mainWindow.Dispose();
API.Dispose();
_mainVM.Dispose();
_themeManager.Dispose();
_disposed = true;
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
_disposed = true;
Log.Info("|App.OnExit| End PowerToys Run Exit ---------------------------------------------------- ");
});
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~App()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Windows;
using ManagedCommon;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Telemetry;
using PowerLauncher.Helper;
using PowerLauncher.ViewModel;
using Wox;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Infrastructure;
using Wox.Infrastructure.Http;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace PowerLauncher
{
public partial class App : IDisposable, ISingleInstanceApp
{
public static PublicAPIInstance API { get; private set; }
private readonly Alphabet _alphabet = new Alphabet();
private const string Unique = "PowerLauncher_Unique_Application_Mutex";
private static bool _disposed = false;
private static int _powerToysPid;
private Settings _settings;
private MainViewModel _mainVM;
private MainWindow _mainWindow;
private ThemeManager _themeManager;
private SettingWindowViewModel _settingsVM;
private StringMatcher _stringMatcher;
private SettingsWatcher _settingsWatcher;
[STAThread]
public static void Main(string[] args)
{
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
if (args?.Length > 0)
{
_ = int.TryParse(args[0], out _powerToysPid);
}
using (var application = new App())
{
application.InitializeComponent();
application.Run();
}
}
}
private void OnStartup(object sender, StartupEventArgs e)
{
RunnerHelper.WaitForPowerToysRunner(_powerToysPid, () =>
{
try
{
Dispose();
}
finally
{
Environment.Exit(0);
}
});
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();
Stopwatch.Normal("|App.OnStartup|Startup cost", () =>
{
Log.Info("|App.OnStartup|Begin PowerToys Run startup ----------------------------------------------------");
Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}");
RegisterAppDomainExceptions();
RegisterDispatcherUnhandledException();
_themeManager = new ThemeManager(this);
ImageLoader.Initialize(_themeManager.GetCurrentTheme());
_settingsVM = new SettingWindowViewModel();
_settings = _settingsVM.Settings;
_alphabet.Initialize(_settings);
_stringMatcher = new StringMatcher(_alphabet);
StringMatcher.Instance = _stringMatcher;
_stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;
PluginManager.LoadPlugins(_settings.PluginSettings);
_mainVM = new MainViewModel(_settings);
_mainWindow = new MainWindow(_settings, _mainVM);
API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet, _themeManager);
PluginManager.InitializePlugins(API);
Current.MainWindow = _mainWindow;
Current.MainWindow.Title = Constant.ExeFileName;
// happlebao todo temp fix for instance code logic
// load plugin before change language, because plugin language also needs be changed
InternationalizationManager.Instance.Settings = _settings;
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
// main windows needs initialized before theme change because of blur settings
Http.Proxy = _settings.Proxy;
RegisterExitEvents();
_settingsWatcher = new SettingsWatcher(_settings);
_mainVM.MainWindowVisibility = Visibility.Visible;
_mainVM.ColdStartFix();
_themeManager.ThemeChanged += OnThemeChanged;
Log.Info("|App.OnStartup|End PowerToys Run startup ---------------------------------------------------- ");
bootTime.Stop();
PowerToysTelemetry.Log.WriteEvent(new LauncherBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
// [Conditional("RELEASE")]
// check update every 5 hours
// check updates on startup
});
}
private void RegisterExitEvents()
{
AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose();
Current.Exit += (s, e) => Dispose();
Current.SessionEnding += (s, e) => Dispose();
}
/// <summary>
/// Callback when windows theme is changed.
/// </summary>
/// <param name="oldTheme">Previous Theme</param>
/// <param name="newTheme">Current Theme</param>
private void OnThemeChanged(Theme oldTheme, Theme newTheme)
{
ImageLoader.UpdateIconPath(newTheme);
_mainVM.Query();
}
/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private void RegisterDispatcherUnhandledException()
{
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
}
/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterAppDomainExceptions()
{
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
}
public void OnSecondAppStarted()
{
Current.MainWindow.Visibility = Visibility.Visible;
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
Stopwatch.Normal("|App.OnExit|Exit cost", () =>
{
Log.Info("|App.OnExit| Start PowerToys Run Exit---------------------------------------------------- ");
if (disposing)
{
_themeManager.ThemeChanged -= OnThemeChanged;
API.SaveAppAllSettings();
PluginManager.Dispose();
_mainWindow.Dispose();
API.Dispose();
_mainVM.Dispose();
_themeManager.Dispose();
_disposed = true;
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
_disposed = true;
Log.Info("|App.OnExit| End PowerToys Run Exit ---------------------------------------------------- ");
});
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~App()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -1,35 +1,35 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PowerLauncher.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("https://aka.ms/powerToys")]
public string GithubRepo {
get {
return ((string)(this["GithubRepo"]));
}
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PowerLauncher.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("https://aka.ms/powerToys")]
public string GithubRepo {
get {
return ((string)(this["GithubRepo"]));
}
}
}
}

View File

@@ -1,277 +1,277 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using PowerLauncher.Helper;
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
namespace PowerLauncher.ViewModel
{
public class ResultsViewModel : BaseModel
{
private readonly object _collectionLock = new object();
private readonly Settings _settings;
public ResultsViewModel()
{
Results = new ResultCollection();
BindingOperations.EnableCollectionSynchronization(Results, _collectionLock);
}
public ResultsViewModel(Settings settings)
: this()
{
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
_settings.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(_settings.MaxResultsToShow))
{
Application.Current.Dispatcher.Invoke(() =>
{
OnPropertyChanged(nameof(MaxHeight));
});
}
};
}
public int MaxHeight
{
get
{
return _settings.MaxResultsToShow * 75;
}
}
public int SelectedIndex { get; set; }
private ResultViewModel _selectedItem;
public ResultViewModel SelectedItem
{
get
{
return _selectedItem;
}
set
{
if (value != null)
{
if (_selectedItem != null)
{
_selectedItem.DeactivateContextButtons(ResultViewModel.ActivationType.Selection);
}
_selectedItem = value;
_selectedItem.ActivateContextButtons(ResultViewModel.ActivationType.Selection);
}
else
{
_selectedItem = value;
}
}
}
public Thickness Margin { get; set; }
public Visibility Visibility { get; set; } = Visibility.Hidden;
public ResultCollection Results { get; }
private static int InsertIndexOf(int newScore, IList<ResultViewModel> list)
{
int index = 0;
for (; index < list.Count; index++)
{
var result = list[index];
if (newScore > result.Result.Score)
{
break;
}
}
return index;
}
private int NewIndex(int i)
{
var n = Results.Count;
if (n > 0)
{
i = (n + i) % n;
return i;
}
else
{
// SelectedIndex returns -1 if selection is empty.
return -1;
}
}
public void SelectNextResult()
{
SelectedIndex = NewIndex(SelectedIndex + 1);
}
public void SelectPrevResult()
{
SelectedIndex = NewIndex(SelectedIndex - 1);
}
public void SelectNextPage()
{
SelectedIndex = NewIndex(SelectedIndex + _settings.MaxResultsToShow);
}
public void SelectPrevPage()
{
SelectedIndex = NewIndex(SelectedIndex - _settings.MaxResultsToShow);
}
public void SelectFirstResult()
{
SelectedIndex = NewIndex(0);
}
public void Clear()
{
Results.Clear();
}
public void RemoveResultsExcept(PluginMetadata metadata)
{
Results.RemoveAll(r => r.Result.PluginID != metadata.ID);
}
public void RemoveResultsFor(PluginMetadata metadata)
{
Results.RemoveAll(r => r.Result.PluginID == metadata.ID);
}
public void SelectNextTabItem()
{
// Do nothing if there is no selected item or we've selected the next context button
if (!SelectedItem?.SelectNextContextButton() ?? true)
{
SelectNextResult();
}
}
public void SelectPrevTabItem()
{
// Do nothing if there is no selected item or we've selected the previous context button
if (!SelectedItem?.SelectPrevContextButton() ?? true)
{
// Tabbing backwards should highlight the last item of the previous row
SelectPrevResult();
SelectedItem.SelectLastContextButton();
}
}
public void SelectNextContextMenuItem()
{
if (SelectedItem != null)
{
if (!SelectedItem.SelectNextContextButton())
{
SelectedItem.SelectLastContextButton();
}
}
}
public void SelectPreviousContextMenuItem()
{
if (SelectedItem != null)
{
SelectedItem.SelectPrevContextButton();
}
}
public bool IsContextMenuItemSelected()
{
if (SelectedItem != null && SelectedItem.ContextMenuSelectedIndex != ResultViewModel.NoSelectionIndex)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Add new results to ResultCollection
/// </summary>
public void AddResults(List<Result> newRawResults, CancellationToken ct)
{
if (newRawResults == null)
{
throw new ArgumentNullException(nameof(newRawResults));
}
List<ResultViewModel> newResults = new List<ResultViewModel>(newRawResults.Count);
foreach (Result r in newRawResults)
{
newResults.Add(new ResultViewModel(r));
ct.ThrowIfCancellationRequested();
}
Results.AddRange(newResults);
}
public void Sort()
{
var sorted = Results.OrderByDescending(x => x.Result.Score).ToList();
Clear();
Results.AddRange(sorted);
}
public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached(
"FormattedText",
typeof(Inline),
typeof(ResultsViewModel),
new PropertyMetadata(null, FormattedTextPropertyChanged));
public static void SetFormattedText(DependencyObject textBlock, IList<int> value)
{
if (textBlock != null)
{
textBlock.SetValue(FormattedTextProperty, value);
}
}
public static Inline GetFormattedText(DependencyObject textBlock)
{
return (Inline)textBlock?.GetValue(FormattedTextProperty);
}
private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var textBlock = d as TextBlock;
if (textBlock == null)
{
return;
}
var inline = (Inline)e.NewValue;
textBlock.Inlines.Clear();
if (inline == null)
{
return;
}
textBlock.Inlines.Add(inline);
}
}
}
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using PowerLauncher.Helper;
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
namespace PowerLauncher.ViewModel
{
public class ResultsViewModel : BaseModel
{
private readonly object _collectionLock = new object();
private readonly Settings _settings;
public ResultsViewModel()
{
Results = new ResultCollection();
BindingOperations.EnableCollectionSynchronization(Results, _collectionLock);
}
public ResultsViewModel(Settings settings)
: this()
{
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
_settings.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(_settings.MaxResultsToShow))
{
Application.Current.Dispatcher.Invoke(() =>
{
OnPropertyChanged(nameof(MaxHeight));
});
}
};
}
public int MaxHeight
{
get
{
return _settings.MaxResultsToShow * 75;
}
}
public int SelectedIndex { get; set; }
private ResultViewModel _selectedItem;
public ResultViewModel SelectedItem
{
get
{
return _selectedItem;
}
set
{
if (value != null)
{
if (_selectedItem != null)
{
_selectedItem.DeactivateContextButtons(ResultViewModel.ActivationType.Selection);
}
_selectedItem = value;
_selectedItem.ActivateContextButtons(ResultViewModel.ActivationType.Selection);
}
else
{
_selectedItem = value;
}
}
}
public Thickness Margin { get; set; }
public Visibility Visibility { get; set; } = Visibility.Hidden;
public ResultCollection Results { get; }
private static int InsertIndexOf(int newScore, IList<ResultViewModel> list)
{
int index = 0;
for (; index < list.Count; index++)
{
var result = list[index];
if (newScore > result.Result.Score)
{
break;
}
}
return index;
}
private int NewIndex(int i)
{
var n = Results.Count;
if (n > 0)
{
i = (n + i) % n;
return i;
}
else
{
// SelectedIndex returns -1 if selection is empty.
return -1;
}
}
public void SelectNextResult()
{
SelectedIndex = NewIndex(SelectedIndex + 1);
}
public void SelectPrevResult()
{
SelectedIndex = NewIndex(SelectedIndex - 1);
}
public void SelectNextPage()
{
SelectedIndex = NewIndex(SelectedIndex + _settings.MaxResultsToShow);
}
public void SelectPrevPage()
{
SelectedIndex = NewIndex(SelectedIndex - _settings.MaxResultsToShow);
}
public void SelectFirstResult()
{
SelectedIndex = NewIndex(0);
}
public void Clear()
{
Results.Clear();
}
public void RemoveResultsExcept(PluginMetadata metadata)
{
Results.RemoveAll(r => r.Result.PluginID != metadata.ID);
}
public void RemoveResultsFor(PluginMetadata metadata)
{
Results.RemoveAll(r => r.Result.PluginID == metadata.ID);
}
public void SelectNextTabItem()
{
// Do nothing if there is no selected item or we've selected the next context button
if (!SelectedItem?.SelectNextContextButton() ?? true)
{
SelectNextResult();
}
}
public void SelectPrevTabItem()
{
// Do nothing if there is no selected item or we've selected the previous context button
if (!SelectedItem?.SelectPrevContextButton() ?? true)
{
// Tabbing backwards should highlight the last item of the previous row
SelectPrevResult();
SelectedItem.SelectLastContextButton();
}
}
public void SelectNextContextMenuItem()
{
if (SelectedItem != null)
{
if (!SelectedItem.SelectNextContextButton())
{
SelectedItem.SelectLastContextButton();
}
}
}
public void SelectPreviousContextMenuItem()
{
if (SelectedItem != null)
{
SelectedItem.SelectPrevContextButton();
}
}
public bool IsContextMenuItemSelected()
{
if (SelectedItem != null && SelectedItem.ContextMenuSelectedIndex != ResultViewModel.NoSelectionIndex)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Add new results to ResultCollection
/// </summary>
public void AddResults(List<Result> newRawResults, CancellationToken ct)
{
if (newRawResults == null)
{
throw new ArgumentNullException(nameof(newRawResults));
}
List<ResultViewModel> newResults = new List<ResultViewModel>(newRawResults.Count);
foreach (Result r in newRawResults)
{
newResults.Add(new ResultViewModel(r));
ct.ThrowIfCancellationRequested();
}
Results.AddRange(newResults);
}
public void Sort()
{
var sorted = Results.OrderByDescending(x => x.Result.Score).ToList();
Clear();
Results.AddRange(sorted);
}
public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached(
"FormattedText",
typeof(Inline),
typeof(ResultsViewModel),
new PropertyMetadata(null, FormattedTextPropertyChanged));
public static void SetFormattedText(DependencyObject textBlock, IList<int> value)
{
if (textBlock != null)
{
textBlock.SetValue(FormattedTextProperty, value);
}
}
public static Inline GetFormattedText(DependencyObject textBlock)
{
return (Inline)textBlock?.GetValue(FormattedTextProperty);
}
private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var textBlock = d as TextBlock;
if (textBlock == null)
{
return;
}
var inline = (Inline)e.NewValue;
textBlock.Inlines.Clear();
if (inline == null)
{
return;
}
textBlock.Inlines.Add(inline);
}
}
}