Skip to content

Commit

Permalink
table actions: keyboard shortcuts now configurable in preferences dia…
Browse files Browse the repository at this point in the history
…log and available in toolbar configurability (#2124, #2195, #2219)
  • Loading branch information
giuspen committed Feb 25, 2023
1 parent 1d510bb commit f949ad6
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 84 deletions.
1 change: 1 addition & 0 deletions src/ct/ct_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class CtActions
bool _is_curr_node_not_read_only_or_error();
bool _is_curr_node_not_syntax_highlighting_or_error(bool plain_text_ok = false);
bool _is_there_text_selection_or_error();
bool _is_there_table_selection_or_error();

public:
void object_set_selection(CtAnchoredWidget* widget);
Expand Down
20 changes: 20 additions & 0 deletions src/ct/ct_actions_others.cc
Original file line number Diff line number Diff line change
Expand Up @@ -637,18 +637,21 @@ void CtActions::codebox_decrease_height()

void CtActions::table_cut()
{
if (not _is_there_table_selection_or_error()) return;
object_set_selection(curr_table_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "cut-clipboard");
}

void CtActions::table_copy()
{
if (not _is_there_table_selection_or_error()) return;
object_set_selection(curr_table_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard");
}

void CtActions::table_delete()
{
if (not _is_there_table_selection_or_error()) return;
object_set_selection(curr_table_anchor);
_curr_buffer()->erase_selection(true/*interactive*/, _pCtMainWin->get_text_view().get_editable());
curr_table_anchor = nullptr;
Expand All @@ -657,41 +660,47 @@ void CtActions::table_delete()

void CtActions::table_column_add()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->column_add(curr_table_anchor->current_column());
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_column_delete()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->column_delete(curr_table_anchor->current_column());
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_column_left()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->column_move_left(curr_table_anchor->current_column(), false/*from_move_right*/);
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_column_right()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->column_move_right(curr_table_anchor->current_column());
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_column_increase_width()
{
if (not _is_there_table_selection_or_error()) return;
if (_pCtMainWin->curr_tree_iter().get_node_read_only()) return;
curr_table_anchor->set_col_width(curr_table_anchor->get_col_width() + CtCodebox::CB_WIDTH_HEIGHT_STEP_PIX);
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_column_decrease_width()
{
if (not _is_there_table_selection_or_error()) return;
if (_pCtMainWin->curr_tree_iter().get_node_read_only()) return;
if (curr_table_anchor->get_col_width() - CtCodebox::CB_WIDTH_HEIGHT_STEP_PIX >= CtCodebox::CB_WIDTH_LIMIT_MIN) {
curr_table_anchor->set_col_width(curr_table_anchor->get_col_width() - CtCodebox::CB_WIDTH_HEIGHT_STEP_PIX);
Expand All @@ -701,20 +710,23 @@ void CtActions::table_column_decrease_width()

void CtActions::table_row_add()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->row_add(curr_table_anchor->current_row());
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_row_cut()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
table_row_copy();
table_row_delete();
}

void CtActions::table_row_copy()
{
if (not _is_there_table_selection_or_error()) return;
auto table_state = std::dynamic_pointer_cast<CtAnchoredWidgetState_TableCommon>(curr_table_anchor->get_state());
// remove rows after current
while (table_state->rows.size() > curr_table_anchor->current_row() + 1)
Expand All @@ -729,6 +741,7 @@ void CtActions::table_row_copy()

void CtActions::table_row_paste()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->exit_cell_edit();
CtClipboard{_pCtMainWin}.table_row_paste(curr_table_anchor);
Expand All @@ -737,27 +750,31 @@ void CtActions::table_row_paste()

void CtActions::table_row_delete()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->row_delete(curr_table_anchor->current_row());
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_row_up()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->row_move_up(curr_table_anchor->current_row(), false/*from_move_down*/);
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_row_down()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
curr_table_anchor->row_move_down(curr_table_anchor->current_row());
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

void CtActions::table_rows_sort_descending()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
if (curr_table_anchor->row_sort_desc()) {
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
Expand All @@ -766,6 +783,7 @@ void CtActions::table_rows_sort_descending()

void CtActions::table_rows_sort_ascending()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
if (curr_table_anchor->row_sort_asc()) {
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
Expand All @@ -774,6 +792,7 @@ void CtActions::table_rows_sort_ascending()

void CtActions::table_edit_properties()
{
if (not _is_there_table_selection_or_error()) return;
if (not _is_curr_node_not_read_only_or_error()) return;
_pCtConfig->tableColWidthDefault = curr_table_anchor->get_col_width_default();
const bool was_light = curr_table_anchor->get_is_light();
Expand Down Expand Up @@ -802,6 +821,7 @@ void CtActions::table_edit_properties()

void CtActions::table_export()
{
if (not _is_there_table_selection_or_error()) return;
CtDialogs::FileSelectArgs args{_pCtMainWin};
args.curr_folder = _pCtConfig->pickDirCsv;
args.curr_file_name = "";
Expand Down
31 changes: 31 additions & 0 deletions src/ct/ct_actions_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,37 @@ bool CtActions::_is_there_text_selection_or_error()
return true;
}

bool CtActions::_is_there_table_selection_or_error()
{
if (not _is_there_selected_node_or_error()) return false;
if (not _is_curr_node_not_syntax_highlighting_or_error()) return false;
bool already_failed{false};
Gtk::TextIter iter_insert;
if (_curr_buffer()->get_has_selection()) {
Gtk::TextIter iter_sel_end;
_pCtMainWin->get_text_view().get_buffer()->get_selection_bounds(iter_insert, iter_sel_end);
const int num_chars = iter_sel_end.get_offset() - iter_insert.get_offset();
if (num_chars != 1) {
already_failed = true;
}
}
else {
iter_insert = _pCtMainWin->get_text_view().get_buffer()->get_insert()->get_iter();
}
if (not already_failed) {
auto widgets = _pCtMainWin->curr_tree_iter().get_anchored_widgets(iter_insert.get_offset(), iter_insert.get_offset());
if (not widgets.empty()) {
auto pTableCommon = dynamic_cast<CtTableCommon*>(widgets.front());
if (pTableCommon) {
curr_table_anchor = pTableCommon;
return true;
}
}
}
CtDialogs::error_dialog(_("No Table is Selected."), *_pCtMainWin);
return false;
}

// Put Selection Upon the achrored widget
void CtActions::object_set_selection(CtAnchoredWidget* widget)
{
Expand Down
88 changes: 44 additions & 44 deletions src/ct/ct_menu_actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void CtMenu::init_actions(CtActions* pActions)
_actions.push_back(CtMenuAction{"", "FindSubMenu", "ct_find", _("_Find"), None, None, sigc::signal<void>()});
_actions.push_back(CtMenuAction{"", "ReplaceSubMenu", "ct_find_replace", _("_Replace"), None, None, sigc::signal<void>()});
_actions.push_back(CtMenuAction{"", "RowSubMenu", "ct_edit", _("Ro_w"), None, None, sigc::signal<void>()});
_actions.push_back(CtMenuAction{"", "TableSubMenu", "ct_table_edit", _("_Table"), None, None, sigc::signal<void>()});
_actions.push_back(CtMenuAction{"", "FormattingSubMenu", "ct_fmt-txt", _("F_ormat"), None, None, sigc::signal<void>()});

// main actions
Expand Down Expand Up @@ -150,6 +151,49 @@ void CtMenu::init_actions(CtActions* pActions)
_actions.push_back(CtMenuAction{editor_cat, "mv_down_row", "ct_go-down", _("Mo_ve Down Row"), KB_ALT+CtConst::STR_KEY_DOWN,
_("Move Down the Current Row/Selected Rows"), sigc::mem_fun(*pActions, &CtActions::text_row_down)});

_actions.push_back(CtMenuAction{editor_cat, "table_cut", "ct_edit_cut", _("C_ut Table"), None,
_("Cut the Selected Table"), sigc::mem_fun(*pActions, &CtActions::table_cut)});
_actions.push_back(CtMenuAction{editor_cat, "table_copy", "ct_edit_copy", _("_Copy Table"), None,
_("Copy the Selected Table"), sigc::mem_fun(*pActions, &CtActions::table_copy)});
_actions.push_back(CtMenuAction{editor_cat, "table_delete", "ct_edit_delete", _("_Delete Table"), None,
_("Delete the Selected Table"), sigc::mem_fun(*pActions, &CtActions::table_delete)});
_actions.push_back(CtMenuAction{editor_cat, "table_column_add", "ct_add", _("_Add Column"), None,
_("Add a Table Column"), sigc::mem_fun(*pActions, &CtActions::table_column_add)});
_actions.push_back(CtMenuAction{editor_cat, "table_column_delete", "ct_edit_delete", _("De_lete Column"), None,
_("Delete the Selected Table Column"), sigc::mem_fun(*pActions, &CtActions::table_column_delete)});
_actions.push_back(CtMenuAction{editor_cat, "table_column_left", "ct_go-back", _("Move Column _Left"), KB_CONTROL+"braceleft",
_("Move the Selected Column Left"), sigc::mem_fun(*pActions, &CtActions::table_column_left)});
_actions.push_back(CtMenuAction{editor_cat, "table_column_right", "ct_go-forward", _("Move Column _Right"), KB_CONTROL+"braceright",
_("Move the Selected Column Right"), sigc::mem_fun(*pActions, &CtActions::table_column_right)});
_actions.push_back(CtMenuAction{editor_cat, "table_column_increase_width", "ct_go-forward",
_("Increase Column Width"), KB_CONTROL+"parenleft",
_("Increase the Width of the Column"), sigc::mem_fun(*pActions, &CtActions::table_column_increase_width)});
_actions.push_back(CtMenuAction{editor_cat, "table_column_decrease_width", "ct_go-back",
_("Decrease Column Width"), KB_CONTROL+KB_ALT+"parenleft",
_("Decrease the Width of the Column"), sigc::mem_fun(*pActions, &CtActions::table_column_decrease_width)});
_actions.push_back(CtMenuAction{editor_cat, "table_row_add", "ct_add", _("_Add Row"), KB_CONTROL+"comma",
_("Add a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_add)});
_actions.push_back(CtMenuAction{editor_cat, "table_row_cut", "ct_edit_cut", _("Cu_t Row"), None,
_("Cut a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_cut)});
_actions.push_back(CtMenuAction{editor_cat, "table_row_copy", "ct_edit_copy", _("_Copy Row"), None,
_("Copy a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_copy)});
_actions.push_back(CtMenuAction{editor_cat, "table_row_paste", "ct_edit_paste", _("_Paste Row"), None,
_("Paste a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_paste)});
_actions.push_back(CtMenuAction{editor_cat, "table_row_delete", "ct_edit_delete", _("De_lete Row"), KB_CONTROL+KB_ALT+"comma",
_("Delete the Selected Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_delete)});
_actions.push_back(CtMenuAction{editor_cat, "table_row_up", "ct_go-up", _("Move Row _Up"), KB_CONTROL+"bracketleft",
_("Move the Selected Row Up"), sigc::mem_fun(*pActions, &CtActions::table_row_up)});
_actions.push_back(CtMenuAction{editor_cat, "table_row_down", "ct_go-down", _("Move Row _Down"), KB_CONTROL+"bracketright",
_("Move the Selected Row Down"), sigc::mem_fun(*pActions, &CtActions::table_row_down)});
_actions.push_back(CtMenuAction{editor_cat, "table_rows_sort_descending", "ct_sort-desc", _("Sort Rows De_scending"), None,
_("Sort all the Rows Descending"), sigc::mem_fun(*pActions, &CtActions::table_rows_sort_descending)});
_actions.push_back(CtMenuAction{editor_cat, "table_rows_sort_ascending", "ct_sort-asc", _("Sort Rows As_cending"), None,
_("Sort all the Rows Ascending"), sigc::mem_fun(*pActions, &CtActions::table_rows_sort_ascending)});
_actions.push_back(CtMenuAction{editor_cat, "table_edit_properties", "ct_table_edit", _("_Edit Table Properties..."), None,
_("Edit the Table Properties"), sigc::mem_fun(*pActions, &CtActions::table_edit_properties)});
_actions.push_back(CtMenuAction{editor_cat, "table_export", "ct_table_save", _("_Table Export..."), None,
_("Export Table as CSV File"), sigc::mem_fun(*pActions, &CtActions::table_export)});

const char* fmt_cat = _("Format");
_actions.push_back(CtMenuAction{fmt_cat, "fmt_clone", "ct_fmt-txt-clone", _("Format Clo_ne"), None,
_("Clone the Text Format Type at Cursor"), sigc::mem_fun(*pActions, &CtActions::save_tags_at_cursor_as_latest)});
Expand Down Expand Up @@ -474,50 +518,6 @@ void CtMenu::init_actions(CtActions* pActions)
_actions.push_back(CtMenuAction{link_cat, "link_delete", "ct_edit_delete", _("_Delete Link"), None,
_("Delete the Selected Link"), sigc::mem_fun(*pActions, &CtActions::link_delete)});

const char* table_cat = "";
_actions.push_back(CtMenuAction{table_cat, "table_cut", "ct_edit_cut", _("C_ut Table"), None,
_("Cut the Selected Table"), sigc::mem_fun(*pActions, &CtActions::table_cut)});
_actions.push_back(CtMenuAction{table_cat, "table_copy", "ct_edit_copy", _("_Copy Table"), None,
_("Copy the Selected Table"), sigc::mem_fun(*pActions, &CtActions::table_copy)});
_actions.push_back(CtMenuAction{table_cat, "table_delete", "ct_edit_delete", _("_Delete Table"), None,
_("Delete the Selected Table"), sigc::mem_fun(*pActions, &CtActions::table_delete)});
_actions.push_back(CtMenuAction{table_cat, "table_column_add", "ct_add", _("_Add Column"), None,
_("Add a Table Column"), sigc::mem_fun(*pActions, &CtActions::table_column_add)});
_actions.push_back(CtMenuAction{table_cat, "table_column_delete", "ct_edit_delete", _("De_lete Column"), None,
_("Delete the Selected Table Column"), sigc::mem_fun(*pActions, &CtActions::table_column_delete)});
_actions.push_back(CtMenuAction{table_cat, "table_column_left", "ct_go-back", _("Move Column _Left"), KB_CONTROL+"braceleft",
_("Move the Selected Column Left"), sigc::mem_fun(*pActions, &CtActions::table_column_left)});
_actions.push_back(CtMenuAction{table_cat, "table_column_right", "ct_go-forward", _("Move Column _Right"), KB_CONTROL+"braceright",
_("Move the Selected Column Right"), sigc::mem_fun(*pActions, &CtActions::table_column_right)});
_actions.push_back(CtMenuAction{table_cat, "table_column_increase_width", "ct_go-forward",
_("Increase Column Width"), KB_CONTROL+"parenleft",
_("Increase the Width of the Column"), sigc::mem_fun(*pActions, &CtActions::table_column_increase_width)});
_actions.push_back(CtMenuAction{table_cat, "table_column_decrease_width", "ct_go-back",
_("Decrease Column Width"), KB_CONTROL+KB_ALT+"parenleft",
_("Decrease the Width of the Column"), sigc::mem_fun(*pActions, &CtActions::table_column_decrease_width)});
_actions.push_back(CtMenuAction{table_cat, "table_row_add", "ct_add", _("_Add Row"), KB_CONTROL+"comma",
_("Add a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_add)});
_actions.push_back(CtMenuAction{table_cat, "table_row_cut", "ct_edit_cut", _("Cu_t Row"), None,
_("Cut a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_cut)});
_actions.push_back(CtMenuAction{table_cat, "table_row_copy", "ct_edit_copy", _("_Copy Row"), None,
_("Copy a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_copy)});
_actions.push_back(CtMenuAction{table_cat, "table_row_paste", "ct_edit_paste", _("_Paste Row"), None,
_("Paste a Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_paste)});
_actions.push_back(CtMenuAction{table_cat, "table_row_delete", "ct_edit_delete", _("De_lete Row"), KB_CONTROL+KB_ALT+"comma",
_("Delete the Selected Table Row"), sigc::mem_fun(*pActions, &CtActions::table_row_delete)});
_actions.push_back(CtMenuAction{table_cat, "table_row_up", "ct_go-up", _("Move Row _Up"), KB_CONTROL+"bracketleft",
_("Move the Selected Row Up"), sigc::mem_fun(*pActions, &CtActions::table_row_up)});
_actions.push_back(CtMenuAction{table_cat, "table_row_down", "ct_go-down", _("Move Row _Down"), KB_CONTROL+"bracketright",
_("Move the Selected Row Down"), sigc::mem_fun(*pActions, &CtActions::table_row_down)});
_actions.push_back(CtMenuAction{table_cat, "table_rows_sort_descending", "ct_sort-desc", _("Sort Rows De_scending"), None,
_("Sort all the Rows Descending"), sigc::mem_fun(*pActions, &CtActions::table_rows_sort_descending)});
_actions.push_back(CtMenuAction{table_cat, "table_rows_sort_ascending", "ct_sort-asc", _("Sort Rows As_cending"), None,
_("Sort all the Rows Ascending"), sigc::mem_fun(*pActions, &CtActions::table_rows_sort_ascending)});
_actions.push_back(CtMenuAction{table_cat, "table_edit_properties", "ct_table_edit", _("_Edit Table Properties..."), None,
_("Edit the Table Properties"), sigc::mem_fun(*pActions, &CtActions::table_edit_properties)});
_actions.push_back(CtMenuAction{table_cat, "table_export", "ct_table_save", _("_Table Export..."), None,
_("Export Table as CSV File"), sigc::mem_fun(*pActions, &CtActions::table_export)});

const char* codebox_cat = "";
_actions.push_back(CtMenuAction{codebox_cat, "codebox_change_properties", "ct_codebox_edit", _("Change CodeBox _Properties..."), KB_CONTROL+"bracketleft",
_("Edit the Properties of the CodeBox"), sigc::mem_fun(*pActions, &CtActions::codebox_change_properties)});
Expand Down
Loading

0 comments on commit f949ad6

Please sign in to comment.