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
|
/* Copyright 2016 Software Freedom Conservancy Inc.
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
public class FacePage : CollectionPage {
private Face face;
public FacePage(Face face) {
base (face.get_name());
this.face = face;
Face.global.items_altered.connect(on_faces_altered);
face.mirror_sources(get_view(), create_thumbnail);
init_page_context_menu("FacesContextMenu");
}
~FacePage() {
get_view().halt_mirroring();
Face.global.items_altered.disconnect(on_faces_altered);
}
protected override void init_collect_ui_filenames(Gee.List<string> ui_filenames) {
base.init_collect_ui_filenames(ui_filenames);
ui_filenames.add("faces.ui");
}
public Face get_face() {
return face;
}
protected override void get_config_photos_sort(out bool sort_order, out int sort_by) {
Config.Facade.get_instance().get_event_photos_sort(out sort_order, out sort_by);
}
protected override void set_config_photos_sort(bool sort_order, int sort_by) {
Config.Facade.get_instance().set_event_photos_sort(sort_order, sort_by);
}
private const GLib.ActionEntry[] entries = {
{ "DeleteFace", on_delete_face },
{ "RenameFace", on_rename_face },
{ "RemoveFaceFromPhotos", on_remove_face_from_photos },
{ "SetFaceRefFromPhoto", on_set_face_ref },
{ "DeleteFaceSidebar", on_delete_face },
{ "RenameFaceSidebar", on_rename_face }
};
protected override void init_actions(int selected_count, int count) {
base.init_actions(selected_count, count);
set_action_sensitive("DeleteFace", true);
set_action_sensitive("RenameFace", true);
set_action_sensitive("RemoveFaceFromPhotos", true);
}
protected override void add_actions (GLib.ActionMap map) {
base.add_actions (map);
map.add_action_entries (entries, this);
}
protected override InjectionGroup[] init_collect_injection_groups() {
InjectionGroup[] groups = base.init_collect_injection_groups();
groups += create_faces_menu_injectables();
return groups;
}
private InjectionGroup create_faces_menu_injectables(){
InjectionGroup menuFaces = new InjectionGroup("FacesMenuPlaceholder");
menuFaces.add_menu_item(Resources.remove_face_from_photos_menu(this.face.get_name(), get_view().get_count()), "RemoveFaceFromPhotos", "<Primary>r");
menuFaces.add_menu_item(Resources.rename_face_menu(this.face.get_name()), "RenameFace", "<Primary>e");
menuFaces.add_menu_item(Resources.set_face_from_photo_menu(this.face.get_name()), "SetFaceRefFromPhoto", null);
menuFaces.add_menu_item(Resources.delete_face_menu(this.face.get_name()), "DeleteFace", "<Primary>t");
return menuFaces;
}
private void on_faces_altered(Gee.Map<DataObject, Alteration> map) {
if (map.has_key(face)) {
set_page_name(face.get_name());
update_actions(get_view().get_selected_count(), get_view().get_count());
}
}
protected override void update_actions(int selected_count, int count) {
set_action_details("DeleteFace",
Resources.delete_face_menu(face.get_name()),
null,
true);
set_action_details("RenameFace",
Resources.rename_face_menu(face.get_name()),
null,
true);
set_action_details("RemoveFaceFromPhotos",
Resources.remove_face_from_photos_menu(face.get_name(), get_view().get_count()),
null,
selected_count > 0);
set_action_details("SetFaceRefFromPhoto",
Resources.set_face_from_photo_menu(face.get_name()),
null,
selected_count == 1);
base.update_actions(selected_count, count);
}
private void on_rename_face() {
LibraryWindow.get_app().rename_face_in_sidebar(face);
}
private void on_delete_face() {
if (Dialogs.confirm_delete_face(face))
AppWindow.get_command_manager().execute(new DeleteFaceCommand(face));
}
private void on_remove_face_from_photos() {
if (get_view().get_selected_count() > 0) {
get_command_manager().execute(new RemoveFacesFromPhotosCommand(face,
(Gee.Collection<MediaSource>) get_view().get_selected_sources()));
}
}
private void on_set_face_ref() {
if (get_view().get_selected_count() == 1) {
get_command_manager().execute(new SetFaceRefCommand(face,
(MediaSource) get_view().get_selected_at(0).get_source()));
}
}
}
|