|
|
@@ -2,9 +2,13 @@ using Avalonia;
|
|
|
using Avalonia.Controls;
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
using Avalonia.Layout;
|
|
|
+using Avalonia.Media.Imaging;
|
|
|
using Avalonia.Threading;
|
|
|
+using Clowd.Clipboard;
|
|
|
+using PicView.Avalonia.ColorManagement;
|
|
|
using PicView.Avalonia.CustomControls;
|
|
|
using PicView.Avalonia.DragAndDrop;
|
|
|
+using PicView.Avalonia.Interfaces;
|
|
|
using PicView.Avalonia.StartUp;
|
|
|
using PicView.Avalonia.UI;
|
|
|
using PicView.Avalonia.ViewModels;
|
|
|
@@ -12,25 +16,94 @@ using PicView.Avalonia.Views.UC;
|
|
|
using PicView.Avalonia.Views.UC.Menus;
|
|
|
using PicView.Avalonia.Win32.WindowImpl;
|
|
|
using PicView.Avalonia.WindowBehavior;
|
|
|
+using PicView.Core.FileAssociations;
|
|
|
+using PicView.Core.FileSorting;
|
|
|
+using PicView.Core.Localization;
|
|
|
+using PicView.Core.ProcessHandling;
|
|
|
using PicView.Core.ViewModels;
|
|
|
+using PicView.Core.WindowsNT;
|
|
|
+using PicView.Core.WindowsNT.Copy;
|
|
|
+using PicView.Core.WindowsNT.FileAssociation;
|
|
|
+using PicView.Core.WindowsNT.FileHandling;
|
|
|
+using PicView.Core.WindowsNT.Taskbar;
|
|
|
+using PicView.Core.WindowsNT.Wallpaper;
|
|
|
using R3;
|
|
|
using R3.Avalonia;
|
|
|
|
|
|
namespace PicView.Avalonia.Win32.Views;
|
|
|
|
|
|
-public partial class WinMainWindow2 : Window
|
|
|
+public partial class WinMainWindow2 : Window, IPlatformSpecificService, IPlatformWindowService
|
|
|
{
|
|
|
private readonly AvaloniaRenderingFrameProvider _frameProvider;
|
|
|
private readonly CompositeDisposable _disposables = new();
|
|
|
+
|
|
|
+ private static WindowInitializer? _windowInitializer;
|
|
|
+ private TaskbarProgress? _taskbarProgress;
|
|
|
+ private MainViewModel? _vm;
|
|
|
|
|
|
public WinMainWindow2()
|
|
|
{
|
|
|
- InitializeComponent();
|
|
|
-
|
|
|
// initialize RenderingFrameProvider
|
|
|
_frameProvider = new AvaloniaRenderingFrameProvider(GetTopLevel(this)!);
|
|
|
UIHelper.SetFrameProvider(_frameProvider);
|
|
|
+
|
|
|
+ Initialization();
|
|
|
+ }
|
|
|
+
|
|
|
+ public WinMainWindow2(bool mainWindowAlreadyExists)
|
|
|
+ {
|
|
|
+ if (mainWindowAlreadyExists)
|
|
|
+ {
|
|
|
+ // initialize RenderingFrameProvider
|
|
|
+ _frameProvider = new AvaloniaRenderingFrameProvider(GetTopLevel(this)!);
|
|
|
+ UIHelper.SetFrameProvider(_frameProvider);
|
|
|
+
|
|
|
+ Initialization();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var settingsExists = LoadSettings();
|
|
|
+
|
|
|
+ // initialize RenderingFrameProvider
|
|
|
+ _frameProvider = new AvaloniaRenderingFrameProvider(GetTopLevel(this)!);
|
|
|
+ UIHelper.SetFrameProvider(_frameProvider);
|
|
|
+
|
|
|
+ Initialization();
|
|
|
+ WindowInitialization(settingsExists);
|
|
|
+ }
|
|
|
|
|
|
+ private void WindowInitialization(bool settingsExists)
|
|
|
+ {
|
|
|
+ TranslationManager.Init();
|
|
|
+
|
|
|
+ _vm = new MainViewModel(this, this)
|
|
|
+ {
|
|
|
+ MainWindow =
|
|
|
+ {
|
|
|
+ TopTitlebarViewModel = new TopTitlebarViewModel()
|
|
|
+ }
|
|
|
+ };
|
|
|
+ DataContext = _vm;
|
|
|
+
|
|
|
+ if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ThemeManager.DetermineTheme(Application.Current, settingsExists);
|
|
|
+ StartUpHelper2.StartWithArguments(_vm, settingsExists, desktop, this);
|
|
|
+ _windowInitializer = new WindowInitializer();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Initialization()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+
|
|
|
+ LoadedInitialization();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadedInitialization()
|
|
|
+ {
|
|
|
Loaded += delegate
|
|
|
{
|
|
|
if (DataContext is not MainViewModel vm)
|
|
|
@@ -121,7 +194,7 @@ public partial class WinMainWindow2 : Window
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- private void MainTabControlOnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
|
+ private void MainTabControlOnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
if (DataContext is not MainViewModel vm)
|
|
|
{
|
|
|
@@ -237,7 +310,7 @@ public partial class WinMainWindow2 : Window
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
{
|
|
|
// Create a new window with the detached tab
|
|
|
- var newWindow = new WinMainWindow2
|
|
|
+ var newWindow = new WinMainWindow2(true)
|
|
|
{
|
|
|
Position = new PixelPoint(e.ScreenPosition.X - 100, e.ScreenPosition.Y - 50),
|
|
|
Width = Width,
|
|
|
@@ -313,4 +386,203 @@ public partial class WinMainWindow2 : Window
|
|
|
_disposables.Dispose();
|
|
|
base.OnClosed(e);
|
|
|
}
|
|
|
+
|
|
|
+ #region Interface Implementations
|
|
|
+
|
|
|
+ public int CombinedTitleButtonsWidth
|
|
|
+ {
|
|
|
+ get => (int)(Settings.WindowProperties.Maximized && !Settings.WindowProperties.Fullscreen
|
|
|
+ ? OffScreenMargin.Left + OffScreenMargin.Right + field : field);
|
|
|
+ set;
|
|
|
+ } = 185;
|
|
|
+
|
|
|
+ public Task<bool> DeleteFile(string path, bool recycle) =>
|
|
|
+ Task.Run(() => WinFileHelper.DeleteFile(path, recycle));
|
|
|
+
|
|
|
+ public void SetTaskbarProgress(ulong progress, ulong maximum)
|
|
|
+ {
|
|
|
+ if (_taskbarProgress is null)
|
|
|
+ {
|
|
|
+ var handle = TryGetPlatformHandle()?.Handle;
|
|
|
+
|
|
|
+ // Ensure the handle is valid before proceeding
|
|
|
+ if (handle == IntPtr.Zero || handle is null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _taskbarProgress = new TaskbarProgress(handle.Value);
|
|
|
+ }
|
|
|
+
|
|
|
+ _taskbarProgress.SetProgress(progress, maximum);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void StopTaskbarProgress()
|
|
|
+ {
|
|
|
+ var handle = TryGetPlatformHandle()?.Handle;
|
|
|
+
|
|
|
+ // Ensure the handle is valid before proceeding
|
|
|
+ if (handle == IntPtr.Zero || handle is null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _taskbarProgress?.StopProgress();
|
|
|
+
|
|
|
+ _taskbarProgress = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetCursorPos(int x, int y)
|
|
|
+ {
|
|
|
+ NativeMethods.SetCursorPos(x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<FileInfo> GetFiles(FileInfo fileInfo)
|
|
|
+ {
|
|
|
+ return FileListRetriever.RetrieveFiles(fileInfo, CompareStrings);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int CompareStrings(string str1, string str2)
|
|
|
+ {
|
|
|
+ return NativeMethods.StrCmpLogicalW(str1, str2);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OpenWith(string path)
|
|
|
+ {
|
|
|
+ ProcessHelper.OpenWith(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void LocateOnDisk(string path)
|
|
|
+ {
|
|
|
+ var folder = Path.GetDirectoryName(path);
|
|
|
+ FileExplorer.OpenFolderAndSelectFile(folder, path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ShowFileProperties(string path)
|
|
|
+ {
|
|
|
+ FileExplorer.ShowFileProperties(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Print(string path)
|
|
|
+ {
|
|
|
+ if (Settings.UIProperties.ShowPrintPreview)
|
|
|
+ {
|
|
|
+ _windowInitializer?.ShowPrintPreviewWindow(_vm, path);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ProcessHelper.Print(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task SetAsWallpaper(string path, int wallpaperStyle)
|
|
|
+ {
|
|
|
+ await Task.Run(() =>
|
|
|
+ {
|
|
|
+ var style = (WallpaperHelper.WallpaperStyle)wallpaperStyle;
|
|
|
+ WallpaperHelper.SetDesktopWallpaper(path, style);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SetAsLockScreen(string path)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ // return LockscreenHelper.SetLockScreenImage(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool CopyFile(string path)
|
|
|
+ {
|
|
|
+ return Win32Clipboard.CopyFileToClipboard(false, path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool CutFile(string path)
|
|
|
+ {
|
|
|
+ return Win32Clipboard.CopyFileToClipboard(true, path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task CopyImageToClipboard(Bitmap bitmap)
|
|
|
+ {
|
|
|
+ await ClipboardAvalonia.SetImageAsync(bitmap).ConfigureAwait(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<Bitmap?> GetImageFromClipboard()
|
|
|
+ {
|
|
|
+ return await ClipboardAvalonia.GetImageAsync().ConfigureAwait(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<bool> ExtractWithLocalSoftwareAsync(string path, string tempDirectory)
|
|
|
+ {
|
|
|
+ return await ArchiveExtractionHelper.ExtractWithLocalSoftwareAsync(path, tempDirectory);
|
|
|
+ }
|
|
|
+
|
|
|
+ public string DefaultJsonKeyMap()
|
|
|
+ {
|
|
|
+ return WindowsKeybindings.DefaultKeybindings;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void InitiateFileAssociationService()
|
|
|
+ {
|
|
|
+ var iIFileAssociationService = new WindowsFileAssociationService();
|
|
|
+ FileAssociationManager.Initialize(iIFileAssociationService);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void DisableScreensaver()
|
|
|
+ {
|
|
|
+ NativeMethods.DisableScreensaver();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void EnableScreensaver()
|
|
|
+ {
|
|
|
+ NativeMethods.EnableScreensaver();
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Window interface implementations
|
|
|
+
|
|
|
+ public void ShowAboutWindow() =>
|
|
|
+ _windowInitializer?.ShowAboutWindow(_vm);
|
|
|
+
|
|
|
+ public async Task ShowImageInfoWindow() =>
|
|
|
+ await _windowInitializer?.ShowImageInfoWindow(_vm);
|
|
|
+
|
|
|
+ public async Task ShowKeybindingsWindow() =>
|
|
|
+ await _windowInitializer?.ShowKeybindingsWindow(_vm);
|
|
|
+
|
|
|
+ public async Task ShowSettingsWindow() =>
|
|
|
+ await _windowInitializer?.ShowSettingsWindow(_vm);
|
|
|
+
|
|
|
+ public void ShowSingleImageResizeWindow() =>
|
|
|
+ _windowInitializer?.ShowSingleImageResizeWindow(_vm);
|
|
|
+
|
|
|
+ public async Task ShowBatchResizeWindow() =>
|
|
|
+ await _windowInitializer?.ShowBatchResizeWindow(_vm);
|
|
|
+
|
|
|
+ public void ShowEffectsWindow() =>
|
|
|
+ _windowInitializer?.ShowEffectsWindow(_vm);
|
|
|
+
|
|
|
+ public void ShowConvertWindow() =>
|
|
|
+ _windowInitializer?.ShowConvertWindow(_vm);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public async Task Maximize(bool saveSetting = true) =>
|
|
|
+ await Win32Window.Maximize(this, _vm, saveSetting);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public async Task MaximizeRestore(bool saveSetting = true) =>
|
|
|
+ await Win32Window.ToggleMaximize(this, _vm, saveSetting);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public async Task Fullscreen(bool saveSetting = true) =>
|
|
|
+ await Win32Window.Fullscreen(this, _vm, saveSetting);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public async Task ToggleFullscreen(bool saveSetting = true) =>
|
|
|
+ await Win32Window.ToggleFullscreen(this, _vm, saveSetting);
|
|
|
+
|
|
|
+ /// <inheritdoc />
|
|
|
+ public async Task Restore() =>
|
|
|
+ await Win32Window.Restore(this, _vm);
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|