Ejemplo n.º 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);

			// FIXME; if you use UTF8, it starts with a BOM???
			XmlTextWriter writer = new XmlTextWriter (filename, System.Text.Encoding.ASCII);
			writer.Formatting = Formatting.Indented;
			doc.Save (writer);
			writer.Close ();
		}
Ejemplo n.º 2
0
		public static XmlDocument Export (Gtk.Widget widget)
		{
			Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup (widget);
			if (wrapper == null)
				return null;

			XmlDocument doc = new XmlDocument ();
			doc.PreserveWhitespace = true;

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

			// For toplevel widgets, glade just saves it as-is. For
			// non-toplevels, it puts the widget into a dummy GtkWindow,
			// but using the packing attributes of the widget's real
			// container (so as to preserve expand/fill settings and the
			// like).

			XmlElement elem;
			Stetic.Wrapper.Container parent = wrapper.ParentWrapper;
			ObjectWriter writer = new ObjectWriter (doc, FileFormat.Glade);

			if (parent == null) {
				elem = wrapper.Write (writer);
				if (elem == null)
					return null;
				if (!(widget is Gtk.Window)) {
					XmlElement window = doc.CreateElement ("widget");
					window.SetAttribute ("class", "GtkWindow");
					window.SetAttribute ("id", "glade-dummy-container");
					XmlElement child = doc.CreateElement ("child");
					window.AppendChild (child);
					child.AppendChild (elem);
					elem = window;
				}
			} else {
				elem = doc.CreateElement ("widget");
				// Set the class correctly (temporarily) so the XSL
				// transforms will work correctly.
				ClassDescriptor klass = parent.ClassDescriptor;
				elem.SetAttribute ("class", klass.CName);
				elem.AppendChild (parent.WriteContainerChild (writer, wrapper));
			}
			toplevel.AppendChild (elem);

			doc = XslExportTransform (doc);

			if (parent != null) {
				elem = (XmlElement)doc.SelectSingleNode ("glade-interface/widget");
				elem.SetAttribute ("class", "GtkWindow");
				elem.SetAttribute ("id", "glade-dummy-container");
			}
			return doc;
		}
Ejemplo n.º 3
0
		public override XmlElement Write (ObjectWriter writer)
		{
			if (writer.Format != this.format) {
				ErrorWidget ew = (ErrorWidget) Wrapped;
				XmlElement elem = writer.XmlDocument.CreateElement ("widget");
				elem.SetAttribute ("class", "Gtk.Label");
				elem.SetAttribute ("id", Wrapped.Name);
				XmlElement ce = writer.XmlDocument.CreateElement ("property");
				string msg;
				if (ew.Exception != null)
					msg = "Invalid widget";
				else
					msg = "Unknown widget: " + ew.ClassName;
				ce.SetAttribute ("name", "LabelProp");
				ce.InnerText = msg;
				elem.AppendChild (ce);
				return elem;
			}
			else
				return (XmlElement) writer.XmlDocument.ImportNode (elementData, true);
		}
Ejemplo n.º 4
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", ToOSAgnosticRelPath (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 = ToOSAgnosticRelPath (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;
		}
Ejemplo n.º 5
0
		public virtual XmlElement Write (ObjectWriter writer)
		{
			throw new System.NotImplementedException ();
		}
Ejemplo n.º 6
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;
		}
Ejemplo n.º 7
0
 public virtual XmlElement Write(ObjectWriter writer)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 8
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", ToOSAgnosticRelPath(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 = ToOSAgnosticRelPath(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);
        }
Ejemplo n.º 9
0
        public static XmlDocument Export(Gtk.Widget widget)
        {
            Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup(widget);
            if (wrapper == null)
            {
                return(null);
            }

            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;

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

            doc.AppendChild(toplevel);

            // For toplevel widgets, glade just saves it as-is. For
            // non-toplevels, it puts the widget into a dummy GtkWindow,
            // but using the packing attributes of the widget's real
            // container (so as to preserve expand/fill settings and the
            // like).

            XmlElement elem;

            Stetic.Wrapper.Container parent = wrapper.ParentWrapper;
            ObjectWriter             writer = new ObjectWriter(doc, FileFormat.Glade);

            if (parent == null)
            {
                elem = wrapper.Write(writer);
                if (elem == null)
                {
                    return(null);
                }
                if (!(widget is Gtk.Window))
                {
                    XmlElement window = doc.CreateElement("widget");
                    window.SetAttribute("class", "GtkWindow");
                    window.SetAttribute("id", "glade-dummy-container");
                    XmlElement child = doc.CreateElement("child");
                    window.AppendChild(child);
                    child.AppendChild(elem);
                    elem = window;
                }
            }
            else
            {
                elem = doc.CreateElement("widget");
                // Set the class correctly (temporarily) so the XSL
                // transforms will work correctly.
                ClassDescriptor klass = parent.ClassDescriptor;
                elem.SetAttribute("class", klass.CName);
                elem.AppendChild(parent.WriteContainerChild(writer, wrapper));
            }
            toplevel.AppendChild(elem);

            doc = XslExportTransform(doc);

            if (parent != null)
            {
                elem = (XmlElement)doc.SelectSingleNode("glade-interface/widget");
                elem.SetAttribute("class", "GtkWindow");
                elem.SetAttribute("id", "glade-dummy-container");
            }
            return(doc);
        }