示例#1
0
		private void RefreshView(FileModel aFile)
		{
			DebugConsole.Trace("Refresh...");
			classTree.BeginStatefulUpdate();
			try
			{
				classTree.Nodes.Clear();
				TreeNode root = new TreeNode(aFile.FileName,9,9);
				classTree.Nodes.Add(root);
				//if (aFile.Version < 1) 
				//	return;
				
				TreeNodeCollection folders = root.Nodes;
				TreeNodeCollection nodes;
				TreeNode node;
				int img;
				
				// imports
				if (showImports)
				{
					node = new TreeNode("Imports", 1,1);
					folders.Add(node);
					nodes = node.Nodes;
					foreach(MemberModel import in aFile.Imports)
					{
						if (import.Type.EndsWith(".*"))
							nodes.Add(new TreeNode(import.Type, 6,6));
						else 
						{
							img = ((import.Flags & FlagType.Intrinsic) > 0) ? 7 : 0;
							nodes.Add(new TreeNode(import.Type, img,img));
						}
					}
				}
				
				// class members
				if (aFile.Members.Count > 0)
				{
					AddMembers(folders, aFile.Members);
				}
				
				// classes
				if (aFile.Classes.Count > 0)
				{
					//node = new TreeNode("Classes", 1,1);
					//folders.Add(node);
					nodes = folders; //node.Nodes;
					
					foreach(ClassModel aClass in aFile.Classes)
					{
						img = ((aClass.Flags & FlagType.Intrinsic) > 0) ? 7 : 0;
						node = new TreeNode(aClass.ClassName, img,img);
						nodes.Add(node);
						AddMembers(node.Nodes, aClass.Members);
						node.Expand();
					}
				}
				
				root.Expand();
			}
			catch(Exception ex)
			{
				ErrorHandler.ShowError(ex.Message, ex);
			}
			finally
			{
				classTree.EndStatefulUpdate();
			}
		}
示例#2
0
		public void AddFile(FileModel aFile)
		{
			if (!IsValid) return;
			//
			Files[aFile.FileName.ToUpper()] = aFile;
		}
