diff --git a/devel/201_80.md b/devel/201_80.md new file mode 100644 index 0000000000..5ec9f2ed24 --- /dev/null +++ b/devel/201_80.md @@ -0,0 +1,15 @@ +# [201_80] 定制化表格handles显示 + +## 如何测试 +1. 插入任意样式的表格(大表格、小表格除外),handles应该正确显示,且支持拖拽 +2. 插入`align`、`eqnarray`、`gather`、`multline`、`alignat`、`flalign`等数学环境,handles应该不显示,且不支持拖拽 +3. 手动修改样式TS文件(`样式`->`编辑样式`),插入 `` 后保存 +4. 再次插入任意表格,handles应该始终不显示,且不支持拖拽 + +## 2026/2/9 +### What +在align环境等数学环境下的所有表格结构的组件,在编辑时,handles都应该不显示,也不应支持拖拽 + +### How +1. 在 `vars.hpp`、 `vars.cpp` 和 `env_default.cpp` 中添加 `TABLE_HANDLES` 环境变量,默认值为 `"true"`,表示表格handles默认显示 +2. 在 `edit_repaint.cpp` 中的 `repaint_table_handles` 函数中添加判断,如果当前表格所在环境不是“真表格”(通过 `is_true_table` 判断),则不显示handles;如果 `TABLE_HANDLES` 环境变量值为 `"false"`,则始终不显示handles diff --git a/moebius/moebius/drd/drd_std.cpp b/moebius/moebius/drd/drd_std.cpp index 461c6bf084..acdd00f3e6 100644 --- a/moebius/moebius/drd/drd_std.cpp +++ b/moebius/moebius/drd/drd_std.cpp @@ -1352,6 +1352,7 @@ init_std_drd () { init_var (TABLE_MIN_COLS, TYPE_INTEGER); init_var (TABLE_MAX_ROWS, TYPE_INTEGER); init_var (TABLE_MAX_COLS, TYPE_INTEGER); + init_var (TABLE_HANDLES, TYPE_STRING); init_var (CELL_FORMAT, TYPE_ADHOC); init_var (CELL_DECORATION, TYPE_ADHOC); diff --git a/moebius/moebius/vars.cpp b/moebius/moebius/vars.cpp index 46fdbbc9a5..98ec1102bf 100644 --- a/moebius/moebius/vars.cpp +++ b/moebius/moebius/vars.cpp @@ -233,6 +233,7 @@ string TABLE_MIN_ROWS ("table-min-rows"); string TABLE_MIN_COLS ("table-min-cols"); string TABLE_MAX_ROWS ("table-max-rows"); string TABLE_MAX_COLS ("table-max-cols"); +string TABLE_HANDLES ("table-handles"); /****************************************************************************** * Environment variables for cells of tables diff --git a/moebius/moebius/vars.hpp b/moebius/moebius/vars.hpp index 74c89932c7..ce5f8d2672 100644 --- a/moebius/moebius/vars.hpp +++ b/moebius/moebius/vars.hpp @@ -216,6 +216,7 @@ extern string TABLE_MIN_ROWS; extern string TABLE_MIN_COLS; extern string TABLE_MAX_ROWS; extern string TABLE_MAX_COLS; +extern string TABLE_HANDLES; extern string CELL_FORMAT; extern string CELL_DECORATION; diff --git a/src/Edit/Interface/edit_interface.cpp b/src/Edit/Interface/edit_interface.cpp index 019c84c6e2..66bd4d305d 100644 --- a/src/Edit/Interface/edit_interface.cpp +++ b/src/Edit/Interface/edit_interface.cpp @@ -1184,6 +1184,21 @@ edit_interface_rep::is_embedded_widget () { // FIXME: could be made more robust: test should not be based on file name } +bool +edit_interface_rep::is_true_table (path p) { + for (path q= p; !is_nil (q) && q != rp; q= path_up (q)) { + tree qt= subtree (et, q); + if (is_compound (qt, "align") || is_compound (qt, "align*") || + is_compound (qt, "eqnarray") || is_compound (qt, "eqnarray*") || + is_compound (qt, "gather") || is_compound (qt, "gather*") || + is_compound (qt, "multline") || is_compound (qt, "multline*") || + is_compound (qt, "alignat") || is_compound (qt, "alignat*") || + is_compound (qt, "flalign") || is_compound (qt, "flalign*")) + return false; + } + return true; +} + void edit_interface_rep::handle_get_size_hint (SI& w, SI& h) { gui_root_extents (w, h); diff --git a/src/Edit/Interface/edit_interface.hpp b/src/Edit/Interface/edit_interface.hpp index f7f49bbc3c..db5e7cfb45 100644 --- a/src/Edit/Interface/edit_interface.hpp +++ b/src/Edit/Interface/edit_interface.hpp @@ -278,6 +278,7 @@ class edit_interface_rep : virtual public editor_rep { /* event handlers */ bool is_editor_widget (); bool is_embedded_widget (); + bool is_true_table (path p); void handle_get_size_hint (SI& w, SI& h); void handle_notify_resize (SI w, SI h); void handle_keypress (string key, time_t t); diff --git a/src/Edit/Interface/edit_repaint.cpp b/src/Edit/Interface/edit_repaint.cpp index ddf7909161..797f1248dc 100644 --- a/src/Edit/Interface/edit_repaint.cpp +++ b/src/Edit/Interface/edit_repaint.cpp @@ -250,6 +250,13 @@ edit_interface_rep::draw_image_resize_handles (renderer ren) { void edit_interface_rep::draw_table_resize_handles (renderer ren) { + if (as_string (get_env_value (TABLE_HANDLES)) == "false") { + if (!is_zero (last_table_brec)) invalidate (last_table_brec); + last_table_brec= rectangle (0, 0, 0, 0); + last_table_hr = 0; + return; + } + // 鼠标位于表格中时,绘制 handles SI hs = 8 * ren->pixel; // handles 半径(正方形半边长) rectangle new_table_brec= rectangle (0, 0, 0, 0); @@ -260,6 +267,7 @@ edit_interface_rep::draw_table_resize_handles (renderer ren) { for (path p= path_up (tp); !is_nil (p) && p != rp; p= path_up (p)) { tree st= subtree (et, p); if (!is_func (st, TABLE)) continue; + if (!is_true_table (p)) break; selection sel= eb->find_check_selection (p * 0, p * 1); if (!sel->valid || is_nil (sel->rs)) break; diff --git a/src/Typeset/Env/env_default.cpp b/src/Typeset/Env/env_default.cpp index dcb4f5b594..910f1f9f7e 100644 --- a/src/Typeset/Env/env_default.cpp +++ b/src/Typeset/Env/env_default.cpp @@ -234,6 +234,7 @@ initialize_default_env () { env (TABLE_MIN_COLS) = ""; // suggested minimal number of columns env (TABLE_MAX_ROWS) = ""; // suggested maximal number of rows env (TABLE_MAX_COLS) = ""; // suggested maximal number of columns + env (TABLE_HANDLES) = "true"; // show table resize handles env (CELL_DECORATION) = ""; // decorating table of cell env (CELL_FORMAT) = tree (TFORMAT); // format of cell