Skip to content

Commit

Permalink
Uniformize all "Copied to clipboard" messages (nvaccess#6757)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienCochuyt committed Jul 15, 2019
1 parent e579eb0 commit 72e9d14
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
11 changes: 10 additions & 1 deletion source/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import braille
import watchdog
import appModuleHandler
import speech

#User functions

Expand Down Expand Up @@ -279,17 +280,21 @@ def processPendingEvents(processEventQueue=True):
if processEventQueue:
queueHandler.flushQueue(queueHandler.eventQueue)

def copyToClip(text):
def copyToClip(text, notify=False):
"""Copies the given text to the windows clipboard.
@returns: True if it succeeds, False otherwise.
@rtype: boolean
@param text: the text which will be copied to the clipboard
@type text: string
@param notify: whether to emit a confirmation message
@type notify: boolean
"""
if isinstance(text,basestring) and len(text)>0 and not text.isspace():
try:
win32clipboard.OpenClipboard()
except win32clipboard.error:
# Translators: Presented when unable to copy to the clipboard because of an error.
ui.message(_("Unable to copy"))
return False
try:
win32clipboard.EmptyClipboard()
Expand All @@ -302,6 +307,10 @@ def copyToClip(text):
finally:
win32clipboard.CloseClipboard()
if got == text:
# Translators: Announced when a text has been copied to clipboard. %s is replaced by the copied text.
speech.speakMessage(_("Copied to clipboard: %s" % text))
# Translators: Displayed in braille when a text has been copied to clipboard. %s is replaced by the copied text.
braille.handler.message(_("Copied: %s" % text))
return True
return False

Expand Down
4 changes: 1 addition & 3 deletions source/cursorManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,7 @@ def script_copyToClipboard(self,gesture):
# Translators: Reported when there is no text selected (for copying).
ui.message(_("No selection"))
return
if info.copyToClipboard():
# Translators: Message presented when text has been copied to clipboard.
ui.message(_("Copied to clipboard"))
info.copyToClipboard(notify=True)

def reportSelectionChange(self, oldTextInfo):
newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION)
Expand Down
18 changes: 4 additions & 14 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,7 @@ def script_navigatorObject_current(self,gesture):
if scriptHandler.getLastScriptRepeatCount()==1:
speech.speakSpelling(text)
else:
if api.copyToClip(text):
# Translators: Indicates something has been copied to clipboard (example output: title text copied to clipboard).
speech.speakMessage(_("%s copied to clipboard")%text)
api.copyToClip(text, notify=True)
else:
speech.speakObject(curObject,reason=controlTypes.REASON_QUERY)
# Translators: Input help mode message for report current navigator object command.
Expand Down Expand Up @@ -1455,9 +1453,7 @@ def script_reportStatusLine(self,gesture):
# Translators: Reported when user attempts to copy content of the empty status line.
ui.message(_("unable to copy status bar content to clipboard"))
else:
if api.copyToClip(text):
# Translators: The message presented when the status bar is copied to the clipboard.
ui.message(_("%s copied to clipboard")%text)
api.copyToClip(text, notify=True)
# Translators: Input help mode message for report status line text command.
script_reportStatusLine.__doc__ = _("Reads the current application status bar and moves the navigator to it. If pressed twice, spells the information. If pressed three times, copies the status bar to the clipboard")
script_reportStatusLine.category=SCRCAT_FOCUS
Expand Down Expand Up @@ -1509,8 +1505,7 @@ def script_title(self,gesture):
elif repeatCount==1:
speech.speakSpelling(title)
else:
if api.copyToClip(title):
ui.message(_("%s copied to clipboard")%title)
api.copyToClip(title, notify=True)
# Translators: Input help mode message for report title bar command.
script_title.__doc__=_("Reports the title of the current application or foreground window. If pressed twice, spells the title. If pressed three times, copies the title to the clipboard")
script_title.category=SCRCAT_FOCUS
Expand Down Expand Up @@ -2003,12 +1998,7 @@ def script_review_copy(self, gesture):
return
elif scriptHandler.getLastScriptRepeatCount()==1: # the second call, try to copy the text
copyMarker = pos.obj._selectThenCopyRange
if copyMarker.copyToClipboard():
# Translators: Presented when some review text has been copied to clipboard.
ui.message(_("Review selection copied to clipboard"))
else:
# Translators: Presented when unable to copy to the clipboard because of an error.
ui.message(_("Unable to copy"))
copyMarker.copyToClipboard(notify=True)
# on the second call always clean up the start marker
api.getReviewPosition().obj._selectThenCopyRange = None
api.getReviewPosition().obj._copyStartMarker = None
Expand Down
6 changes: 4 additions & 2 deletions source/textInfos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,15 @@ def _get_clipboardText(self):
"""Text suitably formatted for copying to the clipboard. E.g. crlf characters inserted between lines."""
return convertToCrlf(self.text)

def copyToClipboard(self):
def copyToClipboard(self, notify=False):
"""Copy the content of this instance to the clipboard.
@return: C{True} if successful, C{False} otherwise.
@rtype: bool
@param notify: whether to emit a confirmation message
@type notify: boolean
"""
import api
return api.copyToClip(self.clipboardText)
return api.copyToClip(self.clipboardText, notify)

def getTextInChunks(self, unit):
"""Retrieve the text of this instance in chunks of a given unit.
Expand Down
4 changes: 2 additions & 2 deletions source/treeInterceptorHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def _set__rangeObj(self,r):
def _get_locationText(self):
return self.innerTextInfo.locationText

def copyToClipboard(self):
return self.innerTextInfo.copyToClipboard()
def copyToClipboard(self, notify=False):
return self.innerTextInfo.copyToClipboard(notify)

def find(self,text,caseSensitive=False,reverse=False):
return self.innerTextInfo.find(text,caseSensitive,reverse)
Expand Down

0 comments on commit 72e9d14

Please sign in to comment.