Exemplo n.º 1
0
        public void UpdateASCompletion(IMainForm mainForm, Project project)
        {
            List <string> classPaths  = new List <string>();
            List <string> hiddenPaths = new List <string>();
            string        version;
            string        platform = "";

            if (project != null)
            {
                BuildActions.GetCompilerPath(project); // refresh project's SDK
                project.UpdateVars(true);

                // platform/version
                platform = project.MovieOptions.Platform;
                version  = project.MovieOptions.Version;
                if (platform != PlatformData.FLASHPLAYER_PLATFORM &&
                    project.MovieOptions.HasPlatformSupport && project.MovieOptions.PlatformSupport.IsFlashPlatform)
                {
                    version = PlatformData.ResolveFlashPlayerVersion(project.Language, platform, version);
                }

                // add project classpaths
                foreach (string cp in project.AbsoluteClasspaths)
                {
                    if (Directory.Exists(cp))
                    {
                        classPaths.Add(cp);
                    }
                }

                // add AS3 libraries
                string absPath;
                if (project is AS3Project)
                {
                    MxmlcOptions options = (project as AS3Project).CompilerOptions;
                    foreach (string relPath in options.IntrinsicPaths)
                    {
                        absPath = PathHelper.ResolvePath(relPath);
                        if (absPath == null)
                        {
                            absPath = project.GetAbsolutePath(relPath);
                        }
                        if (absPath == null)
                        {
                            continue;
                        }
                        if (Directory.Exists(absPath))
                        {
                            classPaths.Add(absPath);
                        }
                    }
                    foreach (string relPath in options.LibraryPaths)
                    {
                        absPath = project.GetAbsolutePath(relPath);
                        if (absPath == null)
                        {
                            continue;
                        }
                        if (File.Exists(absPath))
                        {
                            classPaths.Add(absPath);
                        }
                        else if (Directory.Exists(absPath))
                        {
                            string[] libs = Directory.GetFiles(absPath, "*.swc");
                            foreach (string lib in libs)
                            {
                                classPaths.Add(lib);
                            }
                        }
                    }
                    foreach (string relPath in options.IncludeLibraries)
                    {
                        absPath = project.GetAbsolutePath(relPath);
                        if (absPath == null)
                        {
                            continue;
                        }
                        if (Directory.Exists(absPath) || File.Exists(absPath))
                        {
                            classPaths.Add(absPath);
                        }
                    }
                    foreach (string relPath in options.ExternalLibraryPaths)
                    {
                        absPath = project.GetAbsolutePath(relPath);
                        if (absPath == null)
                        {
                            continue;
                        }
                        if (Directory.Exists(absPath) || File.Exists(absPath))
                        {
                            classPaths.Add(absPath);
                        }
                    }
                    foreach (string relPath in options.RSLPaths)
                    {
                        string[] parts = relPath.Split(',');
                        if (parts.Length < 2)
                        {
                            continue;
                        }
                        absPath = project.GetAbsolutePath(relPath);
                        if (absPath == null)
                        {
                            continue;
                        }
                        if (File.Exists(absPath))
                        {
                            classPaths.Add(absPath);
                        }
                    }
                }

                string dir = project.Directory;
                foreach (string hidPath in project.HiddenPaths)
                {
                    absPath = Path.Combine(dir, hidPath);
                    foreach (string cp in classPaths)
                    {
                        if (absPath.StartsWithOrdinal(cp))
                        {
                            hiddenPaths.Add(absPath);
                            break;
                        }
                    }
                }
            }
            else if (PlatformData.SupportedLanguages.ContainsKey("as3"))
            {
                var targets       = PlatformData.SupportedLanguages["as3"].Platforms;
                var flashPlatform = targets[PlatformData.FLASHPLAYER_PLATFORM];
                version = flashPlatform.LastVersion.Value;
            }
            else
            {
                version = "11.0";
            }

            DataEvent de;
            Hashtable info = new Hashtable();

            // release old classpath
            if (currentLang != null && project == null)
            {
                info["lang"]        = currentLang;
                info["platform"]    = "";
                info["targetBuild"] = "";
                info["version"]     = "0.0";
                info["classpath"]   = null;
                info["hidden"]      = null;

                de = new DataEvent(EventType.Command, "ASCompletion.ClassPath", info);
                EventManager.DispatchEvent(this, de);
            }

            // set new classpath
            if (project != null)
            {
                currentLang = project.Language;

                info["platform"]    = platform;
                info["version"]     = version;
                info["targetBuild"] = project.TargetBuild;
                info["lang"]        = currentLang;
                info["classpath"]   = classPaths.ToArray();
                info["hidden"]      = hiddenPaths.ToArray();

                de = new DataEvent(EventType.Command, "ASCompletion.ClassPath", info);
                EventManager.DispatchEvent(this, de);

                project.AdditionalPaths = info.ContainsKey("additional") ? info["additional"] as string[] : null;
            }
            else
            {
                currentLang = null;
            }
        }