Пример #1
0
        private void UpdateFunctionList()
        {
            if (_file == null)
            {
                lstFunctions.Items.Clear();
                return;
            }

            TextFilter tf = new TextFilter(txtFunctionFilter.Text);

            // Get a list of the functions, and where they are in the file now.
            FunctionParser fp = new FunctionParser();
            var parsedFuncs = fp.Parse(_plugin.GetText(_plugin.Start, _plugin.End)).ToArray();

            Action updateAction = () =>
            {
                var listFuncs = (from i in lstFunctions.Items.Cast<ListViewItem>() select i.Tag as Function).ToArray();
                var fileFuncs = _file.Functions.ToArray();

                var newFuncs = (from func in parsedFuncs where !_file.FunctionIdExists(func.Id) select func).ToArray();
                var updatedFuncs = (from func in parsedFuncs where _file.FunctionIdExists(func.Id) select _file.GetFunction(func.Id)).ToArray();
                var deletedFuncs = (from name in _file.FunctionIds where !parsedFuncs.Any(f => f.Id == name) select _file.GetFunction(name)).ToArray();

                lstFunctions.BeginUpdate();
                try
                {
                    foreach (var func in deletedFuncs)
                    {
                        func.LVI.Remove();
                        _file.RemoveFunction(func.Id);
                    }

                    foreach (var func in newFuncs)
                    {
                        var lvi = CreateFunctionLvi(func);
                        lstFunctions.Items.Add(lvi);
                        _file.AddFunction(func);
                    }

                    foreach (var func in updatedFuncs)
                    {
                        UpdateFunctionLvi(func.LVI, func, (from f in parsedFuncs where f.Id == func.Id select f).FirstOrDefault());
                    }
                }
                finally
                {
                    lstFunctions.EndUpdate();
                }
            };
            if (lstFunctions.InvokeRequired) lstFunctions.BeginInvoke(updateAction);
            else updateAction();
        }
Пример #2
0
        public void InsertDiag()
        {
            var selText = SelectedText.Trim();
            if (selText.IndexOf('\n') >= 0) selText = string.Empty;

            var sb = new StringBuilder();
            sb.Append("diag(\"");
            if (Settings.Tagging.InitialsInDiags && !string.IsNullOrWhiteSpace(Settings.Tagging.Initials))
            {
                sb.Append(Settings.Tagging.Initials);
                sb.Append(": ");
            }

            if (Settings.Tagging.FileNameInDiags)
            {
                sb.Append(Path.GetFileName(ActiveFileName));
                sb.Append(": ");
            }

            if (Settings.Tagging.FunctionNameInDiags)
            {
                var line = CurrentLine;
                var fp = new FunctionParser();
                var parsedFuncs = fp.Parse(GetText(Start, End));
                var fn = (from f in parsedFuncs where f.StartLine <= line select f).LastOrDefault();
                if (fn != null)
                {
                    sb.Append(fn.Name);
                    sb.Append("(): ");
                }
            }

            if (!string.IsNullOrWhiteSpace(selText))
            {
                sb.Append(ProbeEnvironment.StringEscape(selText));
                sb.Append(" [\", ");
                sb.Append(selText);
                sb.Append(", \"]");
            }

            int lengthBefore = sb.Length;

            sb.Append("\\n\");");
            if (Settings.Tagging.TodoAfterDiags) sb.Append("\t// TODO");

            Insert(sb.ToString());

            if (string.IsNullOrWhiteSpace(selText))
            {
                GoTo(CurrentLocation - (sb.Length - lengthBefore));
            }
        }
Пример #3
0
        public void ParseFunctions(string source)
        {
            FunctionParser parser = new FunctionParser();
            var funcs = parser.Parse(source);

            lock (_funcs)
            {
                foreach (var func in funcs) _funcs[func.Id] = func;
            }
        }