Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give ui.browseableMessage the ability to show copy and close buttons after the message, and add buttons to some instances #16369

Merged
merged 45 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e06d613
Basic code in browseableMessage
Mar 28, 2024
2dcd7f8
Message.html changes to support optional close and copy buttons.
Mar 28, 2024
d36f480
Report link destination & character formatting browseableMessages giv…
Apr 6, 2024
2d3d656
Changes
Jun 19, 2024
5bce427
Removed customizable text for close button feature.
Jun 22, 2024
2187b9e
Added copy and close buttons to the Speak selection command browseabl…
Jun 22, 2024
5c640e2
Added a close button to the Review current symbol command browseableM…
Jun 22, 2024
1cb3e84
Added alt+c keypress for the copy button.
Jun 22, 2024
a49e516
Revised changes.
Jun 22, 2024
934fab3
Fix indent error
Jun 22, 2024
c749936
User alerts for copying (unlocalized).
Jun 22, 2024
e48229a
Add user alerts about completion, reorganize message.html code a bit.
Jun 23, 2024
56a16be
Apply suggestions from code review
XLTechie Jun 26, 2024
80d4357
Adding missing translatable strings for copy operation alerts.
XLTechie Jun 26, 2024
ef23a09
Merge tag 'prenormal' into fix14641
Jun 28, 2024
8b03cd2
Merge tag 'normalize' into fix14641
Jun 28, 2024
eed604f
renormalize files
Jun 28, 2024
2253a8a
Merge branch 'master' into fix14641
Jun 28, 2024
b6227e9
Merge branch 'master' into fix14641
Jul 6, 2024
0ebe496
Merge branch 'master' into fix14641
Aug 3, 2024
fb880f5
Pre-commit auto-fix
pre-commit-ci[bot] Aug 3, 2024
6ee880c
New alert code, using a live region.
Aug 3, 2024
9926347
Remove failed attempt at Alt+C for Copy button press.
Aug 3, 2024
a6b8d78
Move changes to correct version.
Aug 3, 2024
f50d397
Added a new browsable message component failure messenging function.
Aug 3, 2024
14ea6de
f
Aug 3, 2024
cd71aaa
Used AI's proposed error handling in ui.py, with generic error messag…
Aug 3, 2024
43713e8
Pre-commit auto-fix
pre-commit-ci[bot] Aug 3, 2024
cac67d7
Change onkeypress to onkeydown, in order to pick up Alt+C for copy.
Aug 3, 2024
455769b
Implement a translatable accessibility label for the copy accelerator…
Aug 5, 2024
7f72d91
Merge branch 'master' into fix14641
Aug 5, 2024
196e409
Solve for MSHTML bug in the use of aria-labelledby.
Aug 5, 2024
f8e3d86
Removed unnecessary comment
Aug 5, 2024
3eb6ce3
Merge branch 'master' into fix14641
Aug 7, 2024
6aa5de0
Update source/message.html to remove invalid language attribute
XLTechie Aug 8, 2024
82f1bb2
Merge branch 'master' into fix14641
Aug 8, 2024
bca9eeb
Add further explanation to the translation comment for the Alt+C copy…
Aug 8, 2024
b1e220b
Guard against code injection in copy status translations.
Aug 8, 2024
5d10774
Switch to innerText from innerHTML where possible.
Aug 8, 2024
a133639
Slightly safer handling of messages.
Aug 8, 2024
268cc5f
Close the Window if args wasn't provided.
Aug 8, 2024
3337887
ID fix.
Aug 8, 2024
cdbcdeb
Merge branch 'master' into fix14641
Aug 8, 2024
465f852
Merge branch 'master' into fix14641
Aug 8, 2024
2776962
Update source/message.html
seanbudd Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,10 @@ def _reportFormattingHelper(self, info, browseable=False):
ui.browseableMessage(
message,
# Translators: title for formatting information dialog.
_("Formatting")
_("Formatting"),
copyButton=True,
# Translators: Close button label
closeButtonText=_("Close")
)

@staticmethod
Expand Down Expand Up @@ -4052,7 +4055,7 @@ def script_reportLinkDestination(
) -> None:
"""Generates a ui.message or ui.browseableMessage of a link's destination, if focus or caret is
positioned on a link, or an element with an included link such as a graphic.
@param forceBrowseable: skips the press once check, and displays the browseableMessage version.
:param forceBrowseable: skips the press once check, and displays the browseableMessage version.
"""
try:
ti: textInfos.TextInfo = api.getCaretPosition()
Expand Down Expand Up @@ -4089,7 +4092,10 @@ def script_reportLinkDestination(
linkDestination,
# Translators: Informs the user that the window contains the destination of the
# link with given title
title=_("Destination of: {name}").format(name=obj.name)
title=_("Destination of: {name}").format(name=obj.name),
# Translators: Close button label, recommending to press escape to close the message.
closeButtonText=_("Press escape to close"),
copyButton=True
)
elif presses == 0: # One press
ui.message(linkDestination) # Speak the link
Expand Down
34 changes: 33 additions & 1 deletion source/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,51 @@
if(e.keyCode == 27){ // code for escape
XLTechie marked this conversation as resolved.
Show resolved Hide resolved
window.close();
}
};
}

