diff --git a/src/book/mod.rs b/src/book/mod.rs index 6651a82..7e9f77f 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -37,7 +37,7 @@ impl<'book> AddressRange<'book> { for ri in row_range.iter() { let mut row = Vec::with_capacity(col_range.len()); for ci in col_range.iter() { - row.push(Address { row: *ri, col: *ci }); + row.push(Address { sheet: self.start.sheet, row: *ri, col: *ci }); } rows.push(row); } @@ -49,7 +49,7 @@ impl<'book> AddressRange<'book> { let mut rows = Vec::with_capacity(row_range.len() * col_range.len()); for ri in row_range.iter() { for ci in col_range.iter() { - rows.push(Address { row: *ri, col: *ci }); + rows.push(Address { sheet: self.start.sheet, row: *ri, col: *ci }); } } rows @@ -85,7 +85,6 @@ impl<'book> AddressRange<'book> { /// A spreadsheet book with some internal state tracking. pub struct Book { pub(crate) model: UserModel, - pub current_sheet: u32, pub location: crate::ui::Address, } @@ -94,7 +93,6 @@ impl Book { pub fn new(model: UserModel) -> Self { Self { model, - current_sheet: 0, location: Address::default(), } } @@ -162,7 +160,7 @@ impl Book { self.set_sheet_name(idx, name)?; } self.model - .set_selected_sheet(self.current_sheet) + .set_selected_sheet(self.location.sheet) .map_err(|e| anyhow!(e))?; Ok(()) } @@ -173,7 +171,7 @@ impl Book { } /// Move to a specific sheet location in the current sheet - pub fn move_to(&mut self, Address { row, col }: &Address) -> Result<()> { + pub fn move_to(&mut self, Address { sheet: _, row, col }: &Address) -> Result<()> { // FIXME(zaphar): Check that this is safe first. self.location.row = *row; self.location.col = *col; @@ -194,7 +192,7 @@ impl Book { .model .get_model() .extend_to( - self.current_sheet, + self.location.sheet, from.row as i32, from.col as i32, cell.row as i32, @@ -203,7 +201,7 @@ impl Book { .map_err(|e| anyhow!(e))?; self.model .set_user_input( - self.current_sheet, + self.location.sheet, cell.row as i32, cell.col as i32, &contents, @@ -215,14 +213,14 @@ impl Book { } pub fn clear_current_cell(&mut self) -> Result<()> { - self.clear_cell_contents(self.current_sheet as u32, self.location.clone()) + self.clear_cell_contents(self.location.clone()) } pub fn clear_current_cell_all(&mut self) -> Result<()> { - self.clear_cell_all(self.current_sheet as u32, self.location.clone()) + self.clear_cell_all(self.location.clone()) } - pub fn clear_cell_contents(&mut self, sheet: u32, Address { row, col }: Address) -> Result<()> { + pub fn clear_cell_contents(&mut self, Address { sheet, row, col }: Address) -> Result<()> { Ok(self .model .range_clear_contents(&Area { @@ -235,15 +233,15 @@ impl Book { .map_err(|s| anyhow!("Unable to clear cell contents {}", s))?) } - pub fn clear_cell_range(&mut self, sheet: u32, start: Address, end: Address) -> Result<()> { - let area = calculate_area(sheet, &start, &end); + pub fn clear_cell_range(&mut self, start: Address, end: Address) -> Result<()> { + let area = calculate_area(start.sheet, &start, &end); self.model .range_clear_contents(&area) .map_err(|s| anyhow!("Unable to clear cell contents {}", s))?; Ok(()) } - pub fn clear_cell_all(&mut self, sheet: u32, Address { row, col }: Address) -> Result<()> { + pub fn clear_cell_all(&mut self, Address { sheet, row, col }: Address) -> Result<()> { Ok(self .model .range_clear_all(&Area { @@ -256,8 +254,8 @@ impl Book { .map_err(|s| anyhow!("Unable to clear cell contents {}", s))?) } - pub fn clear_cell_range_all(&mut self, sheet: u32, start: Address, end: Address) -> Result<()> { - let area = calculate_area(sheet, &start, &end); + pub fn clear_cell_range_all(&mut self, start: Address, end: Address) -> Result<()> { + let area = calculate_area(start.sheet, &start, &end); self.model .range_clear_all(&area) .map_err(|s| anyhow!("Unable to clear cell contents {}", s))?; @@ -269,13 +267,13 @@ impl Book { Ok(self.get_cell_addr_rendered(&self.location)?) } - pub fn get_cell_style(&self, sheet: u32, cell: &Address) -> Option