Skip to content

Commit

Permalink
添加拖动切换tab功能,修改输出文件路径逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshinohikari committed Aug 15, 2023
1 parent 180e869 commit 450a70b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
3 changes: 2 additions & 1 deletion NegativeEncoder/EncodingTask/TaskDetailWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
</Window.Title>
<Grid>
<TextBox x:Name="logBox" Margin="10,10,10,40" TextWrapping="Wrap" Text="{Binding RunLog}" IsReadOnly="True"
TextChanged="logBox_TextChanged" ScrollViewer.CanContentScroll="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" />
TextChanged="logBox_TextChanged" ScrollViewer.CanContentScroll="True"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" />
<ProgressBar Margin="10,0,300,9.5" Height="22" VerticalAlignment="Bottom" Value="{Binding Progress}"
Maximum="1000" />
<Button x:Name="mainButton" Margin="0,0,10,9.5" HorizontalAlignment="Right" Width="75" Height="22"
Expand Down
15 changes: 13 additions & 2 deletions NegativeEncoder/FileSelector/FileName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ public static string RecalcOutputPath(string input, string oldOutput, string suf
var basicOutputPath = Path.GetDirectoryName(AppContext.PresetContext.OutputFile);

var inputWithoutExt = Path.GetFileNameWithoutExtension(input);
var outputName = Path.ChangeExtension($"{inputWithoutExt}{suffix}", ext);
var outputName = Path.ChangeExtension($"{inputWithoutExt}{suffix}.out", ext);

if (!string.IsNullOrEmpty(outputPath)) return Path.Combine(outputPath, outputName);

if (!string.IsNullOrEmpty(basicOutputPath)) return Path.Combine(basicOutputPath, outputName);

var basePath = Path.GetDirectoryName(input);
return Path.Combine(basePath, outputName);
return Path.Combine(basePath!, outputName);
}

public static string RecalcOutputPath(string input, string suffix, string ext)
{
if (string.IsNullOrEmpty(input)) return "";

var inputWithoutExt = Path.GetFileNameWithoutExtension(input);
var outputName = Path.ChangeExtension($"{inputWithoutExt}{suffix}.out", ext);

var basePath = Path.GetDirectoryName(input);
return Path.Combine(basePath!, outputName);
}

public static (string ext, string filter) GetOutputExt(OutputFormat outputFormat)
Expand Down
16 changes: 8 additions & 8 deletions NegativeEncoder/FunctionTabs/FunctionTabs.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<Label Content="输出" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top" Height="25" />
<TextBox Margin="55,40,90,0" TextWrapping="NoWrap" VerticalAlignment="Top" Height="25"
VerticalContentAlignment="Center"
Text="{Binding OutputFile}" />
Text="{Binding OutputFile}" TextChanged="OutputFile_TextChanged" />
<Button Content="浏览..." HorizontalAlignment="Right" Margin="0,40,20,0" VerticalAlignment="Top" Height="25"
Width="65" Click="OutputBrowseButton_Click" />

<TabControl Margin="10,79,20,10">
<TabItem Header="编码器">
<TabControl Margin="10,79,20,10" SelectedIndex="{Binding SelectedTab}">
<TabItem Header="编码器" DragOver="Tab_DragOver" AllowDrop="True">
<Grid>
<Label Content="编码器" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"
Height="25" />
Expand Down Expand Up @@ -344,7 +344,7 @@

</Grid>
</TabItem>
<TabItem Header="HDR">
<TabItem Header="HDR" DragOver="Tab_DragOver" AllowDrop="True">
<Grid>
<CheckBox Content="输出带有HDR标记的视频" HorizontalAlignment="Left" Margin="10,10,0,0" Height="25"
VerticalAlignment="Top" VerticalContentAlignment="Center"
Expand Down Expand Up @@ -434,7 +434,7 @@

