Explorar o código

Added file drag and drop support

CPKreuz %!s(int64=4) %!d(string=hai) anos
pai
achega
ebb1f8747f

+ 17 - 17
PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -162,23 +162,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             Open((object)null);
         }
 
-        private void Owner_OnStartupEvent(object sender, System.EventArgs e)
-        {
-            var lastArg = Environment.GetCommandLineArgs().Last();
-            if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
-            {
-                Open(lastArg);
-            }
-            else
-            {
-                if (IPreferences.Current.GetPreference("ShowStartupWindow", true))
-                {
-                    OpenHelloTherePopup();
-                }
-            }
-        }
-
-        private void Open(string path)
+        public void Open(string path)
         {
             try
             {
@@ -203,6 +187,22 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
         }
 
+        private void Owner_OnStartupEvent(object sender, System.EventArgs e)
+        {
+            var lastArg = Environment.GetCommandLineArgs().Last();
+            if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
+            {
+                Open(lastArg);
+            }
+            else
+            {
+                if (IPreferences.Current.GetPreference("ShowStartupWindow", true))
+                {
+                    OpenHelloTherePopup();
+                }
+            }
+        }
+
         private void Open(object property)
         {
             OpenFileDialog dialog = new OpenFileDialog

+ 2 - 1
PixiEditor/Views/MainWindow.xaml

@@ -15,7 +15,8 @@
         xmlns:avalonDockTheme="clr-namespace:PixiEditor.Styles.AvalonDock" d:DataContext="{d:DesignInstance Type=vm:ViewModelMain}" xmlns:dataHolders="clr-namespace:PixiEditor.Models.DataHolders"
         mc:Ignorable="d" WindowStyle="None" Initialized="MainWindow_Initialized"
         Title="PixiEditor" Name="mainWindow" Height="1000" Width="1600" Background="{StaticResource MainColor}"
-        WindowStartupLocation="CenterScreen" WindowState="Maximized">
+        WindowStartupLocation="CenterScreen" WindowState="Maximized"
+        AllowDrop="True" Drop="MainWindow_Drop">
     <WindowChrome.WindowChrome>
         <WindowChrome CaptionHeight="32"
                       ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />

+ 10 - 0
PixiEditor/Views/MainWindow.xaml.cs

@@ -146,5 +146,15 @@ namespace PixiEditor
         {
             AppDomain.CurrentDomain.UnhandledException += (sender, e) => Helpers.CrashHelper.SaveCrashInfo((Exception)e.ExceptionObject);
         }
+
+        private void MainWindow_Drop(object sender, DragEventArgs e)
+        {
+            if (e.Data.GetDataPresent(DataFormats.FileDrop))
+            {
+                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
+
+                DataContext.FileSubViewModel.Open(files[0]);
+            }
+        }
     }
 }