示例#1
0
//        public void SelectedTextFindInCurrentSource()
//        {
//            SourceContainerDocument sourceDocument = MainForm.ActiveMdiChild as SourceContainerDocument;
//            if (sourceDocument != null)
//            {
//                string selectedText = sourceDocument.SourceEditorPanel.fastColoredTextBox1.SelectedText;
//                if (!string.IsNullOrEmpty(selectedText)) { sourceDocument.SourceEditorPanel.FindInSourcePanel.SetSeachableText(selectedText,true); }
//            }
//        }

        public void OpenNewNote()
        {
            SourceContainerDocument newDocument;
            FileClass fileClass = new FileClass()
            {
                FileName  = "note",
                FilePath  = "Notes",
                TextState = ETextState.ReadNotChanged,
                Name      = "note"
            };

            newDocument = CreateNewDocument(fileClass);
            ShowPanel(newDocument);
            newDocument.SourceEditorPanel.fastColoredTextBox1.Focus();
        }
示例#2
0
        private void OpenOrSwitchFile(FileClass fileClass, bool reloadFileContent = false)
        {
            if (fileClass != null)
            {
                SourceContainerDocument newDocument = null;

                DockPane orDefault = MainDockPanel.Panes.FirstOrDefault(x => x.Appearance == DockPane.AppearanceStyle.Document);
                if (orDefault != null)
                {
                    IDockContent firstOrDefault = orDefault.Contents.FirstOrDefault(s => (s is SourceContainerDocument) && ((SourceContainerDocument)s).FileClass.FilePath == fileClass.FilePath);
                    if (firstOrDefault != null)
                    {
                        newDocument = firstOrDefault as SourceContainerDocument;
                    }
                }
                if (newDocument == null)
                {
                    if (fileClass.TextState == ETextState.UnRead)
                    {
                        fileClass.Text      = ReadSourceFile(fileClass.FilePath);
                        fileClass.TextState = ETextState.ReadNotChanged;
                    }
                    fileClass.IsOpened = true;
                    newDocument        = CreateNewDocument(fileClass);
                    OpenedDocumentsPanel.RefreshOpenedDocumentsList();
                    if (App.Configuration.SaveOnCloseOpenDocument)
                    {
                        if (MainEngine.Instance.IsLoadingWorkspase == false)
                        {
                            SaveWorkSpace();
                        }
                    }
                }
                else
                {
                    if (reloadFileContent)
                    {
                        ReloadDocumentContent(newDocument, fileClass);
                    }
                }
                if (reloadFileContent == false)
                {
                    ShowPanel(newDocument);
                }
                newDocument.SourceEditorPanel.fastColoredTextBox1.Focus();
            }
        }
