Using SysInetHTMLEditor in Ax 2009 - dynamics-ax-2009

I need to provide a HTML editor functionality in Dynamics Ax 2009.
I figure out a button in a my form the call the html editor provided by SysInetHTMLEditor.
I can call the form with code like this:
SysInetHTMLEditor editor;
;
editor = new SysInetHTMLEditor();
editor.run();
But I have not idea how to use the return, setting the initial text and so on.
I still searching documentation about the class but I can't found it.
Someone can provide me some example?

Finally I found the solution. First, build a class that extends SysInetHTMLEditor.
build a method text:
str text(str text = '')
{
int i;
;
if (prmisdefault(text))
return super();
i = strscan(text, '<body', 1, strlen(text));
if (i)
{
text = strdel(text, i, strscan(text, '>', i, strlen(text))-i+1);
}
return super(text);
}
use "this.text(sometext)" to set initial text (usually on new method)
override save() to save the text (get it with this.text())
override caption method to change caption
override canClose() to save before exit
override isToolEnabled for control tools:
boolean isToolEnabled(int commandId, int tab)
{
switch (tab)
{
case #TABSource:
switch (commandId)
{
case #TOOL_SAVE:
return true;
}
return false;
case #TABPreview:
return false;
case #TABNormal:
switch (commandId)
{
case #TOOL_SAVEAS:
case #TOOL_NEW:
case #TOOL_OPEN:
case #TOOL_MENU_ELEMENT:
case #TOOL_MAKEABSOLUTE:
case #TOOL_BRINGTOFRONT:
case #TOOL_SENDTOBACK:
case #TOOL_BRINGFORWARD:
case #TOOL_SENDBACKWARD:
case #TOOL_BRINGABOVETEXT:
case #TOOL_SENDBELOWTEXT:
case #TOOL_LOCKELEMENT:
case #TOOL_INSERTWEBPART:
case #TOOL_INSERTACTIVEX:
case #TOOL_INSERTWEBLET:
case #TOOL_INSERTAXAPTAMENU:
case #TOOL_THEME:
return false;
case #TOOL_INSERTBOOKMARKLINK:
case #TOOL_HELPSYSTEM:
case #TOOL_INSERTHELPLINKMENU:
case #TOOL_INSERTFORMRUNLINK:
case #TOOL_INSERTEXTHELPLINK:
case #TOOL_INSERTFIELDLINK:
case #TOOL_INSERTMENUDISPLAYLINK:
case #TOOL_INSERTMENUOUTPUTLINK:
case #TOOL_INSERTMENUACTIONLINK:
case #TOOL_INSERTCLASSLINK:
case #TOOL_INSERTMETHODLINK:
case #TOOL_INSERTFUNCTIONLINK:
case #TOOL_INSERTPROPERTYLINK:
case #TOOL_INSERTHELPTITLE:
case #TOOL_INSERTIFRAME:
return false;
}
}
return true;
}

Related

Is there any way to implement long press gesture with SkiaSharp?

I am using Skiasharp on Xamarin Forms app. With SKTouchAction I was trying to capture the time duration of SKTouchAction.Pressed and SKTouchAction.Released and find if the gesture is Long pressed or not. But the issue is SKTouchAction.Released is not triggered on Android.
protected override void OnTouch(SKTouchEventArgs e)
{
switch (e.ActionType)
{
case SKTouchAction.Moved:
break;
case SKTouchAction.Pressed:
//save current time here
break;
case SKTouchAction.Released:
//Compare time here to check long press
break;
}
}
There is a similar issue on the github. It seems you need to let the OS know that you wanted to continue receiving touch events. Such as:
protected override void OnTouch(SKTouchEventArgs e)
{
e.Handled = true;
switch (e.ActionType)
{
case SKTouchAction.Moved:
break;
case SKTouchAction.Pressed:
//save current time here
break;
case SKTouchAction.Released:
//Compare time here to check long press
break;
}
}
In addition, you can also refer to this case.

Changing filename color in Windows Explorer list view.

