WFX custom icons update

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
Korney San
Junior Member
Junior Member
Posts: 19
Joined: 2011-10-13, 11:42 UTC
Location: Belarus, Gomel

WFX custom icons update

Post by *Korney San »

I'm set some custom fields and custom icons to my files in WFX plugin.
On data change I modify custom field value (returned by FsContentGetValue) and custom icon handle (returned by FsExtractCustomIcon in TheIcon), then call cm_rereadsource.
The field is updated and the icon is not. If I try to exit plugin and enter it back, the file has proper (updated) icon.

Is this default TC behaviour or another my mistake?
Praemonitus praemunitus
User avatar
Flint
Power Member
Power Member
Posts: 3511
Joined: 2003-10-27, 09:25 UTC
Location: Belgrade, Serbia
Contact:

Post by *Flint »

Korney San
TC caches the icons and does not always request them from plugin. I met with this problem too, and worked it around by changing the modification date of the file entry and then calling cm_rereadsource.
Flint's Homepage: Full TC Russification Package, VirtualDisk, NTFS Links, NoClose Replacer, and other stuff!
 
Using TC 11.03 / Win10 x64
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Korney San, AFAIK TC doesn't ask for icons on refresh until you re-enter current folder. Also TC remembers pair <RemoteName, icon> (returned by you from FsExtractCustomIcon) in cache and doesn't change icon in cache if you return same RemoteName, so you should return another RemoteName in order to change icon. You may return any strings, not only filenames.

E.g. if you have a file \indicator and it may take 4 different icons indicating different modes, you may return \indicator/0, \indicator/1, \indicator/2 etc. in RemoteName so TC will show previously cached icons.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50840
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

MVV is right, TC uses the name returned by FsExtractCustomIcon to cache the icon. So if for example all .txt files have the same icon, you should return the same name to save memory (TC has to cache the icon only once then).
Author of Total Commander
https://www.ghisler.com
User avatar
Korney San
Junior Member
Junior Member
Posts: 19
Joined: 2011-10-13, 11:42 UTC
Location: Belarus, Gomel

Post by *Korney San »

Mmm, I need to update the state of file (i. e. icon) once per minute.
Here is a piece of code of FsExtractCustomIcon:

Code: Select all

    st:=ParseTagXML('state', s);
    case StrToIntDef(st, -1) of
     0, 1:
      begin
       TheIcon := CustomIcons[icPaused].Handle;
       StrCopy(RemoteName, CustomIcons[icPaused].Name);
       Result := FS_ICON_EXTRACTED;
      end;
     2:
      begin
       sv:=ParseTagXML('saveto', s);
       if FileExists(sv) then
        begin
         TheIcon := CustomIcons[icCompleted].Handle;
         StrCopy(RemoteName, CustomIcons[icCompleted].Name);
         Result := FS_ICON_EXTRACTED;
        end
       else
        begin
         TheIcon := CustomIcons[icCompletedNoFile].Handle;
         StrCopy(RemoteName, CustomIcons[icCompletedNoFile].Name);
         Result := FS_ICON_EXTRACTED;
        end;
      end;
     3:
      begin
       TheIcon := CustomIcons[icDownloading].Handle;
       StrCopy(RemoteName, CustomIcons[icDownloading].Name);
       Result := FS_ICON_EXTRACTED;
      end;
     4, 5:
      begin
       TheIcon := CustomIcons[icError].Handle;
       StrCopy(RemoteName, CustomIcons[icError].Name);
       Result := FS_ICON_EXTRACTED;
      end;
     6:
      begin
       TheIcon := CustomIcons[icQueue].Handle;
       StrCopy(RemoteName, CustomIcons[icQueue].Name);
       Result := FS_ICON_EXTRACTED;
      end;
     else
      begin
       TheIcon := CustomIcons[icMain].Handle;
       StrCopy(RemoteName, CustomIcons[icMain].Name);
       Result := FS_ICON_EXTRACTED;
      end;
     end;
Icons were not updated with it.
I change code as

Code: Select all

...
     0, 1:
      begin
       TheIcon := CustomIcons[icPaused].Handle;
       //StrCopy(RemoteName, CustomIcons[icPaused].Name);
       StrLCat(RemoteName, '/', MAX_PATH-1);
       StrLCat(RemoteName, CustomIcons[icPaused].Name, MAX_PATH-1);
       Result := FS_ICON_EXTRACTED;
      end;
...
     3:
      begin
       TheIcon := CustomIcons[icDownloading].Handle;
       //StrCopy(RemoteName, CustomIcons[icDownloading].Name);
       StrLCat(RemoteName, '/', MAX_PATH-1);
       StrLCat(RemoteName, CustomIcons[icDownloading].Name, MAX_PATH-1);
       Result := FS_ICON_EXTRACTED;
      end;
...
     6:
      begin
       TheIcon := CustomIcons[icQueue].Handle;
       //StrCopy(RemoteName, CustomIcons[icQueue].Name);
       StrLCat(RemoteName, '/', MAX_PATH-1);
       StrLCat(RemoteName, CustomIcons[icQueue].Name, MAX_PATH-1);
       Result := FS_ICON_EXTRACTED;
      end;
but icons are not updating yet.

What shall I do else?

P.S. I decide to leave files their native icons and make another field to display state of file, if I cannot solve this problem.
Praemonitus praemunitus
Post Reply