Additional formatting tweaks (#5909)

This commit is contained in:
Clint Rutkas
2020-08-13 15:32:12 -07:00
committed by GitHub
parent 38b0d427f8
commit 23a9fa40e7
15 changed files with 129 additions and 137 deletions

View File

@@ -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
}
}