Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DesignTab.xaml.cs
1using ICSharpCode.AvalonEdit.Highlighting;
2using ICSharpCode.AvalonEdit.Highlighting.Xshd;
4using System;
5using System.ComponentModel;
6using System.IO;
7using System.Windows;
8using System.Windows.Controls;
9using System.Windows.Documents;
10using System.Xml;
12
13namespace LegalLab.Tabs
14{
18 public partial class DesignTab : UserControl
19 {
20 private readonly DesignModel model;
21
22 public DesignTab()
23 {
24 this.model = Types.InstantiateDefault<DesignModel>(false);
25 this.model.PropertyChanged += this.Model_PropertyChanged;
26
27 // Register AvalonEdit Syntax Highlighting for Smart Contract Markdown documents:
28
29 byte[] Bin = Waher.Content.Resources.LoadResource(typeof(DesignModel).Namespace + ".AvalonExtensions.SmartContractMarkdown.xshd", typeof(App).Assembly);
30 using MemoryStream ms = new(Bin);
31 using XmlReader r = XmlReader.Create(ms);
32 IHighlightingDefinition Def = HighlightingLoader.Load(r, HighlightingManager.Instance);
33 HighlightingManager.Instance.RegisterHighlighting(Def.Name, Array.Empty<string>(), Def);
34
36 }
37
38 private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
39 {
40 switch (e.PropertyName)
41 {
43 string Markdown = this.model.HumanReadableMarkdown;
44 if (Markdown != this.HumanReadableMarkdownEditor.Text)
45 this.HumanReadableMarkdownEditor.Text = Markdown;
46 break;
47
48 case nameof(DesignModel.MachineReadable):
49 string Xml = this.model.MachineReadable;
50 if (Xml != this.MachineReadableXmlEditor.Text)
51 this.MachineReadableXmlEditor.Text = Xml;
52 break;
53 }
54 }
55
56 private void OpenAiKey_PasswordChanged(object sender, RoutedEventArgs e)
57 {
58 this.model.OpenAiKey = this.OpenAiKey.Password;
59 }
60
61 private void Hyperlink_Click(object sender, RoutedEventArgs e)
62 {
63 if (sender is Hyperlink Link)
64 MainWindow.OpenUrl(Link.NavigateUri);
65 }
66
67 private void HumanReadableMarkdownEditor_TextChanged(object sender, EventArgs e)
68 {
69 this.model.HumanReadableMarkdown = this.HumanReadableMarkdownEditor.Text;
70 }
71
72 private void MachineReadableXmlEditor_TextChanged(object sender, EventArgs e)
73 {
74 this.model.MachineReadable = this.MachineReadableXmlEditor.Text;
75 }
76 }
77}
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static byte[] LoadResource(string ResourceName)
Loads a resource from an embedded resource.
Definition: Resources.cs:61
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition: Types.cs:14
static object InstantiateDefault(Type Type, params object[] Arguments)
Returns an instance of the type Type . If one needs to be created, it is. If the constructor requires...
Definition: Types.cs:1465
Definition: App.xaml.cs:4