Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the 'none' sorting setting #655

Merged
merged 4 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Wolfgang Popp (woefe) <mail at wolfgang-popp dot de>
Ankur Sinha (sanjayankur31) <ankursinha at fedoraproject dot org>
Jean-Claude Graf (jcjgraf) <jeanggi90 at gmail dot com>
Mateus Etto (Yutsuten) <mateus dot etto at gmail dot com>
buzzingwires (buzzingwires) <buzzingwires at outlook dot com>

All contributors of non-trivial code are listed here. Please send an email to
<karlch at protonmail dot com> or open an issue / pull request if you feel like your
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Added:
the changes with ``<return>`` and reject them with ``<escape>``. The
``{transformation-info}`` status module displays the currently selected geometry of
the original image. Thanks `@Yutsuten`_ for reviving this!
* Add the ``none`` sorting type for the ``sort.image_order`` and ``sort.directory_order``
options, implemented by `@buzzingwires`_
karlch marked this conversation as resolved.
Show resolved Hide resolved

Changed:
^^^^^^^^
Expand Down Expand Up @@ -535,3 +537,4 @@ Initial release of the Qt version.
.. _@timsofteng: https://github.com/timsofteng
.. _@kAldown: https://github.com/kaldown
.. _@Yutsuten: https://github.com/Yutsuten
.. _@buzzingwires: https://github.com/buzzingwires
6 changes: 4 additions & 2 deletions docs/documentation/configuration/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ directories. The ordering principle is defined by the ``sort.image_order`` and
natural Natural ordering by basename, i.e. image2.jpg comes before image11.jpg
recently-modified Ordering by modification time (``mtime``)
size Ordering by filesize, in bytes for images, in number of files for directories
none Do not sort or reverse. Use the existing order of the images (including that of a previous sort type). This is mostly for keeping the order from the command line or stdin.
========================= ===========

In addition, the ordering can be reversed using ``sort.reverse`` and the string-like
orderings (``alphabetical`` and ``natural``) can be made case-insensitive using
``sort.ignore_case``. When ``sort.shuffle`` is set, the image filelist is shuffled
regardless of the other orderings, but the library remains ordered.
``sort.ignore_case`` except for when the ``none`` ordering type is used.
When ``sort.shuffle`` is set, the image filelist is shuffled regardless of the other
orderings, but the library remains ordered.
20 changes: 20 additions & 0 deletions tests/end2end/features/image/imageorder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ Feature: Ordering the image filelist.
And the image number 2 should be image_2.jpg
And the image number 11 should be image_11.jpg

Scenario: Set none sorting after another sort
Given I open 12 images without leading zeros in their name
When I run set sort.image_order natural
Then the image should have the index 1
And the image number 1 should be image_1.jpg
And the image number 2 should be image_2.jpg
And the image number 11 should be image_11.jpg
When I run set sort.image_order none
Then the image should have the index 1
And the image number 1 should be image_1.jpg
And the image number 2 should be image_2.jpg
And the image number 11 should be image_11.jpg

Scenario: Reverse none sorting
Given I open 5 images
When I run set sort.image_order none
Then the image should have the index 1
When I run set sort.reverse
Then the image should have the index 1

Scenario: Reverse current filelist
Given I open 5 images
When I run set sort.reverse!
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/api/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ def test_order_setting_sort(
assert sorted_values == expected_values


@pytest.mark.parametrize("reverse", [True, False])
@pytest.mark.parametrize("ignore_case", [True, False])
def test_order_setting_sort_none(monkeypatch, reverse, ignore_case):
values = ["a5.j", "A6.j", "a11.j", "a3.j"]
monkeypatch.setattr(settings.sort.reverse, "value", reverse)
monkeypatch.setattr(settings.sort.ignore_case, "value", ignore_case)
o = settings.OrderSetting("order", "none")
sorted_values = o.sort(values)
assert sorted_values == values


@pytest.mark.parametrize("ignore_case", [True, False])
def test_order_setting_sort_ignore_case(monkeypatch, ignore_case):
monkeypatch.setattr(settings.sort.ignore_case, "value", ignore_case)
Expand Down
1 change: 1 addition & 0 deletions vimiv/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class OrderSetting(Setting):
"alphabetical": str,
"natural": natural_sort,
"recently-modified": os.path.getmtime,
"none": lambda x: 0
}

STR_ORDER_TYPES = "alphabetical", "natural"
Expand Down