phase 1
This commit is contained in:
151
ModVersionChecker/ui/forms/GlobalConfigForm.cs
Normal file
151
ModVersionChecker/ui/forms/GlobalConfigForm.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using ModVersionChecker.managers.interfaces;
|
||||
using ModVersionChecker.model;
|
||||
|
||||
namespace ModVersionChecker.ui.forms
|
||||
{
|
||||
public class GlobalConfigForm : Form
|
||||
{
|
||||
private IConfigManager _configManager;
|
||||
private Config _config;
|
||||
|
||||
private Label _millislabel, _checkStartupLabel, _runOnStartupLabel;
|
||||
private TrackBar _millisField;
|
||||
private CheckBox _checkStartupField, _runOnStartupField;
|
||||
private Button _saveButton, _cancelButton;
|
||||
private TableLayoutPanel _mainLayout, _configsPanel;
|
||||
private FlowLayoutPanel _buttonPanel;
|
||||
|
||||
public GlobalConfigForm(IConfigManager configManager)
|
||||
{
|
||||
_configManager = configManager;
|
||||
_config = _configManager.GetConfig();
|
||||
this.Load += GlobalConfigForm_Load;
|
||||
}
|
||||
|
||||
private void GlobalConfigForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Load existing configurations if needed
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
SuspendLayout();
|
||||
|
||||
ClientSize = new System.Drawing.Size(600, 250);
|
||||
Name = "GlobalConfigForm";
|
||||
Text = "Global Configuration";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Padding = new Padding(10, 20, 10, 20 );
|
||||
_mainLayout = GetMainLayout();
|
||||
_configsPanel = GetConfigsPanel();
|
||||
|
||||
_buttonPanel = GetButtonsPanel();
|
||||
|
||||
_mainLayout.Controls.Add(_configsPanel, 0, 0);
|
||||
_mainLayout.Controls.Add(_buttonPanel, 0, 1);
|
||||
|
||||
Controls.Add(_mainLayout);
|
||||
|
||||
|
||||
ResumeLayout(false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private FlowLayoutPanel GetButtonsPanel()
|
||||
{
|
||||
var buttonsPanel = new FlowLayoutPanel { FlowDirection = FlowDirection.RightToLeft, AutoSize = true, Dock = DockStyle.Fill };
|
||||
_saveButton = new Button { Text = "Save", AutoSize = true };
|
||||
_saveButton.Click += (sender, e) =>
|
||||
{
|
||||
_config.IntervalMinutes = _millisField.Value;
|
||||
_config.CheckOnStartup = _checkStartupField.Checked;
|
||||
_config.RunOnStartup = _runOnStartupField.Checked;
|
||||
_configManager.Save(_config);
|
||||
DialogResult = DialogResult.OK;
|
||||
UpdateStartupSetting(_config.RunOnStartup);
|
||||
Close();
|
||||
};
|
||||
_cancelButton = new Button { Text = "Cancel", AutoSize = true };
|
||||
_cancelButton.Click += (sender, e) =>
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
};
|
||||
buttonsPanel.Controls.Add(_saveButton);
|
||||
buttonsPanel.Controls.Add(_cancelButton);
|
||||
return buttonsPanel;
|
||||
}
|
||||
|
||||
private TableLayoutPanel GetConfigsPanel()
|
||||
{
|
||||
// Initialize the configurations panel
|
||||
var configsPanel = new TableLayoutPanel
|
||||
{
|
||||
AutoSize = true,
|
||||
Dock = DockStyle.Fill,
|
||||
ColumnCount = 2,
|
||||
RowCount = 2,
|
||||
ColumnStyles = { new ColumnStyle(SizeType.Absolute, 150), new ColumnStyle(SizeType.Percent, 100) }
|
||||
};
|
||||
|
||||
_millislabel = new Label { Text = "Millis", Width = 150};
|
||||
_millisField = new TrackBar { Minimum = 0, Maximum = 120, Value= _config.IntervalMinutes, Width = 300, TickStyle = TickStyle.None };
|
||||
FlowLayoutPanel millisPanel = new FlowLayoutPanel { FlowDirection = FlowDirection.LeftToRight, AutoSize = true };
|
||||
Label millisValue = new Label { Text = _millisField.Value.ToString() + " minutes", AutoSize = true, Padding = new Padding(10, 10, 0, 0) };
|
||||
millisPanel.Controls.Add(_millisField);
|
||||
millisPanel.Controls.Add(millisValue);
|
||||
|
||||
_millisField.Scroll += (sender, e) => { millisValue.Text = _millisField.Value.ToString() + " minutes"; };
|
||||
|
||||
_checkStartupLabel = new Label { Text = "Check on Application Start:", Width = 150 };
|
||||
_checkStartupField = new CheckBox { Checked = _config.CheckOnStartup };
|
||||
_runOnStartupLabel= new Label { Text = "Run on Windows Startup:", Width = 150 };
|
||||
_runOnStartupField = new CheckBox { Checked = _config.RunOnStartup };
|
||||
|
||||
configsPanel.Controls.Add(_millislabel, 0, 0);
|
||||
configsPanel.Controls.Add(millisPanel, 1, 0);
|
||||
configsPanel.Controls.Add(_checkStartupLabel, 0, 1);
|
||||
configsPanel.Controls.Add(_checkStartupField, 1, 1);
|
||||
configsPanel.Controls.Add(_runOnStartupLabel, 0, 2);
|
||||
configsPanel.Controls.Add(_runOnStartupField, 1, 2);
|
||||
|
||||
return configsPanel;
|
||||
}
|
||||
|
||||
private TableLayoutPanel GetMainLayout()
|
||||
{
|
||||
// Initialize the main layout panel
|
||||
var mainLayout = new TableLayoutPanel
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
RowCount = 2,
|
||||
ColumnCount = 1
|
||||
};
|
||||
mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 150)); // Paths panel height
|
||||
mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 50)); // Button panel height
|
||||
Controls.Add(mainLayout);
|
||||
return mainLayout;
|
||||
}
|
||||
|
||||
private void UpdateStartupSetting(bool runOnStartup)
|
||||
{
|
||||
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
|
||||
{
|
||||
if (runOnStartup)
|
||||
{
|
||||
key?.SetValue("XintanalabsUpdateChecker", $"\"{Application.ExecutablePath}\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
key?.DeleteValue("XintanalabsUpdateChecker", false); // Remove if unchecked
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add methods and properties for global configuration management here
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user