Skip to content

Commit 8538a16

Browse files
committed
WIP
1 parent e92fda2 commit 8538a16

4 files changed

Lines changed: 31 additions & 66 deletions

File tree

‎src/library.ml‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ let dynarray_to_iarray a = Obj.magic (Dynarray.to_array a)
2121
type time = float
2222

2323
type display = [`Table | `Grid]
24+
type void = |
2425

2526
type ('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

3334
type 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+
11341140
let set_dir_opt lib dir_opt =
11351141
Option.iter (fun (dir : dir) ->
11361142
if Table.num_selected lib.albums <> 0 then
11371143
Printf.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
(*
11641170
if 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
11671173
Printf.eprintf "[select_dir] save=%s, new %d albums selected\n%!" (Table.string_of_save dir.view.albums.save) (Table.num_selected lib.albums);
11681174
if 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 [||];

‎src/library.mli‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
open Data
44

55
type display = [`Table | `Grid]
6+
type void = |
67

78
type ('data, 'attr) view =
89
{
910
mutable shown : display option;
1011
mutable columns : 'attr columns;
1112
mutable sorting : 'attr sorting;
12-
mutable save : 'data Table.save option;
13+
mutable save : ('data, void) Table.t option;
1314
}
1415

1516
type artists_view = (artist, artist_attr_ex) view
@@ -45,9 +46,9 @@ type 'cache t = private
4546
search : Edit.t;
4647
rename : Edit.t;
4748
browser : (dir, 'cache) Table.t;
48-
artists : (artist, 'cache) Table.t;
49-
albums : (album, 'cache) Table.t;
50-
tracks : (track, 'cache) Table.t;
49+
mutable artists : (artist, 'cache) Table.t;
50+
mutable albums : (album, 'cache) Table.t;
51+
mutable tracks : (track, 'cache) Table.t;
5152
covers : cover Map.Make(String).t Atomic.t;
5253
mutable age_covers : (path * cover) Seq.t;
5354
mutable views_clip : views option;

‎src/table.ml‎

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@ type 'a undo =
1414
undo_restore : (unit -> unit) option;
1515
}
1616

17-
type 'a save =
18-
{
19-
save_vscroll : int;
20-
save_hscroll : int;
21-
save_selection : 'a array;
22-
save_undos : 'a undo list;
23-
save_redos : 'a undo list;
24-
}
25-
let save_array x = x.save_selection
26-
let string_of_save = function
27-
| None -> "none"
28-
| Some save -> Printf.sprintf "{scroll=%d,%d sel=%d}" save.save_vscroll save.save_hscroll (Array.length save.save_selection)
29-
3017
type ('a, 'b) t =
3118
{
3219
mutex : Mutex.t;
@@ -45,6 +32,9 @@ type ('a, 'b) t =
4532
undo_depth : int;
4633
undo_save : (unit -> unit -> unit) option;
4734
}
35+
let string_of_save = function
36+
| None -> "none"
37+
| Some save -> Printf.sprintf "{scroll=%d,%d sel=%d}" save.vscroll save.hscroll (IntSet.cardinal save.selected)
4838

4939

5040
(* Constructor *)
@@ -247,7 +237,6 @@ Printf.eprintf "[save_selection %d/%d]\n%!" (num_selected tab) (length tab);
247237
let restore_selection tab key selection =
248238
if length tab = 2983 then
249239
Printf.eprintf "[restore_selection %d/%d]\n%!" (Array.length selection) (length tab);
250-
assert (length tab <> 2983 || Array.length selection > 0);
251240
if selection <> [||] then
252241
(
253242
dirty tab;
@@ -258,29 +247,6 @@ assert (length tab <> 2983 || Array.length selection > 0);
258247
)
259248

260249

261-
(* Save & Restore *)
262-
263-
let save tab =
264-
if length tab = 2983 then
265-
Printf.eprintf "[save %d]\n%!" (length tab);
266-
{
267-
save_vscroll = tab.vscroll;
268-
save_hscroll = tab.hscroll;
269-
save_selection = save_selection tab;
270-
save_undos = !(tab.undos);
271-
save_redos = !(tab.redos);
272-
}
273-
274-
let restore tab key save =
275-
if length tab = 2983 then
276-
Printf.eprintf "[restore %d]\n%!" (length tab);
277-
tab.vscroll <- max save.save_vscroll (length tab);
278-
tab.hscroll <- save.save_hscroll;
279-
restore_selection tab key save.save_selection;
280-
tab.undos := save.save_undos;
281-
tab.redos := save.save_redos
282-
283-
284250
(* Marking *)
285251

286252
let num_marked tab = IntSet.cardinal tab.marked

‎src/table.mli‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module IntSet : module type of Set.Make(Int)
44

55
type 'data undo
6-
type 'data save
76

87
type ('data, 'cache) t = private
98
{
@@ -24,8 +23,7 @@ type ('data, 'cache) t = private
2423
undo_save : (unit -> unit -> unit) option;
2524
}
2625
(*TODO: remove*)
27-
val save_array : 'a save->'a array
28-
val string_of_save : 'a save option -> string
26+
val string_of_save : ('a,'b) t option -> string
2927

3028

3129
(* Constructor *)
@@ -81,12 +79,6 @@ val save_selection : ('a, 'b) t -> 'a array
8179
val restore_selection : ('a, 'b) t -> ('a -> string) -> 'a array -> unit
8280

8381

84-
(* Save & Restore *)
85-
86-
val save : ('a, 'b) t -> 'a save
87-
val restore : ('a, 'b) t -> ('a -> string) -> 'a save -> unit
88-
89-
9082
(* Marking *)
9183

9284
val num_marked : ('a, 'b) t -> int

0 commit comments

Comments
 (0)