|
| 1 | + |
| 2 | +using System.ComponentModel; |
| 3 | +using Avalonia; |
| 4 | +using Avalonia.Controls; |
| 5 | +using Avalonia.Layout; |
| 6 | +using Avalonia.Media; |
| 7 | +using SnapX.Avalonia.ViewModels; |
| 8 | +using SnapX.Avalonia.Views.Settings.Views.FileUploaders; |
| 9 | +using SnapX.Avalonia.Views.Settings.Views.ImageUploaders; |
| 10 | +using SnapX.Avalonia.Views.Settings.Views.TextUploaders; |
| 11 | +using SnapX.Core.Upload.File; |
| 12 | +using SnapX.Core.Upload.Img; |
| 13 | +using SnapX.Core.Upload.Text; |
| 14 | + |
| 15 | +namespace SnapX.Avalonia.Views.Settings.Views; |
| 16 | + |
| 17 | +public partial class BuiltInUploaderSettingsView : UserControl |
| 18 | +{ |
| 19 | + private readonly CoreUploaderVM _vm; |
| 20 | + public BuiltInUploaderSettingsView(CoreUploaderVM vm) |
| 21 | + { |
| 22 | + _vm = vm; |
| 23 | + DataContext = _vm; |
| 24 | + InitializeComponent(); |
| 25 | + _vm.PropertyChanged += OnVmPropertyChanged; |
| 26 | + |
| 27 | + } |
| 28 | + |
| 29 | + public BuiltInUploaderSettingsView() : this(new CoreUploaderVM()) |
| 30 | + { |
| 31 | + |
| 32 | + } |
| 33 | + private void OnVmPropertyChanged(object? sender, PropertyChangedEventArgs e) |
| 34 | + { |
| 35 | + if (e.PropertyName == nameof(CoreUploaderVM.SelectedUploaderInstance)) |
| 36 | + { |
| 37 | + UpdateSettingsView(_vm.SelectedUploaderInstance); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + private void UpdateSettingsView(object? instance) |
| 42 | + { |
| 43 | + if (instance == null) |
| 44 | + { |
| 45 | + SettingsContainer.Child = new StackPanel |
| 46 | + { |
| 47 | + Spacing = 10, |
| 48 | + VerticalAlignment = VerticalAlignment.Center, |
| 49 | + HorizontalAlignment = HorizontalAlignment.Center, |
| 50 | + Children = |
| 51 | + { |
| 52 | + new TextBlock { |
| 53 | + Text = "🖱️", |
| 54 | + FontSize = 44, |
| 55 | + HorizontalAlignment = HorizontalAlignment.Center, |
| 56 | + Margin = new Thickness(0, 0, 0, 10) |
| 57 | + }, |
| 58 | + new TextBlock { |
| 59 | + Text = "Ready to Configure", |
| 60 | + FontSize = 18, |
| 61 | + FontWeight = FontWeight.Bold, |
| 62 | + HorizontalAlignment = HorizontalAlignment.Center |
| 63 | + }, |
| 64 | + new TextBlock { |
| 65 | + Text = "Select an uploader from the list to get started.", |
| 66 | + Foreground = Brushes.Gray, |
| 67 | + TextAlignment = TextAlignment.Center, |
| 68 | + HorizontalAlignment = HorizontalAlignment.Center |
| 69 | + } |
| 70 | + } |
| 71 | + }; |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + Control? newView = instance switch |
| 76 | + { |
| 77 | + Imgur => new ImgurUploaderSettingsView { DataContext = instance }, |
| 78 | + ImageShackUploader => new ImageShackUploaderSettingsView { DataContext = instance }, |
| 79 | + FlickrUploader => new FlickrUploaderSettingsView { DataContext = instance }, |
| 80 | + GooglePhotos => new PicasaUploaderSettingsView { DataContext = instance }, |
| 81 | + Pastebin => new PastebinUploaderSettingsView() { DataContext = instance }, |
| 82 | + Paste_ee => new PasteeUploaderSettingsView() { DataContext = instance }, |
| 83 | + GitHubGist => new GithubGistUploaderSettingsView() { DataContext = instance }, |
| 84 | + Hastebin => new HastebinUploaderSettingsView() { DataContext = instance }, |
| 85 | + OneTimeSecret => new OneTimeSecretUploadSettingsView() { DataContext = instance }, |
| 86 | + FTP => new FTPSettingsView() { DataContext = instance }, |
| 87 | + // Add other mappings here: |
| 88 | + // AmazonS3 => new S3SettingsView { DataContext = instance }, |
| 89 | + _ => new StackPanel |
| 90 | + { |
| 91 | + Spacing = 15, |
| 92 | + VerticalAlignment = VerticalAlignment.Center, |
| 93 | + HorizontalAlignment = HorizontalAlignment.Center, |
| 94 | + Children = |
| 95 | + { |
| 96 | + new TextBlock { |
| 97 | + Text = "🛠️", |
| 98 | + FontSize = 48, |
| 99 | + HorizontalAlignment = HorizontalAlignment.Center |
| 100 | + }, |
| 101 | + new SelectableTextBlock { |
| 102 | + Text = $"{instance.GetType().Name} Settings", |
| 103 | + FontSize = 20, |
| 104 | + FontWeight = FontWeight.Bold, |
| 105 | + HorizontalAlignment = HorizontalAlignment.Center |
| 106 | + }, |
| 107 | + new TextBlock { |
| 108 | + Text = "This uploader doesn't have a configuration view yet.", |
| 109 | + Foreground = Brushes.Gray, |
| 110 | + HorizontalAlignment = HorizontalAlignment.Center |
| 111 | + }, |
| 112 | + new Border { |
| 113 | + Background = Brushes.Transparent, |
| 114 | + BorderBrush = Brushes.DodgerBlue, |
| 115 | + BorderThickness = new Thickness(1), |
| 116 | + CornerRadius = new CornerRadius(4), |
| 117 | + Padding = new Thickness(10, 5), |
| 118 | + Margin = new Thickness(0, 10, 0, 0), |
| 119 | + Child = new TextBlock { |
| 120 | + Text = "Pull Requests Welcome!", |
| 121 | + Foreground = Brushes.DodgerBlue, |
| 122 | + HorizontalAlignment = HorizontalAlignment.Center, |
| 123 | + FontWeight = FontWeight.SemiBold |
| 124 | + } |
| 125 | + }, |
| 126 | + new TextBlock { |
| 127 | + Text = "Adding a view is simple: create a UserControl and link it in the BuiltInUploaderSettingsView.", |
| 128 | + FontSize = 12, |
| 129 | + FontStyle = FontStyle.Italic, |
| 130 | + Foreground = Brushes.DimGray, |
| 131 | + TextWrapping = TextWrapping.Wrap, |
| 132 | + MaxWidth = 300, |
| 133 | + TextAlignment = TextAlignment.Center |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + }; |
| 138 | + |
| 139 | + SettingsContainer.Child = newView; |
| 140 | + } |
| 141 | +} |
| 142 | + |
0 commit comments