phase 1
This commit is contained in:
64
ModVersionChecker/utils/InputControlsFactory.cs
Normal file
64
ModVersionChecker/utils/InputControlsFactory.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using ModVersionChecker.controls;
|
||||
using ModVersionChecker.model;
|
||||
using ModVersionChecker.repository.api.dto;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModVersionChecker.utils
|
||||
{
|
||||
public class InputControlsFactory
|
||||
{
|
||||
public static Control CreateControl(FieldResponse field, TypeConfig config, Boolean enabled = true)
|
||||
{
|
||||
var value = config?.ConfigValues != null && config.ConfigValues.ContainsKey(field.Name) ? config.ConfigValues[field.Name] : field.DefaultValue;
|
||||
var directoryField = () =>
|
||||
{
|
||||
var textBox = new TextBox
|
||||
{
|
||||
Width = 300,
|
||||
Text = value,
|
||||
ReadOnly = true
|
||||
};
|
||||
var control = new TableLayoutPanel
|
||||
{
|
||||
AutoSize = true,
|
||||
Dock = DockStyle.Fill,
|
||||
ColumnCount = 2,
|
||||
RowCount = 1,
|
||||
ColumnStyles = { new ColumnStyle(SizeType.Percent, 80), new ColumnStyle(SizeType.Percent, 20) }
|
||||
};
|
||||
control.Controls.Add(textBox, 0, 0);
|
||||
var browseButton = new Button { Text = "Browse", Width = 80, Enabled = enabled };
|
||||
browseButton.Click += (s, e) =>
|
||||
{
|
||||
using (var folderDialog = new FolderBrowserDialog())
|
||||
{
|
||||
folderDialog.Description = $"Select directory for {field.Label}";
|
||||
//folderDialog.SelectedPath = textBox.Text == "" ? Path.Combine(fs.Path) : textBox.Text;
|
||||
|
||||
if (folderDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string selectedDirectory = folderDialog.SelectedPath;
|
||||
//string folderName = Path.GetFileName(selectedDirectory);
|
||||
textBox.Text = selectedDirectory;
|
||||
}
|
||||
}
|
||||
};
|
||||
control.Controls.Add(browseButton, 1, 0);
|
||||
return control;
|
||||
};
|
||||
|
||||
return field. ControlType.ToLower() switch
|
||||
{
|
||||
"text" => new TextBox { Text = value, Width = 300, Enabled = enabled },
|
||||
"number" => new NumericUpDown { Value = decimal.TryParse(value, out var num) ? num : 0, Width = 100, Enabled = enabled },
|
||||
"checkbox" => new CheckBox { Checked = bool.TryParse(value, out var isChecked) && isChecked, AutoSize = true, Enabled = enabled },
|
||||
"directory" => new DirectoryPickerControl { SelectedPath = value, Enabled = enabled },
|
||||
_ => new TextBox { Text = value, Width = 300, Enabled = enabled }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user