Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M3: opening a file and expanding All tools take the usual workspace path

alehelcb21b2cce4c4
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 81184ce68..0cd9a2934 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1426,6 +1426,10 @@ impl PdfCraftApp {
{
view.open_organize();
}
+ // The document shows, not the expanded All tools view over it (whichever workspace opens).
+ if activate {
+ self.all_tools_full = false;
+ }
if activate && let Some(mode) = self.mode_override {
// Explicit mode options do not reset independent --tool / --left choices.
self.mode = mode;
@@ -2286,6 +2290,10 @@ impl PdfCraftApp {
/// again and applies a paragraph still open in the editor.
fn enter_mode(&mut self, mode: Mode) {
self.mode = mode;
+ // Another workspace puts the expanded All tools view away.
+ if mode != Mode::AllTools {
+ self.all_tools_full = false;
+ }
if mode == Mode::Edit {
self.quick_tool = QuickTool::EditText;
} else if matches!(self.quick_tool, QuickTool::EditText | QuickTool::AddText) {
@@ -2298,6 +2306,15 @@ impl PdfCraftApp {
}
}
+ /// Fill the workspace with the expanded All tools view, entering All tools the way the mode
+ /// bar does: leaving Read restores its right panel and leaving Edit puts the editing tool down.
+ pub(crate) fn expand_all_tools(&mut self) {
+ if self.mode != Mode::AllTools {
+ self.switch_mode(Mode::AllTools, true);
+ }
+ self.all_tools_full = true;
+ }
+
/// Back to the Select tool from an editing tool. A paragraph still open in the editor is
/// applied, as clicking away from it does; left open, its page would keep showing the
/// paragraph's text removed with no editor over it.
@@ -2316,10 +2333,6 @@ impl PdfCraftApp {
/// Read mode hides the quick toolbar, so entering it also puts the current tool down.
pub(crate) fn switch_mode(&mut self, mode: Mode, select_tools: bool) {
let was_read = self.mode == Mode::Read;
- // Another workspace puts the expanded All tools view away.
- if mode != Mode::AllTools {
- self.all_tools_full = false;
- }
if select_tools {
self.select_mode(mode);
} else {
@@ -2730,10 +2743,7 @@ impl PdfCraftApp {
_ => Some(Dialog::About),
}
}
- ("tools", _) if value == "full" => {
- self.mode = Mode::AllTools;
- self.all_tools_full = true;
- }
+ ("tools", _) if value == "full" => self.expand_all_tools(),
("tools", _) => {
self.all_tools_full = false;
self.all_tools_expanded = value != "collapsed";
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index f4fbb397a..ebddd320b 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -66,8 +66,7 @@ fn all_tools(app: &mut PdfCraftApp, ui: &mut egui::Ui, t: &Tokens) {
// Labels distinct from the Combine grid's Expand and Collapse, which can show beside them.
let (expand, close) = panel_header(ui, t, "All tools", Some(("maximize-2", tl!("Expand all tools"))));
if expand {
- app.all_tools_full = true;
- app.mode = crate::Mode::AllTools;
+ app.expand_all_tools();
}
if close {
app.left_open = false;
diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs
index 8416e3460..f65da9ac6 100644
--- a/crates/ui-egui/tests/ui.rs
+++ b/crates/ui-egui/tests/ui.rs
@@ -190,6 +190,51 @@ fn another_workspace_from_the_mode_option_puts_the_expanded_all_tools_away() {
assert!(!app.all_tools_full, "coming back shows the sidebar, as the mode bar does");
}
+#[test]
+fn opening_a_document_puts_the_expanded_all_tools_away() {
+ use pdfcraft_ui_egui::Mode;
+ // All tools as the default workspace: no workspace change, but the document must show.
+ let mut app = PdfCraftApp::new();
+ app.set_option("tools", "full").unwrap();
+ app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens");
+ assert!(!app.all_tools_full, "the document shows, not the catalogue over it");
+ // Read as the default workspace: coming back to All tools later shows the sidebar.
+ let mut app = PdfCraftApp::new();
+ app.set_option("default-mode", "read").unwrap();
+ app.set_option("tools", "full").unwrap();
+ app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens");
+ assert_eq!(app.mode, Mode::Read);
+ assert!(!app.all_tools_full);
+}
+
+#[test]
+fn expanding_all_tools_from_read_mode_restores_the_right_panel() {
+ use pdfcraft_ui_egui::{Mode, RightPanel};
+ let mut h = harness(|app| app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));
+ h.state_mut().right = Some(RightPanel::Bookmarks);
+ h.state_mut().execute("view.read_mode");
+ h.run_steps(3);
+ assert_eq!((h.state().mode, h.state().right), (Mode::Read, None), "Read mode hides the panel");
+ h.state_mut().set_option("tools", "full").unwrap();
+ h.run_steps(3);
+ assert!(h.state().all_tools_full);
+ assert_eq!((h.state().mode, h.state().right), (Mode::AllTools, Some(RightPanel::Bookmarks)));
+}
+
+#[test]
+fn expanding_all_tools_from_edit_puts_edit_text_down() {
+ use pdfcraft_ui_egui::{LeftPanel, Mode, QuickTool};
+ let mut h = harness(|app| app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));
+ h.get_by_label("Edit").click();
+ h.run_steps(3);
+ assert_eq!(h.state().quick_tool, QuickTool::EditText);
+ h.state_mut().set_option("tools", "full").unwrap();
+ h.run_steps(3);
+ assert!(h.state().all_tools_full);
+ assert_eq!((h.state().mode, h.state().quick_tool), (Mode::AllTools, QuickTool::Select));
+ assert_eq!(h.state().left, LeftPanel::AllTools, "collapsing goes back to the All tools list");
+}
+
#[test]
fn opening_a_pdf_shows_comments_and_bookmarks() {
let mut h = harness(|app| app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));