Пример #1
0
        /// <summary>
        /// Classpathes & classes cache initialisation
        /// </summary>
        public override void BuildClassPath()
        {
            ReleaseClasspath();
            started = true;
            if (as3settings == null)
            {
                throw new Exception("BuildClassPath() must be overridden");
            }
            if (contextSetup == null)
            {
                contextSetup          = new ContextSetupInfos();
                contextSetup.Lang     = settings.LanguageId;
                contextSetup.Platform = "Flash Player";
                contextSetup.Version  = as3settings.DefaultFlashVersion;
            }

            // external version definition
            platform     = contextSetup.Platform;
            majorVersion = 10;
            minorVersion = 0;
            ParseVersion(contextSetup.Version, ref majorVersion, ref minorVersion);
            hasAIRSupport    = platform == "AIR" || platform == "AIR Mobile";
            hasMobileSupport = platform == "AIR Mobile";

            string cpCheck = contextSetup.Classpath != null?
                             String.Join(";", contextSetup.Classpath).Replace('\\', '/') : "";

            // check if CP contains a custom playerglobal.swc
            bool hasCustomAPI = re_customAPI.IsMatch(cpCheck);

            //
            // Class pathes
            //
            classPath = new List <PathModel>();
            MxmlFilter.ClearCatalogs();
            MxmlFilter.AddProjectManifests();

            // SDK
            string compiler = PluginBase.CurrentProject != null
                ? PluginBase.CurrentProject.CurrentSDK
                : as3settings.GetDefaultSDK().Path;

            char S = Path.DirectorySeparatorChar;

            if (compiler == null)
            {
                compiler = Path.Combine(PathHelper.ToolDir, "flexlibs");
            }
            string        frameworks     = compiler + S + "frameworks";
            string        sdkLibs        = frameworks + S + "libs";
            string        sdkLocales     = frameworks + S + "locale" + S + PluginBase.MainForm.Settings.LocaleVersion;
            string        fallbackLibs   = PathHelper.ResolvePath(PathHelper.ToolDir + S + "flexlibs" + S + "frameworks" + S + "libs");
            string        fallbackLocale = PathHelper.ResolvePath(PathHelper.ToolDir + S + "flexlibs" + S + "frameworks" + S + "locale" + S + "en_US");
            List <string> addLibs        = new List <string>();
            List <string> addLocales     = new List <string>();

            if (!Directory.Exists(sdkLibs) && !sdkLibs.StartsWith("$")) // fallback
            {
                sdkLibs = PathHelper.ResolvePath(PathHelper.ToolDir + S + "flexlibs" + S + "frameworks" + S + "libs" + S + "player");
            }

            if (majorVersion > 0 && !String.IsNullOrEmpty(sdkLibs) && Directory.Exists(sdkLibs))
            {
                // core API SWC
                if (!hasCustomAPI)
                {
                    if (hasAIRSupport)
                    {
                        addLibs.Add("air" + S + "airglobal.swc");
                        addLibs.Add("air" + S + "aircore.swc");
                        addLibs.Add("air" + S + "applicationupdater.swc");
                    }
                    else
                    {
                        bool   swcPresent   = false;
                        string playerglobal = MatchPlayerGlobalExact(majorVersion, minorVersion, sdkLibs);
                        if (playerglobal != null)
                        {
                            swcPresent = true;
                        }
                        else
                        {
                            playerglobal = MatchPlayerGlobalExact(majorVersion, minorVersion, fallbackLibs);
                        }
                        if (playerglobal == null)
                        {
                            playerglobal = MatchPlayerGlobalAny(ref majorVersion, ref minorVersion, fallbackLibs);
                        }
                        if (playerglobal == null)
                        {
                            playerglobal = MatchPlayerGlobalAny(ref majorVersion, ref minorVersion, sdkLibs);
                        }
                        if (playerglobal != null)
                        {
                            // add missing SWC in new SDKs
                            if (!swcPresent && sdkLibs.IndexOf(S + "flexlibs") < 0 && Directory.Exists(compiler))
                            {
                                string swcDir = sdkLibs + S + "player" + S;
                                if (!Directory.Exists(swcDir + "9") && !Directory.Exists(swcDir + "10"))
                                {
                                    swcDir += majorVersion + "." + minorVersion;
                                }
                                else
                                {
                                    swcDir += majorVersion;
                                }
                                try
                                {
                                    if (!File.Exists(swcDir + S + "playerglobal.swc"))
                                    {
                                        Directory.CreateDirectory(swcDir);
                                        File.Copy(playerglobal, swcDir + S + "playerglobal.swc");
                                        File.WriteAllText(swcDir + S + "FlashDevelopNotice.txt",
                                                          "This 'playerglobal.swc' was copied here automatically by FlashDevelop from:\r\n" + playerglobal);
                                    }
                                    playerglobal = swcDir + S + "playerglobal.swc";
                                }
                                catch { }
                            }
                            addLibs.Add(playerglobal);
                        }
                    }
                }
                addLocales.Add("playerglobal_rb.swc");

                // framework SWCs
                string as3Fmk = PathHelper.ResolvePath("Library" + S + "AS3" + S + "frameworks");

                // Flex core - ie. (Bitmap|Font|ByteArray|...)Asset / Flex(Sprite|MobieClip|Loader...)
                addLibs.Add("flex.swc");
                addLibs.Add("core.swc");

                // Flex framework
                if (cpCheck.IndexOf("Library/AS3/frameworks/Flex", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    addLibs.Add("framework.swc");
                    addLibs.Add("mx/mx.swc");
                    addLibs.Add("rpc.swc");
                    addLibs.Add("datavisualization.swc");
                    addLibs.Add("flash-integration.swc");
                    addLocales.Add("framework_rb.swc");
                    addLocales.Add("mx_rb.swc");
                    addLocales.Add("rpc_rb.swc");
                    addLocales.Add("datavisualization_rb.swc");
                    addLocales.Add("flash-integration_rb.swc");

                    if (hasAIRSupport)
                    {
                        addLibs.Add("air" + S + "airframework.swc");
                        addLocales.Add("airframework_rb.swc");
                    }

                    if (cpCheck.IndexOf("Library/AS3/frameworks/Flex4", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        addLibs.Add("spark.swc");
                        addLibs.Add("spark_dmv.swc");
                        addLibs.Add("sparkskins.swc");
                        //addLibs.Add("textLayout.swc");
                        addLibs.Add("osmf.swc");
                        addLocales.Add("spark_rb.swc");
                        //addLocales.Add("textLayout_rb.swc");
                        addLocales.Add("osmf_rb.swc");

                        if (hasAIRSupport)
                        {
                            addLibs.Add("air" + S + "airspark.swc");
                            addLocales.Add("airspark_rb.swc");

                            if (hasMobileSupport)
                            {
                                addLibs.Add("mobile" + S + "mobilecomponents.swc");
                                addLocales.Add("mobilecomponents_rb.swc");
                            }
                        }

                        MxmlFilter.AddManifest("http://ns.adobe.com/mxml/2009", as3Fmk + S + "Flex4" + S + "manifest.xml");
                    }
                    else
                    {
                        MxmlFilter.AddManifest(MxmlFilter.OLD_MX, as3Fmk + S + "Flex3" + S + "manifest.xml");
                    }
                }
            }

            foreach (string file in addLocales)
            {
                string swcItem = sdkLocales + S + file;
                if (!File.Exists(swcItem))
                {
                    swcItem = fallbackLocale + S + file;
                }
                AddPath(swcItem);
            }
            foreach (string file in addLibs)
            {
                if (File.Exists(file))
                {
                    AddPath(file);
                }
                else
                {
                    AddPath(sdkLibs + S + file);
                }
            }

            // intrinsics (deprecated, excepted for FP10 Vector.<T>)
            string fp9cp = as3settings.AS3ClassPath + S + "FP9";

            AddPath(PathHelper.ResolvePath(fp9cp));
            if (majorVersion > 9)
            {
                string fp10cp = as3settings.AS3ClassPath + S + "FP" + majorVersion;
                AddPath(PathHelper.ResolvePath(fp10cp));
                string fp101cp = as3settings.AS3ClassPath + S + "FP" + majorVersion + "." + minorVersion;
                AddPath(PathHelper.ResolvePath(fp101cp));
            }

            // add external pathes
            List <PathModel> initCP = classPath;

            classPath = new List <PathModel>();
            if (contextSetup.Classpath != null)
            {
                foreach (string cpath in contextSetup.Classpath)
                {
                    AddPath(cpath.Trim());
                }
            }

            // add library
            AddPath(PathHelper.LibraryDir + S + "AS3" + S + "classes");
            // add user pathes from settings
            if (settings.UserClasspath != null && settings.UserClasspath.Length > 0)
            {
                foreach (string cpath in settings.UserClasspath)
                {
                    AddPath(cpath.Trim());
                }
            }

            // add initial pathes
            foreach (PathModel mpath in initCP)
            {
                AddPath(mpath);
            }

            // parse top-level elements
            InitTopLevelElements();
            if (cFile != null)
            {
                UpdateTopLevelElements();
            }

            // add current temporaty path
            if (temporaryPath != null)
            {
                string tempPath = temporaryPath;
                temporaryPath = null;
                SetTemporaryPath(tempPath);
            }
            FinalizeClasspath();
        }
Пример #2
0
        /// <summary>
        /// Handles the incoming events
        /// </summary>
        public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
        {
            if (priority == HandlingPriority.Low)
            {
                switch (e.Type)
                {
                case EventType.ProcessArgs:
                    TextEvent te = e as TextEvent;
                    if (te.Value.IndexOfOrdinal("$(FlexSDK)") >= 0)
                    {
                        te.Value = te.Value.Replace("$(FlexSDK)", contextInstance.GetCompilerPath());
                    }
                    break;

                case EventType.Command:
                    DataEvent de     = e as DataEvent;
                    string    action = de.Action;
                    if (action == "ProjectManager.Project")
                    {
                        FlexShells.Instance.Stop();     // clear
                    }
                    else if (action == "ProjectManager.OpenVirtualFile")
                    {
                        if (PluginBase.CurrentProject != null && PluginBase.CurrentProject.Language == "as3")
                        {
                            e.Handled = OpenVirtualFileModel(de.Data as String);
                        }
                    }
                    else if (!settingObject.DisableFDB && action == "AS3Context.StartDebugger")
                    {
                        string workDir = (PluginBase.CurrentProject != null)
                                ? Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath)
                                : Environment.CurrentDirectory;

                        string flexSdk = settingObject.GetDefaultSDK().Path;

                        // if the default sdk is not defined ask for project sdk
                        if (String.IsNullOrEmpty(flexSdk))
                        {
                            flexSdk = PluginBase.MainForm.ProcessArgString("$(CompilerPath)");
                        }
                        e.Handled = FlexDebugger.Start(workDir, flexSdk, null);
                    }
                    else if (action == "AS3Context.StartProfiler")
                    {
                        if (profilerUI.AutoStart)
                        {
                            profilerUI.StartProfiling();
                        }
                    }
                    break;

                case EventType.Keys:
                    if (inMXML)
                    {
                        KeyEvent ke = e as KeyEvent;
                        if (ke.Value == PluginBase.MainForm.GetShortcutItemKeys("SearchMenu.GotoDeclaration"))
                        {
                            if (MxmlComplete.GotoDeclaration())
                            {
                                ke.Handled    = true;
                                ke.ProcessKey = false;
                            }
                        }
                    }
                    break;
                }
                return;
            }

            else if (priority == HandlingPriority.Normal)
            {
                switch (e.Type)
                {
                case EventType.UIStarted:
                    contextInstance = new Context(settingObject);
                    ValidateSettings();
                    AddToolbarItems();
                    // Associate this context with AS3 language
                    ASContext.RegisterLanguage(contextInstance, "as3");
                    ASContext.RegisterLanguage(contextInstance, "mxml");
                    break;

                case EventType.FileSave:
                case EventType.FileSwitch:
                    if (contextInstance != null)
                    {
                        contextInstance.OnFileOperation(e);
                    }

                    if (PluginBase.MainForm.CurrentDocument.IsEditable)
                    {
                        string ext = Path.GetExtension(PluginBase.MainForm.CurrentDocument.FileName);
                        inMXML = (ext.ToLower() == ".mxml");
                        MxmlComplete.IsDirty = true;
                    }
                    else
                    {
                        inMXML = false;
                    }
                    break;
                }
                return;
            }

            else if (priority == HandlingPriority.High)
            {
                if (e.Type == EventType.Command)
                {
                    string action = (e as DataEvent).Action;
                    if (action == "ProjectManager.Project")
                    {
                        FlexDebugger.Stop();
                        IProject project = PluginBase.CurrentProject;
                        viewButton.Enabled = project == null || project.Language == "as3" || project.Language == "haxe";
                    }
                    else if (action.StartsWithOrdinal("FlashViewer."))
                    {
                        if (action == "FlashViewer.Closed")
                        {
                            FlexDebugger.Stop();
                        }
                        else if (action == "FlashViewer.External" || action == "FlashViewer.Default" ||
                                 action == "FlashViewer.Popup" || action == "FlashViewer.Document")
                        {
                            if (PluginBase.CurrentProject != null &&
                                PluginBase.CurrentProject.EnableInteractiveDebugger)
                            {
                                DataEvent de = new DataEvent(EventType.Command, "AS3Context.StartProfiler", null);
                                EventManager.DispatchEvent(this, de);

                                if (PluginBase.CurrentProject.TraceEnabled)
                                {
                                    de = new DataEvent(EventType.Command, "AS3Context.StartDebugger", (e as DataEvent).Data);
                                    EventManager.DispatchEvent(this, de);
                                }
                            }
                        }
                    }
                    else if (action == "FlashConnect")
                    {
                        ProfilerUI.HandleFlashConnect(sender, (e as DataEvent).Data);
                    }
                    else if (inMXML)
                    {
                        DataEvent de = e as DataEvent;
                        if (de.Action == "XMLCompletion.Element")
                        {
                            de.Handled = MxmlComplete.HandleElement(de.Data);
                        }
                        if (de.Action == "XMLCompletion.Namespace")
                        {
                            de.Handled = MxmlComplete.HandleNamespace(de.Data);
                        }
                        else if (de.Action == "XMLCompletion.CloseElement")
                        {
                            de.Handled = MxmlComplete.HandleElementClose(de.Data);
                        }
                        else if (de.Action == "XMLCompletion.Attribute")
                        {
                            de.Handled = MxmlComplete.HandleAttribute(de.Data);
                        }
                        else if (de.Action == "XMLCompletion.AttributeValue")
                        {
                            de.Handled = MxmlComplete.HandleAttributeValue(de.Data);
                        }
                    }
                }
            }
        }