1.8.8 - Filelist sort order not reflected in browser

Bugs which have been reproduced by a second user or the developer, or features to do

Moderators: helmut, XnTriq, xnview, Dreamer

Post Reply
Neuro-NX
Posts: 24
Joined: Wed Aug 31, 2022 9:38 pm

1.8.8 - Filelist sort order not reflected in browser

Post by Neuro-NX »

Expected Outcome

When a FILELIST is loaded from a text file. I expect the files to be sorted, as it appears in my filelist.txt.

This seems logical, as a filelist is a "curated" list. Similar to a sorted bookshelf, that may be sorted according to "theme", "topic", "author" etc. Users may want to sort their files according to their own use case. In which case using a filelist should support that.

The program should therefore respect the users choice of file order.

The "Sort by" value should not be affected or changed! There should instead be separate logic, to understand that, If a filelist is loaded, then the images would be indexed according to the line number in the text file. The program would then reflect this index order in the browser.

UNTIL (event change)

A) the FILELIST window is closed.
B) the user changes the "Sort by" type.

My filelist.txt:

Code: Select all

"/home/user/colors/1.png"
"/home/user/colors/3.png"
"/home/user/colors/2.png"
"/home/user/colors/5.png"
"/home/user/colors/4.png"
"/home/user/colors/6.png"
Actual Outcome

The browser does not match the sort order in my filelist.txt. The files are sorted using the last selected sorting from the "Sort by" toolbar menu.

I generated 6 example PNG images, to explain my point. See FIG1.

I want the images sorted according to my own order, specified in the filelist.txt => 1, 3, 2, 5, 4, 6.

FIG 1
Shows loaded filelist *not* sorted according to filelist.txt
Shows loaded filelist *not* sorted according to filelist.txt
Screenshot_2025-05-25_22-27-21.png (208.56 KiB) Viewed 361 times
Suggestion for Bug Fix:
  1. Add Settings Option:

    Add option in Settings to globally set whether to match the sort order from wtihin the filelist FILE.

    FIG 2
    BUG FIX: Add option to match sort order in filelist
    BUG FIX: Add option to match sort order in filelist
    Screenshot_2025-05-26_00-47-04.png (215.52 KiB) Viewed 358 times
  2. Add Command-line Option:

    If the settings option "Keep same order in filelist file" is not enabled (unchecked).

    Provide another method. The user can pass a command-line option, when loading a filelist. For example "-keep-order".

    Code: Select all

    xnviewmp -filelist filelist.txt -keep-order
    
    FIG4
    Arg -keep-order for -filelist option
    Arg -keep-order for -filelist option
    Screenshot_2025-05-27_13-27-46.png (131.55 KiB) Viewed 262 times
Last edited by Neuro-NX on Tue May 27, 2025 2:42 pm, edited 2 times in total.
User avatar
user0
XnThusiast
Posts: 2410
Joined: Sat May 09, 2015 9:37 am

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by user0 »

Neuro-NX wrote: Sun May 25, 2025 11:43 pm When a FILELIST is loaded from a text file. I expect the files to be sorted, as it appears in my filelist.txt.
I disagree
I see no difference in opening folder/search_results/filelist/etc, so all of them should follow current 'Sort by' option.
However, if opened via console - arguments may change sort order (but it should be indicated in 'Sort by' menu as well)

Neuro-NX wrote: Sun May 25, 2025 11:43 pm Suggestion for Bug Fix:
  1. Add Settings Option:
    Add option in Settings to globally set whether to match the sort order from wtihin the filelist FILE.
  2. Add Command-line Option:
    If the settings option "Keep same order in filelist file" is not enabled (unchecked).

    Provide another method. The user can pass a command-line option, when loading a filelist. For example "-keep-order".

    Code: Select all

    xnviewmp -filelist filelist.txt -keep-order
    
I doubt any extra option is required in Settings.
Maybe new 'Source' option in 'Sort by' menu (as this is the place where all sort options exist)
Neuro-NX
Posts: 24
Joined: Wed Aug 31, 2022 9:38 pm

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by Neuro-NX »

