|
@@ -1,13 +1,67 @@
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls;
|
|
|
|
+using Avalonia.Input;
|
|
|
|
+using PixiEditor.AvaloniaUI.Helpers;
|
|
using PixiEditor.AvaloniaUI.Helpers.Behaviours;
|
|
using PixiEditor.AvaloniaUI.Helpers.Behaviours;
|
|
|
|
+using PixiEditor.AvaloniaUI.Helpers.Extensions;
|
|
|
|
+using PixiEditor.AvaloniaUI.Models.Controllers;
|
|
|
|
+using PixiEditor.AvaloniaUI.Models.IO;
|
|
|
|
+using PixiEditor.AvaloniaUI.ViewModels;
|
|
|
|
|
|
namespace PixiEditor.AvaloniaUI.Views;
|
|
namespace PixiEditor.AvaloniaUI.Views;
|
|
|
|
|
|
public partial class MainView : UserControl
|
|
public partial class MainView : UserControl
|
|
{
|
|
{
|
|
|
|
+ private ViewModelMain Context => (ViewModelMain)DataContext;
|
|
public MainView()
|
|
public MainView()
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
TextBoxFocusBehavior.FallbackFocusElement = FocusableGrid;
|
|
TextBoxFocusBehavior.FallbackFocusElement = FocusableGrid;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void MainView_Drop(object sender, DragEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Context.ActionDisplays[nameof(MainView_Drop)] = null;
|
|
|
|
+
|
|
|
|
+ var fileDropList = e.Data.GetFileDropList();
|
|
|
|
+ if (fileDropList == null || fileDropList.Length == 0)
|
|
|
|
+ {
|
|
|
|
+ if (!ColorHelper.ParseAnyFormat(e.Data, out var color))
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ e.DragEffects = DragDropEffects.Copy;
|
|
|
|
+ Context.ColorsSubViewModel.PrimaryColor = color.Value;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (fileDropList is { Length: > 0 } && Importer.IsSupportedFile(fileDropList[0].Path.LocalPath))
|
|
|
|
+ {
|
|
|
|
+ Context.FileSubViewModel.OpenFromPath(fileDropList[0].Path.LocalPath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void MainView_DragEnter(object sender, DragEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (!ClipboardController.IsImage(e.Data))
|
|
|
|
+ {
|
|
|
|
+ if (ColorHelper.ParseAnyFormat(e.Data, out _))
|
|
|
|
+ {
|
|
|
|
+ Context.ActionDisplays[nameof(MainView_Drop)] = "PASTE_AS_PRIMARY_COLOR";
|
|
|
|
+ e.DragEffects = DragDropEffects.Copy;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ e.DragEffects = DragDropEffects.None;
|
|
|
|
+ e.Handled = true;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Context.ActionDisplays[nameof(MainView_Drop)] = "IMPORT_AS_NEW_FILE";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void MainView_DragLeave(object sender, DragEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Context.ActionDisplays[nameof(MainView_Drop)] = null;
|
|
|
|
+ }
|
|
}
|
|
}
|