public void CreateTextEditor(string caption, string script) { frmTextEditor frm = null; try { frm = TextEditorFactory.Create(caption, script); TextEditorFactory.ShowTextEditor(frm); } catch (Exception ex) { frm.Dispose(); frm = null; throw ex; } }
private void btnNewScript_Click(object sender, EventArgs e) { frmTextEditor editor = TextEditorFactory.Create(); TextEditorFactory.ShowTextEditor(editor); }
private void PerformRestore() { ConnectionParams cp = null; IList <frmTextEditor> textEditors = new List <frmTextEditor>(); IList <frmScriptEditor> scriptEditors = new List <frmScriptEditor>(); StringBuilder sbErrors = new StringBuilder(); bool showTextEditorInfoHeader = false; bool failedConnections = false; string scriptWarningText = String.Empty; InitializeProgress(lv.CheckedItems.Count); try { foreach (ListViewItem lvItem in lv.Items) { cp = null; scriptWarningText = String.Empty; RecoverContent item = lvItem.Tag as RecoverContent; if (!lvItem.Checked || item == null) { continue; } string itemCaption = item.Title; failedConnections = false; showTextEditorInfoHeader = false; frmTextEditor txtEditor = null; frmScriptEditor scriptEditor = null; try { if (item.ItemType == RecoverContentType.Script || item.ItemType == RecoverContentType.ScriptFile) { if (item.HasConnectionInfo) { cp = PrepareWorkspaceItemConnection(item, out failedConnections); if (cp == null && !failedConnections) { Utils.ShowWarning(String.Format(Properties.Resources.RecoverScriptWarning, item.Database, item.Server), MessageBoxButtons.OK); } } if (cp == null) { item.SyntaxMode = "SQL"; if (item.ItemType == RecoverContentType.Script) { item.ItemType = RecoverContentType.Text; } else if (item.ItemType == RecoverContentType.ScriptFile) { item.ItemType = RecoverContentType.TextFile; } showTextEditorInfoHeader = true; scriptWarningText = !item.HasConnectionInfo ? Properties.Resources.RecoverScript_NoConnWarningInfoHeader : String.Format(Properties.Resources.RecoverScriptWarningInfoHeader, item.Database, item.Server); } else { if (item.ItemType == RecoverContentType.Script) { scriptEditor = ScriptEditorFactory.CreateWithAsyncConnection(itemCaption, item.Content, cp, cp.Database, String.Empty); } else if (item.ItemType == RecoverContentType.ScriptFile) { scriptEditor = ScriptEditorFactory.CreateWithAsyncConnection(itemCaption, item.Content, cp, cp.Database, item.FileName); } scriptEditor.Uid = item.Uid; scriptEditor.IsRecoveredContent = true; scriptEditor.ObjectType = item.ObjectType; if (OpMode == OperationMode.Recover) { scriptEditor.ShowInfo(String.Format("Recovered content. Content automatically saved on {0}", DateTime.FromFileTime(item.Time))); } scriptEditors.Add(scriptEditor); } } txtEditor = null; switch (item.ItemType) { case RecoverContentType.Script: case RecoverContentType.ScriptFile: break; case RecoverContentType.SharedScript: txtEditor = TextEditorFactory.CreateSharedScript(itemCaption, item.Content); txtEditor.SetSyntaxMode("SQL"); txtEditor.Uid = item.Uid; txtEditor.IsRecoveredContent = true; break; case RecoverContentType.SharedSnippet: txtEditor = TextEditorFactory.CreateSharedSnippet(itemCaption, item.Content); txtEditor.SetSyntaxMode("SQL"); txtEditor.Uid = item.Uid; txtEditor.IsRecoveredContent = true; break; case RecoverContentType.Text: txtEditor = TextEditorFactory.Create(itemCaption, item.Content, item.SyntaxMode); txtEditor.Uid = item.Uid; txtEditor.IsRecoveredContent = true; break; case RecoverContentType.TextFile: txtEditor = TextEditorFactory.Create(itemCaption, item.Content, item.SyntaxMode, item.FileName); txtEditor.Uid = item.Uid; txtEditor.IsRecoveredContent = true; break; default: throw new Exception(String.Format("Unknowm item type: {0}", item.ItemType)); } if (txtEditor != null) { if (showTextEditorInfoHeader) { txtEditor.ShowInfo(scriptWarningText); } else if (OpMode == OperationMode.Recover) { txtEditor.ShowInfo(String.Format("Recovered content. Automatically saved on: {0}", DateTime.FromFileTime(item.Time))); } textEditors.Add(txtEditor); } ChangeProgress(String.Format("Restoring {0}", item.Title)); } catch (Exception ex) { sbErrors.AppendLine(String.Format("- Can not restore '{0} ({1})'. Error: {2}", item.Title, item.ItemType, ex.Message)); } Application.DoEvents(); } } finally { ResetProgress(); } try { this.Visible = false; foreach (frmTextEditor editor in textEditors) { TextEditorFactory.ShowTextEditor(editor); } foreach (frmScriptEditor editor in scriptEditors) { ScriptEditorFactory.ShowScriptEditor(editor); } } catch (Exception ex) { this.Visible = true; throw ex; } if (sbErrors.Length > 0) { GenericErrorDialog.ShowError("Content Restore Error", "Some content items can not be restored.", sbErrors.ToString()); } }
private void OnAction_NewScript_Execute(object sender, EventArgs e) { frmTextEditor editor = TextEditorFactory.Create(); TextEditorFactory.ShowTextEditor(editor); }