Wow, that works pretty good. I tested it with a few edge cases. I had to add the '-' to your regular expression so that it would decrement beyond 0.highend wrote:Btw, one way to reduce the necessary tagitems calls:
It builds a list of ratings for all files and then filters it and goes only over all ratings that need to changeCode: Select all
// Decrement stars by one $list = ""; foreach($item, <get selecteditemspathnames |>) { $tag = tagitems(1, , $item) - 1; if ($tag < -1) { $tag = -1; } if (!$tag) { $tag = ""; } $list = $list . $tag . "|" . $item . <crlf>; } foreach($rating, formatlist(regexmatches($list, "^[0-9.,]+"), "des")) { $matches = regexmatches($list, "^$rating\|.*?(?=\r?\n)"); $matches = regexreplace(formatlist($matches, "des"), "^$rating\|"); tagitems(1, $rating, $matches); } #485; // Refresh list
So even if you would use it on 1000 files and e.g. you've only given 3 and 5 stars, tagitems would only
be called two times (one time for 3 and one time for 5)
regexmatches($list, "^[0-9.,-]+"), "des")
Also, it doesn't work when the highlighted items include a file with a rating of 1 and another file with a rating of -1. The rating 1 file doesn't decrement.
But, the speed improvement is excellent!