I would like to customize Windows Explorer.
One thing I want to do is changing file name's color in list view if the file has a special condition.
Is it possible by window subclassing? or does it need api hooking?
Please let me know what is the best way to do this.
Thanks.
Yes, you can do it with the window subclassing:
Add NM_CUSTOMDRAW handler to your CListCtrl-derived class
void CMyList::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
switch (lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
lplvcd->clrText = **MY_COLOR**;
*pResult = CDRF_DODEFAULT;
}
}

Determining object types in Qt

I have a series of QTextEdits and QLineEdits connected to a slot through a QSignalMapper(which emits a textChanged(QWidget*) signal). When the connected slot is called (pasted below), I need to be able to differentiate between the two so I know whether to call the text() or toPlainText() function. What's the easiest way to determine the subclass type of a QWidget?
void MainWindow::changed(QWidget *sender)
{
QTextEdit *temp = qobject_cast<QTextEdit *>(sender);
QString currentText = temp->toPlainText(); // or temp->text() if its
// a QLineEdit...
if(currentText.compare(""))
{
...
}
else
{
...
}
}
I was considering using try-catch but Qt doesn't seem to have very extensive support for Exceptions... Any ideas?
Actually, your solution is already almost there. In fact, qobject_cast will return NULL if it can't perform the cast. So try it on one of the classes, if it's NULL, try it on the other:
QString text;
QTextEdit *textEdit = qobject_cast<QTextEdit*>(sender);
QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender);
if (textEdit) {
text = textEdit->toPlainText();
} else if (lineEdit) {
text = lineEdit->text();
} else {
// Return an error
}
You can also use sender->metaObject()->className() so you won't make unnecesary casts. Specially if you have a lot of classes to test. The code will be like this:
QString text;
QString senderClass = sender->metaObject()->className();
if (senderClass == "QTextEdit") {
QTextEdit *textEdit = qobject_cast<QTextEdit*>(sender);
text = textEdit->toPlainText();
} else if (senderClass == "QLineEdit") {
QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender);
text = lineEdit->text();
} else {
// Return an error
}
I know is an old question but I leave this answer just in case it would be useful for somebody...

refactor dilemma

I want to extract the guard statement from the following method
private void CreateProxy()
{
//extract the following guard statement.
Host selected = this.comboBox1.SelectedItem as Host;
if (selected == null)
{
return;
}
this.SearchProxy = ServiceProxy.ProxyFactory.CreateSearchProxy(GetSelectedIP().ToString());
this.StreamProxy = ServiceProxy.ProxyFactory.CreatePlayerProxy(GetSelectedIP().ToString());
}
//extracted guard method
public bool IsHostSelected()
{
Host selected = this.comboBox1.SelectedItem as Host;
if (selected == null)
{
return false;
}
return true;
}
see? now i have to add return value for the extracted method, is this kinda ugly?
any better solution to avoid adding the return value for the extracted method?
I don't see the big deal. First, I would rewrite it as:
static bool SelectedItemIsHost(ComboBox box) {
return box.SelectedItem is Host;
}
Note the rename, the ComboBox as a parameter, and the body change.
Now, this makes your code read more clearly:
void CreateProxy() {
if(SelectedItemIsHost(this.comboBox1)) {
this.SearchProxy = ServiceProxy.ProxyFactory.CreateSearchProxy(GetSelectedIP().ToString());
this.StreamProxy = ServiceProxy.ProxyFactory.CreatePlayerProxy(GetSelectedIP().ToString());
}
}
So now it reads "if the selected item is a Host then do stuff."
Now, this goes way beyond your question, but this looks like a big coupling of UI logic and domain logic. You might want to reconsider a decoupling there.
any better solution to avoid adding the return value for the extracted method?
Yes:
//extracted guard method
public bool IsHostSelected()
{
Host selected = this.comboBox1.SelectedItem as Host;
return selected != null;
}

Replacing nested if statements

