| 1 | using Avalonia; |
| 2 | using Avalonia.Controls; |
| 3 | using Avalonia.Layout; |
| 4 | |
| 5 | namespace CascadeIDE.Views; |
| 6 | |
| 7 | internal static class FeatureDocsPickDialog |
| 8 | { |
| 9 | public static async Task<string?> ShowAsync(Window? owner, string title, IReadOnlyList<string> docPaths) |
| 10 | { |
| 11 | if (owner is null || docPaths.Count == 0) |
| 12 | return null; |
| 13 | |
| 14 | var dialog = new Window |
| 15 | { |
| 16 | Title = title, |
| 17 | Width = 560, |
| 18 | Height = 380, |
| 19 | CanResize = true, |
| 20 | WindowStartupLocation = WindowStartupLocation.CenterOwner, |
| 21 | }; |
| 22 | |
| 23 | var list = new ListBox |
| 24 | { |
| 25 | ItemsSource = docPaths, |
| 26 | SelectionMode = SelectionMode.Single, |
| 27 | MinHeight = 220, |
| 28 | }; |
| 29 | |
| 30 | string? result = null; |
| 31 | |
| 32 | var open = new Button { Content = "Открыть", MinWidth = 110, IsDefault = true }; |
| 33 | var cancel = new Button { Content = "Отмена", MinWidth = 110, IsCancel = true }; |
| 34 | |
| 35 | void CloseWithSelection() |
| 36 | { |
| 37 | if (list.SelectedItem is string s && !string.IsNullOrWhiteSpace(s)) |
| 38 | result = s; |
| 39 | dialog.Close(); |
| 40 | } |
| 41 | |
| 42 | open.Click += (_, _) => CloseWithSelection(); |
| 43 | cancel.Click += (_, _) => dialog.Close(); |
| 44 | list.DoubleTapped += (_, _) => CloseWithSelection(); |
| 45 | |
| 46 | dialog.Content = new StackPanel |
| 47 | { |
| 48 | Margin = new Thickness(16), |
| 49 | Spacing = 12, |
| 50 | Children = |
| 51 | { |
| 52 | new TextBlock { Text = "Документация фичи:", TextWrapping = Avalonia.Media.TextWrapping.Wrap }, |
| 53 | list, |
| 54 | new StackPanel |
| 55 | { |
| 56 | Orientation = Orientation.Horizontal, |
| 57 | HorizontalAlignment = HorizontalAlignment.Right, |
| 58 | Spacing = 10, |
| 59 | Children = { open, cancel }, |
| 60 | } |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | await dialog.ShowDialog(owner); |
| 65 | return result; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |