예제 #1
0
        public static void Export(ProjectBackend project, string filename)
        {
            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;

            XmlElement toplevel = doc.CreateElement("glade-interface");

            doc.AppendChild(toplevel);

            ObjectWriter owriter = new ObjectWriter(doc, FileFormat.Glade);

            foreach (Widget w in project.Toplevels)
            {
                Stetic.Wrapper.Container wrapper = Stetic.Wrapper.Container.Lookup(w);
                if (wrapper == null)
                {
                    continue;
                }

                XmlElement elem = wrapper.Write(owriter);
                if (elem != null)
                {
                    toplevel.AppendChild(elem);
                }
            }

            doc = GladeUtils.XslExportTransform(doc);

            XmlTextWriter writer = new XmlTextWriter(filename, EncodingUtility.UTF8NoBom);

            writer.Formatting = Formatting.Indented;
            doc.Save(writer);
            writer.Close();
        }
예제 #2
0
        XmlDocument Write(bool includeUndoInfo)
        {
            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;

            XmlElement toplevel = doc.CreateElement("stetic-interface");

            doc.AppendChild(toplevel);

            ObjectWriter writer = new ObjectWriter(doc, FileFormat.Native);

            writer.CreateUndoInfo = includeUndoInfo;
            if (ownedGlobalActionGroups)
            {
                foreach (Wrapper.ActionGroup agroup in actionGroups)
                {
                    XmlElement elem = agroup.Write(writer);
                    toplevel.AppendChild(elem);
                }
            }

            if (iconFactory.Icons.Count > 0)
            {
                toplevel.AppendChild(iconFactory.Write(doc));
            }

            foreach (WidgetData data in topLevels)
            {
                if (data.Widget != null)
                {
                    Stetic.Wrapper.Container wrapper = Stetic.Wrapper.Container.Lookup(data.Widget);
                    if (wrapper == null)
                    {
                        continue;
                    }

                    XmlElement elem = wrapper.Write(writer);
                    if (elem != null)
                    {
                        toplevel.AppendChild(elem);
                    }
                }
                else
                {
                    toplevel.AppendChild(doc.ImportNode(data.XmlData, true));
                }
            }

            // Remove undo annotations from the xml document
            if (!includeUndoInfo)
            {
                CleanUndoData(doc.DocumentElement);
            }

            return(doc);
        }
예제 #3
0
        XmlDocument Write(bool includeUndoInfo)
        {
            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;

            XmlElement toplevel = doc.CreateElement("stetic-interface");

            doc.AppendChild(toplevel);

            XmlElement config = doc.CreateElement("configuration");

            if (!string.IsNullOrEmpty(imagesRootPath))
            {
                XmlElement iroot = doc.CreateElement("images-root-path");
                iroot.InnerText = imagesRootPath;
                config.AppendChild(iroot);
            }
            if (!string.IsNullOrEmpty(targetGtkVersion))
            {
                XmlElement iroot = doc.CreateElement("target-gtk-version");
                iroot.InnerText = targetGtkVersion;
                config.AppendChild(iroot);
            }

            if (config.ChildNodes.Count > 0)
            {
                toplevel.AppendChild(config);
            }

            if (widgetLibraries.Count > 0 || (resolver != null && resolver.Directories.Count > 0))
            {
                XmlElement importElem = doc.CreateElement("import");
                toplevel.AppendChild(importElem);
                string basePath = Path.GetDirectoryName(fileName);

                if (resolver != null && resolver.Directories.Count > 0)
                {
                    foreach (string dir in resolver.Directories)
                    {
                        XmlElement dirElem = doc.CreateElement("assembly-directory");
                        if (basePath != null)
                        {
                            dirElem.SetAttribute("path", AbsoluteToRelativePath(basePath, dir));
                        }
                        else
                        {
                            dirElem.SetAttribute("path", dir);
                        }
                        toplevel.AppendChild(dirElem);
                    }
                }

                foreach (string wlib in widgetLibraries)
                {
                    string     libName = wlib;
                    XmlElement libElem = doc.CreateElement("widget-library");
                    if (wlib.EndsWith(".dll") || wlib.EndsWith(".exe"))
                    {
                        if (basePath != null)
                        {
                            libName = AbsoluteToRelativePath(basePath, wlib);
                        }
                    }

                    libElem.SetAttribute("name", libName);
                    if (IsInternalLibrary(wlib))
                    {
                        libElem.SetAttribute("internal", "true");
                    }
                    importElem.AppendChild(libElem);
                }
            }

            ObjectWriter writer = new ObjectWriter(doc, FileFormat.Native);

            writer.CreateUndoInfo = includeUndoInfo;
            if (ownedGlobalActionGroups)
            {
                foreach (Wrapper.ActionGroup agroup in actionGroups)
                {
                    XmlElement elem = agroup.Write(writer);
                    toplevel.AppendChild(elem);
                }
            }

            if (iconFactory.Icons.Count > 0)
            {
                toplevel.AppendChild(iconFactory.Write(doc));
            }

            foreach (WidgetData data in topLevels)
            {
                if (data.Widget != null)
                {
                    Stetic.Wrapper.Container wrapper = Stetic.Wrapper.Container.Lookup(data.Widget);
                    if (wrapper == null)
                    {
                        continue;
                    }

                    XmlElement elem = wrapper.Write(writer);
                    if (elem != null)
                    {
                        toplevel.AppendChild(elem);
                    }
                }
                else
                {
                    toplevel.AppendChild(doc.ImportNode(data.XmlData, true));
                }
            }

            // Remove undo annotations from the xml document
            if (!includeUndoInfo)
            {
                CleanUndoData(doc.DocumentElement);
            }

            return(doc);
        }