This is related to a chapter from beautiful code.
And in that chapter I read about the nested ifs.
The author was talking about deeply nested ifs as originator of bugs and less readable.
And he was talking about replacing nested ifs with case statements and decision tables.
Can anybody illustrate how to remove nested ifs with case (select case) and decision tables ?
Well, not directly an answer to your question since you specifically ask about switch/case statements, but here is a similar question.
Invert “if” statement to reduce nesting
This talks about replacing nested if's with guard-statements, that return early, instead of progressively checking more and more things before settling on a return value.
One example I always try to do is replace heavily nested if's like this (actually this one's not too bad but I've seen them up to 8 or 9 levels deep in the wild):
if (i == 1) {
// action 1
} else {
if (i == 2) {
// action 2
} else {
if (i == 3) {
// action 3
} else {
// action 4
}
}
}
with this:
switch (i) {
case 1:
// action 1
break;
case 2:
// action 2
break;
case 3:
// action 3
break;
default:
// action 4
break;
}
I also try to keep the actions as small as possible (function calls are best for this) to keep the switch statement compressed (so you don't have to go four pages ahead to see the end of it).
Decision tables, I believe, are simply setting flags indicating what actions have to be taken later on. The "later on" section is simple sequencing of actions based on those flags. I could be wrong (it won't be the first or last time :-).
An example would be (the flag-setting phase can be complicated if's since its actions are very simple):
switch (i) {
case 1:
outmsg = "no paper";
genmsg = true;
mailmsg = true;
phonemsg = false;
break;
case 2:
outmsg = "no ink";
genmsg = true;
mailmsg = true;
phonemsg = false;
break;
default:
outmsg = "unknown problem";
genmsg = true;
mailmsg = true;
phonemsg = true;
break;
}
if (genmsg)
// Send message to screen.
if (mailmsg)
// Send message to operators email address.
if (phonemsg)
// Hassle operators mobile phone.
How about chained ifs?
Replace
if (condition1)
{
do1
}
else
{
if (condition2)
{
do2
}
else (condition3)
{
do3;
}
}
with
if (condition1) {
do1;
} else if (condition2) {
do2;
} else if (condition3) {
do3;
}
This is much like switch statement for complex conditions.
Make the condition into booleans and then write boolean expression for each case.
If the code was:
if (condition1)
{
do1
}
else
{
if (condition2)
{
do2
}
else (condition3)
{
do3;
}
}
One can write it as:
bool cond1=condition1;
bool cond2=condition2;
bool cond3=condition3;
if (cond1) {do1;}
if (!cond1 and cond2) {do2;}
if (!cond1 and cond3) {do2;}
For decision tables, please see my answer to this question, or better still read chapter 18 in Code Complete 2.
You can just break once a part of the validation failed for example.
function validate(){
if(b=="" || b==null){
alert("Please enter your city");
return false;
}
if(a=="" || a==null){
alert("Please enter your address");
return false;
}
return true;
}
Decision tables are where you store the conditional logic in a data structure rather than within the code itself.
So instead of this (using #Pax's example):
if (i == 1) {
// action 1
} else {
if (i == 2) {
// action 2
} else {
if (i == 3) {
// action 3
} else {
// action 4
}
}
}
you do something like this:
void action1()
{
// action 1
}
void action2()
{
// action 2
}
void action3()
{
// action 3
}
void action4()
{
// action 4
}
#define NUM_ACTIONS 4
// Create array of function pointers for each allowed value of i
void (*actions[NUM_ACTIONS])() = { NULL, action1, action2, action3 }
// And now in the body of a function somewhere...
if ((i < NUM_ACTIONS) && actions[i])
actions[i]();
else
action4();
If the possibilities for i are not low-numbered integers then you could create a lookup table instead of directly accessing the ith element of the actions array.
This technique becomes much more useful than nested ifs or switch statements when you have a decision over dozens of possible values.
If and switch statements are not purely OO. They are conditional procedural logic, but do a very good job! If you want to remove these statements for a more OO approach, combine the 'State' and 'Descriptor' patterns.
You might also consider using the Visitor pattern.
Nested if are equivalent to the logical operator AND
if (condition1)
{
if (function(2))
{
if (condition3)
{
// do something
}
}
}
Equivalent code:
if (condition1 && function(2) && condition3)
{
// do something
}
In both cases, when an expression evaluates false, the subsequent expression will not be evaluated. For example, if condition1 is false, the function() will not be called, and condition3 won't be evaluated.
Another example some languages allow is this
switch true{
case i==0
//action
break
case j==2
//action
break
case i>j
//action
break
}

Resources