Shoutbox

Help with a menu selection - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Help with a menu selection (/showthread.php?tid=62899)

Help with a menu selection by Paril on 07-09-2006 at 12:57 PM

Hey, again.

For my Programming Languages Keyword Script (C/C++ Keywords is gone, it has now support for over 12 languages), I am working on the menus. So far so good, but I can't get it able to click something, and to add something to his/her send message bar.

On the click of item "PHP", I want it to add (but not send):

[ code=php] [/code ]

I tried this:

code:
var talkerList = new Array(
"PHP", "C/C++");

function OnGetScriptMenu(Location){
    var sMenu = "<ScriptMenu>";
    if(Location == 1)
    {
            sMenu += "<MenuEntry Id=\"Help\">Help - How to Use</MenuEntry>";
            sMenu += "<MenuEntry Id=\"About\">About</MenuEntry>";
    }
    else if(Location == 2)
    {
        for(var i = 0; i < talkerList.length; i++)
            sMenu += "<MenuEntry Id=\""+talkerList[i]+""+talkerList[i]+"\">"+talkerList[i]+"</MenuEntry>";
        sMenu += "<Separator/>";
        sMenu += "<MenuEntry Id=\"Help\">Help - How to Use</MenuEntry>";
        sMenu += "<MenuEntry Id=\"About\">About</MenuEntry>";
    }
    sMenu += "</ScriptMenu>";
    return sMenu;
}

function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
    var currenttext = OriginWnd.EditText;
    switch(MenuItemId)
    {
            case "PHP":
                OriginWnd.EditText_SetCurSel (currenttext.substr(0,1), currenttext.substr(currenttext.length,1));
                OriginWnd.EditText_ReplaceSel ("[ code=php] [/code ]");
                break;
    }
}


It's about the PHP one. How will I get it to work?

- Jon
RE: Help with a menu selection by J-Thread on 07-09-2006 at 01:27 PM

code:
sMenu += "<MenuEntry Id=\""+talkerList[i]+""+talkerList[i]+"\">"+talkerList[i]+"</MenuEntry>";

shouldn't that be:
code:
sMenu += "<MenuEntry Id=\""+talkerList[i]+"\">"+talkerList[i]+"</MenuEntry>";

RE: Help with a menu selection by Paril on 07-09-2006 at 01:29 PM

I'll try that..

EDIT:
That's not what I'm having problems with, both work correctly.

I want it to add:

[ code=PHP] [ /code]

in the send message box, when you click on it.


RE: Help with a menu selection by Paril on 07-09-2006 at 01:48 PM

It's this part here

function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
var currenttext = OriginWnd.EditText;
switch(MenuItemId)
{
         case "PHP":
         OriginWnd.EditText_SetCurSel (currenttext.substr(0,1), currenttext.substr(currenttext.length,1));
         OriginWnd.EditText_ReplaceSel ("[ code=php] [/code ]");
         break;
    }
}


it seems to not want to do anything..


RE: Help with a menu selection by J-Thread on 07-09-2006 at 01:59 PM

You're using EditText_SetCurSel in the wrong way. The function takes 2 numbers, and you are passing 2 strings. You should do:

code:
function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
var currenttext = OriginWnd.EditText;
switch(MenuItemId)
{
         case "PHP":
         OriginWnd.EditText_SetCurSel (0, currenttext.length - 1);
         OriginWnd.EditText_ReplaceSel ("[ code=php] [/code ]");
         break;
    }
}

That will replace all text in the edit box with [ code=php][/code ]. To replace it with: [ code=php]oldtext[/code ] use:

code:
function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
var currenttext = OriginWnd.EditText;
switch(MenuItemId)
{
         case "PHP":
         OriginWnd.EditText_SetCurSel (0, currenttext.length - 1);
         OriginWnd.EditText_ReplaceSel ("[ code=php]"+currenttext+"[/code ]");
         break;
    }
}

RE: Help with a menu selection by Paril on 07-09-2006 at 02:01 PM

Ah, thanks, will try it..

EDIT:
Thanks, it works!
:)

Expect a release soon.