示例#3
0
        private void AddNodeByRegex(FileClass fileClass, string nodeName, string regex, string format, int imageIndex)
        {
            MatchCollection matchCollection = Regex.Matches(fileClass.Text, regex, RegexOptions.ExplicitCapture);
            var             typeNode        = new TreeNode();

            typeNode.Expand();
            typeNode.Text               = string.Format(nodeName, matchCollection.Count);
            typeNode.ImageIndex         = imageIndex;
            typeNode.SelectedImageIndex = typeNode.ImageIndex;
            typeNode.NodeFont           = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold);
            foreach (Match match in matchCollection)
            {
                var node = new TreeNode();
                node.Text               = string.Format(format, match.Groups[1], match.Groups[2]);
                node.ImageIndex         = imageIndex;
                node.SelectedImageIndex = node.ImageIndex;
                var filePositionItem = new FilePositionItem();
                filePositionItem.IndexItemStart = match.Groups[1].Index;
                filePositionItem.IndexItemEnd   = filePositionItem.IndexItemStart + 10;
//                filePositionItem.IndexItemEnd = eventMatch.Groups[5].Index + powerBuilderFileType.IndexInstanceVarEnd;
//                filePositionItem.IsHasCode = eventMatch.Groups[4].Length > 5;
                filePositionItem.LineNumberStart = MainEngine.Instance.GetTextLineByCharIndex(filePositionItem.IndexItemStart);
                filePositionItem.LineNumberEnd   = MainEngine.Instance.GetTextLineByCharIndex(filePositionItem.IndexItemEnd);
                node.Tag = filePositionItem;
                MatchCollection matchExpresionCollection = Regex.Matches(match.Groups[0].Value, @"(?<prop>\w+)\=\""(?<val>[^\""]*)\~t(?<expr>.*?)\""", RegexOptions.ExplicitCapture);
                foreach (Match m in matchExpresionCollection)
                {
                    var nodeExpr = new TreeNode();
                    nodeExpr.Text               = string.Format("{0}=  {2}", m.Groups[1], m.Groups[2], m.Groups[3]);
                    nodeExpr.ImageIndex         = 14;
                    nodeExpr.SelectedImageIndex = node.ImageIndex;
                    nodeExpr.Tag = filePositionItem;
//                    nodeExpr.NodeFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Italic);
                    nodeExpr.ForeColor = Color.Gray;
                    node.Nodes.Add(nodeExpr);
                }
                typeNode.Nodes.Add(node);
            }
            treeView1.Nodes.Add(typeNode);
        }
示例#4
0
        public void SetObjectsList(FileClass fileClass)
        {
            try
            {
                treeView1.BeginUpdate();

                //DataWindow's objects
                if (fileClass.Text.Contains(".srd"))
                {
                    treeView1.Nodes.Clear();

                    MainEngine.Instance.FillRnCounts(fileClass.Text);
                    AddNodeByRegex(fileClass, "Arguments ({0})", @"\,?\(\""(?<name>(\w+))\""\,\s*(?<type>\w+)\)", ":{0}=? : {1}", 11, "sqlArgument");
                    AddNodeByRegex(fileClass, "SQL Columns ({0})", @"(column\=\().*?name\=(?<name>\w+).*?dbname\=\""(?<dbname>(\w|\.)+)\"".*\)", "{0} : {1}", 9, "sqlColumns");
                    AddNodeByRegex(fileClass, "Columns ({0})", @"(?<=column\().*?name\=(?<name>\w+).*\)", "{0}", 12, "pbColumns");
                    AddNodeByRegex(fileClass, "Reports ({0})", @"(?<=report\().*?dataobject\=\""(?<dataobject>(\w)+)\"".*?name\=(?<name>\w+).*?\)", "{1} : {0}", 12, "reports");
                    AddNodeByRegex(fileClass, "Calculated ({0})", @"(?<=compute\().*?expression\=\""(?<expr>.*?)\"".*?name\=(?<name>\w+).*\)", "{1} : {0}", 12, "calculated");
                    AddNodeByRegex(fileClass, "Texts ({0})", @"(?<=text\().*?text\=\""(?<expr>.*?)\"".*?name\=(?<name>\w+).*\)", "\"{0}\" : {1}", 15, "text");
                    //treeView1.ExpandAll();
                }
                else if (fileClass.IsSql == false)
                {
                    treeView1.Nodes.Clear();
                    foreach (PowerBuilderFileType powerBuilderFileType in fileClass.PowerBuilderFileTypes)
                    {
                        MainEngine.Instance.FillRnCounts(fileClass.Text);

                        var typeNode = new TreeNode();
                        if (powerBuilderFileType.IsMainType)
                        {
                            typeNode.Expand();
                        }
                        FilePositionItem textVar = GetVarValueFromType(powerBuilderFileType, "Text", fileClass, @"string\s*(text|title)\s*\=\s*\""(?<dataobj>[^""]+)""");
                        var name = string.IsNullOrEmpty(textVar?.Name) ? "" : "  '" + textVar?.Name + "'  ";
                        typeNode.Text = $"{powerBuilderFileType.Name}{name}: {powerBuilderFileType.InheritFrom}";
                        typeNode.Tag  = powerBuilderFileType;
                        //typeNode.NodeFont = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold);
                        if (typeNode.Text.ToLower().StartsWith("w"))
                        {
                            typeNode.ImageIndex = 0;
                        }
                        if (typeNode.Text.ToLower().StartsWith("d"))
                        {
                            typeNode.ImageIndex = 7;
                        }
                        if (typeNode.Text.ToLower().StartsWith("u"))
                        {
                            typeNode.ImageIndex = 2;
                        }
                        if (typeNode.Text.ToLower().StartsWith("s"))
                        {
                            typeNode.ImageIndex = 1;
                        }
                        if (typeNode.Text.ToLower().StartsWith("cb"))
                        {
                            typeNode.ImageIndex = 13;
                        }
                        typeNode.SelectedImageIndex = typeNode.ImageIndex;

                        //DataObjects
                        if (powerBuilderFileType.Name.ToLower().StartsWith("d"))
                        {
                            string initialDataObject = "";
                            var    dataObjNode       = new TreeNode();
                            dataObjNode.Text               = "Dataobject";
                            dataObjNode.ImageIndex         = 7;
                            dataObjNode.SelectedImageIndex = dataObjNode.ImageIndex;
                            typeNode.Nodes.Add(dataObjNode);

                            string textInstanceRange = fileClass.Text.Substring(powerBuilderFileType.IndexStart, powerBuilderFileType.IndexInstanceVarEnd - powerBuilderFileType.IndexStart);
                            Match  match             = Regex.Match(textInstanceRange, @"string\s*dataobject\s*\=\s*\""(?<dataobj>\w+)""", RegexOptions.ExplicitCapture);
                            if (match.Success)
                            {
                                string dataObjectSource = match.Groups["dataobj"].Value;
                                initialDataObject = dataObjectSource;
                                //typeNode.Text = string.Format(@"{0} ""{2}"" : {1}", powerBuilderFileType.Name, powerBuilderFileType.InheritFrom, initialDataObject);
                                TreeNode dnode = new TreeNode();
                                dnode.Text = initialDataObject;
                                dnode.Tag  = new FilePositionItem()
                                {
                                    LineNumberStart = MainEngine.Instance.GetTextLineByCharIndex(powerBuilderFileType.IndexStart + match.Groups["dataobj"].Index),
                                    ItemType        = "DataObjectSource",
                                    Name            = dataObjectSource
                                };
                                dataObjNode.Tag = new FilePositionItem()
                                {
                                    LineNumberStart = MainEngine.Instance.GetTextLineByCharIndex(powerBuilderFileType.IndexStart + match.Groups["dataobj"].Index),
                                    ItemType        = "DataObjectList"
                                };
                                dataObjNode.Nodes.Add(dnode);
                            }

                            int length = powerBuilderFileType.IndexEnd - powerBuilderFileType.IndexStart;
                            length            = length > 0 ? length : fileClass.Text.Length - powerBuilderFileType.IndexStart;
                            textInstanceRange = fileClass.Text.Substring(powerBuilderFileType.IndexStart, length);

                            MatchCollection matchesCollection    = Regex.Matches(textInstanceRange, @"[\r\n](\s*)(this\.)?dataobject\s*\=\s*(\""|\')(?<dataobj>\w+)(\""|\')", RegexOptions.ExplicitCapture);
                            MatchCollection matchesCollection2   = Regex.Matches(fileClass.Text, @"[\r\n](\s*)" + powerBuilderFileType.Name + @"\.dataobject\s*\=\s*(\""|\')(?<dataobj>\w+)(\""|\')", RegexOptions.ExplicitCapture);
                            Action <MatchCollection, int> action = (MatchCollection matches, int indexOffset) =>
                            {
                                foreach (Match m in matches)
                                {
                                    TreeNode dnode            = new TreeNode();
                                    string   dataObjectSource = m.Groups["dataobj"].Value;
                                    dnode.Text = dataObjectSource;
                                    dnode.Tag  = new FilePositionItem()
                                    {
                                        LineNumberStart = MainEngine.Instance.GetTextLineByCharIndex(indexOffset + m.Groups["dataobj"].Index),
                                        ItemType        = "DataObjectSource",
                                        Name            = dataObjectSource
                                    };
                                    dataObjNode.Nodes.Add(dnode);
                                }
                            };
                            action.Invoke(matchesCollection, powerBuilderFileType.IndexStart);
                            action.Invoke(matchesCollection2, 0);
                            int count = dataObjNode.Nodes.Count;
                            if (count > 1)
                            {
                                dataObjNode.Text = $"Dataobjects ({count})";
                            }
                            typeNode.Text = string.Format(@"{0} ""{2}""{3}: {1}", powerBuilderFileType.Name, powerBuilderFileType.InheritFrom, initialDataObject, count > 1 ? " (" + count + ") ":" ");
                        }

                        // Events
                        foreach (var filePositionItem in powerBuilderFileType.Events.OrderBy(o => o.Name))
                        {
                            var eventNode = new TreeNode();
                            eventNode.Text        = $"{filePositionItem.Name}{(filePositionItem.ItemParameters.Length > 0 ? " (...) " : " () ")}[{filePositionItem.LineNumberEnd - filePositionItem.LineNumberStart}]";
                            eventNode.Tag         = filePositionItem;
                            eventNode.ImageIndex  = 6;
                            eventNode.ToolTipText = $"{filePositionItem.Name}{" (" + filePositionItem.ItemParameters + ") "}[{filePositionItem.LineNumberEnd - filePositionItem.LineNumberStart}]";
                            ;
                            eventNode.SelectedImageIndex = eventNode.ImageIndex;
                            if (filePositionItem.IsHasCode == false)
                            {
                                eventNode.ForeColor = Color.DimGray;
                            }
                            typeNode.Nodes.Add(eventNode);
                        }

                        //Functions
                        foreach (var filePositionItem in powerBuilderFileType.Functions.OrderBy(o => o.Name))
                        {
                            var eventNode = new TreeNode();
                            eventNode.Text        = $"{filePositionItem.Name}{(filePositionItem.ItemParameters.Length > 0 ? " (...) " : " () ")}: {(filePositionItem.ReturnType == "subroutine" ? "" : filePositionItem.ReturnType)} [{filePositionItem.LineNumberEnd - filePositionItem.LineNumberStart}]";
                            eventNode.Tag         = filePositionItem;
                            eventNode.ImageIndex  = 10;
                            eventNode.ToolTipText = $"{filePositionItem.Name}{" (" + filePositionItem.ItemParameters + ") "}: {(filePositionItem.ReturnType == "subroutine" ? "" : filePositionItem.ReturnType)} [{filePositionItem.LineNumberEnd - filePositionItem.LineNumberStart}]";
                            ;
                            eventNode.SelectedImageIndex = eventNode.ImageIndex;
                            if (filePositionItem.IsHasCode == false)
                            {
                                eventNode.ForeColor = Color.DimGray;
                            }
                            typeNode.Nodes.Add(eventNode);
                        }
                        treeView1.Nodes.Add(typeNode);
                    }
                }
                treeView1.EndUpdate();
            }
            catch (Exception ex)
            {
            }
        }
示例#5
0
        private FilePositionItem GetVarValueFromType(PowerBuilderFileType powerBuilderFileType, string text, FileClass fileClass, string varRegex)
        {
            string textInstanceRange = fileClass.Text.Substring(powerBuilderFileType.IndexStart, powerBuilderFileType.IndexInstanceVarEnd - powerBuilderFileType.IndexStart);
            Match  match             = Regex.Match(textInstanceRange, varRegex, RegexOptions.ExplicitCapture);

            if (match.Success)
            {
                string dataObjectSource = match.Groups["dataobj"].Value;
                return(new FilePositionItem()
                {
                    LineNumberStart = MainEngine.Instance.GetTextLineByCharIndex(powerBuilderFileType.IndexStart + match.Groups["dataobj"].Index),
                    ItemType = "Variable",
                    Name = dataObjectSource
                });
            }
            return(null);
        }
示例#6
0
 public void SetSourceFileClass(FileClass fileClass)
 {
     FileClass = fileClass;
 }
示例#7
0
        public void AnalayzeFileForTypes(FileClass fileClass)
        {
            string text = fileClass.Text;

            try
            {
                //return;
//                var regex = new Regex(@"^event\s*(?<eventname>\w+)\s*(\((?<params>.*?)\))?;.*", RegexOptions.Multiline);
//                MatchCollection matchCollection = regex.Matches(text);
                //var test = Regex.Matches(text, @"(?<=event)\s*(?<eventname>\w+)\s*\((?<params>.+?)\);(.+?)(?=end event)", RegexOptions.Multiline);

                FillRnCounts(text);

                Match matchEndFarword = Regex.Match(text, "end forward", RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5));
                int   indexEndFarword = matchEndFarword.Groups[0].Index;

                string typeListRegex = @"(?si)[\n](global\s+type|type)+\s+(?<typename>\w+)\s+from\s+(?<inferitfrom>\w+)(\s+within\s+\w+)?(?<instatncevars>.*?)(?<endtype>end type)";

                MatchCollection matchCollection = Regex.Matches(text, typeListRegex, RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5));
                // Find Types
                PowerBuilderFileType fileType = null;
                fileClass.PowerBuilderFileTypes = new List <PowerBuilderFileType>();
                foreach (Match matchType in matchCollection)
                {
                    if (indexEndFarword > matchType.Groups[1].Index)
                    {
                        continue;
                    }

                    if (fileType != null)
                    {
                        fileType.IndexEnd      = matchType.Groups[1].Index;
                        fileType.LineNumberEnd = GetTextLineByCharIndex(fileType.IndexEnd);
                    }
                    //New type
                    fileType                       = new PowerBuilderFileType();
                    fileType.Name                  = matchType.Groups["typename"].Value;
                    fileType.InheritFrom           = matchType.Groups["inferitfrom"].Value;
                    fileType.IndexInstanceVarStart = matchType.Groups[3].Index;
                    fileType.IndexStart            = matchType.Groups[1].Index;
                    fileType.IndexInstanceVarEnd   = matchType.Groups["endtype"].Index;

                    fileType.LineNumberStart           = GetTextLineByCharIndex(fileType.IndexStart);
                    fileType.LineNumberInstanceVarsEnd = GetTextLineByCharIndex(fileType.IndexInstanceVarEnd);

                    fileClass.PowerBuilderFileTypes.Add(fileType);

                    //Find Instance Vars
                    if (matchType.Groups[3].Length > 5)
                    {
                        //
                    }
                }

                string eventListRegex = @"(?si)([\n]event|^event)(.*?)(?<eventname>\w+)\s*(\((?<params>.*?)\))?;(?<body>.*?)(?<endevent>([\n]e|^e)nd event)";
                foreach (var powerBuilderFileType in fileClass.PowerBuilderFileTypes)
                {
                    int length = powerBuilderFileType.IndexEnd - powerBuilderFileType.IndexInstanceVarEnd;
                    if (length < 0)
                    {
                        length = text.Length - powerBuilderFileType.IndexInstanceVarEnd;
                    }
                    var subText = text.Substring(powerBuilderFileType.IndexInstanceVarEnd, length);
                    matchCollection = Regex.Matches(subText, eventListRegex, RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5));
                    foreach (Match eventMatch in matchCollection)
                    {
                        var filePositionItem = new FilePositionItem();
                        filePositionItem.Name            = eventMatch.Groups[1].Value;
                        filePositionItem.ItemType        = "event";
                        filePositionItem.ItemParameters  = eventMatch.Groups[2].Value;
                        filePositionItem.IndexItemStart  = eventMatch.Groups[1].Index + powerBuilderFileType.IndexInstanceVarEnd;
                        filePositionItem.IndexItemEnd    = eventMatch.Groups[4].Index + powerBuilderFileType.IndexInstanceVarEnd;
                        filePositionItem.IsHasCode       = eventMatch.Groups[3].Length > 5;
                        filePositionItem.LineNumberStart = GetTextLineByCharIndex(filePositionItem.IndexItemStart);
                        filePositionItem.LineNumberEnd   = GetTextLineByCharIndex(filePositionItem.IndexItemEnd);
                        powerBuilderFileType.Events.Add(filePositionItem);
                    }
                }


                if (fileClass.PowerBuilderFileTypes.Count > 0)
                {
                    string functionListRegex = @"(?si)([\n](public|private|protected)(\sfunction)?|^(public|private|protected)(\sfunction)?)\s*(?<functype>\w+)\s*(?<functname>\w+)\s*(\((?<params>[^\)]*?)\));+(?<body>.*?)(?<endfunct>end(\sfunction|\ssubroutine))";
//                    string functionListRegex = @"(?si)([\n](public|private)(\sfunction)?|^(public|private)(\sfunction)?)\s*(?<functype>\w+)\s*(?<functname>\w+)\s*(\((?<params>[^)]*?)\));+(?<body>.*?)(?<endfunct>end(\sfunction|\ssubroutine))";
                    //var powerBuilderFileType = fileClass.PowerBuilderFileTypes.FirstOrDefault();
                    foreach (var powerBuilderFileType in fileClass.PowerBuilderFileTypes)
                    {
                        int length = powerBuilderFileType.IndexEnd - powerBuilderFileType.IndexInstanceVarEnd;
                        if (length < 0)
                        {
                            length = text.Length - powerBuilderFileType.IndexInstanceVarEnd;
                        }
                        var subText = text.Substring(powerBuilderFileType.IndexInstanceVarEnd, length);
                        matchCollection = Regex.Matches(subText, functionListRegex, RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5));
                        foreach (Match eventMatch in matchCollection)
                        {
                            var filePositionItem = new FilePositionItem();
                            filePositionItem.Name            = eventMatch.Groups[2].Value;
                            filePositionItem.ReturnType      = eventMatch.Groups[1].Value;
                            filePositionItem.ItemType        = "function";
                            filePositionItem.ItemParameters  = eventMatch.Groups[3].Value;
                            filePositionItem.IndexItemStart  = eventMatch.Groups[2].Index + powerBuilderFileType.IndexInstanceVarEnd;
                            filePositionItem.IndexItemEnd    = eventMatch.Groups[5].Index + powerBuilderFileType.IndexInstanceVarEnd;
                            filePositionItem.IsHasCode       = eventMatch.Groups[4].Length > 5;
                            filePositionItem.LineNumberStart = GetTextLineByCharIndex(filePositionItem.IndexItemStart);
                            filePositionItem.LineNumberEnd   = GetTextLineByCharIndex(filePositionItem.IndexItemEnd);
                            powerBuilderFileType.Functions.Add(filePositionItem);
                        }
                    }
                }

                _rnCounts = null;
            }
            catch (Exception e) {
                MessageBox.Show(e.Message);
            }
        }
示例#8
0
        private void AddFolderItems(TreeNode parentNode, string selectedPath)
        {
            string[] directories = Directory.GetDirectories(selectedPath);

            foreach (string directory in directories)
            {
                var diretoryNode = new TreeNode();
                diretoryNode.BackColor = Color.FromArgb(163, 254, 252, 225);
                var match = Regex.Match(directory, @"([^\\]+$)");
                diretoryNode.Text               = match.Value;
                diretoryNode.ToolTipText        = directory;
                diretoryNode.ImageIndex         = 2;
                diretoryNode.SelectedImageIndex = 2;
                parentNode.Nodes.Add(diretoryNode);
                AddFolderItems(diretoryNode, directory);

                var files = Directory.GetFiles(directory, "*.sr*").ToList();
                files.AddRange(Directory.GetFiles(directory, "*.sql"));

                foreach (string file in files)
                {
                    var fileNode = new TreeNode();
                    fileNode.Text = Path.GetFileNameWithoutExtension(file);
                    string extension = Path.GetExtension(file);
                    if (extension == ".srd")
                    {
                        fileNode.ImageIndex = 1;
                    }
                    else if (extension == ".srw")
                    {
                        fileNode.ImageIndex = 4;
                    }
                    else if (extension == ".sru")
                    {
                        fileNode.ImageIndex = 5;
                    }
                    else if (extension == ".srm")
                    {
                        fileNode.ImageIndex = 10;
                    }
                    else if (extension == ".srs")
                    {
                        fileNode.ImageIndex = 11;
                    }
                    else
                    {
                        fileNode.ImageIndex = 6;
                    }
                    fileNode.SelectedImageIndex = fileNode.ImageIndex;
                    fileNode.ForeColor          = Color.Black;
                    fileNode.ToolTipText        = file;

                    var fileClass = new FileClass();
                    fileClass.Name     = fileNode.Text;
                    fileClass.FilePath = file;
                    fileClass.FileName = fileNode.Text;
                    fileNode.Tag       = fileClass;
                    diretoryNode.Nodes.Add(fileNode);
                }
            }
        }
示例#9
0
 public void ReloadDocumentContent(SourceContainerDocument sourceContainerDocument, FileClass fileClass)
 {
     fileClass.Text      = ReadSourceFile(fileClass.FilePath);
     fileClass.TextState = ETextState.ReadNotChanged;
     fileClass.IsOpened  = true;
     sourceContainerDocument.SetSourceFileClass(fileClass);
 }
示例#10
0
        public static void SetSourceRules(object sender, bool isSql, FileClass fileClass)
        {
            var fctb  = (FastColoredTextBox)sender;
            var range = fctb.Range;

            //var range = fctb.Range;
            range.BeginUpdate();
            range.ClearStyle(StyleIndex.All);

            if (fileClass.FilePath.Contains(".srd") && !isSql)
            {
                range.SetStyle(SourceFileStylesClass.TypeStyle, @"(?<range>(\s*|\()(\w|\.)+)\s*\=", RegexOptions.Compiled);
            }
            //  range.SetStyle(SourceFileStylesClass.WhiteRangeStyle, @"(?si)([\n](public|private|protected)(\sfunction)?|^(public|private|protected)(\sfunction)?)\s*(?<functype>\w+)\s*(?<functname>\w+)\s*(\((?<params>[^\)]*?)\));+(?<body>.*?)(?<endfunct>end(\sfunction|\ssubroutine))");

            //SQL Arguments
            range.SetStyle(SourceFileStylesClass.MaroonStyle, @"(:\w*)");

            //Operators
            range.SetStyle(SourceFileStylesClass.OperatorStyle, @"(\.|\(|\)|\=|\[|\]|\>|\<|\+|\-|\,|\;|\*|\&)");

            //Data Types
            const string pbDataTypes = @"(DATAWINDOWCHILD|subroutine|Blob|Integer|Int|Boolean|Byte|Long|Char|character|Real|Date|String|DateTime|Time|Decimal|Dec|UnsignedInteger|UnsignedInt|UInt|Double|UnsignedLong|ULong)";

            range.SetStyle(SourceFileStylesClass.SaddleBrown, @"\b" + pbDataTypes + @"\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            //string highlighting
            range.SetStyle(SourceFileStylesClass.BrownStyle, @"""""|@""""|''|@"".*?""|(?<!@)(?<range>"".*?[^\\]"")|'.*?[^\\]'", RegexOptions.Compiled);

            //number highlighting
            range.SetStyle(SourceFileStylesClass.MagentaStyle, @"\b(\d+[\.]?\d*([eE]\-?\d+)?[lLdDfF]?\b|\b0x[a-fA-F\d]+|true|false)\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            //True False highlighting
//            range.SetStyle(SourceFileStylesClass.TrueStyle, @"\b(true)\b",RegexOptions.IgnoreCase);
//            range.SetStyle(SourceFileStylesClass.FalseStyle, @"\b(false)\b",RegexOptions.IgnoreCase);

            string SpecialWords = @"(?<range>\b(readonly|ref|public|Private|protected|function|subroutine|global|within|from|type)\b|\btype\b( variables)?|[\r\n]event|[\r\n]end (event|subroutine|function|type|variables))";

            range.SetStyle(SourceFileStylesClass.PbSpecialSourceKeywordsStyle, SpecialWords, RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string PbKeyWords = @"\b(on|call|super|HALT|CLOSE|parent|FETCH|OPEN|DECLARE|post|create|Destroy|AND|IF|ELSEIF|END|END IF|ELSE|THEN|FOR|NEXT|TO|choose|case|DO|UNTIL|LOOP|this|not|null|INTO|OR|return|while)\b";

            range.SetStyle(SourceFileStylesClass.PbKeywordsStyle, PbKeyWords, RegexOptions.IgnoreCase | RegexOptions.Compiled);

            //FunctionCall Highlight
            range.SetStyle(SourceFileStylesClass.FunctionCallStyle, @"(?<range>(?!" + PbKeyWords + "|" + pbDataTypes + "|\b(WHERE|SET)\b" + @")\b\w+)\s*?\(", RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled);

            //Types name highlighting
            range.SetStyle(SourceFileStylesClass.TypeStyle, @"(type){1}\s(?<range>\w+?)\b\s(from)", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            //Event Functions name highlighting
            //range.SetStyle(SourceFileStylesClass.EventFunctionStyle, @"[\r\n](event|function|public|protected|private){1}\s?(" + pbDataTypes + @"\s+)?(?<range>\w+?)\b", RegexOptions.IgnoreCase);

            range.SetStyle(SourceFileStylesClass.SqlCoulmnsBrown, @"(?<=\.object\.)(?<range>\w+)", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled);
            //range.SetStyle(SourceFileStylesClass.CommentsStyle, @"\.(?<range>object)\.", RegexOptions.Singleline | RegexOptions.IgnoreCase);

            //keyword highlighting
            //fctb.Range.SetStyle(BlueStyle, @"\b(abstract|as|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|do|double|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|goto|if|implicit|in|int|interface|internal|is|lock|long|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sbyte|sealed|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|virtual|void|volatile|while|add|alias|ascending|descending|dynamic|from|get|global|group|into|join|let|orderby|partial|remove|select|set|value|var|where|yield)\b|#region\b|#endregion\b");

            if (isSql)
            {
                SetSqlStyle(range);
            }
            else
            {
                //Detect sql code ranges
                IEnumerable <Range> sqlRanges = range.GetRanges(@"(?si)[\r\n][\s]*\b(execute|commit|rollback|select|SELECTBLOB|update|delete|INSERT)\b(.|[\r\n])*?((?!((COMMIT )|(ROLBACK )))using)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                foreach (Range sqlRange in sqlRanges)
                {
                    SetSqlStyle(sqlRange);
                }
            }

            // clear comment range from another styles
            string commentRegex = @"(?si)(?!('|""))(?<range>((//|--)[^\n]*)\n|(/\*(.|[\r\n])*?\*/).*?)(?!('|""))";

            foreach (Range range1 in fctb.GetRanges(commentRegex))
            {
                range1.ClearStyle(StyleIndex.All);
            }
            //comment highlighting
            range.SetStyle(SourceFileStylesClass.CommentsStyle, commentRegex, RegexOptions.Singleline | RegexOptions.Compiled);

            //clear folding markers
            range.ClearFoldingMarkers();

            if (!isSql)
            {
                //set folding markers
                range.SetFoldingMarkers(@"[\n](?<range>event)\b", @"[\n](?<range>end event)\b", RegexOptions.Compiled);                                                                                                                                                                      //allow to collapse #region blocks
                range.SetFoldingMarkers(@"[\n](?<range>(public|private|protected) (function|subroutine))\b", @"[\n](?<range>end (function|subroutine|prototypes))\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);                                                                      //allow to collapse #region blocks
                range.SetFoldingMarkers(@"(?si)[\r\n][\s]*(?<range>((?!END\s)IF))(.|\s])*?THEN(\s*\/\/(.|\s)*?)?", @"(?si)(([\r\n][\s]*)(?<range>END IF)(.|[\r\n])*?)|((?<range>THEN )(\s+.|[^\/]\w+)+?)", RegexOptions.IgnoreCase | RegexOptions.Compiled);                                 //allow to collapse #region blocks
                range.SetFoldingMarkers(@"(?si)[\r\n][\s]*(?<range>(DO))(.|[\r\n])*?", @"(?si)(([\r\n][\s]*(?<range>LOOP)(.|[\r\n])*?))", RegexOptions.IgnoreCase | RegexOptions.Compiled);                                                                                                  //allow to collapse #region blocks
                range.SetFoldingMarkers(@"(?si)[\r\n][\s]*(?<range>(FOR))(.|[\r\n])*?", @"(?si)(([\r\n][\s]*(?<range>NEXT)(.|[\r\n])*?))", RegexOptions.IgnoreCase | RegexOptions.Compiled);                                                                                                 //allow to collapse #region blocks
                range.SetFoldingMarkers(@"(?si)[\r\n][\s]*(?<range>(choose case))(.|[\r\n])*?", @"(?si)(([\r\n][\s]*(?<range>end choose)(.|[\r\n])*?))", RegexOptions.IgnoreCase | RegexOptions.Compiled);                                                                                   //allow to collapse #region blocks
                //range.SetFoldingMarkers(@"(?si)[\r\n][\s]*(?<range>((?!choose )case))(.|[\r\n])*?", @"(?si)(([\r\n][\s]*(?<range>(end choose)|((?!choose )case))(.|[\r\n])*?))",  RegexOptions.IgnoreCase | RegexOptions.Singleline); //allow to collapse #region blocks
                range.SetFoldingMarkers(@"(?si)[\r\n][\s]*(?<range>(COMMIT|ROLBACK|UPDATE|SELECT|SELECTBLOB|INSERT|DELETE|EXECUTE|PREPARE))(.|[\r\n])*?", @"(?si)([\r\n])[\s]*?\b(?<range>((?!((COMMIT )|(ROLBACK )))USING)(.|[\r\n])*?)", RegexOptions.IgnoreCase | RegexOptions.Compiled); //allow to collapse #region blocks
            }
            range.EndUpdate();
        }