Skip to content

Commit 29b526c

Browse files
authored
Merge a793b78 into 7bfe713
2 parents 7bfe713 + a793b78 commit 29b526c

3 files changed

Lines changed: 57 additions & 9 deletions

File tree

source/globalCommands.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,8 @@ def _reportFormattingHelper(self, info, browseable=False):
23492349
ui.browseableMessage(
23502350
message,
23512351
# Translators: title for formatting information dialog.
2352-
_("Formatting")
2352+
_("Formatting"),
2353+
closeButtonText=_("Press escape to close")
23532354
)
23542355

23552356
@staticmethod
@@ -3950,7 +3951,7 @@ def script_reportLinkDestination(
39503951
) -> None:
39513952
"""Generates a ui.message or ui.browseableMessage of a link's destination, if focus or caret is
39523953
positioned on a link, or an element with an included link such as a graphic.
3953-
@param forceBrowseable: skips the press once check, and displays the browseableMessage version.
3954+
:param forceBrowseable: skips the press once check, and displays the browseableMessage version.
39543955
"""
39553956
try:
39563957
ti: textInfos.TextInfo = api.getCaretPosition()
@@ -3987,7 +3988,9 @@ def script_reportLinkDestination(
39873988
linkDestination,
39883989
# Translators: Informs the user that the window contains the destination of the
39893990
# link with given title
3990-
title=_("Destination of: {name}").format(name=obj.name)
3991+
title=_("Destination of: {name}").format(name=obj.name),
3992+
closeButtonText=_("Press escape to exit"),
3993+
copyButtonText=_("Copy")
39913994
)
39923995
elif presses == 0: # One press
39933996
ui.message(linkDestination) # Speak the link

source/message.html

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,51 @@
99
if(e.keyCode == 27){ // code for escape
1010
window.close();
1111
}
12-
};
12+
}
13+
14+
function onCopyButtonPress() {
15+
// Copy code came from http://www.codestore.net/store.nsf/unid/DOMM-4QHQE8/
16+
var rng = document.body.createTextRange();
17+
rng.moveToElementText(messageID);
18+
rng.scrollIntoView();
19+
rng.select();
20+
rng.execCommand("Copy");
21+
rng.collapse(false);
22+
rng.select();
23+
}
24+
25+
function onCloseButtonPress() {
26+
//window.open('', '_self', ''); // Only enable if window.close() stops working in a future version, may fix.
27+
window.close();
28+
}
1329

1430
function windowOnLoad() {
1531
var args = window.dialogArguments;
1632
if (args) {
1733
document.title = args.item('title');
1834
messageID.innerHTML = args.item('message');
35+
// If caller wants a close button
36+
if (args.item('closeButtonText') != null) {
37+
closeButton.innerHTML = args.item('closeButtonText'); // Assign the (translated) label
38+
closeButton.style.display = 'inline'; // Display the button
39+
buttonDiv.style.display = 'block'; // Display the div
40+
}
41+
// If caller wants a copy to clip button
42+
if (args.item('copyButtonText') != null) {
43+
copyButton.innerHTML = args.item('copyButtonText'); // Assign the (translated) label
44+
copyButtonSpan.style.display = 'inline'; // Display the button
45+
buttonDiv.style.display = 'block'; // Display the div
46+
}
1947
}
2048
}
2149
//-->
2250
</SCRIPT>
2351
</HEAD>
2452
<BODY tabindex='0' id='main_body' style="margin:1em" LANGUAGE=javascript onload="return windowOnLoad()" onkeypress="return escapeKeyPress()" >
2553
<div id=messageID></div>
54+
<div id="buttonDiv" style="display: none;"><hr>
55+
<span id="copyButtonSpan" style="display: none;"><button id="copyButton" onclick="onCopyButtonPress();"></button>&nbsp;</span>
56+
<span><button id="closeButton" style="display: none;" onclick="onCloseButtonPress();"></button></span>
57+
</div>
2658
</body>
2759
</html>

source/ui.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,21 @@ def _warnBrowsableMessageNotAvailableOnSecureScreens(title: Optional[str]) -> No
8989
)
9090

9191

92-
def browseableMessage(message: str, title: Optional[str] = None, isHtml: bool = False) -> None:
92+
def browseableMessage(
93+
message: str,
94+
title: Optional[str] = None,
95+
isHtml: bool = False,
96+
closeButtonText: Optional[str] = None,
97+
copyButtonText: Optional[str] = None
98+
) -> None:
9399
"""Present a message to the user that can be read in browse mode.
94100
The message will be presented in an HTML document.
95-
@param message: The message in either html or text.
96-
@param title: The title for the message.
97-
@param isHtml: Whether the message is html
101+
:param message: The message in either html or text.
102+
:param title: The title for the message, defaults to "NVDA Message".
103+
:param isHtml: Whether the message is html, defaults to False.
104+
:param closeButtonText: Text to use as label for a "close" button, defaults to None, meaning no close button.
105+
:param copyButtonText: Text to use as label for a "copy" (to clipboard) button, defaults to None,
106+
meaning no copy button.
98107
"""
99108
if isRunningOnSecureDesktop():
100109
import wx # Late import to prevent circular dependency.
@@ -106,7 +115,7 @@ def browseableMessage(message: str, title: Optional[str] = None, isHtml: bool =
106115
raise LookupError(htmlFileName )
107116
moniker = POINTER(IUnknown)()
108117
windll.urlmon.CreateURLMonikerEx(0, htmlFileName, byref(moniker), URL_MK_UNIFORM)
109-
if not title:
118+
if title is None:
110119
# Translators: The title for the dialog used to present general NVDA messages in browse mode.
111120
title = _("NVDA Message")
112121
if not isHtml:
@@ -120,6 +129,10 @@ def browseableMessage(message: str, title: Optional[str] = None, isHtml: bool =
120129
return
121130
d.add("title", title)
122131
d.add("message", message)
132+
if closeButtonText is not None:
133+
d.add("closeButtonText", closeButtonText)
134+
if copyButtonText is not None:
135+
d.add("copyButtonText", copyButtonText)
123136
dialogArgsVar = automation.VARIANT(d)
124137
gui.mainFrame.prePopup()
125138
windll.mshtml.ShowHTMLDialogEx(

0 commit comments

Comments
 (0)