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?
Custom Item Type, OnItemAction
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Custom Item Type, OnItemAction
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.
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.
-
- Posts: 16
- Joined: Mon May 09, 2016 9:16 am
Re: Custom Item Type, OnItemAction
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?
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?
-
- Posts: 16
- Joined: Mon May 09, 2016 9:16 am
Re: Custom Item Type, OnItemAction
Any idea?
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Custom Item Type, OnItemAction
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)
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)