mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 11:09:28 +08:00
07310c7714
* fix typo * make function obsolete it is not used in the code * rewrite the function that converts chinese chars to pinyin 1. Only difference in this rewrite is instead of returning 2D array, return as a combined single string of all the possible pinyin combination. Since fuzzy search does character matching, this shouldn't be a problem. 2. Added a function that returns a custom language converter. In this case Pinyin converter. New converters can be added. * Use new language converter param + strip out ScoreForPinyin method * update * Change parameter name * fix failing tests * WIP * Remove todo There should be some distinction between score after precision filter and actual raw score derived from FuzzySearch. Although so far RawScore is used in testing, but it seems to describe the structure. Originally it was to avoid assigning score directly as it would be hard to reason about that output of FuzzySearch score is. * Add constructors, remove default to enforce required properties * remove setting rawscore in SearchPrecision * Change method name to reflect intention * Change parameter name + update comment * update * Remove params comment Co-authored-by: theClueless <14300910+theClueless@users.noreply.github.com>
168 lines
4.5 KiB
C#
168 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using Squirrel;
|
|
using Wox.Core.Plugin;
|
|
using Wox.Core.Resource;
|
|
using Wox.Helper;
|
|
using Wox.Infrastructure;
|
|
using Wox.Infrastructure.Hotkey;
|
|
using Wox.Infrastructure.Image;
|
|
using Wox.Plugin;
|
|
using Wox.ViewModel;
|
|
|
|
namespace Wox
|
|
{
|
|
public class PublicAPIInstance : IPublicAPI
|
|
{
|
|
private readonly SettingWindowViewModel _settingsVM;
|
|
private readonly MainViewModel _mainVM;
|
|
private readonly Alphabet _alphabet;
|
|
|
|
#region Constructor
|
|
|
|
public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM, Alphabet alphabet)
|
|
{
|
|
_settingsVM = settingsVM;
|
|
_mainVM = mainVM;
|
|
_alphabet = alphabet;
|
|
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
|
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public API
|
|
|
|
public void ChangeQuery(string query, bool requery = false)
|
|
{
|
|
_mainVM.ChangeQueryText(query);
|
|
}
|
|
|
|
public void ChangeQueryText(string query, bool selectAll = false)
|
|
{
|
|
_mainVM.ChangeQueryText(query);
|
|
}
|
|
|
|
[Obsolete]
|
|
public void CloseApp()
|
|
{
|
|
Application.Current.MainWindow.Close();
|
|
}
|
|
|
|
public void RestarApp()
|
|
{
|
|
_mainVM.MainWindowVisibility = Visibility.Hidden;
|
|
|
|
// we must manually save
|
|
// UpdateManager.RestartApp() will call Environment.Exit(0)
|
|
// which will cause ungraceful exit
|
|
SaveAppAllSettings();
|
|
|
|
UpdateManager.RestartApp();
|
|
}
|
|
|
|
public void SaveAppAllSettings()
|
|
{
|
|
_mainVM.Save();
|
|
_settingsVM.Save();
|
|
PluginManager.Save();
|
|
ImageLoader.Save();
|
|
_alphabet.Save();
|
|
}
|
|
|
|
public void ReloadAllPluginData()
|
|
{
|
|
PluginManager.ReloadData();
|
|
}
|
|
|
|
[Obsolete]
|
|
public void HideApp()
|
|
{
|
|
_mainVM.MainWindowVisibility = Visibility.Hidden;
|
|
}
|
|
|
|
[Obsolete]
|
|
public void ShowApp()
|
|
{
|
|
_mainVM.MainWindowVisibility = Visibility.Visible;
|
|
}
|
|
|
|
public void ShowMsg(string title, string subTitle = "", string iconPath = "")
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
var m = new Msg { Owner = Application.Current.MainWindow };
|
|
m.Show(title, subTitle, iconPath);
|
|
});
|
|
}
|
|
|
|
public void OpenSettingDialog()
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsVM);
|
|
});
|
|
}
|
|
|
|
public void StartLoadingBar()
|
|
{
|
|
_mainVM.ProgressBarVisibility = Visibility.Visible;
|
|
}
|
|
|
|
public void StopLoadingBar()
|
|
{
|
|
_mainVM.ProgressBarVisibility = Visibility.Collapsed;
|
|
}
|
|
|
|
public void InstallPlugin(string path)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() => PluginManager.InstallPlugin(path));
|
|
}
|
|
|
|
public string GetTranslation(string key)
|
|
{
|
|
return InternationalizationManager.Instance.GetTranslation(key);
|
|
}
|
|
|
|
public List<PluginPair> GetAllPlugins()
|
|
{
|
|
return PluginManager.AllPlugins.ToList();
|
|
}
|
|
|
|
public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent;
|
|
|
|
[Obsolete("This will be removed in Wox 1.3")]
|
|
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
|
{
|
|
results.ForEach(o =>
|
|
{
|
|
o.PluginDirectory = plugin.PluginDirectory;
|
|
o.PluginID = plugin.ID;
|
|
o.OriginQuery = query;
|
|
});
|
|
Task.Run(() =>
|
|
{
|
|
_mainVM.UpdateResultView(results, plugin, query);
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private Methods
|
|
|
|
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
|
{
|
|
if (GlobalKeyboardEvent != null)
|
|
{
|
|
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
|
|
}
|
|
return true;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|