public override void SetUp() { base.SetUp(); touchedFiles = new List<TouchedFile>(); logStub.Stub(x => x.TouchedFiles) .Return(touchedFiles); scmData.Stub(x => x.Log("10")) .Return(logStub); mapper = new ProjectFileMapper(scmData); }
/// <summary> /// Handles the incoming events /// </summary> public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority) { TextEvent te = e as TextEvent; DataEvent de = e as DataEvent; ITabbedDocument document = PluginBase.MainForm.CurrentDocument; //BxmlDesigner designer = document != null && designers.ContainsKey(document) ? designers[document] : null; // TODO: we need to handle these too: //ProjectManagerEvents.BuildComplete; //ProjectManagerEvents.BuildFailed; //ProjectManagerEvents.BuildProject; //ProjectManagerEvents.CreateProject; //ProjectManagerEvents.FileMoved; //ProjectManagerEvents.FilePasted; //ProjectManagerEvents.OpenVirtualFile; //ProjectManagerEvents.ProjectCreated; if (e.Type == EventType.Command && de.Action == ProjectManagerEvents.FileMapping) { ProjectFileMapper.Map((FileMappingRequest)de.Data); return; } // our first priority is getting a non-null Project, otherwise // we can't do anything if (e.Type == EventType.Command && de.Action == ProjectManagerEvents.Project) { // the projectexplorer plugin is telling us what project we're working with this.asproject = de.Data as ProjectManager.Projects.Project; Console.WriteLine("We found a project " + this.asproject + " : " + de.Data + " : " + (de.Data is ProjectManager.Projects.Project)); //return; } // we need a project and context to handle these events if (e.Type == EventType.FileOpen) { if (this.IsNfxMxml(document)) { Console.WriteLine("MXML file opened"); PluginBase.MainForm.CallCommand("ChangeSyntax", "xml"); // var timer = new Timer { Interval = 1, Enabled = true }; // timer.Tick += (o, evt) => // { // timer.Enabled = false; // create the design surface //if (GetProjectAndContext()) //{ // if (project.AbsoluteClasspaths.GetClosestParent(document.FileName) != null) // { // designer = new BxmlDesigner(document, project, GetDesignerSwfPath()); // designers.Add(document, designer); // //Compile(document, designer); // } // else // SendErrorToResults(document.FileName, "Cannot design this file because the classpath could not be determined."); //} //else SendErrorToResults(document.FileName, "Could not start up the Bent Designer - no project loaded or AS3 completion plugin not loaded."); // }; } } else if (e.Type == EventType.FileClose) { Console.WriteLine("MXML file closed"); // TODO: Recompile code behind here //if (designers.ContainsKey(document)) // designers.Remove(document); } else if (e.Type == EventType.Command) { switch (de.Action) { case ProjectManagerEvents.BuildComplete: // TODO: Not sure we need this //if (!GetProjectAndContext()) return; //if (!File.Exists(project.OutputPathAbsolute)) return; //if (!CheckIsBentApplication()) return; //BuildDesignerSwf(); //foreach (BxmlDesigner d in designers.Values) // d.SwfOutdated = true; //if (designer != null) // designer.ReloadSwf(); break; case "XMLCompletion.Element": // TODO: Not yet... //if (!IsBxml(document) || !GetProjectAndContext()) return; //if (designer == null) return; ////DateTime started = DateTime.Now; //completion.HandleElement(designer, (XMLContextTag)de.Data); //TraceManager.Add("Took " + (DateTime.Now - started).TotalMilliseconds + "ms."); //e.Handled = true; break; case "XMLCompletion.CloseElement": // TODO: We would try to rely on FD own autocompletion better... //if (!IsBxml(document) || !GetProjectAndContext()) return; //if (designer == null) return; //string ending = completion.HandleCloseElement(designer, (XMLContextTag)de.Data); //if (ending != null) //{ // if (ending != ">") // { // ScintillaNet.ScintillaControl sci = document.SciControl; // int position = sci.CurrentPos; // sci.SetSel(position - 1, position); // sci.ReplaceSel(ending); // sci.SetSel(position + 1, position + 1); // } // e.Handled = true; //} break; case "XMLCompletion.Attribute": // TODO: We would try to rely on FD own autocompletion better... //if (!IsBxml(document) || !GetProjectAndContext()) return; //if (designer == null) return; //object[] o = de.Data as object[]; ////started = DateTime.Now; //completion.HandleAttribute(designer, (XMLContextTag)o[0], o[1] as string); ////TraceManager.Add("Took " + (DateTime.Now - started).TotalMilliseconds + "ms."); //e.Handled = true; break; } } else if (e.Type == EventType.FileSave && this.IsNfxMxml(document)) { Console.WriteLine("MXML file saved " + document.FileName); if (String.IsNullOrEmpty(this.preprocessorLocation)) { OpenFileDialog dialog = new OpenFileDialog(); dialog.CheckFileExists = true; dialog.Filter = "JAR files (*.jar)|*.jar"; DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK) { this.preprocessorLocation = this.settingObject.ParserPath = dialog.FileNames[0]; } else { return; } } this.context = ASCompletion.Context.ASContext.GetLanguageContext("as3"); string classpath = this.asproject.AbsoluteClasspaths.GetClosestParent(document.FileName); Console.WriteLine("Our classpath: " + classpath); ASCompletion.Model.PathModel pathModel = context.Classpath.Find(pm => pm.Path == classpath); Hashtable ht = new Hashtable(); ht.Add("-source", document.FileName); ht.Add("-source-dir", classpath); NotifyEvent ne = new NotifyEvent(EventType.ProcessStart); EventManager.DispatchEvent(this, ne); PluginCore.Managers.EventManager.DispatchEvent( this, new DataEvent(EventType.Command, "ResultsPanel.ClearResults", null)); // TEST: trying to remove sci from our generated AS file so we won't get an update message ITabbedDocument[] documents = FlashDevelop.Globals.MainForm.Documents; ITabbedDocument current = FlashDevelop.Globals.MainForm.CurrentDocument; Boolean designerOpen = false; Char[] splitter = new Char[] { '.' }; foreach (ITabbedDocument doc in documents) { Console.WriteLine("doc.FileName " + doc.FileName + " document " + document.FileName); if (doc.FileName.Split(splitter)[0] == document.FileName.Split(splitter)[0]) { // Our designer AS file is open now designerOpen = true; this.lastDesignerFileName = doc.FileName; this.tempRemovedSci = doc.SciControl; //((Form)doc).Controls.Remove(doc.SciControl); break; } } if (designerOpen) { if (this.restoreDesigner == null) { this.restoreDesigner = new Timer(); this.restoreDesigner.Interval = 50; this.restoreDesigner.Tick += new EventHandler(restoreDesigner_Tick); } this.restoreDesigner.Enabled = true; } NFXShell.Run(new FileInfo(document.FileName), this.preprocessorLocation, null, ht); // TODO: we should only handle our projects // TODO: not really sure this will be needed as those files should be picked up by ASCompletion anyway. //string classpath = this.project.AbsoluteClasspaths.GetClosestParent(document.FileName); this.TellASCompletionAbout(document.FileName, pathModel); } else if (e.Type == EventType.FileSwitch) { // TODO: think we don't need this //if (!GetProjectAndContext()) return; //// if this flash is marked as "dirty" we'll need to reload it //if (designer != null && designer.SwfOutdated) // designer.ReloadSwf(); } else if (e.Type == EventType.UIStarted) { // TODO: Not sure what this does... we'll see later this.projectManager = (ProjectManager.PluginMain)PluginBase.MainForm.FindPlugin( "30018864-fadd-1122-b2a5-779832cbbf23"); //ProjectManager.Controls.TreeView.FileNode.FileAssociations.Add(".nxml", NFXNode.Create); //Timer timer = new Timer(); //timer.Interval = 100; //timer.Tick += delegate { GetProjectAndContext(); timer.Stop(); }; //timer.Start(); } }