Beispiel #1
0
 /// <summary>
 /// Disposes the plugin
 /// </summary>
 public void Dispose()
 {
     FlexDebugger.Stop();
     if (profilerUI != null)
     {
         profilerUI.Cleanup();
     }
     this.SaveSettings();
 }
Beispiel #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.IndexOf("$(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 as AS3Settings).DisableFDB && action == "AS3Context.StartDebugger")
                    {
                        string workDir = (PluginBase.CurrentProject != null)
                                ? Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath)
                                : Environment.CurrentDirectory;

                        string flexSdk = (settingObject as AS3Settings).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.StartsWith("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);
                        }
                    }
                }
            }
        }