From 48b9cd75972ce3b05661b425007ad3d7f4bd678e Mon Sep 17 00:00:00 2001 From: wang-junbo456 Date: Thu, 11 Dec 2025 08:28:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Signed-off-by:=20wang-junbo456=20=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=BD=93=E5=89=8D=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E9=93=BE=E6=8E=A5=E5=B9=B6=E9=80=89=E6=8B=A9=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E6=96=87=E4=BB=B6=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=BE=83=E5=A4=A7=E6=88=96=E4=B8=BA=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E5=8C=85=EF=BC=8C=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=8D=A1=E6=AD=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TeXmacs/progs/generic/insert-menu.scm | 2 +- devel/202_82.md | 59 +++++++++++++++++++++++++++ src/Plugins/Qt/qt_chooser_widget.cpp | 12 ++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 devel/202_82.md diff --git a/TeXmacs/progs/generic/insert-menu.scm b/TeXmacs/progs/generic/insert-menu.scm index 02085af8a..4a0ebf0e7 100644 --- a/TeXmacs/progs/generic/insert-menu.scm +++ b/TeXmacs/progs/generic/insert-menu.scm @@ -29,7 +29,7 @@ --- (when (not (selection-active?)) (if (detailed-menus?) - ("Include" (choose-file make-include "Include file" "")))) + ("Include" (choose-file make-include "Include file" "action_include")))) (when (not (selection-active-non-small?)) ("Link to URL" (make 'slink)) ("Hyperlink" (make 'hlink)) diff --git a/devel/202_82.md b/devel/202_82.md new file mode 100644 index 000000000..ba51735f0 --- /dev/null +++ b/devel/202_82.md @@ -0,0 +1,59 @@ +# 202_82 限制"插入->链接->包含文件"的文件格式 + +## 如何测试 + +1. 点击 `插入 -> 链接 -> 包含文件` +2. 检查文件选择对话框的文件类型过滤器 + - 应显示:STEM files for include (*.tmu *.tm *.ts *.tp) + - 可切换子过滤器:TMU files, TM files, Style files, Template files +3. 准备测试文件:test.tmu, test.tm, test.ts, test.tp, test.txt, test.zip, test.png +4. 确认在默认过滤器下只能看到和选择 tmu、tm、ts、tp 格式的文件 +5. 选择一个 tmu 或 tm 文件,确认成功插入 include 标记 +6. 验证不会因选择大文件或压缩包而卡死(这些文件不应该在过滤器中显示) + +## 2025/12/10 + +### What +1. 添加新的文件类型标识符 `action_include` +2. 在 qt_chooser_widget.cpp 中添加对应的文件过滤器逻辑 +3. 修改 insert-menu.scm 中的类型参数从空字符串改为 "action_include" +4. **关键修复**:在 set_type 函数中添加 `nameFilters.clear()` 清空旧过滤器 + +### Why +防止用户在"包含文件"功能中选择大文件或不支持的格式(如压缩包、图片等),避免界面卡死。 + +### How +参考 action_open 和 action_save_as 的实现模式,添加 action_include 类型处理: + +1. **在 src/Plugins/Qt/qt_chooser_widget.cpp 中**: + - 第 165 行:添加 `nameFilters.clear()` 清空之前累积的过滤器(**关键修复**) + - 在 set_type 函数的第 183-185 行添加 action_include 类型的 mainNameFilter 定义 + - 在第 253-260 行添加文件过滤器设置,支持 *.tmu *.tm *.ts *.tp 格式 + - 提供多个子过滤器选项供用户选择 + +2. **在 TeXmacs/progs/generic/insert-menu.scm 中**: + - 第 32 行:将 choose-file 调用的 type 参数从空字符串 "" 改为 "action_include" + +### 技术细节 + +**支持的文件格式**: +- *.tmu - TeXmacs 主要文档格式 +- *.tm - TeXmacs 传统文档格式 +- *.ts - TeXmacs 样式文件(style packages) +- *.tp - TeXmacs 模板文件 + +**与其他功能的对比**: +- action_open:支持 tmu/tm/ts/tp + 其他代码文件格式 +- action_save_as:支持 tmu(主要)和 tm +- action_include:仅支持 tmu/tm/ts/tp(TeXmacs 相关格式) + +**实现要点**: +- 遵循现有的 action_open 和 action_save_as 命名模式 +- 使用 Qt 文件对话框的原生过滤功能,性能良好 +- 不影响已有文档中的 include 标记 + +**重要 Bug 修复**: +- `nameFilters` 是 qt_chooser_widget_rep 的成员变量,会在多次调用中累积 +- 必须在 set_type 开始时调用 `nameFilters.clear()` 清空旧的过滤器 +- 否则会导致旧的 "All Format(*)" 等过滤器保留在对话框中 +- 这是导致初始实现未生效的根本原因 diff --git a/src/Plugins/Qt/qt_chooser_widget.cpp b/src/Plugins/Qt/qt_chooser_widget.cpp index 436a11bd9..5da26e401 100644 --- a/src/Plugins/Qt/qt_chooser_widget.cpp +++ b/src/Plugins/Qt/qt_chooser_widget.cpp @@ -162,6 +162,7 @@ qt_chooser_widget_rep::plain_window_widget (string s, command q, int b) { bool qt_chooser_widget_rep::set_type (const string& _type) { QString mainNameFilter; + nameFilters.clear (); // Clear previous filters if (_type == "directory") { type= _type; return true; @@ -180,6 +181,9 @@ qt_chooser_widget_rep::set_type (const string& _type) { else if (_type == "action_save_as") { mainNameFilter= to_qstring (translate ("STEM files")); } + else if (_type == "action_include") { + mainNameFilter= to_qstring (translate ("STEM files for include")); + } else if (_type == "text") { mainNameFilter= to_qstring (translate ("Plain text files")); } @@ -247,6 +251,14 @@ qt_chooser_widget_rep::set_type (const string& _type) { nameFilters << mainNameFilter; nameFilters << to_qstring (translate ("TM files") * " (*.tm)"); } + else if (_type == "action_include") { + mainNameFilter+= " (*.tmu *.tm *.ts *.tp)"; + nameFilters << mainNameFilter; + nameFilters << to_qstring (translate ("TMU files") * " (*.tmu)"); + nameFilters << to_qstring (translate ("TM files") * " (*.tm)"); + nameFilters << to_qstring (translate ("Style files") * " (*.ts)"); + nameFilters << to_qstring (translate ("Template files") * " (*.tp)"); + } else { mainNameFilter+= " ("; object ret = call ("format-get-suffixes*", _type); -- Gitee From 9f8c82e9172752bbf3196b14b309444f55065207 Mon Sep 17 00:00:00 2001 From: wang-junbo456 Date: Thu, 11 Dec 2025 12:34:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=8F=92=E5=85=A5->=E9=93=BE=E6=8E=A5->=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E6=96=87=E4=BB=B6=E6=97=B6=E6=98=93=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wang-junbo456 --- devel/202_82.md | 77 ++++++++++++---------------- src/Plugins/Qt/qt_chooser_widget.cpp | 4 +- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/devel/202_82.md b/devel/202_82.md index ba51735f0..526698a83 100644 --- a/devel/202_82.md +++ b/devel/202_82.md @@ -3,57 +3,46 @@ ## 如何测试 1. 点击 `插入 -> 链接 -> 包含文件` -2. 检查文件选择对话框的文件类型过滤器 - - 应显示:STEM files for include (*.tmu *.tm *.ts *.tp) - - 可切换子过滤器:TMU files, TM files, Style files, Template files -3. 准备测试文件:test.tmu, test.tm, test.ts, test.tp, test.txt, test.zip, test.png -4. 确认在默认过滤器下只能看到和选择 tmu、tm、ts、tp 格式的文件 -5. 选择一个 tmu 或 tm 文件,确认成功插入 include 标记 -6. 验证不会因选择大文件或压缩包而卡死(这些文件不应该在过滤器中显示) +2. 确认过滤器显示:*.tmu *.tm +3. 确认只能看到和选择 tmu、tm格式的文件 +4. 选择一个 tmu 或 tm 文件,确认成功插入 include 标记 -## 2025/12/10 +## 2025/12/11 修复了插入->链接->包含文件选择链接文件时易卡死的问题 ### What + +```cc 1. 添加新的文件类型标识符 `action_include` 2. 在 qt_chooser_widget.cpp 中添加对应的文件过滤器逻辑 3. 修改 insert-menu.scm 中的类型参数从空字符串改为 "action_include" -4. **关键修复**:在 set_type 函数中添加 `nameFilters.clear()` 清空旧过滤器 +4. 在 set_type 函数中添加 `nameFilters.clear()` +``` + + ### Why -防止用户在"包含文件"功能中选择大文件或不支持的格式(如压缩包、图片等),避免界面卡死。 +```cc +防止用户选择大文件或不支持格式,避免界面卡死。 +``` + + ### How -参考 action_open 和 action_save_as 的实现模式,添加 action_include 类型处理: - -1. **在 src/Plugins/Qt/qt_chooser_widget.cpp 中**: - - 第 165 行:添加 `nameFilters.clear()` 清空之前累积的过滤器(**关键修复**) - - 在 set_type 函数的第 183-185 行添加 action_include 类型的 mainNameFilter 定义 - - 在第 253-260 行添加文件过滤器设置,支持 *.tmu *.tm *.ts *.tp 格式 - - 提供多个子过滤器选项供用户选择 - -2. **在 TeXmacs/progs/generic/insert-menu.scm 中**: - - 第 32 行:将 choose-file 调用的 type 参数从空字符串 "" 改为 "action_include" - -### 技术细节 - -**支持的文件格式**: -- *.tmu - TeXmacs 主要文档格式 -- *.tm - TeXmacs 传统文档格式 -- *.ts - TeXmacs 样式文件(style packages) -- *.tp - TeXmacs 模板文件 - -**与其他功能的对比**: -- action_open:支持 tmu/tm/ts/tp + 其他代码文件格式 -- action_save_as:支持 tmu(主要)和 tm -- action_include:仅支持 tmu/tm/ts/tp(TeXmacs 相关格式) - -**实现要点**: -- 遵循现有的 action_open 和 action_save_as 命名模式 -- 使用 Qt 文件对话框的原生过滤功能,性能良好 -- 不影响已有文档中的 include 标记 - -**重要 Bug 修复**: -- `nameFilters` 是 qt_chooser_widget_rep 的成员变量,会在多次调用中累积 -- 必须在 set_type 开始时调用 `nameFilters.clear()` 清空旧的过滤器 -- 否则会导致旧的 "All Format(*)" 等过滤器保留在对话框中 -- 这是导致初始实现未生效的根本原因 +1. **qt_chooser_widget.cpp **: + + ```cc + - 第 165 行:添加 `nameFilters.clear()`(清空累积的旧过滤器) + - 第 183 行:添加 `action_include` 的 `mainNameFilter` + - 第 253 行:添加 `*.tmu *.tm `过滤器 + ``` + + + +2. **insert-menu.scm 中**: + + ```cc + - 第 32 行:将 choose-file 调用的 type 参数从空字符串 "" 改为 "action_include" + ``` + + + diff --git a/src/Plugins/Qt/qt_chooser_widget.cpp b/src/Plugins/Qt/qt_chooser_widget.cpp index 5da26e401..847d42499 100644 --- a/src/Plugins/Qt/qt_chooser_widget.cpp +++ b/src/Plugins/Qt/qt_chooser_widget.cpp @@ -252,12 +252,10 @@ qt_chooser_widget_rep::set_type (const string& _type) { nameFilters << to_qstring (translate ("TM files") * " (*.tm)"); } else if (_type == "action_include") { - mainNameFilter+= " (*.tmu *.tm *.ts *.tp)"; + mainNameFilter+= " (*.tmu *.tm)"; nameFilters << mainNameFilter; nameFilters << to_qstring (translate ("TMU files") * " (*.tmu)"); nameFilters << to_qstring (translate ("TM files") * " (*.tm)"); - nameFilters << to_qstring (translate ("Style files") * " (*.ts)"); - nameFilters << to_qstring (translate ("Template files") * " (*.tp)"); } else { mainNameFilter+= " ("; -- Gitee From d0133c86b68163a47b9c87d7230096453f058b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A=E6=B3=A2?= <16476390+wang-junbo456@user.noreply.gitee.com> Date: Thu, 11 Dec 2025 04:45:26 +0000 Subject: [PATCH 3/3] update devel/202_82.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王俊波 <16476390+wang-junbo456@user.noreply.gitee.com> --- devel/202_82.md | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/devel/202_82.md b/devel/202_82.md index 526698a83..e6b1bec25 100644 --- a/devel/202_82.md +++ b/devel/202_82.md @@ -11,38 +11,26 @@ ### What -```cc 1. 添加新的文件类型标识符 `action_include` 2. 在 qt_chooser_widget.cpp 中添加对应的文件过滤器逻辑 3. 修改 insert-menu.scm 中的类型参数从空字符串改为 "action_include" 4. 在 set_type 函数中添加 `nameFilters.clear()` -``` - - ### Why -```cc -防止用户选择大文件或不支持格式,避免界面卡死。 -``` - +防止用户选择大文件或不支持格式,避免界面卡死。 ### How + 1. **qt_chooser_widget.cpp **: - - ```cc + - 第 165 行:添加 `nameFilters.clear()`(清空累积的旧过滤器) - 第 183 行:添加 `action_include` 的 `mainNameFilter` - 第 253 行:添加 `*.tmu *.tm `过滤器 - ``` - - - + 2. **insert-menu.scm 中**: - - ```cc + - 第 32 行:将 choose-file 调用的 type 参数从空字符串 "" 改为 "action_include" - ``` - + -- Gitee