private void btnSaveAll_Click(object sender, EventArgs e) { if (tcCodes.TabPages == null) { ShowMessage.Confirm("请先生成代码!"); return; } FolderBrowserDialog dlg = new FolderBrowserDialog(); if (dlg.ShowDialog() == DialogResult.OK) { foreach (TabPage page in tcCodes.TabPages) { Generator.Template generator = page.Tag as Generator.Template; generator.GenerateFile(dlg.SelectedPath); } } }
private void btnSaveCurrentTab_Click(object sender, EventArgs e) { if (tcCodes.SelectedTab == null) { ShowMessage.Confirm("请先生成代码!"); return; } Generator.Template generator = tcCodes.SelectedTab.Tag as Generator.Template; SaveFileDialog dlg = new SaveFileDialog(); dlg.AddExtension = true; dlg.FileName = generator.Name; dlg.Filter = string.Format(".{0}|*.{0}", generator.Ext); if (dlg.ShowDialog() == DialogResult.OK) { Generator.IOHelper.WriteFile(dlg.FileName, generator.Code); } }
/// <summary> /// 生成一个代码页 /// </summary> public void AddCodeTabPage(Generator.Template template) { try { ICSharpCode.TextEditor.TextEditorControl txt = new ICSharpCode.TextEditor.TextEditorControl(); txt.Dock = DockStyle.Fill; txt.ShowInvalidLines = false; TextEditor.SetStyleByExt(txt, template.Ext); txt.Text = template.Code; TabPage page = new TabPage(); page.Tag = template; page.Text = template.TemplateName; page.Controls.Add(txt); tcCodes.TabPages.Add(page); } catch (Exception ex) { ShowMessage.Error(string.Format("使用代码模板{0}生成代码文件失败。{1}", template.TemplateName, ex.Message)); throw; } }