private void DisplayPCode(object sender, RoutedEventArgs e) { try { if (disp == null) { disp = new DisplayWindow(this); } MenuItem item = sender as MenuItem; char level = ((string)item.Header)[0]; int Level = 0; switch (level) { case '1': Level = 1; break; case '2': Level = 2; break; case '3': Level = 3; break; } PCodeGeneraotr pg = new PCodeGeneraotr(); pg.GenerateCode(CodeEditor.Text, Level); disp.Show(pg.GetPCodeString()); } catch (Exception ex) { MessageBox.Show($"编译PCode的时候遇到错误 {ex.Message}", "错误"); disp = new DisplayWindow(this); } }
private void ExportPCode(object sender, RoutedEventArgs e) { try { List <ErrorInfo> list = ErrorList.ItemsSource as List <ErrorInfo>; if (list.Count > 0) { StatusContent.Text = "在执行前请改正所有错误"; return; } MenuItem item = sender as MenuItem; char level = ((string)item.Header)[0]; int Level = 0; switch (level) { case '1': Level = 1; break; case '2': Level = 2; break; case '3': Level = 3; break; } string code = new string(CodeEditor.Text.ToCharArray()); SaveFileDialog dialog = new SaveFileDialog(); bool? result = dialog.ShowDialog(); if (result.Value) { PCodeGeneraotr generaotr = new PCodeGeneraotr(); generaotr.GenerateCode(code, Level); TextWriter writer = new StreamWriter(File.Create(dialog.FileName)); Console.SetOut(writer); Console.WriteLine(generaotr.GetPCodeString()); writer.Flush(); writer.Dispose(); Console.SetOut(Console.Out); StatusContent.Text = "PCode导出成功"; } } catch (Exception ex) { MessageBox.Show($"导出PCode的时候遇到错误 {ex.Message}", "错误"); } }