diff options
author | sr55 <[email protected]> | 2019-09-14 13:54:34 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-09-14 13:54:52 +0100 |
commit | 3e00e3be2e421a5bf00f3b3b6761580ed4cd8ad1 (patch) | |
tree | 7d54a9a8ed327b624c0789b139e62d86904ae974 /win | |
parent | e2a9571535740938341ebe50d4fbf6747fd3e3c1 (diff) |
WinGui: When double clicking in the destination box, for the filename only, select the full filename, and not a single word of that filename. #2312
This is considered an experiment so may or may not stay.
Diffstat (limited to 'win')
-rw-r--r-- | win/CS/HandBrakeWPF/Behaviours/DoubleClickFileBehaviours.cs | 66 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/MainView.xaml | 5 |
3 files changed, 73 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/Behaviours/DoubleClickFileBehaviours.cs b/win/CS/HandBrakeWPF/Behaviours/DoubleClickFileBehaviours.cs new file mode 100644 index 000000000..d7358e117 --- /dev/null +++ b/win/CS/HandBrakeWPF/Behaviours/DoubleClickFileBehaviours.cs @@ -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); + } + } + } + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index f50fb8a24..d35fa87f6 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -110,6 +110,7 @@ </ApplicationDefinition>
<Compile Include="AttachedProperties\MenuItemExtensions.cs" />
<Compile Include="AttachedProperties\WindowHelper.cs" />
+ <Compile Include="Behaviours\DoubleClickFileBehaviours.cs" />
<Compile Include="Collections\SerializableDictionary.cs" />
<Compile Include="Commands\InputBindingTrigger.cs" />
<Compile Include="Commands\Menu\QueueCommandParams.cs" />
@@ -786,6 +787,7 @@ <ItemGroup>
<Resource Include="Views\Images\Dark\Disc.png" />
</ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<TargetFrameworkSDKToolsDirectory Condition=" '$(Platform)' == 'x64'">$(TargetFrameworkSDKToolsDirectory)$(Platform)\</TargetFrameworkSDKToolsDirectory>
diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index dfa4da0df..1e1cf40dd 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -11,6 +11,7 @@ xmlns:helpers="clr-namespace:HandBrakeWPF.Helpers"
xmlns:loc="clr-namespace:HandBrakeWPF.Services.Presets.Model"
xmlns:queue="clr-namespace:HandBrakeWPF.Converters.Queue"
+ xmlns:behaviours="clr-namespace:HandBrakeWPF.Behaviours"
AllowDrop="True"
FontSize="11"
cal:Message.Attach="[Event Loaded] = [Action Load]"
@@ -572,6 +573,10 @@ Margin="5,0,0,0" ToolTip="{x:Static Properties:ResourcesTooltips.MainView_Destination}"
Text="{Binding Destination,
UpdateSourceTrigger=PropertyChanged}">
+
+ <i:Interaction.Behaviors>
+ <behaviours:DoubleClickFileBehaviours/>
+ </i:Interaction.Behaviors>
<TextBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Open this Directory" cal:Message.Attach="[Event Click] = [Action OpenDestinationDirectory]" />
|