Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow clicking filename/FFmpeg parameters to insert into templates #1198

Merged
merged 14 commits into from
Aug 28, 2024
Merged
31 changes: 31 additions & 0 deletions TwitchDownloaderWPF/Extensions/TextBoxExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Diagnostics.CodeAnalysis;
using System.Windows.Controls;

namespace TwitchDownloaderWPF.Extensions
{
public static class TextBoxExtensions
{
public static bool TryInsertAtCaret([AllowNull] this TextBox textBox, string textToInsert)
{
if (textBox is null || string.IsNullOrEmpty(textToInsert))
{
return false;
}

var caretPos = textBox.CaretIndex;
if (caretPos < 0)
{
return false;
}

if (textBox.IsSelectionActive)
{
textBox.Text = textBox.Text.Remove(caretPos, textBox.SelectionLength);
}

textBox.Text = textBox.Text.Insert(caretPos, textToInsert);
textBox.CaretIndex = caretPos + textToInsert.Length;
return true;
}
}
}
19 changes: 17 additions & 2 deletions TwitchDownloaderWPF/PageChatRender.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,23 @@
<TextBlock Text="{lex:Loc FfmpegOutputArguments}" Margin="0,6,0,0" Foreground="{DynamicResource AppText}"></TextBlock>
<TextBox x:Name="textFfmpegOutput" LostFocus="textFfmpegOutput_LostFocus" Background="{DynamicResource AppElementBackground}" BorderBrush="{DynamicResource AppElementBorder}" Foreground="{DynamicResource AppText}"></TextBox>
<Button HorizontalAlignment="Left" Content="{lex:Loc FfmpegReset}" Margin="0,6,0,0" Click="btnResetFfmpeg_Click" Background="{DynamicResource ActionButtonBackground}" Foreground="{DynamicResource ActionButtonText}" BorderBrush="{DynamicResource ActionButtonBorder}"></Button>
<TextBlock Margin="0,8,0,0" Foreground="{DynamicResource AppText}">
<Run Text="{lex:Loc AvailableParameters}" /> <Run Text="{lex:Loc FfmpegParameters}" FontWeight="Bold" />
<TextBlock Margin="0,8,0,0" Foreground="{DynamicResource AppText}" TextWrapping="Wrap">
<Run Text="{lex:Loc AvailableParameters}" />
<Run MouseDown="FfmpegParameter_MouseDown" Cursor="Hand" FontWeight="Bold">
{fps}
</Run>
<Run MouseDown="FfmpegParameter_MouseDown" Cursor="Hand" FontWeight="Bold">
{height}
</Run>
<Run MouseDown="FfmpegParameter_MouseDown" Cursor="Hand" FontWeight="Bold">
{width}
</Run>
<Run MouseDown="FfmpegParameter_MouseDown" Cursor="Hand" FontWeight="Bold">
{max_int}
</Run>
<Run MouseDown="FfmpegParameter_MouseDown" Cursor="Hand" FontWeight="Bold">
{save_path}
</Run>
</TextBlock>
<TextBlock>
<Hyperlink NavigateUri="https://ffmpeg.org/ffmpeg.html" RequestNavigate="Hyperlink_RequestNavigate" Foreground="{DynamicResource AppHyperlink}">
Expand Down
40 changes: 40 additions & 0 deletions TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using TwitchDownloaderCore;
using TwitchDownloaderCore.Chat;
using TwitchDownloaderCore.Options;
using TwitchDownloaderCore.TwitchObjects;
using TwitchDownloaderWPF.Extensions;
using TwitchDownloaderWPF.Models;
using TwitchDownloaderWPF.Properties;
using TwitchDownloaderWPF.Utils;
using WpfAnimatedGif;
using MessageBox = System.Windows.MessageBox;
using TextBox = System.Windows.Controls.TextBox;

