Beispiel #1
0
        public Position SelectFirstWordOfLine(ScintillaGateway scintilla)
        {
            int lineNumber = scintilla.GetCurrentLineNumber();

            var lineContent = scintilla.GetLine(lineNumber);

            if (lineContent.StartsWith("#"))
            {
                return(null);
            }

            int endOfFirstWordOnLine = lineContent.IndexOf(' ');

            if (endOfFirstWordOnLine == -1)
            {
                return(null);
            }

            var positionOfLine          = scintilla.PositionFromLine(lineNumber);
            var cursorpos               = scintilla.GetCurrentPos() - positionOfLine;
            var cursorIsWithinFirstWord = cursorpos.Value <= endOfFirstWordOnLine;

            if (!cursorIsWithinFirstWord)
            {
                return(null);
            }

            var newPosition = new Position(positionOfLine.Value + endOfFirstWordOnLine);

            scintilla.SetAnchor(newPosition);
            scintilla.SetCurrentPos(positionOfLine);

            return(newPosition);
        }
Beispiel #2
0
        private static void GotoSectionOrPerform()
        {
            if (SNDialogStruct.Form == null)
            {
                SourceNavigationDialog();
            }
            var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

            CheckAndSwitchOnCobolWords();
            editor.SetSelection(editor.WordEndPosition(editor.GetCurrentPos(), true), editor.WordStartPosition(editor.GetCurrentPos(), true));

            if (editor.GetSelectionLength() == 0)
            {
                return;
            }
            // If new search
            if (sectionName != editor.GetSelText().ToUpper())
            {
                sectionName = editor.GetSelText().ToUpper();
                int sectionImplementationLine = GetSectionImplementationLine(sectionName);
                if (sectionImplementationLine >= 0)
                {
                    if (editor.GetCurrentLineNumber() == sectionImplementationLine)
                    {
                        if (!SearchNextSectionOrPerform(sectionName, editor.GetCurrentPos().Value))
                        {
                            SearchNextSectionOrPerform(sectionName, 0);
                        }
                    }
                    else
                    {
                        ScrollToLine(sectionImplementationLine);
                        CurrentSearchOffset = sectionImplementationLine;
                    }
                }
                else
                {
                    sectionName = "";
                }
            }
            //If continuing search
            else
            {
                if (!SearchNextSectionOrPerform(sectionName, CurrentSearchOffset))
                {
                    SearchNextSectionOrPerform(sectionName, 0);
                }
            }
        }
Beispiel #3
0
        internal static void printDebugLine()
        {
            IntPtr           hCurrScintilla = PluginBase.GetCurrentScintilla();
            ScintillaGateway sci            = new ScintillaGateway(hCurrScintilla);
            var lineNumber       = sci.GetCurrentLineNumber() + 1;
            NotepadPPGateway npp = new NotepadPPGateway();
            var fileName         = Path.GetFileNameWithoutExtension(npp.GetCurrentFilePath());
            var stream           = new FileStream(@"plugins/Config/GoToDefinition/debug_table.txt", FileMode.Open, FileAccess.Read);

            using (var streamReader = new StreamReader(stream, Encoding.UTF8))
            {
                var text = streamReader.ReadToEnd();
                text = text + $"'{fileName}', {lineNumber}, )";
                sci.AddText(text.Length, text);
            }
        }
Beispiel #4
0
        internal static void Process(bool isScript, string script = null, Action <object> setResult = null, bool forceErrorInOutput = false)
        {
            Init();

            if (!Config.Instance.KeepVariablesBetweenEvaluations)
            {
                LastVariables = new Dictionary <string, object>();
            }
            else if (LastVariables != null)
            {
                LastVariables
                .ToList()
                .FindAll(kvp => kvp.Value is StronglyTypedVariable)
                .ForEach(kvp => LastVariables.Remove(kvp.Key));
            }

            evaluator.Variables = LastVariables;

            evaluator.OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = Config.Instance.OptionForceIntegerNumbersEvaluationsAsDoubleByDefault;
            evaluator.OptionCaseSensitiveEvaluationActive = Config.Instance.CaseSensitive;
            evaluator.OptionsSyntaxRules.MandatoryLastStatementTerminalPunctuator      = false;
            evaluator.OptionsSyntaxRules.IsNewKeywordForAnonymousExpandoObjectOptional = true;
            evaluator.OptionsSyntaxRules.AllowSimplifiedCollectionSyntax     = true;
            evaluator.OptionsSyntaxRules.SimplifiedCollectionMode            = SimplifiedCollectionMode.List;
            evaluator.OptionsSyntaxRules.InitializerPropertyValueSeparators  = new[] { "=", ":" };
            evaluator.OptionsSyntaxRules.InitializerAllowStringForProperties = true;

            try
            {
                if (BNpp.SelectionLength <= 0)
                {
                    IScintillaGateway
                        scintilla = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                    int line      = scintilla.GetCurrentLineNumber();
                    int end       = scintilla.GetLineEndPosition(line);
                    int start     = 0;

                    if (isScript)
                    {
                        // TODO special start script tag
                    }
                    else
                    {
                        int i;
                        for (i = line; i > 0 && scintilla.GetLine(line).TrimStart().StartsWith("."); i--)
                        {
                            ;
                        }

                        start = scintilla.PositionFromLine(i);

                        for (i = line; i < scintilla.GetLineCount() && scintilla.GetLine(line).TrimStart().StartsWith("."); i++)
                        {
                            ;
                        }

                        end = scintilla.GetLineEndPosition(i);
                    }

                    if (setResult == null)
                    {
                        scintilla.SetSel(new Position(start), new Position(end));
                    }
                }

                setResult ??= Config.Instance.CurrentResultOut.SetResult;

                script ??= BNpp.SelectedText;

                Config.Instance.LastScripts.Insert(0, script);
                while (Config.Instance.LastScripts.Count > Config.Instance.NbrOfLastScriptToKeep)
                {
                    Config.Instance.LastScripts.RemoveAt(Config.Instance.LastScripts.Count - 1);
                }

                Config.Instance.LastScripts = Config.Instance.LastScripts.Distinct().ToList();

                object result = isScript ? evaluator.ScriptEvaluate(evaluator.RemoveComments(script)) : evaluator.Evaluate(evaluator.RemoveComments(script.TrimEnd(';')));

                setResult(result);
            }
            catch (Exception exception)
            {
                if (Config.Instance.ShowExceptionInMessageBox && !forceErrorInOutput)
                {
                    MessageBox.Show(exception.Message);
                }

                if (Config.Instance.ShowExceptionInOutput || forceErrorInOutput)
                {
                    setResult(exception);
                }

                if (!string.IsNullOrEmpty(CustomEvaluations.Print))
                {
                    setResult(CustomEvaluations.Print);
                }
            }
            finally
            {
                LastVariables = evaluator.Variables;
                Config.Instance.Save();
            }
        }