user0 wrote: Mon May 26, 2025 2:56 pm
Neuro-NX wrote: Sun May 25, 2025 11:43 pm When a FILELIST is loaded from a text file. I expect the files to be sorted, as it appears in my filelist.txt.
I disagree
filelist must be sorted as per app's existing 'Sort by' setting
Yes. By default, it should be sorted as per the "Sort by" configuration setting values.

Code: Select all

[Browser]
sort=INT
sortNameMethod=INT
sortOrder=INT
My suggestion is to introduce a new option to override the default behaviour, using a globally set option.

Refer to FIG2 image.
user0 wrote: Mon May 26, 2025 2:56 pm I doubt any extra option is required in Settings
I explained my rationale and reasoning behind my user expectation. Which is that.

1. what the program refers to as a "Filelist" is a compiled or indexed record of files that is user created.
2. Like an analogy to a sorted bookshelf or managed database
3. that sorts items according to a user defined "heuristic".
4. Therefore, the program should match the same file order.
5. => IF <= the user specifically enabled a globally set option in Settings "Keep same order in filelist file".

Maybe I should have been more explicit.
user0 wrote: Mon May 26, 2025 2:56 pm However, if opened via console - arguments may change sort order (but it should be indicated in 'Sort by' menu as well)
The problem is not every user will know to use the command-line. Or may decide NOT to use the command-line and prefer to use a GUI.

So it should not be the only way to enable this feature. It should be an alternative option.

The reason for adding an argument option "-keep-order" for the command-line. Is to cover the edge-case, where => IF <= the globally set Settings option "Keep same order in filelist file" is unchecked. Users can still apply the option using the command-line.

The command-line option "-keep-order" is important to include in this bug fix or revision. As it allows users like me to perform file sorting operations in the terminal, then generate the output file paths into a compiled FILELIST file. So it's critical, for my use case, that the order of the files in the FILELIST is reflected in browser because I want to use it as part of my automation workflow.

Use Case:

1. I wrote a python script that uses "ffprobe" to find videos in a directory based on it's EXIF metadata. And print the absolute path of the file.
2. I sort the videos based on some TYPE, that is not provided in the "Sort by" list. Such as EXIF tag "bit_rate" or "r_frame_rate".
3. I output the file paths to a FILELIST.
Notice the order is not alphabetical or numerical starting from the first character of the filename. But numerically, based on the framerate value.

Code: Select all

"/path/video1-24.mp4"
"/path/video2--24.mp4"
"/path/video1-30.mp4"
"/path/video1-60.mp4"
In XnView MP browser. It would currently show like this. Which is NOT what I want.

Code: Select all

"/path/video1-24.mp4"
"/path/video1-30.mp4"
"/path/video1-60.mp4"
"/path/video2--24.mp4"
user0 wrote: Mon May 26, 2025 2:56 pm Maybe new 'Source' option in 'Sort by' menu (as this is the place where all sort options exist)
I am unclear as to what you mean by "Source".

If by "Source", you mean copy the order as it appears in the "source" FILELIST file. Then Yes, I have no problem with that. But it should be in addition to the globally set Settings option. By that I mean, the developer provides both ways of accessing the feature. Otherwise, a user would have to select that button in "Sort by" menu, each time they load a FILELIST. This would affect usability and ease of use. That's why there should be a Settings option, for users that want this always enabled.

Update:
Actually. This could be a toggle checkbox element, rather than a button element. Which would solve the issue I mentioned above.
In which case, the user could enable a toggle checkbox, as an item in the "Sort by" menu,

FIG3
Keep filelist order option
Keep filelist order option
Screenshot_2025-05-26_18-48-30.png (28.64 KiB) Viewed 297 times
The developer can make the appropriate choice, on where to place the option.

What's important to me, is that there is a globally set option AND a a terminal command-line option.
Neuro-NX
Posts: 24
Joined: Wed Aug 31, 2022 9:38 pm

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by Neuro-NX »

To Reproduce

I'm using Linux. On Windows you can use WSL or follow the steps using your own process.

Example 1

To generate 6 numbered images, then add to filelist.

Requires 'imagemagick'

Copy and paste the whole code in a terminal. Remember to change "FONT-NAME".

