mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
Additional formatting tweaks (#5909)
This commit is contained in:
@@ -51,7 +51,7 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
PluginName = PluginName,
|
||||
Trigger = triggerType.ToString(),
|
||||
ActionName = Title
|
||||
ActionName = Title,
|
||||
};
|
||||
PowerToysTelemetry.Log.WriteEvent(eventData);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
public class MainViewModel : BaseModel, ISavable, IDisposable
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private Query _currentQuery;
|
||||
private static Query _emptyQuery = new Query();
|
||||
private static bool _disposed;
|
||||
@@ -56,15 +54,12 @@ namespace PowerLauncher.ViewModel
|
||||
private System.Diagnostics.Stopwatch hotkeyTimer = new System.Diagnostics.Stopwatch();
|
||||
|
||||
private readonly object _addResultsLock = new object();
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public MainViewModel(Settings settings)
|
||||
{
|
||||
_hotkeyManager = new HotkeyManager();
|
||||
_saved = false;
|
||||
_queryTextBeforeLeaveResults = "";
|
||||
_queryTextBeforeLeaveResults = string.Empty;
|
||||
_currentQuery = _emptyQuery;
|
||||
_disposed = false;
|
||||
|
||||
@@ -204,7 +199,9 @@ namespace PowerLauncher.ViewModel
|
||||
if (!didExecuteContextButton)
|
||||
{
|
||||
var result = results.SelectedItem.Result;
|
||||
if (result != null && result.Action != null) // SelectedItem returns null if selection is empty.
|
||||
|
||||
// SelectedItem returns null if selection is empty.
|
||||
if (result != null && result.Action != null)
|
||||
{
|
||||
MainWindowVisibility = Visibility.Collapsed;
|
||||
|
||||
@@ -212,7 +209,7 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
result.Action(new ActionContext
|
||||
{
|
||||
SpecialKeyState = KeyboardHelper.CheckModifiers()
|
||||
SpecialKeyState = KeyboardHelper.CheckModifiers(),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -266,10 +263,6 @@ namespace PowerLauncher.ViewModel
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ViewModel Properties
|
||||
|
||||
public Brush MainWindowBackground { get; set; }
|
||||
|
||||
public Brush MainWindowBorderBrush { get; set; }
|
||||
@@ -280,16 +273,16 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
public ResultsViewModel History { get; private set; }
|
||||
|
||||
public string SystemQueryText { get; set; } = String.Empty;
|
||||
public string SystemQueryText { get; set; } = string.Empty;
|
||||
|
||||
public string QueryText { get; set; } = String.Empty;
|
||||
public string QueryText { get; set; } = string.Empty;
|
||||
|
||||
/// <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.
|
||||
/// Also we don't want to force the results to change unless explicitly told to.
|
||||
/// </summary>
|
||||
/// <param name="queryText"></param>
|
||||
/// <param name="queryText">Text that is being queried from user</param>
|
||||
/// <param name="requery">Optional Parameter that if true, will automatically execute a query against the updated text</param>
|
||||
public void ChangeQueryText(string queryText, bool requery = false)
|
||||
{
|
||||
@@ -308,7 +301,10 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
private ResultsViewModel SelectedResults
|
||||
{
|
||||
get { return _selectedResults; }
|
||||
get
|
||||
{
|
||||
return _selectedResults;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
@@ -337,6 +333,7 @@ namespace PowerLauncher.ViewModel
|
||||
QueryText = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
_selectedResults.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
@@ -347,7 +344,10 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
public Visibility MainWindowVisibility
|
||||
{
|
||||
get { return _visibility; }
|
||||
get
|
||||
{
|
||||
return _visibility;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
@@ -360,7 +360,6 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new LauncherHideEvent());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,8 +395,6 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
public ICommand ClearQueryCommand { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public void Query()
|
||||
{
|
||||
if (SelectedIsFromQueryResults())
|
||||
@@ -433,18 +430,17 @@ namespace PowerLauncher.ViewModel
|
||||
SelectedResults = Results;
|
||||
ChangeQueryText(h.Query);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(query))
|
||||
{
|
||||
var filtered = results.Where
|
||||
(
|
||||
var filtered = results.Where(
|
||||
r => StringMatcher.FuzzySearch(query, r.Title).IsSearchPrecisionScoreMet() ||
|
||||
StringMatcher.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()
|
||||
).ToList();
|
||||
StringMatcher.FuzzySearch(query, r.SubTitle).IsSearchPrecisionScoreMet()).ToList();
|
||||
|
||||
History.AddResults(filtered, _updateToken);
|
||||
}
|
||||
else
|
||||
@@ -547,7 +543,6 @@ namespace PowerLauncher.ViewModel
|
||||
// nothing to do here
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -559,10 +554,9 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
QueryTimeMs = queryTimer.ElapsedMilliseconds,
|
||||
NumResults = Results.Results.Count,
|
||||
QueryLength = query.RawQuery.Length
|
||||
QueryLength = query.RawQuery.Length,
|
||||
};
|
||||
PowerToysTelemetry.Log.WriteEvent(queryEvent);
|
||||
|
||||
}, currentCancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -617,7 +611,6 @@ namespace PowerLauncher.ViewModel
|
||||
var selected = SelectedResults == History;
|
||||
return selected;
|
||||
}
|
||||
#region Hotkey
|
||||
|
||||
private void SetHotkey(string hotkeyStr, HotkeyCallback action)
|
||||
{
|
||||
@@ -651,25 +644,37 @@ namespace PowerLauncher.ViewModel
|
||||
/// <summary>
|
||||
/// Checks if Wox should ignore any hotkeys
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>if any hotkeys should be ignored</returns>
|
||||
private bool ShouldIgnoreHotkeys()
|
||||
{
|
||||
// double if to omit calling win32 function
|
||||
if (_settings.IgnoreHotkeysOnFullscreen)
|
||||
{
|
||||
if (WindowsInteropHelper.IsWindowFullscreen())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SetCustomPluginHotkey()
|
||||
{
|
||||
if (_settings.CustomPluginHotkeys == null) return;
|
||||
if (_settings.CustomPluginHotkeys == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (CustomPluginHotkey hotkey in _settings.CustomPluginHotkeys)
|
||||
{
|
||||
SetHotkey(hotkey.Hotkey, () =>
|
||||
{
|
||||
if (ShouldIgnoreHotkeys()) return;
|
||||
if (ShouldIgnoreHotkeys())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MainWindowVisibility = Visibility.Visible;
|
||||
ChangeQueryText(hotkey.ActionKeyword);
|
||||
});
|
||||
@@ -687,6 +692,7 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
StartHotkeyTimer();
|
||||
}
|
||||
|
||||
if (_settings.LastQueryMode == LastQueryMode.Empty)
|
||||
{
|
||||
ChangeQueryText(string.Empty);
|
||||
@@ -721,10 +727,6 @@ namespace PowerLauncher.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (!_saved)
|
||||
@@ -777,7 +779,7 @@ namespace PowerLauncher.ViewModel
|
||||
List<Result> list = new List<Result>();
|
||||
Result r = new Result
|
||||
{
|
||||
Title = "hello"
|
||||
Title = "hello",
|
||||
};
|
||||
list.Add(r);
|
||||
Results.AddResults(list, _updateToken);
|
||||
@@ -794,17 +796,17 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
var _ = PluginManager.QueryForPlugin(plugin, query);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleContextMenu(Key AcceleratorKey, ModifierKeys AcceleratorModifiers)
|
||||
public void HandleContextMenu(Key acceleratorKey, ModifierKeys acceleratorModifiers)
|
||||
{
|
||||
var results = SelectedResults;
|
||||
if (results.SelectedItem != null)
|
||||
{
|
||||
foreach (ContextMenuItemViewModel contextMenuItems in results.SelectedItem.ContextMenuItems)
|
||||
{
|
||||
if (contextMenuItems.AcceleratorKey == AcceleratorKey && contextMenuItems.AcceleratorModifiers == AcceleratorModifiers)
|
||||
if (contextMenuItems.AcceleratorKey == acceleratorKey && contextMenuItems.AcceleratorModifiers == acceleratorModifiers)
|
||||
{
|
||||
MainWindowVisibility = Visibility.Collapsed;
|
||||
contextMenuItems.Command.Execute(null);
|
||||
@@ -813,7 +815,7 @@ namespace PowerLauncher.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetAutoCompleteText(int index, string input, String query)
|
||||
public static string GetAutoCompleteText(int index, string input, string query)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(query))
|
||||
{
|
||||
@@ -830,7 +832,7 @@ namespace PowerLauncher.ViewModel
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static string GetSearchText(int index, String input, string query)
|
||||
public static string GetSearchText(int index, string input, string query)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(input))
|
||||
{
|
||||
@@ -841,6 +843,7 @@ namespace PowerLauncher.ViewModel
|
||||
return query + input.Substring(query.Length);
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -871,6 +874,7 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
_hotkeyManager?.UnregisterHotkey(_hotkeyHandle);
|
||||
}
|
||||
|
||||
_hotkeyManager?.Dispose();
|
||||
_updateSource?.Dispose();
|
||||
_disposed = true;
|
||||
@@ -898,7 +902,5 @@ namespace PowerLauncher.ViewModel
|
||||
hotkeyTimer.Reset();
|
||||
return recordedTime;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using PowerLauncher.Helper;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Infrastructure.Image;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin;
|
||||
using PowerLauncher.Helper;
|
||||
|
||||
namespace PowerLauncher.ViewModel
|
||||
{
|
||||
@@ -19,7 +19,7 @@ namespace PowerLauncher.ViewModel
|
||||
public enum ActivationType
|
||||
{
|
||||
Selection,
|
||||
Hover
|
||||
Hover,
|
||||
}
|
||||
|
||||
public ObservableCollection<ContextMenuItemViewModel> ContextMenuItems { get; } = new ObservableCollection<ContextMenuItemViewModel>();
|
||||
@@ -140,17 +140,20 @@ namespace PowerLauncher.ViewModel
|
||||
AcceleratorModifiers = r.AcceleratorModifiers,
|
||||
Command = new RelayCommand(_ =>
|
||||
{
|
||||
bool hideWindow = r.Action != null && r.Action(new ActionContext
|
||||
{
|
||||
SpecialKeyState = KeyboardHelper.CheckModifiers()
|
||||
});
|
||||
bool hideWindow =
|
||||
r.Action != null &&
|
||||
r.Action(
|
||||
new ActionContext
|
||||
{
|
||||
SpecialKeyState = KeyboardHelper.CheckModifiers(),
|
||||
});
|
||||
|
||||
if (hideWindow)
|
||||
{
|
||||
// TODO - Do we hide the window
|
||||
// MainWindowVisibility = Visibility.Collapsed;
|
||||
}
|
||||
})
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -269,7 +272,7 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var display = String.IsNullOrEmpty(Result.QueryTextDisplay) ? Result.Title : Result.QueryTextDisplay;
|
||||
var display = string.IsNullOrEmpty(Result.QueryTextDisplay) ? Result.Title : Result.QueryTextDisplay;
|
||||
return display;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,21 +18,18 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
public class ResultsViewModel : BaseModel
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private readonly object _collectionLock = new object();
|
||||
|
||||
private readonly Settings _settings;
|
||||
|
||||
#endregion
|
||||
|
||||
public ResultsViewModel()
|
||||
{
|
||||
Results = new ResultCollection();
|
||||
BindingOperations.EnableCollectionSynchronization(Results, _collectionLock);
|
||||
}
|
||||
|
||||
public ResultsViewModel(Settings settings) : this()
|
||||
public ResultsViewModel(Settings settings)
|
||||
: this()
|
||||
{
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_settings.PropertyChanged += (s, e) =>
|
||||
@@ -47,8 +44,6 @@ namespace PowerLauncher.ViewModel
|
||||
};
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
public int MaxHeight
|
||||
{
|
||||
get
|
||||
@@ -63,11 +58,13 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
public ResultViewModel SelectedItem
|
||||
{
|
||||
get { return _selectedItem; }
|
||||
get
|
||||
{
|
||||
return _selectedItem;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// value can be null when selecting an item in a virtualized list
|
||||
if (value != null)
|
||||
{
|
||||
if (_selectedItem != null)
|
||||
@@ -91,10 +88,6 @@ namespace PowerLauncher.ViewModel
|
||||
|
||||
public ResultCollection Results { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static int InsertIndexOf(int newScore, IList<ResultViewModel> list)
|
||||
{
|
||||
int index = 0;
|
||||
@@ -125,10 +118,6 @@ namespace PowerLauncher.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void SelectNextResult()
|
||||
{
|
||||
SelectedIndex = NewIndex(SelectedIndex + 1);
|
||||
@@ -247,9 +236,6 @@ namespace PowerLauncher.ViewModel
|
||||
Results.AddRange(sorted);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region FormattedText Dependency Property
|
||||
public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached(
|
||||
"FormattedText",
|
||||
typeof(Inline),
|
||||
@@ -272,16 +258,20 @@ namespace PowerLauncher.ViewModel
|
||||
private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var textBlock = d as TextBlock;
|
||||
if (textBlock == null) return;
|
||||
if (textBlock == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var inline = (Inline)e.NewValue;
|
||||
|
||||
textBlock.Inlines.Clear();
|
||||
if (inline == null) return;
|
||||
if (inline == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
textBlock.Inlines.Add(inline);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,16 +34,8 @@ namespace PowerLauncher.ViewModel
|
||||
_storage.Save();
|
||||
}
|
||||
|
||||
#region general
|
||||
|
||||
private static Internationalization _translater => InternationalizationManager.Instance;
|
||||
|
||||
#endregion
|
||||
|
||||
#region about
|
||||
|
||||
public string ActivatedTimes => string.Format(CultureInfo.InvariantCulture, _translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user