|
1 | 1 | # -*- coding: UTF-8 -*- |
2 | | -#globalCommands.py |
3 | | -#A part of NonVisual Desktop Access (NVDA) |
4 | | -#This file is covered by the GNU General Public License. |
5 | | -#See the file COPYING for more details. |
6 | | -#Copyright (C) 2006-2018 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Rui Batista, Joseph Lee, Leonard de Ruijter, Derek Riemer, Babbage B.V., Davy Kager, Ethan Holliger, Łukasz Golonka |
| 2 | +# A part of NonVisual Desktop Access (NVDA) |
| 3 | +# This file is covered by the GNU General Public License. |
| 4 | +# See the file COPYING for more details. |
| 5 | +# Copyright (C) 2006-2020 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Rui Batista, Joseph Lee, |
| 6 | +# Leonard de Ruijter, Derek Riemer, Babbage B.V., Davy Kager, Ethan Holliger, Łukasz Golonka |
7 | 7 |
|
8 | 8 | import time |
9 | 9 | import itertools |
@@ -1391,6 +1391,8 @@ def script_sayAll(self,gesture): |
1391 | 1391 | def _reportFormattingHelper(self, info, browseable=False): |
1392 | 1392 | # Report all formatting-related changes regardless of user settings |
1393 | 1393 | # when explicitly requested. |
| 1394 | + if info is None: |
| 1395 | + return |
1394 | 1396 | # These are the options we want reported when reporting formatting manually. |
1395 | 1397 | # for full list of options that may be reported see the "documentFormatting" section of L{config.configSpec} |
1396 | 1398 | reportFormattingOptions = ( |
@@ -1463,16 +1465,87 @@ def _reportFormattingHelper(self, info, browseable=False): |
1463 | 1465 | _("Formatting") |
1464 | 1466 | ) |
1465 | 1467 |
|
1466 | | - def script_reportFormatting(self,gesture): |
1467 | | - info=api.getReviewPosition() |
1468 | | - repeats=scriptHandler.getLastScriptRepeatCount() |
1469 | | - if repeats==0: |
1470 | | - self._reportFormattingHelper(info,False) |
1471 | | - elif repeats==1: |
1472 | | - self._reportFormattingHelper(info,True) |
1473 | | - # Translators: Input help mode message for report formatting command. |
1474 | | - script_reportFormatting.__doc__ = _("Reports formatting info for the current review cursor position within a document. If pressed twice, presents the information in browse mode") |
1475 | | - script_reportFormatting.category=SCRCAT_TEXTREVIEW |
| 1468 | + def _getTIAtCaret(self): |
| 1469 | + # Returns text info at the caret position if there is a caret in the current control, None othervise. |
| 1470 | + # Note that if there is no caret this fact is announced in speech and braille. |
| 1471 | + obj = api.getFocusObject() |
| 1472 | + treeInterceptor = obj.treeInterceptor |
| 1473 | + if( |
| 1474 | + isinstance(treeInterceptor, treeInterceptorHandler.DocumentTreeInterceptor) |
| 1475 | + and not treeInterceptor.passThrough |
| 1476 | + ): |
| 1477 | + obj = treeInterceptor |
| 1478 | + try: |
| 1479 | + info = obj.makeTextInfo(textInfos.POSITION_CARET) |
| 1480 | + return info |
| 1481 | + except (NotImplementedError, RuntimeError): |
| 1482 | + # Translators: Reported when there is no caret. |
| 1483 | + ui.message(_("No caret")) |
| 1484 | + return |
| 1485 | + |
| 1486 | + @script( |
| 1487 | + # Translators: Input help mode message for report formatting command. |
| 1488 | + description=_("Reports formatting info for the current review cursor position."), |
| 1489 | + category=SCRCAT_TEXTREVIEW, |
| 1490 | + ) |
| 1491 | + def script_reportFormattingAtReview(self, gesture): |
| 1492 | + self._reportFormattingHelper(api.getReviewPosition(), False) |
| 1493 | + |
| 1494 | + @script( |
| 1495 | + # Translators: Input help mode message for show formatting at review cursor command. |
| 1496 | + description=_("Presents, in browse mode, formatting info for the current review cursor position."), |
| 1497 | + category=SCRCAT_TEXTREVIEW, |
| 1498 | + ) |
| 1499 | + def script_showFormattingAtReview(self, gesture): |
| 1500 | + self._reportFormattingHelper(api.getReviewPosition(), True) |
| 1501 | + |
| 1502 | + @script( |
| 1503 | + description=_( |
| 1504 | + # Translators: Input help mode message for report formatting command. |
| 1505 | + "Reports formatting info for the current review cursor position." |
| 1506 | +" If pressed twice, presents the information in browse mode" |
| 1507 | + ), |
| 1508 | + category=SCRCAT_TEXTREVIEW, |
| 1509 | + gesture="kb:NVDA+shift+f", |
| 1510 | + ) |
| 1511 | + def script_reportFormatting(self, gesture): |
| 1512 | + repeats = scriptHandler.getLastScriptRepeatCount() |
| 1513 | + if repeats == 0: |
| 1514 | + self.script_reportFormattingAtReview(gesture) |
| 1515 | + elif repeats == 1: |
| 1516 | + self.script_showFormattingAtReview(gesture) |
| 1517 | + |
| 1518 | + @script( |
| 1519 | + # Translators: Input help mode message for report formatting at caret command. |
| 1520 | + description=_("Reports formatting info for the text under the caret."), |
| 1521 | + category=SCRCAT_SYSTEMCARET, |
| 1522 | + ) |
| 1523 | + def script_reportFormattingAtCaret(self, gesture): |
| 1524 | + self._reportFormattingHelper(self._getTIAtCaret(), False) |
| 1525 | + |
| 1526 | + @script( |
| 1527 | + # Translators: Input help mode message for show formatting at caret position command. |
| 1528 | + description=_("Presents, in browse mode, formatting info for the text under the caret."), |
| 1529 | + category=SCRCAT_SYSTEMCARET, |
| 1530 | + ) |
| 1531 | + def script_showFormattingAtCaret(self, gesture): |
| 1532 | + self._reportFormattingHelper(self._getTIAtCaret(), True) |
| 1533 | + |
| 1534 | + @script( |
| 1535 | + description=_( |
| 1536 | + # Translators: Input help mode message for report formatting at caret command. |
| 1537 | + "Reports formatting info for the thext under the caret." |
| 1538 | + " If pressed twice, presents the information in browse mode" |
| 1539 | + ), |
| 1540 | + category=SCRCAT_SYSTEMCARET, |
| 1541 | + gesture="kb:NVDA+f", |
| 1542 | + ) |
| 1543 | + def script_reportOrShowFormattingAtCaret(self, gesture): |
| 1544 | + repeats = scriptHandler.getLastScriptRepeatCount() |
| 1545 | + if repeats == 0: |
| 1546 | + self.script_reportFormattingAtCaret(gesture) |
| 1547 | + elif repeats == 1: |
| 1548 | + self.script_showFormattingAtCaret(gesture) |
1476 | 1549 |
|
1477 | 1550 | def script_reportCurrentFocus(self,gesture): |
1478 | 1551 | focusObject=api.getFocusObject() |
@@ -2625,8 +2698,6 @@ def _enableScreenCurtain(doEnable: bool = True): |
2625 | 2698 | "kb(laptop):NVDA+l": "reportCurrentLine", |
2626 | 2699 | "kb(desktop):NVDA+shift+upArrow": "reportCurrentSelection", |
2627 | 2700 | "kb(laptop):NVDA+shift+s": "reportCurrentSelection", |
2628 | | - "kb:NVDA+f": "reportFormatting", |
2629 | | - |
2630 | 2701 | # Object navigation |
2631 | 2702 | "kb:NVDA+numpad5": "navigatorObject_current", |
2632 | 2703 | "kb(laptop):NVDA+shift+o": "navigatorObject_current", |
|
0 commit comments