Code: Select all

mkdir colors; \
cd colors; \
font="FONT-NAME" && for i in {1..6}; do magick convert -size 500x500 xc:grey -gravity Center -pointsize 100 -font "$font" -fill white -annotate 0 "$i" "$i.png"; done; \
for f in `realpath {1,3,2,5,4,6}.png`; do printf "\"$f\"\n" >> filelist.txt; done
Example 2

To generate 4 videos with different framerates, then add to filelist.

Requires 'ffmpeg'

Code: Select all

mkdir path; \
cd path; \
ffmpeg -f lavfi -i nullsrc=s=1280x720:r=24 -t 10 -c:v libx264 -pix_fmt yuv420p video1-24.mp4 && ffmpeg -f lavfi -i nullsrc=s=1280x720:r=24 -t 10 -c:v libx264 -pix_fmt yuv420p video2-24.mp4 && ffmpeg -f lavfi -i nullsrc=s=1280x720:r=30 -t 10 -c:v libx264 -pix_fmt yuv420p video1-30.mp4 && ffmpeg -f lavfi -i nullsrc=s=1280x720:r=60 -t 10 -c:v libx264 -pix_fmt yuv420p video1-60.mp4; \
for f in `realpath *-24.mp4`; do printf "\"$f\"\n" >> filelist.txt; done && \
for f in `realpath *-{30,60}.mp4`; do printf "\"$f\"\n" >> filelist.txt; done
Neuro-NX
Posts: 24
Joined: Wed Aug 31, 2022 9:38 pm

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by Neuro-NX »

To provide more clarity. Let me explain the user interaction flow.

We have 2 different users. They both want to keep the order of files, as it appears in the FILELIST file. But in different ways.

User 1:

Desire:
- Keep the same file order and override the sort order. TRUE.
- But ONLY when I choose to do so.

User Preference:
- Settings option to set global override to always keep the same file order. FALSE

User Actions:
- Enable option via command-line argument. See FIG4.

Code: Select all

xnviewmp -filelist filelist.txt -keep-order
- Use toggle button in "Sort by" dropdown menu, to enable option in GUI when needed. See FIG3.

User 2:

Desire:
- Keep the same file order and override the sort order. TRUE.
- But do so EACH time I load a filelist.

User Preference:
- Settings option to set global override to always keep the same file order. TRUE

User Actions:
- Enable option without command-line argument (As global Settings option is set to TRUE - See FIG2).

Code: Select all

xnviewmp -filelist filelist.txt
Sort Order Should Not Be Fixed

The browser file sorting should be flexible, and allow the user to revert to the default browser sorting order set in xnview.ini.

Code: Select all

[Browser]
sort=INT
sortNameMethod=INT
sortOrder=INT
Conditional logic

Condition: Listen for an event change in the GUI.
  • IF the global Settings option is enabled to "keep same order in filelist file" OR the toggle button in "Sort by" dropdown menu is CHECKED "Keep filelist order".
  • AND the user selects a different sorting item, either from the "Sort by" menu or toolbar button (cmd)
  • THEN the browser should update the file sorting order to update this change.
  • ONLY IF TRUE that the toggle button in "Sort by" dropdown menu is UNCHECKED. See FIG3.
[*] IF the sort order was changed (2). To re-sort using the same order in the filelist file (without reloading the filelist).
[*] The user can use the toggle button in "Sort by" dropdown menu ". See FIG3.

If you did not have this logic. Then it's less flexible, and some users may avoid this option, because it's too restrictive.
Some users will want to initially "keep the same filelist order" only momentarily for review and analysis. Then sort using some other sort order type.
meteorquake
Posts: 55
Joined: Wed Sep 13, 2023 9:37 am

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by meteorquake »

This is an important issue.
Some filelists are in a particularised order, some are not.
There does need to be a way to match the filelist order, and ways to switch out of that order and back in.
A number of ways come to my mind to do this, which are not exclusive of each other -

