-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
150 lines (126 loc) · 5.59 KB
/
MainWindow.xaml.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using ARPA_Programming_Language.Antlr4;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
namespace ARPA.IDE
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitializeMonacoEditor();
}
private async void InitializeMonacoEditor()
{
// WebView2'nin başlatılmasını bekleyin
await MonacoEditorWebView.EnsureCoreWebView2Async(null);
// Monaco Editor HTML dosyasını yükleyin
var indexPath = Path.Combine(Directory.GetCurrentDirectory(), "index.html");
MonacoEditorWebView.CoreWebView2.Navigate(indexPath);
}
private async void ButtonRun_Click(object sender, RoutedEventArgs e)
{
try
{
// Monaco Editor'den yazılan kodu al
string text = await MonacoEditorWebView.ExecuteScriptAsync("window.editor.getValue();");
// Gelen string JSON formatında olabilir, bunu düzenle:
text = text.Trim('"').Replace("\\n", "\n").Replace("\\r", "\r").Replace("\\t", "\t");
// Unicode kaçış karakterlerini çözümlemek için bir Regex kullan
text = Regex.Unescape(text);
// Kaçış karakterlerini kaldır (örn. \\u003C yerine < koy)
text = Regex.Replace(text, @"\\u([0-9A-Fa-f]{4})", m => ((char)int.Parse(m.Groups[1].Value, System.Globalization.NumberStyles.HexNumber)).ToString());
var interpreter = new ARPAInterpreter();
// Kodu çalıştır
interpreter.Execute(text);
StringBuilder output = interpreter._output;
// Çıktıyı temizle ve ekrana yazdır
string cleanedOutput = output.ToString().Replace("\\", "");
TextBoxOutput.Text = cleanedOutput;
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
private void MenuItemDocumentation_Click(object sender, RoutedEventArgs e)
{
DocumentationWindow documentationWindow = new DocumentationWindow();
documentationWindow.ShowDialog();
}
private async void MenuItemNew_Click(object sender, RoutedEventArgs e)
{
if (MonacoEditorWebView.CoreWebView2 != null)
{
// Yeni bir dosya için editörü temizler.
await MonacoEditorWebView.ExecuteScriptAsync("window.editor.setValue('');");
}
}
private async void MenuItemOpen_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Filter = "ARPA Files (*.arp)|*.arp", // Sadece .arp uzantılı dosyaları açar
DefaultExt = ".arp"
};
if (openFileDialog.ShowDialog() == true)
{
string filePath = openFileDialog.FileName;
string fileContent = File.ReadAllText(filePath);
if (MonacoEditorWebView.CoreWebView2 != null)
{
// Seçilen dosyanın içeriğini Monaco Editör'e yükle.
await MonacoEditorWebView.ExecuteScriptAsync($"window.editor.setValue(`{fileContent}`);");
}
}
}
private async void MenuItemSave_Click(object sender, RoutedEventArgs e)
{
// SaveFileDialog kullanarak dosya kaydetme işlemi
Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog
{
Filter = "ARPA Files (*.arp)|*.arp", // Sadece .arp uzantılı dosyaları kaydeder
DefaultExt = ".arp"
};
if (saveFileDialog.ShowDialog() == true)
{
string filePath = saveFileDialog.FileName;
if (MonacoEditorWebView.CoreWebView2 != null)
{
// Monaco Editör'den mevcut içeriği al
string editorContent = await MonacoEditorWebView.ExecuteScriptAsync("window.editor.getValue();");
// İçeriği dosyaya kaydet
File.WriteAllText(filePath, editorContent);
}
}
}
private async void ThemeComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
//if (MonacoEditorWebView.CoreWebView2 != null && ThemeComboBox.SelectedItem is ComboBoxItem selectedItem)
//{
// string themeName = selectedItem.Content.ToString();
// switch (themeName)
// {
// case "Light":
// await MonacoEditorWebView.ExecuteScriptAsync("monaco.editor.setTheme('vs');");
// break;
// case "Dark":
// await MonacoEditorWebView.ExecuteScriptAsync("monaco.editor.setTheme('vs-dark');");
// break;
// case "High Contrast":
// await MonacoEditorWebView.ExecuteScriptAsync("monaco.editor.setTheme('hc-black');");
// break;
// }
//}
}
private void ThemeComboBox_Loaded(object sender, RoutedEventArgs e)
{
ThemeComboBox.SelectedIndex = 0;
}
}
}