Forum > Designer
onFormChanged event
(1/1)
warleyalex:
The plan would be to implement an IDE notifier to the Lazarus plugin IDE project event onFormChanged.
For instance, whenever a form designer has been changed I would like to fire a method. e.g. You drag 'n drop a TLabel widget into designer, set the Caption to 'abcd' and then fire the event "onFormChanged".
So, I am stuck on this plan.
Any idea is very welcome.
warleyalex:
Every designed LCL form has a Designer of type TIDesigner. The IDE creates designers of type TComponentEditorDesigner defined in the IDEIntf unit componenteditors.
You get notified when a designer form is modified with this piece of code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---GlobalDesignHook.AddHandlerModified(@Extension.OnDesignerModified);
...but there is an issue here:
the designer is notified using only the Object Inspector!
Important note:
when you resize a component at design-time, you resize with the mouse, dragging the component, the designer is not notified!
Any idea?
warleyalex:
I'll share you guys the solution.
...the problem of the method AddHandlerModified is triggered after little change, for instance, if I set the WebLabel caption to 'abc' the method is fired 3 times. This is unwanted. I only want to trigger on form save.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---GlobalDesignHook.AddHandlerModified(@Extension.OnDesignerModified);
I found the undocumented method AddHandlerOnSaveEditorFile. We can fire the method LFM-TO-PAS "on before save" the form unit.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---LazarusIDE.AddHandlerOnSaveEditorFile(@Extension.BeforeSaveCallLFM2PAS);
Do not forget to use RemoveHandlerOnSaveEditorFile on the add-on the destructor.
This is the trick!
Navigation
[0] Message Index