Ejemplo n.º 1
0
        public bool LoadDocument()
        {
            bool ret = false;

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Text Files (*.txt)|*.TXT";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Host.SetFileDetails(dialog.FileName);

                Gutenberg.TextFormatter formatter = new Gutenberg.TextFormatter();

                FileStream stream = File.OpenRead(dialog.FileName);
                try
                {
                    Gutenberg.Document doc = formatter.ProcessTextBook(stream);

                    Host.SetDocument(doc.SerializeToHtml());
                    ret = true;
                }
                finally
                {
                    stream.Close();
                }
            }

            return(ret);
        }
Ejemplo n.º 2
0
        private void ImportFromClipboardMenuItem_Click(object sender, EventArgs e)
        {
            if (Clipboard.ContainsText(TextDataFormat.Text))
            {
                MemoryStream stream = new MemoryStream();
                BinaryWriter writer = new BinaryWriter(stream);
                writer.Write(Clipboard.GetText(TextDataFormat.Text));
                writer.Flush();

                stream.Position = 0;
                Gutenberg.TextFormatter formatter = new Gutenberg.TextFormatter();

                Gutenberg.Document doc = formatter.ProcessTextBook(stream);
                m_HtmlEditor.DocumentText = doc.SerializeToHtml();
            }
            else if (Clipboard.ContainsText(TextDataFormat.Html))
            {
                m_HtmlEditor.DocumentText = Clipboard.GetText(TextDataFormat.Html);
            }
            else
            {
                Debug.WriteLine("Unknown clipboard data format");
            }
        }