123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Controls.Primitives;
- using Avalonia.Media;
- using PicView.Avalonia.Functions;
- using PicView.Avalonia.UI;
- using PicView.Avalonia.WindowBehavior;
- using R3;
- namespace PicView.Avalonia.ViewModels;
- public class MainWindowViewModel : IDisposable
- {
- public BindableReactiveProperty<Brush?> ImageBackground { get; } = new();
- public BindableReactiveProperty<Brush?> ConstrainedImageBackground { get; } = new();
- public BindableReactiveProperty<Thickness> RightControlOffSetMargin { get; } = new();
- public BindableReactiveProperty<Thickness> TopScreenMargin { get; } = new();
- public BindableReactiveProperty<Thickness> BottomScreenMargin { get; } = new();
- public BindableReactiveProperty<CornerRadius> BottomCornerRadius { get; } = new();
- public BindableReactiveProperty<int> BackgroundChoice { get; } = new();
- public BindableReactiveProperty<double> WindowMinSize { get; } = new();
- public BindableReactiveProperty<double> TitlebarHeight { get; } = new();
- public BindableReactiveProperty<double> BottombarHeight { get; } = new();
-
- public BindableReactiveProperty<SizeToContent> SizeToContent { get; } = new();
-
- public BindableReactiveProperty<ScrollBarVisibility> ToggleScrollBarVisibility { get; } = new();
- public BindableReactiveProperty<bool> CanResize { get; } = new();
- public BindableReactiveProperty<UserControl?> CurrentView { get; } = new();
- public BindableReactiveProperty<bool> IsFileMenuVisible { get; } = new();
- public BindableReactiveProperty<bool> IsImageMenuVisible { get; } = new();
- public BindableReactiveProperty<bool> IsSettingsMenuVisible { get; } = new();
- public BindableReactiveProperty<bool> IsToolsMenuVisible { get; } = new();
-
- public BindableReactiveProperty<double> TitleMaxWidth { get; } = new();
-
- public BindableReactiveProperty<bool> IsFullscreen { get; } = new();
- public BindableReactiveProperty<bool> IsMaximized { get; } = new();
- public BindableReactiveProperty<bool> ShouldRestore { get; } = new();
- public BindableReactiveProperty<bool> ShouldMaximizeBeShown { get; } = new(true);
- public BindableReactiveProperty<bool> IsLoadingIndicatorShown { get; } = new();
- public BindableReactiveProperty<bool> IsUIShown { get; } = new();
- public BindableReactiveProperty<bool> IsTopToolbarShown { get; } = new();
- public BindableReactiveProperty<bool> IsBottomToolbarShown { get; } = new();
- public BindableReactiveProperty<bool> IsEditableTitlebarOpen { get; } = new();
-
- public BindableReactiveProperty<IImage?> ChangeCtrlZoomImage { get; } = new();
- public void LayoutButtonSubscription()
- {
- Observable.EveryValueChanged(this, x => x.IsMaximized.CurrentValue, UIHelper.GetFrameProvider)
- .Subscribe(_ => SetButtonValues());
- Observable.EveryValueChanged(this, x => x.IsFullscreen.CurrentValue, UIHelper.GetFrameProvider)
- .Subscribe(_ => SetButtonValues());
- }
-
- #region Menus
-
- public ReactiveCommand CloseMenuCommand { get; } = new(CloseMenus);
-
- public ReactiveCommand ToggleFileMenuCommand { get; } = new(ToggleFileMenu);
- public ReactiveCommand ToggleImageMenuCommand { get; } = new(ToggleImageMenu);
- public ReactiveCommand ToggleSettingsMenuCommand { get; } = new(ToggleSettingsMenu);
- public ReactiveCommand ToggleToolsMenuCommand { get; } = new(ToggleToolsMenu);
- private static void CloseMenus(Unit unit) => MenuManager.CloseMenus(UIHelper.GetMainView.DataContext as MainViewModel);
-
- private static void ToggleFileMenu(Unit unit) => MenuManager.ToggleFileMenu(UIHelper.GetMainView.DataContext as MainViewModel);
- private static void ToggleImageMenu(Unit unit) => MenuManager.ToggleImageMenu(UIHelper.GetMainView.DataContext as MainViewModel);
- private static void ToggleSettingsMenu(Unit unit) => MenuManager.ToggleSettingsMenu(UIHelper.GetMainView.DataContext as MainViewModel);
- private static void ToggleToolsMenu(Unit unit) => MenuManager.ToggleToolsMenu(UIHelper.GetMainView.DataContext as MainViewModel);
- #endregion Menus
-
- public ReactiveCommand ExitCommand { get; } = new(async (_, _) =>
- {
- await FunctionsMapper.Close();
- });
-
- public ReactiveCommand MaximizeCommand { get; } = new(async (_, _) =>
- {
- await FunctionsMapper.Maximize();
- });
-
- public ReactiveCommand MinimizeCommand { get; } = new(async (_, _) =>
- {
- await WindowFunctions.Minimize();
- });
-
- public ReactiveCommand RestoreCommand { get; } = new(async (_, _) =>
- {
- await FunctionsMapper.Restore();
- });
-
- public ReactiveCommand ToggleFullscreenCommand { get; } = new(async (_, _) =>
- {
- await FunctionsMapper.ToggleFullscreen();
- });
-
- private void SetButtonValues()
- {
- ShouldRestore.Value = IsFullscreen.CurrentValue || IsMaximized.CurrentValue;
- ShouldMaximizeBeShown.Value = !IsFullscreen.CurrentValue && !IsMaximized.CurrentValue;
- }
- public void Dispose()
- {
- Disposable.Dispose(ImageBackground,
- ConstrainedImageBackground,
- RightControlOffSetMargin,
- TopScreenMargin,
- BottomScreenMargin,
- BottomCornerRadius,
- BackgroundChoice,
- WindowMinSize,
- TitlebarHeight,
- BottombarHeight,
- SizeToContent,
- CanResize,
- CurrentView,
- TitleMaxWidth,
- IsLoadingIndicatorShown,
- IsUIShown,
- IsTopToolbarShown,
- IsBottomToolbarShown,
- IsEditableTitlebarOpen);
- }
- }
|