|
17 | 17 | from utils.displayString import DisplayStringIntEnum |
18 | 18 |
|
19 | 19 |
|
| 20 | +# From WdOutlineLevel enumeration |
| 21 | +# See https://learn.microsoft.com/fr-fr/office/vba/api/word.wdoutlinelevel |
| 22 | +wdOutlineLevelBodyText = 10 |
| 23 | + |
| 24 | + |
20 | 25 | class ViewType(DisplayStringIntEnum): |
21 | 26 | """Enumeration containing the possible view types in Word documents:. |
22 | 27 | https://learn.microsoft.com/en-us/office/vba/api/word.wdviewtype |
@@ -79,6 +84,39 @@ def script_toggleChangeTracking(self, gesture): |
79 | 84 | # Translators: a message when toggling change tracking in Microsoft word |
80 | 85 | ui.message(_("Change tracking off")) |
81 | 86 |
|
| 87 | + @script(gestures=["kb:alt+shift+-", "kb:alt+shift+="]) |
| 88 | + def script_collapseOrExpandHeading(self, gesture: "inputCore.InputGesture"): |
| 89 | + if not self.WinwordSelectionObject: |
| 90 | + # We cannot fetch the Word object model, so we therefore cannot report the format change. |
| 91 | + # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail, |
| 92 | + # or it's within Windows Defender Application Guard. |
| 93 | + # In this case, just let the gesture through and don't report anything. |
| 94 | + return gesture.send() |
| 95 | + maxParagraphs = 50 |
| 96 | + for nParagraph, paragraph in enumerate(self.WinwordSelectionObject.paragraphs): |
| 97 | + if paragraph.outlineLevel != wdOutlineLevelBodyText: |
| 98 | + break |
| 99 | + if nParagraph >= maxParagraphs: |
| 100 | + log.debugWarning("Too many paragraphs selected") |
| 101 | + gesture.send() |
| 102 | + return |
| 103 | + else: |
| 104 | + gesture.send() |
| 105 | + # Translators: a message when collapsing or expanding headings in MS Word |
| 106 | + ui.message(_("No heading selected")) |
| 107 | + return |
| 108 | + val = self._WaitForValueChangeForAction( |
| 109 | + lambda: gesture.send(), |
| 110 | + lambda: paragraph.CollapsedState, |
| 111 | + ) |
| 112 | + if val: |
| 113 | + # Translators: a message when collapsing a heading in MS Word |
| 114 | + msg = _("Collapsed") |
| 115 | + else: |
| 116 | + # Translators: a message when expanding a heading in MS Word |
| 117 | + msg = _("Expanded") |
| 118 | + ui.message(msg) |
| 119 | + |
82 | 120 | __gestures = { |
83 | 121 | "kb:control+shift+b": "toggleBold", |
84 | 122 | "kb:control+shift+w": "toggleUnderline", |
|
0 commit comments