Exemplo n.º 1
0
        protected override void Run()
        {
            _isRunning = true;
            try {
                _document = IdeApp.Workbench.ActiveDocument;
                _editor   = _document.Editor;
                _project  = _document.Project as DotNetProject;

                if (_project != null)
                {
                    _newNamespace = _project.GetDefaultNamespace(_document.FileName.ToString());

                    var namespaceLine    = _editor.GetLine(_editor.Caret.Line);
                    var oldNamespacetext = _editor.GetLineText(_editor.Caret.Line);
                    _originalNamespace = GetNameSpaceAtCaret();
                    var newNamespaceText = oldNamespacetext.Replace(_originalNamespace, _newNamespace);

                    //TODO ask for confirmation
                    var isRefactoring = ShowMessageBox("Do you wish to refactor?\nThe refactoring functionality is experimental, you should ensure you have committed/backed up first.");
                    if (isRefactoring)
                    {
                        RefactorNamespaceChanges();
                    }
                    var modifiedText          = GetUpdatedSourceText(_editor.Text);
                    var oldNamespaceStatement = string.Format("namespace {0}", _originalNamespace);
                    var newNameSpaceStatement = string.Format("namespace {0}", _newNamespace);

                    modifiedText         = modifiedText.Replace(oldNamespaceStatement, newNameSpaceStatement);
                    _editor.Text         = modifiedText;
                    _editor.Caret.Line   = namespaceLine.LineNumber;
                    _editor.Caret.Column = "namespace ".Length + 1;
                    _document.IsDirty    = true;
//					_editor.Replace (namespaceLine.Offset, namespaceLine.Length, newNamespaceText);
                }
            } catch (Exception ex) {
            }
            _isRunning = false;
        }
