Search Results for

    Show / Hide Table of Contents

    Customize

    It's possible to embed the editor on an existing page or add an action to open the editor in a separate page.

    Editor Action

    The easiest way to implement the editor is to open it by an action.

    Here is an example of adding the actions:

    action(ActionRichTextEditor)
    {
        ApplicationArea = CCSTMRTE;
        Caption = 'Rich Text Editor';
        Image = DocumentEdit;
        Promoted = true;
        PromotedCategory = Process;
        PromotedOnly = true;
        ToolTip = 'Open the rich text editor for the selected line.';
    
        trigger OnAction()
        begin
            OpenRichTextEditor(false);
            CurrPage.Update(false);
        end;
    }
    action(ActionRichTextEditorLineConversion)
    {
        ApplicationArea = CCSTMRTE;
        Caption = 'Rich Text Editor (Line Conversion)';
        Image = DocumentEdit;
        Promoted = true;
        PromotedCategory = Process;
        PromotedOnly = true;
        ToolTip = 'Open the rich text editor for the selected line and convert the text into plain text document lines, afterwards.';
        Visible = PageEditable;
    
        trigger OnAction()
        begin
            OpenRichTextEditor(true);
            CurrPage.Update(false);
        end;
    }
    

    Here is an example of calling the editor on action:

    local procedure OpenRichTextEditor(LineConversion: Boolean)
    var
        TempRichTextLine: Record "CCS TM Line Document" temporary;
    begin
        TempRichTextLine.Copy(Rec, true);
        OpenRichTextEditor(TempRichTextLine, LineConversion, CurrPage.Editable);
    end;
    
    procedure OpenRichTextEditor(RichTextLine: Record "CCS TM Line"; LineConversion: Boolean): Boolean
    var
        RichTextEditor: Page "CCS TM Rich Text Editor";
    begin
        RichTextEditor.SetContent(GetRichText(RichTextLine, RichTextLine.FieldNo("Rich Text")));
        RichTextEditor.SetRequestPageId(Page::"CCS TM Subform");
        RichTextEditor.SetEditable(true);
        if RichTextEditor.RunModal() = Action::OK then begin
            SetRichText(RichTextLine, RichTextEditor.GetContent());
            SetLineText(RichTextLine, RichTextEditor.GetText());
            RichTextLine.Modify();
            DeleteChildLines(RichTextLine);
            if LineConversion then
                ConvertLines(RichTextLine, RichTextEditor.GetText());
            exit(true);
        end;
    end;
    

    The line conversion will not be handled in detail. Check codeunit 5060608 "CCS TM Rich Text Management" for details.

    Embedded Editor

    The CCS TM Rich Text Editor user control defines the rich text editor. To embed the editor on an existing page, the user control must be added, and saving and loading the content must be handled.

    Here is an example of adding the user control:

    group("CCS TM Rich Text Editor Group")
    {
        Caption = 'Rich Text Editor';
    
        usercontrol("CCS TM Rich Text Editor"; "CCS TM Rich Text Editor")
        {
            ApplicationArea = CCSTMRTE;
    
            trigger OnControlAddInReady()
            var
                Management: Codeunit "CCS TM Rich Text Management";
            begin
                CurrPage."CCS TM Rich Text Editor".InitializeEditor(Management.GetEditorToolbarString(Page::"Extended Text"));
            end;
    
            trigger OnEditorInitialized()
            begin
                EditorInitialized := true;
                LoadContentToEditor();
            end;
    
            trigger OnEditorChange(Content: Text; Text: Text)
            begin
                SaveContentFromEditor(Content);
            end;
        }
    }
    

    Here is an example of handling the saving and loading of content:

    trigger OnAfterGetCurrRecord()
    begin
        LoadContentToEditor();
    end;
    
    local procedure UpdateControls()
    begin
        if EditorInitialized then
            CurrPage."CCS TM Rich Text Editor".SetReadOnly(not Editable);
    end;
    
    local procedure LoadContentToEditor()
    var
        Content: Text;
        InStr: InStream;
    begin
        if not EditorInitialized then
            exit;
    
        Rec.CalcFields("CCS TM Rich Text");
        Rec."CCS TM Rich Text".CreateInStream(InStr);
        InStr.Read(Content);
        CurrPage."CCS TM Rich Text Editor".SetContent(Content);
    end;
    
    local procedure SaveContentFromEditor(Content: Text)
    var
        OutStr: OutStream;
    begin
        if StrLen(Content) > 0 then begin
            Clear(Rec."CCS TM Rich Text");
            Rec."CCS TM Rich Text".CreateOutStream(OutStr);
            OutStr.Write(Content);
        end else
            Clear(Rec."CCS TM Rich Text");
    end;
    

    To convert lines, you can listen to an event of the user control:

    trigger OnConvertToLines(Content: Text; Text: Text)
    begin
        ConvertLines(Text);
    end;
    

    The conversion implementation could look like this:

    local procedure ConvertLines(EditorText: Text)
    var
        Line: Text;
        LineLine: Text;
        Lines: List of [Text];
        LineLines: List of [Text];
        Management: Codeunit "CCS TM Rich Text Management";
        NextLineNo: Integer;
        ExtendedTextLine: Record "Extended Text Line";
    begin
        DeleteChildLines();
        NextLineNo := 1;
        Management.ConvertTextToLines(EditorText, Lines);
        foreach Line in Lines do begin
            Management.SplitTextToLines(Line, MaxStrLen(ExtendedTextLine.Text), LineLines);
            foreach LineLine in LineLines do begin
                CreateLine(NextLineNo, LineLine);
                NextLineNo += 1;
            end;
        end;
    end;
    
    local procedure CreateLine(LineNo: Integer; Value: Text)
    var
        ExtendedTextLine: Record "Extended Text Line";
    begin
        ExtendedTextLine."Table Name" := Rec."Table Name";
        ExtendedTextLine."No." := Rec."No.";
        ExtendedTextLine."Language Code" := Rec."Language Code";
        ExtendedTextLine."Text No." := Rec."Text No.";
        ExtendedTextLine."Line No." := LineNo;
        ExtendedTextLine.Text := Value;
        ExtendedTextLine.Insert();
    end;
    
    local procedure DeleteChildLines()
    var
        ExtendedTextLine: Record "Extended Text Line";
    begin
        ExtendedTextLine.SetRange("Table Name", Rec."Table Name");
        ExtendedTextLine.SetRange("No.", Rec."No.");
        ExtendedTextLine.SetRange("Language Code", Rec."Language Code");
        ExtendedTextLine.SetRange("Text No.", Rec."Text No.");
        if not ExtendedTextLine.IsEmpty then
            ExtendedTextLine.DeleteAll();
    end;
    


    Feedback
    Submit feedback for this page.

    In This Article
    Back to top 2025 © COSMO CONSULT - Data protection - Imprint