This is a migrated thread and some comments may be shown as answers.

Empty PermissonRange gets uneditable

8 Answers 114 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Christoph
Top achievements
Rank 1
Christoph asked on 29 Feb 2012, 12:31 PM
Hi

I have a document with lots of pairs of "readonlyrange-followed-by-permissonrange".
The readonlyranges(->ROR) are Titles, the permissonranges (->PR)
are the place where the users enter their input related to the title.

The XAML source code looks like:

<t:Paragraph>
      <t:BookmarkRangeStart AnnotationID="1" Name="SingleResult_TITLE" />
      <t:ReadOnlyRangeStart AnnotationID="2" />
      <t:Span Text="TITLE" />
      <t:ReadOnlyRangeEnd AnnotationID="2" />
      <t:BookmarkRangeEnd AnnotationID="1" />
      <t:BookmarkRangeStart AnnotationID="3" Name="SingleResult_TEXT" />
      <t:PermissionRangeStart AnnotationID="4">
        <t:PermissionRangeInfo Name="jmiller" Type="Individual" />
      </t:PermissionRangeStart>
      <t:Span Text="¬hello}" />
      <t:PermissionRangeEnd AnnotationID="4" />
      <t:BookmarkRangeEnd AnnotationID="3" />
    </t:Paragraph>

The current user of the richtextbox is "jmiller" so the PR is editable.

Now there is a little issue with deleting all text from the span / PR via the keyboard.
When all text is gone and the cursor is at the end of the ROR -
with text "TITLE" - one cannot enter new text into the PR again, although the
PR is still there (as proved by saving it as XAML).
I think that's because the Cursor position is considered as belonging to the
ROR, so it is not editable.
And since the PR is empty, I can't position the cursor to the start of the PR
with the mouse.

Is there a way / trick how i must arrange ROR and PR so that i can remove all contents
from the PR but have it still accepting new input?
Can I position the cursor programmatically into the empty PR
when it is at the end of the ROR (by some event handler)
or can I control, whether the end-of-ROR position is regarded as
inside or outside the ROR?

Thanks in advance
Greetings, Chris

8 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 05 Mar 2012, 03:25 PM
Hello Chris,

The behavior of the permission ranges is similar to that of comments - once you delete the content between the range start and end, it is not possible to add text between these ranges.
We will consider changing the behavior of the permission ranges. The only way to achieve the behavior you have described would be to use custom annotation ranges, similar to the PermissionRanges. Here is how they can be implemented:

[ContentProperty("Info")]
public class CustomPermissionRangeStart : AnnotationRangeStart
{
    [XamlSerializable]
    public PermissionRangeInfo Info { get; set; }
 
    public override bool SkipPositionBefore
    {
        get { return true; }
    }
 
    protected override void CopyPropertiesFromOverride(DocumentElement fromElement)
    {
        base.CopyPropertiesFromOverride(fromElement);
 
        CustomPermissionRangeStart fromPermissionRangeStart = (CustomPermissionRangeStart)fromElement;
        if (fromPermissionRangeStart.Info != null)
        {
            this.Info = fromPermissionRangeStart.Info.CreateDeepCopy();
        }
    }
 
    protected override DocumentElement CreateNewElementInstance()
    {
        return new CustomPermissionRangeStart();
    }
 
    protected override void CopyContentFromOverride(DocumentElement fromElement)
    {
    }
}

and the CustomPermissionRangeEnd:
public class CustomPermissionRangeEnd : AnnotationRangeEnd
{
    protected override AnnotationRangeStart CreateRangeStartInstance()
    {
        return new CustomPermissionRangeStart();
    }
 
    public override bool SkipPositionBefore
    {
        get { return false; }
    }
 
    protected override DocumentElement CreateNewElementInstance()
    {
        return new CustomPermissionRangeEnd();
    }
 
    protected override void CopyContentFromOverride(DocumentElement fromElement)
    {
    }
}

The use of custom annotations with UILayer is demonstrated in the StructuredContentEditing demo for the Silverlight version of RadRichTextBox. For more information on the approach, please refer to this forum post.

Greetings,
Iva Toteva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Christoph
Top achievements
Rank 1
answered on 06 Mar 2012, 11:05 AM
Hello Iva

Thanks for your reply and the pointer to the custom PermissonRange.

