-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
159 lines (126 loc) · 5.43 KB
/
Form1.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
151
152
153
154
155
156
157
158
159
using FastColoredTextBoxNS;
using System.Diagnostics;
using System.Windows.Forms;
namespace osmonIdeTiny
{
public partial class Form1 : Form
{
Style styleKeyword = new TextStyle(Brushes.Blue, null, FontStyle.Bold);
Style styleString = new TextStyle(Brushes.Red, null, FontStyle.Regular);
Style styleComment = new TextStyle(Brushes.Green, null, FontStyle.Italic);
public Form1()
{
InitializeComponent();
mainEditorBox.TextChanged += mainEditorBox_TextChanged;
}
private void ochishToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void yangiToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void shriftToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog fontDialog = new FontDialog();
if (fontDialog.ShowDialog() == DialogResult.OK)
{
mainEditorBox.Font = fontDialog.Font;
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Osmon files (*.osm)|*.osm|All files (*.*)|*.*";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = openFileDialog.FileName;
string fileContents = File.ReadAllText(fileName);
mainEditorBox.Text = fileContents;
}
}
private void toolStripButton6_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Osmon files (*.osm)|*.osm";
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string fileName = saveFileDialog.FileName;
string fileContents = mainEditorBox.Text;
File.WriteAllText(fileName, fileContents);
}
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
}
private void mainEditorBox_Load(object sender, EventArgs e)
{
}
private void mainEditorBox_TextChanged(object sender, TextChangedEventArgs e)
{
e.ChangedRange.ClearStyle(styleKeyword, styleString, styleComment);
// Define the regular expressions to match the different parts of the code
string keywords = @"\b(if|else|while|for|foreach|break|continue|ha|yoq|joy|agar|tuga|unda|toki|qachonki|qayta|toxta|qaytar|yangi|funksiya|nol|tur|shu|guruh|label|goto)\b";
string strings = "\"(.*?)\"";
string comments = @"//(.*?)$|/\*(.*?)\*/";
// Apply the styles to the matching ranges of text in the control
e.ChangedRange.SetStyle(styleKeyword, keywords);
e.ChangedRange.SetStyle(styleString, strings);
e.ChangedRange.SetStyle(styleComment, comments);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void korinishToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
// Get the path of the selected file
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "OSM files (*.osm)|*.osm";
if (openFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
string programName = openFileDialog.FileName;
// Build the command to execute
string command = "osmon.exe \"" + programName + "\"";
// Start the process and redirect standard output and error
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c " + command;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = startInfo;
// Attach event handlers to capture output and error messages
process.OutputDataReceived += new DataReceivedEventHandler((s, args) =>
{
if (!string.IsNullOrEmpty(args.Data))
{
// Write output to the console and the output textbox
Console.WriteLine(args.Data);
terminalBox.AppendText(args.Data + Environment.NewLine);
}
});
process.ErrorDataReceived += new DataReceivedEventHandler((s, args) =>
{
if (!string.IsNullOrEmpty(args.Data))
{
// Write error messages to the console and the output textbox
Console.WriteLine("Error: " + args.Data);
terminalBox.AppendText("Error: " + args.Data + Environment.NewLine);
}
});
// Start the process and begin reading from its output streams
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
}
}