Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ deunicode = "1.6"
url = { version = "2", default-features = false, features = ["std"] }
uuid = { version = "1", features = ["v4"] }
email_address = "0.2"
open = "5"

[dev-dependencies]
tempfile = "3.14"
Expand Down
25 changes: 25 additions & 0 deletions src/mvu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum Msg {
SaveRequested(PathBuf),
SaveCancelled,
SaveCompleted(Result<PathBuf, String>),
OpenHelp,
HelpOpened(Result<(), String>),
ThumbnailDecoded {
path: PathBuf,
image: eframe::egui::ColorImage,
Expand All @@ -76,6 +78,7 @@ pub enum Command {
HashFile { path: PathBuf, _retry: bool },
LoadThumbnail { path: PathBuf, _retry: bool },
PickExtraFieldsFile,
OpenUrl { url: String },
SaveArchive(SavePayload),
}

Expand Down Expand Up @@ -209,6 +212,24 @@ pub fn update(model: &mut AppModel, msg: Msg, cmds: &mut Vec<Command>) {
Ok(path) => surface_event(model, format!("Archive saved: {}", path.display()), false),
Err(err) => surface_event(model, format!("Failed to save archive:\n\n{err}"), true),
},
Msg::OpenHelp => {
cmds.push(Command::OpenUrl {
url: "https://athemis.github.io/ELNPack/".to_string(),
});
surface_event(
model,
"Opening ELNPack user guide in your browser…".into(),
false,
);
}
Msg::HelpOpened(result) => match result {
Ok(()) => surface_event(model, "Help opened in browser.".into(), false),
Err(err) => surface_event(
model,
format!("Could not open help page: {err}"),
true,
),
},
}
}

Expand Down Expand Up @@ -300,6 +321,10 @@ pub fn run_command(cmd: Command) -> Msg {
.map(|_| payload.output.clone());
Msg::SaveCompleted(res.map_err(|e| e.to_string()))
}
Command::OpenUrl { url } => {
let res = open::that(url).map(|_| ());
Msg::HelpOpened(res.map_err(|e| e.to_string()))
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl eframe::App for ElnPackApp {
ui.horizontal(|ui| {
ui.heading("ELN Entry");
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
self.render_help_button(ui);
self.render_theme_controls(ui);
ui.separator();
self.render_save_button(ui);
Expand Down Expand Up @@ -166,6 +167,19 @@ impl ElnPackApp {
egui::widgets::global_theme_preference_switch(ui);
}

/// Render a compact help button that opens the hosted user guide in a browser tab.
fn render_help_button(&mut self, ui: &mut egui::Ui) {
ui.add_space(2.0);
let button = egui::Button::new(egui_phosphor::regular::QUESTION);
if ui
.add(button)
.on_hover_text("Open the ELNPack user guide")
.clicked()
{
self.inbox.push(Msg::OpenHelp);
}
}

/// Renders the "Save ELN archive" button and, when activated, opens a file-save dialog to request saving the current entry.
///
/// 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.
Expand Down
Loading