* The Filelist could have a top line of options, prefixed with * (which won't appear in a file name) specifying what to do when opened, which could include sorting but could include other settings, perhaps in the format of command-line options (using the same names where coinciding). I think this self-declaration would be very useful.

* View - Sort By could have an "Unsorted" or "Default" option which for a filelist would be the filelist's order

* I don't think a global setting is too helpful since some filelists are ordered and some are not, which is why I think it's better if the filelist itself declares whether it is an ordered list or not, however there's no harm in a global setting if the filelist doesn't self-declare

* Whether a filelist is ordered or not could also be indicated (where nowhere else indicates) by its extension or name pattern, e.g. mylist-ordered.txt

* Holding down modifiers when OKing the Open Filelist... dialog could also allow the user to state whether to use the current sorted order or the filelist order, or the dialog could have two open buttons, one for opening with the current sort, one for opening with the Filelist order.

* Provide shortcuttable commands to adjust the sorting, including one for Unsorted (i.e. Filelist order).

* Sorting provided by the command line

David
Neuro-NX
Posts: 24
Joined: Wed Aug 31, 2022 9:38 pm

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by Neuro-NX »

meteorquake wrote: Thu May 29, 2025 9:38 am * The Filelist could have a top line of options, prefixed with * (which won't appear in a file name) specifying what to do when opened, which could include sorting but could include other settings, perhaps in the format of command-line options (using the same names where coinciding). I think this self-declaration would be very useful.
:!: Note: Using the asterisk character ' * ' is dangerous and unsafe!

This could execute a function called Globbing, which enables Filename Expansion, in UNIX-like systems (Linux/macOS). If a user used an asterisk/wildcard (glob) in the terminal or in a script. The system call may access and read the FILELIST file, due to recursive search, and thus perform filename expansion on ALL files referenced on each line. As the pathname is wrapped in double-quotes, which would treat the whole path as type 'String'. It could lead to every file being deleted or modified.

The safer, and more common pattern, would be to use the INI syntax for commented-lines '#'.

Code: Select all

# OPTION1=VALUE, OPTION2=VALUE,
"/path/file"
"/path/file"
"/path/file"
"/path/file"
meteorquake wrote: Thu May 29, 2025 9:38 am * I don't think a global setting is too helpful since some filelists are ordered and some are not, which is why I think it's better if the filelist itself declares whether it is an ordered list or not, however there's no harm in a global setting if the filelist doesn't self-declare
Two points here.
  • The reason for suggesting a global setting, is that a user may not want to manually or explicitly (hardcode) the option in the FILELIST file. This would affect usability, because in some workflows, the user just wants to enable this functionality for some management task they are actively working on. So having some ON/OFF toggle, in the application GUI, whether it's in the form of a Settings option FIG2 or menu button FIG3), would allow for more flexibility.
  • The only issue I see for explicitly declaring an option header within the FILELIST itself, is that it becomes difficult for some users, if they have multiple files. For advanced users that are comfortable in the terminal, this is trivial to do. For example.

    Code: Select all

    ```sh
    # Iterate over all filelists in the directory, and add header line.
    for file in ./filelist-*.txt; do
        sed -i '1s/^/# OPTION=VALUE\n/' "$file"
    done
    ```
    
meteorquake wrote: Thu May 29, 2025 9:38 am * Whether a filelist is ordered or not could also be indicated (where nowhere else indicates) by its extension or name pattern, e.g. mylist-ordered.txt
This is similar to my previous point. It would require the user to manually format each file. In use cases, where the user is working on a task, that requires the browser to match the sort order, as it appears in the FILELIST file, periodically for a short time, it would not work in practical terms and affect usability. They would have revert the filename change back to 'mylist.txt'. It is also prone to error (mistyped word) and would reduce loading time, because it would have to parse every filename and use logic to check if each filename contains string "-ordered".

In version 1.9.0, some of the toolbar buttons have moved to the bottom.

There could be an indicator that informs the user whether the browser sorts according to the FILELIST order.

* The label must be short that's why I opted for "Filelist Ordered".
* The label would not be centered as shown in FIG5, but should be aligned to either the left or right of the toolbar.

FIG5
Add indicator to bottom
Add indicator to bottom
Screenshot_2025-05-29_14-27-32.png (184.12 KiB) Viewed 200 times
meteorquake wrote: Thu May 29, 2025 9:38 am * Sorting provided by the command line
:thumbsup: +1
meteorquake
Posts: 55
Joined: Wed Sep 13, 2023 9:37 am

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by meteorquake »

So if there's a problem with using *, some other symbol indicating heading options is fine. I'm conscious that # is a permissable filename character (though admittedly not as the first character of a full path but if relative names become usable, such as relative to the chosen filelist path, it could be an opening character) so I'd be looking at something that wouldn't be in a filename, instead of * perhaps :: would also do it which is already used as a comment symbol in DOS.

Regarding the other points, the suggestions I outlined are inclusive which means they are all optional alternatives. So, for example, having a filelist header line of default options for the filelist isn't a problem, a user or program will add one if they want to, users who know nothing about such things or have many files would just have a flat list and use one of the other ways. As with many things, a few different methods caters for more people and circumstances than just a single one, although even one method is definitely an improvement on none.

An example of another setting for the file header options would be a base path for which the files when relative are relative to.

The global setting sounds viable as one of the methods for people who want to toggle it to work on an extended task...

David
User avatar
user0
XnThusiast
Posts: 2410
Joined: Sat May 09, 2015 9:37 am

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by user0 »

you are overcomplicating this simple feature
no options are needed in the txt file
  • option location
    'Sort by' menu (in Browser) should be the only one place for this new sorting option
    it will:
    - explicitly show current sorting method
    - allow to select any other option and return back to Source
    browser_sortby_source.png
    browser_sortby_source.png (4.18 KiB) Viewed 159 times
  • use condition
    If you want source order to be applied automatically and only temporarily (until <files> path or sort order is changed) when loading txt file manually via 'Open file list...' - new 'Use source sort order for file list' checkbox should be added in Settings > Filelist (as per OP's request).
    However, I think he will bring more mess than good with his behavior. Manual switching to Source option is more than enough.
  • command line
    Better to use -order-source as a more general approach, allowing any other orders to be added in future (eg -order-name)
Neuro-NX
Posts: 24
Joined: Wed Aug 31, 2022 9:38 pm

Re: 1.8.8 - Filelist sort order not reflected in browser

Post by Neuro-NX »

To summarize the suggestions so far.
  • Enable Feature: From Settings
    • Option in "Tools > Settings > File list". See FIG2.
      This would define a global value for the browser to ALWAYS sort files according the order in the loaded FILELIST file.
    • To better emphasis that this option is a global override - Which means, it has the highest precedence. You could name the option "Always source order from the filelist".

      @user0, the distinction between the two modes of settings is explained by the conditional logic further down. Maybe the "mess" you have in mind, could be confusion between the two modes? If so, that's why I think "Always" should be added to the Settings option, like in the option "Folder always sorted alphabetically".
  • Enable Feature: From Command-line
    • New argument flag "-source-order". See FIG4. That would be read by OPTION -filelist.

      Code: Select all

      xnviewmp -filelist FILELIST -source-order
      
    • This allows users to NOT set the option globally in the Settings. But use the feature when necessary via the command-line.
  • Enable Feature: From Toggle (radio) button in "Sort By" menu
    • This allows users to NOT set the option globally in the GUI. But use the feature when necessary via a toggle button (Qt radio button).
    • The toggle button in FIG3 would be a way to toggle the feature ON or OFF.
    • Use Conditional Logic:
      • IF the Settings option "Always source the order from the filelist" is ENABLED (checkbox is SELECTED).
      • The user can SELECT the toggle (radio) button in "Sort By" menu ON and OFF - To temporarily use the sorting order in "Sort by" menu.
      • EVENT CHANGE: Then when the loaded filelist WINDOW or TAB is closed. The sort order will still continue to be sorted according to the FILELIST file.
  • Show an indicator
    • Add an indicator to the toolbar. Either as an icon or label (or both?), that will provide a visual cue, when the SOURCE order is ENABLED.See FIG5.
    Update:

    To clarify my position on Settings option:

    It is not that important for me, as I am a command-line user.

    I am trying think of how it could be used from multiple use cases. If Pierre or other people involved think it's over-engineering a problem, then you can omit the Settings option.
Post Reply