In a previous beta we got get("list_recentlocations") command, so I was able to develop this missing feature. I think it can be interesting for other people, because it shows how a script can change itself during running. It can pretend for example a toggle button, which can change its state on clicking.
Preparations:
1. The script name have to be copy_recent.xys in the general Scripts folder.
2. Make a new user button, the On Click event should be: load "copy_recent", "_loadrec"; load "copy_recent" The first command creates the recent menu, the second shows the menu for us.
Usage:
If you click this new user button, the first row of the menu shows the operation type. If you click on that, the operation will change from Copy to Move and vica versa. If you click on a folder below, the files selected on the list panel will be copied or moved to that recent location, according to the operation in the first menu row.
Code: Select all
"_loadrec"
$limit = 15;
$sfile = readfile("<xydata>\Scripts\copy_recent.xys");
// the sript remains the same before the separator
$sfile = SubStr($sfile, 0, StrPos($sfile,'"-"', -1) + 3) . "<crlf>";
$mostrecent = get("list_recentlocations");
$i = 1;
$ownrecent = "";
// the limit contains the max number of the recent folders
while ($i <= $limit) {
// The first recent folder is the actual one. So have to start with the second folder.
$path = gettoken ($mostrecent, $i+1, "<crlf>");
if ($path != "") {
// creating the command which will execute the copy or move command.
$ownrecent = $ownrecent . '"' . $path . '|:copyto" if (get("CountSelected") > 0) { copyto "' . $path . '" } else { status "Nothing is selected!", , "alert" }';
$ownrecent = $ownrecent . "<crlf>";
}
$i++;
}
// sorting the recent folders
$ownrecent = formatlist($ownrecent,"se","<crlf>");
// attach the recent folders to the end of the script, after the separator
$sfile = $sfile . $ownrecent;
// write the script back to the original script file
writefile("<xydata>\Scripts\copy_recent.xys", $sfile, "o");
"Operation: COPY|:nuke"
$sfile=readfile("<xydata>\Scripts\copy_recent.xys");
if ( StrPos($sfile, "Operation: " . "COPY") == -1) {
// change the operation label, it will seem as a toggle button
$sfile=replace($sfile, "Operation: " . "MOVE", "Operation: " . "COPY", , , 1);
// change the commands
$sfile=replace($sfile, " mo" . "veto ", " co" . "pyto ");
//change the icons of recent folders
$sfile=replace($sfile, "|:c" . "ut", "|:co" . "pyto");
}
else {
// change the operation label, it will seem as a toggle button
$sfile=replace($sfile, "Operation: " . "COPY", "Operation: " . "MOVE", , , 1);
// change the commands
$sfile=replace($sfile, " co" . "pyto ", " mo" . "veto ");
//change the icons of recent folders
$sfile=replace($sfile, "|:co" . "pyto", "|:c" . "ut");
}
// write the script back to the original script file
writefile("<xydata>\Scripts\copy_recent.xys", $sfile, "o");
"-"
XYplorer Beta Club