How to Set Ratings

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
ag346
Posts: 6
Joined: 14 Nov 2017 11:36

How to Set Ratings

Post by ag346 »

Are there any other options available for editing a file's rating other than right-clicking in the ratings column?
If you select the small tiles or thumbnail views, there doesn't seem to be a way to set the rating other than changing the view first.

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: How to Set Ratings

Post by highend »

A script would work (please save it with UTF-8 from an editor, otherwise the stars could
get lost! in the "Scripts" folder inside the XY data folder, as e.g.: Rating.xys) and load it from
a button on the toolbar or via a user defined command (and a belonging keyboard shortcut)...

The code for a button to load the script could be:

Code: Select all

::load "Rating";
user button.png
user button.png (7.19 KiB) Viewed 2757 times
YOU NEED TO ADAPT the $column variable in the script to reflect the ex1-ex5 column you
are using!

Code: Select all

    $column = "ex1"; // The "extra" column used
    $empty  = chr(13);
    $rating = <<<>>>
        $empty
        ★
        ★★
        ★★★
        ★★★★
        ★★★★★
>>>;
    $rating = regexreplace($rating, "^[ ]*");
    $index  = popupmenu($rating, , , , , 1, <crlf>, , 0);
    if ($index == 0) { end true; }
    elseif ($index == 1) { tagitems($column, ""); } // Empty rating
    else { tagitems($column, $index - 1); } // Rating 1 - 5
One of my scripts helped you out? Please donate via Paypal

ag346
Posts: 6
Joined: 14 Nov 2017 11:36

Re: How to Set Ratings

Post by ag346 »

Thanks for your help, although I think I am doing something wrong. I'm new to scripting, but I was able to follow the example in the help file listed under scripts:

// some little test scripts
"Go to C:\"
goto "C:\"
"Go to System Folder"
goto "%winsysdir%"
"Go to XYplorer Folder"
goto "<xypath>"

My ratings column is called Rating and I used the first extra column. I tried renaming the example you gave to $column = "Rating"; // The "extra" column used
Attachments
ratingScript.png
ratingScript.png (31.35 KiB) Viewed 2733 times

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: How to Set Ratings

Post by highend »

You removed the indentation in the script code that I posted.
Because of this you get the output that you see in your
screenshot. Try to copy and paste the code into your
editor again and don't mess with the indentation this time :mrgreen:

You can leave the $column variable as it is, it already uses the
first extra column.
One of my scripts helped you out? Please donate via Paypal

jupe
Posts: 2788
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: How to Set Ratings

Post by jupe »

@highend I hope you don't mind me posting this but because I'd modified your posted script for myself to make a few changes that suit my use case better, I thought I might share it, my scripting skills are still in their development stage so use my version at your own peril, but I haven't had any problems while using it. All credit goes to @highend for his initial work.

I think I am a little OCD because I like my stars to go from 5 down to 0 like how they are arranged when using the actual column to set ratings, instead of the opposite way round, so I modified @highends code to behave like this and also to display a check mark when you have a previous rating already set as well as an extra empty item to clear the rating that only displays when there is already a rating set.
rating.png
rating.png (947 Bytes) Viewed 2652 times
rating_sel.png
rating_sel.png (1.17 KiB) Viewed 2652 times
As explained in the post above this and still applicable here you may need to adjust the $column variable to match the Extra column you are using for ratings, any of these are valid values ex1,ex2,ex3,ex4,ex5

Code: Select all

	$column = "ex:Rating"; // ############ SET THIS VALUE ############
	$rating = <<<>>>
