TASK 20 step 2: hotkey config UI + modifier chord persistence + conflict detection
This commit is contained in:
@@ -1220,6 +1220,57 @@ public class LayoutStore : IDisposable
|
||||
meta.ScheduledStartTime?.ToString("o") ?? string.Empty);
|
||||
}
|
||||
|
||||
// ─── Hotkey bindings (TASK 20 step 2) ───
|
||||
|
||||
/// <summary>
|
||||
/// Load saved hotkey bindings. Returns only entries that have been explicitly
|
||||
/// saved — missing HotkeyIds are unbound (not in the returned dictionary).
|
||||
/// Caller fills in defaults for any missing entries as needed.
|
||||
/// </summary>
|
||||
public Dictionary<HotkeyId, HotkeyChord> LoadHotkeyBindings()
|
||||
{
|
||||
var result = new Dictionary<HotkeyId, HotkeyChord>();
|
||||
foreach (HotkeyId id in Enum.GetValues(typeof(HotkeyId)))
|
||||
{
|
||||
var raw = GetSetting($"Hotkey.{id}");
|
||||
if (raw == null) continue; // not saved = unbound
|
||||
if (raw == "none") continue; // explicitly unbound
|
||||
try
|
||||
{
|
||||
result[id] = HotkeyChord.ParseStorage(raw);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// corrupt entry — skip, will fall back to default
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save hotkey bindings. Null entries in the dictionary mean "unbound" (stored
|
||||
/// as "none"). Only the provided entries are saved; previously saved entries
|
||||
/// for HotkeyIds not in the dictionary are deleted.
|
||||
/// </summary>
|
||||
public void SaveHotkeyBindings(Dictionary<HotkeyId, HotkeyChord?> bindings)
|
||||
{
|
||||
// Delete all existing hotkey settings first
|
||||
foreach (HotkeyId id in Enum.GetValues(typeof(HotkeyId)))
|
||||
{
|
||||
using var cmd = _connection.CreateCommand();
|
||||
cmd.CommandText = "DELETE FROM Settings WHERE Key = $key;";
|
||||
cmd.Parameters.AddWithValue("$key", $"Hotkey.{id}");
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// Save the new bindings
|
||||
foreach (var (id, chord) in bindings)
|
||||
{
|
||||
var value = chord?.ToString() ?? "none";
|
||||
UpsertSetting($"Hotkey.{id}", value);
|
||||
}
|
||||
}
|
||||
|
||||
public (double Left, double Top, double Width, double Height, string State)? LoadWindowState()
|
||||
{
|
||||
var left = GetSetting("Window.Left");
|
||||
|
||||
Reference in New Issue
Block a user