mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-10-24 06:29:07 -04:00
Improve SearchSyntaxDialog
- Double-clicking a tag will paste the tage into the search bar - SearchSyntaxDialog now modeless
This commit is contained in:
1 parent
e2fd88d075
commit
46be532740
5 files changed
+44
-8
No files matched your search
@@ -50,25 +50,25 @@
|
||||
<Grid Grid.Row="1" RowDefinitions="Auto,Auto,*">
|
||||
<TextBlock Text="STRING FIELDS" />
|
||||
<TextBlock Grid.Row="1" Text="{CompiledBinding StringUsage}" />
|
||||
<ListBox Grid.Row="2" ItemsSource="{CompiledBinding StringFields}"/>
|
||||
<ListBox Grid.Row="2" DoubleTapped="ListBox_DoubleTapped" ItemsSource="{CompiledBinding StringFields}"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="1" RowDefinitions="Auto,Auto,*">
|
||||
<TextBlock Text="NUMBER FIELDS" />
|
||||
<TextBlock Grid.Row="1" Text="{CompiledBinding NumberUsage}" />
|
||||
<ListBox Grid.Row="2" ItemsSource="{CompiledBinding NumberFields}"/>
|
||||
<ListBox Grid.Row="2" DoubleTapped="ListBox_DoubleTapped" ItemsSource="{CompiledBinding NumberFields}"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="2" RowDefinitions="Auto,Auto,*">
|
||||
<TextBlock Text="BOOLEAN (TRUE/FALSE) FIELDS" />
|
||||
<TextBlock Grid.Row="1" Text="{CompiledBinding BoolUsage}" />
|
||||
<ListBox Grid.Row="2" ItemsSource="{CompiledBinding BoolFields}"/>
|
||||
<ListBox Grid.Row="2" DoubleTapped="ListBox_DoubleTapped" ItemsSource="{CompiledBinding BoolFields}"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="3" RowDefinitions="Auto,Auto,*">
|
||||
<TextBlock Text="ID FIELDS" />
|
||||
<TextBlock Grid.Row="1" Text="{CompiledBinding IdUsage}" />
|
||||
<ListBox Grid.Row="2" ItemsSource="{CompiledBinding IdFields}"/>
|
||||
<ListBox Grid.Row="2" DoubleTapped="ListBox_DoubleTapped" ItemsSource="{CompiledBinding IdFields}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,10 +1,14 @@
|
||||
using Avalonia;
|
||||
using LibationSearchEngine;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
namespace LibationAvalonia.Dialogs
|
||||
{
|
||||
public partial class SearchSyntaxDialog : DialogWindow
|
||||
{
|
||||
public event EventHandler<string>? TagDoubleClicked;
|
||||
public string StringUsage { get; }
|
||||
public string NumberUsage { get; }
|
||||
public string BoolUsage { get; }
|
||||
@@ -51,5 +55,13 @@ namespace LibationAvalonia.Dialogs
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
private void ListBox_DoubleTapped(object? sender, Avalonia.Input.TappedEventArgs e)
|
||||
{
|
||||
if (e.Source is StyledElement { DataContext: string tag })
|
||||
{
|
||||
TagDoubleClicked?.Invoke(this, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace LibationAvalonia.ViewModels
|
||||
|
||||
public void AddQuickFilterBtn() { if (SelectedNamedFilter != null) QuickFilters.Add(SelectedNamedFilter); }
|
||||
public async Task FilterBtn(string filterString) => await PerformFilter(new(filterString, null));
|
||||
public async Task FilterHelpBtn() => await new LibationAvalonia.Dialogs.SearchSyntaxDialog().ShowDialog(MainWindow);
|
||||
public void FilterHelpBtn() => MainWindow.ShowSearchSyntaxDialog();
|
||||
public void ToggleFirstFilterIsDefault() => FirstFilterIsDefault = !FirstFilterIsDefault;
|
||||
public async Task EditQuickFiltersAsync() => await new LibationAvalonia.Dialogs.EditQuickFilters().ShowDialog(MainWindow);
|
||||
public async Task PerformFilter(QuickFilters.NamedFilter? namedFilter)
|
||||
|
||||
@@ -223,5 +223,28 @@ namespace LibationAvalonia.Views
|
||||
}
|
||||
|
||||
private void setProgressVisible(bool visible) => ViewModel.DownloadProgress = visible ? 0 : null;
|
||||
|
||||
public SearchSyntaxDialog ShowSearchSyntaxDialog()
|
||||
{
|
||||
var dialog = new SearchSyntaxDialog();
|
||||
dialog.TagDoubleClicked += Dialog_TagDoubleClicked;
|
||||
dialog.Closed += Dialog_Closed;
|
||||
filterHelpBtn.IsEnabled = false;
|
||||
dialog.Show(this);
|
||||
return dialog;
|
||||
|
||||
void Dialog_Closed(object sender, EventArgs e)
|
||||
{
|
||||
dialog.TagDoubleClicked -= Dialog_TagDoubleClicked;
|
||||
filterHelpBtn.IsEnabled = true;
|
||||
}
|
||||
void Dialog_TagDoubleClicked(object sender, string tag)
|
||||
{
|
||||
var text = filterSearchTb.Text;
|
||||
filterSearchTb.Text = text.Insert(Math.Min(Math.Max(0, filterSearchTb.CaretIndex), text.Length), tag);
|
||||
filterSearchTb.CaretIndex += tag.Length;
|
||||
filterSearchTb.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,9 +203,10 @@ namespace LibationAvalonia
|
||||
|
||||
await displayControlAsync(MainForm.filterHelpBtn);
|
||||
|
||||
var filterHelp = new SearchSyntaxDialog();
|
||||
await filterHelp.ShowDialog(MainForm);
|
||||
|
||||
var searchDialog = MainForm.ShowSearchSyntaxDialog();
|
||||
var tcs = new TaskCompletionSource();
|
||||
searchDialog.Closed += (_, _) => tcs.SetResult();
|
||||
await tcs.Task;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user