]> granicus.if.org Git - handbrake/commitdiff
WinGui: When double clicking in the destination box, for the filename only, select...
authorsr55 <sr55.hb@outlook.com>
Sat, 14 Sep 2019 12:54:34 +0000 (13:54 +0100)
committersr55 <sr55.hb@outlook.com>
Sat, 14 Sep 2019 12:54:52 +0000 (13:54 +0100)
This is considered an experiment so may or may not stay.

win/CS/HandBrakeWPF/Behaviours/DoubleClickFileBehaviours.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Views/MainView.xaml

diff --git a/win/CS/HandBrakeWPF/Behaviours/DoubleClickFileBehaviours.cs b/win/CS/HandBrakeWPF/Behaviours/DoubleClickFileBehaviours.cs
new file mode 100644 (file)
index 0000000..d7358e1
--- /dev/null
@@ -0,0 +1,66 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="DoubleClickFileBehaviours.cs" company="HandBrake Project (http://handbrake.fr)">
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+//   Improve the behaviour of textboxes including file paths. - Select the full filename.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Behaviours
+{
+    using System;
+    using System.Diagnostics;
+    using System.IO;
+    using System.Net;
+    using System.Windows;
+    using System.Windows.Controls;
+    using System.Windows.Forms.VisualStyles;
+    using System.Windows.Interactivity;
+
+    public class DoubleClickFileBehaviours : Behavior<TextBox>
+    {
+        protected override void OnAttached()
+        {
+            AssociatedObject.MouseDoubleClick += AssociatedObjectMouseDoubleClick;
+            base.OnAttached();
+        }
+
+        protected override void OnDetaching()
+        {
+            AssociatedObject.MouseDoubleClick -= AssociatedObjectMouseDoubleClick;
+            base.OnDetaching();
+        }
+
+        private void AssociatedObjectMouseDoubleClick(object sender, RoutedEventArgs routedEventArgs)
+        {
+            TextBox tb = sender as TextBox;
+
+            if (tb != null)
+            {
+                string filePath = tb.Text;
+                if (!string.IsNullOrEmpty(filePath))
+                {
+                    try
+                    {
+                        string filename = Path.GetFileNameWithoutExtension(filePath);
+                        string extension = Path.GetExtension(filePath);
+
+                        long index = tb.CaretIndex;
+                        int filenameIndex = filePath.IndexOf(filename, StringComparison.Ordinal);
+                        int extensionIndex = filePath.IndexOf(extension, StringComparison.Ordinal);
+
+                        if (index >= filenameIndex && index < extensionIndex)
+                        {
+                            tb.Select(filenameIndex, filename.Length);
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        Debug.WriteLine(e);
+                    }
+                }
+            }
+        }
+    }
+}
index f50fb8a240e3ebf78dcd9395f718bebc7c94a011..d35fa87f6610e5b5a8e9edfc78f9c651dd9468e0 100644 (file)
     </ApplicationDefinition>\r
     <Compile Include="AttachedProperties\MenuItemExtensions.cs" />\r
     <Compile Include="AttachedProperties\WindowHelper.cs" />\r
+    <Compile Include="Behaviours\DoubleClickFileBehaviours.cs" />\r
     <Compile Include="Collections\SerializableDictionary.cs" />\r
     <Compile Include="Commands\InputBindingTrigger.cs" />\r
     <Compile Include="Commands\Menu\QueueCommandParams.cs" />\r
   <ItemGroup>\r
     <Resource Include="Views\Images\Dark\Disc.png" />\r
   </ItemGroup>\r
+  <ItemGroup />\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
   <PropertyGroup>\r
     <TargetFrameworkSDKToolsDirectory Condition=" '$(Platform)' == 'x64'">$(TargetFrameworkSDKToolsDirectory)$(Platform)\</TargetFrameworkSDKToolsDirectory>\r
index dfa4da0df7131762177cb4bb2ab0b6cd7bf64036..1e1cf40ddbfd59f8781a2dccddbcc2a8818dc8b7 100644 (file)
@@ -11,6 +11,7 @@
              xmlns:helpers="clr-namespace:HandBrakeWPF.Helpers"\r
              xmlns:loc="clr-namespace:HandBrakeWPF.Services.Presets.Model"\r
              xmlns:queue="clr-namespace:HandBrakeWPF.Converters.Queue"\r
+             xmlns:behaviours="clr-namespace:HandBrakeWPF.Behaviours"\r
              AllowDrop="True"\r
              FontSize="11"\r
              cal:Message.Attach="[Event Loaded] = [Action Load]"\r
                              Margin="5,0,0,0" ToolTip="{x:Static Properties:ResourcesTooltips.MainView_Destination}"\r
                              Text="{Binding Destination,\r
                                             UpdateSourceTrigger=PropertyChanged}">\r
+\r
+                        <i:Interaction.Behaviors>\r
+                            <behaviours:DoubleClickFileBehaviours/>\r
+                        </i:Interaction.Behaviors>\r
                         <TextBox.ContextMenu>\r
                             <ContextMenu>\r
                                 <MenuItem Header="Open this Directory" cal:Message.Attach="[Event Click] = [Action OpenDestinationDirectory]" />\r