コード例 #1
0
        internal static void myDockableDialog()
        {
            if (frmMyDlg == null || frmMyDlg.IsDisposed)
            {
                frmMyDlg = new frmMyDlg();

                using (Bitmap newBmp = new Bitmap(16, 16))
                {
                    Graphics   g        = Graphics.FromImage(newBmp);
                    ColorMap[] colorMap = new ColorMap[1];
                    colorMap[0]          = new ColorMap();
                    colorMap[0].OldColor = Color.Fuchsia;
                    colorMap[0].NewColor = Color.FromKnownColor(KnownColor.ButtonFace);
                    ImageAttributes attr = new ImageAttributes();
                    attr.SetRemapTable(colorMap);
                    g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
                    tbIcon = Icon.FromHandle(newBmp.GetHicon());
                }

                NppTbData _nppTbData = new NppTbData();
                _nppTbData.hClient       = frmMyDlg.Handle;
                _nppTbData.pszName       = "SnippetExecutor Console";
                _nppTbData.dlgID         = idMyDlg;
                _nppTbData.uMask         = NppTbMsg.DWS_DF_CONT_BOTTOM; // | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
                _nppTbData.hIconTab      = (uint)tbIcon.Handle;
                _nppTbData.pszModuleName = PluginName;
                IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
                Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);

                debug = frmMyDlg.getIOToConsole();  //update the debug IO

                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
            }
            else
            {
                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, frmMyDlg.Handle);
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: gburgett/SnippetExecutor
        internal static void myDockableDialog()
        {
            if (frmMyDlg == null || frmMyDlg.IsDisposed)
            {
                frmMyDlg = new frmMyDlg();

                using (Bitmap newBmp = new Bitmap(16, 16))
                {
                    Graphics g = Graphics.FromImage(newBmp);
                    ColorMap[] colorMap = new ColorMap[1];
                    colorMap[0] = new ColorMap();
                    colorMap[0].OldColor = Color.Fuchsia;
                    colorMap[0].NewColor = Color.FromKnownColor(KnownColor.ButtonFace);
                    ImageAttributes attr = new ImageAttributes();
                    attr.SetRemapTable(colorMap);
                    g.DrawImage(tbBmp_tbTab, new Rectangle(0, 0, 16, 16), 0, 0, 16, 16, GraphicsUnit.Pixel, attr);
                    tbIcon = Icon.FromHandle(newBmp.GetHicon());
                }

                NppTbData _nppTbData = new NppTbData();
                _nppTbData.hClient = frmMyDlg.Handle;
                _nppTbData.pszName = "SnippetExecutor Console";
                _nppTbData.dlgID = idMyDlg;
                _nppTbData.uMask = NppTbMsg.DWS_DF_CONT_BOTTOM; // | NppTbMsg.DWS_ICONTAB | NppTbMsg.DWS_ICONBAR;
                _nppTbData.hIconTab = (uint) tbIcon.Handle;
                _nppTbData.pszModuleName = PluginName;
                IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
                Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);

                debug = frmMyDlg.getIOToConsole();  //update the debug IO

                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);
            }
            else
            {
                Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_DMMSHOW, 0, frmMyDlg.Handle);
            }
        }