★★★★★
★★★★
★★★
★★
★
>>>;

	$tag = tagitems($column);

	if ($tag Like "#" && $tag <= 5) {
		$result = "";
		foreach ($line, $rating, <crlf>) {
			if ($tag == strlen($line)) {
				$result = $result . $line .  ";;;2<crlf>";
			} else {
				$result = $result . $line . <crlf>;
			}
		}
		$rating = $result . <crlf> . chr(13);
	}
	
	$index  = popupmenu($rating, , , , , 1, <crlf>, , 0);

	switch ($index) {
		case "0":
			end true;
		case "1":    
			tagitems($column, 5);
			break;
		case "2":    
			tagitems($column, 4);
			break;
		case "3":    
			tagitems($column, $index);
			break;
		case "4":    
			tagitems($column, 2);
			break;
		case "5":    
			tagitems($column, 1);
			break;
		case "6":    
			tagitems($column, "");
			break;
		}
Last edited by jupe on 16 Dec 2017 15:31, edited 1 time in total.

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: How to Set Ratings

Post by highend »

I hope you don't mind me posting this
Nope :mrgreen:

Maybe you should make a note that the user needs to name the column "Rating", otherwise
the script would find no tag entries...

In that case I would at least check if that column really exists:

Code: Select all

    if !(gettokenindex("Rating", setcolumns(, 64), ",", "")) {
        status "'Rating' column does NOT exist, aborted!", "8B4513", "stop"; end true;
    }
One of my scripts helped you out? Please donate via Paypal

ag346
Posts: 6
Joined: 14 Nov 2017 11:36

Re: How to Set Ratings

Post by ag346 »

Thanks to both of you for your help.

I'm not sure if this should go on a separate post or not but I just noticed that changing a file's rating does not update the modified time, but that seems to be across the board with any file operations done in xyplorer.

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: How to Set Ratings

Post by highend »

I just noticed that changing a file's rating does not update the modified time
Ofc it doesn't. The file itself isn't modified because this tag is written to the tag.dat database file...
but that seems to be across the board with any file operations done in xyplorer
That depends on the operation^^
One of my scripts helped you out? Please donate via Paypal

peptide
Posts: 31
Joined: 14 May 2011 14:34

Re: How to Set Ratings

Post by peptide »

Hi highend, hi jupe -

I tried to implement this with the expectation that it would tag items with numbers 1-5. It does add a number to the extra column that I named Rating, but it doesn't seem to create the tag entry that I expected it to. Should it create the same kind of tag entry that I would otherwise have done manually?

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: How to Set Ratings

Post by highend »

but it doesn't seem to create the tag entry that I expected it to
Where, in the tag.dat file?

If you mean this, did you save your tags (File - Settings Special - Save Tags) afterwards?
One of my scripts helped you out? Please donate via Paypal

peptide
Posts: 31
Joined: 14 May 2011 14:34

Re: How to Set Ratings

Post by peptide »

@highend -

Correct, it did not save to tag.dat and I didn't use the tag saving methodology you mentioned, but I have never had to with other tags.

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: How to Set Ratings

Post by highend »

Tags aren't saved immediately. Either you do it manually, have a necessary setting (still doesn't do it instantly) or exit the current instance (with saving settings)...
One of my scripts helped you out? Please donate via Paypal

peptide
Posts: 31
Joined: 14 May 2011 14:34

Re: How to Set Ratings

Post by peptide »

highend wrote:Tags aren't saved immediately. Either you do it manually, have a necessary setting (still doesn't do it instantly) or exit the current instance (with saving settings)...
I understand, but I usually just "save settings" to commit them and not the option that you used.

jupe
Posts: 2788
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: How to Set Ratings

Post by jupe »

I don't understand what you mean exactly, but if you want to save tags file to disk instantly when you are using one of the above scripts, just add this to the bottom of the script (with indentation):

Code: Select all

    #195;

peptide
Posts: 31
Joined: 14 May 2011 14:34

Re: How to Set Ratings

Post by peptide »

What I mean is that I'm clicking the disk icon ("Save Settings"), which saves all settings, correct?

I looked in the tag.dat file and the ratings (1-5) are making it into the file, but they're not being returned as result when I search by tag. Ideas?

Post Reply