Requires Directory Opus 12 or above.
Overview:
This script-button shuffles the files and folders in the tab into a random order each time you click it.
Files and folders are mixed together.
Right-clicking the button resets things back to normal.
You might use this for generating music playlists, or similar.
Installation:
Download Shuffle.dcf, enter Settings > Customize mode, and drag it to a toolbar. Then click OK in the Customize window.
(For more detailed instructions: How to use buttons and scripts from this forum)
- Shuffle.dcf (2.75 KB)
History:
- 1.0 (04/Sep/2016): Initial version.
Script code:
The script code from the download above is reproduced below. This is for people browsing the forum for scripting techniques. You do not need to care about this code if you just want to use the script.
function OnClick(clickData)
{
var vecNewOrder = DOpus.Create.Vector();
vecNewOrder.reserve(clickData.func.sourcetab.all.count);
for (var eItems = new Enumerator(clickData.func.sourcetab.all); !eItems.atEnd(); eItems.moveNext())
{
vecNewOrder.push_back(eItems.item().name);
}
var currentIndex = vecNewOrder.size;
var temporaryValue;
var randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex)
{
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
vecNewOrder.exchange(currentIndex, randomIndex);
}
clickData.func.Command.RunCommand("Set MANUALSORT=On");
var sortOrder = clickData.func.sourcetab.format.manual_sort_order;
sortOrder.SetOrder(vecNewOrder);
clickData.func.Command.RunCommand("Select FIRST SETFOCUS");
clickData.func.Command.RunCommand("Select SHOWFOCUS");
clickData.func.Command.RunCommand("Select NONE");
}
The right-click action runs a simple non-script command:
Set MANUALSORT=off
Select FIRST SETFOCUS
Select SHOWFOCUS
Select NONE