static void beNotified(IntPtr notifyCode) { try { SCNotification nc = (SCNotification)Marshal.PtrToStructure(notifyCode, typeof(SCNotification)); if (nc.nmhdr.code == (uint)NppMsg.NPPN_TBMODIFICATION) { Plugin.FuncItems.RefreshItems(); Plugin.RefreshToolbarImages(); } else if (nc.nmhdr.code == (uint)SciMsg.SCN_CHARADDED) { } else if (nc.nmhdr.code == (uint)NppMsg.NPPN_READY) { CSScriptIntegration.Initialize(); Plugin.InitView(); } else if (nc.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN) { Marshal.FreeHGlobal(_ptrPluginName); Plugin.CleanUp(); } Plugin.OnNotification(nc); } catch { }//this is indeed the last line of defense as all CS-S calls have the error handling inside }
static public void ClearBuildError() { if (BuildOutputWriteLine != null) { CSScriptIntegration.BuildOutputWriteLine(""); } }
public void beNotified(IntPtr notifyCode) { lock (typeof(UnmanagedExports)) { try { ScNotification nc = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification)); string contentFile = Npp.Editor.GetTabFile(nc.Header.IdFrom); if (nc.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION) { PluginBase._funcItems.RefreshItems(); Plugin.RefreshToolbarImages(); } else if (nc.Header.Code == (uint)SciMsg.SCN_CHARADDED) { } else if (nc.Header.Code == (uint)NppMsg.NPPN_READY) { CSScriptIntegration.Initialize(); Plugin.InitView(); } else if (nc.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN) { Marshal.FreeHGlobal(_ptrPluginName); Plugin.CleanUp(); } Plugin.OnNotification(nc); } catch { }//this is indeed the last line of defense as all CS-S calls have the error handling inside } }
static public void ShowBuildError(string error) { if (BuildOutputWriteLine != null) { CSScriptIntegration.BuildOutputWriteLine(error); } else { MessageBox.Show(error, "Notepad++ Automation"); } }
static public object GetOutputPanel() { try { return(CSScriptIntegration.GetOutputPanel()); } catch { MessageBox.Show("CS-Script Output Panel cannot be found.\nPlease ensure you have CS-Script Plugin installed.", "Notepad++ Automation"); } return(null); }
static NppScript LoadScript(string file, int id) { try { CSScriptIntegration.ClearBuildError(); CSScript.CacheEnabled = true; bool debugScript = true; string asmFile = CSScript.CompileFile(file, null, debugScript, Assembly.GetExecutingAssembly().Location); string debugSymbols = Path.ChangeExtension(asmFile, ".pdb"); Assembly asm; if (File.Exists(debugSymbols) && debugScript) { asm = Assembly.Load(File.ReadAllBytes(asmFile), File.ReadAllBytes(debugSymbols)); } else { asm = Assembly.Load(File.ReadAllBytes(asmFile)); } object script = CreateObject(asm, "Script"); var retval = (NppScript)script; retval.ScriptFile = file; retval.ScriptId = id; retval.OnLoaded(); return(retval); } catch (UnauthorizedAccessException) { if (DialogResult.Yes == MessageBox.Show("The Script is locked. Restarting Notepad++ will release it.\nDo you want to restart it now?", "Notepad++ Automation", MessageBoxButtons.YesNo)) { var proc = System.Diagnostics.Process.GetProcessById(55); ScriptManager.RestartNpp(); } } catch (Exception e) { //MessageBox.Show("Script '" + file + "' is invalid.\n" + e.Message, "Notepad++ Automation"); CSScriptIntegration.ShowBuildError("Script '" + file + "' is invalid.\n" + e.Message); } return(new NppScriptStub { ScriptFile = file, ScriptId = id }); }