Skip to content

Commit

Permalink
implementing lightweight variant of tables (#2140)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuspen committed Dec 20, 2022
1 parent bdbae6e commit 003274b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/ct/ct_actions_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ CtActions::text_view_n_buffer_codebox_proof CtActions::_get_text_view_n_buffer_c
}
if (CtTable* pTable = _table_in_use()) {
return text_view_n_buffer_codebox_proof{
&static_cast<CtTextCell*>(pTable->get_table_matrix().at(pTable->current_row()).at(pTable->current_column()))->get_text_view(),
&pTable->curr_cell_text_view(),
CtConst::PLAIN_TEXT_ID,
nullptr,
pTable};
Expand Down
5 changes: 5 additions & 0 deletions src/ct/ct_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ void CtTable::grab_focus() const
static_cast<CtTextCell*>(_tableMatrix.at(current_row()).at(current_column()))->get_text_view().grab_focus();
}

CtTextView& CtTable::curr_cell_text_view() const
{
return static_cast<CtTextCell*>(_tableMatrix.at(current_row()).at(current_column()))->get_text_view();
}

void CtTable::_on_populate_popup_cell(Gtk::Menu* menu)
{
if (not _pCtMainWin->user_active()) return;
Expand Down
2 changes: 1 addition & 1 deletion src/ct/ct_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CtTable : public CtTableCommon
CtAnchWidgType get_type() override { return CtAnchWidgType::Table; }
std::shared_ptr<CtAnchoredWidgetState> get_state() override;

const CtTableMatrix& get_table_matrix() const { return _tableMatrix; }
CtTextView& curr_cell_text_view() const;

void write_strings_matrix(std::vector<std::vector<Glib::ustring>>& rows) const override;
size_t get_num_rows() const override { return _tableMatrix.size(); }
Expand Down
43 changes: 10 additions & 33 deletions tests/tests_read_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,41 +493,18 @@ void TestCtApp::_assert_tree_data(CtMainWin* pWin)
for (size_t i = 0; i < expected_column_widths.size(); ++i) {
ASSERT_EQ(expected_column_widths.at(i), actual_column_widths.at(i));
}
const CtTableMatrix& tableMatrix = pTable->get_table_matrix();
std::vector<std::vector<Glib::ustring>> rows;
pTable->write_strings_matrix(rows);
// three rows
ASSERT_EQ(3, tableMatrix.size());
ASSERT_EQ(3, rows.size());
// two columns
ASSERT_EQ(2, tableMatrix.at(0).size());
{
CtTextCell* pCell = static_cast<CtTextCell*>(tableMatrix.at(0).at(0));
ASSERT_STREQ("h1", pCell->get_text_content().c_str());
ASSERT_STREQ(CtConst::TABLE_CELL_TEXT_ID, pCell->get_syntax_highlighting().c_str());
}
{
CtTextCell* pCell = static_cast<CtTextCell*>(tableMatrix.at(0).at(1));
ASSERT_STREQ("h2", pCell->get_text_content().c_str());
ASSERT_STREQ(CtConst::TABLE_CELL_TEXT_ID, pCell->get_syntax_highlighting().c_str());
}
{
CtTextCell* pCell = static_cast<CtTextCell*>(tableMatrix.at(1).at(0));
ASSERT_STREQ("йцукенгшщз", pCell->get_text_content().c_str());
ASSERT_STREQ(CtConst::TABLE_CELL_TEXT_ID, pCell->get_syntax_highlighting().c_str());
}
{
CtTextCell* pCell = static_cast<CtTextCell*>(tableMatrix.at(1).at(1));
ASSERT_STREQ("2", pCell->get_text_content().c_str());
ASSERT_STREQ(CtConst::TABLE_CELL_TEXT_ID, pCell->get_syntax_highlighting().c_str());
}
{
CtTextCell* pCell = static_cast<CtTextCell*>(tableMatrix.at(2).at(0));
ASSERT_STREQ("3", pCell->get_text_content().c_str());
ASSERT_STREQ(CtConst::TABLE_CELL_TEXT_ID, pCell->get_syntax_highlighting().c_str());
}
{
CtTextCell* pCell = static_cast<CtTextCell*>(tableMatrix.at(2).at(1));
ASSERT_STREQ("4", pCell->get_text_content().c_str());
ASSERT_STREQ(CtConst::TABLE_CELL_TEXT_ID, pCell->get_syntax_highlighting().c_str());
}
ASSERT_EQ(2, rows.at(0).size());
ASSERT_STREQ("h1", rows.at(0).at(0).c_str());
ASSERT_STREQ("h2", rows.at(0).at(1).c_str());
ASSERT_STREQ("йцукенгшщз", rows.at(1).at(0).c_str());
ASSERT_STREQ("2", rows.at(1).at(1).c_str());
ASSERT_STREQ("3", rows.at(2).at(0).c_str());
ASSERT_STREQ("4", rows.at(2).at(1).c_str());
} break;
case CtAnchWidgType::TableLight: {
//TODO
Expand Down

0 comments on commit 003274b

Please sign in to comment.