forked from ReClassNET/ReClass.NET-PythonScriptingPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptEditorForm.cs
More file actions
73 lines (58 loc) · 1.76 KB
/
ScriptEditorForm.cs
File metadata and controls
73 lines (58 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Windows.Forms;
using ReClassNET.Forms;
using ReClassNET.UI;
namespace PythonScriptingPlugin.Forms
{
public partial class ScriptEditorForm : IconForm
{
private readonly List<ScriptContent> scripts;
private readonly BindingSource scriptsBindingSource;
public ScriptEditorForm(List<ScriptContent> scripts)
{
Contract.Requires(scripts != null);
this.scripts = scripts;
InitializeComponent();
scriptsBindingSource = new BindingSource
{
DataSource = scripts
};
scriptsListBox.DataSource = scriptsBindingSource;
scriptsListBox.DisplayMember = "Name";
scriptNameTextBox.DataBindings.Add("Text", scriptsBindingSource, "Name", true, DataSourceUpdateMode.OnPropertyChanged);
scriptContentTextBox.DataBindings.Add("Text", scriptsBindingSource, "Content", true, DataSourceUpdateMode.OnPropertyChanged);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GlobalWindowManager.AddWindow(this);
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
GlobalWindowManager.RemoveWindow(this);
}
private void addScriptIconButton_Click(object sender, EventArgs e)
{
scripts.Add(new ScriptContent { Name = "New Script" });
scriptsBindingSource.ResetBindings(false);
}
private void deleteScriptIconButton_Click(object sender, EventArgs e)
{
if (!(scriptsListBox.SelectedItem is ScriptContent script))
{
return;
}
if (MessageBox.Show($"Do you really want to delete the script '{script.Name}'?", "Script", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
if (scripts.Remove(script))
{
scriptsBindingSource.ResetBindings(false);
}
}
}
}