mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-10 04:19:48 -06:00
#3101: show or hide the sheet tabs and scroll bars of a workbook
Excel can hide the sheet tabs, the horizontal scroll bar and the vertical scroll bar of a workbook window (File › Options › Advanced › Display options for this workbook), saved with the workbook. GridCraft already read and wrote these settings (#3057) but always showed all three, and had no command or option for them. New commands view.showSheetTabs, view.showHorizontalScrollBar and view.showVerticalScrollBar {on?} (toggling without `on`, undoable, saved with the workbook), and a "Display options for this workbook" section in File › Options. The tab bar follows them: without the tabs the scroll bar takes the bar, without the scroll bar the tabs do, and with neither the bar isn't shown; without the vertical scroll bar the grid takes its width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
178f3eb745
commit
846cc09d67
@@ -40,6 +40,27 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
cmd!("view.showZeros", "Show Zeros", [], None, "{on?}", has_doc, |s, p| sheet_flag(s, p, "zeros")),
|
||||
cmd!("view.showOutlineSymbols", "Show Outline Symbols", [], Some("Ctrl+8"), "{on?}", has_doc, |s, p| sheet_flag(s, p, "outlineSymbols")),
|
||||
cmd!("view.showObjects", "Show Objects", [], Some("Ctrl+6"), "{on?}", has_doc, show_objects),
|
||||
cmd!(
|
||||
"view.showSheetTabs",
|
||||
"Show Sheet Tabs",
|
||||
[],
|
||||
None,
|
||||
"{on?} (File › Options › Advanced, this workbook; toggles without `on`)",
|
||||
has_doc,
|
||||
|s, p| { workbook_view_flag(s, p, "sheetTabs") }
|
||||
),
|
||||
cmd!(
|
||||
"view.showHorizontalScrollBar",
|
||||
"Show Horizontal Scroll Bar",
|
||||
[],
|
||||
None,
|
||||
"{on?} (this workbook; toggles without `on`)",
|
||||
has_doc,
|
||||
|s, p| { workbook_view_flag(s, p, "horizontal") }
|
||||
),
|
||||
cmd!("view.showVerticalScrollBar", "Show Vertical Scroll Bar", [], None, "{on?} (this workbook; toggles without `on`)", has_doc, |s, p| {
|
||||
workbook_view_flag(s, p, "vertical")
|
||||
}),
|
||||
cmd!("view.rightToLeft", "Sheet Right-to-Left", ["Page Layout", "Sheet Options"], None, "{on?}", has_doc, |s, p| sheet_flag(s, p, "rtl")),
|
||||
cmd!("view.zoom", "Zoom", ["View", "Zoom"], None, "{percent: 10..400}", has_doc, zoom),
|
||||
cmd!("view.zoom100", "100%", ["View", "Zoom"], None, "{}", has_doc, |s, _| zoom(s, &json!({"percent": 100}))),
|
||||
@@ -189,6 +210,21 @@ fn sheet_flag(s: &mut Session, p: &Json, which: &str) -> Result<Json> {
|
||||
})
|
||||
}
|
||||
|
||||
/// File › Options › Advanced › Display options for this workbook: the sheet tabs and the two
|
||||
/// scroll bars, saved with the workbook (`<workbookView showSheetTabs … />`).
|
||||
fn workbook_view_flag(s: &mut Session, p: &Json, which: &str) -> Result<Json> {
|
||||
edit(s, |cx| {
|
||||
let view = &mut cx.wb.view;
|
||||
let slot = match which {
|
||||
"sheetTabs" => &mut view.show_sheet_tabs,
|
||||
"horizontal" => &mut view.show_horizontal_scroll,
|
||||
_ => &mut view.show_vertical_scroll,
|
||||
};
|
||||
*slot = bool_param(p, "on").unwrap_or(!*slot);
|
||||
Ok(json!({"on": *slot}))
|
||||
})
|
||||
}
|
||||
|
||||
/// Ctrl+6: hides every object, or shows them again. Placeholders (from a file) count as shown.
|
||||
fn show_objects(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
use gridcraft_model::ShowObjects;
|
||||
|
||||
@@ -5457,3 +5457,22 @@ fn a_view_kept_through_redo_doesnt_make_the_saved_workbook_dirty() {
|
||||
assert_eq!(d.wb.active().unwrap().view, gridcraft_model::SheetViewMode::PageBreakPreview);
|
||||
assert!(!d.is_dirty(), "back at the saved edits, the view alone isn't a change");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workbook_display_options_are_commands() {
|
||||
// #3101: Show sheet tabs / horizontal / vertical scroll bar, toggling without `on`, saved with
|
||||
// the workbook and undoable.
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
let view = |s: &Session| s.doc().unwrap().wb.view;
|
||||
assert_eq!(s.execute("view.showSheetTabs", json!({})).unwrap()["on"], json!(false));
|
||||
assert_eq!(s.execute("view.showHorizontalScrollBar", json!({"on": false})).unwrap()["on"], json!(false));
|
||||
assert_eq!(s.execute("view.showVerticalScrollBar", json!({"on": false})).unwrap()["on"], json!(false));
|
||||
let v = view(&s);
|
||||
assert!(!v.show_sheet_tabs && !v.show_horizontal_scroll && !v.show_vertical_scroll);
|
||||
let (back, _) = gridcraft_xlsx::read_xlsx(&gridcraft_xlsx::write_xlsx(&s.doc().unwrap().wb).unwrap()).unwrap();
|
||||
assert_eq!(back.view, v, "saved with the workbook");
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert!(view(&s).show_vertical_scroll);
|
||||
assert_eq!(s.execute("view.showSheetTabs", json!({})).unwrap()["on"], json!(true), "toggles back");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user