Exemple #1
0
        static public void ToggleBreakpoint(int lineClick = -1)
        {
            var    document = Npp.GetCurrentDocument();
            string file     = Npp.Editor.GetCurrentFilePath();

            int line = 0;

            if (lineClick != -1)
            {
                line = lineClick;
            }
            else
            {
                line = document.GetCurrentLineNumber();
            }

            bool isAutoGenerated = file.EndsWith(".g.cs", StringComparison.OrdinalIgnoreCase);

            if (!isAutoGenerated)
            {
                ToggleBreakpoint(file, line);
            }

            if (OnBreakpointChanged != null)
            {
                OnBreakpointChanged();
            }
        }
Exemple #2
0
        public static void OnCurrentFileChanged()
        {
            string file     = Npp.Editor.GetCurrentFilePath();
            var    document = Npp.GetCurrentDocument();

            string dbg = CSScriptHelper.GetDbgInfoFile(file);

            if (File.Exists(dbg))
            {
                PlaceBreakPointsForCurrentTab();
            }

            if (!IsRunning)
            {
                OnNextFileOpenComplete = null;
                document.ClearIndicator(INDICATOR_DEBUGSTEP, 0, -1); //clear all document
            }
            else
            {
                if (OnNextFileOpenComplete != null)
                {
                    OnNextFileOpenComplete();
                    OnNextFileOpenComplete = null;
                }
            }

            if (OnBreakpointChanged != null)
            {
                OnBreakpointChanged();
            }
        }
Exemple #3
0
        void MembersList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (membersList.SelectedItem != null)
            {
                var info = (membersList.SelectedItem as MemberInfo);
                try
                {
                    membersList.SelectedItem = null;
                    if (info.Line != -1)
                    {
                        var document = Npp.GetCurrentDocument();

                        document.GrabFocus();

                        int currentLineNum  = document.GetCurrentLineNumber();
                        int prevLineEnd     = document.PositionFromLine(currentLineNum) - Environment.NewLine.Length;
                        int topScrollOffset = currentLineNum - document.GetFirstVisibleLine();

                        document.GotoLine(info.Line);
                        document.SetFirstVisibleLine(info.Line - topScrollOffset);
                    }
                }
                catch { } //it is expected to fail if the line does not contain the file content position spec. This is also the reason for not validating any "IndexOf" results.
            }
        }
Exemple #4
0
        static public void ShowCalltip(int position, string text)
        {
            var document = Npp.GetCurrentDocument();

            document.CallTipCancel();
            document.CallTipShow(position, text);
        }
Exemple #5
0
        public void RefreshContent()
        {
            string file = Npp.Editor.GetCurrentFilePath();

            if (file.IsScriptFile() || file.IsPythonFile())
            {
                membersList.Visible = true;
                if (file != currentFile)
                {
                    currentFile = file;

                    watcher.Path   = Path.GetDirectoryName(currentFile);
                    watcher.Filter = Path.GetFileName(currentFile);
                }

                var document = Npp.GetCurrentDocument();

                if (file.IsScriptFile())
                {
                    GenerateContent(document.GetTextBetween(0));
                }
                else if (file.IsPythonFile())
                {
                    GenerateContentPython(document.GetTextBetween(0));
                }
            }
            else
            {
                membersList.Visible = false;
            }
        }
