Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#613) Fix settings to show all result when showing search box #618

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ alias a
inner join data_alias_synonyms_v s on s.id_alias = a.id
where a.hidden = 0
order by
e.exec_count desc,
a.exec_count desc,
an.name
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,15 @@ public void Save()
Db.WithinTransaction(
tx =>
{
const string sqlExists = "select count(*) from settings where s_key = 'json'";
var exists = tx.Connection!.ExecuteScalar<long>(sqlExists) > 0;

if (!exists)
{
const string sqlInsert = "insert into settings(s_key) values ('json')";
tx.Connection.Execute(sqlInsert);
}

const string sql = "update settings set s_value = @value where s_key = 'json'";
const string sql = """
insert into settings(s_key, s_value) values ('json', @json)
on conflict (s_key) do update
set
s_value = @json
where s_key = 'json'
""";
var json = JsonConvert.SerializeObject(Current);
tx.Connection.Execute(sql, new { value = json });
tx.Connection!.Execute(sql, new { json });
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Infra/Lanceur.Infra/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task<IEnumerable<QueryResult>> SearchAsync(Cmdline query, bool does
{
using var measurement = _logger.MeasureExecutionTime(this);

if (doesReturnAllIfEmpty && query is null) return await GetAllAsync();
if (doesReturnAllIfEmpty && (query is null || query.IsEmpty)) return await GetAllAsync();
if (query is null || query.IsEmpty) return new List<QueryResult>();

//Get the alive stores
Expand Down
9 changes: 9 additions & 0 deletions src/UI/Lanceur.Ui.Core/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ private void SetQuery()
WeakReferenceMessenger.Default.Send<SetQueryMessage>(new(cmd));
}

public void DisplayResultsIfAllowed()
{
if (_settingsFacade.Application.ShowResult)
_ = Task.Run(() => _searchService.SearchAsync(Cmdline.Empty, true))
.ContinueWith(r => Results = new(r.Result), TaskScheduler.FromCurrentSynchronizationContext());

_logger.LogTrace("When showing search, display all results: {ShowAtStartup}", _settingsFacade.Application.ShowAtStartup);
}

public void RefreshSettings()
{
_settingsFacade.Reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class ApplicationSettingsViewModel : ObservableObject
private readonly IAppRestartService _appRestartService;
[ObservableProperty] private ISettingsFacade _settings;
private readonly IUserInteractionService _userInteraction;
[ObservableProperty] private bool _showResults;
[ObservableProperty] private bool _showResult;
[ObservableProperty] private bool _isTraceEnabled;

#endregion
Expand Down Expand Up @@ -68,7 +68,7 @@ IUserInteractionService userInteraction
DbPath = _settings.Local.DbPath;
WindowBackdropStyle = _settings.Application.Window.BackdropStyle;
SearchDelay = _settings.Application.SearchDelay;
ShowResults = _settings.Application.ShowResult;
ShowResult = _settings.Application.ShowResult;
ShowAtStartup = _settings.Application.ShowAtStartup;
ShowLastQuery = _settings.Application.ShowLastQuery;

Expand Down Expand Up @@ -116,7 +116,7 @@ private void MapSettings()
Settings.Local.DbPath = DbPath;
Settings.Application.Window.BackdropStyle = WindowBackdropStyle;
Settings.Application.SearchDelay = SearchDelay;
Settings.Application.ShowResult = ShowResults;
Settings.Application.ShowResult = ShowResult;
Settings.Application.ShowAtStartup = ShowAtStartup;
Settings.Application.ShowLastQuery = ShowLastQuery;
}
Expand Down
1 change: 1 addition & 0 deletions src/UI/Lanceur.Ui.WPF/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ private void ShowWindow()
_logger.LogTrace("Current window is at {Coordinate}", this.ToCoordinate());

ViewModel.RefreshSettings();
ViewModel.DisplayResultsIfAllowed();
Visibility = Visibility.Visible;
QueryTextBox.Focus();

Expand Down