cadmus_core/view/settings_editor/kinds/
library.rs1use super::{SettingData, SettingIdentity, SettingKind, WidgetKind};
4use crate::fl;
5use crate::geom::Rectangle;
6use crate::i18n::I18nDisplay;
7use crate::settings::{FinishedAction, Settings};
8use crate::view::{EntryId, EntryKind, Event};
9
10pub struct LibraryInfo(pub usize);
12
13impl SettingKind for LibraryInfo {
14 fn identity(&self) -> SettingIdentity {
15 SettingIdentity::LibraryInfo(self.0)
16 }
17
18 fn label(&self, settings: &Settings) -> String {
19 settings
20 .libraries
21 .get(self.0)
22 .map(|lib| lib.name.clone())
23 .unwrap_or_else(|| fl!("settings-general-unknown"))
24 }
25
26 fn fetch(&self, settings: &Settings) -> SettingData {
27 let value = settings
28 .libraries
29 .get(self.0)
30 .map(|lib| lib.path.display().to_string())
31 .unwrap_or_else(|| fl!("settings-general-unknown"));
32
33 SettingData {
34 value,
35 widget: WidgetKind::ActionLabel(Event::EditLibrary(self.0)),
36 }
37 }
38
39 fn hold_event(&self, rect: Rectangle) -> Option<Event> {
40 let entries = vec![EntryKind::Command(
41 fl!("delete"),
42 EntryId::DeleteLibrary(self.0),
43 )];
44
45 Some(Event::SubMenu(rect, entries))
46 }
47}
48
49pub struct LibraryName(pub usize);
51
52impl SettingKind for LibraryName {
53 fn identity(&self) -> SettingIdentity {
54 SettingIdentity::LibraryName(self.0)
55 }
56
57 fn label(&self, _settings: &Settings) -> String {
58 fl!("settings-library-name")
59 }
60
61 fn fetch(&self, settings: &Settings) -> SettingData {
62 let value = settings
63 .libraries
64 .get(self.0)
65 .map(|lib| lib.name.clone())
66 .unwrap_or_else(|| fl!("settings-general-unknown"));
67
68 SettingData {
69 value,
70 widget: WidgetKind::ActionLabel(Event::Select(EntryId::EditLibraryName)),
71 }
72 }
73}
74
75pub struct LibraryPath(pub usize);
77
78impl SettingKind for LibraryPath {
79 fn identity(&self) -> SettingIdentity {
80 SettingIdentity::LibraryPath(self.0)
81 }
82
83 fn label(&self, _settings: &Settings) -> String {
84 fl!("settings-library-path")
85 }
86
87 fn fetch(&self, settings: &Settings) -> SettingData {
88 let value = settings
89 .libraries
90 .get(self.0)
91 .map(|lib| lib.path.display().to_string())
92 .unwrap_or_else(|| fl!("settings-general-unknown"));
93
94 SettingData {
95 value,
96 widget: WidgetKind::ActionLabel(Event::Select(EntryId::EditLibraryPath)),
97 }
98 }
99}
100
101pub struct LibraryFinishedAction(pub usize);
103
104impl SettingKind for LibraryFinishedAction {
105 fn identity(&self) -> SettingIdentity {
106 SettingIdentity::LibraryFinishedAction(self.0)
107 }
108
109 fn label(&self, _settings: &Settings) -> String {
110 fl!("settings-library-end-of-book-action")
111 }
112
113 fn fetch(&self, settings: &Settings) -> SettingData {
114 let index = self.0;
115 let current = settings.libraries.get(index).and_then(|lib| lib.finished);
116
117 let value = current
118 .map(|action| action.to_i18n_string())
119 .unwrap_or_else(|| fl!("settings-library-inherit"));
120
121 let entries = vec![
122 EntryKind::RadioButton(
123 fl!("settings-library-inherit"),
124 EntryId::ClearLibraryFinishedAction(index),
125 current.is_none(),
126 ),
127 EntryKind::RadioButton(
128 FinishedAction::Notify.to_i18n_string(),
129 EntryId::SetLibraryFinishedAction(index, FinishedAction::Notify),
130 current == Some(FinishedAction::Notify),
131 ),
132 EntryKind::RadioButton(
133 FinishedAction::Close.to_i18n_string(),
134 EntryId::SetLibraryFinishedAction(index, FinishedAction::Close),
135 current == Some(FinishedAction::Close),
136 ),
137 EntryKind::RadioButton(
138 FinishedAction::GoToNext.to_i18n_string(),
139 EntryId::SetLibraryFinishedAction(index, FinishedAction::GoToNext),
140 current == Some(FinishedAction::GoToNext),
141 ),
142 ];
143
144 SettingData {
145 value,
146 widget: WidgetKind::SubMenu(entries),
147 }
148 }
149}