Exemple #6
0
        static public void RemoveAllBreakpoints()
        {
            var document = Npp.GetCurrentDocument();

            foreach (var key in breakpoints.Keys)
            {
                document.DeleteMarker(breakpoints[key]);
                if (IsRunning)
                {
                    DebuggerServer.RemoveBreakpoint(key);
                }
            }
            breakpoints.Clear();

            foreach (string file in Npp.Editor.GetOpenFilesSafe())
            {
                string dbgInfo = CSScriptHelper.GetDbgInfoFile(file, false);
                if (File.Exists(dbgInfo))
                {
                    File.Delete(dbgInfo);
                }
            }

            if (OnBreakpointChanged != null)
            {
                OnBreakpointChanged();
            }
        }
        void MembersList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (membersList.SelectedItem != null)
            {
                var info = (membersList.SelectedItem as MemberInfo);
                try
                {
                    membersList.SelectedItem = null;
                    if (info.Line != -1)
                    {
                        var document = Npp.GetCurrentDocument();

                        document.GrabFocus();

                        int currentLineNum  = document.GetCurrentLineNumber();
                        int prevLineEnd     = document.PositionFromLine(currentLineNum) - Environment.NewLine.Length;
                        int topScrollOffset = currentLineNum - document.GetFirstVisibleLine();

                        document.GotoLine(info.Line - 1); // document counts line as 0-based
                        document.VerticalCentreCaret();

                        //// GetLineVisible just does not work, it returns true always
                        // var caretIsVisible = document.GetLineVisible(currentLineNum);
                        // if (caretIsVisible)
                        //     document.SetFirstVisibleLine(info.Line - topScrollOffset);
                        // else
                        //     document.EnsureVisible(info.Line - 1);
                    }
                }
                catch { } //it is expected to fail if the line does not contain the file content position spec. This is also the reason for not validating any "IndexOf" results.
            }
        }
Exemple #8
0
        private static void ShowBreakpointSourceLocation(FileLocation location)
        {
            if (lastLocation != null && lastLocation.IsSame(location))
            {
                return;
            }
            lastLocation = location;

            ClearDebuggingMarkers();
            var document = Npp.GetCurrentDocument();

            document.PlaceIndicator(INDICATOR_DEBUGSTEP, location.Start, location.End);
            document.PlaceMarker(MARK_DEBUGSTEP, location.Line);

            int start = document.GetFirstVisibleLine();
            int end   = start + document.LinesOnScreen();

            if (location.Line > end || location.Line < start)
            {
                document.SetFirstVisibleLine(Math.Max(location.Line - (end - start) / 2, 0));
            }

            document.SetCurrentPos(location.Start);
            document.ClearSelection(); //need this one as otherwise parasitic selection can be triggered

            Win32.SetForegroundWindow(Npp.Editor.Handle);
        }
