mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-22 13:00:22 -04:00
wip: the beginnings of ui for modifying colors
This commit is contained in:
parent
9db2eb91ad
commit
8f07e8c0e7
@ -251,6 +251,12 @@ impl Book {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_cell_style(&mut self, style: &Style, sheet: u32, cell: &Address) -> Result<()> {
|
||||
self.model.set_cell_style(sheet, cell.row as i32, cell.col as i32, style)
|
||||
.map_err(|s| anyhow!("Unable to format cell {}", s))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get a cells rendered content for display.
|
||||
pub fn get_cell_addr_rendered(&self, Address { row, col }: &Address) -> Result<String> {
|
||||
Ok(self
|
||||
|
@ -7,6 +7,9 @@ pub enum Cmd<'a> {
|
||||
Write(Option<&'a str>),
|
||||
InsertRows(usize),
|
||||
InsertColumns(usize),
|
||||
ColorRows(usize, &'a str),
|
||||
ColorColumns(usize, &'a str),
|
||||
ColorCell(&'a str),
|
||||
RenameSheet(Option<usize>, &'a str),
|
||||
NewSheet(Option<&'a str>),
|
||||
SelectSheet(&'a str),
|
||||
@ -51,6 +54,9 @@ pub fn parse<'cmd, 'i: 'cmd>(input: &'i str) -> Result<Option<Cmd<'cmd>>, &'stat
|
||||
if let Some(cmd) = try_consume_rename_sheet(cursor.clone())? {
|
||||
return Ok(Some(cmd));
|
||||
}
|
||||
if let Some(cmd) = try_consume_color_cell(cursor.clone())? {
|
||||
return Ok(Some(cmd));
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@ -138,6 +144,28 @@ fn try_consume_select_sheet<'cmd, 'i: 'cmd>(
|
||||
return Ok(Some(Cmd::SelectSheet(arg)));
|
||||
}
|
||||
|
||||
fn try_consume_color_cell<'cmd, 'i: 'cmd>(
|
||||
mut input: StrCursor<'i>,
|
||||
) -> Result<Option<Cmd<'cmd>>, &'static str> {
|
||||
const SHORT: &'static str = "cc";
|
||||
const LONG: &'static str = "color-cell";
|
||||
if compare(input.clone(), LONG) {
|
||||
input.seek(LONG.len());
|
||||
} else if compare(input.clone(), SHORT) {
|
||||
input.seek(SHORT.len());
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
if input.remaining() > 0 && !is_ws(&mut input) {
|
||||
return Err("Invalid command: Did you mean to type `color-cell <color>`?");
|
||||
}
|
||||
let arg = input.span(0..).trim();
|
||||
if arg.len() == 0 {
|
||||
return Err("Invalid command: Did you mean to type `color-cell <color>`?");
|
||||
}
|
||||
return Ok(Some(Cmd::ColorCell(arg)));
|
||||
}
|
||||
|
||||
fn try_consume_insert_row<'cmd, 'i: 'cmd>(
|
||||
mut input: StrCursor<'i>,
|
||||
) -> Result<Option<Cmd<'cmd>>, &'static str> {
|
||||
|
@ -465,6 +465,21 @@ impl<'ws> Workspace<'ws> {
|
||||
Ok(Some(Cmd::Quit)) => {
|
||||
Ok(Some(ExitCode::SUCCESS))
|
||||
}
|
||||
Ok(Some(Cmd::ColorRows(_count, _color))) => {
|
||||
Ok(Some(ExitCode::FAILURE))
|
||||
}
|
||||
Ok(Some(Cmd::ColorColumns(_count, _color))) => {
|
||||
Ok(Some(ExitCode::FAILURE))
|
||||
}
|
||||
Ok(Some(Cmd::ColorCell(color))) => {
|
||||
let address = self.book.location.clone();
|
||||
let sheet = self.book.current_sheet;
|
||||
let mut style = self.book.get_cell_style(sheet, &address)
|
||||
.expect("I think this should be impossible.").clone();
|
||||
style.fill.bg_color = Some(color.to_string());
|
||||
self.book.set_cell_style(&style, sheet, &address)?;
|
||||
Ok(None)
|
||||
}
|
||||
Ok(None) => {
|
||||
self.enter_dialog_mode(vec![format!("Unrecognized commmand {}", cmd_text)]);
|
||||
Ok(None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user