Skip to content

Commit e606be5

Browse files
authored
[0734] 实现 ImGui (WASM) 菜单栏 (#3948)
1 parent 463af7d commit e606be5

19 files changed

Lines changed: 1316 additions & 206 deletions

TeXmacs/progs/generic/document-menu.scm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,11 @@
11941194
---
11951195
(dynamic (focus-document-menu t))
11961196
(dynamic (focus-document-extra-menu t))
1197-
---
1198-
("Help" (focus-help))
1197+
(if (qt-gui?)
1198+
;; ImGui 前端精简:移除 Focus 菜单末尾的 Help
1199+
---
1200+
("Help" (focus-help))
1201+
) ;if
11991202
) ;tm-menu
12001203

12011204
(tm-menu (focus-document-extra-icons t))

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@
9898
("Other" (interactive clipboard-cut))
9999
) ;->
100100
) ;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)))
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
106109
) ;menu-bind

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

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -388,52 +388,57 @@
388388
(menu-bind file-menu
389389
("New" (new-document))
390390
("Load" (open-document))
391-
("Revert" (revert-buffer))
392-
(-> "Recent"
393-
(link recent-file-menu)
394-
(if (nnull? (recent-file-list 1)) ---)
395-
(when (nnull? (recent-file-list 1))
396-
("Clear menu" (forget-interactive "recent-buffer"))
397-
) ;when
398-
) ;->
399-
---
391+
(if (qt-gui?)
392+
;; ImGui 前端精简:仅保留 New / Load / Save,以下 Revert/Recent 等仅在 Qt 显示
393+
("Revert" (revert-buffer))
394+
(-> "Recent"
395+
(link recent-file-menu)
396+
(if (nnull? (recent-file-list 1)) ---)
397+
(when (nnull? (recent-file-list 1))
398+
("Clear menu" (forget-interactive "recent-buffer"))
399+
) ;when
400+
) ;->
401+
---
402+
) ;if
400403
("Save" (save-buffer))
401404
("Save as" (choose-file save-buffer-as "Save TeXmacs file" "action_save_as"))
402-
---
403-
(link print-menu)
404-
---
405-
(-> "Import"
406-
(link import-import-menu)
405+
(if (qt-gui?)
407406
---
408-
("Pdf with embedded document"
409-
(choose-file wrapped-import-pdf-embeded-with-tmu "Import pdf file" "tmu.pdf")
410-
) ;
411-
) ;->
412-
(-> "Export"
413-
(link export-export-menu)
407+
(link print-menu)
414408
---
415-
(when (defined? 'texmacs->latex-document)
416-
("LaTeX" (choose-file export-latex-file "Save LaTeX file" "latex"))
417-
) ;when
418-
("TM document" (choose-file save-buffer-as "Save TeXmacs file" "texmacs"))
419-
("Pdf" (choose-file wrapped-print-to-file "Save pdf file" "pdf"))
420-
("Pdf with embedded document"
421-
(choose-file wrapped-print-to-pdf-embeded-with-tmu
422-
"Save tmu.pdf file"
423-
"tmu.pdf"
424-
) ;choose-file
425-
) ;
426-
("Postscript"
427-
(choose-file wrapped-print-to-file "Save postscript file" "postscript")
428-
) ;
429-
(when (selection-active-any?)
430-
(=> "Export selection as image" (link export-as-image-menu))
431-
) ;when
432-
) ;->
433-
---
434-
(if (window-per-buffer?) ("Close window" (close-document)))
435-
(if (not (window-per-buffer?)) ("Close document" (close-document)))
436-
("Close TeXmacs" (safely-quit-TeXmacs))
409+
(-> "Import"
410+
(link import-import-menu)
411+
---
412+
("Pdf with embedded document"
413+
(choose-file wrapped-import-pdf-embeded-with-tmu "Import pdf file" "tmu.pdf")
414+
) ;
415+
) ;->
416+
(-> "Export"
417+
(link export-export-menu)
418+
---
419+
(when (defined? 'texmacs->latex-document)
420+
("LaTeX" (choose-file export-latex-file "Save LaTeX file" "latex"))
421+
) ;when
422+
("TM document" (choose-file save-buffer-as "Save TeXmacs file" "texmacs"))
423+
("Pdf" (choose-file wrapped-print-to-file "Save pdf file" "pdf"))
424+
("Pdf with embedded document"
425+
(choose-file wrapped-print-to-pdf-embeded-with-tmu
426+
"Save tmu.pdf file"
427+
"tmu.pdf"
428+
) ;choose-file
429+
) ;
430+
("Postscript"
431+
(choose-file wrapped-print-to-file "Save postscript file" "postscript")
432+
) ;
433+
(when (selection-active-any?)
434+
(=> "Export selection as image" (link export-as-image-menu))
435+
) ;when
436+
) ;->
437+
---
438+
(if (window-per-buffer?) ("Close window" (close-document)))
439+
(if (not (window-per-buffer?)) ("Close document" (close-document)))
440+
("Close TeXmacs" (safely-quit-TeXmacs))
441+
) ;if
437442
) ;menu-bind
438443

439444
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868
(if (project-attached?) (=> "Project" (link project-menu)))
6969
(if (with-versioning-tool?) (=> "Version" (link version-menu)))
7070
(=> "View::menu" (link view-menu))
71-
(=> "Go" (link go-menu))
72-
(if (detailed-menus?) (=> "Tools" (link tools-menu)))
71+
(if (qt-gui?) (=> "Go" (link go-menu)))
72+
(if (qt-gui?) (if (detailed-menus?) (=> "Tools" (link tools-menu))))
7373
(if (with-database-tool?) (=> "Data" (link db-menu)))
7474
(if (with-debugging-tool?) (=> "Debug" (link debug-menu)))
7575
(if (with-developer-tool?) (=> "Developer" (link developer-menu)))
7676
(if (nnull? (test-menu)) (=> "Test" (link test-menu)))
77-
(=> "Help" (link help-menu))
77+
(if (qt-gui?) (=> "Help" (link help-menu)))
7878
) ;menu-bind
7979

8080
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@
121121
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122122

123123
(menu-bind view-menu
124-
(if (not (window-per-buffer?))
125-
("New window" (new-document*))
126-
("Open in new window" (open-document*))
127-
;; ("Clone window" (clone-window))
128-
("Close window" (close-document*))
129-
---
124+
(if (qt-gui?)
125+
;; ImGui 前端精简:移除 New window / Open in new window / Close window
126+
(if (not (window-per-buffer?))
127+
("New window" (new-document*))
128+
("Open in new window" (open-document*))
129+
;; ("Clone window" (clone-window))
130+
("Close window" (close-document*))
131+
---
132+
) ;if
130133
) ;if
131134
("Full screen mode" (toggle-full-screen-edit-mode))
132135
("Focus mode" (toggle-focus-mode))
@@ -155,11 +158,14 @@
155158

156159
("Snap to pages" (toggle-snap-to-pages))
157160
---
158-
(when (visible-header?)
159-
("Main icon bar" (toggle-visible-icon-bar 0))
160-
("Mode dependent icons" (toggle-visible-icon-bar 1))
161-
("Focus dependent icons" (toggle-visible-icon-bar 2))
162-
) ;when
161+
(if (qt-gui?)
162+
;; ImGui 前端精简:移除 Main/Mode/Focus 图标栏开关(ImGui 暂未实现这些栏的开关)
163+
(when (visible-header?)
164+
("Main icon bar" (toggle-visible-icon-bar 0))
165+
("Mode dependent icons" (toggle-visible-icon-bar 1))
166+
("Focus dependent icons" (toggle-visible-icon-bar 2))
167+
) ;when
168+
) ;if
163169
;; ("User provided icons" (toggle-visible-icon-bar 3))
164170
("Status bar" (toggle-visible-footer))
165171
(if (with-developer-tool?)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,16 @@
612612
) ;with-default-view
613613
) ;tm-define
614614

615+
(tm-define (wasm-save-for-download)
616+
(:synopsis "WASM: 把当前 buffer 保存到它自己的文件并返回该文件路径,供浏览器下载"
617+
) ;:synopsis
618+
;; WASM 的"另存为" = 保存 buffer 到当前文件(普通 Save,不重命名)+ 下载该文件。
619+
;; 不弹文件名对话框、不改 buffer 名。save-buffer-save 同步执行(无
620+
;; with-default-view 的 exec-delayed),把 buffer 内容写入它自己的路径。
621+
(save-buffer-save (current-buffer) '() "save")
622+
(url->system (current-buffer))
623+
) ;tm-define
624+
615625
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616626
;; Exporting buffers
617627
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TeXmacs/progs/text/text-menu.scm

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

3030
(menu-bind full-text-format-menu
31-
(group "Font")
32-
(link text-font-menu)
33-
(if (simple-menus?) (-> "Color" (link color-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
3437
(if (detailed-menus?) --- (group "Text") (link text-properties-menu))
35-
---
36-
(group "Paragraph")
37-
(link paragraph-menu)
38-
---
39-
(when (in-main-flow?)
40-
(group "Page")
41-
(link page-menu)
42-
) ;when
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
4349
) ;menu-bind
4450

4551
(menu-bind compressed-text-format-menu
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-
(-> "Color"
64-
(if (== (get-preference "experimental alpha") "on")
65-
(-> "Opacity" (link opacity-menu))
66-
---
67-
) ;if
68-
(link color-menu)
69-
) ;->
70-
(-> "Adjust" (link adjust-menu))
71-
(-> "Transform" (link linear-transform-menu))
72-
(-> "Specific" (link specific-menu))
73-
(-> "Special" (link format-special-menu))
74-
(-> "Font effects" (link text-font-effects-menu))
75-
(assuming (== (get-preference "bitmap effects") "on")
76-
(-> "Graphical effects" (link text-effects-menu))
77-
) ;assuming
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
7890
) ;menu-bind
7991

8092
(menu-bind text-format-menu

0 commit comments

Comments
 (0)