namespace TwitchDownloaderWPF
{
Expand Down Expand Up @@ -738,9 +743,44 @@ private void MenuItemPartialRender_Click(object sender, RoutedEventArgs e)

private void TextJson_TextChanged(object sender, TextChangedEventArgs e)
{
if (!IsInitialized)
return;

FileNames = textJson.Text.Split("&&", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
UpdateActionButtons(false);
}

private void FfmpegParameter_MouseDown(object sender, MouseButtonEventArgs e)
{
if (!IsInitialized || sender is not Run { Text: var parameter })
return;

if (e.ChangedButton is not MouseButton.Left and not MouseButton.Middle)
return;

var focusedElement = Keyboard.FocusedElement;
var textBox = GetFfmpegTemplateTextBox(focusedElement);

if (textBox is null)
return;

if (textBox.TryInsertAtCaret(parameter))
{
e.Handled = true;
}
}

[return: MaybeNull]
private TextBox GetFfmpegTemplateTextBox(IInputElement inputElement)
{
if (ReferenceEquals(inputElement, textFfmpegInput))
return textFfmpegInput;

if (ReferenceEquals(inputElement, textFfmpegOutput))
return textFfmpegOutput;

return null;
}
}

public class VideoContainer
Expand Down
132 changes: 120 additions & 12 deletions TwitchDownloaderWPF/Translations/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 42 additions & 8 deletions TwitchDownloaderWPF/Translations/Strings.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,12 @@
<data name="FfmpegOutputArguments" xml:space="preserve">
<value>Argumentos de salida:</value>
</data>
<data name="FfmpegParameters" xml:space="preserve">
<value>{fps} {height} {width} {max_int} {save_path}</value>
<comment>No traducir</comment>
</data>
<data name="FfmpegReset" xml:space="preserve">
<value>Restablecer valores por defecto</value>
</data>
<data name="FfzEmotes" xml:space="preserve">
<value>Emotes FFZ:</value>
</data>
<data name="FilenameTemplateParameters" xml:space="preserve">
<value>{title} {id} {date} {channel} {date_custom=""} {random_string} {trim_start} {trim_end} {trim_start_custom=""} {trim_end_custom=""} {length} {length_custom=""} {views} {game}</value>
<comment>No traducir</comment>
</data>
<data name="FontColor" xml:space="preserve">
<value>Color letra:</value>
</data>
Expand Down Expand Up @@ -949,4 +941,46 @@
<data name="UnableToGetChannelClipsMessage" xml:space="preserve">
<value>Unable to get channel clips: {0}</value>
</data>
<data name="FilenameParameterTitleTooltip" xml:space="preserve">
<value>The title of the video/clip.</value>
</data>
<data name="FilenameParameterIdTooltip" xml:space="preserve">
<value>The ID of the video/clip.</value>
</data>
<data name="FilenameParameterDateTooltip" xml:space="preserve">
<value>The date that the video/clip was created in the format M-d-yy.</value>
</data>
<data name="FilenameParameterDateCustomTooltip" xml:space="preserve">
<value>The date that the video/clip was created in a customizable format.</value>
</data>
<data name="FilenameParameterChannelTooltip" xml:space="preserve">
<value>The display name of the channel which owns the video/clip/chat.</value>
</data>
<data name="FilenameParameterRandomStringTooltip" xml:space="preserve">
<value>A string of 11 random characters.</value>
</data>
<data name="FilenameParameterTrimStartTooltip" xml:space="preserve">
<value>The start trim of the video/chat in the format hh-mm-ss.</value>
</data>
<data name="FilenameParameterTrimStartCustomTooltip" xml:space="preserve">
<value>The start trim of the video/chat in a customizable format.</value>
</data>
<data name="FilenameParameterTrimEndTooltip" xml:space="preserve">
<value>The end trim of the video/chat in the format hh-mm-ss.</value>
</data>
<data name="FilenameParameterTrimEndCustomTooltip" xml:space="preserve">
<value>The end trim of the video/chat in a customizable format.</value>
</data>
<data name="FilenameParameterLengthTooltip" xml:space="preserve">
<value>The length (including trim) of the video/clip/chat in the format hh-mm-ss.</value>
</data>
<data name="FilenameParameterLengthCustomTooltip" xml:space="preserve">
<value>The length (including trim) of the video/clip/chat in a customizable format.</value>
</data>
<data name="FilenameParameterViewsTooltip" xml:space="preserve">
<value>The amount of views the video/clip has.</value>
</data>
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
</root>
Loading