Esempio n. 1
0
        /// <summary>
        /// Gets a rich text box that show the syntax highlighted source code of the example.
        /// </summary>
        /// <returns></returns>
        protected virtual NWidget GetExampleSource()
        {
            NRichTextView richText = new NRichTextView();

            richText.HRuler.Visibility = ENVisibility.Collapsed;
            richText.VRuler.Visibility = ENVisibility.Collapsed;
            richText.ReadOnly          = true;

            try
            {
                // Decompress the source code of the example
                Type exampleType = Schema.DomType.Type;
                NSourceCodeDecompressor decompressor = new NSourceCodeDecompressor(exampleType);
                SourceCodeStream.Position = 0;
                NCompression.DecompressZip(SourceCodeStream, decompressor);

                // Highlight the decompressed source code
                NSyntaxHighlighter syntaxHighlighter = new NSyntaxHighlighter();

                MemoryStream decompressedStream = decompressor.GetSourceCodeStream();
                if (decompressedStream != null)
                {
                    Stream htmlStream = syntaxHighlighter.Highlight(decompressedStream);

                    // Load the colorized source code in the source code rich text view
                    richText.LoadFromStream(htmlStream, new NHtmlTextFormat());
                }
            }
            catch (Exception ex)
            {
                NTrace.WriteException("Failed to get example source.", ex);
            }

            return(richText);
        }
Esempio n. 2
0
        private void MergeAndSaveToFolder(string targetPath)
        {
            if (NDirectory.Exists(targetPath) == false)
            {
                NMessageBox.Show("The entered target path does not exist", "Error",
                                 ENMessageBoxButtons.OK, ENMessageBoxIcon.Error);
                return;
            }

            // Clone the rich text view
            NRichTextView clonedRichTextView = (NRichTextView)m_RichText.DeepClone();

            // Switch the mail merge of the cloned rich text view to preview mode
            NMailMerge mailMerge = clonedRichTextView.Content.MailMerge;

            mailMerge.PreviewMailMerge = true;

            // Loop through all mail merge records to save individual documents to file
            for (int i = 0; i < mailMerge.DataRecordCount; i++)
            {
                // Move to the next data source record
                mailMerge.CurrentDataRecordIndex = i;

                // Save the merged document to file
                string fileName = "Document" + i.ToString(CultureInfo.InvariantCulture) + ".docx";
                clonedRichTextView.SaveToFile(NPath.Combine(targetPath, fileName));
            }

            NMessageBox.Show("Merged documents saved to \"" + targetPath + "\".", "Mail Merge Complete",
                             ENMessageBoxButtons.OK, ENMessageBoxIcon.Information);
        }
Esempio n. 3
0
        protected override NWidget CreateExampleContent()
        {
            // Create the rich text
            m_RichText            = new NRichTextView();
            m_RichText.AcceptsTab = true;
            m_RichText.Content.Sections.Clear();

            NSection section = new NSection();

            section.Blocks.Add(new NParagraph("Type some content here"));
            m_RichText.Content.Sections.Add(section);

            m_RichText.Content.Layout    = ENTextLayout.Web;
            m_RichText.VScrollMode       = ENScrollMode.Never;
            m_RichText.HScrollMode       = ENScrollMode.Never;
            m_RichText.HRuler.Visibility = ENVisibility.Hidden;
            m_RichText.VRuler.Visibility = ENVisibility.Hidden;
            m_RichText.PreferredWidth    = double.NaN;
            m_RichText.PreferredHeight   = double.NaN;
            m_RichText.Border            = NBorder.CreateFilledBorder(NColor.Black);
            m_RichText.BorderThickness   = new NMargins(1);

            m_RichText.HorizontalPlacement = Layout.ENHorizontalPlacement.Fit;
            m_RichText.VerticalPlacement   = Layout.ENVerticalPlacement.Top;

            return(m_RichText);
        }
