public void Initialize(IRichEditControl richEditControl, string codeExamplesFileExtension)
        {
            InnerRichEditControl innerControl = richEditControl.InnerControl;

            IRichEditCommandFactoryService commandFactory = innerControl.GetService <IRichEditCommandFactoryService>();

            if (commandFactory == null)
            {
                return; // wpf richedit is not loaded
            }
            innerControl.ReplaceService <ISyntaxHighlightService>(new SyntaxHighlightService(innerControl, codeExamplesFileExtension));

            CustomRichEditCommandFactoryService newCommandFactory = new CustomRichEditCommandFactoryService(commandFactory);

            innerControl.RemoveService(typeof(IRichEditCommandFactoryService));
            innerControl.AddService(typeof(IRichEditCommandFactoryService), newCommandFactory);

            IDocumentImportManagerService importManager = innerControl.GetService <IDocumentImportManagerService>();

            importManager.UnregisterAllImporters();
            importManager.RegisterImporter(new PlainTextDocumentImporter());
            importManager.RegisterImporter(new SourcesCodeDocumentImporter());

            IDocumentExportManagerService exportManager = innerControl.GetService <IDocumentExportManagerService>();

            exportManager.UnregisterAllExporters();
            exportManager.RegisterExporter(new PlainTextDocumentExporter());
            exportManager.RegisterExporter(new SourcesCodeDocumentExporter());

            Document document = innerControl.Document;

            document.BeginUpdate();
            try
            {
                document.DefaultCharacterProperties.FontName = "Consolas";
                document.DefaultCharacterProperties.FontSize = 10;
                document.Sections[0].Page.Width                = Units.InchesToDocumentsF(100);
                document.Sections[0].LineNumbering.CountBy     = 1;
                document.Sections[0].LineNumbering.RestartType = LineNumberingRestart.Continuous;

                //SizeF tabSize = innerControl.MeasureSingleLineString("    ", document.DefaultCharacterProperties);
                //TabInfoCollection tabs = document.Paragraphs[0].BeginUpdateTabs(true);
                //try {
                //    for (int i = 1; i <= 30; i++) {
                //        DevExpress.XtraRichEdit.API.Native.TabInfo tab = new DevExpress.XtraRichEdit.API.Native.TabInfo();
                //        tab.Position = i * tabSize.Width;
                //        tabs.Add(tab);
                //    }
                //}
                //finally {
                //    document.Paragraphs[0].EndUpdateTabs(tabs);
                //}
            }
            finally
            {
                document.EndUpdate();
            }
        }
Exemple #2
0
        public void Initialize(IRichEditControl richEditControl, string codeExamplesFileExtension)
        {
            InnerRichEditControl innerControl = richEditControl.InnerControl;

            IRichEditCommandFactoryService commandFactory = innerControl.GetService <IRichEditCommandFactoryService>();

            if (commandFactory == null)
            {
                return;
            }

            innerControl.ReplaceService <ISyntaxHighlightService>(new SyntaxHighlightService(innerControl, codeExamplesFileExtension));

            CustomRichEditCommandFactoryService newCommandFactory = new CustomRichEditCommandFactoryService(commandFactory);

            innerControl.RemoveService(typeof(IRichEditCommandFactoryService));
            innerControl.AddService(typeof(IRichEditCommandFactoryService), newCommandFactory);

            IDocumentImportManagerService importManager = innerControl.GetService <IDocumentImportManagerService>();

            importManager.UnregisterAllImporters();
            importManager.RegisterImporter(new PlainTextDocumentImporter());
            importManager.RegisterImporter(new SourcesCodeDocumentImporter());

            IDocumentExportManagerService exportManager = innerControl.GetService <IDocumentExportManagerService>();

            exportManager.UnregisterAllExporters();
            exportManager.RegisterExporter(new PlainTextDocumentExporter());
            exportManager.RegisterExporter(new SourcesCodeDocumentExporter());

            Document document = innerControl.Document;

            document.BeginUpdate();
            try
            {
                document.DefaultCharacterProperties.FontName = "Consolas";
                document.DefaultCharacterProperties.FontSize = 10;
                document.Sections[0].Page.Width                = Units.InchesToDocumentsF(100);
                document.Sections[0].LineNumbering.CountBy     = 1;
                document.Sections[0].LineNumbering.RestartType = LineNumberingRestart.Continuous;
            }
            finally
            {
                document.EndUpdate();
            }
        }