--- /dev/null
+// --------------------------------------------------------------------------------------------------------------------
+// <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);
+ }
+ }
+ }
+ }
+ }
+}
</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
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