How can I perform text formatting with a ReadOnly document?

SyntaxEditor for WPF Forum

Posted 10 years ago by Craig - Varigence, Inc.
Version: 11.1.0545
Avatar
I have a syntax editor where I want to format the displayed text but not have it be user-editable. When I try use the ITextFormatter service to format the document's text, nothing happens when the document's IsReadOnly property is set to true. Is there a way I can perform formats but prevent users from editing the text?

Thanks,

-Craig

Comments (3)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

I would think that formatting should work as long as your formatting code's text change isn't doing a read-only check.

If you think there is a problem, please e-mail us a new simple sample project that shows the issue so we can debug. Thanks!


Actipro Software Support

Posted 10 years ago by Craig - Varigence, Inc.
Avatar
You can repro this using the HTML Editor (Web Lang Add-On) sample in the Actipro Sample Browser. In the sample's MainControl.xaml file, set the SyntaxEditor's EditorDocument's IsReadOnly property to true:

<docking:Workspace>
    <editor:SyntaxEditor 
            x:Name="syntaxEditor" 
            DocumentParseDataChanged="OnSyntaxEditorDocumentParseDataChanged" 
            UserInterfaceUpdate="OnSyntaxEditorUserInterfaceUpdate"
            ViewSearch="OnEditorViewSearch"
            ViewSelectionChanged="OnSyntaxEditorViewSelectionChanged"
            >
            <editor:EditorDocument xml:space="preserve" IsReadOnly="true">
When you run the sample and press the Format Document button, you'll see that the text isn't formatted.

-Craig
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Thanks for the repro steps. It happens there because our XmlTextFormatter does have the read-only check in its options:
var options = new TextChangeOptions() {
    RetainSelection = true,
    CheckReadOnly = true,
    OffsetDelta = TextChangeOffsetDelta.SequentialOnly
};
For the next version, we're going to disable the format commands when they will perform on a read-only document (for toolbar buttons). With that update and with the current code, if you are using our XML formatter, you'd probably have to set the document read-only state to false, then call the format programmatically and directly via the service, and set read-only back to true.


Actipro Software Support

The latest build of this product (v21.1.2) was released 20 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.