Page 1 of 1

Custom Item Type, OnItemAction

Posted: Tue Feb 28, 2017 12:16 pm
by cychia_n2n
According to this thread:
http://www.trichview.com/forums/viewtop ... tion#p2644

We were suggested to have a list to keep items and check item existence during OnItemAction.

I need to keep a list of items as well. I have some special items with tags that I need to keep track of, so I have handled OnItemAction, when action = rviaInserted, I will first check the tag if it is something i need to monitor, then will check from my list to confirm it is not existed then add. Those items can be graphicitem, tableitem or textitem so long it is tagged with the special identifier.

For textitem, when I call AddNLTag('whatever', CurTextStyleNo , -1, '[Special]'), OnItemAction will be triggered and that item will be kept in my list.

I have a few problems now:

1. when inserting text, i want it to follow current font style, so I will get from rve.CurTextStyleNo, but at the same time, I want this newly added text to be protected from modification, how can I do that?

2. I tried cut the text item in a table cell, I found the OnItemAction is triggered in the following sequence
- rviaMovingToUndoList
- rviaInserting
- rviaInserted
when I received OnItemAction with both rviaInserting and rviaInserted, i found the item's tag is same with the item that I have cut, any idea?

Re: Custom Item Type, OnItemAction

Posted: Tue Feb 28, 2017 12:22 pm
by Sergey Tkachenko
1) See protection options: http://www.trichview.com/help/idh_tcust ... ction.html
You can protect from changing a text style with rvprStyleProtect option

2) Probably, it happens when an item is removed but an empty text item is inserted in its place.

Re: Custom Item Type, OnItemAction

Posted: Mon Mar 06, 2017 8:44 am
by cychia_n2n
1. I have try the following to protect my item text style, it seems working now. If rvprParaStartProtect is not added into protection, when I press Enter at end of the text item I have inserted, OnItemAction will trigger for an new empty text item with the same tag, but if rvprParaStartProtect is added, it blocks user from pressing Enter button when caret is in the text item front/back. I still need to allow enter to be press to go to new para, or make the item a new para by pressing enter with the caret in front of the text item, but I dont want the tag assigned to the special item being used by the new item. I thought rvprDoNotAutoSwitch should do this trick?

function GetItemStyleNo: Integer;
var
fi: TFontInfo;
begin
fi := TFontInfo.Create(nil);
try
with rve.TopLevelEditor do
begin
fi.Assign(Style.TextStyles[CurTextStyleNo]);
fi.Protection := [rvprParaStartProtect, rvprConcateProtect, rvprDoNotAutoSwitch];
Result := Style.TextStyles.FindSuchStyle(0, fi, RVAllFontInfoProperties);
if Result < 0 then
begin
Result := Style.TextStyles.Count;
Style.TextStyles.Add;
Style.TextStyles[Result].Assign(fi);
Style.TextStyles[Result].Standard := False;
end;
end;
finally
fi.Free;
end;
end;

procedure InsertText(s: widestring; ATAg: string);
begin
with rve.TopLevelEditor do
begin
CurTextStyleNo := GetItemStyleNo;
InsertStringWTag(s, ATag);
end;
end;

2) why my caret always moved to the front after InsertStringWTag? How can I maintain the caret at the end of the item?

3) any other possibilities where new empty item with same tag will be added besides pressing ENTER?

Re: Custom Item Type, OnItemAction

Posted: Thu Mar 09, 2017 11:15 am
by cychia_n2n
Any idea?

Re: Custom Item Type, OnItemAction

Posted: Thu Mar 09, 2017 5:40 pm
by Sergey Tkachenko
1. When user press Enter, a new item must be added using the current text style. rvprDoNotAutoSwitch should prevent switching to this style, so, if the text item is protected, new items must not be created using this style when the user pressed Enter at the end of the paragraph. If it still happens, please send me a simple project to reproduce.

2. After InsertStringWTag, the caret must be at the end of the inserted text. May be you call Format after that, Format moves the caret to the beginning.

3. Plain text insertion (including pasting and drag&drop) inside the item. Copy-pasting and drag&drop of fragments containing these items (in RVF format)