Ejemplo n.º 1
0
        void openFile(string path)
        {
            //Open the file:
            StreamReader file = new StreamReader(path, Encoding.Default);
            string       text = file.ReadToEnd();

            codeEditor.Text = text;
            file.Close();

            fileSaved = true;

            //Set the current file path:
            currentFilePath = path;
            //Set the current file name:
            string[] tokens = currentFilePath.Split('\\');
            currentFileName = tokens[tokens.Length - 1];
            //Remove extension:
            tokens          = currentFileName.Split('.');
            currentFileName = tokens[0];
            //Just loaded the new file - co changes possible:
            noChanges = true;

            //Lexer:
            List <lexer.defineData>   userDefineList   = null;
            List <lexer.functionData> userFunctionList = null;
            lexer lex = new lexer();

            lex.codeAnalysis(text, ref userDefineList, ref userFunctionList, false);

            //Autocomplete list:
            ScanDocumentThreaded(true);

            //Recently opened:
            StreamWriter recentlyFile = new StreamWriter(appPath + "\\PawnStuff\\last_opened.data", false);

            recentlyFile.Write(path);
            recentlyFile.Close();

            //Update caption:
            this.Text = "Pawnfox - " + currentFileName;
        }
Ejemplo n.º 2
0
        private void analyzeThread_DoWork(object sender, DoWorkEventArgs e)
        {
            //Variables:
            string[] lines = (e.Argument.ToString()).Split('\n');
            //Define variables:
            tempDefineContent = new TreeNode();
            TreeNode maxNode    = tempDefineContent.Nodes.Add("MAX");
            TreeNode dialogNode = tempDefineContent.Nodes.Add("DIALOG");
            TreeNode colorNode  = tempDefineContent.Nodes.Add("COLORS");
            TreeNode otherNode  = tempDefineContent.Nodes.Add("Other");

            //User function variables:
            tempUserFunctionContent = new TreeNode();
            //Enum variables:
            TreeNode tempNode = null;

            tempEnumContent = new TreeNode();
            int stage = 0;

            //PVar variables:
            tempPVarContent = new TreeNode();

            //Analyse:
            tempUserFunctionList = null;
            List <lexer.defineData> defineList = null;
            lexer lex = new lexer();

            lex.codeAnalysis(e.Argument.ToString(), ref defineList, ref tempUserFunctionList, false);
            foreach (lexer.defineData define in defineList)
            {
                if (define.identifer.ToLower().Contains("max"))
                {
                    maxNode.Nodes.Add(define.identifer + " " + define.value);
                }
                else if (define.identifer.ToLower().Contains("dialog"))
                {
                    dialogNode.Nodes.Add(define.identifer + " " + define.value);
                }
                else if (define.identifer.ToLower().Contains("color"))
                {
                    colorNode.Nodes.Add(define.identifer + " " + define.value);
                }
                else
                {
                    otherNode.Nodes.Add(define.identifer + " " + define.value);
                }
            }
            foreach (lexer.functionData function in tempUserFunctionList)
            {
                tempNode = tempUserFunctionContent.Nodes.Add(function.fullIdentiferDataTypes);
                TreeNode callNode = tempNode.Nodes.Add("Calls");
                tempNode.Nodes.Add("Add to code (double click)");
                //Call stuff:
                foreach (int call in function.occurences)
                {
                    callNode.Nodes.Add((call + 1).ToString());
                }
            }

            foreach (string line in lines)
            {
                //PVars:
                if (line.ToLower().Contains("setpvar") || line.ToLower().Contains("getpvar"))
                {
                    string[] tokens = line.Split('\"');
                    if (tokens.Length >= 3)
                    {
                        string varName = "\"" + tokens[1] + "\"";
                        varName = varName.Replace("\"", "");
                        if (!varName.Contains('%'))
                        {
                            bool exists = false;
                            foreach (TreeNode node in tempPVarContent.Nodes)
                            {
                                if (node.Text == varName)
                                {
                                    exists = true;
                                    break;
                                }
                            }
                            if (!exists)
                            {
                                tempPVarContent.Nodes.Add(varName);
                            }
                        }
                    }
                }
                if (line.Contains("enum") || stage != 0)
                {
                    if (line.Contains("enum"))
                    {
                        tempNode = new TreeNode(line);
                        stage    = 1;
                    }
                    else
                    {
                        if (line.Contains('{') && !line.Contains('}'))
                        {
                            //Skip line (continue would be dangerous)
                        }
                        else if (line.Contains('}') && !line.Contains('{'))
                        {
                            tempEnumContent.Nodes.Add(tempNode);
                            stage = 0;
                        }
                        else
                        {
                            tempNode.Nodes.Add(line);
                        }
                    }
                }
            }
        }