コード例 #3
0
        internal static void CompileSnippet()
        {
            Logger log = null;

            try
            {
                log = Logger.CreateLogger();
                try
                {
                    IntPtr currScint = PluginBase.GetCurrentScintilla();

                    myDockableDialog();
                    IO console = frmMyDlg.getIOToConsole();


                    log.Log("compile snippet");

                    int           len = (int)Win32.SendMessage(currScint, SciMsg.SCI_GETSELTEXT, 0, 0);
                    StringBuilder text;

                    if (len > 1)
                    {
                        //a selection exists
                        text = new StringBuilder(len);
                        Win32.SendMessage(currScint, SciMsg.SCI_GETSELTEXT, 0, text);
                    }
                    else
                    {
                        //no selection, parse whole file
                        len  = (int)Win32.SendMessage(currScint, SciMsg.SCI_GETTEXT, 0, 0);
                        text = new StringBuilder(len);
                        Win32.SendMessage(currScint, SciMsg.SCI_GETTEXT, len, text);
                    }


                    if (text.Length == 0)
                    {
                        console.writeLine("No Text");
                        return;
                    }

                    //create defaults
                    SnippetInfo info = new SnippetInfo();
                    info.language = LangType.L_TEXT;
                    int langtype = (int)LangType.L_TEXT;
                    Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTLANGTYPE, 0, out langtype);
                    info.language        = (LangType)langtype;
                    info.stdIO           = console;
                    info.console         = console;
                    info.preprocessed    = text.ToString();
                    info.runCmdLine      = String.Empty;
                    info.compilerCmdLine = String.Empty;
                    info.options         = new Hashtable();

                    StringBuilder sb = new StringBuilder(Win32.MAX_PATH);
                    Win32.SendMessage(PluginBase.nppData._nppHandle, NppMsg.NPPM_GETCURRENTDIRECTORY, Win32.MAX_PATH, sb);
                    info.workingDirectory = sb.ToString();

                    //process overrides
                    try
                    {
                        PreprocessSnippet(ref info, text.ToString());
                    }
                    catch (Exception ex)
                    {
                        console.writeLine("\r\n\r\n--- SnippetExecutor " + DateTime.Now.ToShortTimeString() + " ---");
                        console.writeLine("Exception processing snippet");
                        Main.HandleException(console, ex);
                        return;
                    }

                    console = info.console;

                    console.writeLine("\r\n\r\n--- SnippetExecutor " + DateTime.Now.ToShortTimeString() + " ---");

                    foreach (DictionaryEntry pair in info.options)
                    {
                        console.writeLine(pair.Key.ToString() + ":" + pair.Value.ToString());
                    }

                    //get correct compiler for language
                    info.compiler = getCompilerForLanguage(info.language);

                    info.compiler.console = info.console;
                    info.compiler.stdIO   = info.stdIO;
                    foreach (DictionaryEntry e in info.options)
                    {
                        info.compiler.options.Add(e.Key, e.Value);
                    }

                    Thread th = new Thread(
                        delegate()
                    {
                        Logger logInner = Logger.CreateLogger();
                        try
                        {
                            console.writeLine("-- Generating source for snippet...");
                            info.postprepared = info.compiler.PrepareSnippet(info.postprocessed);

                            if (info.options.ContainsKey("source"))
                            {
                                IO writer = console;
                                writer.writeLine();
                                if (!String.IsNullOrEmpty((string)info.options["source"]))
                                {
                                    string opt = (info.options["source"] as string);
                                    if (!String.IsNullOrEmpty(opt))
                                    {
                                        try
                                        {
                                            writer = ioForOption(opt, info);
                                        }
                                        catch (Exception ex)
                                        {
                                            console.writeLine("Cannot write to " + opt);
                                            console.writeLine(ex.Message);
                                            return;
                                        }
                                    }
                                }
                                writer.write(info.postprepared);
                            }

                            if (String.IsNullOrEmpty(info.postprepared))
                            {
                                return;
                            }

                            info.compilerCmdLine = (string)info.options["compile"];
                            console.writeLine("\r\n-- compiling source with options " + info.compilerCmdLine);
                            info.executable = info.compiler.Compile(info.postprepared, info.compilerCmdLine);

                            if (info.executable == null)
                            {
                                return;
                            }

                            EventHandler cancelDelegate = delegate(object sender, EventArgs e)
                            {
                                info.compiler.Cancel();
                                console.write("-- Cancelling --");
                            };
                            frmMyDlg.CancelRunButtonClicked += cancelDelegate;

                            info.compiler.workingDirectory = info.workingDirectory;

                            info.runCmdLine = (string)info.options["run"];
                            console.writeLine("-- running with options " + info.runCmdLine + " --");
                            info.compiler.execute(info.executable, info.runCmdLine);
                            console.writeLine("\r\n-- finished run --");

                            frmMyDlg.CancelRunButtonClicked -= cancelDelegate;
                        }
                        catch (Exception ex)
                        {
                            Main.HandleException(console, ex);
                            return;
                        }
                        finally
                        {
                            if (info.executable != null)
                            {
                                info.compiler.cleanup(info);
                            }

                            console.Dispose();
                            info.stdIO.Dispose();
                            logInner.Dispose();
                        }
                    }
                        );



                    th.Start();
                }
                catch (Exception ex)
                {
                    if (Main.debug != null)
                    {
                        Main.HandleException(Main.debug, ex);
                    }
                    else
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error creating logger: " + ex.ToString());
            }
            finally
            {
                if (log != null)
                {
                    log.Dispose();
                }
            }
        }