I did a quick test replacing the Telerik PermissonRangeStart/End
tags/instances in my test document with the new Custom implementation.

With the custom implementaion, the mechansim of
protecting and unprotecting the PermissonRange
by changing the CurrentUser (letting the CurrentUser name and the name of the range
equal) doesn't seem to function anymore :-(
The custom permisson range remains readonly - even if both names resolve to 'jmiller'
and protection type is 'Individual'.

I tried to derive the custom AnnotationMarkers from PermissionRangeStart and PermissionRangeEnd instead
but this doesn't seem to do the trick either (document got invalid and was rendered/displayed as empty).

On the other hand I've seen the StructedEditing demo and where it works.
So I'll go and find out the details that make it function.

Greetings,
Chris
0
Charles
Top achievements
Rank 1
answered on 07 Mar 2012, 12:24 PM
Hi Iva

I've also got the same issue, and I like the solution you've proposed as it also allows me to add other metadata to the range as well as solving the original problem.

However, I have the same issue as Christoph - when the document is protected, you cannot edit the custom range.  It would appear the "ContentProperty" attribute is being ignored, or we're missing something in the implementation.

I've checked the Structured Content Editing demo that Christoph refers to, and the implementation here is different - each custom range is wrapped in a PermissionRange.
<t:PermissionRangeStart AnnotationID="11">
<t:PermissionRangeInfo Type="Everyone" />
</t:PermissionRangeStart>
<custom1:RecipeRangeStart AnnotationID="12" Name="yield" />
<t:Span Text="Good apptizer for 2 adults for dinner." />
<custom1:RecipeRangeEnd AnnotationID="12" />
<t:PermissionRangeEnd AnnotationID="11" />
This cures the sympton, as your cursor is in the inner custom range, so you can add text (I assume the difference in behaviour is due to the "SkipPositionBefore" and "SkipPositionAfter" properties? I can't find any documentation on this, though!).

If there's a simple solution to make the example posted work with content protection, please let us know!

Thanks

Charlie

EDIT: Just tried inheriting from PermissionRangeStart and PermissionRangeEnd, as Christoph described.  It does, however, appear to work for me...
0
Christoph
Top achievements
Rank 1
answered on 09 Mar 2012, 11:11 AM
Hi Iva and Charles

I found a solution now, that works for me.
I derived from ProtectionRangeStart and ~End, adding a Name property.
As for the range becoming uneditable-issue (which is somewhat unpredictable:
sometimes the empty range remains editable, sometimes it seems locked)
 - I decided to watch the DocumentElementRemoved event.
In the handler I take care that between the Start/End tags of interest
there always is a span.
If there is none, I insert one with a blank space as text.
Kind of a workaround that works for me.

As for the proposed solution with the dual AnnotaionsMarkers.
I tried this one as well, it is also the way it is implemented
in the StructuredEditingDemo, but I didn't get it to work
(Protection toggling worked, but having the empty range
still editable didn't, probably missed something).

In general I agree with Charles that having a documentation
espcially on the overridable Members of AnnotationMarkerBase
would be good.

Thanks all of you for your support
and help,
Chris



0
Charles
Top achievements
Rank 1
answered on 09 Mar 2012, 12:23 PM
Hi Chris

Providing you override the "SkipsPositionBefore" as Iva described in the exampl, it appears to solve the issue for me.
0
Ivailo Karamanolev
Telerik team
answered on 09 Mar 2012, 02:53 PM
Hello,

I'm glad you have successfully resolved your issues. If any of them remain or you experience new ones, do not hesitate to contact us again.

Greetings,
Ivailo Karamanolev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Robert
Top achievements
Rank 1
answered on 23 May 2012, 09:12 PM
I also have the same issue with the protection range when all content is deleted. I don't see why it has been made so that you cannot insert content into the protection range after the original content has been deleted.

I will have to make a work around for this. It would be nice if a fix were to be implemented into the API.

Thanks.
0
Robert
Top achievements
Rank 1
answered on 25 May 2012, 06:41 PM
Please vote for this feature in the PITs.

Enable deletion using backspace when at the end of a protected region:
http://www.telerik.com/support/pits.aspx#/public/silverlight/11214

Tags
RichTextBox
Asked by
Christoph
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Christoph
Top achievements
Rank 1
Charles
Top achievements
Rank 1
Charles
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Robert
Top achievements
Rank 1
Share this question
or