Repository navigation
Expand file tree
/
Copy pathapp_toolbar.cpp
More file actions
1965 lines (1781 loc) · 95.9 KB
/
Copy pathapp_toolbar.cpp
File metadata and controls
1965 lines (1781 loc) · 95.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of the Diffractor photo and video organizer
// Copyright 2026 Zac Walker
//
// This program is free software; you can redistribute it and / or modify it
// under the terms of the LGPL License either version 2.1 or later.
// License details are available at https://www.gnu.org/licenses/lgpl-2.1.html
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
// Purpose: Toolbars and how commands present. Builds the title bar and status bar each view declares
// - toolbars for its commands, the item filter box and size slider - and arranges them, decides each
// command's enabled, checked and visible state and its disabled reason, sets command text and icons,
// owns the default keyboard accelerators, and shows command and status-bar tooltips. What a command
// does is registered in app_commands.cpp.
#include "pch.h"
#include "app_text.h"
#include "model_location.h"
#include "model_index.h"
#include "model_db.h"
#include "model.h"
#include "ui_dialog.h"
#include "view_items.h"
#include "view_sync.h"
#include "view_tags.h"
#include "view_import.h"
#include "view_rename.h"
#include "view_batch.h"
#include "view_locate.h"
#include "view_movie.h"
#include "view_edit.h"
#include "view_media.h"
#include "app_sidebar.h"
#include "app_commands.h"
#include "app.h"
#include <utility>
bool toggle_details_state = false;
// The address bar shows the scope of the current search: a folder, a folder searched recursively,
// or the kind of the first term. The star glyph is reserved for ratings, so fall back to the
// generic search icon rather than showing it here.
static icon_index address_icon(const df::search_t& search)
{
if (search.has_recursive_selector()) return icon_index::recursive;
if (search.has_selector()) return icon_index::folder;
if (search.has_terms())
{
const auto icon = search.first_type()->icon;
if (icon != icon_index::star && icon != icon_index::none) return icon;
}
return icon_index::search;
}
void app_frame::create_toolbars()
{
const std::vector<ui::command_ptr> tbButtonsNav1 =
{
find_command(commands::view_show_sidebar),
#ifndef WINSTORE
find_command(commands::info_new_version),
#endif
find_command(commands::browse_back),
find_command(commands::browse_forward),
find_command(commands::browse_parent),
find_command(commands::refresh),
};
// Options is not here: its cog starts the status bar, under the sidebar that shows the collection it sets up
// first, and it is in the Options menu.
const std::vector<ui::command_ptr> tbButtonsNav2 =
{
find_command(commands::favorite),
find_command(commands::browse_previous_folder),
find_command(commands::browse_next_folder),
find_command(commands::advanced_search),
find_command(commands::menu_main),
};
const std::vector<ui::command_ptr> tbButtonsNav3 =
{
find_command(commands::view_minimize),
find_command(commands::view_maximize),
find_command(commands::view_restore),
find_command(commands::exit),
};
ui::toolbar_styles tb_styles;
tb_styles.button_extent = {30, 40};
_navigate1 = ui::make_toolbar(tb_styles, tbButtonsNav1);
_navigate2 = ui::make_toolbar(tb_styles, tbButtonsNav2);
tb_styles.button_extent = {40, 40};
_navigate3 = ui::make_toolbar(tb_styles, tbButtonsNav3);
ui::edit_styles search_styles;
search_styles.rounded_corners = true;
search_styles.select_all_on_focus = true;
search_styles.capture_key_down = [this](const int key_code, const platform::key_state keys)
{
const auto key = static_cast<char32_t>(key_code);
if (key == platform::keys::RETURN)
{
search_enter();
return true;
}
if (key == platform::keys::ESCAPE)
{
cancel_search_edit();
return true;
}
if (key == platform::keys::UP || key == platform::keys::DOWN)
{
if (_search_predictions_frame)
{
_search_predictions_frame->step_selection(key == platform::keys::UP ? -1 : 1);
}
return true;
}
return key == platform::keys::TAB && !keys.control && !keys.shift && search_accept_selected();
};
_search_edit = ui::make_edit(search_styles, {}, [this](const std::string_view text)
{
search_text_changed(text);
});
// The filter box is the address box's sibling at the other end of the window: the same edit, so
// the two read, select and edit alike.
ui::edit_styles filter_styles;
filter_styles.rounded_corners = true;
filter_styles.select_all_on_focus = true;
filter_styles.cue = tt.filter.sv();
filter_styles.capture_key_down = [this](const int key_code, const platform::key_state keys)
{
return filter_key_down(static_cast<char32_t>(key_code), keys);
};
_filter_edit = ui::make_edit(filter_styles, _state.filter().text(), [this](const std::string_view text)
{
filter_text_changed(text);
});
_item_size = ui::make_slider(0, settings_t::item_scale_position_max,
[this](const int pos, const bool tracking)
{
item_size_changed(pos, tracking);
});
update_item_size_slider();
// Every bar a view can declare is built now, before the first layout, so switching views only
// shows and hides controls that already exist.
const std::shared_ptr<view_base> views[] = {
_view_items, _view_media, _view_edit, _view_movie, _view_rename, _view_batch, _view_import, _view_sync,
_view_locate, _view_tags
};
for (const auto& v : views)
{
const auto declared = v->bars();
if (!declared.navigation) bar(declared.top);
bar(declared.bottom);
bar(declared.bottom_leading);
}
bar(running_task_bar());
}
const std::vector<bar_entry>& app_frame::running_task_bar()
{
// Nothing else a task view offers may start under a run that is still going, so its commands give
// way to the one that stops it.
static const std::vector<bar_entry> entries = {commands::view_cancel};
return entries;
}
const app_frame::frame_bar& app_frame::bar(const std::vector<bar_entry>& entries)
{
if (const auto found = _bars.find(entries); found != _bars.end()) return found->second;
ui::toolbar_styles styles;
styles.button_extent = {0, 0};
frame_bar result;
std::vector<ui::command_ptr> run;
const auto close_run = [this, &result, &run, &styles]
{
if (run.empty()) return;
result.push_back({ui::make_toolbar(styles, run)});
run.clear();
};
for (const auto& entry : entries)
{
if (const auto* const id = std::get_if<commands>(&entry))
{
// A null button is a separator, so an unresolved command is dropped rather than turned
// into a divider nobody declared.
if (auto command = find_command(*id)) run.emplace_back(std::move(command));
}
else
{
close_run();
result.push_back({nullptr, std::get<bar_control>(entry)});
}
}
close_run();
return _bars.emplace(entries, std::move(result)).first->second;
}
std::vector<bar_slot> app_frame::measure_bar(render::measure_context& mc, const frame_bar& b,
const int control_height) const
{
std::vector<bar_slot> result;
result.reserve(b.size());
for (const auto& part : b)
{
if (part.toolbar)
{
result.push_back({part.toolbar->measure_toolbar(mc, _extent.cx)});
continue;
}
switch (part.control)
{
case bar_control::item_filter:
// Narrows before anything is cut, but not past what still shows a typed word.
result.push_back({
{core::round(150 * mc.scale_factor), control_height}, core::round(80 * mc.scale_factor)
});
break;
case bar_control::item_size:
// The wheel and the display menu also size thumbnails, so the slider is the first to go.
result.push_back({{core::round(100 * mc.scale_factor), control_height}, 0, true});
break;
case bar_control::item_totals:
result.push_back({
{
mc.measure_text(_totals_text, render::font_face::dialog, render::text_style::single_line,
_extent.cx).cx + mc.padding2 * 2,
mc.text_line_height(render::font_face::dialog)
}
});
break;
}
}
return result;
}
bar_arrangement arrange_bar(const recti bounds, const std::vector<bar_slot>& slots, const int gap,
const bar_alignment alignment)
{
// A leading bar is a trailing one seen in a mirror: its slots in reverse, arranged from the right
// and reflected back, so both ends give way by the same rules.
if (alignment == bar_alignment::leading)
{
const std::vector<bar_slot> reversed(slots.rbegin(), slots.rend());
const auto mirrored = arrange_bar(bounds, reversed, gap, bar_alignment::trailing);
const auto reflect = [&bounds](const recti r)
{
return recti(bounds.left + bounds.right - r.right, r.top, bounds.left + bounds.right - r.left, r.bottom);
};
bar_arrangement result;
result.slots.resize(slots.size());
for (auto i = 0u; i < slots.size(); ++i)
{
const auto placed = mirrored.slots[slots.size() - 1 - i];
if (!placed.is_empty()) result.slots[i] = reflect(placed);
}
result.remainder = reflect(mirrored.remainder);
return result;
}
const auto count = slots.size();
std::vector<int> widths(count);
std::vector<bool> shown(count, true);
for (auto i = 0u; i < count; ++i)
{
widths[i] = std::max(0, slots[i].extent.cx);
shown[i] = widths[i] > 0;
}
const auto total = [&]
{
auto sum = 0;
auto visible = 0;
for (auto i = 0u; i < count; ++i)
{
if (!shown[i]) continue;
sum += widths[i];
++visible;
}
return sum + std::max(0, visible - 1) * gap;
};
const auto available = std::max(0, bounds.width());
for (auto i = 0u; i < count && total() > available; ++i)
{
if (slots[i].optional) shown[i] = false;
}
for (auto i = 0u; i < count && total() > available; ++i)
{
if (!shown[i] || slots[i].min_width <= 0 || slots[i].min_width >= widths[i]) continue;
widths[i] -= std::min(total() - available, widths[i] - slots[i].min_width);
}
// Cut from the leading end. A part past its minimum is no use at any width, so parts go whole,
// and only the last one standing is clipped to the bar.
for (auto i = 0u; i < count && total() > available; ++i)
{
if (!shown[i]) continue;
if (std::count(shown.begin() + i + 1, shown.end(), true) > 0)
{
shown[i] = false;
}
else
{
widths[i] = std::max(0, widths[i] - (total() - available));
}
}
bar_arrangement result;
result.slots.resize(count);
auto x = bounds.right;
auto leading = bounds.right;
for (auto i = count; i-- > 0;)
{
if (!shown[i]) continue;
const auto height = std::min(slots[i].extent.cy, bounds.height());
const auto top = bounds.top + (bounds.height() - height) / 2;
result.slots[i] = recti(x - widths[i], top, x, top + height);
leading = x - widths[i];
x = leading - gap;
}
const auto remainder_right = leading == bounds.right ? bounds.right : leading - gap;
result.remainder = recti(bounds.left, bounds.top, std::max(bounds.left, remainder_right), bounds.bottom);
return result;
}
bool app_frame::filter_key_down(const char32_t key, const platform::key_state keys)
{
if (key == platform::keys::ESCAPE)
{
cancel_filter_edit();
return true;
}
// The filter applies as it is typed, so Enter and Tab have nothing left to commit: both hand the
// keyboard back to the list it filtered.
if ((key == platform::keys::RETURN || key == platform::keys::TAB) && !keys.control && !keys.alt)
{
focus_view();
return true;
}
return false;
}
void app_frame::filter_text_changed(const std::string_view text)
{
_state.filter().wildcard(text);
invalidate_view(view_invalid::group_layout | view_invalid::view_redraw);
}
void app_frame::set_filter_edit_text(const std::string_view text)
{
_filter_edit->window_text(text);
}
void app_frame::focus_filter(const bool has_focus)
{
if (_filter_has_focus == has_focus) return;
_filter_has_focus = has_focus;
if (has_focus) _filter_edit_original = _state.filter().text();
}
void app_frame::focus_filter_edit()
{
// A box the status bar is not showing - Fullscreen, zoom mode - cannot take the keyboard, or
// typing would go somewhere the user cannot see.
if (_filter_edit && std::ranges::find(_status_bar->_controls, _filter_edit) != _status_bar->_controls.end())
{
_filter_edit->focus();
}
}
// Escape abandons the edit: the filter goes back to what it was when the box took focus.
void app_frame::cancel_filter_edit()
{
if (_state.filter().text() != _filter_edit_original)
{
set_filter_edit_text(_filter_edit_original);
filter_text_changed(_filter_edit_original);
}
focus_view();
}
void app_frame::item_size_changed(const int pos, const bool tracking)
{
setting.set_item_scale_position(pos);
invalidate_view(view_invalid::view_layout);
if (tracking)
{
_item_size_dragging = true;
}
else if (std::exchange(_item_size_dragging, false))
{
// A drag is pointer work, and the keyboard still belongs to the list it resized. Left on the
// slider, the arrow keys would go on resizing thumbnails instead of moving through them.
queue_ui([this] { focus_view(); });
}
}
void app_frame::update_item_size_slider() const
{
// Ctrl+wheel, a pinch and the display menu change the size as well, so the slider follows the
// setting whenever it is not the one being dragged.
if (_item_size && !_item_size_dragging)
{
const auto pos = setting.item_scale_slider_position();
if (_item_size->get_pos() != pos) _item_size->set_pos(pos);
}
}
// locations.md 7.1, baseline defect 5: this button now reads only what the grouping and sorting
// are, because that is the menu it opens. The totals moved to their own affordance next to it,
// which has no menu, so a user reaching for the count is no longer offered a grouping menu.
std::string format_items_summary(const group_by grouping, const sort_by order,
const df::file_group_histogram& summary, const bool is_init_complete)
{
std::string_view group_text;
std::string_view sort_text;
switch (grouping)
{
case group_by::presence: group_text = tt.sort_by_presence;
break;
case group_by::file_type: group_text = tt.sort_by_file_type;
break;
case group_by::shuffle: group_text = tt.sort_by_shuffle;
break;
case group_by::size: group_text = tt.sort_by_size;
break;
case group_by::extension: group_text = tt.sort_by_extension;
break;
case group_by::location: group_text = tt.sort_by_location;
break;
case group_by::rating_label: group_text = tt.sort_by_rating_label;
break;
case group_by::date_created: group_text = tt.prop_name_created;
break;
case group_by::date_original: group_text = tt.prop_name_original;
break;
case group_by::date_modified: group_text = tt.prop_name_modified;
break;
case group_by::camera: group_text = tt.prop_name_camera;
break;
case group_by::album_show: group_text = tt.sort_by_album_show;
break;
case group_by::resolution: group_text = tt.sort_by_resolution;
break;
case group_by::aspect_ratio: group_text = tt.sort_by_aspect_ratio;
break;
case group_by::folder: group_text = tt.sort_by_Folder;
break;
case group_by::related: group_text = tt.command_related;
break;
}
switch (order)
{
case sort_by::def: sort_text = tt.sort_by_def;
break;
case sort_by::name: sort_text = tt.sort_by_name;
break;
case sort_by::size: sort_text = tt.sort_by_size;
break;
case sort_by::date_created: sort_text = tt.prop_name_created;
break;
case sort_by::date_original: sort_text = tt.prop_name_original;
break;
case sort_by::date_modified: sort_text = tt.prop_name_modified;
break;
}
const auto total_items = summary.total_items();
const auto has_content = total_items.count > 0 || summary.total_folders().count > 0;
if (!has_content)
{
return std::string(is_init_complete ? tt.empty : tt.loading);
}
if (group_text == sort_text || grouping == group_by::shuffle || sort_text.empty() || order == sort_by::def)
{
return str_format(tt.grouped_by_fmt.sv(), group_text);
}
return str_format(tt.grouped_and_sorted_fmt.sv(), group_text, sort_text);
}
// locations.md 7.1: the totals read as totals and nothing else. Hovering shows the breakdown by
// type; there is no menu behind them.
std::string format_items_totals(const df::file_group_histogram& summary, const bool is_init_complete)
{
const auto total_items = summary.total_items();
if (total_items.count > 0)
{
return std::format("{}|{}", core::format_count(total_items.count), platform::format_size(total_items.size));
}
const auto total_folders = summary.total_folders();
if (total_folders.count > 0)
{
return std::format("{} {}", core::format_count(total_folders.count), tt.folders);
}
return std::string(is_init_complete ? tt.empty : tt.loading);
}
std::string format_selection_summary(const df::item_set& selected)
{
if (selected.empty()) return {};
const auto summary = selected.summary();
const auto files = summary.total_items();
const auto count = format_plural_text(tt.title_item_count_fmt,
static_cast<int64_t>(files.count + summary.total_folders().count));
return files.size.is_empty() ? count : std::format("{} \u00B7 {}", count, platform::format_size(files.size));
}
icon_index volumes_icons[5] = {
icon_index::volume3, icon_index::volume2, icon_index::volume1, icon_index::volume0, icon_index::mute
};
void app_frame::toggle_volume()
{
auto v = setting.media_volume;
if (v == 0)
{
v = media_volumes[0];
}
else
{
for (const int volume : media_volumes)
{
if (v > volume)
{
v = volume;
break;
}
}
}
setting.media_volume = std::clamp(v, 0, media_volume_boost);
_commands[commands::playback_volume_toggle]->icon = sound_icon();
invalidate_view(view_invalid::command_state);
}
icon_index app_frame::sound_icon()
{
const auto v = setting.media_volume;
for (auto i = 0u; i < std::size(media_volumes); i++)
{
if (v >= media_volumes[i])
{
return volumes_icons[i];
}
}
return icon_index::mute;
}
icon_index app_frame::repeat_toggle_icon()
{
if (setting.repeat == repeat_mode::repeat_one) return icon_index::repeat_one;
if (setting.repeat == repeat_mode::repeat_all) return icon_index::repeat_all;
return icon_index::repeat_none;
}
bool app_frame::update_toolbar_text(const commands cc, const std::string& text)
{
const auto command = _commands[cc];
const auto changed = text != command->toolbar_text;
if (changed)
{
command->toolbar_text = text;
// The items view measures its rendered toolbars from this text, so the view has to
// re-lay out as well as the frame.
invalidate_view(view_invalid::app_layout | view_invalid::view_layout);
}
return changed;
}
// One place that names which run command each task view answers to. While a command dialog is up
// it owns the keyboard, so the task view claims nothing.
commands app_frame::task_view_run_command() const
{
if (ui::command_active != 0) return commands::none;
switch (_state.view_mode())
{
case view_type::rename:
case view_type::batch: return commands::tool_run;
case view_type::import: return commands::import_run;
case view_type::sync: return commands::sync_run;
case view_type::locate: return commands::locate_run;
case view_type::tags: return commands::tags_run;
default: return commands::none;
}
}
void app_frame::update_button_state(const bool resize)
{
// Not cached: the update snooze is measured in days, so a session left open overnight has to
// see the new day arrive.
const auto now_days = core::utc_now().to_days();
if (!_has_burner) _has_burner = platform::has_burner();
const auto has_burner = *_has_burner;
const auto view_mode = _state.view_mode();
const auto view_processing = _view && _view->progress().active;
const auto selection_status = _state.selection_status();
const auto is_playing = selection_status.is_playing;
const auto is_playing_media = selection_status.is_playing_media;
const auto can_play_media = selection_status.can_play_media;
const auto is_slideshow = selection_status.is_slideshow;
const auto can_zoom = selection_status.can_zoom;
const auto display = _state.display_state();
const auto is_maximized = _app_frame->is_maximized();
const auto is_edit_view = ui::command_active == 0 && view_mode == view_type::edit;
const auto is_items_view = ui::command_active == 0 && view_mode == view_type::items;
const auto is_media_view = ui::command_active == 0 && view_mode == view_type::media;
const auto is_media_or_items_view = ui::command_active == 0 && (view_mode == view_type::items || view_mode ==
view_type::media);
const auto has_selection = is_media_or_items_view && _state.has_selection();
const auto has_movie_selection = is_media_or_items_view && std::any_of(
_state.selected_items().items().begin(), _state.selected_items().items().end(), [](const auto& item)
{
const auto* const type = item->file_type();
return type && (type->group == file_group::photo || type->group == file_group::video);
});
const auto is_single_media_selection = is_media_or_items_view && selection_status.has_single_media_selection;
const auto local_files_result = _state.selection_process_result(df::process_items_type::local_file);
const auto local_items_result = _state.selection_process_result(df::process_items_type::local_file_or_folder);
const auto save_metadata_result = _state.selection_process_result(df::process_items_type::can_save_metadata);
const auto save_pixels_result = _state.selection_process_result(df::process_items_type::can_save_pixels);
const auto photos_only_result = _state.selection_process_result(df::process_items_type::photos_only);
const auto can_process_local_files = is_media_or_items_view && local_files_result.success();
const auto can_process_local_items = is_media_or_items_view && local_items_result.success();
const auto can_save_metadata = is_media_or_items_view && save_metadata_result.success();
const auto can_save_pixels = is_media_or_items_view && save_pixels_result.success();
#ifndef WINSTORE
const auto new_version_avail = is_media_or_items_view &&
core::version(s_app_version) < core::version(setting.available_version) && static_cast<int>(now_days) >= setting.
min_show_update_day;
const auto show_new_version = is_media_or_items_view && (setting.force_available_version || new_version_avail);
#endif
const auto command_item = _state.command_item();
const auto is_displaying_item = is_media_or_items_view && command_item;
const auto search_has_selector = _state.search().has_selector(); // This line remains unchanged
const auto has_save_folder = _state.search().is_showing_folder();
#ifndef WINSTORE
_commands[commands::info_new_version]->visible = !is_edit_view && show_new_version;
// The whole point of this button is to be noticed, so it carries the accent fill.
_commands[commands::info_new_version]->highlight = true;
#endif
_commands[commands::view_maximize]->visible = !is_maximized;
_commands[commands::view_restore]->visible = is_maximized;
_commands[commands::view_show_sidebar]->visible = !is_edit_view;
_commands[commands::browse_forward]->visible = !is_edit_view;
_commands[commands::advanced_search]->enable = is_media_or_items_view;
_commands[commands::browse_back]->enable = is_media_or_items_view && _state.history.can_browse_back();
_commands[commands::browse_forward]->enable = is_media_or_items_view && _state.history.can_browse_forward();
_commands[commands::browse_next_folder]->enable = is_items_view && _state.has_next_path(true);
_commands[commands::browse_next_group]->enable = is_media_or_items_view && _state.has_display_items();
_commands[commands::browse_next_item]->enable = is_media_or_items_view && _state.has_display_items();
_commands[commands::browse_next_item_extend]->enable = is_media_or_items_view && _state.has_display_items();
_commands[commands::browse_open_containingfolder]->enable = is_media_or_items_view && is_displaying_item;
_commands[commands::browse_open_googlemap]->enable = is_media_or_items_view && _state.has_gps();
_commands[commands::browse_open_in_file_browser]->enable = is_media_or_items_view && has_selection;
// In the media view Parent returns to the items view; in the items view it broadens the scope.
_commands[commands::browse_parent]->enable = is_media_view || (is_items_view && _state.has_parent_search());
_commands[commands::browse_previous_folder]->enable = is_items_view && _state.has_next_path(false);
_commands[commands::browse_previous_group]->enable = is_media_or_items_view && _state.has_display_items();
_commands[commands::browse_previous_item]->enable = is_media_or_items_view && _state.has_display_items();
_commands[commands::browse_previous_item_extend]->enable = is_media_or_items_view && _state.has_display_items();
_commands[commands::browse_recursive]->enable = is_items_view && search_has_selector;
_commands[commands::browse_search]->enable = is_items_view;
_commands[commands::edit_copy]->enable = can_process_local_items;
_commands[commands::edit_copy_item_path]->enable = can_process_local_items;
// Cut runs the same eligibility test as Copy when invoked, so it answers the same way here. Enabled
// on a bare selection, it offered itself for offline items and outside the item views only to
// refuse once chosen.
_commands[commands::edit_cut]->enable = can_process_local_items;
const auto can_edit_pixels = is_edit_view && _view_edit && _view_edit->can_edit_pixels();
_commands[commands::edit_item_auto_color]->enable = can_edit_pixels;
_commands[commands::edit_item_auto_document]->enable = can_edit_pixels;
_commands[commands::edit_item_auto_straighten]->enable = can_edit_pixels;
_commands[commands::edit_item_preview]->enable = can_edit_pixels;
_commands[commands::edit_item_color_reset]->enable = can_edit_pixels;
_commands[commands::edit_item_save]->enable = is_edit_view && _state._edit_item && edit_has_changes();
// In the locate view these run the same operation as locate_run, so they answer to the same
// test: an enabled button that writes nothing reads as a broken command.
const auto can_locate = view_mode == view_type::locate && _view_locate && _view_locate->can_run();
_commands[commands::edit_item_save_and_next]->enable = is_edit_view || can_locate;
_commands[commands::edit_item_save_and_prev]->enable = is_edit_view || can_locate;
const auto locate_view = view_mode == view_type::locate;
const auto previous_text = locate_view ? tt.command_locate_and_back.sv() : tt.command_save_and_back.sv();
const auto next_text = locate_view ? tt.command_locate_and_next.sv() : tt.command_save_and_next.sv();
update_toolbar_text(commands::edit_item_save_and_prev, std::string(previous_text));
update_toolbar_text(commands::edit_item_save_and_next, std::string(next_text));
_commands[commands::edit_item_save_and_prev]->text = previous_text;
_commands[commands::edit_item_save_and_next]->text = next_text;
_commands[commands::edit_item_save_and_prev]->tooltip_text = locate_view
? std::string{}
: std::string(
tt.command_save_and_back_tooltip.sv());
_commands[commands::edit_item_save_and_next]->tooltip_text = locate_view
? std::string{}
: std::string(
tt.command_save_and_next_tooltip.sv());
_commands[commands::edit_item_save_as]->enable = can_edit_pixels;
_commands[commands::edit_paste]->enable = is_items_view && has_save_folder;
_commands[commands::english]->enable = true;
_commands[commands::exit]->enable = true;
_commands[commands::favorite]->enable = is_media_or_items_view;
_commands[commands::filter_items]->enable = is_items_view;
_commands[commands::filter_audio]->enable = is_items_view;
_commands[commands::filter_photos]->enable = is_items_view;
_commands[commands::filter_videos]->enable = is_items_view;
// A related search groups by relation, so choosing a grouping would change nothing visible.
const auto can_group = is_items_view && _state.effective_group_order() == _state.group_order();
_commands[commands::group_album]->enable = can_group;
_commands[commands::group_aspect_ratio]->enable = can_group;
_commands[commands::group_camera]->enable = can_group;
_commands[commands::group_created]->enable = can_group;
_commands[commands::group_original]->enable = can_group;
_commands[commands::group_extension]->enable = can_group;
_commands[commands::group_file_type]->enable = can_group;
_commands[commands::group_folder]->enable = can_group;
_commands[commands::group_location]->enable = can_group;
_commands[commands::group_modified]->enable = can_group;
_commands[commands::group_pixels]->enable = can_group;
_commands[commands::group_presence]->enable = can_group;
_commands[commands::group_rating]->enable = can_group;
_commands[commands::group_shuffle]->enable = can_group;
_commands[commands::group_size]->enable = can_group;
_commands[commands::group_toggle]->enable = can_group;
_commands[commands::import_analyze]->enable = view_mode == view_type::import && !view_processing && _view_import &&
_view_import->can_analyze();
_commands[commands::import_run]->enable = view_mode == view_type::import && !view_processing && _view_import &&
_view_import->can_run();
#ifndef WINSTORE
// Must match the visibility test above: a button that appears only to sit dimmed reads as broken.
_commands[commands::info_new_version]->enable = is_media_or_items_view;
_commands[commands::info_check_for_updates]->enable = true;
#endif
// The keyboard reference reads command state; like Help it answers from anywhere.
_commands[commands::keyboard]->enable = true;
_commands[commands::label_approved]->enable = can_save_metadata;
_commands[commands::label_none]->enable = can_save_metadata;
_commands[commands::label_review]->enable = can_save_metadata;
_commands[commands::label_second]->enable = can_save_metadata;
_commands[commands::label_select]->enable = can_save_metadata;
_commands[commands::label_to_do]->enable = can_save_metadata;
_commands[commands::large_font]->enable = true;
_commands[commands::menu_display_options]->enable = true;
_commands[commands::menu_group]->enable = true;
_commands[commands::menu_group_toolbar]->enable = true;
_commands[commands::menu_language]->enable = true;
_commands[commands::menu_main]->enable = true;
_commands[commands::menu_navigate]->enable = true;
_commands[commands::menu_open]->enable = has_selection;
_commands[commands::menu_open_status]->enable = has_selection;
_commands[commands::menu_options]->enable = true;
_commands[commands::menu_playback]->enable = is_media_or_items_view;
auto playback_toolbar_text = std::string(tt.command_playback_toolbar.sv());
if (display && display->is_one() && display->_player_media_info.has_multiple_audio_streams)
{
auto audio_track_number = 0;
for (const auto& stream : display->_player_media_info.streams)
{
if (stream.type != av_stream_type::audio) continue;
++audio_track_number;
if (stream.is_playing)
{
playback_toolbar_text = str_format(tt.audio_track_current_fmt.sv(),
format_audio_stream_name(stream, audio_track_number));
break;
}
}
}
update_toolbar_text(commands::menu_playback, playback_toolbar_text);
// The parent must answer the same test as the entries it opens, or it promises what they refuse.
_commands[commands::menu_rate_or_label]->enable = can_save_metadata;
_commands[commands::menu_select]->enable = true;
_commands[commands::menu_tools]->enable = has_selection;
_commands[commands::menu_tools_toolbar]->enable = has_selection;
_commands[commands::option_highlight_large_items]->enable = is_items_view;
_commands[commands::option_scale_up]->enable = is_media_or_items_view;
_commands[commands::option_show_rotated]->enable = is_media_or_items_view;
_commands[commands::option_toggle_details]->enable = is_items_view;
_commands[commands::option_toggle_item_size]->enable = is_items_view;
_commands[commands::options]->enable = is_media_or_items_view;
_commands[commands::options_sidebar]->enable = is_media_or_items_view;
_commands[commands::options_save]->enable = view_mode == view_type::options;
_commands[commands::options_cancel]->enable = view_mode == view_type::options;
_commands[commands::options_help]->enable = view_mode == view_type::options;
_commands[commands::favorite_tags]->enable = is_media_or_items_view || view_mode == view_type::tags;
_commands[commands::pin_item]->enable = is_media_or_items_view && (_state.has_pin() || _state.focus_item() !=
nullptr);
_commands[commands::play]->enable = is_media_or_items_view && (can_play_media || is_playing);
_commands[commands::slideshow]->enable = is_media_or_items_view && _state.can_slideshow();
_commands[commands::playback_auto_play]->enable = is_media_or_items_view;
_commands[commands::playback_auto_advance]->enable = is_media_or_items_view;
_commands[commands::playback_last_played_pos]->enable = is_media_or_items_view;
_commands[commands::playback_menu]->enable = is_media_or_items_view;
_commands[commands::playback_repeat_all]->enable = is_media_or_items_view;
_commands[commands::playback_repeat_none]->enable = is_media_or_items_view;
_commands[commands::playback_repeat_one]->enable = is_media_or_items_view;
_commands[commands::playback_volume_toggle]->enable = is_media_or_items_view;
_commands[commands::playback_volume0]->enable = is_media_or_items_view;
_commands[commands::playback_volume100]->enable = is_media_or_items_view;
_commands[commands::playback_volume200]->enable = is_media_or_items_view;
_commands[commands::playback_volume25]->enable = is_media_or_items_view;
_commands[commands::playback_volume50]->enable = is_media_or_items_view;
_commands[commands::playback_volume75]->enable = is_media_or_items_view;
_commands[commands::print]->enable = can_process_local_files;
_commands[commands::rate_1]->enable = can_save_metadata;
_commands[commands::rate_2]->enable = can_save_metadata;
_commands[commands::rate_3]->enable = can_save_metadata;
_commands[commands::rate_4]->enable = can_save_metadata;
_commands[commands::rate_5]->enable = can_save_metadata;
_commands[commands::rate_none]->enable = can_save_metadata;
_commands[commands::rate_rejected]->enable = can_save_metadata;
_commands[commands::refresh]->enable = true;
// Refresh belongs to the batch view for as long as it is open, not just after a run: it always
// means "re-plan from what is on disk now", and a button that appears only once is a button
// nobody finds. A finished run keeps its results until it is pressed.
const auto is_batch_view = view_mode == view_type::batch && _view_batch;
_commands[commands::tool_refresh]->visible = is_batch_view;
_commands[commands::tool_refresh]->enable = is_batch_view && _view_batch->can_refresh();
_commands[commands::tool_run]->enable = !view_processing && ((view_mode == view_type::rename && _view_rename &&
_view_rename->can_run()) || (view_mode == view_type::batch && _view_batch && _view_batch->can_run()));
// One toolbar serves the rename view and every batch tool, so the run button must name the
// operation the current view will actually perform.
const auto run_text = (view_mode == view_type::batch && _view_batch)
? _view_batch->run_text().sv()
: tt.command_rename_files.sv();
update_toolbar_text(commands::tool_run, std::string(run_text));
_commands[commands::tool_run]->text = run_text;
_commands[commands::locate_run]->enable = view_mode == view_type::locate && _view_locate && _view_locate->can_run();
_commands[commands::repeat_toggle]->enable = is_media_or_items_view;
_commands[commands::search_related]->enable = is_media_or_items_view && is_displaying_item;
_commands[commands::select_all]->enable = is_media_or_items_view;
_commands[commands::select_invert]->enable = is_media_or_items_view;
_commands[commands::select_nothing]->enable = is_media_or_items_view && has_selection;
_commands[commands::show_raw_preview]->enable = is_media_or_items_view;
_commands[commands::sort_date_created]->enable = is_media_or_items_view;
_commands[commands::sort_date_original]->enable = is_media_or_items_view;
_commands[commands::sort_date_modified]->enable = is_media_or_items_view;
_commands[commands::sort_dates_ascending]->enable = is_media_or_items_view;
_commands[commands::sort_dates_descending]->enable = is_media_or_items_view;
_commands[commands::sort_def]->enable = is_media_or_items_view;
_commands[commands::sort_name]->enable = is_media_or_items_view;
_commands[commands::sort_size]->enable = is_media_or_items_view;
_commands[commands::sync_analyze]->enable = view_mode == view_type::sync && !view_processing && _view_sync &&
_view_sync->can_analyze();
_commands[commands::sync_run]->enable = view_mode == view_type::sync && !view_processing && _view_sync &&
_view_sync->can_run();
_commands[commands::tags_run]->enable = view_mode == view_type::tags && !view_processing && _view_tags &&
_view_tags->can_run();
_commands[commands::tool_adjust_date]->enable = can_save_metadata;
// A machine with no writer cannot burn at all, and design.md is explicit that a capability the
// platform lacks is absent rather than dimmed - dimming would say "not now" forever.
_commands[commands::tool_burn]->visible = has_burner;
_commands[commands::tool_burn]->enable = has_selection && has_burner;
_commands[commands::tool_convert]->enable = is_media_or_items_view && photos_only_result.success();
_commands[commands::tool_copy_to_folder]->enable = can_process_local_items;
_commands[commands::tool_delete]->enable = can_process_local_items;
_commands[commands::tool_desktop_background]->enable = is_media_or_items_view && selection_status.showing_image;
_commands[commands::tool_edit]->enable = is_media_or_items_view && _state.can_edit_media();
_commands[commands::tool_edit_description]->enable = can_save_metadata;
_commands[commands::tool_edit_metadata]->enable = can_save_metadata;
_commands[commands::tool_share]->enable = can_process_local_files;
// Ejecting a drive does not depend on what is being browsed, so it answers from every view.
_commands[commands::tool_eject]->enable = true;
_commands[commands::tool_file_properties]->enable = has_selection;
_commands[commands::tool_import]->enable = is_media_or_items_view;
_commands[commands::tool_locate]->enable = can_save_metadata;
_commands[commands::tool_move_to_folder]->enable = can_process_local_items;
const auto is_movie_view = view_mode == view_type::movie && _view_movie;
// A timeline outlives the view, so clearing the selection must not lock the user out of the
// movie they are part way through building.
_commands[commands::tool_movie]->enable = is_media_or_items_view &&
(has_movie_selection || (_view_movie && _view_movie->has_clips()));
const auto movie_project_busy = is_movie_view && _view_movie->project_io_active();
_commands[commands::tool_movie_add]->enable = is_movie_view && !movie_project_busy;
_commands[commands::tool_movie_open]->enable = is_movie_view && !movie_project_busy;
_commands[commands::tool_movie_import]->enable = is_movie_view && !movie_project_busy;
_commands[commands::tool_movie_save]->enable = is_movie_view && !movie_project_busy && _view_movie->can_save_project();
_commands[commands::tool_movie_remove]->enable = is_movie_view && _view_movie->has_clips();
_commands[commands::tool_movie_send_to_end]->enable = is_movie_view && _view_movie->has_clips();
_commands[commands::tool_movie_select_all]->enable = is_movie_view && _view_movie->has_clips();
// Nothing to repair is not the same as a repair that is unavailable, so the offer appears only
// once the probe has found a clip that is gone.
_commands[commands::tool_movie_relink]->visible = is_movie_view && _view_movie->has_missing_clips();
_commands[commands::tool_movie_relink]->enable = is_movie_view && !movie_project_busy && _view_movie->has_missing_clips();
// A machine with no encoder cannot render at all, so Render is absent rather than dimmed, as
// Burn is on a machine with no writer. The answer comes from the startup worker.
const auto can_write_movies = _can_write_movies.value_or(false);
_commands[commands::tool_movie_render]->visible = can_write_movies;
_commands[commands::tool_movie_render]->enable = is_movie_view && !view_processing && can_write_movies &&
_view_movie->can_render();
_commands[commands::tool_new_folder]->enable = is_media_or_items_view && has_save_folder;
_commands[commands::tool_open_with]->enable = has_selection;
_commands[commands::tool_rename]->enable = can_process_local_items;
_commands[commands::tool_rotate_anticlockwise]->enable = can_save_pixels;
_commands[commands::tool_rotate_clockwise]->enable = can_save_pixels;
_commands[commands::tool_rotate_reset]->enable = is_edit_view;
_commands[commands::tool_save_current_video_frame]->enable = is_single_media_selection;
_commands[commands::tool_scan]->enable = is_media_or_items_view;
_commands[commands::tool_sync]->enable = is_media_or_items_view;
_commands[commands::tool_tag]->enable = can_save_metadata;
_commands[commands::verbose_metadata]->enable = is_media_or_items_view;
// Close belongs to the task views, and Items to everything that is not already Items. Both are
// tested by view alone: a command running in Items must not make either of them available.
_commands[commands::view_close]->enable = view_mode != view_type::items && view_mode != view_type::media;
// Cancel is a distinct command from Close: it stops the running task and leaves the view open.
_commands[commands::view_cancel]->enable = view_processing;
_commands[commands::view_cancel]->visible = view_processing;
const auto close_text_changed = update_toolbar_text(commands::view_close, std::string(tt.command_close.sv()));
_commands[commands::view_favorite_tags]->enable = is_media_or_items_view;
_commands[commands::view_fullscreen]->enable = is_media_or_items_view;
_commands[commands::view_help]->enable = true;
_commands[commands::view_items]->enable = view_mode != view_type::items;
_commands[commands::view_maximize]->enable = true;
_commands[commands::view_minimize]->enable = true;
_commands[commands::view_restore]->enable = true;
_commands[commands::view_show_sidebar]->enable = is_items_view;
_commands[commands::view_zoom]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_fit]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_fit_width]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_fill]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_toggle_fit]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_in]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_pane_flip]->enable = is_media_or_items_view && display && display->is_two() &&
can_zoom;
_commands[commands::view_zoom_out]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_100]->enable = is_media_or_items_view && can_zoom;
_commands[commands::menu_zoom]->enable = is_media_or_items_view && can_zoom;
_commands[commands::menu_zoom_navigator]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_navigator_auto_hide]->enable = is_media_or_items_view && can_zoom;
_commands[commands::view_zoom_navigator_off]->enable = is_media_or_items_view && can_zoom;
// A dimmed button is only honest if it says what would make it work again, so every command
// gated on selection eligibility carries that test's own failure text while it is disabled.
const auto set_disabled_reasons = [this, is_media_or_items_view](const df::process_result& result,
const std::initializer_list<commands> ids)
{