Skip to content

Commit

Permalink
Adds a temporary bookmark feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nvdaes committed Jun 28, 2017
1 parent 1ab64f0 commit 269614b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
45 changes: 45 additions & 0 deletions addon/globalPlugins/placeMarkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def getLastSpecificFindText():
def getFileBookmarks():
return getFile("bookmarks", ".pickle")

def getFileTempBookmark():
return getFile("bookmarks", ".txt")

def getSavedBookmarks():
fileName = getFileBookmarks()
try:
Expand Down Expand Up @@ -836,6 +839,48 @@ def script_copyCurrentBookmarksFile(self, gesture):
# Translators: message presented in input mode, when a keystroke of an addon script is pressed.
script_copyCurrentBookmarksFile.__doc__ = _("Copies the name of the current file for place markers to the clipboard.")

def script_saveTempBookmark(self, gesture):
obj = api.getFocusObject()
treeInterceptor=obj.treeInterceptor
if hasattr(treeInterceptor,'TextInfo') 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)
fileName = getFileTempBookmark()
try:
with codecs.open(fileName, "w", "utf-8") as f:
f.write(str(count))
# Translators: Message presented when a temporary bookmark is saved.
ui.message(_("Saved temporary bookmark at position %d" % count))
except Exception as e:
log.debugWarning("Error saving temporary bookmark", exc_info=True)
raise e
# Translators: message presented in input mode, when a keystroke of an addon script is pressed.
script_saveTempBookmark.__doc__ = _("Saves the current position as a temporary bookmark.")

def script_moveToTempBookmark(self, gesture):
fileName = getFileTempBookmark()
try:
with codecs.open(fileName, "r", "utf-8") as f:
tempBookmark = int(f.read())
moveToBookmark(tempBookmark)
except:
# Translators: Message presented when a temporary bookmark can't be found.
ui.message("Temporary bookmark not found")
# Translators: Message presented in input help mode.
script_moveToTempBookmark.__doc__ = _("Moves to the temporary bookmark for the current document.")

__gestures = {
"kb:control+shift+NVDA+f": "specificFind",
"kb:control+shift+NVDA+k": "saveBookmark",
Expand Down
6 changes: 4 additions & 2 deletions addon/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ This addon is based on SpecificSearch and Bookmark&Search, developed by the same
* shift+NVDA+k: Moves to the previous bookmark.
* control+shift+k: Copies the file name where the place markers data will be saved to the clipboard, without an extension.
* alt+NVDA+k: Opens a dialog with the bookmarks saved for this document. You can write a note for each bookmark; press Save note to save changes. Pressing OK you can move to the selected position.

Note: Sometimes this doesn't work on browsers like Firefox. If it happens, please refresh the buffer pressing NVDA+f5 and try to use the dialog again, or move to the bookmark from the document using NVDA+k.
* Not assigned: Save a position as a temporary bookmark.
* Not assigned: Moves to the temporary bookmark for the current document.


## Place markers Submenu (NVDA+N) ##
Expand All @@ -32,6 +32,8 @@ Using the Place markers submenu under NVDA's Preferences menu, you can access:

Note: The bookmark position is based on the number of characters; and therefore in dynamic pages it is better to use the specific search, not bookmarks.

## Changes for 9.0 ##
* It's possible to save and move to a temporary bookmark for each document.

## Changes for 8.0 ##
* Removed fragment identifiers from bookmark filenames, which can avoid issues in the VitalSource Bookshelf ePUB reader.
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" : "8.0",
"addon_version" : "9.0-dev",
# Author(s)
"addon_author" : u"Noelia <[email protected]>, Chris <[email protected]>",
# URL for the add-on documentation support
Expand Down

0 comments on commit 269614b

Please sign in to comment.