mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #1 from AminSallah/reselect
Prevent reselect first result if needed
This commit is contained in:
commit
99ac5f010d
4 changed files with 21 additions and 9 deletions
|
|
@ -293,9 +293,10 @@ namespace Flow.Launcher.Plugin
|
|||
public bool IsGameModeOn();
|
||||
|
||||
/// <summary>
|
||||
/// Reload Query
|
||||
/// Reloads the query.
|
||||
/// This method should run
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void ReQuery();
|
||||
/// <param name="reselect">Choose the first result after reload if true; keep the last selected result if false. Default is true.</param>
|
||||
public void ReQuery(bool reselect = true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ namespace Flow.Launcher
|
|||
public void RegisterGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Add(callback);
|
||||
public void RemoveGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Remove(callback);
|
||||
|
||||
public void ReQuery() => _mainVM.ReQuery();
|
||||
public void ReQuery(bool reselect = true) => _mainVM.ReQuery(reselect);
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ namespace Flow.Launcher.ViewModel
|
|||
#region Private Fields
|
||||
|
||||
private bool _isQueryRunning;
|
||||
private bool _reselect = true;
|
||||
private Query _lastQuery;
|
||||
private Result lastContextMenuResult = new Result();
|
||||
private List<Result> lastContextMenuResults = new List<Result>();
|
||||
|
|
@ -216,6 +217,15 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
public void ReQuery(bool reselect)
|
||||
{
|
||||
if (SelectedIsFromQueryResults())
|
||||
{
|
||||
_reselect = reselect;
|
||||
QueryResults(isReQuery: true);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void LoadContextMenu()
|
||||
{
|
||||
|
|
@ -1151,7 +1161,8 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
Results.AddResults(resultsForUpdates, token);
|
||||
Results.AddResults(resultsForUpdates, token, _reselect);
|
||||
_reselect = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -147,23 +147,23 @@ namespace Flow.Launcher.ViewModel
|
|||
/// <summary>
|
||||
/// To avoid deadlock, this method should not called from main thread
|
||||
/// </summary>
|
||||
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token)
|
||||
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
|
||||
{
|
||||
var newResults = NewResults(resultsForUpdates);
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
UpdateResults(newResults, token);
|
||||
UpdateResults(newResults, token, reselect);
|
||||
}
|
||||
|
||||
private void UpdateResults(List<ResultViewModel> newResults, CancellationToken token = default)
|
||||
private void UpdateResults(List<ResultViewModel> newResults, CancellationToken token = default, bool reselect = true)
|
||||
{
|
||||
lock (_collectionLock)
|
||||
{
|
||||
// update UI in one run, so it can avoid UI flickering
|
||||
Results.Update(newResults, token);
|
||||
if (Results.Any())
|
||||
if (reselect && Results.Any())
|
||||
SelectedItem = Results[0];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue