229 lines
8.1 KiB
C#
229 lines
8.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DD2Switcher {
|
|
public partial class SettingsForm : Form {
|
|
private FlowLayoutPanel windowsPanel;
|
|
private int firstIndex = -1;
|
|
private int lastIndex = -1;
|
|
|
|
public SettingsForm() {
|
|
InitializeComponent();
|
|
LoadIcon();
|
|
RefreshWindowsList();
|
|
}
|
|
|
|
private void InitializeComponent() {
|
|
this.windowsPanel = new System.Windows.Forms.FlowLayoutPanel();
|
|
this.SuspendLayout();
|
|
//
|
|
// windowsPanel
|
|
//
|
|
this.windowsPanel.AutoScroll = true;
|
|
this.windowsPanel.BackColor = System.Drawing.Color.White;
|
|
this.windowsPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
|
this.windowsPanel.Location = new System.Drawing.Point(12, 12);
|
|
this.windowsPanel.Name = "windowsPanel";
|
|
this.windowsPanel.Padding = new System.Windows.Forms.Padding(10);
|
|
this.windowsPanel.Size = new System.Drawing.Size(576, 396);
|
|
this.windowsPanel.TabIndex = 1;
|
|
//
|
|
// SettingsForm
|
|
//
|
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
this.ClientSize = new System.Drawing.Size(600, 420);
|
|
this.Controls.Add(this.windowsPanel);
|
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
|
this.MaximizeBox = false;
|
|
this.MinimizeBox = false;
|
|
this.Name = "SettingsForm";
|
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
|
this.Text = "DD2Switcher Settings";
|
|
this.ResumeLayout(false);
|
|
}
|
|
|
|
private void closeButton_Click(object sender, EventArgs e) {
|
|
this.Close();
|
|
}
|
|
|
|
private void refreshButton_Click(object sender, EventArgs e) {
|
|
RefreshWindowsList();
|
|
}
|
|
|
|
private void RefreshWindowsList() {
|
|
windowsPanel.Controls.Clear();
|
|
|
|
// Get tracked windows from Program
|
|
var trackedWindows = GetTrackedWindows();
|
|
|
|
if (trackedWindows.Count == 0) {
|
|
var noWindowsLabel = new Label();
|
|
noWindowsLabel.Text = "No windows currently tracked";
|
|
noWindowsLabel.AutoSize = true;
|
|
noWindowsLabel.ForeColor = Color.Gray;
|
|
noWindowsLabel.Font = new Font("Segoe UI", 10F);
|
|
windowsPanel.Controls.Add(noWindowsLabel);
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < trackedWindows.Count; i++) {
|
|
var window = trackedWindows[i];
|
|
if (window == null)
|
|
continue;
|
|
|
|
var windowPanel = CreateWindowPanel(i, window);
|
|
windowsPanel.Controls.Add(windowPanel);
|
|
}
|
|
}
|
|
|
|
private Panel CreateWindowPanel(int index, Process window) {
|
|
var panel = new Panel();
|
|
panel.Width = 520;
|
|
panel.Height = 80;
|
|
panel.BorderStyle = BorderStyle.FixedSingle;
|
|
panel.Margin = new Padding(5);
|
|
panel.BackColor = Color.LightGray;
|
|
|
|
// Index label
|
|
var indexLabel = new Label();
|
|
indexLabel.Text = $"Index: {index}";
|
|
indexLabel.Location = new Point(10, 5);
|
|
indexLabel.AutoSize = true;
|
|
indexLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold);
|
|
panel.Controls.Add(indexLabel);
|
|
|
|
// Process name
|
|
var nameLabel = new Label();
|
|
nameLabel.Text = $"Name: {window.ProcessName}";
|
|
nameLabel.Location = new Point(10, 25);
|
|
nameLabel.AutoSize = true;
|
|
nameLabel.Font = new Font("Segoe UI", 9F);
|
|
panel.Controls.Add(nameLabel);
|
|
|
|
// PID
|
|
var pidLabel = new Label();
|
|
pidLabel.Text = $"PID: {window.Id}";
|
|
pidLabel.Location = new Point(10, 45);
|
|
pidLabel.AutoSize = true;
|
|
pidLabel.Font = new Font("Segoe UI", 9F);
|
|
panel.Controls.Add(pidLabel);
|
|
|
|
// Window title
|
|
var titleLabel = new Label();
|
|
titleLabel.Text = $"Title: {window.MainWindowTitle}";
|
|
titleLabel.Location = new Point(200, 25);
|
|
titleLabel.AutoSize = true;
|
|
titleLabel.Font = new Font("Segoe UI", 9F);
|
|
titleLabel.MaximumSize = new Size(200, 0);
|
|
panel.Controls.Add(titleLabel);
|
|
|
|
// First/Last indicator
|
|
var firstLastLabel = new Label();
|
|
firstLastLabel.Text = GetFirstLastText(index);
|
|
firstLastLabel.Location = new Point(200, 45);
|
|
firstLastLabel.AutoSize = true;
|
|
firstLastLabel.Font = new Font("Segoe UI", 9F, FontStyle.Bold);
|
|
firstLastLabel.ForeColor = Color.DarkBlue;
|
|
panel.Controls.Add(firstLastLabel);
|
|
|
|
// Pick button
|
|
var pickButton = new Button();
|
|
pickButton.Text = "Pick";
|
|
pickButton.Location = new Point(420, 10);
|
|
pickButton.Size = new Size(50, 25);
|
|
pickButton.Tag = index;
|
|
pickButton.Click += PickButton_Click;
|
|
panel.Controls.Add(pickButton);
|
|
|
|
// Untrack button
|
|
var untrackButton = new Button();
|
|
untrackButton.Text = "Untrack";
|
|
untrackButton.Location = new Point(420, 45);
|
|
untrackButton.Size = new Size(50, 25);
|
|
untrackButton.Tag = index;
|
|
untrackButton.Click += UntrackButton_Click;
|
|
panel.Controls.Add(untrackButton);
|
|
|
|
return panel;
|
|
}
|
|
|
|
private string GetFirstLastText(int index) {
|
|
if (index == firstIndex && index == lastIndex) {
|
|
return "First & Last";
|
|
} else if (index == firstIndex) {
|
|
return "First";
|
|
} else if (index == lastIndex) {
|
|
return "Last";
|
|
}
|
|
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() {
|
|
var windows = Program.GetTrackedWindows();
|
|
return windows.ToList();
|
|
}
|
|
|
|
private void UntrackWindow(int index) {
|
|
Program.UntrackWindow(index);
|
|
}
|
|
|
|
private void LoadIcon() {
|
|
try {
|
|
this.Icon = new Icon(System.IO.Path.Combine(
|
|
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
|
|
"app.ico"));
|
|
} catch {
|
|
// Use default icon if custom icon not found
|
|
}
|
|
}
|
|
}
|
|
} |