Exemple #1
0
        bool OpenVirtualFileModel(string virtualPath)
        {
            var p = virtualPath.IndexOfOrdinal("::");

            if (p < 0)
            {
                return(false);
            }
            var container = virtualPath.Substring(0, p);

            if (!File.Exists(container))
            {
                return(false);
            }
            var ext = Path.GetExtension(container).ToLower();

            if (ext == ".swf" || ext == ".swc")
            {
                var fileName = Path.Combine(container, virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
                var path     = new PathModel(container, contextInstance);
                var parser   = new ContentParser(path.Path);
                parser.Run();
                AbcConverter.Convert(parser, path, contextInstance);
                if (!path.HasFile(fileName))
                {
                    return(false);
                }
                var model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return(true);
            }
            return(false);
        }
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOf("::");

            if (p < 0)
            {
                return(false);
            }

            string container = virtualPath.Substring(0, p);
            string ext       = Path.GetExtension(container).ToLower();

            if (ext != ".loomlib")
            {
                return(false);
            }
            if (!File.Exists(container))
            {
                return(false);
            }

            string    fileName = Path.Combine(container, virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel path     = new PathModel(container, contextInstance);

            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return(true);
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Open a file in the classpath (physical or virtual) or a specific context
        /// </summary>
        public FileModel OpenFile(string filename, IASContext context)
        {
            if (context == null || context.Classpath == null)
            {
                return(null);
            }
            FileModel model = null;

            foreach (PathModel aPath in context.Classpath)
            {
                if (aPath.HasFile(filename))
                {
                    model = aPath.GetFile(filename);
                    break;
                }
            }
            if (model != null)
            {
                if (File.Exists(model.FileName))
                {
                    ASContext.MainForm.OpenEditableDocument(model.FileName, false);
                }
                else
                {
                    ASComplete.OpenVirtualFile(model);
                    model = ASContext.Context.CurrentModel;
                }
            }
            return(model);
        }
Exemple #4
0
        private bool OpenVirtualFileModel(string virtualPath)
        {
            int p = virtualPath.IndexOf("::");

            if (p < 0)
            {
                return(false);
            }

            string container = virtualPath.Substring(0, p);
            string ext       = Path.GetExtension(container).ToLower();

            if (ext != ".swf" && ext != ".swc" && ext != ".ane")
            {
                return(false);
            }
            if (!File.Exists(container))
            {
                return(false);
            }

            string        fileName = Path.Combine(container, virtualPath.Substring(p + 2).Replace('.', Path.DirectorySeparatorChar));
            PathModel     path     = new PathModel(container, contextInstance);
            ContentParser parser   = new ContentParser(path.Path);

            parser.Run();
            AbcConverter.Convert(parser, path, contextInstance);

            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return(true);
            }
            int split = fileName.LastIndexOf(Path.DirectorySeparatorChar) + 1;

            fileName = fileName.Substring(0, split) + "package.as";
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return(true);
            }
            fileName = fileName.Substring(0, split) + "toplevel.as";
            if (path.HasFile(fileName))
            {
                FileModel model = path.GetFile(fileName);
                ASComplete.OpenVirtualFile(model);
                return(true);
            }
            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Checks if a given search match actually points to the given target source
        /// </summary>
        /// <returns>True if the SearchMatch does point to the target source.</returns>
        public static ASResult DeclarationLookupResult(ScintillaControl Sci, int position)
        {
            if (!ASContext.Context.IsFileValid || (Sci == null))
            {
                return(null);
            }
            // get type at cursor position
            ASResult result = ASComplete.GetExpressionType(Sci, position);

            if (result.IsPackage)
            {
                return(result);
            }
            // open source and show declaration
            if (!result.IsNull())
            {
                if (result.Member != null && (result.Member.Flags & FlagType.AutomaticVar) > 0)
                {
                    return(null);
                }
                FileModel model = result.InFile ?? ((result.Member != null && result.Member.InFile != null) ? result.Member.InFile : null) ?? ((result.Type != null) ? result.Type.InFile : null);
                if (model == null || model.FileName == "")
                {
                    return(null);
                }
                ClassModel inClass = result.InClass ?? result.Type;
                // for Back command
                int lookupLine = Sci.CurrentLine;
                int lookupCol  = Sci.CurrentPos - Sci.PositionFromLine(lookupLine);
                ASContext.Panel.SetLastLookupPosition(ASContext.Context.CurrentFile, lookupLine, lookupCol);
                // open the file
                if (model != ASContext.Context.CurrentModel)
                {
                    if (model.FileName.Length > 0 && File.Exists(model.FileName))
                    {
                        ASContext.MainForm.OpenEditableDocument(model.FileName, false);
                    }
                    else
                    {
                        ASComplete.OpenVirtualFile(model);
                        result.InFile = ASContext.Context.CurrentModel;
                        if (result.InFile == null)
                        {
                            return(null);
                        }
                        if (inClass != null)
                        {
                            inClass = result.InFile.GetClassByName(inClass.Name);
                            if (result.Member != null)
                            {
                                result.Member = inClass.Members.Search(result.Member.Name, 0, 0);
                            }
                        }
                        else if (result.Member != null)
                        {
                            result.Member = result.InFile.Members.Search(result.Member.Name, 0, 0);
                        }
                    }
                }
                if ((inClass == null || inClass.IsVoid()) && result.Member == null)
                {
                    return(null);
                }
                Sci = ASContext.CurSciControl;
                if (Sci == null)
                {
                    return(null);
                }
                int    line    = 0;
                string name    = null;
                bool   isClass = false;
                // member
                if (result.Member != null && result.Member.LineFrom > 0)
                {
                    line = result.Member.LineFrom;
                    name = result.Member.Name;
                }
                // class declaration
                else if (inClass.LineFrom > 0)
                {
                    line    = inClass.LineFrom;
                    name    = inClass.Name;
                    isClass = true;
                    // constructor
                    foreach (MemberModel member in inClass.Members)
                    {
                        if ((member.Flags & FlagType.Constructor) > 0)
                        {
                            line    = member.LineFrom;
                            name    = member.Name;
                            isClass = false;
                            break;
                        }
                    }
                }
                if (line > 0) // select
                {
                    if (isClass)
                    {
                        ASComplete.LocateMember("(class|interface)", name, line);
                    }
                    else
                    {
                        ASComplete.LocateMember("(function|var|const|get|set|property|[,(])", name, line);
                    }
                }
                return(result);
            }
            return(null);
        }