Skip to content

Commit

Permalink
(#613) Fix settings to show all result when showing search box
Browse files Browse the repository at this point in the history
  • Loading branch information
jibedoubleve committed Jan 19, 2025
1 parent 371ad8f commit b360cd1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
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

0 comments on commit b360cd1

Please sign in to comment.