Esempio n. 4
0
        protected override NWidget CreateExampleContent()
        {
            NSplitter splitter = new NSplitter();

            splitter.SplitMode   = ENSplitterSplitMode.Proportional;
            splitter.SplitFactor = 0.5;

            // Create the "HTML Code" group box
            m_HtmlTextBox = new NTextBox();
            m_HtmlTextBox.AcceptsEnter = true;
            m_HtmlTextBox.AcceptsTab   = true;
            m_HtmlTextBox.Multiline    = true;
            m_HtmlTextBox.WordWrap     = false;
            m_HtmlTextBox.VScrollMode  = ENScrollMode.WhenNeeded;
            m_HtmlTextBox.HScrollMode  = ENScrollMode.WhenNeeded;

            NButton importButton = new NButton("Import");

            importButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center;
            importButton.Click += new Function <NEventArgs>(OnImportButtonClick);

            NPairBox pairBox = CreatePairBox(m_HtmlTextBox, importButton);

            splitter.Pane1.Content = new NGroupBox("HTML Code", pairBox);

            // Create the "Preview" group box
            m_PreviewRichText                 = new NRichTextView();
            m_PreviewRichText.ReadOnly        = true;
            m_PreviewRichText.DocumentLoaded += OnRichTextDocumentLoaded;
            splitter.Pane2.Content            = new NGroupBox("Preview", m_PreviewRichText);

            return(splitter);
        }
Esempio n. 5
0
        protected override NWidget CreateExampleContent()
        {
            // Create the rich text
            m_RichText            = new NRichTextView();
            m_RichText.AcceptsTab = true;
            m_RichText.Content.Sections.Clear();

            // Create the ribbon
            m_RibbonBuilder = new NRichTextRibbonBuilder();
            return(m_RibbonBuilder.CreateUI(m_RichText));
        }
Esempio n. 6
0
        private NWidget CreateRTFDemo()
        {
            NStackPanel stack = new NStackPanel();

            stack.FillMode = ENStackFillMode.Last;
            stack.FitMode  = ENStackFitMode.Last;

            NButton setButton = new NButton("Set Clipboard RTF");

            setButton.Click += new Function <NEventArgs>(OnSetRTFButtonClick);

            NButton getButton = new NButton("Get Clipboard RTF");

            getButton.Click += new Function <NEventArgs>(OnGetRTFButtonClick);

            NPairBox pairBox = new NPairBox(setButton, getButton);

            pairBox.HorizontalPlacement = ENHorizontalPlacement.Left;
            pairBox.Spacing             = NDesign.HorizontalSpacing;
            stack.Add(pairBox);

            // Create a rich text view and some content
            m_RichText = new NRichTextView();
            m_RichText.PreferredSize = new NSize(400, 300);

            NSection section = new NSection();

            m_RichText.Content.Sections.Add(section);

            NTable table = new NTable(2, 2);

            table.AllowSpacingBetweenCells = false;

            section.Blocks.Add(table);
            for (int i = 0; i < 4; i++)
            {
                NTableCell cell = table.Rows[i / 2].Cells[i % 2];
                cell.Border          = NBorder.CreateFilledBorder(NColor.Black);
                cell.BorderThickness = new NMargins(1);
                NParagraph paragraph = (NParagraph)cell.Blocks[0];
                paragraph.Inlines.Add(new NTextInline("Cell " + (i + 1).ToString(CultureInfo.InvariantCulture)));
            }

            stack.Add(m_RichText);
            return(stack);
        }
Esempio n. 7
0
        protected override NWidget CreateExampleContent()
        {
            NStackPanel stack = new NStackPanel();

            stack.FillMode        = ENStackFillMode.Last;
            stack.FitMode         = ENStackFitMode.Last;
            stack.VerticalSpacing = 10;

            m_RichTextView = new NRichTextView();
            m_RichTextView.Content.Sections.Clear();

            NSection section = new NSection();

            m_RichTextView.Content.Sections.Add(section);
            stack.Add(m_RichTextView);

            section.Blocks.Add(new NParagraph(Text1));
            section.Blocks.Add(new NParagraph(Text2));

            return(stack);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates the example description.
        /// </summary>
        /// <returns></returns>
        protected virtual NWidget CreateExampleDescription()
        {
            NRichTextView richTextView = new NRichTextView();

            richTextView.Padding = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

            richTextView.HRuler.Visibility = ENVisibility.Collapsed;
            richTextView.VRuler.Visibility = ENVisibility.Collapsed;
            richTextView.ReadOnly          = true;

            byte[] descriptionData = NEncoding.UTF8.GetBytes(GetExampleDescription());
            using (MemoryStream stream = new MemoryStream(descriptionData))
            {
                richTextView.LoadFromStream(stream, new NHtmlTextFormat());
            }

            richTextView.Content.Padding = new NMargins(NDesign.HorizontalSpacing * 2, NDesign.VerticalSpacing);

            NGroupBox groupBox = new NGroupBox("Description");

            groupBox.Content = richTextView;
            return(groupBox);
        }