Added detection for design mode

This commit is contained in:
Thorsten Sommer 2022-07-10 20:30:28 +02:00
parent aa641770d2
commit 3dfaccc99f
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
5 changed files with 34 additions and 5 deletions

View File

@ -62,6 +62,9 @@ public partial class LoaderStart : UserControl
private void buttonOpen_Click(object sender, EventArgs e)
{
if(this.DesignMode)
return;
if(this.areRecentProjectsVisible)
{
this.areRecentProjectsVisible = false;
@ -91,6 +94,9 @@ public partial class LoaderStart : UserControl
private void buttonNew_Click(object sender, EventArgs e)
{
if(this.DesignMode)
return;
var saveDialog = new SaveFileDialog
{
AddExtension = true,

View File

@ -13,6 +13,8 @@ public partial class SectionTree : UserControl
public SectionTree()
{
this.InitializeComponent();
if(this.DesignMode)
return;
// Get the DI context from the main form:
this.db = Program.SERVICE_PROVIDER.GetService<DataContext>()!;
@ -35,6 +37,9 @@ public partial class SectionTree : UserControl
private async void LoadNodes(object? sender, EventArgs e)
{
if(this.DesignMode)
return;
// A dictionary to cache all known tree nodes:
var treeNodes = new Dictionary<string, TreeNode>();
@ -112,6 +117,9 @@ public partial class SectionTree : UserControl
private async void buttonAdd_Click(object sender, EventArgs e)
{
if(this.DesignMode)
return;
var result = InputDialog.Show(new InputDialog.Options(
Message: "Please type the desired section name.",
Title: "Add a section",
@ -151,6 +159,9 @@ public partial class SectionTree : UserControl
private async void buttonRemove_Click(object sender, EventArgs e)
{
if(this.DesignMode)
return;
// Get the currently selected section, which will be removed:
var selectedNode = this.treeView.SelectedNode;
@ -175,6 +186,9 @@ public partial class SectionTree : UserControl
private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if(this.DesignMode)
return;
// Get the currently selected section:
var selectedNode = this.treeView.SelectedNode;
@ -184,6 +198,9 @@ public partial class SectionTree : UserControl
private async void buttonRename_Click(object sender, EventArgs e)
{
if(this.DesignMode)
return;
// Ask the user if he really wants to rename the section:
if(MessageBox.Show("Are you sure, you want to rename the selected section? If you are already using this section in your code, you will need to manually refactor your code after renaming it.", "Rename section", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
return;

View File

@ -48,6 +48,9 @@ public partial class InputDialog : Form
private void buttonOk_Click(object sender, EventArgs e)
{
if(this.DesignMode)
return;
if (!string.IsNullOrWhiteSpace(this.textBoxInput.Text))
{
this.DialogResult = DialogResult.OK;

View File

@ -11,6 +11,9 @@ public partial class Loader : Form
private void loaderStart_LoadProject(object sender, string projectFilePath)
{
if(this.DesignMode)
return;
this.DataFile = projectFilePath;
this.DialogResult = DialogResult.OK;
this.Close();