Skip to content

Commit e7fe3ec

Browse files
author
JackChen
committed
text-toolbar-chapter-icons支持显示选中态
1 parent 9073f88 commit e7fe3ec

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

TeXmacs/progs/generic/text-toolbar.scm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
(dynamic (focus-variant-menu t))))))
150150

151151
;; 提取当前选区对应的章节层级节点。
152-
(tm-define (chatper-selection-tree . opt-t)
152+
(tm-define (chapter-selection-tree . opt-t)
153153
(with l '(chapter section subsection subsubsection)
154154
(if (nnull? opt-t)
155155
(and (tree-in? (car opt-t) (numbered-unnumbered-append l))
@@ -166,11 +166,11 @@
166166

167167
;; 返回当前章节节点可切换的结构变体列表。
168168
(tm-define (focus-variants-of t)
169-
(:require (chatper-selection-tree t))
170-
(chatper-selection-tree t))
169+
(:require (chapter-selection-tree t))
170+
(chapter-selection-tree t))
171171

172-
(menu-bind text-toolbar-chatper-icons
173-
(with t (chatper-selection-tree)
172+
(menu-bind text-toolbar-chapter-icons
173+
(with t (chapter-selection-tree)
174174
(when (and t (numbered-context? t))
175175
((check (balloon (icon "tm_numbered.xpm") "Numbered") "v"
176176
(numbered-numbered? t))
@@ -222,8 +222,8 @@
222222
(not (not (semantic-block-selection-tree))))
223223

224224
;; 判断当前选区是否处于章节标题上下文中。
225-
(tm-define (chatper-selection-context? t)
226-
(not (not (chatper-selection-tree))))
225+
(tm-define (chapter-selection-context? t)
226+
(not (not (chapter-selection-tree))))
227227

228228
;; 合并两个模式列表,并去掉重复项。
229229
(define (mode-list-union l1 l2)
@@ -304,7 +304,7 @@
304304
((table-of-contents-selection-context? t) #f)
305305
((image-selection-context? t) #f)
306306
((table-selection-context? t) 'table)
307-
((chatper-selection-context? t) 'chatper)
307+
((chapter-selection-context? t) 'chapter)
308308
((semantic-block-selection-context? t) 'semantic)
309309
((math-selection-context? t) 'math)
310310
((text-selection-context? t) 'text)
@@ -315,8 +315,8 @@
315315
(cond
316316
((== context 'table)
317317
(link text-toolbar-table-icons))
318-
((== context 'chatper)
319-
(link text-toolbar-chatper-icons))
318+
((== context 'chapter)
319+
(link text-toolbar-chapter-icons))
320320
((== context 'semantic)
321321
(link text-toolbar-semantic-icons))
322322
((== context 'text)

devel/201_63.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
- ✅ 纯文本选区(`text`,且不包含图片)
2121
- ✅ 纯数学选区(`math`
2222
- ✅ 表格或单元格相关选区(`table`
23-
- ✅ 章节标题相关选区(`chatper`
23+
- ✅ 章节标题相关选区(`chapter`
2424
- ✅ 语义块相关选区,如 theorem / proposition(`semantic`
2525

2626
**建议按 `TeXmacs/tests/tmu/201_63.tmu` 分区手动验证**
2727
- `toc`:选中目录内任意内容,或直接选中整个目录,不应该显示文本悬浮框
2828
- `math`:选中公式,应该显示数学工具栏
2929
- `text`:选中文字,应该显示文本工具栏
3030
- `table`:选中表格/单元格,应该显示表格工具栏
31-
- `chatper`:选中章节标题,应该显示章节工具栏
31+
- `chapter`:选中章节标题,应该显示章节工具栏
3232
- `semantic`:选中 theorem / proposition 等,应该显示语义工具栏
3333

3434
**不会显示的情况**(满足任一):

src/Plugins/Qt/QTMTextPopup.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@
3636
#include <algorithm>
3737
#include <cmath>
3838

39+
namespace {
40+
void
41+
prepareTextPopupButton (QToolButton* button, QAction* action) {
42+
if (button == nullptr || action == nullptr) return;
43+
44+
// Match focus-toolbar semantics: a check-backed toolbar action is rendered
45+
// selected whenever TeXmacs marks it as checkable.
46+
action->setChecked (action->isCheckable ());
47+
48+
button->setObjectName ("base_popup_button");
49+
button->setAutoRaise (true);
50+
button->setDefaultAction (action);
51+
button->setPopupMode (QToolButton::InstantPopup);
52+
#if defined(Q_OS_MAC)
53+
button->setProperty ("platform", "mac");
54+
#endif
55+
if (tm_style_sheet == "") button->setStyle (qtmstyle ());
56+
button->setCheckable (action->isCheckable ());
57+
button->setChecked (action->isChecked ());
58+
button->update ();
59+
}
60+
} // namespace
61+
3962
// 悬浮工具栏创建函数
4063
QTMTextPopup::QTMTextPopup (QWidget* parent, qt_simple_widget_rep* owner)
4164
: QTMBasePopup (parent, owner) {
@@ -98,11 +121,7 @@ QTMTextPopup::rebuildButtonsFromScheme () {
98121
}
99122

100123
QToolButton* button= new QToolButton (this);
101-
button->setObjectName ("base_popup_button");
102-
button->setAutoRaise (true);
103-
button->setDefaultAction (action);
104-
button->setPopupMode (QToolButton::InstantPopup);
105-
if (tm_style_sheet == "") button->setStyle (qtmstyle ());
124+
prepareTextPopupButton (button, action);
106125
layout->addWidget (button);
107126
}
108127
}
@@ -198,9 +217,7 @@ QTMTextPopup::updateButtonsFromScheme () {
198217
if (stale_action) button->removeAction (stale_action);
199218
}
200219
button->setMenu (nullptr);
201-
button->setDefaultAction (action);
202-
button->setPopupMode (QToolButton::InstantPopup);
203-
if (tm_style_sheet == "") button->setStyle (qtmstyle ());
220+
prepareTextPopupButton (button, action);
204221
}
205222
cached_width = width ();
206223
cached_height= height ();
@@ -236,11 +253,7 @@ QTMTextPopup::updateButtonsFromScheme () {
236253
}
237254

238255
QToolButton* button= new QToolButton (this);
239-
button->setObjectName ("base_popup_button");
240-
button->setAutoRaise (true);
241-
button->setDefaultAction (action);
242-
button->setPopupMode (QToolButton::InstantPopup);
243-
if (tm_style_sheet == "") button->setStyle (qtmstyle ());
256+
prepareTextPopupButton (button, action);
244257
if (old_icon_size.isValid ()) button->setIconSize (old_icon_size);
245258
if (old_button_size.isValid ()) button->setFixedSize (old_button_size);
246259
layout->addWidget (button);

0 commit comments

Comments
 (0)