示例#3
0
		static public FileModel ParseFile(FileModel fileModel)
		{
			string src;
			using( StreamReader sr = new StreamReader(fileModel.FileName) )
			{
				src = sr.ReadToEnd();
				sr.Close();
			}
			ASFileParser parser = new ASFileParser();
			try
			{
				fileModel.LastWriteTime = File.GetLastWriteTime(fileModel.FileName);
				if (parentPath != null) 
					cacheLastWriteTime = fileModel.LastWriteTime;
				parser.ParseSrc(fileModel, src);
			}
			catch(Exception ex)
			{
				System.Windows.Forms.MessageBox.Show("Error while parsing the file:\n"+fileModel.FileName, "Error: "+ex.Message, 
				                                    System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
			}
			return fileModel;
		}
示例#4
0
		public void UpdateView(FileModel aFile)
		{
			DebugConsole.Trace("UI: update "+aFile.FileName);
			try
			{
				// files "checksum"
				StringBuilder sb = new StringBuilder().Append(aFile.Version).Append(aFile.Package);
				foreach(MemberModel import in aFile.Imports)
					sb.Append(import.Type);
				foreach(MemberModel member in aFile.Members)
					sb.Append(member.Flags.ToString()).Append(member.ToString());
				foreach(ClassModel aClass in aFile.Classes)
				{
					sb.Append(aClass.Flags.ToString()).Append(aClass.ClassName);
					foreach(MemberModel member in aClass.Members)
						sb.Append(member.Flags.ToString()).Append(member.ToString());
				}
				if (aFile.haXe)
				foreach(ClassModel aClass in aFile.Enums)
				{
					sb.Append(aClass.Flags.ToString()).Append(aClass.ClassName);
					foreach(MemberModel member in aClass.Members)
						sb.Append(member.Flags.ToString()).Append(member.ToString());
				}
				string checksum = sb.ToString();
				if (checksum != prevChecksum)
				{
					prevChecksum = checksum;
					RefreshView(aFile);
				}
			}
			catch(Exception ex)
			{
				ErrorHandler.ShowError(ex.Message, ex);
			}
		}
示例#5
0
		private void ParseSrc(FileModel fileModel, string ba)
		{
			model = fileModel;
			if (model.haXe) model.Enums.Clear();
			model.Classes.Clear();
			model.Members.Clear();
			
			// state
			int len = ba.Length;
			if (len < 0)
				return;
			int i = 0;
			int line = 0;
			
		// when parsing cache file including multiple files
		resetParser:
			
			char c1;
			char c2;
			int matching = 0;
			bool isInString = false;
			int inString = 0;
			int braceCount = 0;
			bool inCode = true;

			// comments
			char[] commentBuffer = new char[COMMENTS_BUFFER];
			int commentLength = 0;
			lastComment = null;
			curComment = null;

			// tokenisation
			tryPackage = true;
			haXe = model.haXe;
			version = (haXe)? 4 : 1;
			curToken = new Token();
			prevToken = new Token();
			int tokPos = 0;
			int tokLine = 0;
			curMethod = null;
			curMember = null;
			valueKeyword = null;
			curModifiers = 0;
			curNamespace = "public";

			char[] buffer = new char[TOKEN_BUFFER];
			int length = 0;
			char[] valueBuffer = new char[VALUE_BUFFER];
			int valueLength = 0;
			int paramBraceCount = 0;
			int paramTempCount = 0;
			int paramParCount = 0;
			int paramSqCount = 0;

			bool hadWS = true;
			bool hadDot = false;
			inParams = false;
			inEnum = false;
			inValue = false;
			inType = false;

			bool addChar = false;
			int evalToken = 0;
			bool evalKeyword = true;
			context = 0;
			modifiers = 0;
			foundColon = false;

			while (i < len)
			{
				c1 = ba[i++];
				isInString = (inString > 0);

				/* MATCH COMMENTS / STRING LITTERALS */

				switch (matching)
				{
					// look for comment block/line and preprocessor commands
					case 0:
						if (!isInString)
						{
							// new comment
							if (c1 == '/')
							{
								c2 = ba[i];
								if (c2 == '/') {
									matching = 1;
									inCode = false;
									i++;
									continue;
								}
								else if (c2 == '*') {
									matching = 2;
									inCode = false;
									i++;
									while (i < len-1)
									{
										c2 = ba[i];
										if (c2 == '*' && ba[i+1] != '/') i++;
										else break;
									}
									continue;
								}
							}
							// don't look for comments in strings
							else if (c1 == '"')
							{
								isInString = true;
								inString = 1;
							}
							else if (c1 == '\'')
							{
								isInString = true;
								inString = 2;
							}
							// preprocessor statements
							else if (c1 == '#')
							{
								c2 = ba[i];
								if (i < 2 || ba[i-2] < 33 && c2 >= 'a' && c2 <= 'z') 
								{
									matching = 3;
									inCode = false;
									continue;
								}
							}
						}
						// end of string
						else if (isInString)
						{
							if (c1 == '\\') i++;
							else if ((inString == 1) && (c1 == '"')) inString = 0;
							else if ((inString == 2) && (c1 == '\'')) inString = 0;
						}
						break;

					// skip commented line
					case 1:
						if (c1 == 10 || c1 == 13) 
						{
							// ignore single comments
							commentLength = 0;
							inCode = true;
							matching = 0;
						}
						break;

					// skip commented block
					case 2:
						if (c1 == '*')
						{
							bool end = false;
							while (i < len)
							{
								c2 = ba[i];
								if (c2 == '/') 
								{
									end = true;
									break;
								}
								else if (c2 == '*') i++;
								else break;
							}
							if (end)
							{
								lastComment = (commentLength > 0) ? new string(commentBuffer, 0, commentLength) : null;
								// TODO  parse for TODO statements?
								commentLength = 0;
								inCode = true;
								matching = 0;
								i++;
								continue;
							}
						}
						break;
						
					// directive/preprocessor statement
					case 3:
						if (c1 == 10 || c1 == 13) 
						{
							if (commentLength > 0)
							{
								string directive = new string(commentBuffer, 0, commentLength);
								// TODO Store haXe directives in model
								
								// FD cache custom directive
								if (parentPath != null && directive.StartsWith("file-cache "))
								{
									model.Version = version;
									model = new FileModel(directive.Substring(11), cacheLastWriteTime);
									parentPath.AddFile(model);
									goto resetParser;
								}
							}
							commentLength = 0;							
							inCode = true;
							matching = 0;
						}
						break;

				}

				/* LINE/COLUMN NUMBER */

				if (c1 == 10 || c1 == 13)
				{
					line++;
					if (c1 == 13 && ba[i] == 10) i++;
				}


				/* SKIP CONTENT */

				if (!inCode)
				{
					// store comments
					if (matching == 2 || (matching == 3 && (haXe || parentPath != null)))
					{
						if (commentLength < COMMENTS_BUFFER) commentBuffer[commentLength++] = c1;
					}
					continue;
				}
				else if (isInString)
				{
					// store parameter default value
					if (inParams && inValue && valueLength < VALUE_BUFFER) valueBuffer[valueLength++] = c1;
					continue;
				}
				if (braceCount > 0)
				{
					if (c1 == '}')
					{
						braceCount--;
						if (braceCount == 0 && curMethod != null)
						{
							//Debug.WriteLine("} "+curMethod.Name+" @"+line);
							curMethod.LineTo = line;
							curMethod = null;
						}
					}
					else if (c1 == '{') braceCount++;
					continue;
				}


				/* PARSE DECLARATION VALUES/TYPES */

				if (inValue)
				{
					if (c1 == '{') paramBraceCount++;
					else if (c1 == '}'&& paramBraceCount > 0)
					{
						paramBraceCount--;
						if (paramBraceCount == 0 && paramParCount == 0 && paramSqCount == 0 && valueLength < VALUE_BUFFER) 
							valueBuffer[valueLength++] = '}';
					}
					else if (c1 == '(') paramParCount++;
					else if (c1 == ')'&& paramParCount > 0) paramParCount--;
					else if (c1 == '(') paramSqCount++;
					else if (c1 == ')' && paramSqCount > 0) paramSqCount--;
					else if (paramTempCount > 0)
					{
						if (c1 == '<') paramTempCount++;
						else if (c1 == '>') paramTempCount--;
					}

					// end of value
					if ( paramBraceCount == 0 && paramParCount == 0 && paramSqCount == 0 && paramTempCount == 0
					    && (c1 == ',' || c1 == ';' || c1 == '}' || (inParams && c1 == ')') || inType) )
					{
						inValue = false;
						length = 0;
						if (inType) valueBuffer[valueLength++] = c1;
					}

					// in params, store the default value
					else if ((inParams || inType) && valueLength < VALUE_BUFFER)
					{
						if (c1 < 32)
						{
							if (valueLength > 0 && valueBuffer[valueLength-1] != ' ') valueBuffer[valueLength++] = ' ';
						}
						else valueBuffer[valueLength++] = c1;
					}

					// only try to detect keywords
					if (c1 < 'a' || c1 > 'z')
					{
						hadWS = true;
						continue;
					}
				}
				// store parameter value
				if (!inValue && valueLength > 0)
				{
					string param = new string(valueBuffer, 0, valueLength);
					
					if (valueKeyword != null)
					{
						int p = param.LastIndexOf(valueKeyword.Text);
						if (p > 0) param = param.Substring(0,p).TrimEnd();
					}
					//
					if (curMember == null)
					{
						if (inType)
						{
							prevToken.Text = curToken.Text;
							prevToken.Line = curToken.Line;
							prevToken.Position = curToken.Position;
							curToken.Text = param;
							curToken.Line = tokLine;
							curToken.Position = tokPos;
							EvalToken(true, false, i-1-valueLength);
							evalKeyword = true;
							evalToken = 0;
						}
					}
					else if (inType)
					{
						//Debug.WriteLine("      : "+param);
						//
						foundColon = false;
						curMember.Type = param;
					}
					else
					{
						//Debug.WriteLine("      = "+param);
						//
						curMember.Parameters = new ArrayList();
						curMember.Parameters.Add(param);
					}
					//
					valueLength = 0;
					length = 0;
				}

				/* TOKENIZATION */

				// whitespace
				if (c1 <= 32)
				{
					hadWS = true;
					continue;
				}
				// a dot can be in an identifier
				if (c1 == '.')
				{
					if (length > 0 || (inParams && version == 3))
					{
						hadWS = false;
						hadDot = true;
						addChar = true;
					}
					else continue;
				}
				else
				{
					// should we evaluate the token?
					if (hadWS && !hadDot && length > 0)
					{
						evalToken = (evalKeyword) ? 1 : 2;
					}
					hadWS = false;
					hadDot = false;

					// valid char for keyword
					if (c1 >= 'a' && c1 <= 'z')
					{
						addChar = true;
					}
					else
					{
						// valid chars for identifiers
						if (c1 >= 'A' && c1 <= 'Z')
						{
							addChar = true;
						}
						else if (c1 == '$' || c1 == '_')
						{
							addChar = true;
						}
						else if (length > 0)
						{
							if (c1 >= '0' && c1 <= '9')
							{
								addChar = true;
							}
							else if (c1 == '*' && context == FlagType.Import)
							{
								addChar = true;
							}
							// haXe template types
							else if (haXe && c1 == '<')
							{
								inValue = true;
								inType = true;
								valueLength = 0;
								for(int j=0; j<length; j++)
									valueBuffer[valueLength++] = buffer[j];
								valueBuffer[valueLength++] = c1;
								length = 0;
								paramBraceCount = 0;
								paramParCount = 0;
								paramSqCount = 0;
								paramTempCount = 1;
								continue;
							}
							else
							{
								evalToken = (evalKeyword) ? 1 : 2;
							}
						}
						// star is valid in import statements
						else if (c1 == '*' && version == 3 && !foundColon)
						{
							addChar = true;
						}

						// these chars are not valid in keywords
						if (length > 0) evalKeyword = false;
					}

					// eval this word
					if (evalToken > 0)
					{
						prevToken.Text = curToken.Text;
						prevToken.Line = curToken.Line;
						prevToken.Position = curToken.Position;
						curToken.Text = new string(buffer, 0, length);
						curToken.Line = tokLine;
						curToken.Position = tokPos;
						EvalToken(!inValue, (evalToken == 1), i-1-length);
						length = 0;
						evalKeyword = true;
						evalToken = 0;
					}

					// start of block
					if (c1 == '{')
					{
						if (context == FlagType.Package || context == FlagType.Class)
						{
						}
						else if (context == FlagType.Enum)
						{
							inEnum = true;
						}
						else if (foundColon && haXe && length == 0)
						{
							inValue = true;
							inType = true;
							valueLength = 0;
							valueBuffer[valueLength++] = c1;
							paramBraceCount = 1;
							paramParCount = 0;
							paramSqCount = 0;
							paramTempCount = 0;
							continue;
						}
						else 
						{
							braceCount++;
							//Debug.WriteLine("{"+braceCount);
						}
					}
					
					// end of block
					else if (c1 == '}')
					{
						// outside of a method, the '}' ends the current class
						if (curClass != null)
						{
							//Debug.WriteLine("} class "+curClass+" @"+line);
							if (curClass != null) curClass.LineTo = line;
							curClass = null;
							tryPackage = true;
						}
					}
					
					// member type declaration
					else if (c1 == ':')
					{
						foundColon = true;
					}
					
					// next variable declaration
					else if (c1 == ',')
					{
						if (context == FlagType.Variable)
							foundKeyword = FlagType.Variable;
					}
					
					else if (c1 == '(')
					{
						// beginning of method parameters
						if (context == FlagType.Function)
						{
							context = FlagType.Variable;
							inParams = true;
							if (curMember == null)
							{
								context = FlagType.Function;
								if ((curModifiers & FlagType.Getter) > 0) 
								{
									curModifiers -= FlagType.Getter;
									EvalToken(true, false, i);
									curMethod = curMember;
								}
								else if ((curModifiers & FlagType.Setter) > 0) 
								{
									curModifiers -= FlagType.Setter;
									EvalToken(true, false, i);
									curMethod = curMember;
								}
								else
								{
									inParams = false;
									context = 0;
								}
							}
							else 
							{
								curMethod = curMember;
								Debug.WriteLine("{ "+curMember.Name);
							}
						}
						
						// an Enum value with parameters
						else if (inEnum && curToken != null)
						{
							//Debug.WriteLine("********** enum construc "+curToken);
							context = FlagType.Variable;
							inParams = true;
							curMethod = new MemberModel();
							curMethod.Name = curToken.Text;
							curMethod.Flags = curModifiers | FlagType.Function | FlagType.Enum;
							//
							if (curClass != null) curClass.Members.Add(curMethod);
						}
					}
					
					// end of statement
					else if (c1 == ';')
					{
						context = 0;
						modifiers = 0;
						inParams = false;
						curMember = null;
						//curMethod = null;
					}
					
					// end of method parameters
					else if (c1 == ')' && inParams)
					{
						context = (inEnum) ? FlagType.Enum : 0;
						modifiers = 0;
						inParams = false;
						curMember = curMethod;
					}
					
					// skip value of a declared variable
					else if (c1 == '=' && context == FlagType.Variable)
					{
						if (!inValue)
						{
							inValue = true;
							inType = false;
							paramBraceCount = 0;
							paramParCount = 0;
							paramSqCount = 0;
							paramTempCount = 0;
							valueLength = 0;
						}
					}
					
					// special haXe types: T -> T
					else if (haXe && c1 == '-' && curMember != null)
					{
						if (ba[i] == '>')
						{
							curMember.Type += " ->";
						}
					}
					
				}

				// put in buffer
				if (addChar)
				{
					if (length < TOKEN_BUFFER) buffer[length++] = c1;
					
					if (length == 1)
					{
						tokPos = i-1;
						tokLine = line;
					}
					addChar = false;
				}
			}
			
			// parsing done!
			model.Version = version;
		}
示例#6
0
		static public FileModel ParseFile(string file)
		{
			FileModel fileModel = new FileModel(file);
			return ParseFile(fileModel);
		}
        private void ParseSrc(FileModel fileModel, string ba)
        {
            model = fileModel;
            if (model.haXe)
            {
                model.Enums.Clear();
            }
            model.Classes.Clear();
            model.Members.Clear();

            // state
            int len = ba.Length;

            if (len < 0)
            {
                return;
            }
            int i    = 0;
            int line = 0;

            // when parsing cache file including multiple files
resetParser:

            char c1;
            char c2;
            int  matching   = 0;
            bool isInString = false;
            int  inString   = 0;
            int  braceCount = 0;
            bool inCode     = true;

            // comments
            char[] commentBuffer = new char[COMMENTS_BUFFER];
            int    commentLength = 0;

            lastComment = null;
            curComment  = null;

            // tokenisation
            tryPackage = true;
            haXe       = model.haXe;
            version    = (haXe)? 4 : 1;
            curToken   = new Token();
            prevToken  = new Token();
            int tokPos  = 0;
            int tokLine = 0;

            curMethod    = null;
            curMember    = null;
            valueKeyword = null;
            curModifiers = 0;
            curNamespace = "public";

            char[] buffer = new char[TOKEN_BUFFER];
            int    length = 0;

            char[] valueBuffer     = new char[VALUE_BUFFER];
            int    valueLength     = 0;
            int    paramBraceCount = 0;
            int    paramTempCount  = 0;
            int    paramParCount   = 0;
            int    paramSqCount    = 0;

            bool hadWS  = true;
            bool hadDot = false;

            inParams = false;
            inEnum   = false;
            inValue  = false;
            inType   = false;

            bool addChar     = false;
            int  evalToken   = 0;
            bool evalKeyword = true;

            context    = 0;
            modifiers  = 0;
            foundColon = false;

            while (i < len)
            {
                c1         = ba[i++];
                isInString = (inString > 0);

                /* MATCH COMMENTS / STRING LITTERALS */

                switch (matching)
                {
                // look for comment block/line and preprocessor commands
                case 0:
                    if (!isInString)
                    {
                        // new comment
                        if (c1 == '/')
                        {
                            c2 = ba[i];
                            if (c2 == '/')
                            {
                                matching = 1;
                                inCode   = false;
                                i++;
                                continue;
                            }
                            else if (c2 == '*')
                            {
                                matching = 2;
                                inCode   = false;
                                i++;
                                while (i < len - 1)
                                {
                                    c2 = ba[i];
                                    if (c2 == '*' && ba[i + 1] != '/')
                                    {
                                        i++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                continue;
                            }
                        }
                        // don't look for comments in strings
                        else if (c1 == '"')
                        {
                            isInString = true;
                            inString   = 1;
                        }
                        else if (c1 == '\'')
                        {
                            isInString = true;
                            inString   = 2;
                        }
                        // preprocessor statements
                        else if (c1 == '#')
                        {
                            c2 = ba[i];
                            if (i < 2 || ba[i - 2] < 33 && c2 >= 'a' && c2 <= 'z')
                            {
                                matching = 3;
                                inCode   = false;
                                continue;
                            }
                        }
                    }
                    // end of string
                    else if (isInString)
                    {
                        if (c1 == '\\')
                        {
                            i++;
                        }
                        else if ((inString == 1) && (c1 == '"'))
                        {
                            inString = 0;
                        }
                        else if ((inString == 2) && (c1 == '\''))
                        {
                            inString = 0;
                        }
                    }
                    break;

                // skip commented line
                case 1:
                    if (c1 == 10 || c1 == 13)
                    {
                        // ignore single comments
                        commentLength = 0;
                        inCode        = true;
                        matching      = 0;
                    }
                    break;

                // skip commented block
                case 2:
                    if (c1 == '*')
                    {
                        bool end = false;
                        while (i < len)
                        {
                            c2 = ba[i];
                            if (c2 == '/')
                            {
                                end = true;
                                break;
                            }
                            else if (c2 == '*')
                            {
                                i++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (end)
                        {
                            lastComment = (commentLength > 0) ? new string(commentBuffer, 0, commentLength) : null;
                            // TODO  parse for TODO statements?
                            commentLength = 0;
                            inCode        = true;
                            matching      = 0;
                            i++;
                            continue;
                        }
                    }
                    break;

                // directive/preprocessor statement
                case 3:
                    if (c1 == 10 || c1 == 13)
                    {
                        if (commentLength > 0)
                        {
                            string directive = new string(commentBuffer, 0, commentLength);
                            // TODO Store haXe directives in model

                            // FD cache custom directive
                            if (parentPath != null && directive.StartsWith("file-cache "))
                            {
                                model.Version = version;
                                model         = new FileModel(directive.Substring(11), cacheLastWriteTime);
                                parentPath.AddFile(model);
                                goto resetParser;
                            }
                        }
                        commentLength = 0;
                        inCode        = true;
                        matching      = 0;
                    }
                    break;
                }

                /* LINE/COLUMN NUMBER */

                if (c1 == 10 || c1 == 13)
                {
                    line++;
                    if (c1 == 13 && ba[i] == 10)
                    {
                        i++;
                    }
                }


                /* SKIP CONTENT */

                if (!inCode)
                {
                    // store comments
                    if (matching == 2 || (matching == 3 && (haXe || parentPath != null)))
                    {
                        if (commentLength < COMMENTS_BUFFER)
                        {
                            commentBuffer[commentLength++] = c1;
                        }
                    }
                    continue;
                }
                else if (isInString)
                {
                    // store parameter default value
                    if (inParams && inValue && valueLength < VALUE_BUFFER)
                    {
                        valueBuffer[valueLength++] = c1;
                    }
                    continue;
                }
                if (braceCount > 0)
                {
                    if (c1 == '}')
                    {
                        braceCount--;
                        if (braceCount == 0 && curMethod != null)
                        {
                            //Debug.WriteLine("} "+curMethod.Name+" @"+line);
                            curMethod.LineTo = line;
                            curMethod        = null;
                        }
                    }
                    else if (c1 == '{')
                    {
                        braceCount++;
                    }
                    continue;
                }


                /* PARSE DECLARATION VALUES/TYPES */

                if (inValue)
                {
                    if (c1 == '{')
                    {
                        paramBraceCount++;
                    }
                    else if (c1 == '}' && paramBraceCount > 0)
                    {
                        paramBraceCount--;
                        if (paramBraceCount == 0 && paramParCount == 0 && paramSqCount == 0 && valueLength < VALUE_BUFFER)
                        {
                            valueBuffer[valueLength++] = '}';
                        }
                    }
                    else if (c1 == '(')
                    {
                        paramParCount++;
                    }
                    else if (c1 == ')' && paramParCount > 0)
                    {
                        paramParCount--;
                    }
                    else if (c1 == '(')
                    {
                        paramSqCount++;
                    }
                    else if (c1 == ')' && paramSqCount > 0)
                    {
                        paramSqCount--;
                    }
                    else if (paramTempCount > 0)
                    {
                        if (c1 == '<')
                        {
                            paramTempCount++;
                        }
                        else if (c1 == '>')
                        {
                            paramTempCount--;
                        }
                    }

                    // end of value
                    if (paramBraceCount == 0 && paramParCount == 0 && paramSqCount == 0 && paramTempCount == 0 &&
                        (c1 == ',' || c1 == ';' || c1 == '}' || (inParams && c1 == ')') || inType))
                    {
                        inValue = false;
                        length  = 0;
                        if (inType)
                        {
                            valueBuffer[valueLength++] = c1;
                        }
                    }

                    // in params, store the default value
                    else if ((inParams || inType) && valueLength < VALUE_BUFFER)
                    {
                        if (c1 < 32)
                        {
                            if (valueLength > 0 && valueBuffer[valueLength - 1] != ' ')
                            {
                                valueBuffer[valueLength++] = ' ';
                            }
                        }
                        else
                        {
                            valueBuffer[valueLength++] = c1;
                        }
                    }

                    // only try to detect keywords
                    if (c1 < 'a' || c1 > 'z')
                    {
                        hadWS = true;
                        continue;
                    }
                }
                // store parameter value
                if (!inValue && valueLength > 0)
                {
                    string param = new string(valueBuffer, 0, valueLength);

                    if (valueKeyword != null)
                    {
                        int p = param.LastIndexOf(valueKeyword.Text);
                        if (p > 0)
                        {
                            param = param.Substring(0, p).TrimEnd();
                        }
                    }
                    //
                    if (curMember == null)
                    {
                        if (inType)
                        {
                            prevToken.Text     = curToken.Text;
                            prevToken.Line     = curToken.Line;
                            prevToken.Position = curToken.Position;
                            curToken.Text      = param;
                            curToken.Line      = tokLine;
                            curToken.Position  = tokPos;
                            EvalToken(true, false, i - 1 - valueLength);
                            evalKeyword = true;
                            evalToken   = 0;
                        }
                    }
                    else if (inType)
                    {
                        //Debug.WriteLine("      : "+param);
                        //
                        foundColon     = false;
                        curMember.Type = param;
                    }
                    else
                    {
                        //Debug.WriteLine("      = "+param);
                        //
                        curMember.Parameters = new ArrayList();
                        curMember.Parameters.Add(param);
                    }
                    //
                    valueLength = 0;
                    length      = 0;
                }

                /* TOKENIZATION */

                // whitespace
                if (c1 <= 32)
                {
                    hadWS = true;
                    continue;
                }
                // a dot can be in an identifier
                if (c1 == '.')
                {
                    if (length > 0 || (inParams && version == 3))
                    {
                        hadWS   = false;
                        hadDot  = true;
                        addChar = true;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    // should we evaluate the token?
                    if (hadWS && !hadDot && length > 0)
                    {
                        evalToken = (evalKeyword) ? 1 : 2;
                    }
                    hadWS  = false;
                    hadDot = false;

                    // valid char for keyword
                    if (c1 >= 'a' && c1 <= 'z')
                    {
                        addChar = true;
                    }
                    else
                    {
                        // valid chars for identifiers
                        if (c1 >= 'A' && c1 <= 'Z')
                        {
                            addChar = true;
                        }
                        else if (c1 == '$' || c1 == '_')
                        {
                            addChar = true;
                        }
                        else if (length > 0)
                        {
                            if (c1 >= '0' && c1 <= '9')
                            {
                                addChar = true;
                            }
                            else if (c1 == '*' && context == FlagType.Import)
                            {
                                addChar = true;
                            }
                            // haXe template types
                            else if (haXe && c1 == '<')
                            {
                                inValue     = true;
                                inType      = true;
                                valueLength = 0;
                                for (int j = 0; j < length; j++)
                                {
                                    valueBuffer[valueLength++] = buffer[j];
                                }
                                valueBuffer[valueLength++] = c1;
                                length          = 0;
                                paramBraceCount = 0;
                                paramParCount   = 0;
                                paramSqCount    = 0;
                                paramTempCount  = 1;
                                continue;
                            }
                            else
                            {
                                evalToken = (evalKeyword) ? 1 : 2;
                            }
                        }
                        // star is valid in import statements
                        else if (c1 == '*' && version == 3 && !foundColon)
                        {
                            addChar = true;
                        }

                        // these chars are not valid in keywords
                        if (length > 0)
                        {
                            evalKeyword = false;
                        }
                    }

                    // eval this word
                    if (evalToken > 0)
                    {
                        prevToken.Text     = curToken.Text;
                        prevToken.Line     = curToken.Line;
                        prevToken.Position = curToken.Position;
                        curToken.Text      = new string(buffer, 0, length);
                        curToken.Line      = tokLine;
                        curToken.Position  = tokPos;
                        EvalToken(!inValue, (evalToken == 1), i - 1 - length);
                        length      = 0;
                        evalKeyword = true;
                        evalToken   = 0;
                    }

                    // start of block
                    if (c1 == '{')
                    {
                        if (context == FlagType.Package || context == FlagType.Class)
                        {
                        }
                        else if (context == FlagType.Enum)
                        {
                            inEnum = true;
                        }
                        else if (foundColon && haXe && length == 0)
                        {
                            inValue     = true;
                            inType      = true;
                            valueLength = 0;
                            valueBuffer[valueLength++] = c1;
                            paramBraceCount            = 1;
                            paramParCount  = 0;
                            paramSqCount   = 0;
                            paramTempCount = 0;
                            continue;
                        }
                        else
                        {
                            braceCount++;
                            //Debug.WriteLine("{"+braceCount);
                        }
                    }

                    // end of block
                    else if (c1 == '}')
                    {
                        // outside of a method, the '}' ends the current class
                        if (curClass != null)
                        {
                            //Debug.WriteLine("} class "+curClass+" @"+line);
                            if (curClass != null)
                            {
                                curClass.LineTo = line;
                            }
                            curClass   = null;
                            tryPackage = true;
                        }
                    }

                    // member type declaration
                    else if (c1 == ':')
                    {
                        foundColon = true;
                    }

                    // next variable declaration
                    else if (c1 == ',')
                    {
                        if (context == FlagType.Variable)
                        {
                            foundKeyword = FlagType.Variable;
                        }
                    }

                    else if (c1 == '(')
                    {
                        // beginning of method parameters
                        if (context == FlagType.Function)
                        {
                            context  = FlagType.Variable;
                            inParams = true;
                            if (curMember == null)
                            {
                                context = FlagType.Function;
                                if ((curModifiers & FlagType.Getter) > 0)
                                {
                                    curModifiers -= FlagType.Getter;
                                    EvalToken(true, false, i);
                                    curMethod = curMember;
                                }
                                else if ((curModifiers & FlagType.Setter) > 0)
                                {
                                    curModifiers -= FlagType.Setter;
                                    EvalToken(true, false, i);
                                    curMethod = curMember;
                                }
                                else
                                {
                                    inParams = false;
                                    context  = 0;
                                }
                            }
                            else
                            {
                                curMethod = curMember;
                                Debug.WriteLine("{ " + curMember.Name);
                            }
                        }

                        // an Enum value with parameters
                        else if (inEnum && curToken != null)
                        {
                            //Debug.WriteLine("********** enum construc "+curToken);
                            context         = FlagType.Variable;
                            inParams        = true;
                            curMethod       = new MemberModel();
                            curMethod.Name  = curToken.Text;
                            curMethod.Flags = curModifiers | FlagType.Function | FlagType.Enum;
                            //
                            if (curClass != null)
                            {
                                curClass.Members.Add(curMethod);
                            }
                        }
                    }

                    // end of statement
                    else if (c1 == ';')
                    {
                        context   = 0;
                        modifiers = 0;
                        inParams  = false;
                        curMember = null;
                        //curMethod = null;
                    }

                    // end of method parameters
                    else if (c1 == ')' && inParams)
                    {
                        context   = (inEnum) ? FlagType.Enum : 0;
                        modifiers = 0;
                        inParams  = false;
                        curMember = curMethod;
                    }

                    // skip value of a declared variable
                    else if (c1 == '=' && context == FlagType.Variable)
                    {
                        if (!inValue)
                        {
                            inValue         = true;
                            inType          = false;
                            paramBraceCount = 0;
                            paramParCount   = 0;
                            paramSqCount    = 0;
                            paramTempCount  = 0;
                            valueLength     = 0;
                        }
                    }

                    // special haXe types: T -> T
                    else if (haXe && c1 == '-' && curMember != null)
                    {
                        if (ba[i] == '>')
                        {
                            curMember.Type += " ->";
                        }
                    }
                }

                // put in buffer
                if (addChar)
                {
                    if (length < TOKEN_BUFFER)
                    {
                        buffer[length++] = c1;
                    }

                    if (length == 1)
                    {
                        tokPos  = i - 1;
                        tokLine = line;
                    }
                    addChar = false;
                }
            }

            // parsing done!
            model.Version = version;
        }
        static public FileModel ParseFile(string file)
        {
            FileModel fileModel = new FileModel(file);

            return(ParseFile(fileModel));
        }
示例#9
0
		public ASContext()
		{
			cClass = ClassModel.VoidClass;
			cFile = cClass.InFile;
		}
示例#10
0
		/// <summary>
		/// Retrieves a class model from its name
		/// </summary>
		/// <param name="cname">Class (short or full) name</param>
		/// <param name="inClass">Current file</param>
		/// <returns>A parsed class or an empty ClassModel if the class is not found</returns>
		public virtual ClassModel ResolveClass(string cname, FileModel inFile)
		{
			// to be implemented
			return null;
		}
示例#11
0
		/// <summary>
		/// Currently edited class. On set, synchronise CurrentClass. 
		/// </summary>
		public FileModel SetCurrentFile(string fileName)
		{
			DebugConsole.Trace("Set '"+fileName+"'");
			// non-AS file
			if (fileName == null || fileName == "")
			{
				string nFile = MainForm.CurFile;
				if (doPathNormalization)
					nFile = nFile.Replace(dirAltSeparator, dirSeparator);
				cFile = new FileModel(nFile);
				cClass = ClassModel.VoidClass;
			}
			// AS file
			else
			{
				string nFile = fileName;
				if (doPathNormalization)
					nFile = nFile.Replace(dirAltSeparator, dirSeparator);
				cFile = PathModel.FindFile(nFile);
				cClass = cFile.GetPublicClass();
				DebugConsole.Trace("Parsed: "+cClass.ClassName);
				// update "this" and "super" special vars
				UpdateTopLevelElements();
			}
			if (Panel != null)
				Panel.UpdateView(cFile);
			return cFile;
		}
示例#12
0
        /**
         * Handles the incoming events
         */
        public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
        {
            try
            {
                // ignore all events when leaving
                if (PluginBase.MainForm.ClosingEntirely)
                {
                    return;
                }
                // current active document
                ITabbedDocument doc = PluginBase.MainForm.CurrentDocument;

                // application start
                if (!started && e.Type == EventType.UIStarted)
                {
                    started = true;
                    PathExplorer.OnUIStarted();
                    // associate context to initial document
                    e = new NotifyEvent(EventType.SyntaxChange);
                    this.pluginUI.UpdateAfterTheme();
                }

                // editor ready?
                if (doc == null)
                {
                    return;
                }
                ScintillaControl sci = doc.IsEditable ? doc.SciControl : null;

                //
                //  Events always handled
                //
                bool      isValid;
                DataEvent de;
                switch (e.Type)
                {
                // caret position in editor
                case EventType.UIRefresh:
                    if (!doc.IsEditable)
                    {
                        return;
                    }
                    timerPosition.Enabled = false;
                    timerPosition.Enabled = true;
                    return;

                // key combinations
                case EventType.Keys:
                    Keys key = (e as KeyEvent).Value;
                    if (ModelsExplorer.HasFocus)
                    {
                        e.Handled = ModelsExplorer.Instance.OnShortcut(key);
                        return;
                    }
                    if (!doc.IsEditable)
                    {
                        return;
                    }
                    e.Handled = ASComplete.OnShortcut(key, sci);
                    return;

                // user-customized shortcuts
                case EventType.Shortcut:
                    de = e as DataEvent;
                    if (de.Action == "Completion.ShowHelp")
                    {
                        ASComplete.HelpKeys = (Keys)de.Data;
                        de.Handled          = true;
                    }
                    return;

                //
                // File management
                //
                case EventType.FileSave:
                    if (!doc.IsEditable)
                    {
                        return;
                    }
                    ASContext.Context.CheckModel(false);
                    // toolbar
                    isValid = ASContext.Context.IsFileValid;
                    if (isValid && !PluginBase.MainForm.SavingMultiple)
                    {
                        if (ASContext.Context.Settings.CheckSyntaxOnSave)
                        {
                            CheckSyntax(null, null);
                        }
                        ASContext.Context.RemoveClassCompilerCache();
                    }
                    return;

                case EventType.SyntaxDetect:
                    // detect Actionscript language version
                    if (!doc.IsEditable)
                    {
                        return;
                    }
                    if (doc.FileName.ToLower().EndsWith(".as"))
                    {
                        settingObject.LastASVersion = DetectActionscriptVersion(doc);
                        (e as TextEvent).Value      = settingObject.LastASVersion;
                        e.Handled = true;
                    }
                    break;

                case EventType.ApplySettings:
                case EventType.SyntaxChange:
                case EventType.FileSwitch:
                    if (!doc.IsEditable)
                    {
                        ASContext.SetCurrentFile(null, true);
                        ContextChanged();
                        return;
                    }
                    currentDoc = doc.FileName;
                    currentPos = sci.CurrentPos;
                    // check file
                    bool ignoreFile = !doc.IsEditable;
                    ASContext.SetCurrentFile(doc, ignoreFile);
                    // UI
                    ContextChanged();
                    return;

                case EventType.Completion:
                    if (ASContext.Context.IsFileValid)
                    {
                        e.Handled = true;
                    }
                    return;

                // some commands work all the time
                case EventType.Command:
                    de = e as DataEvent;
                    string command = de.Action ?? "";

                    if (command.StartsWith("ASCompletion."))
                    {
                        string cmdData = de.Data as string;

                        // add a custom classpath
                        if (command == "ASCompletion.ClassPath")
                        {
                            Hashtable info = de.Data as Hashtable;
                            if (info != null)
                            {
                                ContextSetupInfos setup = new ContextSetupInfos();
                                setup.Platform    = (string)info["platform"];
                                setup.Lang        = (string)info["lang"];
                                setup.Version     = (string)info["version"];
                                setup.TargetBuild = (string)info["targetBuild"];
                                setup.Classpath   = (string[])info["classpath"];
                                setup.HiddenPaths = (string[])info["hidden"];
                                ASContext.SetLanguageClassPath(setup);
                                if (setup.AdditionalPaths != null)     // report custom classpath
                                {
                                    info["additional"] = setup.AdditionalPaths.ToArray();
                                }
                            }
                            e.Handled = true;
                        }

                        // send a UserClasspath
                        else if (command == "ASCompletion.GetUserClasspath")
                        {
                            Hashtable info = de.Data as Hashtable;
                            if (info != null && info.ContainsKey("language"))
                            {
                                IASContext context = ASContext.GetLanguageContext(info["language"] as string);
                                if (context != null && context.Settings != null &&
                                    context.Settings.UserClasspath != null)
                                {
                                    info["cp"] = new List <string>(context.Settings.UserClasspath);
                                }
                            }
                            e.Handled = true;
                        }
                        // update a UserClasspath
                        else if (command == "ASCompletion.SetUserClasspath")
                        {
                            Hashtable info = de.Data as Hashtable;
                            if (info != null && info.ContainsKey("language") && info.ContainsKey("cp"))
                            {
                                IASContext    context = ASContext.GetLanguageContext(info["language"] as string);
                                List <string> cp      = info["cp"] as List <string>;
                                if (cp != null && context != null && context.Settings != null)
                                {
                                    string[] pathes = new string[cp.Count];
                                    cp.CopyTo(pathes);
                                    context.Settings.UserClasspath = pathes;
                                }
                            }
                            e.Handled = true;
                        }
                        // send the language's default compiler path
                        else if (command == "ASCompletion.GetCompilerPath")
                        {
                            Hashtable info = de.Data as Hashtable;
                            if (info != null && info.ContainsKey("language"))
                            {
                                IASContext context = ASContext.GetLanguageContext(info["language"] as string);
                                if (context != null)
                                {
                                    info["compiler"] = context.GetCompilerPath();
                                }
                            }
                            e.Handled = true;
                        }

                        // show a language's compiler settings
                        else if (command == "ASCompletion.ShowSettings")
                        {
                            e.Handled = true;
                            IASContext context = ASContext.GetLanguageContext(cmdData);
                            if (context == null)
                            {
                                return;
                            }
                            string filter = "SDK";
                            string name   = "";
                            switch (cmdData.ToUpper())
                            {
                            case "AS2": name = "AS2Context"; break;

                            case "AS3": name = "AS3Context"; break;

                            default:
                                name = cmdData.Substring(0, 1).ToUpper() + cmdData.Substring(1) + "Context";
                                break;
                            }
                            PluginBase.MainForm.ShowSettingsDialog(name, filter);
                        }

                        // Open types explorer dialog
                        else if (command == "ASCompletion.TypesExplorer")
                        {
                            TypesExplorer(null, null);
                        }

                        // call the Flash IDE
                        else if (command == "ASCompletion.CallFlashIDE")
                        {
                            if (flashErrorsWatcher == null)
                            {
                                flashErrorsWatcher = new FlashErrorsWatcher();
                            }
                            e.Handled = CallFlashIDE.Run(settingObject.PathToFlashIDE, cmdData);
                        }

                        // create Flash 8+ trust file
                        else if (command == "ASCompletion.CreateTrustFile")
                        {
                            if (cmdData != null)
                            {
                                string[] args = cmdData.Split(';');
                                if (args.Length == 2)
                                {
                                    e.Handled = CreateTrustFile.Run(args[0], args[1]);
                                }
                            }
                        }
                        else if (command == "ASCompletion.GetClassPath")
                        {
                            if (cmdData != null)
                            {
                                string[] args = cmdData.Split(';');
                                if (args.Length == 1)
                                {
                                    FileModel  model  = ASContext.Context.GetFileModel(args[0]);
                                    ClassModel aClass = model.GetPublicClass();
                                    if (!aClass.IsVoid())
                                    {
                                        Clipboard.SetText(aClass.QualifiedName);
                                        e.Handled = true;
                                    }
                                }
                            }
                        }
                        else if (command == "ProjectManager.FileActions.DisableWatchers")
                        {
                            foreach (PathModel cp in ASContext.Context.Classpath)
                            {
                                cp.DisableWatcher();
                            }
                        }
                        else if (command == "ProjectManager.FileActions.EnableWatchers")
                        {
                            // classpaths could be invalid now - remove those, BuildClassPath() is too expensive
                            ASContext.Context.Classpath.RemoveAll(cp => !Directory.Exists(cp.Path));

                            foreach (PathModel cp in ASContext.Context.Classpath)
                            {
                                cp.EnableWatcher();
                            }
                        }

                        // Return requested language SDK list
                        else if (command == "ASCompletion.InstalledSDKs")
                        {
                            Hashtable info = de.Data as Hashtable;
                            if (info != null && info.ContainsKey("language"))
                            {
                                IASContext context = ASContext.GetLanguageContext(info["language"] as string);
                                if (context != null)
                                {
                                    info["sdks"] = context.Settings.InstalledSDKs;
                                }
                            }
                            e.Handled = true;
                        }
                    }

                    // Create a fake document from a FileModel
                    else if (command == "ProjectManager.OpenVirtualFile")
                    {
                        string cmdData = de.Data as string;
                        if (reVirtualFile.IsMatch(cmdData))
                        {
                            string[] path     = Regex.Split(cmdData, "::");
                            string   fileName = path[0] + Path.DirectorySeparatorChar
                                                + path[1].Replace('.', Path.DirectorySeparatorChar).Replace("::", Path.DirectorySeparatorChar.ToString());
                            FileModel found = ModelsExplorer.Instance.OpenFile(fileName);
                            if (found != null)
                            {
                                e.Handled = true;
                            }
                        }
                    }
                    else if (command == "ProjectManager.UserRefreshTree")
                    {
                        ASContext.UserRefreshRequestAll();
                    }
                    break;
                }

                //
                // Actionscript context specific
                //
                if (ASContext.Context.IsFileValid)
                {
                    switch (e.Type)
                    {
                    case EventType.ProcessArgs:
                        TextEvent te = (TextEvent)e;
                        if (reArgs.IsMatch(te.Value))
                        {
                            // resolve current element
                            Hashtable details = ASComplete.ResolveElement(sci, null);
                            te.Value = ArgumentsProcessor.Process(te.Value, details);

                            if (te.Value.IndexOf("$") >= 0 && reCostlyArgs.IsMatch(te.Value))
                            {
                                ASResult result = ASComplete.CurrentResolvedContext.Result ?? new ASResult();
                                details = new Hashtable();
                                // Get closest list (Array or Vector)
                                string closestListName = "", closestListItemType = "";
                                ASComplete.FindClosestList(ASContext.Context, result.Context, sci.CurrentLine, ref closestListName, ref closestListItemType);
                                details.Add("TypClosestListName", closestListName);
                                details.Add("TypClosestListItemType", closestListItemType);
                                // get free iterator index
                                string iterator = ASComplete.FindFreeIterator(ASContext.Context, ASContext.Context.CurrentClass, result.Context);
                                details.Add("ItmUniqueVar", iterator);
                                te.Value = ArgumentsProcessor.Process(te.Value, details);
                            }
                        }
                        break;

                    // menu commands
                    case EventType.Command:
                        string command = (e as DataEvent).Action ?? "";
                        if (command.StartsWith("ASCompletion."))
                        {
                            string cmdData = (e as DataEvent).Data as string;
                            // run MTASC
                            if (command == "ASCompletion.CustomBuild")
                            {
                                if (cmdData != null)
                                {
                                    ASContext.Context.RunCMD(cmdData);
                                }
                                else
                                {
                                    ASContext.Context.RunCMD("");
                                }
                                e.Handled = true;
                            }

                            // build the SWF using MTASC
                            else if (command == "ASCompletion.QuickBuild")
                            {
                                ASContext.Context.BuildCMD(false);
                                e.Handled = true;
                            }

                            // resolve element under cusor and open declaration
                            else if (command == "ASCompletion.GotoDeclaration")
                            {
                                ASComplete.DeclarationLookup(sci);
                                e.Handled = true;
                            }

                            // resolve element under cursor and send a CustomData event
                            else if (command == "ASCompletion.ResolveElement")
                            {
                                ASComplete.ResolveElement(sci, cmdData);
                                e.Handled = true;
                            }
                            else if (command == "ASCompletion.MakeIntrinsic")
                            {
                                ASContext.Context.MakeIntrinsic(cmdData);
                                e.Handled = true;
                            }

                            // alternative to default shortcuts
                            else if (command == "ASCompletion.CtrlSpace")
                            {
                                ASComplete.OnShortcut(Keys.Control | Keys.Space, ASContext.CurSciControl);
                                e.Handled = true;
                            }
                            else if (command == "ASCompletion.CtrlShiftSpace")
                            {
                                ASComplete.OnShortcut(Keys.Control | Keys.Shift | Keys.Space, ASContext.CurSciControl);
                                e.Handled = true;
                            }
                            else if (command == "ASCompletion.CtrlAltSpace")
                            {
                                ASComplete.OnShortcut(Keys.Control | Keys.Alt | Keys.Space, ASContext.CurSciControl);
                                e.Handled = true;
                            }
                            else if (command == "ASCompletion.ContextualGenerator")
                            {
                                if (ASContext.HasContext && ASContext.Context.IsFileValid)
                                {
                                    ASGenerator.ContextualGenerator(ASContext.CurSciControl);
                                }
                            }
                        }
                        return;

                    case EventType.ProcessEnd:
                        string procResult = (e as TextEvent).Value;
                        ASContext.Context.OnProcessEnd(procResult);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorManager.ShowError(ex);
            }
        }
示例#13
0
        private void ConvertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = outlineTreeView.SelectedNode;

            if (node == null || current == null || current.Classpath == null)
            {
                return;
            }

            ResolvedPath resolved = ResolvePath(node);
            string       package  = resolved.package;
            PathModel    thePath  = resolved.model;

            if (thePath == null)
            {
                return;
            }

            if (node is TypeTreeNode)
            {
                string    filename = (node.Tag as string).Split('@')[0];
                FileModel theModel = thePath.GetFile(filename);
                if (theModel == null)
                {
                    return;
                }

                saveFileDialog.Title      = TextHelper.GetString("Title.SaveIntrinsicAs");
                saveFileDialog.FileName   = Path.GetFileName(filename);
                saveFileDialog.DefaultExt = Path.GetExtension(filename);
                if (PluginBase.CurrentProject != null)
                {
                    saveFileDialog.InitialDirectory = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath);
                }
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        WriteIntrinsic(theModel, saveFileDialog.FileName);
                    }
                    catch (Exception ex)
                    {
                        ErrorManager.ShowError(ex);
                    }
                }
            }
            else
            {
                folderBrowserDialog.ShowNewFolderButton    = true;
                folderBrowserDialog.UseDescriptionForTitle = true;
                folderBrowserDialog.Description            = TextHelper.GetString("Title.SelectIntrinsicTargetFolder");
                if (PluginBase.CurrentProject != null)
                {
                    folderBrowserDialog.SelectedPath = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath);
                }
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        string sourcePath = Path.Combine(thePath.Path, package.Replace('.', Path.DirectorySeparatorChar));
                        string targetPath = folderBrowserDialog.SelectedPath + Path.DirectorySeparatorChar;
                        string packagep   = (package.Length > 0) ? package + "." : "";

                        thePath.ForeachFile((aModel) =>
                        {
                            if (aModel.Package == package || aModel.Package.StartsWithOrdinal(packagep))
                            {
                                if (aModel.FileName.StartsWithOrdinal(sourcePath))
                                {
                                    WriteIntrinsic(aModel, aModel.FileName.Replace(sourcePath, targetPath));
                                }
                            }
                            return(true);
                        });
                    }
                    catch (Exception ex)
                    {
                        ErrorManager.ShowError(ex);
                    }
                }
            }
        }
示例#14
0
 /// <summary>
 /// Retrieves a class model from its name
 /// </summary>
 /// <param name="cname">Class (short or full) name</param>
 /// <param name="inClass">Current file</param>
 /// <returns>A parsed class or an empty ClassModel if the class is not found</returns>
 public virtual ClassModel ResolveClass(string cname, FileModel inFile)
 {
     // to be implemented
     return(null);
 }
示例#15
0
 public ASContext()
 {
     cClass = ClassModel.VoidClass;
     cFile  = cClass.InFile;
 }