Просмотр исходного кода

Add dragover and drop event for folders #37

Ruben 4 лет назад
Родитель
Сommit
25fa6cbb24

+ 5 - 1
PicView/Views/UserControls/Misc/ThumbnailOutputUC.xaml.cs

@@ -1,4 +1,6 @@
-using System.Windows.Controls;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
 
 
 namespace PicView.Views.UserControls
 namespace PicView.Views.UserControls
 {
 {
@@ -20,6 +22,8 @@ namespace PicView.Views.UserControls
                     OutPutStringBox.Text = newFolder;
                     OutPutStringBox.Text = newFolder;
                 }
                 }
             };
             };
+
+            Windows.ResizeWindow.SetTextboxDragEvent(OutPutStringBox);
          }
          }
     }
     }
 }
 }

+ 5 - 1
PicView/Views/Windows/ResizeWindow.xaml

@@ -6,6 +6,7 @@
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:uc="clr-namespace:PicView.Views.UserControls"
     xmlns:uc="clr-namespace:PicView.Views.UserControls"
     Width="500"
     Width="500"
+    AllowDrop="False"
     BorderBrush="{DynamicResource WindowBorderColorBrush}"
     BorderBrush="{DynamicResource WindowBorderColorBrush}"
     BorderThickness="1"
     BorderThickness="1"
     FontFamily="/PicView;component/Themes/Resources/fonts/#Roboto"
     FontFamily="/PicView;component/Themes/Resources/fonts/#Roboto"
@@ -77,7 +78,10 @@
                 <uc:FolderButton x:Name="SourceFolderButton" />
                 <uc:FolderButton x:Name="SourceFolderButton" />
             </StackPanel>
             </StackPanel>
 
 
-            <StackPanel Margin="0,0,0,10" Orientation="Horizontal">
+            <StackPanel
+                Margin="0,0,0,10"
+                AllowDrop="True"
+                Orientation="Horizontal">
                 <TextBlock Text="Output folder" />
                 <TextBlock Text="Output folder" />
                 <TextBox
                 <TextBox
                     x:Name="OutputFolderInput"
                     x:Name="OutputFolderInput"

+ 47 - 0
PicView/Views/Windows/ResizeWindow.xaml.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
 using System.Windows.Input;
 using System.Windows.Input;
+using System.Windows.Media;
 using static PicView.UILogic.Sizing.WindowSizing;
 using static PicView.UILogic.Sizing.WindowSizing;
 
 
 namespace PicView.Views.Windows
 namespace PicView.Views.Windows
@@ -32,6 +33,9 @@ namespace PicView.Views.Windows
                     OutputFolderInput.Text = SourceFolderInput.Text + @"\Processed Pictures";
                     OutputFolderInput.Text = SourceFolderInput.Text + @"\Processed Pictures";
                 }
                 }
 
 
+                SetTextboxDragEvent(SourceFolderInput);
+                SetTextboxDragEvent(OutputFolderInput);
+
                 SourceFolderButton.FileMenuButton.Click += (_, _) =>
                 SourceFolderButton.FileMenuButton.Click += (_, _) =>
                 {
                 {
                     var newFolder = FileHandling.Open_Save.SelectAndReturnFolder();
                     var newFolder = FileHandling.Open_Save.SelectAndReturnFolder();
@@ -40,6 +44,7 @@ namespace PicView.Views.Windows
                         SourceFolderInput.Text = newFolder;
                         SourceFolderInput.Text = newFolder;
                     }
                     }
                 };
                 };
+
                 OutputFolderButton.FileMenuButton.Click += (_, _) =>
                 OutputFolderButton.FileMenuButton.Click += (_, _) =>
                 {
                 {
                     var newFolder = FileHandling.Open_Save.SelectAndReturnFolder();
                     var newFolder = FileHandling.Open_Save.SelectAndReturnFolder();
@@ -120,6 +125,48 @@ namespace PicView.Views.Windows
             };
             };
         }
         }
 
 
+        internal static void SetTextboxDragEvent(TextBox textBox)
+        {
+            textBox.PreviewDragOver += (_, e) =>
+            {
+                e.Handled = true; // Needs this to allow drag to work
+
+                textBox.Background = (SolidColorBrush)Application.Current.Resources["BackgroundHoverHighlightBrush"];
+            };
+
+            textBox.PreviewDragLeave += (_, _) =>
+            {
+                textBox.Background = (SolidColorBrush)Application.Current.Resources["BackgroundColorBrushAlt"];
+            };
+
+            textBox.Drop += (_, e) =>
+            {
+                if (e.Data.GetData(DataFormats.FileDrop, true) is not string[] files)
+                {
+                    var data = e.Data.GetData(DataFormats.Text);
+
+                    if (data != null) // Check if from web)
+                    {
+                        var text = data.ToString();
+                        if (Directory.Exists(text))
+                        {
+                            textBox.Text = text;
+                        }
+                    }
+                    else
+                    {
+                        return;
+                    }
+                }
+                else if (Directory.Exists(files[0]))
+                {
+                    textBox.Text = files[0];
+                }
+
+                textBox.Background = (SolidColorBrush)Application.Current.Resources["BackgroundColorBrushAlt"];
+            };
+        }
+
         protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
         protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
         {
         {
             if (sizeInfo == null || !sizeInfo.WidthChanged && !sizeInfo.HeightChanged)
             if (sizeInfo == null || !sizeInfo.WidthChanged && !sizeInfo.HeightChanged)