Support drag n drop file to video converter form

This commit is contained in:
Jaex 2021-09-06 04:42:07 +03:00
parent cc8c3fd511
commit f383e3893c
3 changed files with 42 additions and 14 deletions

View file

@ -176,8 +176,8 @@ private void InitializeComponent()
//
// VideoConverterForm
//
this.AllowDrop = true;
resources.ApplyResources(this, "$this");
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.SystemColors.Window;
this.Controls.Add(this.lblVideoQualityValue);
@ -204,6 +204,8 @@ private void InitializeComponent()
this.MaximizeBox = false;
this.Name = "VideoConverterForm";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.VideoConverterForm_FormClosing);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.VideoConverterForm_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.VideoConverterForm_DragEnter);
((System.ComponentModel.ISupportInitialize)(this.tbVideoQuality)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

View file

@ -146,6 +146,21 @@ private void UpdateOptions()
!string.IsNullOrEmpty(Options.OutputFileName);
}
private void UpdateInputFilePathTextBox(string filePath)
{
txtInputFilePath.Text = filePath;
if (string.IsNullOrEmpty(txtOutputFolder.Text))
{
txtOutputFolder.Text = Path.GetDirectoryName(filePath);
}
if (string.IsNullOrEmpty(txtOutputFileName.Text))
{
txtOutputFileName.Text = Path.GetFileNameWithoutExtension(filePath) + "-output";
}
}
private bool StartEncoding()
{
bool result = false;
@ -198,17 +213,7 @@ private void btnInputFilePathBrowse_Click(object sender, EventArgs e)
if (ofd.ShowDialog(this) == DialogResult.OK)
{
string filePath = ofd.FileName;
txtInputFilePath.Text = filePath;
if (string.IsNullOrEmpty(txtOutputFolder.Text))
{
txtOutputFolder.Text = Path.GetDirectoryName(filePath);
}
if (string.IsNullOrEmpty(txtOutputFileName.Text))
{
txtOutputFileName.Text = Path.GetFileNameWithoutExtension(filePath) + "-output";
}
UpdateInputFilePathTextBox(filePath);
}
}
}
@ -288,6 +293,27 @@ private async void btnEncode_Click(object sender, EventArgs e)
}
}
private void VideoConverterForm_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void VideoConverterForm_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && e.Data.GetData(DataFormats.FileDrop, false) is string[] files && files.Length > 0)
{
string filePath = files[0];
UpdateInputFilePathTextBox(filePath);
}
}
private void VideoConverterForm_FormClosing(object sender, FormClosingEventArgs e)
{
formClosing = true;

View file

@ -594,7 +594,7 @@
<value>pbProgress</value>
</data>
<data name="&gt;&gt;pbProgress.Type" xml:space="preserve">
<value>ShareX.HelpersLib.BlackStyleProgressBar, ShareX.HelpersLib, Version=13.0.2.0, Culture=neutral, PublicKeyToken=null</value>
<value>ShareX.HelpersLib.BlackStyleProgressBar, ShareX.HelpersLib, Version=13.6.1.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;pbProgress.Parent" xml:space="preserve">
<value>$this</value>
@ -633,7 +633,7 @@
<value>True</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 13</value>
<value>96, 96</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>456, 278</value>