feat(Program.cs): implement automatic first and last index calculation for sequence mode
This commit is contained in:
@@ -47,6 +47,23 @@ namespace DD2Switcher {
|
|||||||
|
|
||||||
public static void StartSequenceMode() {
|
public static void StartSequenceMode() {
|
||||||
Console.WriteLine($"StartSequenceMode called. FirstIndex: {FirstIndex}, LastIndex: {LastIndex}");
|
Console.WriteLine($"StartSequenceMode called. FirstIndex: {FirstIndex}, LastIndex: {LastIndex}");
|
||||||
|
|
||||||
|
// Compute default indices if not set by user
|
||||||
|
if (FirstIndex == -1 || LastIndex == -1) {
|
||||||
|
FirstIndex = FindFirstNonNullWindow();
|
||||||
|
LastIndex = FindLastNonNullWindow();
|
||||||
|
Console.WriteLine($"Computed default indices: FirstIndex={FirstIndex}, LastIndex={LastIndex}");
|
||||||
|
|
||||||
|
// Ensure LastIndex is different from FirstIndex if there are multiple windows
|
||||||
|
if (FirstIndex != -1 && LastIndex != -1 && FirstIndex == LastIndex) {
|
||||||
|
int nextWindow = FindNextNonNullWindow(FirstIndex + 1);
|
||||||
|
if (nextWindow != -1) {
|
||||||
|
LastIndex = nextWindow;
|
||||||
|
Console.WriteLine($"Adjusted LastIndex to: {LastIndex} (different from FirstIndex)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (FirstIndex >= 0 && LastIndex >= 0 && FirstIndex <= LastIndex) {
|
if (FirstIndex >= 0 && LastIndex >= 0 && FirstIndex <= LastIndex) {
|
||||||
CurrentState = SequenceState.PROCESSING;
|
CurrentState = SequenceState.PROCESSING;
|
||||||
CurrentSequenceIndex = FirstIndex;
|
CurrentSequenceIndex = FirstIndex;
|
||||||
@@ -101,6 +118,8 @@ namespace DD2Switcher {
|
|||||||
SequenceKeybind = settings.SequenceKeybind;
|
SequenceKeybind = settings.SequenceKeybind;
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
$"Loaded settings: First={FirstIndex}, Last={LastIndex}, Keybind={SequenceKeybind}");
|
$"Loaded settings: First={FirstIndex}, Last={LastIndex}, Keybind={SequenceKeybind}");
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("No settings file found, using defaults");
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Console.WriteLine($"Error loading settings: {ex.Message}");
|
Console.WriteLine($"Error loading settings: {ex.Message}");
|
||||||
@@ -155,6 +174,16 @@ namespace DD2Switcher {
|
|||||||
LastIndex = FindLastNonNullWindow();
|
LastIndex = FindLastNonNullWindow();
|
||||||
Console.WriteLine($"Set default LastIndex to: {LastIndex}");
|
Console.WriteLine($"Set default LastIndex to: {LastIndex}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure LastIndex is different from FirstIndex if there are multiple windows
|
||||||
|
if (FirstIndex != -1 && LastIndex != -1 && FirstIndex == LastIndex) {
|
||||||
|
// Find the next non-null window after FirstIndex
|
||||||
|
int nextWindow = FindNextNonNullWindow(FirstIndex + 1);
|
||||||
|
if (nextWindow != -1) {
|
||||||
|
LastIndex = nextWindow;
|
||||||
|
Console.WriteLine($"Adjusted LastIndex to: {LastIndex} (different from FirstIndex)");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateSequenceHotkey(Keys newKey) {
|
public static void UpdateSequenceHotkey(Keys newKey) {
|
||||||
@@ -175,6 +204,10 @@ namespace DD2Switcher {
|
|||||||
SaveSettings();
|
SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SaveFirstLastIndices() {
|
||||||
|
SaveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
// Static properties for first/last selection persistence
|
// Static properties for first/last selection persistence
|
||||||
public static int FirstIndex { get; set; } = -1;
|
public static int FirstIndex { get; set; } = -1;
|
||||||
public static int LastIndex { get; set; } = -1;
|
public static int LastIndex { get; set; } = -1;
|
||||||
@@ -371,10 +404,6 @@ namespace DD2Switcher {
|
|||||||
PushHistory(firstNullIndex);
|
PushHistory(firstNullIndex);
|
||||||
ActiveIndex = firstNullIndex;
|
ActiveIndex = firstNullIndex;
|
||||||
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
||||||
|
|
||||||
// Set default first/last indices if not set
|
|
||||||
SetDefaultFirstLastIndices();
|
|
||||||
SaveSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TrackProcess() {
|
private static void TrackProcess() {
|
||||||
|
Reference in New Issue
Block a user