File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 11import enum
2+ import random
23from dataclasses import dataclass , replace
34from pathlib import Path
45
@@ -69,6 +70,7 @@ class SortingModeEnum(enum.Enum):
6970 DATE_ADDED = "file.date_added"
7071 FILE_NAME = "generic.filename"
7172 PATH = "file.path"
73+ RANDOM = "sorting.mode.random"
7274
7375
7476@dataclass
@@ -78,6 +80,7 @@ class BrowsingState:
7880 page_index : int = 0
7981 sorting_mode : SortingModeEnum = SortingModeEnum .DATE_ADDED
8082 ascending : bool = True
83+ random_seed : float = 0
8184
8285 query : str | None = None
8386
@@ -133,7 +136,10 @@ def with_page_index(self, index: int) -> "BrowsingState":
133136 return replace (self , page_index = index )
134137
135138 def with_sorting_mode (self , mode : SortingModeEnum ) -> "BrowsingState" :
136- return replace (self , sorting_mode = mode )
139+ seed = self .random_seed
140+ if mode == SortingModeEnum .RANDOM :
141+ seed = random .random ()
142+ return replace (self , sorting_mode = mode , random_seed = seed )
137143
138144 def with_sorting_direction (self , ascending : bool ) -> "BrowsingState" :
139145 return replace (self , ascending = ascending )
Original file line number Diff line number Diff line change @@ -921,6 +921,8 @@ def search_library(
921921 sort_on = func .lower (Entry .filename )
922922 case SortingModeEnum .PATH :
923923 sort_on = func .lower (Entry .path )
924+ case SortingModeEnum .RANDOM :
925+ sort_on = func .sin (Entry .id * search .random_seed )
924926
925927 statement = statement .order_by (asc (sort_on ) if search .ascending else desc (sort_on ))
926928 if page_size is not None :
Original file line number Diff line number Diff line change 264264 "settings.title" : " Settings" ,
265265 "sorting.direction.ascending" : " Ascending" ,
266266 "sorting.direction.descending" : " Descending" ,
267+ "sorting.mode.random" : " Random" ,
267268 "splash.opening_library" : " Opening Library \" {library_path}\" ..." ,
268269 "status.deleted_file_plural" : " Deleted {count} files!" ,
269270 "status.deleted_file_singular" : " Deleted 1 file!" ,
You can’t perform that action at this time.
0 commit comments