How to do conditional formatting?

Started by ChrisMatch, December 22, 2013, 10:08:30 PM

Previous topic - Next topic

ChrisMatch

Hi

I just tried to show the extension in the thumbnail view in different colours for different types of files.
E.g. I want to show NEF files with a red 'NEF extension' and MOV files with the extension MOV shown in blue and so on.

I have tried something like this:
{File.Ext|is:NEF,{File.Ext|prefix:<Run FontSize='8pt' Foreground='#EE2020'>.;postfix:</Run>},some_other_formatting}

Maybe I miss something obvious - but maybe those nested expressions are not possible?

Any idea how to achieve a conditional formatting?

Thanks
Chris

JohnZeman

I've done quite a bit experimenting with various conditional formatting possibilities but I don't recall any way to do what you want to do.

Mario

This was a challenging one. I first thought it could not be done because you cannot nest variables that way (e.g. in prefixes). But if you think the other way, you'll end up with this:

<Run Foreground='{File.Ext|is:nef,#ff5050,#50ff00,false}'>{File.Ext}</Run>

This colors the extension differently for NEF files. Use this as a start.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ChrisMatch

thanks, for taking the time to have a look at it  :)
and of course for finding a solution

Chris

PS:
slowly but surely I should start preparing for Christmas
and stop playing around with iMatch ;)

Mario

I'm all prepped. Just a few more gifts to wrap and then it's full house until the weekend...  :)
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Ferdinand

This is neat, but try as I might, and reading the help as many times as I might, I can't generalise this to more than one tested filetype and more than two colours.  Can it be done?

Mario

#6
There are limits of what can be done with variables. I don't know what you tried, but you cannot nest variables in elements like prefix or something. You can nest variables in general, but not in formatting functions.

Variables are vital for many performance-critical features in IMatch. I always have to keep the balance between power of use and speed. Nesting variables in formatting functions would make things way more complicated internally and would be a performance killer. And I doubt that many users will ever try that, anyway.

Maybe a HTML template or App for the App Panel is better suited for such purposes. Here you can do almost everything you want using a mix of HTML and JavaScript. Doing conditional formatting is easy in an App.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Ferdinand

Pity.  This is something (the ability to colour the file extension) that I would find really useful.  It would free up category colours to be used for something else.

Mario

If you find this useful, why not file a feature request. If many users would like to have this, I'll look into it for a later release.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ChrisMatch

#9
Quote from: Ferdinand on December 24, 2013, 09:39:47 AM
This is neat, but try as I might, and reading the help as many times as I might, I can't generalise this to more than one tested filetype and more than two colours.  Can it be done?
Since Mario suggested a solution I am trying to get it to work with more than two colors.

The best working solution I have found is this:
<Run Foreground='{File.Ext|is:nef,#FFD700,#FFFFFF,false}'>{File.Ext|is:nef,.NEF, ,false}</Run>
<Run Foreground='{File.Ext|is:jpg,#ADFF2F,#FFFFFF,false}'>{File.Ext|is:jpg,.JPG, ,false}</Run>
<Run Foreground='{File.Ext|is:jpeg,#ADFF2F,#FFFFFF,false}'>{File.Ext|is:jpeg,.JPEG, ,false}</Run>
<Run Foreground='{File.Ext|is:mov,#FF4040,#FFFFFF,false}'>{File.Ext|is:mov,.MOV, ,false}</Run>
<Run Foreground='{File.Ext|is:mp3,#00BFFF,#FFFFFF,false}'>{File.Ext|is:mp3,.MP3, ,false}</Run>

But there are two disadvantages:
1) you have to define EVERY extension (no default color for other extensions)
2) every step adds another space because I found no way to return nothing (an empty string)
(maybe this can be solved)

Then I found an example of a nested variable in the help:
{File.Label|is:Final,Finished: {File.Modified|format:YYYY-MM-DD}}
I tried to use the idea like this:
<Run Foreground='{File.Ext|is:nef,#FFD700,{File.Ext|is:MOV,#ADFF2F,#FFFFFF,false},false}'>.{File.Ext}</Run>
BUT unfortunately this does not work (not sure why).

Maybe someone of you can find the flaw
or Mario can confirm that this is no valid approach.


Ferdinand

I think you might have cracked it!  Thanks!!

Regarding recursion, above Mario said "You can nest variables in general, but not in formatting functions".  In any case, I think your formulation is easier to deal with and code than a recursion.

Ferdinand

p.s.  Worked like a treat, with one exception.  While having each run command on a new line might make it easy to edit and read, you want one long line for avoid formatting irregularities (like extra spaces at the end leading to alignment issues).

Mario

Quote2) every step adds another space because I found no way to return nothing (an empty string)
That was a glitch. Fixed for the next build. An empty string should be possible.


QuoteI tried to use the idea like this:
<Run Foreground='{File.Ext|is:nef,#FFD700,{File.Ext|is:MOV,#ADFF2F,#FFFFFF,false},false}'>.{File.Ext}</Run>
BUT unfortunately this does not work (not sure why).
Maybe someone of you can find the flaw

You cannot nest variables within formatting functions like "is".
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ChrisMatch

QuoteThat was a glitch. Fixed for the next build
Nice, now we have two relatively simple ways of doing it.
Not perfect, but astonishing how iMatch can fulfil feature request before the even got reported  :)