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

View File

@ -13,6 +13,8 @@ public partial class SectionTree : UserControl
public SectionTree() public SectionTree()
{ {
this.InitializeComponent(); this.InitializeComponent();
if(this.DesignMode)
return;
// Get the DI context from the main form: // Get the DI context from the main form:
this.db = Program.SERVICE_PROVIDER.GetService<DataContext>()!; this.db = Program.SERVICE_PROVIDER.GetService<DataContext>()!;
@ -35,6 +37,9 @@ public partial class SectionTree : UserControl
private async void LoadNodes(object? sender, EventArgs e) private async void LoadNodes(object? sender, EventArgs e)
{ {
if(this.DesignMode)
return;
// A dictionary to cache all known tree nodes: // A dictionary to cache all known tree nodes:
var treeNodes = new Dictionary<string, TreeNode>(); var treeNodes = new Dictionary<string, TreeNode>();
@ -112,6 +117,9 @@ public partial class SectionTree : UserControl
private async void buttonAdd_Click(object sender, EventArgs e) private async void buttonAdd_Click(object sender, EventArgs e)
{ {
if(this.DesignMode)
return;
var result = InputDialog.Show(new InputDialog.Options( var result = InputDialog.Show(new InputDialog.Options(
Message: "Please type the desired section name.", Message: "Please type the desired section name.",
Title: "Add a section", Title: "Add a section",
@ -151,6 +159,9 @@ public partial class SectionTree : UserControl
private async void buttonRemove_Click(object sender, EventArgs e) private async void buttonRemove_Click(object sender, EventArgs e)
{ {
if(this.DesignMode)
return;
// Get the currently selected section, which will be removed: // Get the currently selected section, which will be removed:
var selectedNode = this.treeView.SelectedNode; var selectedNode = this.treeView.SelectedNode;
@ -175,6 +186,9 @@ public partial class SectionTree : UserControl
private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) private void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{ {
if(this.DesignMode)
return;
// Get the currently selected section: // Get the currently selected section:
var selectedNode = this.treeView.SelectedNode; var selectedNode = this.treeView.SelectedNode;
@ -184,6 +198,9 @@ public partial class SectionTree : UserControl
private async void buttonRename_Click(object sender, EventArgs e) private async void buttonRename_Click(object sender, EventArgs e)
{ {
if(this.DesignMode)
return;
// Ask the user if he really wants to rename the section: // 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) 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; return;

View File

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

View File

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

View File

@ -3,12 +3,12 @@
partial class Main partial class Main
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
@ -23,8 +23,8 @@
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {