mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-15 16:07:45 +01:00
Fix main window stealing focus after dropping queue videos
This commit is contained in:
@@ -285,29 +285,48 @@ namespace Flowframes
|
||||
return filePath.IsConcatFile() ? $"{rateStr}-safe 0 -f concat " : "";
|
||||
}
|
||||
|
||||
public static string Get(this Dictionary<string, string> dict, string key, bool returnKeyInsteadOfEmptyString = false, bool ignoreCase = false)
|
||||
public static string Get<TKey>(this Dictionary<TKey, string> dict, string key, bool returnKeyInsteadOfEmptyString = false, bool ignoreCase = false)
|
||||
{
|
||||
if (key == null)
|
||||
key = "";
|
||||
|
||||
// Safely handle a null dictionary
|
||||
for (int i = 0; i < (dict == null ? 0 : dict.Count); i++)
|
||||
{
|
||||
var elementKey = dict.ElementAt(i).Key;
|
||||
var elementValue = dict.ElementAt(i).Value;
|
||||
|
||||
// Convert the dictionary key to string (handling null)
|
||||
string dictKeyString = (elementKey == null ? "" : elementKey.ToString());
|
||||
|
||||
if (ignoreCase)
|
||||
{
|
||||
if (key.Lower() == dict.ElementAt(i).Key.Lower())
|
||||
return dict.ElementAt(i).Value;
|
||||
if (key.Lower() == dictKeyString.Lower())
|
||||
return elementValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (key == dict.ElementAt(i).Key)
|
||||
return dict.ElementAt(i).Value;
|
||||
if (key == dictKeyString)
|
||||
return elementValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (returnKeyInsteadOfEmptyString)
|
||||
return key;
|
||||
else
|
||||
return "";
|
||||
return returnKeyInsteadOfEmptyString ? key : "";
|
||||
}
|
||||
|
||||
/// <summary> Get a value from a dictionary, returns <paramref name="fallback"/> if not found. For strings, the default fallback is an empty string instead of null. </summary>
|
||||
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue fallback = default)
|
||||
{
|
||||
// For string values, use empty string instead of null as default value
|
||||
if (typeof(TValue) == typeof(string) && fallback != null)
|
||||
{
|
||||
fallback = (TValue)(object)string.Empty;
|
||||
}
|
||||
|
||||
if (dictionary == null)
|
||||
return fallback;
|
||||
|
||||
return dictionary.TryGetValue(key, out var value) ? value : fallback;
|
||||
}
|
||||
|
||||
public static void FillFromEnum<TEnum>(this ComboBox comboBox, Dictionary<string, string> stringMap = null, int defaultIndex = -1, List<TEnum> exclusionList = null, bool useKeyNames = false) where TEnum : Enum
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Flowframes.Data;
|
||||
using static Flowframes.Ui.ControlExtensions;
|
||||
|
||||
namespace Flowframes.Forms
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace Flowframes.Forms
|
||||
RefreshGui();
|
||||
}
|
||||
|
||||
public void RefreshGui ()
|
||||
public void RefreshGui()
|
||||
{
|
||||
taskList.Items.Clear();
|
||||
|
||||
@@ -34,29 +35,29 @@ namespace Flowframes.Forms
|
||||
InterpSettings entry = Program.batchQueue.ElementAt(i);
|
||||
string outFormat = Strings.OutputFormat.Get(entry.outSettings.Format.ToString());
|
||||
string inPath = string.IsNullOrWhiteSpace(entry.inPath) ? "No Path" : Path.GetFileName(entry.inPath).Trunc(40);
|
||||
string str = $"#{i+1}: {inPath} - {entry.inFps.Float} FPS => {entry.interpFactor}x {entry.ai.NameShort} ({entry.model.Name}) => {outFormat}";
|
||||
string str = $"#{i + 1}: {inPath} - {entry.inFps.Float} FPS => {entry.interpFactor}x {entry.ai.NameShort} ({entry.model.Name}) => {outFormat}";
|
||||
taskList.Items.Add(str);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshIndex ()
|
||||
private void RefreshIndex()
|
||||
{
|
||||
for(int i = 0; i < taskList.Items.Count; i++)
|
||||
for (int i = 0; i < taskList.Items.Count; i++)
|
||||
{
|
||||
string[] split = taskList.Items[i].ToString().Split(':');
|
||||
split[0] = $"#{i+1}";
|
||||
split[0] = $"#{i + 1}";
|
||||
taskList.Items[i] = string.Join(":", split);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetWorking (bool working)
|
||||
public void SetWorking(bool working)
|
||||
{
|
||||
runBtn.Enabled = !working;
|
||||
addToQueue.Enabled = !working;
|
||||
stopBtn.Visible = working;
|
||||
forceStopBtn.Visible = working;
|
||||
stopBtn.Enabled = working;
|
||||
}
|
||||
}
|
||||
|
||||
private void BatchForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
@@ -119,7 +120,7 @@ namespace Flowframes.Forms
|
||||
|
||||
Queue<InterpSettings> temp = new Queue<InterpSettings>();
|
||||
|
||||
for(int i = 0; i < Program.batchQueue.Count; i++)
|
||||
for (int i = 0; i < Program.batchQueue.Count; i++)
|
||||
{
|
||||
if (i != taskList.SelectedIndex)
|
||||
temp.Enqueue(Program.batchQueue.ElementAt(i));
|
||||
@@ -146,24 +147,40 @@ namespace Flowframes.Forms
|
||||
await LoadDroppedPaths(droppedPaths);
|
||||
}
|
||||
|
||||
public async Task LoadDroppedPaths (string[] droppedPaths, bool start = false)
|
||||
{
|
||||
foreach (string path in droppedPaths)
|
||||
public async Task LoadDroppedPaths(string[] droppedPaths, bool start = false)
|
||||
{
|
||||
if (droppedPaths == null || droppedPaths.Length < 1)
|
||||
return;
|
||||
|
||||
var prevOpacity = Program.mainForm.Opacity;
|
||||
Program.mainForm.Invoke(() => Program.mainForm.Opacity = 0f);
|
||||
|
||||
try
|
||||
{
|
||||
Logger.Log($"BatchForm: Dropped path: '{path}'", true);
|
||||
foreach (string path in droppedPaths)
|
||||
{
|
||||
Logger.Log($"BatchForm: Dropped path: '{path}'", true);
|
||||
|
||||
InterpSettings current = Program.mainForm.GetCurrentSettings(path);
|
||||
current.inFpsDetected = await IoUtils.GetFpsFolderOrVideo(path);
|
||||
current.inFps = current.inFpsDetected;
|
||||
InterpSettings current = Program.mainForm.GetCurrentSettings(path);
|
||||
current.inFpsDetected = await IoUtils.GetFpsFolderOrVideo(path);
|
||||
current.inFps = current.inFpsDetected;
|
||||
|
||||
if(current.inFps.Float <= 0)
|
||||
current.inFps = InterpolateUtils.AskForFramerate(new DirectoryInfo(path).Name, false);
|
||||
if (current.inFps.Float <= 0)
|
||||
current.inFps = InterpolateUtils.AskForFramerate(new DirectoryInfo(path).Name, false);
|
||||
|
||||
current.outFps = current.inFps * current.interpFactor;
|
||||
current.outFps = current.inFps * current.interpFactor;
|
||||
|
||||
Program.batchQueue.Enqueue(current);
|
||||
RefreshGui();
|
||||
Program.batchQueue.Enqueue(current);
|
||||
RefreshGui();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log($"BatchForm: Error while loading dropped paths: {ex.Message}", true);
|
||||
}
|
||||
|
||||
Program.mainForm.Invoke(() => Program.mainForm.Opacity = prevOpacity);
|
||||
BringToFront();
|
||||
|
||||
if (start)
|
||||
runBtn_Click(null, null);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Flowframes;
|
||||
using Flowframes.Media;
|
||||
using Flowframes.Media;
|
||||
using Flowframes.Data;
|
||||
using Flowframes.IO;
|
||||
using Flowframes.Magick;
|
||||
@@ -17,7 +16,6 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Padding = Flowframes.Data.Padding;
|
||||
using Utils = Flowframes.Main.InterpolateUtils;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace Flowframes
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flowframes.MiscUtils
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user