</Grid>
</TabItem>
<TabItem Header="VS">
<TabItem Header="VS" DragOver="Tab_DragOver" AllowDrop="True">
<DockPanel>
<Grid DockPanel.Dock="Top" Height="65">
<Border BorderBrush="#FFD0D0D0" BorderThickness="0,0,0,1" />
Expand Down Expand Up @@ -495,7 +495,7 @@
</avalonEdit:TextEditor>
</DockPanel>
</TabItem>
<TabItem Header="音频">
<TabItem Header="音频" DragOver="Tab_DragOver" AllowDrop="True">
<Grid>
<Label Content="音频输出" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"
Height="25" />
Expand All @@ -519,7 +519,7 @@
Click="AudioExtractButton_Click" />
</Grid>
</TabItem>
<TabItem Header="封装">
<TabItem Header="封装" DragOver="Tab_DragOver" AllowDrop="True">
<Grid>
<Label Content="音频输入" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"
Height="25" />
Expand Down Expand Up @@ -556,7 +556,7 @@

</Grid>
</TabItem>
<TabItem Header="常用">
<TabItem Header="常用" DragOver="Tab_DragOver" AllowDrop="True">
<Grid>
<GroupBox Header="ffmpeg pipe" VerticalAlignment="Top" Margin="10,10,10,0" Height="72"
ToolTip="使用FFMPEG解码并处理视频,并尝试修复音画同步。">
Expand Down
22 changes: 21 additions & 1 deletion NegativeEncoder/FunctionTabs/FunctionTabs.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace NegativeEncoder.FunctionTabs;
/// </summary>
public partial class FunctionTabs : UserControl
{
private bool _isAutoChange, _pathChanged;

public FunctionTabs()
{
InitializeComponent();
Expand Down Expand Up @@ -44,7 +46,10 @@ private void RecalcOutputPath()
var input = AppContext.PresetContext.InputFile;
var (ext, _) = FileName.GetOutputExt(AppContext.PresetContext.CurrentPreset.OutputFormat);

var output = FileName.RecalcOutputPath(input, AppContext.PresetContext.OutputFile, "_neenc", ext);
var output = _pathChanged
? FileName.RecalcOutputPath(input, AppContext.PresetContext.OutputFile, "_neenc", ext)
: FileName.RecalcOutputPath(input, "_neenc", ext);
_isAutoChange = true;
AppContext.PresetContext.OutputFile = output;
}

Expand Down Expand Up @@ -302,4 +307,19 @@ private void BuildTaskAndAddEncodingQueueAction(EncodingAction action, string pa

TaskBuilder.AddEncodingTask(action, param, preset, selectPaths, input, output, extra);
}

private void Tab_DragOver(object sender, DragEventArgs e)
{
var tabItem1 = (TabItem)sender;
var index = ((TabControl)(tabItem1.Parent)).Items.IndexOf(tabItem1);
AppContext.PresetContext.SelectedTab = index;
}

private void OutputFile_TextChanged(object sender, TextChangedEventArgs e)
{
if (!_isAutoChange)
_pathChanged = true;
else
_isAutoChange = false;
}
}
2 changes: 2 additions & 0 deletions NegativeEncoder/Presets/PresetContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class PresetContext
/// </summary>
public VsScript VsScript { get; set; } = new();

public int SelectedTab { get; set; } = 0;

public event SelectionChangedEventHandler InputFileChanged;

public void NotifyInputFileChange(object sender, SelectionChangedEventArgs e)
Expand Down
14 changes: 13 additions & 1 deletion NegativeEncoder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,21 @@ private static void Init()

//写入软件版本
var asm = Assembly.GetEntryAssembly();
var asmVersion =
/*var asmVersion =
(AssemblyInformationalVersionAttribute)Attribute.GetCustomAttribute(asm,
typeof(AssemblyInformationalVersionAttribute));
AppContext.Version.CurrentVersion = asmVersion?.InformationalVersion ?? "";
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var version = Attribute.GetCustomAttribute(assembly, typeof(AssemblyVersionAttribute)) as AssemblyVersionAttribute;
}
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var version = Attribute.GetCustomAttribute(assembly, typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute;
}*/

AppContext.Version.CurrentVersion = asm!.GetName().Version!.ToString();
}
}

0 comments on commit 450a70b

Please sign in to comment.