mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
Merge branch 'red7/g3' into area/app-1
This commit is contained in:
@@ -154,6 +154,7 @@ impl PdfCraftApp {
|
||||
then: request.then,
|
||||
display_override: None,
|
||||
ready: None,
|
||||
reopen: false,
|
||||
});
|
||||
token
|
||||
}
|
||||
@@ -245,6 +246,9 @@ impl PdfCraftApp {
|
||||
Ok(id) => {
|
||||
if let Some(path) = pending.path.as_deref() {
|
||||
self.watch.known_as(id, std::path::Path::new(path), pending.stamp);
|
||||
if pending.reopen {
|
||||
self.forget_closed_tab(path);
|
||||
}
|
||||
}
|
||||
if let Some(destination) = pending.after_open {
|
||||
self.apply_remote_destination(destination);
|
||||
|
||||
@@ -595,7 +595,7 @@ impl DocView {
|
||||
pages_focus_id: None,
|
||||
thumbnail_zoom: 1.0,
|
||||
grid_reveal: None,
|
||||
bookmarks_open: OpenSet::default(),
|
||||
bookmarks_open: crate::panels::bookmarks::opened_as_filed(&info.outline),
|
||||
redactions_applied: 0,
|
||||
redactions_undone_after_save: 0,
|
||||
saved_redactions_cut_off: false,
|
||||
|
||||
@@ -477,7 +477,13 @@ impl PreferencesModel for Prefs<'_> {
|
||||
// PdfCraft keeps its own appearance and no favourite themes (L-224).
|
||||
let suite = self.app.suite_view();
|
||||
let system_dark = craft::ui::runtime::env::system_appearance(self.ctx).appearance.mode == Some(craft::theme::Mode::Dark);
|
||||
AppearancePage::new(&suite, Bind::bound(&mut *self.selection)).text_size(false).system_dark(system_dark).show(ui);
|
||||
AppearancePage::new(&suite, Bind::bound(&mut *self.selection))
|
||||
.can_favorite(false)
|
||||
.size(false)
|
||||
.text_size(false)
|
||||
.contrast(false)
|
||||
.system_dark(system_dark)
|
||||
.show(ui);
|
||||
}
|
||||
|
||||
fn differs(&self) -> bool {
|
||||
|
||||
@@ -1552,7 +1552,13 @@ mod revert_draft_tests {
|
||||
}
|
||||
assert!(h.state().close_guard.is_some(), "the typed box holds the close");
|
||||
h.run_steps(2);
|
||||
press(&mut h, "Save");
|
||||
// The question's "save it" answer as the framework words it on this OS: Save on macOS, Yes elsewhere.
|
||||
let save = {
|
||||
use craft::i18n::WordSet as _;
|
||||
let words = craft::ui::dialog::DialogWords::english();
|
||||
if cfg!(target_os = "macos") { words.unsaved_save } else { words.unsaved_yes }.as_str().to_string()
|
||||
};
|
||||
press(&mut h, &save);
|
||||
assert!(h.state().views.is_empty(), "the tab closes once saved");
|
||||
|
||||
let mut reopened = PdfCraftApp::for_unit_tests();
|
||||
|
||||
@@ -208,6 +208,8 @@ struct PendingOpen {
|
||||
/// An answer taken from the queue and kept back for later (a password prompt waiting for an
|
||||
/// earlier file's password retry).
|
||||
ready: Option<open_worker::ResultKind>,
|
||||
/// Reopen Closed Tab asked for it: its closed-tab entry goes once it has opened, and stays when it fails.
|
||||
reopen: bool,
|
||||
}
|
||||
|
||||
/// A named destination being looked up in a document.
|
||||
|
||||
@@ -36,6 +36,13 @@ impl crate::PdfCraftApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Drops the latest closed-tab entry of `path`, once Reopen Closed Tab has brought it back.
|
||||
pub(crate) fn forget_closed_tab(&mut self, path: &str) {
|
||||
if let Some(at) = self.closed_tabs.iter().rposition(|closed| closed == path) {
|
||||
self.closed_tabs.remove(at);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn tab_action(&mut self, ctx: &egui::Context, action: Action) {
|
||||
match action {
|
||||
Action::Close(tab) => {
|
||||
@@ -51,18 +58,16 @@ impl crate::PdfCraftApp {
|
||||
Action::Reopen => {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if let Some(path) = self.closed_tabs.last().cloned() {
|
||||
// A tab may already have been reopened through File > Open.
|
||||
if let Some(index) = self.views.iter().position(|v| self.session.get(v.id).is_some_and(|d| d.path.as_deref() == Some(&path))) {
|
||||
self.active = Some(index);
|
||||
self.closed_tabs.pop();
|
||||
} else {
|
||||
let tabs = self.views.len();
|
||||
self.open_path(&path);
|
||||
// open_path reports errors through notifications, not a Result.
|
||||
// Keep the entry until an actual document tab has been opened.
|
||||
if self.views.len() > tabs {
|
||||
self.closed_tabs.pop();
|
||||
// A tab that shows the file already (opened again through File > Open) comes to the front.
|
||||
// Otherwise the open is queued, and its entry goes only once the file has opened.
|
||||
match self.open_path(&path) {
|
||||
crate::OpenOutcome::Opened | crate::OpenOutcome::Focused => self.forget_closed_tab(&path),
|
||||
crate::OpenOutcome::Pending => {
|
||||
if let Some(pending) = self.pending_opens.iter_mut().find(|p| p.path.as_deref() == Some(path.as_str())) {
|
||||
pending.reopen = true;
|
||||
}
|
||||
}
|
||||
crate::OpenOutcome::Failed(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,6 +107,12 @@ mod tests {
|
||||
app
|
||||
}
|
||||
|
||||
/// Runs the queued opens and takes their results, as the next frame would.
|
||||
fn settle(app: &mut PdfCraftApp, jobs: &craft::host::ManualJobs) {
|
||||
jobs.run_all();
|
||||
app.poll_pending_opens(&egui::Context::default());
|
||||
}
|
||||
|
||||
/// An English app whose jobs never run.
|
||||
fn app() -> PdfCraftApp {
|
||||
app_on(Arc::new(craft::host::ManualJobs::new()))
|
||||
@@ -162,14 +173,18 @@ mod tests {
|
||||
let mut file = std::fs::OpenOptions::new().write(true).create_new(true).open(&path).unwrap();
|
||||
file.write_all(PDF).unwrap();
|
||||
drop(file);
|
||||
let mut app = app();
|
||||
let jobs = Arc::new(craft::host::ManualJobs::new());
|
||||
let mut app = app_on(jobs.clone());
|
||||
let path_text = path.to_str().unwrap();
|
||||
for _ in 0..12 {
|
||||
app.open_path(path_text);
|
||||
settle(&mut app, &jobs);
|
||||
app.close_tab(0);
|
||||
}
|
||||
assert_eq!(app.closed_tabs.len(), 10);
|
||||
app.tab_action(&egui::Context::default(), Action::Reopen);
|
||||
assert_eq!(app.closed_tabs.len(), 10, "the entry stays until the file has opened");
|
||||
settle(&mut app, &jobs);
|
||||
assert_eq!(app.views.len(), 1);
|
||||
let doc = app.session.get(app.views[0].id).unwrap();
|
||||
assert_eq!(doc.path.as_deref(), Some(path_text));
|
||||
@@ -187,15 +202,19 @@ mod tests {
|
||||
let mut file = std::fs::OpenOptions::new().create_new(true).write(true).open(&path).unwrap();
|
||||
file.write_all(PDF).unwrap();
|
||||
drop(file);
|
||||
let mut app = app();
|
||||
let jobs = Arc::new(craft::host::ManualJobs::new());
|
||||
let mut app = app_on(jobs.clone());
|
||||
app.open_path(text);
|
||||
settle(&mut app, &jobs);
|
||||
app.close_tab(0);
|
||||
std::fs::remove_file(&path).unwrap();
|
||||
app.tab_action(&egui::Context::default(), Action::Reopen);
|
||||
settle(&mut app, &jobs);
|
||||
assert!(app.views.is_empty());
|
||||
assert_eq!(app.closed_tabs, [text]);
|
||||
std::fs::write(&path, PDF).unwrap();
|
||||
app.tab_action(&egui::Context::default(), Action::Reopen);
|
||||
settle(&mut app, &jobs);
|
||||
assert_eq!(app.views.len(), 1);
|
||||
assert!(app.closed_tabs.is_empty());
|
||||
app.closed_tabs.push(text.into());
|
||||
|
||||
@@ -105,6 +105,27 @@ pub(crate) fn expand_to(view: &mut crate::DocView, outline: &[OutlineItem], leve
|
||||
walk(outline, 0, level, &mut Vec::new(), &mut view.bookmarks_open);
|
||||
}
|
||||
|
||||
/// The groups of `outline` open as the file says: only a positive `/Count` opens one, at every level (ISO 32000-2
|
||||
/// §12.3.3, Table 151). A view starts with them so; the reader's opening and closing changes them from there.
|
||||
pub(crate) fn opened_as_filed(outline: &[OutlineItem]) -> OpenSet<Vec<usize>> {
|
||||
fn walk(items: &[OutlineItem], depth: usize, path: &mut Vec<usize>, open: &mut OpenSet<Vec<usize>>) {
|
||||
if depth >= MAX_DEPTH {
|
||||
return;
|
||||
}
|
||||
for (i, item) in items.iter().enumerate() {
|
||||
path.push(i);
|
||||
if !item.children.is_empty() {
|
||||
open.set(path, item.open);
|
||||
walk(&item.children, depth + 1, path, open);
|
||||
}
|
||||
path.pop();
|
||||
}
|
||||
}
|
||||
let mut open = OpenSet::default();
|
||||
walk(outline, 0, &mut Vec::new(), &mut open);
|
||||
open
|
||||
}
|
||||
|
||||
/// How a bookmark's title is drawn: bold at depth 0 and where the file says, italic where it says, in its own colour
|
||||
/// (ISO 32000-2 §12.3.3, Tables 151 and 152). The row keeps the colour readable.
|
||||
fn title_style(item: &OutlineItem, depth: usize) -> (bool, bool, Option<DataColor>) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use craft::automation::dock as dock_rpc;
|
||||
use craft::behavior::dock::{
|
||||
Action, Column, DockEdge, DockPlacement, Group, Layout, Location, Node, PanelState, Permissions, SplitSize, Target, Workspace,
|
||||
Action, Column, DockEdge, DockError, DockPlacement, Group, Layout, Node, PanelState, Permissions, SplitSize, Target, Workspace,
|
||||
};
|
||||
use craft::behavior::{Axis, DockSide, IconId};
|
||||
use craft::keymap::CommandRef;
|
||||
@@ -165,22 +165,22 @@ const START_SHARE: f32 = 0.2;
|
||||
/// Share of the rest the page area takes beside the end dock.
|
||||
const PAGE_SHARE: f32 = 0.8;
|
||||
|
||||
/// The arrangement of a new install: Tools at the start edge, the toolbar at the rail's edge, the page area between
|
||||
/// the docks, and every side panel closed, remembered as a column after the toolbar's.
|
||||
/// The Tools pane's default width, as production opened it.
|
||||
const TOOLS_WIDTH: f32 = 272.0;
|
||||
|
||||
/// The arrangement of a new install: Tools at the start edge, the toolbar at the rail's edge, the page area between
|
||||
/// the docks, and the side panels as one group in a column inward of the toolbar's, collapsed to their icons.
|
||||
pub fn default_workspace(rail_side: DockSide) -> Workspace<PanelId> {
|
||||
let single = |panel| Column::new(vec![Group::new(vec![panel], 0)]);
|
||||
// The rail is one tool column wide: its column keeps the toolbar's grid, never the theme's column width.
|
||||
// The Tools pane opens at production's width (272 points, the old `TOOLS_WIDTH`), not the theme's column width.
|
||||
let (tools, toolbar) = (single(PanelId::Tools).with_width(TOOLS_WIDTH), single(PanelId::Toolbar).with_steps(1));
|
||||
let (start, end) = if rail_edge(rail_side) == DockEdge::Start { (vec![toolbar, tools], Vec::new()) } else { (vec![tools], vec![toolbar]) };
|
||||
let side = Column::new(vec![Group::new(SIDE.to_vec(), 0)]).with_iconic(true);
|
||||
let (start, end) =
|
||||
if rail_edge(rail_side) == DockEdge::Start { (vec![toolbar, side, tools], Vec::new()) } else { (vec![tools], vec![toolbar, side]) };
|
||||
let page = Node::split(Axis::X, SplitSize::Ratio(PAGE_SHARE), Node::tabs(vec![PanelId::Document], 0), Node::dock(DockEdge::End, end));
|
||||
let root = Node::split(Axis::X, SplitSize::Ratio(START_SHARE), Node::dock(DockEdge::Start, start), page);
|
||||
let mut workspace = Workspace::new(Layout::new(Some(root), Vec::new()));
|
||||
workspace.hidden = SIDE.iter().map(|panel| (*panel, Location::new(Some(PanelId::Toolbar), DockPlacement::column(true)))).collect();
|
||||
workspace
|
||||
Workspace::new(Layout::new(Some(root), Vec::new()))
|
||||
}
|
||||
|
||||
/// The window edge whose dock holds `panel`, `None` when it is closed or floating.
|
||||
@@ -242,21 +242,19 @@ fn edge_name(edge: Option<DockEdge>) -> &'static str {
|
||||
if edge == Some(DockEdge::End) { "right" } else { "left" }
|
||||
}
|
||||
|
||||
/// The side panel that is open, if any.
|
||||
/// The side panel that is open, if any: the front tab of the side panels' expanded column. Collapsed to its icons,
|
||||
/// the column shows none.
|
||||
fn open_side(workspace: &Workspace<PanelId>) -> Option<PanelId> {
|
||||
// The side panels share a group: the open one is its front tab. A minimized or collapsed group
|
||||
// shows none in front, and then the first one open stands for it.
|
||||
let layout = &workspace.layout;
|
||||
SIDE.into_iter().find(|panel| layout.panel_state(panel) == PanelState::Front).or_else(|| SIDE.into_iter().find(|panel| layout.contains(panel)))
|
||||
SIDE.into_iter().find(|panel| workspace.layout.panel_state(panel) == PanelState::Front)
|
||||
}
|
||||
|
||||
/// The tab label of a side panel: its name, and the count of what it lists where it has one.
|
||||
fn side_label(app: &PdfCraftApp, panel: RightPanel) -> String {
|
||||
/// The label of a side panel, which its icon in the collapsed column and its tab share: production's rail button name.
|
||||
fn side_label(panel: RightPanel) -> String {
|
||||
let title = match panel {
|
||||
RightPanel::Comments => "Comments",
|
||||
RightPanel::Bookmarks => "Bookmarks",
|
||||
RightPanel::Pages => "Pages",
|
||||
RightPanel::Fields => "Fields",
|
||||
RightPanel::Pages => "Page thumbnails",
|
||||
RightPanel::Fields => "Form fields",
|
||||
RightPanel::Layers => "Layers",
|
||||
RightPanel::Attachments => "Attachments",
|
||||
RightPanel::Signatures => "Signatures",
|
||||
@@ -265,24 +263,23 @@ fn side_label(app: &PdfCraftApp, panel: RightPanel) -> String {
|
||||
RightPanel::Search => "Search",
|
||||
RightPanel::Compare => "Compare",
|
||||
};
|
||||
let count = app.active_ids().and_then(|(_, id)| {
|
||||
let doc = app.session.get(id)?;
|
||||
let info = &doc.info;
|
||||
match panel {
|
||||
RightPanel::Comments => Some(crate::comments_panel::count(info)),
|
||||
RightPanel::Pages => Some(info.pages.len()),
|
||||
RightPanel::Fields => Some(info.fields.len()),
|
||||
RightPanel::Layers => Some(info.layer_order.iter().filter(|r| matches!(r.item, pdfcraft_render::LayerItem::Layer(_))).count()),
|
||||
RightPanel::Attachments => Some(info.attachments.len()),
|
||||
RightPanel::Signatures => Some(doc.signatures.iter().filter(|s| s.signed).count()),
|
||||
RightPanel::Compare => app.compare.as_ref().filter(|c| c.new == id).map(|c| c.result.changes.len()),
|
||||
RightPanel::Bookmarks | RightPanel::Accessibility | RightPanel::Tags | RightPanel::Search => None,
|
||||
}
|
||||
});
|
||||
let title = crate::i18n::t(title);
|
||||
match count {
|
||||
Some(n) => format!("{title} ({n})"),
|
||||
None => title.to_owned(),
|
||||
crate::i18n::t(title).to_owned()
|
||||
}
|
||||
|
||||
/// The icon of a side panel's cell in its collapsed column, production's rail icon.
|
||||
fn side_icon(panel: RightPanel) -> &'static str {
|
||||
match panel {
|
||||
RightPanel::Comments => "message-square-text",
|
||||
RightPanel::Bookmarks => "bookmark",
|
||||
RightPanel::Pages => "files",
|
||||
RightPanel::Fields => "text-cursor-input",
|
||||
RightPanel::Layers => "layers",
|
||||
RightPanel::Attachments => "paperclip",
|
||||
RightPanel::Signatures => "signature",
|
||||
RightPanel::Accessibility => "accessibility",
|
||||
RightPanel::Tags => "tag",
|
||||
RightPanel::Search => "search",
|
||||
RightPanel::Compare => "git-compare",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,12 +297,12 @@ impl DockPanels<PanelId> for Panels<'_> {
|
||||
if *panel == PanelId::Document {
|
||||
return PanelSpec::new(crate::i18n::t("Document").to_owned()).canvas();
|
||||
}
|
||||
let label = match panel.side() {
|
||||
Some(side) => side_label(self.app, side),
|
||||
None if self.app.left == LeftPanel::CalculationOrder => crate::i18n::t("Calculation order").to_owned(),
|
||||
None => crate::i18n::t("Tools").to_owned(),
|
||||
};
|
||||
PanelSpec::new(label).command(CommandRef::with_params("view.panel", json!({ "panel": panel.name() })))
|
||||
let command = CommandRef::with_params("view.panel", json!({ "panel": panel.name() }));
|
||||
match panel.side() {
|
||||
Some(side) => PanelSpec::new(side_label(side)).icon(IconSpec::svg(IconId::new(side_icon(side)))).command(command),
|
||||
None if self.app.left == LeftPanel::CalculationOrder => PanelSpec::new(crate::i18n::t("Calculation order").to_owned()).command(command),
|
||||
None => PanelSpec::new(crate::i18n::t("Tools").to_owned()).command(command),
|
||||
}
|
||||
}
|
||||
|
||||
fn permissions(&self, panel: &PanelId) -> Permissions {
|
||||
@@ -431,24 +428,42 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) {
|
||||
// Full screen shows the document alone, and a document can hide the toolbars, the menu and the panels around it
|
||||
// in its tab (ISO 32000-2 Table 147); the tab strip stays, and F8 brings the rest back (`viewer_prefs`).
|
||||
let bare = app.full_screen_document() || app.hidden_interface().window_ui;
|
||||
let toolbar = active && !app.hotbar_hidden();
|
||||
let workspace = app.dock.clone();
|
||||
// The rail lists the Accessibility Checker once the document has a report, and Search and Compare only while
|
||||
// they show; their commands open them.
|
||||
let open = open_side(&workspace);
|
||||
let checked = app.active_ids().is_some_and(|(_, id)| app.a11y.report.as_ref().is_some_and(|(d, _)| *d == id));
|
||||
let listed = |panel: &PanelId| match panel {
|
||||
PanelId::Accessibility => checked || open == Some(*panel),
|
||||
PanelId::Search | PanelId::Compare => open == Some(*panel),
|
||||
_ => true,
|
||||
};
|
||||
let mut panels = Panels { ctx: ui.ctx().clone(), app: &mut *app };
|
||||
// Home and Combine have no side panel and no rail, and Read mode hides the tools, not the navigation panels.
|
||||
// Home and Combine have no side panel and no toolbar, and Read mode hides the tools and the quick toolbar, not the
|
||||
// navigation panels.
|
||||
let shown = |panel: &PanelId| match panel {
|
||||
PanelId::Document => true,
|
||||
_ if bare => false,
|
||||
PanelId::Toolbar => active,
|
||||
PanelId::Toolbar => toolbar,
|
||||
PanelId::Tools => !read && !expanded,
|
||||
_ => active && !expanded,
|
||||
_ => active && !expanded && listed(panel),
|
||||
};
|
||||
// An icon of the side panels' collapsed column opens its panel docked, as production's rail buttons did, not in a
|
||||
// flyout: the pick the area writes here becomes the panel shown.
|
||||
let mut picked = None;
|
||||
let output = DockArea::new("Dock", Bind::given(workspace), &mut panels, DockConfig::default().native_windows(false))
|
||||
.hide(HidePanels::Except(&shown))
|
||||
.flyout(Bind::bound(&mut picked))
|
||||
.show(ui);
|
||||
let before = right_of(&app.dock);
|
||||
for action in output.actions.into_iter().chain(output.requested) {
|
||||
// The area drops what the workspace refuses; one refused here is stale, not the user's mistake.
|
||||
drop(app.dock.apply(action, false, permissions));
|
||||
}
|
||||
if let Some(panel) = picked {
|
||||
set_panel_visible(app, panel, true);
|
||||
}
|
||||
let after = right_of(&app.dock);
|
||||
if after != before {
|
||||
app.right_panel_chosen(before, after);
|
||||
@@ -477,8 +492,25 @@ fn refused() -> String {
|
||||
|
||||
/// Opens or closes `panel` in the workspace, the one write path for panel visibility.
|
||||
fn show_panel(app: &mut PdfCraftApp, panel: PanelId, visible: bool) -> Result<(), String> {
|
||||
let fallback = (panel != PanelId::Toolbar && app.dock.layout.contains(&PanelId::Toolbar)).then_some(PanelId::Toolbar);
|
||||
app.dock.set_visible(panel, visible, fallback, false, permissions).map_err(|_| refused())
|
||||
set_shown(&mut app.dock, panel, visible).map_err(|_| refused())
|
||||
}
|
||||
|
||||
/// Shows or hides `panel` in `workspace`. A side panel stays in the layout as an icon of its column: showing it
|
||||
/// expands the column with it in front, hiding it collapses the column to its icons. One closed from its tab comes
|
||||
/// back to its recorded place first.
|
||||
fn set_shown(workspace: &mut Workspace<PanelId>, panel: PanelId, visible: bool) -> Result<(), DockError> {
|
||||
let fallback = (panel != PanelId::Toolbar && workspace.layout.contains(&PanelId::Toolbar)).then_some(PanelId::Toolbar);
|
||||
if panel.side().is_none() {
|
||||
return workspace.set_visible(panel, visible, fallback, false, permissions);
|
||||
}
|
||||
if visible {
|
||||
workspace.set_visible(panel, true, fallback, false, permissions)?;
|
||||
return workspace.apply(Action::set_iconic(panel, false), false, permissions).map(drop);
|
||||
}
|
||||
if workspace.layout.panel_state(&panel) != PanelState::Front {
|
||||
return Ok(());
|
||||
}
|
||||
workspace.apply(Action::set_iconic(panel, true), false, permissions).map(drop)
|
||||
}
|
||||
|
||||
/// The side panel `workspace` has open, `None` when every side panel is closed.
|
||||
@@ -770,7 +802,7 @@ fn build(old: &Old, right: Option<RightPanel>, widths: bool) -> Option<Workspace
|
||||
}
|
||||
let side = right.filter(|_| old.side_open).map(PanelId::from);
|
||||
if let Some(side) = side {
|
||||
workspace.set_visible(side, true, Some(PanelId::Toolbar), false, permissions).ok()?;
|
||||
set_shown(&mut workspace, side, true).ok()?;
|
||||
}
|
||||
if !old.tools_open {
|
||||
workspace.set_visible(PanelId::Tools, false, None, false, permissions).ok()?;
|
||||
@@ -914,8 +946,7 @@ mod tests {
|
||||
if tools_open {
|
||||
assert_eq!(edge_of(&migrated.workspace, PanelId::Tools), Some(edge), "{name}: Tools edge");
|
||||
}
|
||||
let side = [PanelId::Bookmarks, PanelId::Pages].into_iter().any(|p| migrated.workspace.layout.contains(&p));
|
||||
assert_eq!(side, side_open, "{name}: side panel open");
|
||||
assert_eq!(open_side(&migrated.workspace).is_some(), side_open, "{name}: side panel open");
|
||||
assert_eq!(migrated.rail_side, DockSide::End, "{name}: rail side");
|
||||
}
|
||||
let left = migrate(&json!({"side_panels": {"version": 1, "rail_side": "left"}})).expect("migrates");
|
||||
|
||||
@@ -145,6 +145,15 @@ fn settle(r: &mut Rig, what: &str, ready: impl Fn(&PdfCraftApp) -> bool) {
|
||||
panic!("timed out waiting for {what}");
|
||||
}
|
||||
|
||||
/// The unsaved-changes question's "save it" answer as the framework words it on this OS: Save on macOS, Yes on
|
||||
/// Windows and Linux.
|
||||
fn save_answer() -> String {
|
||||
use craft::i18n::WordSet as _;
|
||||
let words = craft::ui::dialog::DialogWords::english();
|
||||
let save = if cfg!(target_os = "macos") { words.unsaved_save } else { words.unsaved_yes };
|
||||
save.as_str().to_string()
|
||||
}
|
||||
|
||||
/// Presses the button called `label` of the dialog on top (the last such node drawn).
|
||||
fn press(r: &mut Rig, label: &str) {
|
||||
r.get_all_by_label(label).last().unwrap_or_else(|| panic!("no {label:?} button on screen")).click();
|
||||
@@ -256,7 +265,7 @@ fn save_on_close_closes_the_tab_only_once_the_file_is_written() {
|
||||
assert!(h.execute("file.close"));
|
||||
h.steps(2);
|
||||
assert_eq!(h.state().views.len(), 1, "a dirty document asks first");
|
||||
press(&mut h, "Save");
|
||||
press(&mut h, &save_answer());
|
||||
assert_eq!(h.state().views.len(), 1, "the tab stays open until the save is written");
|
||||
assert_eq!(h.files.open(), 1, "the Save picker is open");
|
||||
h.answer(Picked::Paths(vec![out.clone()]));
|
||||
@@ -271,7 +280,7 @@ fn a_cancelled_save_on_close_keeps_the_tab_open() {
|
||||
rotate_first_page(h.state_mut());
|
||||
assert!(h.execute("file.close"));
|
||||
h.steps(2);
|
||||
press(&mut h, "Save");
|
||||
press(&mut h, &save_answer());
|
||||
h.answer(Picked::Cancelled); // the user cancels the save panel
|
||||
assert_eq!(h.state().views.len(), 1);
|
||||
assert!(dirty(h.state(), 0), "nothing was saved or lost");
|
||||
@@ -288,7 +297,7 @@ fn close_all_saves_each_untitled_document_in_turn() {
|
||||
assert!(h.execute("file.close_all"));
|
||||
h.steps(2);
|
||||
for (n, name) in ["first.pdf", "second.pdf"].iter().enumerate() {
|
||||
press(&mut h, "Save");
|
||||
press(&mut h, &save_answer());
|
||||
assert_eq!(h.files.open(), 1, "one Save pick for document {n}");
|
||||
h.answer(Picked::Paths(vec![dir.join(name)]));
|
||||
}
|
||||
@@ -536,7 +545,7 @@ fn a_close_prompt_still_means_its_own_document_after_a_pending_save_closes_anoth
|
||||
h.state_mut().active = Some(0);
|
||||
assert!(h.execute("file.close"));
|
||||
h.steps(2);
|
||||
press(&mut h, "Save");
|
||||
press(&mut h, &save_answer());
|
||||
assert_eq!(h.files.open(), 1, "the first tab's save panel is open");
|
||||
// ...when the user asks to close the second one.
|
||||
h.state_mut().active = Some(1);
|
||||
|
||||
@@ -630,7 +630,7 @@ fn a_middle_click_closes_the_tab() {
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().apply_edit(&ctx_h, pdfcraft_engine::Edit::RotatePages { pages: vec![0], degrees: 90 });
|
||||
h.run_steps(2);
|
||||
h.get_by_label("second.pdf (edited)").click_button(egui::PointerButton::Middle);
|
||||
h.get_by_label("second.pdf, modified").click_button(egui::PointerButton::Middle);
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().views.len(), 1, "unsaved changes ask first");
|
||||
h.get_by_label("Cancel");
|
||||
@@ -645,7 +645,7 @@ fn a_link_prompt_above_a_save_prompt_owns_its_keys() {
|
||||
});
|
||||
h.run_steps(3);
|
||||
// The save prompt is the close dialog the tab's close action opens.
|
||||
h.get_by_label("first.pdf (edited)").click_button(egui::PointerButton::Middle);
|
||||
h.get_by_label("first.pdf, modified").click_button(egui::PointerButton::Middle);
|
||||
h.run_steps(3);
|
||||
h.state_mut().pending_link =
|
||||
Some(pdfcraft_ui_egui::PendingLink { url: "https://example.org".to_owned(), origin: pdfcraft_ui_egui::LinkOrigin::Link });
|
||||
@@ -986,7 +986,7 @@ fn dropping_a_pdf_on_the_window_opens_it() {
|
||||
support::input::drop_files(&mut h, [file]);
|
||||
support::wait_until(&mut h, "dropped document", |app| app.views.len() == 1 && app.password_prompt.is_none());
|
||||
assert_eq!(h.state().views.len(), 1, "the dropped PDF opens in a tab");
|
||||
h.get_by_label_contains("dropped.pdf");
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Tab, "dropped.pdf");
|
||||
let (_, id) = h.state().active_ids().unwrap();
|
||||
let doc = h.state().session.get(id).unwrap();
|
||||
assert_eq!(doc.name, "dropped.pdf");
|
||||
@@ -1250,7 +1250,7 @@ fn files_and_quit_from_the_operating_system() {
|
||||
support::wait_until(&mut h, "the file the operating system opened", |app| !app.views.is_empty());
|
||||
std::fs::remove_file(&path).ok();
|
||||
assert_eq!(h.state().views.len(), 1, "the file opens in a tab");
|
||||
h.get_by_label_contains(&name);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Tab, &name);
|
||||
// A file opened while the app runs brings its window forward, even minimized or full screen
|
||||
// on another Space.
|
||||
std::fs::write(&path, FIXTURE).unwrap();
|
||||
@@ -1569,14 +1569,14 @@ fn cancelling_then_discarding_an_earlier_dirty_tab_preserves_the_selected_docume
|
||||
h.run_steps(3);
|
||||
h.get_by_label("middle.pdf").click();
|
||||
h.run_steps(3);
|
||||
close_named_tab(&mut h, "first.pdf (edited)");
|
||||
close_named_tab(&mut h, "first.pdf, modified");
|
||||
h.get_by_label("Don't save");
|
||||
h.get_by_label("Cancel").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().views.len(), 3);
|
||||
assert_eq!(h.state().active_ids().map(|(_, id)| id), Some(ids[1]));
|
||||
assert!(h.state().session.get(ids[0]).unwrap().dirty);
|
||||
close_named_tab(&mut h, "first.pdf (edited)");
|
||||
close_named_tab(&mut h, "first.pdf, modified");
|
||||
h.get_by_label("Don't save").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().active_ids().map(|(_, id)| id), Some(ids[1]));
|
||||
@@ -1624,11 +1624,11 @@ fn document_tab_identity_survives_dirty_labels_and_removing_an_earlier_document(
|
||||
let ctx_h = h.ctx.clone();
|
||||
assert!(h.state_mut().apply_edit(&ctx_h, pdfcraft_engine::Edit::SetInfo { key: "Title".into(), value: "Unsaved title".into() }));
|
||||
h.run_steps(3);
|
||||
let dirty = h.get_by_role_and_label(Role::Tab, "middle.pdf (edited)");
|
||||
let dirty = h.get_by_role_and_label(Role::Tab, "middle.pdf, modified");
|
||||
assert_eq!(dirty.accesskit_node().id(), middle_id);
|
||||
assert!(dirty.is_focused());
|
||||
close_named_tab(&mut h, "first.pdf");
|
||||
assert_eq!(h.get_by_role_and_label(Role::Tab, "middle.pdf (edited)").accesskit_node().id(), middle_id);
|
||||
assert_eq!(h.get_by_role_and_label(Role::Tab, "middle.pdf, modified").accesskit_node().id(), middle_id);
|
||||
assert_eq!(h.state().active, Some(0));
|
||||
assert_eq!(h.state().views.len(), 2);
|
||||
assert!(h.state().session.get(h.state().views[0].id).unwrap().dirty);
|
||||
|
||||
Reference in New Issue
Block a user