public static CodeCompletionKeyHandler Attach(ScriptForm mainForm, TextEditorControl editor) { CodeCompletionKeyHandler h = new CodeCompletionKeyHandler(mainForm, editor); editor.ActiveTextAreaControl.TextArea.KeyEventHandler += h.TextAreaKeyEventHandler; // When the editor is disposed, close the code completion window editor.Disposed += h.CloseCodeCompletionWindow; return(h); }
public ScriptForm(PBObjLib.Application app) { m_App = app; InitializeComponent(); editor.ShowEOLMarkers = false; editor.ShowSpaces = false; editor.ShowTabs = false; editor.ShowInvalidLines = false; editor.SetHighlighting("C#"); workDir = Path.GetTempPath() + "gPBToolKit\\"; fullPathDummyFile = workDir + DummyFileName; if (!Directory.Exists(workDir)) { Directory.CreateDirectory(workDir); } if (!Directory.Exists(workDir + "\\CSharpCodeCompletion\\")) { Directory.CreateDirectory(workDir + "\\CSharpCodeCompletion"); } string indexFile = workDir + "CSharpCodeCompletion\\index.dat"; if (!File.Exists(fullPathDummyFile)) { string sh = @"using System; using System.Collections.Generic; using System.Text; using PBObjLib; using PBSymLib; using VBIDE; using System.Windows.Forms; namespace gPBToolKit { public class gkScript { // ���������� �������� ������� public static void StartScript(Display d) { foreach (Symbol s in d.Symbols) { if (s.Type == 7) { Value v = (Value)s; v.BackgroundColor = 32768; v.ShowUOM = true; } } Action(d.Application); } public static void Action(PBObjLib.Application m_App) { try { VBProject project = null; CodeModule codeModule = null; for (int i = 1; i <= ((VBE)m_App.VBE).VBProjects.Count; i++) { VBProject bufProject = ((VBE)m_App.VBE).VBProjects.Item(i); if (bufProject.FileName.ToLower() == m_App.ActiveDisplay.Path.ToLower()) // ���� �� ��������� ����� ������ { project = bufProject; break; } } if (project == null) { MessageBox.Show(""VBProject not found""); return; } codeModule = project.VBComponents.Item(""ThisDisplay"").CodeModule; try { string procName = ""Display_Open""; int procCountLine = -1, procStart = -1; try{ procStart = codeModule.get_ProcBodyLine(procName, vbext_ProcKind.vbext_pk_Proc); procCountLine = codeModule.get_ProcCountLines(procName, vbext_ProcKind.vbext_pk_Proc); } catch{} if (procStart > 0) codeModule.DeleteLines(procStart, procCountLine); string srvName = ""do51-dc1-du-pis.sgpz.gpp.gazprom.ru""; string rootModule = ""����""; string dispOpenText = string.Format(@"" Private Sub Display_Open() AVExtension1.Initialize """"{0}"""", """"{1}"""", ThisDisplay, Trend1 End Sub"", srvName, rootModule); codeModule.AddFromString(dispOpenText); } catch (Exception ex) { MessageBox.Show(ex.Message + "" ""+ ex.StackTrace); } } catch { } } } } "; UTF8Encoding asciEncoding = new UTF8Encoding(); FileStream fs = File.Create(fullPathDummyFile); fs.Write(asciEncoding.GetBytes(sh), 0, asciEncoding.GetByteCount(sh)); fs.Close(); } if (!File.Exists(indexFile)) { File.Create(indexFile).Close(); } editor.LoadFile(fullPathDummyFile); refList.Items.Add("System.dll"); refList.Items.Add("System.Drawing.dll"); refList.Items.Add("System.Windows.Forms.dll"); refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\OSIsoft.PBObjLib.dll"); refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\OSIsoft.PBSymLib.dll"); refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\Interop.VBIDE.dll"); CodeCompletionKeyHandler.Attach(this, editor); HostCallbackImplementation.Register(this); pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence caches referenced project contents for faster loading. // It also activates loading XML documentation files and caching them // for faster loading and lower memory usage. pcRegistry.ActivatePersistence(Path.Combine(workDir, "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); myProjectContent.Language = Dom.LanguageProperties.CSharp; }