The following scripts and buttons will give you a multifunction recycle bin button... (see attachments below)
Left-click goes to recycle bin
Right click empties recycle bin and updates button icon to empty recycle bin icon. (Optionally plays empty recycle bin wav file)
The TestBin script fires on OnActivateLister. It checks the state of the recycle bin and updates the button icon whenever the lister gets activated.
This script is necessary if you delete from windows explorer or other third party programs or if you empty the recyclebin from other locations other than Dopus
Bins icon set:
This is just a small icon set containing only the icons for the recycle bin
How to install:
Drag and drop the script into the scripts section in preferences.
I tried your kit, because I don't actively use the recycle bin at all and was curious what it would offer.
I played around with it, had some problems and now some suggestions and thoughts to improve on it. o)
The script should not count all items in the bin. I had 4000 items in there and this caused a noticeably delay when opening a lister, so just exit the loop after the first increment or test for the .count/.length property of the items collection, wether to set the variable.
I think you should use a sensible name for the var instead of "TestVar", what about "Script.RecycleButton" or something?
I think there's no need to use a persistent variable
The button code modifiers you use in the script, probably have no effect, that toggle thing at least hasn't. You should make use of DOpus.Vars.Set("Script.RecycleButton","isFull"); instead of using button modifiers to create variables.
The Button has no icon for me, in case the recycle bin is empty/has been emptied.
The button icon is not automatically updated to reflect changes or new items in the bin.. and you cannot do a thing about it, I know. o)
Will definately change that... I kept creating a new textfile or folder, then delete it while I was trying to get it to work, so with only one or two items in the bin I had no delays, but I can see how this would cause a delay.
I used the persistant variable before I created the script that runs onnewlister, so yes, I will change that also.
From the documentation I thought I needed it to refresh the button to show the new button icon, but I just tested it without @toggle:update and you are right...not needed.
That's weird as I copied my own button from the toolbar and it works for me.
If a file or folder gets deleted in explorer or a thrid party app the button will not update until you start a new lister. It should update immediately though if you delete from a dopus toolbar button that updates the variable.
Anyway, thanks, I appreciate the feedback. Still struggling with the scripting engine, but I am slowly but surely starting to see more and more possibilities the more I get to use. I will work on your suggestions, however, for the more experienced coders in the community, please feel free to tweak the code and post your revisions here
I checked, you still have absolute paths in that button. Not every icon is linked to the icon set, that's why the "empty bin" and the image for "emptying the bin" don't show for me. You really need to speak to the quality assurence about this. o)
Did you change the button code, so it checks for "Script.RecycleButton" instead of "TestVar" ?
Now as I write this, my initial suggestion for the variable name "Script.RecycleButton", is kind of nonsense. o) Maybe you change the variable name again to "Script.RecycleBin", "Script.RecycleBinStatus", "Script.CheckRecycleBin" or somehing else making more sense. A proper name just helps to find out where a variable came from and that your code does not interfere with things other people have created ("TestVar" was a good example on how to not name these things o).
It should work with that line as well, you just need to make sure to correctly use "Script.RecycleButton" as variable name in your buttons, including the "Script." part, as it is part of the variable name and not something to be omitted when used in a button or elsewhere.
If the recycle bin is full and you empty it at another place (e.g. using the context menu of the desktop icon) the icon will not update. You should add something like this at the end:
If BinCount > 0 Then
dim objCmd : Set objCmd = DOpus.NewCommand
Set objCmd = Nothing
Instead of Function OnOpenLister(openListerData) I'm using Function OnActivateLister(ActivateListerData). This updates the icon more easily if something was deleted outside DOpus by e.g. toggleing source/dest.
@kundal, thanks for the feedback. I have updated the script to work on Function OnActivateLister(ActivateListerData). This has the added advantage that the icon is imediately updated if you delete via the context menu as well. I have also implemented all of @tbone's suggestions.
I have quickviewplus installed, but whether you have it or not, I find it way quicker to open a variety of files in the viewer rather than its registered program.
To do that, I edit the double-click event for the filetype and let it run the custom command ShowInViewerPane.
It also changes some layout settings that makes it easier for me to select another file to view in the viewer.
I removed some unnecessary lines from your script and made some minor changes:[code]option explicit
' This is a script for Directory Opus.
' See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
' Called by Directory Opus to initialize the script
initData.name = "TestBin"
initData.desc = "Updates the recycle bin button"
initData.copyright = "goselito on 01/09/2014"
initData.version = "1.2"
initData.default_enable = True
' Called when a Lister is activated
Const RECYCLE_BIN = &Ha&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(RECYCLE_BIN)
If objFolder.Items.Count > 0 Then
DOpus.vars.Set "Script.RecycleButton", "isFull"
Thanks for showing the ShowInViewerPane-thing, unfortunately it does not what I was looking for, but thanks alot! o)
(Maybe you should clear that post to not unnecessarily mix this thread up? Additionally I suggest removing all script snippets once this reaches a usable state.)
Another thought: Think about people not using the recycle-bin (they might have disabled it completly), how is your script going to handle that, I'd expect it to throw an error, don't know for sure. But Set objFolder = objShell.Namespace(RECYCLE_BIN) could fail then, so there's room for some "on error goto " stuff I guess. You probably also could switch to a "recycle-bin" disabled icon! Huh? o))
Wonder though, why is it actually important for you, to see that there are items in the bin? I normally don't care at all. o)