public DedicationManager()
        {
            // Get the embedded resource stream.
            Type type = GetType();
            Assembly assembly = type.Assembly;
            Stream stream = assembly.GetManifestResourceStream(type, "Dedication.xml");

            if (stream == null)
            {
                throw new InvalidOperationException(
                    "Cannot load Dedication.xml from the assembly to load dedications.");
            }

            // Load the XML from the given stream.
            using (XmlReader reader = XmlReader.Create(stream))
            {
                // Loop through the reader.
                Dedications = new List<Dedication>();
                Dedication dedication = null;

                while (reader.Read())
                {
                    // If we have a "dedication", we are either starting or
                    // finishing one.
                    if (reader.LocalName == "dedication")
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            dedication = new Dedication();
                        }
                        else
                        {
                            Dedications.Add(dedication);
                            dedication = null;
                        }
                    }

                    if (reader.NodeType != XmlNodeType.Element
                        || dedication == null)
                    {
                        continue;
                    }

                    // For the remaining tags, we just need to pull out the text.
                    switch (reader.LocalName)
                    {
                        case "author":
                            string author = reader.ReadString();
                            dedication.Author = author;
                            break;

                        case "version":
                            string version = reader.ReadString();
                            var assemblyVersion = new ExtendedVersion(version);
                            dedication.Version = assemblyVersion;
                            break;

                        case "dedicator":
                            string dedicator = reader.ReadString();
                            dedication.Dedicator = dedicator;
                            break;

                        case "p":
                            string p = reader.ReadOuterXml();
                            dedication.Html += p;
                            break;
                    }
                }

                // Finish up the stream.
                reader.Close();
            }
        }
Esempio n. 2
0
        public DedicationManager()
        {
            // Get the embedded resource stream.
            Type     type     = GetType();
            Assembly assembly = type.Assembly;
            Stream   stream   = assembly.GetManifestResourceStream(type, "Dedication.xml");

            if (stream == null)
            {
                throw new InvalidOperationException(
                          "Cannot load Dedication.xml from the assembly to load dedications.");
            }

            // Load the XML from the given stream.
            using (XmlReader reader = XmlReader.Create(stream))
            {
                // Loop through the reader.
                Dedications = new List <Dedication>();
                Dedication dedication = null;

                while (reader.Read())
                {
                    // If we have a "dedication", we are either starting or
                    // finishing one.
                    if (reader.LocalName == "dedication")
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            dedication = new Dedication();
                        }
                        else
                        {
                            Dedications.Add(dedication);
                            dedication = null;
                        }
                    }

                    if (reader.NodeType != XmlNodeType.Element ||
                        dedication == null)
                    {
                        continue;
                    }

                    // For the remaining tags, we just need to pull out the text.
                    switch (reader.LocalName)
                    {
                    case "author":
                        string author = reader.ReadString();
                        dedication.Author = author;
                        break;

                    case "version":
                        string version         = reader.ReadString();
                        var    assemblyVersion = new ExtendedVersion(version);
                        dedication.Version = assemblyVersion;
                        break;

                    case "dedicator":
                        string dedicator = reader.ReadString();
                        dedication.Dedicator = dedicator;
                        break;

                    case "p":
                        string p = reader.ReadOuterXml();
                        dedication.Html += p;
                        break;
                    }
                }

                // Finish up the stream.
                reader.Close();
            }
        }
        private void CreateGui(
			string programName,
			Dedication dedication)
        {
            // Create the title and version labels.
            var programLabel = new Label
            {
                Markup = "<b><span size='100'>" + programName + "</span></b>"
            };
            var versionLabel = new Label
            {
                Markup = "<b><span size='80'>" + dedication.Version + "</span></b>"
            };
            var authorLabel = new Label
            {
                Markup = "<b><span size='80'>" + dedication.Author + "</span></b>"
            };

            // Set up the dedication text.
            string html = string.Join("\n", dedication.Lines);
            string text = html + "- " + dedication.Dedicator;

            // Create an HTML display widget with the text.
            var dedicationView = new TextView
            {
                Buffer =
                {
                    Text = text
                },
                WrapMode = WrapMode.Word,
                PixelsBelowLines = 10,
                RightMargin = 8,
                LeftMargin = 4,
                Justification = Justification.Fill,
                Sensitive = false,
            };

            var dedicatorTag = new TextTag("dedicator");
            dedicatorTag.Style = Pango.Style.Italic;
            dedicatorTag.Justification = Justification.Right;
            dedicationView.Buffer.TagTable.Add(dedicatorTag);

            TextIter dedicatorIterBegin =
                dedicationView.Buffer.GetIterAtOffset(html.Length);
            TextIter dedicatorIterEnd = dedicationView.Buffer.GetIterAtOffset(
                text.Length);
            dedicationView.Buffer.ApplyTag(
                dedicatorTag, dedicatorIterBegin, dedicatorIterEnd);

            // Wrap it in a scroll window with some additional spacing.
            var dedicationScroll = new ScrolledWindow
            {
                BorderWidth = 4
            };
            dedicationScroll.Add(dedicationView);

            // Create the notebook we'll be using for the larger text tabs.
            var notebook = new Notebook();
            notebook.SetSizeRequest(512, 256);
            notebook.BorderWidth = 4;

            notebook.AppendPage(dedicationScroll, new Label("Dedication"));

            // Arrange everything in the vertical box.
            VBox.PackStart(programLabel, false, false, 4);
            VBox.PackStart(versionLabel, false, false, 4);
            VBox.PackStart(authorLabel, false, false, 4);
            VBox.PackStart(notebook, true, true, 4);

            // Set up the buttons.
            Modal = true;

            AddButton("Close", ResponseType.Close);
        }