Skip to content

Commit 2f8760c

Browse files
authored
feat: add help button opening the user guide (#27)
* feat: add help button opening the user guide * style: adjust code formatting * style(ui): add label to help button
1 parent 252d236 commit 2f8760c

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

Cargo.lock

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ deunicode = "1.6"
3434
url = { version = "2", default-features = false, features = ["std"] }
3535
uuid = { version = "1", features = ["v4"] }
3636
email_address = "0.2"
37+
open = "5"
3738

3839
[dev-dependencies]
3940
tempfile = "3.14"

src/mvu/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub enum Msg {
5454
SaveRequested(PathBuf),
5555
SaveCancelled,
5656
SaveCompleted(Result<PathBuf, String>),
57+
OpenHelp,
58+
HelpOpened(Result<(), String>),
5759
ThumbnailDecoded {
5860
path: PathBuf,
5961
image: eframe::egui::ColorImage,
@@ -76,6 +78,7 @@ pub enum Command {
7678
HashFile { path: PathBuf, _retry: bool },
7779
LoadThumbnail { path: PathBuf, _retry: bool },
7880
PickExtraFieldsFile,
81+
OpenUrl { url: String },
7982
SaveArchive(SavePayload),
8083
}
8184

@@ -209,6 +212,20 @@ pub fn update(model: &mut AppModel, msg: Msg, cmds: &mut Vec<Command>) {
209212
Ok(path) => surface_event(model, format!("Archive saved: {}", path.display()), false),
210213
Err(err) => surface_event(model, format!("Failed to save archive:\n\n{err}"), true),
211214
},
215+
Msg::OpenHelp => {
216+
cmds.push(Command::OpenUrl {
217+
url: "https://athemis.github.io/ELNPack/".to_string(),
218+
});
219+
surface_event(
220+
model,
221+
"Opening ELNPack user guide in your browser…".into(),
222+
false,
223+
);
224+
}
225+
Msg::HelpOpened(result) => match result {
226+
Ok(()) => surface_event(model, "Help opened in browser.".into(), false),
227+
Err(err) => surface_event(model, format!("Could not open help page: {err}"), true),
228+
},
212229
}
213230
}
214231

@@ -300,6 +317,10 @@ pub fn run_command(cmd: Command) -> Msg {
300317
.map(|_| payload.output.clone());
301318
Msg::SaveCompleted(res.map_err(|e| e.to_string()))
302319
}
320+
Command::OpenUrl { url } => {
321+
let res = open::that(url).map(|_| ());
322+
Msg::HelpOpened(res.map_err(|e| e.to_string()))
323+
}
303324
}
304325
}
305326

src/ui/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ impl eframe::App for ElnPackApp {
106106
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
107107
self.render_theme_controls(ui);
108108
ui.separator();
109+
self.render_help_button(ui);
110+
ui.separator();
109111
self.render_save_button(ui);
110112
ui.separator();
111113
self.render_body_format_toggle(ui);
@@ -166,6 +168,19 @@ impl ElnPackApp {
166168
egui::widgets::global_theme_preference_switch(ui);
167169
}
168170

171+
/// Render a compact help button that opens the hosted user guide in a browser tab.
172+
fn render_help_button(&mut self, ui: &mut egui::Ui) {
173+
ui.add_space(2.0);
174+
let button = egui::Button::new(format!("{} Help", egui_phosphor::regular::QUESTION));
175+
if ui
176+
.add(button)
177+
.on_hover_text("Open the ELNPack user guide")
178+
.clicked()
179+
{
180+
self.inbox.push(Msg::OpenHelp);
181+
}
182+
}
183+
169184
/// Renders the "Save ELN archive" button and, when activated, opens a file-save dialog to request saving the current entry.
170185
///
171186
/// The button is enabled only when the entry title is not empty and there are no invalid extra fields. When the user selects a file the chosen path is normalized to have the `.eln` extension and a `Msg::SaveRequested(path)` is queued; if the dialog is cancelled a `Msg::SaveCancelled` is queued.

0 commit comments

Comments
 (0)