public void LoadTextFile(string fileName) { frmTextEditor frm = null; try { frm = TextEditorFactory.OpenFile(fileName); TextEditorFactory.ShowTextEditor(frm); } catch (Exception ex) { frm.Dispose(); frm = null; throw ex; } }
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; } }
public static bool OpenSharedScripts(IPragmaEditor currentEditor, ConnectionParams cp) { bool result = false; if (currentEditor != null && currentEditor.ContentModified) { DialogResult dlgRes = MessageBox.Show("Save changes to \"" + currentEditor.Caption + "\" before opening another script in current script editor", "Save Script", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dlgRes == DialogResult.Cancel) { return(false); } else if (dlgRes == DialogResult.Yes) { currentEditor.SaveContent(); } } IList <IPragmaEditor> editors = new List <IPragmaEditor>(); IList <SharedScriptsItemData> scripts = frmSharedScriptSelectDialog.ShowOpenSharedScriptDialog_MultiSelect(); int i = 0; IPragmaEditor frm = null; foreach (SharedScriptsItemData data in scripts) { if (data.Type != GenericItemType.Item) { continue; } i++; if (i == 1 && currentEditor != null) { currentEditor.Caption = data.Name; currentEditor.Icon = PragmaSQL.Properties.Resources.sharedScript; currentEditor.ContentPersister = new SharedScriptContentPersister(); currentEditor.ContentPersister.Data = data; currentEditor.ContentPersister.Hint = "This is a shared script: " + data.Name; currentEditor.ContentInfo = currentEditor.ContentPersister.Hint; currentEditor.ContentPersister.FilePath = data.Name; currentEditor.ActiveDocument.TextContent = data.Script; currentEditor.ContentModified = false; result = true; continue; } if (cp != null) { frm = ScriptEditorFactory.OpenSharedScript(data, cp); editors.Add(frm); } else { frm = TextEditorFactory.OpenSharedScript(data); editors.Add(frm); } } foreach (IPragmaEditor editor in editors) { if (editor is frmScriptEditor) { ScriptEditorFactory.ShowScriptEditor(editor as frmScriptEditor); } else if (editor is frmTextEditor) { TextEditorFactory.ShowTextEditor(editor as frmTextEditor); } } return(result); }
private void btnNewScript_Click(object sender, EventArgs e) { frmTextEditor editor = TextEditorFactory.Create(); TextEditorFactory.ShowTextEditor(editor); }
private void ReclaimWindowNumber_OnClose() { ReclaimWindowNumber(); TextEditorFactory.Numerator.WindowCount--; TextEditorFactory.ResetNumerator(); }
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_OpenFromFile_Execute(object sender, EventArgs e) { frmTextEditor editor = TextEditorFactory.OpenFile(String.Empty); TextEditorFactory.ShowTextEditor(editor); }
private void OnAction_NewScript_Execute(object sender, EventArgs e) { frmTextEditor editor = TextEditorFactory.Create(); TextEditorFactory.ShowTextEditor(editor); }