Page 1 of 2

Enabl button on selection only

Posted: 06 Sep 2014 02:22
by U_2582
Just like open with toolbar button, how can I have a custom button enabled only when items are selected?

Thanks

Re: Enabl button on selection only

Posted: 06 Sep 2014 08:39
by bdeshi
Scripted buttons cannot update themselves automatically. Sorry.
----
the ctbstate() function sets/gets buttons state.

Re: Enabl button on selection only

Posted: 06 Sep 2014 14:15
by U_2582
Thanks for the reply SammaySarkar.
Is it possible to have a balloon tip? Easier to dismiss than a msg.

Re: Enabl button on selection only

Posted: 06 Sep 2014 15:22
by bdeshi
Can you be more specific about what you want to do?

Here's a demo button script. Set as the LClick script of a button.
The button's hover tooltip changes depending on current selection.
If you select some files and click the button, it's tooltip says " something selected". Otherwise it says "nothing selected".

Code: Select all

if (get(selectedItemsNames) == "") {ctbname("nothing selected")} else {ctbname("something selected")}
Remember, you still do need to click the button to update the tooltip!

BTW, I'm sure you know it's also possible to construct a button script in a way that it executes only if some items are selected, eliminating the need to disable/enable the button.

Re: Enabl button on selection only

Posted: 06 Sep 2014 15:52
by U_2582
Actually I just started scripting in XYplorer, its very useful.
At the moment I'm checking on top of my script to see if something is selected or not, like this...

Code: Select all

end ($p_selCount == 0), "Nothing selected in the file list.";
But that requires one more click to get rid of the msg, I tried the status bar, not obvious enough.
That's why I asked about the balloon tip, they are customizable, icon, title, sub text and timer, and clicking it or anywhere else will dismiss it.
Your example is using a tooltip.

Re: Enabl button on selection only

Posted: 06 Sep 2014 16:44
by highend
Balloon tips aren't supported you'd need an external tool to display them...

Re: Enabl button on selection only

Posted: 06 Sep 2014 17:19
by klownboy
Like both Sammay and highend stated tooltips are not supported but you can as Sammy mentioned use CTBname and also use CTBstate and CTBicon to indicated different states. Just as an example, try this code. Type ::snippet; in the AB and then past the following snippet in the box.

Code: Select all

Snip: CTB 1
  XYplorer 14.40.0304, 9/6/2014 11:17:16 AM
Action
  NewUserButton
Name
  Please select files first
Icon
  :nuke
ScriptL
  $file_sel = get(selecteditemspathnames, "<crlf>");
      if($file_sel != "") {
       ctbstate(1,);
       ctbname("Files selected",);
       ctbicon("label: yes >554433,ffffee",);   //use any icon you'd like here
       echo $file_sel;                          // you could do whatever you'd like to the selected files
    }
      else {ctbstate(0,);
    ctbicon("label: No >554433,ffffee",);    //use any icon you'd like here to reflect a different state
    ctbname("No files selected",);
    echo "No files selected.";               // you could prompt user via na SC input to select files
    ctbname("Please select files first",);
    }
    ctbicon(:nuke,);
    ctbname("Please select files first",);
    ctbstate(0,);
  
ScriptR
  
FireClick
  0

Re: Enabl button on selection only

Posted: 06 Sep 2014 21:07
by bdeshi
highend wrote:Balloon tips aren't supported you'd need an external tool to display them.
winapiexec should fit the bill nicely...

Re: Enabl button on selection only

Posted: 07 Sep 2014 12:19
by PeterH
You can try with popupmenu, showing the wanted text, and executing just "End 1;"
Next Stmt "End 1;", too.

If you click the text, the 'menu' vanishes.
If you click outside: it vanishes too.

Re: Enabl button on selection only

Posted: 07 Sep 2014 15:50
by U_2582
Thanks for the help guys :)
popupmenu is the best solution for now, is it possible to add an icon to it?

Re: Enabl button on selection only

Posted: 07 Sep 2014 22:28
by klownboy
U_2582 wrote: is it possible to add an icon to it?
Not that I'm aware of...popupmenu has no icon options.

Re: Enabl button on selection only

Posted: 08 Sep 2014 04:35
by bdeshi
You can try this:

Code: Select all

 if ($p_selCount == 0/*1:typo*/){
  load <<<#>>>>
  "Nothing selected in filelist|<xyicons>\scheme\crosss.ico" end 1;<crlf>""#>>>>,,s; end 1;
 }
use a valid icon path.

Re: Enabl button on selection only

Posted: 08 Sep 2014 13:25
by klownboy
Very clever Sammay. :appl: In this case so as to match the statement, shouldn't $p_selCount = "" not "1", if you're using something like $p_selCount = get("selectedItemsNames");

Re: Enabl button on selection only

Posted: 08 Sep 2014 14:15
by U_2582
Nice SammaySarkar, only glitch is that I'm getting an extra separator in the popupmenu.
Also can I define icon size for the popupmenu? 24, 32 etc

Re: Enabl button on selection only

Posted: 08 Sep 2014 16:42
by bdeshi
Thanks, Ken!
Thanks, Ken, that would be a devastatypo. :oops: I edited the script to match the snippet U_2 had posted, but missed the if.

U_2, the separator is a necessary evil dummy.
Otherwise the menu has a single member, it's selected automatically, and the menu isn't displayed at all. Which defeats the main purpose here.

Also you can't resize those icons.