Fix "pick" button crashing shit
This commit is contained in:
@@ -83,8 +83,37 @@ namespace DD2Switcher {
|
|||||||
windowPanelForm.IsLast = (i == lastIndex);
|
windowPanelForm.IsLast = (i == lastIndex);
|
||||||
windowPanelForm.UpdateDisplay();
|
windowPanelForm.UpdateDisplay();
|
||||||
|
|
||||||
windowPanelForm.PickClicked += (sender, index) => PickButton_Click(sender, new EventArgs());
|
windowPanelForm.PickClicked += (sender, index) => {
|
||||||
windowPanelForm.UntrackClicked += (sender, index) => UntrackButton_Click(sender, new EventArgs());
|
if (firstIndex == -1) {
|
||||||
|
// First pick - set both first and last
|
||||||
|
firstIndex = index;
|
||||||
|
lastIndex = index;
|
||||||
|
} else if (lastIndex == -1) {
|
||||||
|
// Second pick - set last
|
||||||
|
lastIndex = index;
|
||||||
|
} else {
|
||||||
|
// Subsequent picks - determine which becomes first
|
||||||
|
if (index < firstIndex) {
|
||||||
|
// New index is lower, so it becomes first
|
||||||
|
lastIndex = firstIndex;
|
||||||
|
firstIndex = index;
|
||||||
|
} else {
|
||||||
|
// New index is higher, so it becomes last
|
||||||
|
lastIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RefreshWindowsList();
|
||||||
|
};
|
||||||
|
windowPanelForm.UntrackClicked += (sender, index) => {
|
||||||
|
UntrackWindow(index);
|
||||||
|
if (index == firstIndex) {
|
||||||
|
firstIndex = -1;
|
||||||
|
}
|
||||||
|
if (index == lastIndex) {
|
||||||
|
lastIndex = -1;
|
||||||
|
}
|
||||||
|
RefreshWindowsList();
|
||||||
|
};
|
||||||
|
|
||||||
windowsPanel.Controls.Add(windowPanelForm);
|
windowsPanel.Controls.Add(windowPanelForm);
|
||||||
}
|
}
|
||||||
@@ -101,50 +130,6 @@ namespace DD2Switcher {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PickButton_Click(object sender, EventArgs e) {
|
|
||||||
var button = (Button)sender;
|
|
||||||
int index = (int)button.Tag;
|
|
||||||
|
|
||||||
if (firstIndex == -1) {
|
|
||||||
// First pick - set both first and last
|
|
||||||
firstIndex = index;
|
|
||||||
lastIndex = index;
|
|
||||||
} else if (lastIndex == -1) {
|
|
||||||
// Second pick - set last
|
|
||||||
lastIndex = index;
|
|
||||||
} else {
|
|
||||||
// Subsequent picks - determine which becomes first
|
|
||||||
if (index < firstIndex) {
|
|
||||||
// New index is lower, so it becomes first
|
|
||||||
lastIndex = firstIndex;
|
|
||||||
firstIndex = index;
|
|
||||||
} else {
|
|
||||||
// New index is higher, so it becomes last
|
|
||||||
lastIndex = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RefreshWindowsList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UntrackButton_Click(object sender, EventArgs e) {
|
|
||||||
var button = (Button)sender;
|
|
||||||
int index = (int)button.Tag;
|
|
||||||
|
|
||||||
// Remove from tracked windows
|
|
||||||
UntrackWindow(index);
|
|
||||||
|
|
||||||
// Update first/last indices if needed
|
|
||||||
if (index == firstIndex) {
|
|
||||||
firstIndex = -1;
|
|
||||||
}
|
|
||||||
if (index == lastIndex) {
|
|
||||||
lastIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
RefreshWindowsList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Process> GetTrackedWindows() {
|
private List<Process> GetTrackedWindows() {
|
||||||
var windows = Program.GetTrackedWindows();
|
var windows = Program.GetTrackedWindows();
|
||||||
return windows.ToList();
|
return windows.ToList();
|
||||||
|
Reference in New Issue
Block a user