Page 1 of 1

How to execute command from popupmenu return string

Posted: 19 Oct 2017 20:13
by jaywalker32
I'm trying to setup a custom popupnested menu which can have button commands (like :viewthumbs) or normal commands (like #306)

I don't want to execute the commands directly from the popup menu, but instead read the selected menu item, then decide whether to execute it or not:

Code: Select all

$a = readfile("<xydata>\filters.txt");    
  $fil = popupnested($a);
  if ($fil != ""){  
  	if(gettoken($fil, 1,"") == "§"){
  		execute $fil; //$fil = #306 or $fil = :viewthumbs
  	}	
  	else{
    	filter $fil, 8;
    }
  }



My problem is, how do I 'execute' whatever is in $fil?

Re: How to execute command from popupmenu return string

Posted: 19 Oct 2017 20:51
by highend
Don't know what button commands are but you can execute internal (#...) commands via

Code: Select all

goto #<command id>;

Re: How to execute command from popupmenu return string

Posted: 19 Oct 2017 21:16
by bdeshi
button commands with

Code: Select all

button regexreplace(<button>, "^:");
// Use just the text part of the button name. The colon is only needed for using that button's icon.
// eg, button 'viewthumbs';

Re: How to execute command from popupmenu return string

Posted: 19 Oct 2017 21:30
by bdeshi
In fact, here's a better example. Check whether the $fil var has # or : at start and either run a command or trigger a button.
However, it looks like your $fil already has a '§' marker at the beginning, so we have to trim this before executing the command:

Code: Select all

if (gettoken($fil, 1,"") == "§"){
  $fil = substr($fil, 1);           // trim the first char ("§" marker) of $fil
  switch substr($fil,, 1) {         // get starting char of $fil, this should be now be # or :
  case '#':                         // in case it's # ...
    load $fil,, 's'; break;         // run the #command
  case ':':                         // in case it's : ...
    button substr($fil, 1); break;  // trigger the button (but we don't want the : here)
  }
}

Re: How to execute command from popupmenu return string

Posted: 19 Oct 2017 23:36
by jaywalker32
Thanks! It works. In fact, it seems that 'button' works for both cases, so no need to check whether it's # or :

Nvm, it was executing it directly from the popup. The switch..case still works tho.