mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-09 03:49:54 -06:00
G4: two windows on one workbook without copying it; Arrange All
- The workbook's active sheet is an atomic set in place (Workbook::active_sheet /
set_active_sheet), so a window swap or sheet switch never clones the
Arc<Workbook> or marks it dirty. Selections already live in DocState and the
window views. Save records the sheet of the most recently active window.
- A dialog taken out of its window while it runs goes back to that window when
a command run from it switched windows (dialogs::show, ui.dialog.confirm).
- view.arrangeAll {arrange?: tiled|horizontal|vertical|cascade, activeWorkbook?}
returns the visible windows, active first; the desktop moves and sizes the
native windows over the main window's monitor. New Window and Arrange All
buttons on the View ribbon; Arrange Windows dialog.
- Docs: ui-parity, hardware-parity, gaps #20, target-app-parity, ROADMAP.
This commit is contained in:
@@ -237,7 +237,7 @@ fn cell_set(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
{
|
||||
return Err(EngineError::Other(m));
|
||||
}
|
||||
let active_sheet = s.doc()?.wb.active_sheet;
|
||||
let active_sheet = s.doc()?.wb.active_sheet();
|
||||
edit(s, |cx| {
|
||||
if array {
|
||||
// Legacy Ctrl+Shift+Enter array formula over the selection, when the selection holds
|
||||
@@ -414,23 +414,18 @@ fn selection_set(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
impl crate::DocState {
|
||||
/// Switches the active sheet, remembering each sheet's selection.
|
||||
pub fn wb_switch_sheet(&mut self, i: usize) {
|
||||
if i >= self.wb.sheets.len() || i == self.wb.active_sheet {
|
||||
if i >= self.wb.sheets.len() || i == self.wb.active_sheet() {
|
||||
return;
|
||||
}
|
||||
let cur = self.wb.active_sheet;
|
||||
let cur = self.wb.active_sheet();
|
||||
if self.sheet_selections.len() < self.wb.sheets.len() {
|
||||
self.sheet_selections.resize(self.wb.sheets.len(), crate::Selection::default());
|
||||
}
|
||||
if let Some(slot) = self.sheet_selections.get_mut(cur) {
|
||||
*slot = self.selection.clone();
|
||||
}
|
||||
// The active sheet is view state: change it without making the workbook dirty.
|
||||
let dirty = self.is_dirty();
|
||||
let wb = std::sync::Arc::make_mut(&mut self.wb);
|
||||
wb.active_sheet = i;
|
||||
if !dirty {
|
||||
self.saved = self.wb.clone();
|
||||
}
|
||||
// View state: set in place, so the workbook is neither copied nor made dirty.
|
||||
self.wb.set_active_sheet(i);
|
||||
self.selection = self.sheet_selections.get(i).cloned().unwrap_or_default();
|
||||
}
|
||||
}
|
||||
@@ -558,7 +553,7 @@ pub(super) fn go_to(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
// A defined name or table?
|
||||
let d = s.doc()?;
|
||||
let resolved = if RangeRef::parse(split_sheet(reference).1).is_none() {
|
||||
let sheet = d.wb.active_sheet;
|
||||
let sheet = d.wb.active_sheet();
|
||||
if let Some(n) = d.wb.name(reference, sheet) {
|
||||
n.formula.clone()
|
||||
} else if let Some((si, ti)) = d.wb.table(reference) {
|
||||
@@ -1535,7 +1530,7 @@ fn find(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let workbook = str_param(p, "within") == Some("workbook");
|
||||
s.last_find = Some(p.clone());
|
||||
let d = s.doc()?;
|
||||
let sheets: Vec<usize> = if workbook { (0..d.wb.sheets.len()).collect() } else { vec![d.wb.active_sheet] };
|
||||
let sheets: Vec<usize> = if workbook { (0..d.wb.sheets.len()).collect() } else { vec![d.wb.active_sheet()] };
|
||||
let mut hits: Vec<(usize, CellRef, String)> = Vec::new();
|
||||
for si in sheets {
|
||||
let Some(sh) = d.wb.sheet(si) else { continue };
|
||||
@@ -1565,7 +1560,7 @@ fn find(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
return Ok(json!({"count": list.len(), "results": list}));
|
||||
}
|
||||
// Next hit after the active cell.
|
||||
let cur = (d.wb.active_sheet, d.selection.active);
|
||||
let cur = (d.wb.active_sheet(), d.selection.active);
|
||||
let key = |si: usize, c: CellRef| if by_cols { (si, c.col, c.row) } else { (si, c.row, c.col) };
|
||||
let next = hits.iter().find(|(si, c, _)| key(*si, *c) > key(cur.0, cur.1)).or_else(|| hits.first()).cloned();
|
||||
let Some((si, c, t)) = next else { return Err(EngineError::Other("not found".into())) };
|
||||
@@ -1587,7 +1582,7 @@ fn replace(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let workbook = str_param(p, "within") == Some("workbook");
|
||||
let active = s.doc()?.selection.active;
|
||||
let n = edit(s, |cx| {
|
||||
let sheets: Vec<usize> = if workbook { (0..cx.wb.sheets.len()).collect() } else { vec![cx.wb.active_sheet] };
|
||||
let sheets: Vec<usize> = if workbook { (0..cx.wb.sheets.len()).collect() } else { vec![cx.wb.active_sheet()] };
|
||||
let mut n = 0;
|
||||
for si in sheets {
|
||||
let cells: Vec<(CellRef, String)> =
|
||||
@@ -1659,7 +1654,7 @@ fn replace_ci(text: &str, what: &str, with: &str) -> String {
|
||||
fn format_painter(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
if let Some(dest) = str_param(p, "apply").and_then(RangeRef::parse) {
|
||||
let Some((wb, sheet, src, sticky)) = s.format_painter.clone() else { return Err(EngineError::Other("Pick up a format first.".into())) };
|
||||
let dest_sheet = s.doc()?.wb.active_sheet;
|
||||
let dest_sheet = s.doc()?.wb.active_sheet();
|
||||
let same = std::sync::Arc::ptr_eq(&wb, &s.doc()?.wb) || s.doc()?.wb.styles == wb.styles;
|
||||
edit(s, |cx| {
|
||||
let Some(src_sheet) = wb.sheet(sheet) else { return Ok(()) };
|
||||
@@ -1739,7 +1734,7 @@ fn format_painter(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
}
|
||||
let sticky = bool_param(p, "sticky").unwrap_or(false);
|
||||
let d = s.doc()?;
|
||||
s.format_painter = Some((d.wb.clone(), d.wb.active_sheet, d.selection.current(), sticky));
|
||||
s.format_painter = Some((d.wb.clone(), d.wb.active_sheet(), d.selection.current(), sticky));
|
||||
ok()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user