@@ -21,13 +21,14 @@ let dynarray_to_iarray a = Obj.magic (Dynarray.to_array a)
2121type time = float
2222
2323type display = [`Table | `Grid ]
24+ type void = |
2425
2526type ('data, 'attr) view =
2627{
2728 mutable shown : display option ;
2829 mutable columns : 'attr columns ;
2930 mutable sorting : 'attr sorting ;
30- mutable save : 'data Table .save option ;
31+ mutable save : ( 'data , void ) Table .t option ;
3132}
3233
3334type artists_view = (artist , artist_attr_ex ) view
@@ -85,9 +86,9 @@ type 'cache t =
8586 search : Edit .t ;
8687 rename : Edit .t ;
8788 browser : (dir , 'cache ) Table .t ;
88- artists : (artist , 'cache ) Table .t ;
89- albums : (album , 'cache ) Table .t ;
90- tracks : (track , 'cache ) Table .t ;
89+ mutable artists : (artist , 'cache ) Table .t ;
90+ mutable albums : (album , 'cache ) Table .t ;
91+ mutable tracks : (track , 'cache ) Table .t ;
9192 covers : cover Map .t Atomic .t ;
9293 mutable age_covers : (path * cover ) Seq .t ;
9394 mutable views_clip : views option ;
@@ -684,9 +685,9 @@ let rec load_dir lib (dir : dir) =
684685 let albums_save = dir.view.albums.save in
685686 dir.view < - make_views_for lib dir.path;
686687 dir.view.albums.save < - albums_save;
687- dir.view.albums.save |> Option. iter (fun save ->
688- if Array. length ( Table. save_array save) <> 0 then
689- Printf. eprintf " [load_dir] %d albums selected, custom=%b\n %!" (Array. length ( Table. save_array save) ) dir.view.custom);
688+ dir.view.albums.save |> Option. iter (fun tab ->
689+ if Table. num_selected tab <> 0 then
690+ Printf. eprintf " [load_dir] %d albums selected, custom=%b\n %!" (Table. num_selected tab ) dir.view.custom);
690691 Storage. load_string_opt (dir_name dir) (fun s ->
691692 try
692693 Parse. dir (Text. parse s) dir
@@ -1131,13 +1132,18 @@ let focus_search lib =
11311132 Edit. focus lib.search
11321133
11331134
1135+ (* Hack so that we are independent from cache type *)
1136+ let coerce_table (tab : ('a, _) Table.t ) : ('a, _) Table.t =
1137+ Table. uncache tab;
1138+ Obj. magic tab
1139+
11341140let set_dir_opt lib dir_opt =
11351141 Option. iter (fun (dir : dir ) ->
11361142if Table. num_selected lib.albums <> 0 then
11371143Printf. eprintf " [set_dir] old %d albums selected\n %!" (Table. num_selected lib.albums);
1138- dir.view.artists.save < - Some (Table. save lib.artists);
1139- dir.view.albums.save < - Some (Table. save lib.albums);
1140- dir.view.tracks.save < - Some (Table. save lib.tracks);
1144+ dir.view.artists.save < - Some (coerce_table lib.artists);
1145+ dir.view.albums.save < - Some (coerce_table lib.albums);
1146+ dir.view.tracks.save < - Some (coerce_table lib.tracks);
11411147 ) lib.current;
11421148 Table. deselect_all lib.browser;
11431149 Table. clear_undo lib.tracks;
@@ -1157,16 +1163,16 @@ let select_dir lib i =
11571163 (
11581164 set_dir_opt lib (Some dir);
11591165 Table. select lib.browser i i;
1160- Option. iter (Table. restore lib.artists artist_key ) dir.view.artists.save;
1161- Option. iter (Table. restore lib.albums album_key ) dir.view.albums.save;
1162- Option. iter (Table. restore lib.tracks track_key ) dir.view.tracks.save;
1166+ Option. iter (fun tab -> lib.artists < - coerce_table tab ) dir.view.artists.save;
1167+ Option. iter (fun tab -> lib.albums < - coerce_table tab ) dir.view.albums.save;
1168+ Option. iter (fun tab -> lib.tracks < - coerce_table tab ) dir.view.tracks.save;
11631169(*
11641170if Option.exists (fun save -> Array.length (Table.save_array save) <> 0) dir.view.albums.save || Table.num_selected lib.albums <> 0 then
11651171*)
1166- let n = dir.view.albums.save |> Option. map (fun save -> Array. length ( Table. save_array save) ) |> Option. value ~default: 0 in
1172+ let n = dir.view.albums.save |> Option. map (fun tab -> Table. num_selected tab ) |> Option. value ~default: 0 in
11671173Printf. eprintf " [select_dir] save=%s, new %d albums selected\n %!" (Table. string_of_save dir.view.albums.save) (Table. num_selected lib.albums);
11681174if n <> Table. num_selected lib.albums then
1169- Option. iter (fun save -> Array. iter (fun (album : album ) -> Printf. eprintf " %s\n %!" (String. escaped (album_key album))) ( Table. save_array save) ) dir.view.albums.save;
1175+ Option. iter (fun save -> Array. iter (fun (album : album ) -> Printf. eprintf " %s\n %!" (String. escaped (album_key album))) save. Table. entries ) dir.view.albums.save;
11701176 if Data. is_playlist dir then
11711177 rescan_playlist lib `Thorough dir
11721178 else if Data. is_viewlist dir then
@@ -1422,7 +1428,7 @@ let refresh_artists_albums_tracks s ?(busy = true) ?(after = ignore) lib =
14221428 let vscroll_tracks = lib.tracks.vscroll in
14231429 let vscroll_albums = lib.albums.vscroll in
14241430 let vscroll_artists = lib.artists.vscroll in
1425- if busy then
1431+ if busy && lib.artists.entries = [||] then
14261432 (
14271433 Atomic. set lib.scan.artists_busy true ;
14281434 Table. set lib.tracks [||];
0 commit comments