Enabl button on selection only

Discuss and share scripts and script files...
U_2582
Posts: 34
Joined: 05 Oct 2013 10:33

Enabl button on selection only

Post by U_2582 »

Just like open with toolbar button, how can I have a custom button enabled only when items are selected?

Thanks

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Enabl button on selection only

Post by bdeshi »

Scripted buttons cannot update themselves automatically. Sorry.
----
the ctbstate() function sets/gets buttons state.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

U_2582
Posts: 34
Joined: 05 Oct 2013 10:33

Re: Enabl button on selection only

Post by U_2582 »

Thanks for the reply SammaySarkar.
Is it possible to have a balloon tip? Easier to dismiss than a msg.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Enabl button on selection only

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

U_2582
Posts: 34
Joined: 05 Oct 2013 10:33

Re: Enabl button on selection only

Post 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.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Enabl button on selection only

Post by highend »

Balloon tips aren't supported you'd need an external tool to display them...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Enabl button on selection only

Post 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

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Enabl button on selection only

Post by bdeshi »

highend wrote:Balloon tips aren't supported you'd need an external tool to display them.
winapiexec should fit the bill nicely...
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Enabl button on selection only

Post 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.

U_2582
Posts: 34
Joined: 05 Oct 2013 10:33

Re: Enabl button on selection only

Post by U_2582 »

Thanks for the help guys :)
popupmenu is the best solution for now, is it possible to add an icon to it?

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Enabl button on selection only

Post 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.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Enabl button on selection only

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: Enabl button on selection only

Post 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");

U_2582
Posts: 34
Joined: 05 Oct 2013 10:33

Re: Enabl button on selection only

Post 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

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Enabl button on selection only

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply