mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:57:47 +00:00
Spreadsheet: Track selections across sheet switches
This commit is contained in:
parent
8db5057dc4
commit
dd4bd0943a
3 changed files with 28 additions and 2 deletions
|
@ -150,7 +150,8 @@ public:
|
||||||
|
|
||||||
JsonObject gather_documentation() const;
|
JsonObject gather_documentation() const;
|
||||||
|
|
||||||
Optional<Position> selected_cell() const { return m_selected_cell; }
|
const HashTable<Position>& selected_cells() const { return m_selected_cells; }
|
||||||
|
HashTable<Position>& selected_cells() { return m_selected_cells; }
|
||||||
const HashMap<Position, NonnullOwnPtr<Cell>>& cells() const { return m_cells; }
|
const HashMap<Position, NonnullOwnPtr<Cell>>& cells() const { return m_cells; }
|
||||||
HashMap<Position, NonnullOwnPtr<Cell>>& cells() { return m_cells; }
|
HashMap<Position, NonnullOwnPtr<Cell>>& cells() { return m_cells; }
|
||||||
|
|
||||||
|
@ -200,7 +201,7 @@ private:
|
||||||
Vector<String> m_columns;
|
Vector<String> m_columns;
|
||||||
size_t m_rows { 0 };
|
size_t m_rows { 0 };
|
||||||
HashMap<Position, NonnullOwnPtr<Cell>> m_cells;
|
HashMap<Position, NonnullOwnPtr<Cell>> m_cells;
|
||||||
Optional<Position> m_selected_cell; // FIXME: Make this a collection.
|
HashTable<Position> m_selected_cells;
|
||||||
|
|
||||||
Workbook& m_workbook;
|
Workbook& m_workbook;
|
||||||
mutable SheetGlobalObject* m_global_object;
|
mutable SheetGlobalObject* m_global_object;
|
||||||
|
|
|
@ -79,6 +79,12 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||||
};
|
};
|
||||||
|
|
||||||
m_table_view->on_selection_change = [&] {
|
m_table_view->on_selection_change = [&] {
|
||||||
|
m_sheet->selected_cells().clear();
|
||||||
|
for (auto& index : m_table_view->selection().indexes()) {
|
||||||
|
Position position {m_sheet->column(index.column()), (size_t)index.row()};
|
||||||
|
m_sheet->selected_cells().set(position);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_table_view->selection().is_empty() && on_selection_dropped)
|
if (m_table_view->selection().is_empty() && on_selection_dropped)
|
||||||
return on_selection_dropped();
|
return on_selection_dropped();
|
||||||
|
|
||||||
|
@ -94,6 +100,22 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpreadsheetView::hide_event(GUI::HideEvent&)
|
||||||
|
{
|
||||||
|
if (on_selection_dropped)
|
||||||
|
on_selection_dropped();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpreadsheetView::show_event(GUI::ShowEvent&)
|
||||||
|
{
|
||||||
|
if (on_selection_changed && !m_table_view->selection().is_empty()) {
|
||||||
|
auto selection = m_table_view->selection().first();
|
||||||
|
Position position { m_sheet->column(selection.column()), (size_t)selection.row() };
|
||||||
|
auto& cell = m_sheet->ensure(position);
|
||||||
|
on_selection_changed(position, cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SpreadsheetView::TableCellPainter::paint(GUI::Painter& painter, const Gfx::IntRect& rect, const Gfx::Palette& palette, const GUI::ModelIndex& index)
|
void SpreadsheetView::TableCellPainter::paint(GUI::Painter& painter, const Gfx::IntRect& rect, const Gfx::Palette& palette, const GUI::ModelIndex& index)
|
||||||
{
|
{
|
||||||
// Draw a border.
|
// Draw a border.
|
||||||
|
|
|
@ -47,6 +47,9 @@ public:
|
||||||
Function<void()> on_selection_dropped;
|
Function<void()> on_selection_dropped;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void hide_event(GUI::HideEvent&) override;
|
||||||
|
virtual void show_event(GUI::ShowEvent&) override;
|
||||||
|
|
||||||
SpreadsheetView(Sheet&);
|
SpreadsheetView(Sheet&);
|
||||||
|
|
||||||
class EditingDelegate : public GUI::StringModelEditingDelegate {
|
class EditingDelegate : public GUI::StringModelEditingDelegate {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue