Setting callback for SEditableText widget to save text - unreal-engine4

I have implemented an SEditableText widget in my editor plugin but I can't figure out a reasonable way of accessing the value in the widget. I know there is an SEditableText.OnTextChanged() function but I don't see anyway to override it or set a callback of my own. Is there a standard way to save the content of an SEditableText to a variable?
I am working in the context of FModeToolKit, not sure if that makes a difference.

When you instantiate the slate widget, you should already be making a call to SNew. As part of the property initialiser chain list, initialise SEditableText::OnTextChanged and bind to your container UObject, using BIND_UOBJECT_DELEGATE. The delegate signature should be FOnTextChanged. Your handler will receive an FText which may be stored in a variable as required.
Example:
SEditableText EditableText = SNew(SEditableText)
.OnTextChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, OnTextChanged);
then:
void UMyUObject::HandleOnTextChanged(const FText& InText)
{
// Do something with text
}
Take a look at it in action in UEditableText::RebuildWidget (EditableText.cpp:50, v4.22.1).
NB. I know you specifically asked about OnTextChanged, but also consider OnTextComitted; this is only fired when the slate widget loses focus.
Ah; BIND_UOBJECT_DELEGATE is in UMG. The macro is however just a helper to create a UObject to which you may bind:
#define BIND_UOBJECT_DELEGATE(Type, Function) \
Type::CreateUObject( this, &ThisClass::Function )
So there's two options, either use <my type>::CreateUObject, or you could bind via a shared pointer. Off the top of my head, SP method should look something like:
Edit (based on comments):
If you're not linked against UMG, you could try manually creating the UObject based on the macro defined in SlateWrapperTypes in UMG:
#define BIND_UOBJECT_DELEGATE(Type, Function) \
Type::CreateUObject( this, &ThisClass::Function )
To instead use a shared pointer, the syntax should be along the following lines:
auto OnTextChangedSP = FOnTextChanged::CreateSP(this, &MyClass::MyOnTextChangedHandler);
SEditableText EditableText = SNew(SEditableText)
.OnTextChanged(OnTextChangedSP);

Related

How to moving fields in forms of ncurses

I've written a program in C using ncurses and specially forms. I need that a particular field of my form moves as I'm filling the form. I tried move_field, but it doesn't work.
Here is how I wrote it :
if (typact==ADSD && rowc>rowg )
{
move_field(field[ietg],rowg=rowc,colg);
refresh();
}
I'm sure that the move_field is executed (I use xCode for debugging my program). I presume that refresh is not sufficient. I tried also placing move_field between unpost_form and post_form like this:
if (typact==ADSD && rowc>rowg /* && !field_status(field[ietg]) */ )
{ unpost_form(my_form);
move_field(field[ietg],rowg=rowc,colg);
post_form(my_form); refresh();
}
but it doesn't work once again. The form is erased and re-posted without the texts I have written and the field is always in the same place.
How could I use move_field?
The manual page says
The function move_field moves the given field (which must be disconnected) to a specified location on the screen.
You can disconnect a field by retrieving the current list of fields with form_fields (and its length using field_count), removing the field from that list and updating the list using set_form_fields.
When using move_field, you must also (temporarily) unpost the form with unpost_form. Otherwise, move_field returns E_POSTED (The form is already posted). After moving the field, use post_form to get the form-driver to work with the updated form.
The test/move_field.c file in ncurses sources provides an example of these calls.

How to bind <Tab> key press in Perl Tk?

I am looking for the code syntax to bind a <Tab> keypress event to a Perl Tk Widget.
Reading through the documentation, I saw i can bind <Control> and <Alt> (and any combination), but couldn't find the <Tab> key binding.
I've tried ...->bind('<Tab>', sub{...}); but it didn't work.
How to bind it?
After digging with this issue for a while, and exploring all good advice provided in the comments. I've found out the best way to achieve my purpose is to derive the Widget and create my own custom widget, and use OOP override techniques to control the behavior.
This works like charm.
So for Tk::Text, for example, the native <Tab> event is bind to
$mw->bind($class,'<Tab>', 'insertTab');
sub insertTab
{
my ($w) = #_;
$w->Insert("\t");
$w->focus;
$w->break
}
And by deriving from Tk::Text widget to my own Tk::myText widget, I was able to override the insertTab method as follows:
sub insertTab
{
my ($w) = #_;
// <-- place my stuff here
// <-- to be executed first
$w->SUPER::insertTab(); // <-- then call the original <Tab> handler from the parent
}

