Fix main window stealing focus after dropping queue videos

This commit is contained in:
N00MKRAD
2025-02-06 22:09:06 +01:00
parent 05cb41d818
commit 3cb7b155ba
4 changed files with 66 additions and 34 deletions

View File

@@ -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

View File

@@ -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
{
@@ -147,6 +148,14 @@ namespace Flowframes.Forms
}
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
{
foreach (string path in droppedPaths)
{
@@ -164,6 +173,14 @@ namespace Flowframes.Forms
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);

View File

@@ -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
{

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.MiscUtils
{