Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
nvdaes committed Dec 29, 2018
2 parents 451cb00 + 17ddae3 commit 6c38fee
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 96 deletions.
151 changes: 56 additions & 95 deletions addon/globalPlugins/placeMarkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import globalVars
import languageHandler
import textInfos
from textInfos.offsets import Offsets
from cursorManager import CursorManager
from browseMode import BrowseModeDocumentTreeInterceptor
import controlTypes
Expand Down Expand Up @@ -119,13 +120,10 @@ def moveToBookmark(position):
obj = api.getFocusObject()
treeInterceptor=obj.treeInterceptor
if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough:
obj=treeInterceptor
info = obj.makeTextInfo(textInfos.POSITION_FIRST)
info.move(textInfos.UNIT_CHARACTER, position)
if hasattr(obj,'selection'):
obj.selection=info
else:
info.updateCaret()
obj = treeInterceptor
bookmark = Offsets(position, position)
info = obj.makeTextInfo(bookmark)
info.updateSelection()
speech.cancelSpeech()
info.move(textInfos.UNIT_LINE,1,endPoint="end")
speech.speakTextInfo(info,reason=controlTypes.REASON_CARET)
Expand Down Expand Up @@ -716,34 +714,25 @@ def script_saveBookmark(self, gesture):
gesture.send()
return
treeInterceptor=obj.treeInterceptor
if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough:
if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough:
obj=treeInterceptor
else:
gesture.send()
return
start = obj.makeTextInfo(textInfos.POSITION_ALL)
try:
end = obj.makeTextInfo(textInfos.POSITION_CARET)
except (NotImplementedError, RuntimeError):
ui.message(
# Translators: message presented when a bookmark cannot be saved.
_("Bookmark cannot be saved"))
return
start.setEndPoint(end, "endToStart")
count = len(start.text)
bookmark = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark
bookmarks = getSavedBookmarks()
noteTitle = obj.makeTextInfo(textInfos.POSITION_SELECTION).text[:100].encode("utf-8")
if count in bookmarks:
noteBody = bookmarks[count].body
if bookmark.startOffset in bookmarks:
noteBody = bookmarks[bookmark.startOffset].body
else:
noteBody = ""
bookmarks[count] = Note(noteTitle, noteBody)
bookmarks[bookmark.startOffset] = Note(noteTitle, noteBody)
fileName = getFileBookmarks()
try:
pickle.dump(bookmarks, file(fileName, "wb"))
ui.message(
# Translators: message presented when a position is saved as a bookmark.
_("Saved position at character %d") %count)
_("Saved position at character %d") % bookmark.startOffset)
except Exception as e:
log.debugWarning("Error saving bookmark", exc_info=True)
ui.message(
Expand All @@ -759,7 +748,7 @@ def script_saveBookmark(self, gesture):
def script_deleteBookmark(self, gesture):
obj = api.getFocusObject()
treeInterceptor=obj.treeInterceptor
if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough:
if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough:
obj=treeInterceptor
else:
gesture.send()
Expand All @@ -770,22 +759,13 @@ def script_deleteBookmark(self, gesture):
# Translators: message presented when the current document doesn't contain bookmarks.
_("No bookmarks"))
return
start = obj.makeTextInfo(textInfos.POSITION_ALL)
try:
end = obj.makeTextInfo(textInfos.POSITION_CARET)
except (NotImplementedError, RuntimeError):
ui.message(
# Translators: Message presented when a bookmark can't be deleted.
_("Bookmark cannot be deleted"))
return
start.setEndPoint(end, "endToStart")
count = len(start.text)
if count not in bookmarks:
curPos = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark.startOffset
if curPos not in bookmarks:
ui.message(
# Translators: message presented when the current document has bookmarks, but none is selected.
_("No bookmark selected"))
return
del(bookmarks[count])
del(bookmarks[curPos])
fileName = getFileBookmarks()
if bookmarks != {}:
try:
Expand Down Expand Up @@ -823,7 +803,7 @@ def script_selectNextBookmark(self, gesture):
gesture.send()
return
treeInterceptor=obj.treeInterceptor
if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough:
if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough:
obj=treeInterceptor
else:
gesture.send()
Expand All @@ -834,29 +814,23 @@ def script_selectNextBookmark(self, gesture):
# Translators: message presented when trying to select a bookmark, but none is found.
_("No bookmarks found"))
return
start = obj.makeTextInfo(textInfos.POSITION_ALL)
try:
end = obj.makeTextInfo(textInfos.POSITION_CARET)
except (NotImplementedError, RuntimeError):
ui.message(
# Translators: message presented when cannot find any bookmarks.
_("Cannot find any bookmarks"))
curPos = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark.startOffset
nextPos = None
for pos in sorted(bookmarks):
if pos > curPos:
nextPos = pos
break
if nextPos is not None:
info = obj.makeTextInfo(Offsets(nextPos, nextPos))
info.updateSelection()
if willSayAllResume(gesture):
info.move(textInfos.UNIT_LINE,1,endPoint="end")
#speech.speakTextInfo(info,reason=controlTypes.REASON_CARET)
else:
ui.message(
# Translators: message presented when a bookmark is selected.
_("Position: character %d") % nextPos)
return
start.setEndPoint(end, "endToStart")
count = len(start.text)
positions = list(bookmarks.keys())
positions.sort()
for pos in positions:
if pos > count:
end.move(textInfos.UNIT_CHARACTER, pos - count)
obj.selection = end
if not willSayAllResume(gesture):
end.move(textInfos.UNIT_LINE,1,endPoint="end")
speech.speakTextInfo(end,reason=controlTypes.REASON_CARET)
ui.message(
# Translators: message presented when a bookmark is selected.
_("Position: character %d") % pos)
return
ui.message(
# Translators: message presented when the next bookmark is not found.
_("Next bookmark not found"))
Expand All @@ -874,7 +848,7 @@ def script_selectPreviousBookmark(self, gesture):
gesture.send()
return
treeInterceptor=obj.treeInterceptor
if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough:
if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough:
obj=treeInterceptor
else:
gesture.send()
Expand All @@ -885,29 +859,23 @@ def script_selectPreviousBookmark(self, gesture):
# Translators: message presented when trying to select a bookmark, but none is found.
_("No bookmarks found"))
return
start = obj.makeTextInfo(textInfos.POSITION_ALL)
try:
end = obj.makeTextInfo(textInfos.POSITION_CARET)
except (NotImplementedError, RuntimeError):
# Translators: message presented when cannot find any bookmarks.
ui.message(_("Cannot find any bookmarks"))
curPos = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark.startOffset
prevPos = None
for pos in sorted(bookmarks, reverse=True):
if pos < curPos:
prevPos = pos
break
if prevPos is not None:
info = obj.makeTextInfo(Offsets(prevPos, prevPos))
info.updateSelection()
if willSayAllResume(gesture):
info.move(textInfos.UNIT_LINE,1,endPoint="end")
#speech.speakTextInfo(info,reason=controlTypes.REASON_CARET)
else:
ui.message(
# Translators: message presented when a bookmark is selected.
_("Position: character %d") % prevPos)
return
start.setEndPoint(end, "endToStart")
count = len(start.text)
positions = list(bookmarks.keys())
positions.sort()
positions.reverse()
for pos in positions:
if pos < count:
end.move(textInfos.UNIT_CHARACTER, pos - count)
obj.selection = end
if not willSayAllResume(gesture):
end.move(textInfos.UNIT_LINE,1,endPoint="end")
speech.speakTextInfo(end,reason=controlTypes.REASON_CARET)
ui.message(
# Translators: message presented when a bookmark is selected.
_("Position: character %d") % pos)
return
ui.message(
# Translators: message presented when the previous bookmark is not found.
_("Previous bookmark not found"))
Expand Down Expand Up @@ -945,27 +913,18 @@ def script_saveTempBookmark(self, gesture):
gesture.send()
return
treeInterceptor=obj.treeInterceptor
if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough:
if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough:
obj=treeInterceptor
else:
gesture.send()
return
start = obj.makeTextInfo(textInfos.POSITION_ALL)
try:
end = obj.makeTextInfo(textInfos.POSITION_CARET)
except (NotImplementedError, RuntimeError):
ui.message(
# Translators: message presented when a bookmark cannot be saved.
_("Bookmark cannot be saved"))
return
start.setEndPoint(end, "endToStart")
count = len(start.text)
bookmark = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark
fileName = getFileTempBookmark()
try:
with codecs.open(fileName, "w", "utf-8") as f:
f.write(str(count))
f.write(str(bookmark.startOffset))
# Translators: Message presented when a temporary bookmark is saved.
ui.message(_("Saved temporary bookmark at position %d" % count))
ui.message(_("Saved temporary bookmark at position %d" % bookmark.startOffset))
except Exception as e:
log.debugWarning("Error saving temporary bookmark", exc_info=True)
raise e
Expand All @@ -981,7 +940,9 @@ def script_moveToTempBookmark(self, gesture):
gesture.send()
return
treeInterceptor=obj.treeInterceptor
if not(hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough):
if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough:
obj=treeInterceptor
else:
gesture.send()
return
fileName = getFileTempBookmark()
Expand Down
2 changes: 1 addition & 1 deletion buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
"addon_description" : _("Add-on for setting place markers on specific virtual documents"),
# version
"addon_version" : "12.2",
"addon_version" : "12.2.1",
# Author(s)
"addon_author" : u"Noelia <[email protected]>, Chris <[email protected]>",
# URL for the add-on documentation support
Expand Down

0 comments on commit 6c38fee

Please sign in to comment.