Example #1
0
        public Project NewProject()
        {
            NewProjectDialog dialog = new NewProjectDialog();

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                try
                {
                    LuaDevelopActions.CheckAuthorName();
                    ProjectCreator creator = new ProjectCreator();
                    Project        created = creator.CreateProject(dialog.TemplateDirectory, dialog.ProjectLocation, dialog.ProjectName);
                    PatchProject(created);
                    return(created);
                }
                catch (Exception exception)
                {
                    string msg = TextHelper.GetString("Info.CouldNotCreateProject");
                    ErrorManager.ShowInfo(msg + " " + exception.Message);
                }
            }

            return(null);
        }
Example #2
0
        public void AddFileFromTemplate(Project project, string inDirectory, string templatePath, bool noName)
        {
            try
            {
                // the template could be named something like "MXML.fdt", or maybe "Class.as.fdt"
                string extension = "";
                string fileName  = Path.GetFileNameWithoutExtension(templatePath);
                string caption   = TextHelper.GetString("Label.AddNew") + " ";

                if (fileName.IndexOf('.') > -1)
                {
                    // it's something like Class.as.fdt
                    extension = Path.GetExtension(fileName); // .as
                    if (noName)
                    {
                        caption += extension.Substring(1).ToUpper() + " " + TextHelper.GetString("Label.File");
                        fileName = TextHelper.GetString("Label.NewFile");
                    }
                    else
                    {
                        caption += Path.GetFileNameWithoutExtension(fileName);
                        fileName = TextHelper.GetString("Label.New") + Path.GetFileNameWithoutExtension(fileName).Replace(" ", ""); // just Class
                    }
                }
                else
                {
                    // something like MXML.fdt
                    extension = "." + fileName.ToLower();
                    caption  += fileName + " " + TextHelper.GetString("Label.File");
                    fileName  = TextHelper.GetString("Label.NewFile");
                }

                // let plugins handle the file creation
                Hashtable info = new Hashtable();
                info["templatePath"] = templatePath;
                info["inDirectory"]  = inDirectory;
                DataEvent de = new DataEvent(EventType.Command, "ProjectManager.CreateNewFile", info);
                EventManager.DispatchEvent(this, de);
                if (de.Handled)
                {
                    return;
                }

                LineEntryDialog dialog = new LineEntryDialog(caption, TextHelper.GetString("Label.FileName"), fileName + extension);
                dialog.SelectRange(0, fileName.Length);

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    LuaDevelopActions.CheckAuthorName();

                    string newFilePath = Path.Combine(inDirectory, dialog.Line);
                    if (!Path.HasExtension(newFilePath) && extension != ".ext")
                    {
                        newFilePath = Path.ChangeExtension(newFilePath, extension);
                    }

                    if (!ConfirmOverwrite(newFilePath))
                    {
                        return;
                    }

                    // save this so when we are asked to process args, we know what file it's talking about
                    lastFileFromTemplate = newFilePath;

                    mainForm.FileFromTemplate(templatePath, newFilePath);
                }
            }
            catch (UserCancelException) { }
            catch (Exception exception)
            {
                ErrorManager.ShowError(exception);
            }
        }