-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from logisky/jh/merge
Support merge cells and split merged cells
- Loading branch information
Showing
37 changed files
with
831 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use logisheets_base::id_fetcher::{IdFetcherTrait, SheetIdFetcherByIdxTrait}; | ||
|
||
pub trait CellAttachmentsExecCtx: IdFetcherTrait + SheetIdFetcherByIdxTrait {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use logisheets_base::errors::BasicError; | ||
|
||
use crate::{edit_action::EditPayload, Error}; | ||
|
||
use super::{ctx::CellAttachmentsExecCtx, CellAttachmentsManager}; | ||
|
||
pub struct CellAttachmentsExecutor { | ||
pub manager: CellAttachmentsManager, | ||
} | ||
|
||
impl CellAttachmentsExecutor { | ||
pub fn new(manager: CellAttachmentsManager) -> Self { | ||
Self { manager } | ||
} | ||
|
||
pub fn execute<C: CellAttachmentsExecCtx>( | ||
mut self, | ||
ctx: &mut C, | ||
payload: EditPayload, | ||
) -> Result<(Self, bool), Error> { | ||
match payload { | ||
EditPayload::MergeCells(merge_cells) => { | ||
let sheet_id = ctx | ||
.fetch_sheet_id_by_index(merge_cells.sheet_idx) | ||
.map_err(|l| BasicError::SheetIdxExceed(l))?; | ||
let start_cell_id = ctx.fetch_norm_cell_id( | ||
&sheet_id, | ||
merge_cells.start_row, | ||
merge_cells.start_col, | ||
)?; | ||
let end_cell_id = | ||
ctx.fetch_norm_cell_id(&sheet_id, merge_cells.end_row, merge_cells.end_col)?; | ||
self.manager | ||
.merge_cells | ||
.add_merge_cell(sheet_id, start_cell_id, end_cell_id); | ||
Ok((self, true)) | ||
} | ||
EditPayload::SplitMergedCells(p) => { | ||
let sheet_id = ctx | ||
.fetch_sheet_id_by_index(p.sheet_idx) | ||
.map_err(|l| BasicError::SheetIdxExceed(l))?; | ||
let cell_id = ctx.fetch_norm_cell_id(&sheet_id, p.row, p.col)?; | ||
|
||
if self | ||
.manager | ||
.merge_cells | ||
.get_merge_cell(&sheet_id, &cell_id) | ||
.is_some() | ||
{ | ||
self.manager.merge_cells = self | ||
.manager | ||
.merge_cells | ||
.remove_merge_cell(sheet_id, cell_id); | ||
Ok((self, true)) | ||
} else { | ||
Ok((self, false)) | ||
} | ||
} | ||
_ => Ok((self, false)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod comment; | ||
pub mod ctx; | ||
pub mod executor; | ||
pub mod merge_cell; | ||
|
||
use comment::Comments; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
crates/controller/src/connectors/cell_attachments_connector.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use logisheets_base::{ | ||
errors::BasicError, | ||
id_fetcher::{IdFetcherTrait, SheetIdFetcherByIdxTrait}, | ||
BlockId, CellId, ColId, ExtBookId, RowId, SheetId, | ||
}; | ||
|
||
use crate::{ | ||
cell_attachments::ctx::CellAttachmentsExecCtx, | ||
ext_book_manager::ExtBooksManager, | ||
id_manager::{FuncIdManager, NameIdManager, SheetIdManager, TextIdManager}, | ||
navigator::Navigator, | ||
workbook::sheet_pos_manager::SheetPosManager, | ||
}; | ||
|
||
pub struct CellAttachmentsConnector<'a> { | ||
pub sheet_pos_manager: &'a SheetPosManager, | ||
pub navigator: &'a Navigator, | ||
pub sheet_id_manager: &'a mut SheetIdManager, | ||
pub name_id_manager: &'a mut NameIdManager, | ||
pub external_links_manager: &'a mut ExtBooksManager, | ||
pub func_id_manager: &'a mut FuncIdManager, | ||
pub text_id_manager: &'a mut TextIdManager, | ||
} | ||
|
||
impl<'a> SheetIdFetcherByIdxTrait for CellAttachmentsConnector<'a> { | ||
fn fetch_sheet_id_by_index(&self, idx: usize) -> Result<SheetId, usize> { | ||
self.sheet_pos_manager | ||
.get_sheet_id(idx) | ||
.ok_or(self.sheet_pos_manager.pos.len()) | ||
} | ||
} | ||
|
||
impl<'a> IdFetcherTrait for CellAttachmentsConnector<'a> { | ||
fn fetch_row_id(&self, sheet_id: &SheetId, row_idx: usize) -> Result<RowId, BasicError> { | ||
self.navigator.fetch_row_id(sheet_id, row_idx) | ||
} | ||
|
||
fn fetch_col_id(&self, sheet_id: &SheetId, col_idx: usize) -> Result<ColId, BasicError> { | ||
self.navigator.fetch_col_id(sheet_id, col_idx) | ||
} | ||
|
||
fn fetch_cell_id( | ||
&self, | ||
sheet_id: &SheetId, | ||
row_idx: usize, | ||
col_idx: usize, | ||
) -> Result<CellId, BasicError> { | ||
self.navigator.fetch_cell_id(sheet_id, row_idx, col_idx) | ||
} | ||
|
||
fn fetch_sheet_id(&mut self, sheet_name: &str) -> SheetId { | ||
self.sheet_id_manager.get_or_register_id(sheet_name) | ||
} | ||
|
||
fn fetch_name_id(&mut self, workbook: &Option<&str>, name: &str) -> logisheets_base::NameId { | ||
let book_id = match workbook { | ||
Some(book) => self.fetch_ext_book_id(book), | ||
None => 0 as ExtBookId, | ||
}; | ||
self.name_id_manager.get_id(&(book_id, name.to_owned())) | ||
} | ||
|
||
fn fetch_ext_book_id(&mut self, book: &str) -> logisheets_base::ExtBookId { | ||
self.external_links_manager.fetch_ext_book_id(book) | ||
} | ||
|
||
fn fetch_text_id(&mut self, text: &str) -> logisheets_base::TextId { | ||
self.text_id_manager.get_or_register_id(text) | ||
} | ||
|
||
fn fetch_func_id(&mut self, func_name: &str) -> logisheets_base::FuncId { | ||
self.func_id_manager.get_func_id(func_name) | ||
} | ||
|
||
fn fetch_norm_cell_id( | ||
&self, | ||
sheet_id: &SheetId, | ||
row_idx: usize, | ||
col_idx: usize, | ||
) -> Result<logisheets_base::NormalCellId, BasicError> { | ||
self.navigator | ||
.fetch_norm_cell_id(sheet_id, row_idx, col_idx) | ||
} | ||
|
||
fn fetch_block_cell_id( | ||
&self, | ||
sheet_id: &SheetId, | ||
block_id: &BlockId, | ||
row: usize, | ||
col: usize, | ||
) -> std::prelude::v1::Result<logisheets_base::BlockCellId, logisheets_base::errors::BasicError> | ||
{ | ||
self.navigator | ||
.fetch_block_cell_id(sheet_id, block_id, row, col) | ||
} | ||
} | ||
|
||
impl<'a> CellAttachmentsExecCtx for CellAttachmentsConnector<'a> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.