Page 1 of 1

Quick Folder View Settings

Posted: 20 Nov 2015 21:21
by highend
This one is about getting a specific folder view depending on how many files of one / multiple types are in the current directory...

There are only two variables to modify:

$percent = The value for how many files (as a percentage of all files) at which a folder view get's activated
$types = The lines that define the view mode and the extensions that have to match

The view mode is separated from the extensions via a bar character "|" and the extensions are delimited via a semicolon.
You can use the XY internal general file types here!
These currently are:
{:Text};{:Image};{:Photo};{:Audio};{:Video};{:Media};{:Font};{:Vector};{:Web};{:Office};{:Archive};{:Executable}

Put this script in a user defined command and execute it e.g. from a user defined button or a keyboard shortcut...

Code: Select all

// === CONFIGURE VARIABLES #BEGIN ===

    $percent = 26;

    $types = <<<>>>
// View command | Extensions
#302|*.doc;*.txt;{:Office}
#306|*.jpg;*.png;*.tiff
>>>;

// === CONFIGURE VARIABLES #END =====

/*
    {#View}                         | Command
    =========================================
    0 = Details                     |    #302
    1 = Details with Thumbnails #1  |    #303
    2 = List                        |    #304
    3 = Small Icons                 |    #305
    4 = Thumbnails #1               |    #306
    5 = Thumbnails #2               |    #307
    6 = Thumbnails #3               |    #308
    7 = Large Icons                 |    #309
    8 = Small Tiles                 |    #313
    9 = Large Tiles                 |    #314

    Generic file type "variables"
    =============================
    {:Text}
    {:Image}
    {:Photo}
    {:Audio}
    {:Video}
    {:Media}
    {:Font}
    {:Vector}
    {:Web}
    {:Office}
    {:Archive}
    {:Executable}
*/

    $files      = listpane(, , 1+4);
    $filesCount = gettoken($files, "count", "|");
    $types      = regexreplace($types, "^//.*\r?\n");
    $curView    = get("View");

    if !($filesCount) { status "No file(s) in current directory, no view change necessary!", "8B4513", "stop"; end 1==1; }

    $command = "";
    foreach($entry, $types, "<crlf>", "e") {
        $extensions = gettoken($entry, 2, "|");

        if (strpos($extensions, "{") != -1) {
            $resolvedExtensions = "";
            foreach($ext, $extensions, ";", "e") {
                if (regexmatches($ext, "\{:[a-z0-9]+}")) { $resolved = get("genericfiletype", $ext, ";"); }
                else { $resolved = $ext; }
                $resolvedExtensions = $resolvedExtensions . $resolved . ";";
            }
            $extensions = $resolvedExtensions;
        }
        $extensions = formatlist($extensions, "sde", ";");

        $typeCount = gettoken(formatlist($files, "f", , replace($extensions, ";", "|"), "f"), "count", "|");
        if (($typeCount / ($filesCount / 100)) < $percent) { continue; }
        $command = gettoken($entry, 1, "|");
        break;
    }

    if ($command) {
        if ($command == "#302" && $curView ==  0 ||
            $command == "#303" && $curView ==  1 ||
            $command == "#304" && $curView ==  2 ||
            $command == "#305" && $curView ==  3 ||
            $command == "#306" && $curView ==  4 ||
            $command == "#307" && $curView ==  5 ||
            $command == "#308" && $curView ==  6 ||
            $command == "#309" && $curView ==  7 ||
            $command == "#313" && $curView ==  8 ||
            $command == "#314" && $curView ==  9) {
            status "No view change necessary!", "8B4513", "stop"; end 1==1;
        }
        load "$command", , "s";
    }

Re: Quick Folder View Settings

Posted: 20 Nov 2015 21:28
by highend
<reserved>

Re: Quick Folder View Settings

Posted: 21 Nov 2015 10:20
by huyaowen
RRR.jpg
RRR.jpg (36.86 KiB) Viewed 4358 times
This error may ocurred when only folders exists.

btw,click this custom button just change the view between list and thumbnail.

Re: Quick Folder View Settings

Posted: 21 Nov 2015 10:48
by highend
This error may occurred when only folders exists.
I've added a check to take that into account -> It ends when only folders exist in the current folder
btw,click this custom button just change the view between list and thumbnail.
You mean that it toggles the view? I've added a check for that as well

Re: Quick Folder View Settings

Posted: 22 Nov 2015 20:16
by highend
So, does it work now?

Re: Quick Folder View Settings

Posted: 23 Nov 2015 02:06
by huyaowen
thanks.
I use a custom button for the script.then,how this button works automatically?

Re: Quick Folder View Settings

Posted: 23 Nov 2015 03:33
by highend
?

This thread is called "Quick..." not "Auto..."
xy doesn't support automatic events (internal name "custom event actions") yet...

Re: Quick Folder View Settings

Posted: 23 Nov 2015 07:25
by huyaowen
Thanks anyway