Пример #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
        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 = Path.GetDirectoryName(ProjectPaths.GetRelativePath(classpath, Path.Combine(inDirectory, "foo")));
            }
            catch (System.NullReferenceException)
            {
                package = "";
            }
            AS3ClassWizard dialog = new AS3ClassWizard();

            dialog.Project          = project;
            dialog.Directory        = inDirectory;
            dialog.StartupClassName = className;
            if (package != null)
            {
                package = package.Replace(Path.DirectorySeparatorChar, '.');
                dialog.StartupPackage = package;
            }
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string cPackage    = dialog.getPackage();
                string path        = Path.Combine(classpath, dialog.getPackage().Replace('.', Path.DirectorySeparatorChar));
                string newFilePath = Path.ChangeExtension(Path.Combine(path, dialog.getClassName()), ".as");
                if (File.Exists(newFilePath))
                {
                    string       title   = " " + TextHelper.GetString("FlashDevelop.Title.ConfirmDialog");
                    string       message = TextHelper.GetString("ProjectManager.Info.FolderAlreadyContainsFile");
                    DialogResult result  = MessageBox.Show(PluginBase.MainForm, string.Format(message, newFilePath, "\n"), title, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                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);
                }
            }
        }