Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions linux/crates/app/src/services/cell_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ pub struct CellOverlay {
pub error_flash: bool,
}

/// What tints a cell, without its pending value: every bind asks this
/// of every cell, and copying a value or scanning every edit to tint
/// one would grow with the edits held.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CellMarks {
pub row_deleted: bool,
pub state: CellState,
pub error_flash: bool,
}

#[cfg(test)]
impl CellOverlay {
/// The value the cell shows over `fetched`, a cell left to the
Expand Down
28 changes: 27 additions & 1 deletion linux/crates/app/src/services/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tablepro_core::meta::RowIdentity;
use tablepro_core::save::{ChangeSet, RowChange, RowUpdate};
use tablepro_core::{ColumnInfo, Value};

use super::cell_overlay::CellOverlay;
use super::cell_overlay::{CellMarks, CellOverlay};
use super::column_relayout::{ColumnRelayout, Misfit};
use super::save_batch::{SaveBatch, SaveTarget};
use super::touch::Touch;
Expand Down Expand Up @@ -510,6 +510,14 @@ impl TabChangeTracker {
}
}

pub fn cell_marks(&self, row_key: &RowKey, col: usize) -> CellMarks {
CellMarks {
row_deleted: self.deletes.contains_key(row_key),
state: self.cell_state(row_key, col),
error_flash: self.is_error_row(row_key),
}
}

fn cell_state(&self, row_key: &RowKey, col: usize) -> CellState {
if matches!(row_key, RowKey::Draft(_)) {
return CellState::InsertDraft;
Expand Down Expand Up @@ -1148,6 +1156,24 @@ mod tests {
assert_eq!(t.pending_count(), 2);
}

#[test]
fn cell_marks_tint_a_cell_by_its_own_edit_and_its_rows_delete() {
let mut t = TabChangeTracker::default();
let (edited, deleted) = (rk(&[Value::Int(1)]), rk(&[Value::Int(2)]));
t.track_cell_edit(edited.clone(), 1, Value::Text("a".into()), Value::Text("b".into()));
delete(&mut t, deleted.clone(), vec![Value::Int(2), Value::Text("c".into())]);
let draft = RowKey::Draft(insert(&mut t, vec![Value::Null, Value::Null]));

let marks = |key: &RowKey, col| {
let marks = t.cell_marks(key, col);
(marks.row_deleted, marks.state)
};
assert_eq!(marks(&edited, 1), (false, CellState::Modified));
assert_eq!(marks(&edited, 0), (false, CellState::Clean));
assert_eq!(marks(&deleted, 0), (true, CellState::Clean));
assert_eq!(marks(&draft, 0), (false, CellState::InsertDraft));
}

#[test]
fn delete_marks_row_pending() {
let mut t = TabChangeTracker::default();
Expand Down
6 changes: 5 additions & 1 deletion linux/crates/app/src/services/tab_tracker_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tablepro_core::dml::BuildSqlError;
use tablepro_core::edit::CellInput;
use tablepro_core::{ColumnInfo, Value};

use super::cell_overlay::CellOverlay;
use super::cell_overlay::{CellMarks, CellOverlay};
use super::change_tracker::{DraftRow, ErrorFlash, RowKey, RowState, TabChangeTracker, TrackedChanges};
use super::save_batch::{SaveBatch, SaveTarget};
use super::tracker_delta::TrackerDelta;
Expand All @@ -23,6 +23,10 @@ impl TabTrackerHandle {
self.0.borrow().cell_overlay(row_key, col)
}

pub fn cell_marks(&self, row_key: &RowKey, col: usize) -> CellMarks {
self.0.borrow().cell_marks(row_key, col)
}

pub fn row_state(&self, row_key: &RowKey) -> RowState {
self.0.borrow().row_state(row_key)
}
Expand Down
21 changes: 19 additions & 2 deletions linux/crates/app/src/ui/browse_tab/browse_actions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use gtk4 as gtk;
use gtk4::gio;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use gtk4::{gio, glib};

use super::{
BrowseModel, BrowseTab, BrowseTabInput, ClipboardInput, EditInput, PagingInput, SaveInput, SelectionInput,
Expand All @@ -24,6 +24,10 @@ pub(super) struct BrowseActions {
pub(super) delete_rows: gio::SimpleAction,
pub(super) copy_rows: gio::SimpleAction,
pub(super) clear_selection: gio::SimpleAction,
/// The More menu's Count Rows, on where the pager offers it.
pub(super) count_rows: gio::SimpleAction,
/// The More menu's page sizes, its state the size the tab reads.
pub(super) page_size: gio::SimpleAction,
}

impl BrowseActions {
Expand All @@ -43,7 +47,7 @@ impl BrowseActions {
/// The tab's `browse` group, the tab's own keys for it and the keys its
/// buttons announce. The grid's keys go on each column view the tab
/// builds, through `install_grid_shortcuts`.
pub(super) fn install_browse_actions(tab: &BrowseTab) -> BrowseActions {
pub(super) fn install_browse_actions(tab: &BrowseTab, page_size: u64) -> BrowseActions {
let group = gio::SimpleActionGroup::new();
let add = |name: &str, input: fn() -> BrowseTabInput| {
let action = gio::SimpleAction::new(name, None);
Expand All @@ -57,6 +61,16 @@ pub(super) fn install_browse_actions(tab: &BrowseTab) -> BrowseActions {
action
};
add("filter", || PagingInput::ToggleFilterStrip.into());
add("export", || ClipboardInput::Export(None).into());
let page_size =
gio::SimpleAction::new_stateful("page-size", Some(glib::VariantTy::UINT64), &page_size.to_variant());
let weak = tab.downgrade();
page_size.connect_change_state(move |_, size| {
if let (Some(tab), Some(size)) = (weak.upgrade(), size.and_then(u64::from_variant)) {
tab.send(PagingInput::PageSizeChanged(size));
}
});
group.add_action(&page_size);
add("refresh", || PagingInput::RequestRefresh.into());
add("paste-rows", || ClipboardInput::PasteNotSupported.into());
let previous = add("previous-page", || PagingInput::PrevPage.into());
Expand All @@ -80,6 +94,8 @@ pub(super) fn install_browse_actions(tab: &BrowseTab) -> BrowseActions {
delete_rows,
copy_rows: add("copy-rows", || ClipboardInput::CopySelectedRowsAsTsv.into()),
clear_selection: add("clear-selection", || SelectionInput::ClearSelection.into()),
count_rows: add("count-rows", || PagingInput::CountRows.into()),
page_size,
};
for action in [
&actions.save,
Expand All @@ -89,6 +105,7 @@ pub(super) fn install_browse_actions(tab: &BrowseTab) -> BrowseActions {
&actions.delete_rows,
&actions.copy_rows,
&actions.clear_selection,
&actions.count_rows,
] {
action.set_enabled(false);
}
Expand Down
Loading
Loading