function onCopyButtonPress() {
// Copy code came from http://www.codestore.net/store.nsf/unid/DOMM-4QHQE8/
var rng = document.body.createTextRange();
XLTechie marked this conversation as resolved.
Show resolved Hide resolved
rng.moveToElementText(messageID);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
rng.select();
}
XLTechie marked this conversation as resolved.
Show resolved Hide resolved

function onCloseButtonPress() {
//window.open('', '_self', ''); // Only enable if window.close() stops working in a future version, may fix.
XLTechie marked this conversation as resolved.
Show resolved Hide resolved
window.close();
}
XLTechie marked this conversation as resolved.
Show resolved Hide resolved

function windowOnLoad() {
var args = window.dialogArguments;
if (args) {
document.title = args.item('title');
messageID.innerHTML = args.item('message');
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
// If caller wants a close button
if (args.item('closeButtonText') != null) {
closeButton.innerHTML = args.item('closeButtonText'); // Assign the (translated) label
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
closeButton.style.display = 'inline'; // Display the button
buttonDiv.style.display = 'block'; // Display the div
}
// If caller wants a copy to clip button
if (args.item('copyButtonText') != null) {
copyButton.innerHTML = args.item('copyButtonText'); // Assign the (translated) label
copyButtonSpan.style.display = 'inline'; // Display the button
buttonDiv.style.display = 'block'; // Display the div
}
}
}
//-->
</SCRIPT>
</HEAD>
<BODY tabindex='0' id='main_body' style="margin:1em" LANGUAGE=javascript onload="return windowOnLoad()" onkeypress="return escapeKeyPress()" >
<div id=messageID></div>
<div id="buttonDiv" style="display: none;"><hr>
<span id="copyButtonSpan" style="display: none;"><button id="copyButton" onclick="onCopyButtonPress();"></button>&nbsp;</span>
<span><button id="closeButton" style="display: none;" onclick="onCloseButtonPress();"></button></span>
</div>
</body>
</html>
23 changes: 18 additions & 5 deletions source/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,20 @@ def _warnBrowsableMessageNotAvailableOnSecureScreens(title: Optional[str]) -> No
)


def browseableMessage(message: str, title: Optional[str] = None, isHtml: bool = False) -> None:
def browseableMessage(
message: str,
title: Optional[str] = None,
XLTechie marked this conversation as resolved.
Show resolved Hide resolved
isHtml: bool = False,
closeButtonText: Optional[str] = None,
copyButton: bool = False
) -> None:
"""Present a message to the user that can be read in browse mode.
The message will be presented in an HTML document.
@param message: The message in either html or text.
@param title: The title for the message.
@param isHtml: Whether the message is html
:param message: The message in either html or text.
:param title: The title for the message, defaults to "NVDA Message".
:param isHtml: Whether the message is html, defaults to False.
:param closeButtonText: Text to use as label for a "close" button, defaults to None, meaning no close button.
:param copyButton: Whether to include a "copy" (to clipboard) button, defaults to False.
"""
if isRunningOnSecureDesktop():
import wx # Late import to prevent circular dependency.
Expand All @@ -106,7 +114,7 @@ def browseableMessage(message: str, title: Optional[str] = None, isHtml: bool =
raise LookupError(htmlFileName )
moniker = POINTER(IUnknown)()
windll.urlmon.CreateURLMonikerEx(0, htmlFileName, byref(moniker), URL_MK_UNIFORM)
if not title:
if title is None:
# Translators: The title for the dialog used to present general NVDA messages in browse mode.
title = _("NVDA Message")
if not isHtml:
Expand All @@ -123,6 +131,11 @@ def browseableMessage(message: str, title: Optional[str] = None, isHtml: bool =
return
d.add("title", title)
d.add("message", message)
XLTechie marked this conversation as resolved.
Show resolved Hide resolved
if closeButtonText is not None:
d.add("closeButtonText", closeButtonText)
if copyButton:
# Translators: The text of a button to copy the text of the window to the clipboard.
d.add("copyButtonText", _("Copy"))
dialogArgsVar = automation.VARIANT(d)
gui.mainFrame.prePopup()
windll.mshtml.ShowHTMLDialogEx(
Expand Down
2 changes: 2 additions & 0 deletions user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Unicode CLDR has also been updated.
* In the Python console, the last unexecuted command will no longer be lost when moving in the input history. (#16653, @CyrilleB79)
* A unique anonymous ID is now sent as part of optional NVDA usage statistics gathering. (#16266)
* By default, a new folder will be created when making a portable copy. Warnings have been added when writing to a non-empty directory. (#16684)
* The Report link destination and character formatting information windows, now include "Close" and "Copy" buttons for user convenience. (#16369, @XLTechie)

### Bug Fixes
* Windows 11 fixes:
Expand Down Expand Up @@ -81,6 +82,7 @@ It is especially useful to read the error location markers in tracebacks. (#1632
Jobs are scheduled with a delay to avoid conflicts.
* `scheduleThread.scheduleDailyJob` and `scheduleJob` can be used to schedule jobs at custom times, where a `JobClashError` will be raised on a known job scheduling clash.
* It is now possible to create app modules for apps hosting Edge WebView2 (msedgewebview2.exe) controls. (#16705, @josephsl)
* `ui.browseableMessage` may now be called with options to present a button for copying to clipboard, and also an optional close button which may have its name customized. (#16369, @XLTechie)
XLTechie marked this conversation as resolved.
Show resolved Hide resolved

#### Deprecations

Expand Down