How to protect paragraph against deletion?

General TRichView support forum. Please post your questions here
Post Reply
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

How to protect paragraph against deletion?

Post by duzenko »

I have several rows with paired text, for example:

Code: Select all

1
one
2
two
I must allow user to delete e.g. text "one" but not to delete paragraph, so that an empty paragraph should remain. How to do that?

Current protection that I use

Code: Select all

  FNativeParaStyleId := Style.ParaStyles.Count;
  Style.ParaStyles.Add.Background.Color := clInactiveCaptionText;
  FNativeTextStyleId := Style.TextStyles.Count;
  Style.TextStyles.Add.Protection := [rvprDeleteProtect, rvprModifyProtect, rvprConcateProtect];
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

rvprModifyProtect does not allow editing text, so probably you should remove it.
rvprDeleteProtect does not allow deleting item (at least one character must remain), so this is probably what you need.
Also consider using rvprParaStartProtect.
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

You did not understand.

Current code is

Code: Select all

  FNativeTextStyleId := Style.TextStyles.Count;
  Style.TextStyles.Add.Protection := [rvprDeleteProtect, rvprModifyProtect];
  FTranslationTextStyleId := Style.TextStyles.Count;
  Style.TextStyles.Add.Protection := [rvprParaStartProtect];
FNativeTextStyleId is for odd lines. They are should not be edited at all.

FTranslationTextStyleId is for even lines. They will be edited but should not be erased as paragraphs. In the above-stated example, user should be able to remove text "one" but not the whole line. I.e. empty line should remain.

Now I can delete the line by Backspace key, so that "1" and "2" lines appear close by, without an empty line between them.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's not possible to implement exactly what you want. You can include DeleteProtect without ModifyProtect, it's almost what you need, but... It does not allow the last character of item to be deleted, i.e. it does not allow to create empty item from it.
May be protection allowing making empty items will be introduced in new version, but not now.

May be you can consider using tables?
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

Sergey Tkachenko wrote:May be you can consider using tables?
If this is the only way :( ...
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

I filled a table cells with text. How can I protect text in some cells against editing?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

a) Using paragraph and/or text protection (Options property of paragraph style, Protection property of text style)
or
b) Using table.OnCellEditing event
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

This is ready. Now I need to select certain text in a certain cell, for example, from 10th to 20th characters in the cell[3, 1]. I guess I should use SetSelectionBounds function. But what parameters do I have to pass into it in my case?

Code: Select all

  procedure AddRow(List: TTntStringList; index, ParaStyleId, TextStyleId: Integer);
  var
    tmp: WideString;
  begin
    if List.Count > index then
      tmp := List[index]
    else
      tmp := '';
    if RowCount > TableInfo.RowCount then
      TableInfo.InsertRows(TableInfo.RowCount, RowCount - TableInfo.RowCount, -1);
    with TableInfo.Cells[RowCount - 1, 0] do begin
      DeleteItems(0, ItemCount);
      AddNLWTag(tmp, TextStyleId, ParaStyleId, 0);
      if Odd(RowCount) then
        Color := $DDDDDD;
    end;
    TableInfo.EditCell(RowCount - 1, 0);
    TCustomRVFormattedData(TableInfo.Cells[RowCount - 1, 0].Edit).SelectAll;
    Inc(RowCount);
  end;
On EditCell call I get error

---------------------------
Debugger Exception Notification
---------------------------
Project SE_sample.exe raised exception class EListError with message 'List index out of bounds (-1)'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

Would anyone help me with that?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You cannot select or edit in unformatted documents.
So you cannot call EditCell and SelectAll until you call Format.
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

It's interesting, especially that help topic "Selection in Table" says nothing about it.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Well, I added the remark about formatting in all topics about TRichView/TRichViewEdit methods working with selection (including SelectAll), but I forgot to do it in table topics.
I'll fix the help file in the next update.
duzenko
Posts: 9
Joined: Thu Feb 07, 2008 3:20 pm

Post by duzenko »

I added the Format function call. This allowed me to get rid of the exception, but now the RichViewEdit gets focused on the parent form during the building of documents.

This is a cosmetic thing but is important for us.

How could I avoid self-focusing of the component?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Answered by e-mail
Post Reply