Exemplo n.º 2
0
        // Can add tags for substitution based on project, language or filename.
        // If overriding but still want base implementation's tags, should invoke base method.
        // We supply defaults whenever it is possible, to avoid having unsubstituted tags. However,
        // do not substitute blanks when a sensible default cannot be guessed, because they result
        //in less obvious errors.
        public virtual void ModifyTags(SolutionItem policyParent, Project project, string language,
                                       string identifier, string fileName, ref Dictionary <string, string> tags)
        {
            DotNetProject    netProject        = project as DotNetProject;
            string           languageExtension = "";
            ILanguageBinding binding           = null;

            if (!string.IsNullOrEmpty(language))
            {
                binding = GetLanguageBinding(language);
                if (binding != null)
                {
                    languageExtension = Path.GetExtension(binding.GetFileName("Default")).Remove(0, 1);
                }
            }

            //need a default namespace or if there is no project, substitutions can get very messed up
            string ns = netProject != null?netProject.GetDefaultNamespace(fileName) : "Application";

            //need an 'identifier' for tag substitution, e.g. class name or page name
            //if not given an identifier, use fileName
            if ((identifier == null) && (fileName != null))
            {
                identifier = Path.GetFileName(fileName);
            }

            if (identifier != null)
            {
                //remove all extensions
                while (Path.GetExtension(identifier).Length > 0)
                {
                    identifier = Path.GetFileNameWithoutExtension(identifier);
                }
                identifier        = CreateIdentifierName(identifier);
                tags ["Name"]     = identifier;
                tags ["FullName"] = ns.Length > 0 ? ns + "." + identifier : identifier;

                //some .NET languages may be able to use keywords as identifiers if they're escaped
                IDotNetLanguageBinding dnb = binding as IDotNetLanguageBinding;
                if (dnb != null)
                {
                    System.CodeDom.Compiler.CodeDomProvider provider = dnb.GetCodeDomProvider();
                    if (provider != null)
                    {
                        tags ["EscapedIdentifier"] = provider.CreateEscapedIdentifier(identifier);
                    }
                }
            }

            tags ["Namespace"] = ns;
            if (project != null)
            {
                tags ["ProjectName"]     = project.Name;
                tags ["SafeProjectName"] = CreateIdentifierName(project.Name);
                var info = project.AuthorInformation ?? AuthorInformation.Default;
                tags ["AuthorCopyright"] = info.Copyright;
                tags ["AuthorCompany"]   = info.Company;
                tags ["AuthorTrademark"] = info.Trademark;
                tags ["AuthorEmail"]     = info.Email;
                tags ["AuthorName"]      = info.Name;
            }
            if ((language != null) && (language.Length > 0))
            {
                tags ["Language"] = language;
            }
            if (languageExtension.Length > 0)
            {
                tags ["LanguageExtension"] = languageExtension;
            }

            if (fileName != FilePath.Null)
            {
                FilePath fileDirectory = Path.GetDirectoryName(fileName);
                if (project != null && project.BaseDirectory != FilePath.Null && fileDirectory.IsChildPathOf(project.BaseDirectory))
                {
                    tags ["ProjectRelativeDirectory"] = fileDirectory.ToRelative(project.BaseDirectory);
                }
                else
                {
                    tags ["ProjectRelativeDirectory"] = fileDirectory;
                }

                tags ["FileNameWithoutExtension"] = Path.GetFileNameWithoutExtension(fileName);
                tags ["Directory"] = fileDirectory;
                tags ["FileName"]  = fileName;
            }
        }
        public virtual void GenerateFiles(DotNetProject project, string namspace, string referenceName)
        {
            //make sure we have a valid value for the namespace
            if (string.IsNullOrEmpty(namspace))
            {
                namspace = project.GetDefaultNamespace(null);
            }

            // Create the base directory if it does not exists
            FilePath basePath = GetReferencePath(project, referenceName).CanonicalPath;

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            // Remove old files from the service directory
            List <ProjectFile> toRemove = new List <ProjectFile>(project.Files.GetFilesInPath(basePath));

            foreach (ProjectFile f in toRemove)
            {
                project.Files.Remove(f);
            }

            // Generate the wsdl, disco and map files
            string mapSpec = GenerateDescriptionFiles(project, basePath);

            // Generate the proxy class
            string proxySpec = CreateProxyFile(project, basePath, namspace + "." + referenceName, "Reference");

            ProjectFile mapFile = new ProjectFile(mapSpec);

            mapFile.BuildAction = BuildAction.None;
            mapFile.Subtype     = Subtype.Code;
            mapFile.Generator   = ProxyGenerator;
            project.Files.Add(mapFile);

            ProjectFile proxyFile = new ProjectFile(proxySpec);

            proxyFile.BuildAction = BuildAction.Compile;
            proxyFile.Subtype     = Subtype.Code;
            proxyFile.DependsOn   = mapFile.FilePath;
            project.Files.Add(proxyFile);

            mapFile.LastGenOutput = proxyFile.FilePath.FileName;

            item = new WebReferenceItem(engine, project, referenceName, basePath, mapFile);

            // Add references to the project if they do not exist
            ProjectReference packageRef;

            foreach (string refName in GetAssemblyReferences())
            {
                string targetName = project.TargetRuntime.AssemblyContext.GetAssemblyNameForVersion(refName, null, project.TargetFramework);
                //FIXME: warn when we could not find a matching target assembly
                if (targetName != null)
                {
                    packageRef = new ProjectReference(ReferenceType.Package, targetName);
                    if (!project.References.Contains(packageRef))
                    {
                        project.References.Add(packageRef);
                    }
                }
            }
            WebReferencesService.NotifyWebReferencesChanged(project);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the default namespace for the file, according to the naming policy.
 /// </summary>
 /// <remarks>Always returns a valid namespace, even if the fileName is null.</remarks>
 public string GetDefaultNamespace(string fileName, bool useVisualStudioNamingPolicy = false)
 {
     return(DotNetProject.GetDefaultNamespace(this, DefaultNamespace, fileName, useVisualStudioNamingPolicy));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Adds the custom classes from user interface definition files.
        /// </summary>
        /// <returns>
        /// <c>true</c> if new types were added to the project, or <c>false</c> otherwise.
        /// </returns>
        /// <param name='monitor'>
        /// A progress monitor.
        /// </param>
        /// <param name='context'>
        /// A sync-back context.
        /// </param>
        bool AddCustomClassesFromUIDefinitionFiles(IProgressMonitor monitor, XcodeSyncBackContext context)
        {
            var provider = dnp.LanguageBinding.GetCodeDomProvider();
            var options  = new System.CodeDom.Compiler.CodeGeneratorOptions();
            var writer   = MonoDevelop.DesignerSupport.CodeBehindWriter.CreateForProject(
                new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor(), dnp);
            bool addedTypes = false;

            monitor.BeginTask(GettextCatalog.GetString("Generating custom classes defined in UI definition files"), 0);

            // Collect our list of custom classes from UI definition files
            foreach (var job in context.FileSyncJobs)
            {
                if (!HasInterfaceDefinitionExtension(job.Original))
                {
                    continue;
                }

                string relative = job.SyncedRelative.ParentDirectory;
                string dir      = dnp.BaseDirectory;

                if (!string.IsNullOrEmpty(relative))
                {
                    dir = Path.Combine(dir, relative);
                }

                foreach (var type in GetCustomTypesFromUIDefinition(job.Original))
                {
                    if (context.ProjectInfo.ContainsType(type.ObjCName))
                    {
                        continue;
                    }

                    string designerPath = Path.Combine(dir, type.ObjCName + ".designer." + provider.FileExtension);
                    string path         = Path.Combine(dir, type.ObjCName + "." + provider.FileExtension);
                    string ns           = dnp.GetDefaultNamespace(path);

                    type.CliName = ns + "." + provider.CreateValidIdentifier(type.ObjCName);

                    if (provider is Microsoft.CSharp.CSharpCodeProvider)
                    {
                        CodebehindTemplateBase cs = new CSharpCodeTypeDefinition()
                        {
                            WrapperNamespace = infoService.WrapperRoot,
                            Provider         = provider,
                            Type             = type,
                        };

                        writer.WriteFile(path, cs.TransformText());

                        List <NSObjectTypeInfo> types = new List <NSObjectTypeInfo> ();
                        types.Add(type);

                        cs = new CSharpCodeCodebehind()
                        {
                            WrapperNamespace = infoService.WrapperRoot,
                            Provider         = provider,
                            Types            = types,
                        };

                        writer.WriteFile(designerPath, cs.TransformText());

                        context.ProjectInfo.InsertUpdatedType(type);
                    }
                    else
                    {
                        // FIXME: implement support for non-C# languages
                    }

                    dnp.AddFile(new ProjectFile(path));
                    dnp.AddFile(new ProjectFile(designerPath)
                    {
                        DependsOn = path
                    });
                    addedTypes = true;
                }
            }

            writer.WriteOpenFiles();

            monitor.EndTask();

            return(addedTypes);
        }
Exemplo n.º 6
0
        public override async Task <bool> AddToProjectAsync(SolutionFolderItem policyParent, Project project, string language, string directory, string name)
        {
            if (!GtkDesignInfo.SupportsDesigner(project))
            {
                ReferenceManager mgr = new ReferenceManager(project as DotNetProject);
                mgr.GtkPackageVersion = mgr.DefaultGtkVersion;
                mgr.Dispose();
            }

            GtkDesignInfo info = GtkDesignInfo.FromProject((DotNetProject)project);

            GuiBuilderProject gproject = info.GuiBuilderProject;

            string fileName = fileTemplate.GetFileName(policyParent, project, language, directory, name);
            await fileTemplate.AddToProjectAsync(policyParent, project, language, directory, name);

            DotNetProject netProject = project as DotNetProject;
            string        ns         = netProject != null?netProject.GetDefaultNamespace(fileName) : "";

            string cname    = Path.GetFileNameWithoutExtension(fileName);
            string fullName = ns.Length > 0 ? ns + "." + cname : cname;

            string[,] tags =
            {
                { "Name",      cname    },
                { "Namespace", ns       },
                { "FullName",  fullName }
            };

            XmlElement widgetElem = steticTemplate ["widget"];

            if (widgetElem != null)
            {
                string content = widgetElem.OuterXml;
                content = StringParserService.Parse(content, tags);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(content);

                gproject.AddNewComponent(doc.DocumentElement);
                gproject.SaveAll(false);
                IdeApp.ProjectOperations.SaveAsync(project).Ignore();
                return(true);
            }

            widgetElem = steticTemplate ["action-group"];
            if (widgetElem != null)
            {
                string content = widgetElem.OuterXml;
                content = StringParserService.Parse(content, tags);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(content);

                gproject.SteticProject.AddNewActionGroup(doc.DocumentElement);
                gproject.SaveAll(false);
                IdeApp.ProjectOperations.SaveAsync(project).Ignore();
                return(true);
            }

            throw new InvalidOperationException("<widget> or <action-group> element not found in widget template.");
        }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the default namespace for the file, according to the naming policy.
 /// </summary>
 /// <remarks>Always returns a valid namespace, even if the fileName is null.</remarks>
 public string GetDefaultNamespace(string fileName)
 {
     return(DotNetProject.GetDefaultNamespace(this, DefaultNamespace, fileName));
 }