Page 1 of 1
Inserted item is not updated until you click the mouse
Posted: Fri Jun 03, 2022 8:46 am
by Vitalii
Hi,
I create a new element (a descendant of TRVLabelItemInfo or TRVMathItemInfo) in a dialog box (call it "editor") and change the Text property.
Then I insert the element into SRichView via InsertItem method. The element is added normally, but Text changes only happen when I click on SRichView. Without a mouse click, no changes occur, but the user wants to see the result automatically after closing the editor, of course.
The same thing happens even if I edit a formula through a standard editor (TfrmRVMathEditor). The editor makes changes to the item, but we need to click RichView directly to see them.
I tried to use SetFocus, Invalidate methods after closing the window, but it doesn't help. Only mouse click update the text of the document.
Am I missing something?
Re: Inserted item is not updated until you click the mouse
Posted: Fri Jun 03, 2022 9:57 am
by Sergey Tkachenko
1)
If you change properties of an item, you need to reformat the affected part of the document.
If you want to change it as an editing operation, the simplest way is not a direct assignment to the property, but accessing it as "extra item property".
In this way, the item will be reformatted, and the change is recorded to the undo list.
For example, to change text of TRVLabelInfo, assuming that this is the active item in the editor:
Code: Select all
SRV.ActiveEditor.SetCurrentItemExtraStrProperty(rvespcText, 'New text', True);
See the help file:
https://www.trichview.com/help/idh_trvl ... _text.html
2) How do you use TfrmRVMathEditor? If you use Form.GetItem to apply changes to the editor (as RichViewActions do), all changes are set using SetCurrentItemExtraStrPropertyEx and SetCurrentItemExtraIntPropertyEx, so the editor must be updated properly.
Re: Inserted item is not updated until you click the mouse
Posted: Fri Jun 03, 2022 12:17 pm
by Vitalii
Of course, I format document (using Reformat method) after closing the editor. The problem is loss of focus; strange, but for some reason, it is not possible to programmatically set the focus using the SRV.SetFocus method. Focus returns only when I click the mouse and then SRV successfully finishes format operations.
So, there no problem with TfrmRVMathEditor itself (my question #2) — only when TfrmRVMathEditor takes focus and SRV cannot get it back. Questions #1 and #2 is the same)
Also weird, but when I watch Edit1.Focused (in Watches) - there's always "Inaccessible value"...
My SRV component is created in one window and then moved to another (due to the assignment of a new Parent). Maybe a problem with changing Parent property?
Re: Inserted item is not updated until you click the mouse
Posted: Fri Jun 03, 2022 1:01 pm
by Sergey Tkachenko
For TRVLabelItemInfo, Format/Reformat might be not enough, because it caches some formatting data. It is updated (on the next reformatting) only if you call Label.Changed. This method is called automatically if you change label properties (such as Text or TextStyleNo), but it may be necessary to call if you change other properties.
When TSRichViewEdit gets focus, it moves it to its ActiveEditor. So Check SRV.ActiveEditor.Focused instead of SRV.Focused.
However, in my tests, SRV.SetFocus works. Try SRV.ActiveEditor.SetFocus.
Re: Inserted item is not updated until you click the mouse
Posted: Sat Jun 04, 2022 7:07 am
by Vitalii
Sergey,
I reproduced the issue in the small application (see attached file).
1. Insert equation using "Equation" button --> OK
2. Double click equation to open editor --> OK
3. Edit equation (make some changes), close editor --> NOT OK
Theoretically, in step 3 (after closing the editor) we should see the changed document, but it seems to "lose focus". We will see changes only if we click on the edit. What I'm doing wrong?)
Re: Inserted item is not updated until you click the mouse
Posted: Sat Jun 04, 2022 9:31 am
by Sergey Tkachenko
The problem is in updating ScaleRichView in mouse down item.
The component blocks updates inside this event, so you need to allow them.
The code could be like this:
Code: Select all
procedure TForm1.SRichViewEdit1RVMouseDown(Sender: TCustomRichView;
Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
var
ActionItemProperties: TrvActionItemProperties;
ItemInfo: TCustomRVItemInfo;
CU: Boolean;
begin
if ItemNo < 0 then Exit;
if Shift = [ssLeft, ssDouble] then
begin
ItemInfo := SRichViewEdit1.ActiveEditor.GetItem(ItemNo);
if ItemInfo.StyleNo = rvsMathEquation then
begin
CU := SRichViewEdit1.CanUpdate;
SRichViewEdit1.CanUpdate := True;
ActionItemProperties := TrvActionItemProperties.Create(Self);
try
ActionItemProperties.Execute;
finally
ActionItemProperties.Free;
SRichViewEdit1.CanUpdate := CU;
end;
end;
end;
end;
I removed the call of Format, it is not needed (the action reformats the affected paragraph itself).
Re: Inserted item is not updated until you click the mouse
Posted: Sat Jun 04, 2022 10:16 am
by Vitalii
Thank you very much! It solves everything.