bool Update(string assm_version)
        {
            if (assm_version == null)
            {
                throw new ArgumentException(assm_version);
            }

            bool changed = false;

            updating = true;

            bool gdk = false, gtk = false, posix = false;

            foreach (ProjectReference r in new List <ProjectReference> (project.References))
            {
                if (r.ReferenceType != ReferenceType.Package)
                {
                    continue;
                }
                string name = GetReferenceName(r);
                if (name == "gdk-sharp")
                {
                    gdk = true;
                }
                if (name == "gtk-sharp")
                {
                    gtk = true;
                }
                else if (name == "Mono.Posix")
                {
                    posix = true;
                }

                // Is a gtk-sharp-2.0 assembly?
                if (Array.IndexOf(gnome_assemblies, name) == -1)
                {
                    continue;
                }

                string sr      = r.StoredReference;
                string version = sr.Substring(sr.IndexOf(",") + 1).Trim();
                if (version != assm_version)
                {
                    project.References.Remove(r);
                    if (name == "gnome-sharp" && assm_version == "Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f")
                    {
                        project.References.Add(new ProjectReference(ReferenceType.Package, name + ", Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"));
                    }
                    else
                    {
                        project.References.Add(new ProjectReference(ReferenceType.Package, name + ", " + assm_version));
                    }
                    changed = true;
                }
            }

            if (!gtk)
            {
                project.References.Add(new ProjectReference(ReferenceType.Package, "gtk-sharp" + ", " + assm_version));
                changed = true;
            }

            if (!GtkDesignInfo.HasDesignedObjects(project))
            {
                return(changed);
            }

            GtkDesignInfo info = GtkDesignInfo.FromProject(project);

            if (!gdk)
            {
                project.References.Add(new ProjectReference(ReferenceType.Package, "gdk-sharp" + ", " + assm_version));
                changed = true;
            }

            if (!posix && info.GenerateGettext && info.GettextClass == "Mono.Unix.Catalog")
            {
                // Add a reference to Mono.Posix. Use the version for the selected project's runtime version.
                string aname = project.AssemblyContext.FindInstalledAssembly("Mono.Posix, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756", null, project.TargetFramework);
                aname = project.AssemblyContext.GetAssemblyNameForVersion(aname, project.TargetFramework);
                project.References.Add(new ProjectReference(ReferenceType.Package, aname));
                changed = true;
            }
            updating = false;
            return(changed);
        }
Esempio n. 2
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.");
        }