SettingsWindow.axaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Avalonia.Controls;
  2. using Avalonia.Input;
  3. using Avalonia.Media;
  4. using PicView.Avalonia.Input;
  5. using PicView.Avalonia.UI;
  6. using PicView.Core.FileHandling;
  7. using PicView.Core.Localization;
  8. using PicView.Core.MacOS.FileAssociation;
  9. using PicView.Core.Sizing;
  10. namespace PicView.Avalonia.MacOS.Views;
  11. public partial class SettingsWindow : Window
  12. {
  13. public SettingsWindow()
  14. {
  15. InitializeComponent();
  16. MinHeight = ScreenHelper.ScreenSize.WorkingAreaHeight switch
  17. {
  18. < 650 => 600,
  19. >= 650 => 700,
  20. _ => SizeDefaults.WindowMinSize
  21. };
  22. if (!Settings.Theme.Dark || Settings.Theme.GlassTheme)
  23. {
  24. TitleText.Background = Brushes.Transparent;
  25. XSettingsView.Background = Brushes.Transparent;
  26. }
  27. Loaded += delegate
  28. {
  29. MinWidth = MaxWidth = Bounds.Width;
  30. Height = 500;
  31. Title = TranslationManager.Translation.Settings + " - PicView";
  32. };
  33. KeyDown += (_, e) =>
  34. {
  35. if (e.Key is Key.Escape)
  36. {
  37. e.Handled = true;
  38. MainKeyboardShortcuts.IsEscKeyEnabled = false;
  39. Close();
  40. }
  41. };
  42. Closing += async delegate
  43. {
  44. Hide();
  45. await SaveSettingsAsync();
  46. };
  47. InitializeFileAssociationManager();
  48. }
  49. private void MoveWindow(object? sender, PointerPressedEventArgs e)
  50. {
  51. if (VisualRoot is null) { return; }
  52. var hostWindow = (Window)VisualRoot;
  53. hostWindow?.BeginMoveDrag(e);
  54. }
  55. private static void InitializeFileAssociationManager()
  56. {
  57. var iIFileAssociationService = new MacFileAssociationService();
  58. FileAssociationManager.Initialize(iIFileAssociationService);
  59. }
  60. }