Exemple #9
0
        void newBtn_Click(object sender, EventArgs e)
        {
            using (var input = new ScripNameInput())
            {
                if (input.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                string scriptName = NormalizeScriptName(input.ScriptName ?? "New Script");

                int index = Directory.GetFiles(CSScriptHelper.ScriptsDir, scriptName + "*.cs").Length;

                string newScript = Path.Combine(CSScriptHelper.ScriptsDir, scriptName + ".cs");
                if (index != 0)
                {
                    int count = 0;
                    do
                    {
                        count++;
                        index++;
                        newScript = Path.Combine(CSScriptHelper.ScriptsDir, string.Format("{0}{1}.cs", scriptName, index));
                        if (count > 10)
                        {
                            MessageBox.Show("Too many script files with the similar name already exists.\nPlease specify a different file name or clean up some existing scripts.", "CS-Script");
                        }
                    }while (File.Exists(newScript));
                }

                string scriptCode = (Config.Instance.ClasslessScriptByDefault ? defaultClasslessScriptCode : defaultScriptCode);
                if (!File.Exists(newScript))
                {
                    File.WriteAllText(newScript, scriptCode);

                    PluginBase.Editor.Open(newScript);
                    PluginBase.GetCurrentDocument().GrabFocus();

                    loadBtn.PerformClick();
                }
                else
                {
                    PluginBase.Editor.FileNew();
                    var document = PluginBase.GetCurrentDocument();
                    document.GrabFocus();
                    document.AddText(scriptCode);

                    // Win32.SendMessage(Npp.NppHandle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_NEW);
                    // Win32.SendMessage(Npp.CurrentScintilla, SciMsg.SCI_GRABFOCUS, 0, 0);
                    // Win32.SendMessage(Npp.CurrentScintilla, SciMsg.SCI_ADDTEXT, scriptCode.GetByteCount(), scriptCode);

                    //for some reason setting the lexer does not work
                    int SCLEX_CPP = 3;
                    Win32.SendMessage(Npp.GetCurrentDocument().Handle, SciMsg.SCI_SETLEXER, SCLEX_CPP, 0);
                    Win32.SendMessage(Npp.GetCurrentDocument().Handle, SciMsg.SCI_SETLEXERLANGUAGE, 0, "cpp");
                }
            }
        }
Exemple #10
0
        static public void SetCalltipTime(int milliseconds)
        {
            var document = Npp.GetCurrentDocument();

            //Color: 0xBBGGRR

            document.CallTipSetFore(new Colour(0, 0, 0));
            document.CallTipSetBack(new Colour(0xE3, 0xE3, 0xE3));

            document.SetMouseDwellTime(milliseconds);
        }
Exemple #11
0
        static public string GetStatementAtCaret()
        {
            var document = Npp.GetCurrentDocument();

            string expression = document.GetSelectedText();

            if (string.IsNullOrWhiteSpace(expression))
            {
                expression = document.GetStatementAtPosition();
            }
            return(expression);
        }
Exemple #12
0
        private static void ToggleBreakpoint(string file, int line)
        {
            RefreshBreakPointsFromContent();

            var document = Npp.GetCurrentDocument();

            string key = BuildBreakpointKey(file, line);

            if (breakpoints.ContainsKey(key))
            {
                document.DeleteMarker(breakpoints[key]);
                breakpoints.Remove(key);
                if (IsRunning)
                {
                    string actualKey = TranslateSourceBreakpoint(key);
                    DebuggerServer.RemoveBreakpoint(key);
                }
            }
            else
            {
                var validLine = document.ClosestNonEmptyLineTo(line);

                if (validLine != -1 && validLine != line)
                {
                    key  = BuildBreakpointKey(file, validLine);
                    line = validLine;
                }

                // after valid line was fount it is possible that it aleady has a brealpoint
                if (breakpoints.ContainsKey(key))
                {
                    document.DeleteMarker(breakpoints[key]);
                    breakpoints.Remove(key);
                    if (IsRunning)
                    {
                        string actualKey = TranslateSourceBreakpoint(key);
                        DebuggerServer.RemoveBreakpoint(key);
                    }
                }
                else
                {
                    var handle = document.PlaceMarker(MARK_BREAKPOINT, validLine);
                    breakpoints.Add(key, handle);
                    if (IsRunning)
                    {
                        string actualKey = TranslateSourceBreakpoint(key);
                        DebuggerServer.AddBreakpoint(actualKey);
                    }
                }
            }

            SaveBreakPointsFor(file);
        }
Exemple #13
0
        static public void OnCalltipRequest(int position)
        {
            if (position == -2)
            {
                Calltip.LastEval           =
                    Calltip.LastExpression = null; //if DBG frame is changed so clear the data
            }
            else
            {
                if (Calltip.IsShowing)
                {
                    return;
                }

                Calltip.IsShowing = true;

                Task.Factory.StartNew(() =>  //must be asynch to allow processing other Debugger notifications
                {
                    string underMouseExpression = Npp.GetCurrentDocument().GetStatementAtPosition(position);
                    string document             = Npp.Editor.GetCurrentFilePath();
                    string tooltip = null;

                    if (!string.IsNullOrEmpty(underMouseExpression))
                    {
                        //also need to check expression start position (if not debugging) as the same expression can lead to different tooltip
                        //NOTE: if DBG frame is changed the LastExpression is cleared
                        if (underMouseExpression == Calltip.LastExpression && Calltip.LastDocument == document)
                        {
                        }

                        if (tooltip == null)
                        {
                            if (CSScriptIntellisense.Config.Instance.ShowQuickInfoAsNativeNppTooltip)
                            {
                                tooltip = CSScriptIntellisense.Plugin.GetMemberUnderCursorInfo().FirstOrDefault();
                            }

                            Calltip.LastDocument   = document;
                            Calltip.LastEval       = tooltip.TruncateLines(Config.Instance.CollectionItemsInTooltipsMaxCount, "\n<Content was truncated. Use F12 to see the raw API documentation data.>");
                            Calltip.LastExpression = underMouseExpression;
                        }

                        if (tooltip != null)
                        {
                            npp.ShowCalltip(position, tooltip);
                            return;
                        }
                    }

                    Calltip.IsShowing = false;
                });
            }
        }
Exemple #14
0
 private static void ClearDebuggingMarkers()
 {
     if (lastLocation != null)
     {
         var document = Npp.GetCurrentDocument();
         if (string.Compare(Npp.Editor.GetCurrentFilePath(), lastLocation.File, true) == 0)
         {
             document.ClearIndicator(INDICATOR_DEBUGSTEP, lastLocation.Start, lastLocation.End);
             document.DeleteAllMarkers(MARK_DEBUGSTEP);
         }
     }
 }
Exemple #15
0
        static public void SetCalltipTime(int milliseconds)
        {
            var    document = Npp.GetCurrentDocument();
            IntPtr sci      = PluginBase.GetCurrentScintilla();
            var    ttt      = document.GetMouseDwellTime();

            //Color: 0xBBGGRR

            document.CallTipSetFore(new Colour(0, 0, 0));
            document.CallTipSetBack(new Colour(0xE3, 0xE3, 0xE3));

            document.SetMouseDwellTime(milliseconds);
        }
Exemple #16
0
        static public void SetInstructionPointer()
        {
            if (IsRunning && IsInBreak)
            {
                ClearDebuggingMarkers();
                var document = Npp.GetCurrentDocument();

                int line = TranslateSourceLineLocation(Npp.Editor.GetCurrentFilePath(), document.GetCurrentLineNumber());

                DebuggerServer.SetInstructionPointer(line + 1); //debugger is 1-based
                DebuggerServer.Break();                         //need to break to trigger reporting the current step
            }
        }
Exemple #17
0
        public static void UpdateBreakPointsFromContent()
        {
            // remove no longer active break point handles and update the valid ones
            var currFile = Npp.Editor.GetCurrentFilePath();
            var document = Npp.GetCurrentDocument();

            foreach (string key in breakpoints.Keys.ToArray())
            {
                //IMPORTANT: GetLineOfMarker returns line form the handle of the marker within a
                //current file. Value of handles are file specific and reused between the files/documents.
                //This is because marker handles are just marker indexes within a document.
                //Thus resolving a given handle for a non current document can in fact return a proper line
                //of the current doc if it has the marker with the same handle value. This already led to
                //the break points drifting.

                if (!key.StartsWith(currFile, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                IntPtr marker = breakpoints[key];
                if (marker != IntPtr.Zero)
                {
                    int line = document.GetLineOfMarker(marker);
                    if (line != -1 && !key.EndsWith("|" + (line + 1)))
                    {
                        Debug.WriteLine($@"Save BP Line: {line}");
                        //key = <file>|<line + 1> //server debugger operates in '1-based' and NPP in '0-based' lines
                        string file = key.Split('|').First();

                        string newKey = file + "|" + (line + 1);

                        breakpoints.Remove(key);
                        if (!breakpoints.ContainsKey(newKey))
                        {
                            breakpoints.Add(newKey, marker);
                        }
                        else
                        {
                            breakpoints[newKey] = marker;
                        }
                    }
                }
            }

            if (OnBreakpointChanged != null)
            {
                OnBreakpointChanged();
            }
        }
Exemple #18
0
        static public void RunToCursor()
        {
            if (IsRunning && IsInBreak)
            {
                string file     = Npp.Editor.GetCurrentFilePath();
                var    document = Npp.GetCurrentDocument();

                int    line             = document.GetCurrentLineNumber();
                string key              = BuildBreakpointKey(file, line);
                string actualBreakpoint = TranslateSourceBreakpoint(key);
                DebuggerServer.AddBreakpoint(actualBreakpoint);
                DebuggerServer.Go();
                DebuggerServer.OnBreak = () =>
                {
                    DebuggerServer.RemoveBreakpoint(actualBreakpoint);
                };
            }
        }
Exemple #19
0
        static public void SaveAllButNew()
        {
            //Win32.SendMessage(Npp.NppHandle, NppMsg.NPPM_SAVEALLFILES, 0, 0);
            var document = Npp.GetCurrentDocument();

            var files   = Npp.Editor.GetOpenFilesSafe();
            var current = Npp.Editor.GetCurrentFilePath();

            foreach (var item in files)
            {
                if (Path.IsPathRooted(item))  //the "new" file is not saved so it has no root
                {
                    Npp.Editor.Open(item)
                    .SaveCurrentFile();
                }
            }
            Npp.Editor.Open(current);
        }
Exemple #20
0
        public static void ResetBreaksPointsFromContent()
        {
            // remove all active break point handles and read them again from the content
            var currFile = Npp.Editor.GetCurrentFilePath();
            var document = Npp.GetCurrentDocument();

            int[] actual_markers = document.LinesWithMarker(MARK_BREAKPOINT);

            var currentFileKeys = breakpoints.Keys.Where(k => k.StartsWith(currFile, StringComparison.OrdinalIgnoreCase));

            foreach (string key in currentFileKeys.ToArray())
            {
                //IMPORTANT: GetLineOfMarker returns line form the handle of the marker within a
                //current file. Value of handles are file specific and reused between the files/documents.
                //This is because marker handles are just marker indexes within a document.
                //Thus resolving a given handle for a non current document can in fact return a proper line
                //of the current doc if it has the marker with the same handle value. This already led to
                //the break points drifting.

                IntPtr marker = breakpoints[key];
                if (marker != IntPtr.Zero)
                {
                    document.DeleteMarker(marker);
                }
                breakpoints.Remove(key);
            }

            document.DeleteAllMarkers(MARK_BREAKPOINT);

            foreach (var line in actual_markers)
            {
                IntPtr marker = document.PlaceMarker(MARK_BREAKPOINT, line);
                string newKey = currFile + "|" + (line + 1);
                breakpoints[newKey] = marker;
            }

            Dispatcher.Schedule(10, () =>
            {
                if (OnBreakpointChanged != null)
                {
                    OnBreakpointChanged();
                }
            });
        }
Exemple #21
0
        private static void ProcessOpenStackLocation(string sourceLocation)
        {
            var location = Debugger.FileLocation.Parse(sourceLocation);

            var document = Npp.GetCurrentDocument();

            int start = document.GetFirstVisibleLine();
            int end   = start + document.LinesOnScreen();

            if (location.Line > end || location.Line < start)
            {
                document.SetFirstVisibleLine(Math.Max(location.Line - (end - start) / 2, 0));
            }

            document.SetCurrentPos(location.Start);
            document.ClearSelection(); //need this one as otherwise parasitic selection can be triggered

            Win32.SetForegroundWindow(Npp.Editor.Handle);
            Win32.SetForegroundWindow(Npp.GetCurrentDocument().Handle);
        }
Exemple #22
0
        static Debugger()
        {
            DebuggerServer.OnNotificationReceived        = HandleNotification;
            DebuggerServer.OnDebuggerStateChanged       += HandleDebuggerStateChanged;
            DebuggerServer.OnDebuggeeProcessNotification = message => Plugin.OutputPanel.DebugOutput.WriteLine(message);

            var debugStepPointColor = ColorFromConfig(Config.Instance.DebugStepPointColor, Color.Yellow);

            //selection of the debug step line
            var document = Npp.GetCurrentDocument();

            document.SetIndicatorStyle(INDICATOR_DEBUGSTEP, SciMsg.INDIC_STRAIGHTBOX, debugStepPointColor);
            document.SetIndicatorTransparency(INDICATOR_DEBUGSTEP, 90, 255);

            //left 'panel' arrow and breakpoint image
            document.SetMarkerStyle(MARK_DEBUGSTEP, SciMsg.SC_MARK_SHORTARROW, ColorFromConfig(Config.Instance.DebugStepPointForeColor, Color.Black), debugStepPointColor);
            document.SetMarkerStyle(MARK_BREAKPOINT, CSScriptNpp.Resources.Resources.breakpoint);

            Debugger.BreakOnException = Config.Instance.BreakOnException;
        }
Exemple #23
0
        internal static void PlaceBreakPointsForCurrentTab()
        {
            try
            {
                var    document = Npp.GetCurrentDocument();
                string file     = Npp.Editor.GetCurrentFilePath();

                string   expectedkeyPrefix = file + "|";
                string[] fileBreakpoints   = breakpoints.Keys.Where(x => x.StartsWith(expectedkeyPrefix, StringComparison.OrdinalIgnoreCase)).ToArray();

                foreach (var key in fileBreakpoints)
                {
                    if (breakpoints[key] == IntPtr.Zero) //not placed yet
                    {
                        //key = <file>|<line + 1> //server debugger operates in '1-based' and NPP in '0-based' lines
                        int line = int.Parse(key.Split('|').Last()) - 1;
                        breakpoints[key] = document.PlaceMarker(MARK_BREAKPOINT, line);
                    }
                }
            }
            catch { }
        }
Exemple #24
0
        // public static Dictionary<int, string> NoteBreakpoints()
        // {
        //     var result = new Dictionary<int, string>();
        //     var document = Npp.GetCurrentDocument();
        //     string file = Npp.Editor.GetCurrentFilePath();

        //     string expectedkeyPrefix = file + "|";
        //     string[] fileBreakpoints = breakpoints.Keys.Where(x => x.StartsWith(expectedkeyPrefix, StringComparison.OrdinalIgnoreCase)).ToArray();

        //     foreach (var key in fileBreakpoints)
        //     {
        //         //key = <file>|<line + 1> //server debugger operates in '1-based' and NPP in '0-based' lines
        //         int line = int.Parse(key.Split('|').Last()) - 1;
        //         var linetText = document.GetLine(line);
        //         result.Add(line, linetText.Replace(" ", "")
        //                                   .Replace("\t", "")
        //                                   .TrimEnd('}'));
        //     }

        //     return result;
        // }

        public static void RefreshBreakPointsInContent()
        {
            try
            {
                var    document = Npp.GetCurrentDocument();
                string file     = Npp.Editor.GetCurrentFilePath();

                //clear all
                document.ClearIndicator(INDICATOR_DEBUGSTEP, 0, -1);

                string   expectedkeyPrefix = file + "|";
                string[] fileBreakpoints   = breakpoints.Keys.Where(x => x.StartsWith(expectedkeyPrefix, StringComparison.OrdinalIgnoreCase)).ToArray();

                foreach (var key in fileBreakpoints)
                {
                    //key = <file>|<line + 1> //server debugger operates in '1-based' and NPP in '0-based' lines
                    int line = int.Parse(key.Split('|').Last()) - 1;
                    breakpoints[key] = document.PlaceMarker(MARK_BREAKPOINT, line);
                    Debug.WriteLine($@"Refresh BP Line: {line}");
                }
            }
            catch { }
        }
Exemple #25
0
        static public void SaveDocuments(string[] files)
        {
            try
            {
                var filesToSave = files.Select(x => Path.GetFullPath(x));

                var openFiles = Npp.Editor.GetOpenFilesSafe();
                var document  = Npp.GetCurrentDocument();
                var current   = Npp.Editor.GetCurrentFilePath();

                // the "new" file is not saved so it has no root
                foreach (var item in openFiles.Where(Path.IsPathRooted))
                {
                    var path = Path.GetFullPath(item);
                    if (filesToSave.Contains(path))
                    {
                        Npp.Editor.Open(item)
                        .SaveCurrentFile();
                    }
                }
                Npp.Editor.Open(current);
            }
            catch { }
        }
Exemple #26
0
        static public void OnCalltipRequest(int position)
        {
            if (position == -2)
            {
                Calltip.LastEval           =
                    Calltip.LastExpression = null; //if DBG frame is changed so clear the data
            }
            else
            {
                if (Calltip.IsShowing)
                {
                    return;
                }

                Calltip.IsShowing = true;

                Task.Factory.StartNew(() =>  //must be asynch to allow processing other Debugger notifications
                {
                    string underMouseExpression = Npp.GetCurrentDocument().GetStatementAtPosition(position);
                    string document             = Npp.Editor.GetCurrentFilePath();
                    string tooltip = null;

                    //if (Debugger.IsInBreak) //The calltips are used to show the values of the variables only. For everything else (e.g. MemberInfo) modal borderless forms are used
                    //{
                    if (!string.IsNullOrEmpty(underMouseExpression))
                    {
                        //also need to check expression start position (if not debugging) as the same expression can lead to different tooltip
                        //NOTE: if DBG frame is changed the LastExpression is cleared
                        if (underMouseExpression == Calltip.LastExpression && Calltip.LastDocument == document)
                        {
                            if (Debugger.IsInBreak)
                            {
                                tooltip = Calltip.LastEval;
                            }
                        }

                        //if (underMouseExpression != Calltip.LastExpression)
                        //{
                        //    System.Diagnostics.Debug.WriteLine("GetDebugTooltipValue -> expression is changed...");
                        //    System.Diagnostics.Debug.WriteLine("old: " + Calltip.LastExpression);
                        //    System.Diagnostics.Debug.WriteLine("new: " + underMouseExpression);
                        //}

                        //if (Calltip.LastDocument != document)
                        //    System.Diagnostics.Debug.WriteLine("GetDebugTooltipValue -> document is changed...");

                        if (tooltip == null)
                        {
                            if (Debugger.IsInBreak)
                            {
                                tooltip = Debugger.GetDebugTooltipValue(underMouseExpression);
                            }
                            else if (CSScriptIntellisense.Config.Instance.ShowQuickInfoAsNativeNppTooltip)
                            {
                                tooltip = CSScriptIntellisense.Plugin.GetMemberUnderCursorInfo().FirstOrDefault();
                            }

                            Calltip.LastDocument   = document;
                            Calltip.LastEval       = tooltip.TruncateLines(Config.Instance.CollectionItemsInTooltipsMaxCount, "\n<Content was truncated. Use F12 to see the raw API documentation data.>");
                            Calltip.LastExpression = underMouseExpression;
                        }

                        if (tooltip != null)
                        {
                            npp.ShowCalltip(position, tooltip);
                            return;
                        }
                    }

                    Calltip.IsShowing = false;
                });
            }
        }
Exemple #27
0
        void Run(bool asExternal)
        {
            if (currentScript == null || (Config.Instance.ReloadActiveScriptOnRun && currentScript != Npp.Editor.GetCurrentFilePath()))
            {
                loadBtn.PerformClick();
            }

            if (currentScript == null)
            {
                MessageBox.Show("Please load some script file first.", "CS-Script");
            }
            else
            {
                try
                {
                    if (!CurrentDocumentBelongsToProject())
                    {
                        EditItem(currentScript);
                    }

                    npp.SaveDocuments(GetProjectDocuments());

                    if (asExternal)
                    {
                        try
                        {
                            CSScriptHelper.ExecuteAsynch(currentScript);
                        }
                        catch (Exception e)
                        {
                            Plugin.ShowOutputPanel()
                            .ShowBuildOutput()
                            .WriteLine(e.Message)
                            .SetCaretAtStart();
                        }
                    }
                    else
                    {
                        OutputPanel outputPanel = Plugin.ShowOutputPanel();

                        if (Config.Instance.StartDebugMonitorOnScriptExecution)
                        {
                            outputPanel.AttachDebgMonitor();
                        }

                        outputPanel.ClearAllDefaultOutputs();

                        Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                if (Config.Instance.InterceptConsole)
                                {
                                    CSScriptHelper.ExecuteScript(currentScript, OnRunStart, OnConsoleObjectOut);
                                }
                                else
                                {
                                    CSScriptHelper.ExecuteScript(currentScript, OnRunStart);
                                }
                            }
                            catch (Exception e)
                            {
                                this.InUiThread(() =>
                                {
                                    outputPanel.ShowBuildOutput()
                                    .WriteLine(e.Message)
                                    .SetCaretAtStart();
                                });
                            }
                            finally
                            {
                                this.InUiThread(() =>
                                {
                                    Plugin.RunningScript = null;
                                    RefreshControls();
                                    Npp.GetCurrentDocument().GrabFocus();
                                });
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    Plugin.ShowOutputPanel()
                    .ShowBuildOutput()
                    .WriteLine(ex.Message)
                    .SetCaretAtStart();
                }
            }
        }
Exemple #28
0
        public void beNotified(IntPtr notifyCode)
        {
            try
            {
                CSScriptIntellisense.Interop.NppUI.OnNppTick();

                ScNotification nc          = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));
                string         contentFile = Npp.Editor.GetTabFile(nc.Header.IdFrom);

                //Debug.WriteLine(">>>>>   ncnc.nmhdr.code={0}, {1}", nc.nmhdr.code, (int)nc.nmhdr.code);

                if (nc.Header.Code == (uint)NppMsg.NPPN_READY)
                {
                    CSScriptIntellisense.Plugin.OnNppReady();
                    CSScriptNpp.Plugin.OnNppReady();
                    npp.SetCalltipTime(500);
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
                {
                    CSScriptNpp.Plugin.StopVBCSCompilers();
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
                {
                    CSScriptNpp.Plugin.OnToolbarUpdate();
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPM_SAVECURRENTFILEAS ||
                         (Config.Instance.HandleSaveAs && nc.Header.Code == (uint)SciMsg.SCN_SAVEPOINTREACHED)) //for some strange reason NPP doesn't fire NPPM_SAVECURRENTFILEAS but does 2002 instead.
                {
                    if (Plugin.ProjectPanel != null)
                    {
                        var panel_visible = Plugin.ProjectPanel.Visible;
                    }

                    string file = Npp.Editor.GetCurrentFilePath();
                    if (file != lastActivatedBuffer)
                    {
                        CSScriptNpp.Plugin.OnFileSavedAs(lastActivatedBuffer, file);
                    }
                }
                else if (nc.Header.Code == (uint)SciMsg.SCN_CHARADDED)
                {
                    CSScriptIntellisense.Plugin.OnCharTyped(nc.Character);
                }
                else if (nc.Header.Code == (uint)SciMsg.SCN_MARGINCLICK)
                {
                    if (nc.Margin == _SC_MARGE_SYBOLE && nc.Mmodifiers == SCI_CTRL)
                    {
                        var document  = Npp.GetCurrentDocument();
                        int lineClick = document.LineFromPosition(nc.Position.Value);
                        Debugger.ToggleBreakpoint(lineClick);
                    }
                }
                else if (nc.Header.Code == (uint)SciMsg.SCN_DWELLSTART) //tooltip
                {
                    //Npp.ShowCalltip(nc.position, "\u0001  1 of 3 \u0002  test tooltip " + Environment.TickCount);
                    //Npp.ShowCalltip(nc.position, CSScriptIntellisense.Npp.GetWordAtPosition(nc.position));
                    //tooltip = @"Creates all directories and subdirectories as specified by path.

                    npp.OnCalltipRequest(nc.Position.Value);
                }
                else if (nc.Header.Code == (uint)SciMsg.SCN_DWELLEND)
                {
                    npp.CancelCalltip();
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_BUFFERACTIVATED)
                {
                    string file = Npp.Editor.GetCurrentFilePath();
                    lastActivatedBuffer = file;

                    if (file.EndsWith("npp.args"))
                    {
                        Win32.SendMessage(Npp.Editor.Handle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_CLOSE);

                        string args = File.ReadAllText(file);

                        Plugin.ProcessCommandArgs(args);

                        try { File.Delete(file); }
                        catch { }
                    }
                    else
                    {
                        CSScriptIntellisense.Plugin.OnCurrentFileChanegd();
                        CSScriptNpp.Plugin.OnCurrentFileChanged();
                        Debugger.OnCurrentFileChanged();
                    }
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_FILEOPENED)
                {
                    string file = Npp.Editor.GetTabFile(nc.Header.IdFrom);
                    Debugger.LoadBreakPointsFor(file);
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_FILESAVED)
                {
                    Plugin.OnDocumentSaved();
                    Debugger.RefreshBreakPointsInContent();
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_FILEBEFORECLOSE)
                {
                    SaveBreakpoints(contentFile);
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_FILEBEFORESAVE)
                {
                    CSScriptIntellisense.Plugin.OnBeforeDocumentSaved();
                    // Formatting may have shifted all breakpoints
                    Debugger.ResetBreaksPointsFromContent();
                }
                else if (nc.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
                {
                    Marshal.FreeHGlobal(_ptrPluginName);

                    Plugin.CleanUp();
                }

                if (nc.Header.Code == (uint)SciMsg.SCI_ENDUNDOACTION)
                {
                    //CSScriptIntellisense.Plugin.OnSavedOrUndo();
                }

                Plugin.OnNotification(nc);
            }
            catch { }//this is indeed the last line of defense as all CS-S calls have the error handling inside
        }
Exemple #29
0
        /***********************************/

        static public void CancelCalltip()
        {
            Npp.GetCurrentDocument().CallTipCancel();
            Calltip.IsShowing = false;
        }