public static string ProcessArgs(Project project, string args)
        {
            lastFileFromTemplate = QuickGenerator.QuickSettings.GenerateClass.LastFileFromTemplate;
            lastFileOptions = QuickGenerator.QuickSettings.GenerateClass.LastFileOptions;

            if (lastFileFromTemplate != null)
            {
                string fileName = Path.GetFileNameWithoutExtension(lastFileFromTemplate);

                args = args.Replace("$(FileName)", fileName);

                if (args.Contains("$(FileNameWithPackage)") || args.Contains("$(Package)"))
                {
                    string package = "";
                    string path = lastFileFromTemplate;

                    // Find closest parent

                    string classpath="";
                    if(project!=null)
                    classpath = project.AbsoluteClasspaths.GetClosestParent(path);

                    // Can't find parent, look in global classpaths
                    if (classpath == null)
                    {
                        PathCollection globalPaths = new PathCollection();
                        foreach (string cp in ProjectManager.PluginMain.Settings.GlobalClasspaths)
                            globalPaths.Add(cp);
                        classpath = globalPaths.GetClosestParent(path);
                    }
                    if (classpath != null)
                    {
                        if (project != null)
                        {
                            // Parse package name from path
                            package = Path.GetDirectoryName(ProjectPaths.GetRelativePath(classpath, path));
                            package = package.Replace(Path.DirectorySeparatorChar, '.');
                        }
                    }

                    args = args.Replace("$(Package)", package);

                    if (package.Length!=0)
                        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;
        }
Example #2
0
        public string ProcessArgs(Project project, string args)
        {
            if (lastFileFromTemplate != null)
            {
                string fileName = Path.GetFileNameWithoutExtension(lastFileFromTemplate);

                args = args.Replace("$(FileName)", fileName);

                if (args.Contains("$(FileNameWithPackage)") || args.Contains("$(Package)"))
                {
                    string package = "";
                    string path    = lastFileFromTemplate;

                    // Find closest parent
                    string classpath = project.AbsoluteClasspaths.GetClosestParent(path);

                    // Can't find parent, look in global classpaths
                    if (classpath == null)
                    {
                        PathCollection globalPaths = new PathCollection();
                        foreach (string cp in PluginMain.Settings.GlobalClasspaths)
                        {
                            globalPaths.Add(cp);
                        }
                        classpath = globalPaths.GetClosestParent(path);
                    }
                    if (classpath != null)
                    {
                        // Parse package name from path
                        package = Path.GetDirectoryName(ProjectPaths.GetRelativePath(classpath, path));
                        package = package.Replace(Path.DirectorySeparatorChar, '.');
                    }

                    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);
                    }
                }
            }
            return(args);
        }
        public void AddClass(Project project, string inDirectory)
        {
            string caption     = "Add New Class";
            string label       = "Class Name:";
            string defaultLine = "NewClass";

            LineEntryDialog dialog = new LineEntryDialog(caption, label, defaultLine);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string name = Path.GetFileNameWithoutExtension(dialog.Line);
                    string path = Path.Combine(inDirectory, name + ".as");
                    OnFileCreated(path);

                    // figure out the best classpath to build from
                    string classpath = project.AbsoluteClasspaths.GetClosestParent(path);

                    // no luck?  try the global classpaths!
                    if (classpath == null)
                    {
                        PathCollection globalPaths = new PathCollection();
                        foreach (string cp in Settings.GlobalClasspaths.Split(';'))
                        {
                            globalPaths.Add(cp);
                        }
                        classpath = globalPaths.GetClosestParent(path);
                    }

                    // still no luck?  nothing else we can do
                    if (classpath == null)
                    {
                        throw new Exception("An appropriate project classpath could not be located to create the class from.");
                    }

                    // figure out the full class name cleverly
                    string className = PathHelper.GetRelativePath(classpath, path);
                    className = className.Replace(".as", "");
                    className = className.Replace(Path.DirectorySeparatorChar, '.');

                    string constructor = className;
                    int    p           = className.LastIndexOf('.');
                    if (p >= 0)
                    {
                        constructor = className.Substring(p + 1);
                    }

                    // MIKA: DETECT EOL AND ENCODING
                    Encoding encoding  = this.fdActions.GetDefaultEncoding();
                    string   eolMarker = this.fdActions.GetDefaultEOLMarker();

                    using (FileStream stream = File.Open(path, FileMode.CreateNew))
                    {
                        StreamWriter writer = new StreamWriter(stream, encoding);
                        string       code   = eolMarker;
                        code += "class " + className + eolMarker;
                        code += "{" + eolMarker;
                        code += "\tfunction " + constructor + "()" + eolMarker;
                        code += "\t{" + eolMarker;
                        code += "\t\t";
                        DocumentSeekRequest = code.Length;
                        code += eolMarker;
                        code += "\t}" + eolMarker;
                        code += "}" + eolMarker;
                        writer.Write(code);
                        writer.Flush();
                    }
                    OpenFile(path);
                }
                catch (Exception exception)
                {
                    ErrorHandler.ShowInfo("Could not add the class: " + exception.Message);
                }
            }
        }
Example #4
0
        public string ProcessArgs(Project project, string args)
        {
            if (lastFileFromTemplate != null)
            {
                string fileName = Path.GetFileNameWithoutExtension(lastFileFromTemplate);

                args = args.Replace("$(FileName)", fileName);

                if (args.Contains("$(FileNameWithPackage)") || args.Contains("$(Package)"))
                {
                    string package = "";
                    string path = lastFileFromTemplate;

                    // Find closest parent
                    string classpath = project.AbsoluteClasspaths.GetClosestParent(path);

                    // Can't find parent, look in global classpaths
                    if (classpath == null)
                    {
                        PathCollection globalPaths = new PathCollection();
                        foreach (string cp in ProjectManager.PluginMain.Settings.GlobalClasspaths)
                            globalPaths.Add(cp);
                        classpath = globalPaths.GetClosestParent(path);
                    }
                    if (classpath != null)
                    {
                        // Parse package name from path
                        package = Path.GetDirectoryName(ProjectPaths.GetRelativePath(classpath, path));
                        package = package.Replace(Path.DirectorySeparatorChar, '.');
                    }

                    args = args.Replace("$(Package)", package);
                    args = args.Replace("$(ProName)", proName);
                    args = args.Replace("$(ProRecName)", receiveProName);
                    args = args.Replace("$(ProSendName)", sendProName);
                    if (package != "")
                        args = args.Replace("$(FileNameWithPackage)", package + "." + fileName);
                    else
                        args = args.Replace("$(FileNameWithPackage)", fileName);
                }
            }
            return args;
        }