Skip to content

Commit 8192025

Browse files
authored
[0736] ImGui 菜单排除白名单外 interactive 选项 (#3956)
1 parent 876ea3d commit 8192025

7 files changed

Lines changed: 120 additions & 71 deletions

File tree

TeXmacs/progs/kernel/gui/menu-widget.scm

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,15 +579,28 @@
579579
) ;define
580580

581581
(define (make-menu-entry-dots label action)
582+
(if (menu-action-interactive? action) (menu-label-add-dots label) label)
583+
) ;define
584+
585+
(define (menu-action-interactive? action)
582586
(with source
583587
(promise-source action)
584-
(if (and source (pair? source) (property (car source) :interactive))
585-
(menu-label-add-dots label)
586-
label
587-
) ;if
588+
(and source (pair? source) (property (car source) :interactive))
588589
) ;with
589590
) ;define
590591

592+
(define (imgui-supported-action? action)
593+
;; action 是否为「ImGui 后端尚未支持的交互式命令」(点击会弹出 ImGui 未
594+
;; 实现的对话框/新窗口)。判定基准与 make-menu-entry-dots 一致(带
595+
;; :interactive 属性者,即标签会被加省略号 '...' 的菜单项),但排除已用
596+
;; :imgui-supported 显式标记为 ImGui 已实现的命令(如 choose-file → Save as)。
597+
(with source
598+
(promise-source action)
599+
(and source (property (car source) :imgui-supported))
600+
) ;with
601+
) ;define
602+
603+
591604
(define (make-menu-entry-style style action)
592605
(with source
593606
(promise-source action)
@@ -1111,7 +1124,16 @@
11111124
;; (display* "Make items " p ", " style "\n")
11121125
(if (pair? p)
11131126
(cond ((match? p '(input :%1 :string? :%1 :string?)) (list (make-menu-input p style)))
1114-
((translatable? (car p)) (list (make-menu-entry p style bar?)))
1127+
((translatable? (car p))
1128+
;; ImGui 前端不支持交互式命令弹出的对话框/新窗口,跳过这类叶子项
1129+
(if (and (not (qt-gui?))
1130+
(menu-action-interactive? (cAr p))
1131+
(not (imgui-supported-action? (cAr p)))
1132+
) ;and
1133+
(list)
1134+
(list (make-menu-entry p style bar?))
1135+
) ;if
1136+
) ;
11151137
((symbol? (car p))
11161138
(with result
11171139
(ahash-ref make-menu-items-table (car p))
@@ -1121,7 +1143,15 @@
11211143
) ;if
11221144
) ;with
11231145
) ;
1124-
((match? (car p) ':menu-wide-label) (list (make-menu-entry p style bar?)))
1146+
((match? (car p) ':menu-wide-label)
1147+
(if (and (not (qt-gui?))
1148+
(menu-action-interactive? (cAr p))
1149+
(not (imgui-supported-action? (cAr p)))
1150+
) ;and
1151+
(list)
1152+
(list (make-menu-entry p style bar?))
1153+
) ;if
1154+
) ;
11251155
((match? (car p) ':tab-page) (list (make-tab-page p style bar?)))
11261156
(else (make-menu-items-list p style bar?))
11271157
) ;cond

TeXmacs/progs/kernel/texmacs/tm-define.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@
273273
(ahash-set! define-option-table :secure (define-property* :secure))
274274
(ahash-set! define-option-table :check-mark (define-property* :check-mark))
275275
(ahash-set! define-option-table :interactive (define-property* :interactive))
276+
(ahash-set! define-option-table
277+
:imgui-supported
278+
(define-property* :imgui-supported)
279+
) ;ahash-set!
276280
(ahash-set! define-option-table :balloon (define-property* :balloon))
277281

278282
(define-public (procedure-sources about)

TeXmacs/progs/texmacs/menus/edit-menu.scm

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,9 @@
9898
("Other" (interactive clipboard-cut))
9999
) ;->
100100
) ;if
101-
(if (qt-gui?)
102-
;; ImGui 前端精简:移除 Search recent documents / Preferences
103-
---
104-
("Search recent documents" (interactive docgrep-in-recent))
105-
---
106-
(if (use-menus?) (-> "Preferences" (link preferences-menu)))
107-
(if (use-popups?) ("Preferences" (open-preferences)))
108-
) ;if
101+
---
102+
("Search recent documents" (interactive docgrep-in-recent))
103+
---
104+
(if (use-menus?) (-> "Preferences" (link preferences-menu)))
105+
(if (use-popups?) ("Preferences" (open-preferences)))
109106
) ;menu-bind

TeXmacs/progs/texmacs/texmacs/tm-files.scm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@
201201
) ;with
202202
) ;tm-define
203203

204-
(tm-property (choose-file fun text type) (:interactive #t))
204+
(tm-property (choose-file fun text type)
205+
(:interactive #t)
206+
(:imgui-supported #t)
207+
) ;tm-property
205208

206209
(tm-define (open-auxiliary aux body . opt-master)
207210
(let* ((name (aux-name aux))

TeXmacs/progs/text/text-menu.scm

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,65 +28,56 @@
2828
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2929

3030
(menu-bind full-text-format-menu
31-
(if (qt-gui?)
32-
;; ImGui 前端精简:移除 Format 的 Font / Color
33-
(group "Font")
34-
(link text-font-menu)
35-
(if (simple-menus?) (-> "Color" (link color-menu)))
36-
) ;if
31+
(group "Font")
32+
(link text-font-menu)
33+
(if (simple-menus?) (-> "Color" (link color-menu)))
3734
(if (detailed-menus?) --- (group "Text") (link text-properties-menu))
38-
(if (qt-gui?)
39-
;; ImGui 前端精简:移除 Format 的 Paragraph / Page
40-
---
41-
(group "Paragraph")
42-
(link paragraph-menu)
43-
---
44-
(when (in-main-flow?)
45-
(group "Page")
46-
(link page-menu)
47-
) ;when
48-
) ;if
35+
---
36+
(group "Paragraph")
37+
(link paragraph-menu)
38+
---
39+
(when (in-main-flow?)
40+
(group "Page")
41+
(link page-menu)
42+
) ;when
4943
) ;menu-bind
5044

5145
(menu-bind compressed-text-format-menu
52-
(if (qt-gui?)
53-
;; ImGui 前端精简:移除 Format 的 Font / Paragraph / Page / Cell / Table
54-
("Font" (interactive open-font-selector))
55-
("Paragraph" (open-paragraph-format))
56-
(when (in-main-flow?)
57-
("Page" (open-page-format))
58-
) ;when
59-
(when (inside? 'table)
60-
("Cell" (open-cell-properties))
61-
("Table" (open-table-properties))
62-
) ;when
63-
---
64-
) ;if
65-
;; (-> "Whitespace" (link space-menu))
66-
(-> "Indentation" (link indentation-menu))
67-
(-> "Break" (link break-menu))
68-
(when (and (selection-active-small?) (tm-atomic? (selection-tree)))
69-
("Hyphenate as" (interactive hyphenate-selection-as))
70-
) ;when
71-
---
72-
(if (qt-gui?)
73-
;; ImGui 前端精简:移除 Format 的 Color
74-
(-> "Color"
75-
(if (== (get-preference "experimental alpha") "on")
76-
(-> "Opacity" (link opacity-menu))
77-
---
78-
) ;if
79-
(link color-menu)
80-
) ;->
81-
) ;if
82-
(-> "Adjust" (link adjust-menu))
83-
(-> "Transform" (link linear-transform-menu))
84-
(-> "Specific" (link specific-menu))
85-
(-> "Special" (link format-special-menu))
86-
(-> "Font effects" (link text-font-effects-menu))
87-
(assuming (== (get-preference "bitmap effects") "on")
88-
(-> "Graphical effects" (link text-effects-menu))
89-
) ;assuming
46+
("Font" (interactive open-font-selector))
47+
("Paragraph" (open-paragraph-format))
48+
(when (in-main-flow?)
49+
("Page" (open-page-format))
50+
) ;when
51+
(when (inside? 'table)
52+
("Cell" (open-cell-properties))
53+
("Table" (open-table-properties))
54+
) ;when
55+
---
56+
;; (-> "Whitespace" (link space-menu))
57+
(-> "Indentation" (link indentation-menu))
58+
(-> "Break" (link break-menu))
59+
(when (and (selection-active-small?) (tm-atomic? (selection-tree)))
60+
("Hyphenate as" (interactive hyphenate-selection-as))
61+
) ;when
62+
---
63+
(if (qt-gui?)
64+
;; ImGui 前端精简:移除 Format 的 Color
65+
(-> "Color"
66+
(if (== (get-preference "experimental alpha") "on")
67+
(-> "Opacity" (link opacity-menu))
68+
---
69+
) ;if
70+
(link color-menu)
71+
) ;->
72+
) ;if
73+
(-> "Adjust" (link adjust-menu))
74+
(-> "Transform" (link linear-transform-menu))
75+
(-> "Specific" (link specific-menu))
76+
(-> "Special" (link format-special-menu))
77+
(-> "Font effects" (link text-font-effects-menu))
78+
(assuming (== (get-preference "bitmap effects") "on")
79+
(-> "Graphical effects" (link text-effects-menu))
80+
) ;assuming
9081
) ;menu-bind
9182

9283
(menu-bind text-format-menu

devel/0736.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# [0736] ImGui 菜单排除白名单外 interactive 选项
2+
3+
## What
4+
使用 `make-menu-entry-dots` 的代码片段创建了`menu-action-interactive?`。在构建 Scheme 菜单的时候判断是否为 interactive,如果是且非 qt 环境,则不添加此项。
5+
6+
这个过滤拥有白名单机制,目前 “File-Save as” 菜单在白名单中。
7+
8+
同时,去掉了先前的一些条件块,因为现在会在`make-menu-items`中处理。
9+
10+
## Why?
11+
ImGui 现在没有支持 interactive 菜单的弹窗、tool widget 等功能。

src/Plugins/ImGui/im_menu.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,21 @@ render_node (widget w) {
6767
case im_menu_rep::k_container: {
6868
// horizontal_menu / vertical_menu / …:逐项渲染子节点
6969
array<widget>& kids= m->menu_children ();
70-
for (int i= 0; i < N (kids); ++i)
70+
// 规整分隔符:去除首/末/连续的孤立分隔符。interactive 菜单项在
71+
// scheme 层(menu-widget.scm)被过滤后会残留孤立 '---',此处统一清理。
72+
int last= -1;
73+
for (int i= 0; i < N (kids); ++i) {
74+
im_menu_rep* km= dynamic_cast<im_menu_rep*> (kids[i].rep);
75+
if (km == nullptr || km->kind != im_menu_rep::k_separator) last= i;
76+
}
77+
bool prev_sep= true; // 跳过开头的分隔符
78+
for (int i= 0; i <= last; ++i) {
79+
im_menu_rep* km= dynamic_cast<im_menu_rep*> (kids[i].rep);
80+
bool is_sep = (km != nullptr && km->kind == im_menu_rep::k_separator);
81+
if (is_sep && prev_sep) continue; // 连续或首分隔符:跳过
7182
render_node (kids[i]);
83+
prev_sep= is_sep;
84+
}
7285
} break;
7386
case im_menu_rep::k_submenu: {
7487
// pulldown / pullright:BeginMenu 展开惰性 promise 子菜单。

0 commit comments

Comments
 (0)