How to overwrite form method on form created by code?

On a form created in AOT you can rewrite methods by right click and overwrite. How can you do the same on the form which are created by X++ code?
For example. How to change close method so it will call info("close"); before closing on this:
form = new Form();
formBuildDataSource = form.addDataSource("Table");
formBuildDesign = form.addDesign("Design");
form.design().caption("Caption");
…
args = new Args();
formRun = classfactory.formRunClass(args);
formRun.run();
formRun.detach();
I am using AX2012
Typically you will want to execute a predefined method. You can then use the registerOverrideMethod method of form controls. This is explained here.
In the call to registerOverrideMethod always provide the third argument, being the object holding the method.
formButtonControl.registerOverrideMethod(
methodStr(FormButtonControl,clicked), //method to override
methodStr(testClass,testMethod), //method to invoke
new testClass()); //object of class containing method
It is of cause also possible to save source to the AOT using class TreeNode method AOTSetSource.
An example here.
You will need to save the form to AOT and compile before executing with FormRun.

Get field values in record.js

I override the record view, by creating in custom/modules/myModule/clients/base/views/record/record.js this file record.js. I want to get the value of a field for the current object and I use this.model.get('duration'), but I get nothing.The only field available is "id". How can I retrieve the values for others fileds?
When the record.js script is initially called, the model won't have fully loaded, so the only available field with be the id.
Your best bet is probably to override the _renderHtml function; by the the time the view is being rendered all the model details will have fully loaded:
_renderHtml: function() {
// custom code involving this.model.get('duration')
// call parent
app.view.View.prototype._renderHtml.call(this);
}
Note that you may find _renderHtml is called multiple times, sometines before the model is fully loaded. This is just a quirk of Sugar so it may be best to add a check in your code:
if (this.model.get('duration')) {
// custom code involving this.model.get('duration')
}
Dont forget that app.model.get('myfield') only delivers the right content (from this field) when your field is already displayed in detailview - else you will get "undefined"!
So you
Have to call the rest api (rest/v10/yourmodel/yourid) - than you
have all the values available
Display your fields (even you dont want to) to be able to use it in app.model.get('yourfield'), an alternative you could append your record.js (after rendering) with $('div [data-name="yourfield"]').hide();
I know this question is quite old already (but if someone else run into this he could find this useful).

Which file contains function of core/session in magento?

I need to customize other's code,
so I found they used
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
in Order.php file for custom order email
so I can't find this function getMyCustomBlockInfo();
Can anyone tell me where this function reside?
Thanks
those are magic functions get() and set() and you are asking a session variable there that is set as
Mage::getSingleton('core/session')->setMyCustomBlockInfo();
somewhere in your code. If you use terminal you can easily find by making a following grep:
grep '>setMyCustomBlockInfo(' . -rsni
and it will list the files where your variable is set to session.
example :
Mage::getModel('catalog/product'); //or
Mage::getSingleton('catalog/product');
the code must be in '../app/core/Mage/Catalog/Model/Product.php' file
then
Mage::getSingleton('core/session');
the code must be in '../app/core/Mage/Core/Model/Session.php' file
because the class Mage_Core_Model_Session's parent::parent is Varien_Object, then you can do all magic functions and you can ->getData() to see the Data inside.
Mage::getSingleton('core/session')->getData();
on your problem when go call ->getData() you can see data : [my_custom_block_info]
you can set it with call
Mage::getSingleton('core/session')->setMyCustomBlockInfo('what');
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
// will return 'what'