示例#1
0
        private void DisplayClassWizard(String inDirectory, String templateFile, String className, String constructorArgs, List<String> constructorArgTypes)
        {
            Project project = PluginBase.CurrentProject as Project;
            String classpath = project.AbsoluteClasspaths.GetClosestParent(inDirectory) ?? inDirectory;
            String package;
            try
            {
                package = GetPackage(classpath, inDirectory);
                if (package == "")
                {
                    // search in Global classpath
                    Hashtable info = new Hashtable();
                    info["language"] = project.Language;
                    DataEvent de = new DataEvent(EventType.Command, "ASCompletion.GetUserClasspath", info);
                    EventManager.DispatchEvent(this, de);
                    if (de.Handled && info.ContainsKey("cp"))
                    {
                        List<string> cps = info["cp"] as List<string>;
                        if (cps != null)
                        {
                            foreach (string cp in cps)
                            {
                                package = GetPackage(cp, inDirectory);
                                if (package != "")
                                {
                                    classpath = cp;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (System.NullReferenceException)
            {
                package = "";
            }
            using (AS3ClassWizard dialog = new AS3ClassWizard())
            {
                bool isHaxe = project.Language == "haxe";
                dialog.Project = project;
                dialog.Directory = inDirectory;
                dialog.StartupClassName = className;
                if (package != null)
                {
                    package = package.Replace(Path.DirectorySeparatorChar, '.');
                    dialog.StartupPackage = package;
                }
                DialogResult conflictResult = DialogResult.OK;
                string cPackage, path, newFilePath;
                do
                {
                    if (dialog.ShowDialog() != DialogResult.OK) return;
                    cPackage = dialog.getPackage();
                    path = Path.Combine(classpath, cPackage.Replace('.', Path.DirectorySeparatorChar));
                    newFilePath = Path.ChangeExtension(Path.Combine(path, dialog.getClassName()),
                                                              isHaxe ? ".hx" : ".as");
                    if (File.Exists(newFilePath))
                    {
                        string title = " " + TextHelper.GetString("FlashDevelop.Title.ConfirmDialog");
                        string message = TextHelper.GetString("PluginCore.Info.FolderAlreadyContainsFile");
                        conflictResult = MessageBox.Show(PluginBase.MainForm,
                            string.Format(message, newFilePath, "\n"), title,
                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                        if (conflictResult == DialogResult.No) return;
                    }
                } while (conflictResult == DialogResult.Cancel);

                string templatePath = templateFile + ".wizard";
                this.lastFileFromTemplate = newFilePath;
                this.constructorArgs = constructorArgs;
                this.constructorArgTypes = constructorArgTypes;
                lastFileOptions = new AS3ClassOptions(
                    project.Language,
                    dialog.getPackage(),
                    dialog.getSuperClass(),
                    dialog.hasInterfaces() ? dialog.getInterfaces() : null,
                    dialog.isPublic(),
                    dialog.isDynamic(),
                    dialog.isFinal(),
                    dialog.getGenerateInheritedMethods(),
                    dialog.getGenerateConstructor()
                );

                try
                {
                    if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                    MainForm.FileFromTemplate(templatePath, newFilePath);
                }
                catch (Exception ex)
                {
                    ErrorManager.ShowError(ex);
                }
            }
        }
示例#2
0
 public string ProcessArgs(Project project, string args)
 {
     if (lastFileFromTemplate != null)
     {
         string package = lastFileOptions != null ? lastFileOptions.Package : "";
         string fileName = Path.GetFileNameWithoutExtension(lastFileFromTemplate);
         args = args.Replace("$(FileName)", fileName);
         if (args.Contains("$(FileNameWithPackage)") || args.Contains("$(Package)"))
         {
             if (package == "") args = args.Replace(" $(Package)", "");
             args = args.Replace("$(Package)", package);
             if (package != "") args = args.Replace("$(FileNameWithPackage)", package + "." + fileName);
             else args = args.Replace("$(FileNameWithPackage)", fileName);
             if (lastFileOptions != null)
             {
                 args = ProcessFileTemplate(args);
                 if (processOnSwitch == null) lastFileOptions = null;
             }
         }
         lastFileFromTemplate = null;
     }
     return args;
 }
示例#3
0
        public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
        {
            Project project;
            switch (e.Type)
            {
                case EventType.Command:
                    DataEvent evt = (DataEvent)e;
                    if (evt.Action == "ProjectManager.CreateNewFile")
                    {
                        Hashtable table = evt.Data as Hashtable;
                        project = PluginBase.CurrentProject as Project;
                        if ((project.Language.StartsWithOrdinal("as") || project.Language == "haxe") && IsWizardTemplate(table["templatePath"] as String))
                        {
                            evt.Handled = true;
                            String className = table.ContainsKey("className") ? table["className"] as String : TextHelper.GetString("Wizard.Label.NewClass");
                            DisplayClassWizard(table["inDirectory"] as String, table["templatePath"] as String, className, table["constructorArgs"] as String, table["constructorArgTypes"] as List<String>);
                        }
                    }
                    break;

                case EventType.FileSwitch:
                    if (PluginBase.MainForm.CurrentDocument.FileName == processOnSwitch)
                    {
                        processOnSwitch = null;
                        if (lastFileOptions == null || lastFileOptions.interfaces == null) return;
                        foreach (String cname in lastFileOptions.interfaces)
                        {
                            ASContext.Context.CurrentModel.Check();
                            ClassModel inClass = ASContext.Context.CurrentModel.GetPublicClass();
                            ASGenerator.SetJobContext(null, cname, null, null);
                            ASGenerator.GenerateJob(GeneratorJobType.ImplementInterface, null, inClass, null, null);
                        }
                        lastFileOptions = null;
                    }
                    break;

                case EventType.ProcessArgs:
                    TextEvent te = e as TextEvent;
                    project = PluginBase.CurrentProject as Project;
                    if (lastFileFromTemplate != null && project != null && (project.Language.StartsWithOrdinal("as") || project.Language == "haxe"))
                    {
                        te.Value = ProcessArgs(project, te.Value);
                    }
                    break;
            }
        }