I am working on a plugin that loads text notes from an external resource. The plugin works like this: Launch the command palette and type “open note”. Selecting the “open note” menu item executes ListNotebooks() which displays a list of notebooks. Selecting a notebook executes list_notes() that lists the notes in that notebook. Finally, selecting a specific note opens that note in a new view.
I’m having some issues with the last part, though. After reading some posts here, I ended up creating a seperate ViewNote class, but I’m not having any luck with that either. I’m fairly new to Python, so this is probably due to a misunderstanding on my part. Anyway, I’ve been banging my head against this for a few weeks now with no progress, so I’m hoping someone can help. I am able to select a notebook to view the notes in that notebook, but the plugin stops when I select a particular note. I get no errors when I run the plugin, but it seems to stop at the run_command() in the on_done() function.
class ListNotebooksCommand(sublime_plugin.TextCommand):
def run(self, edit):
paper = PaperworkAPI()
notebooklist = paper.list_notebooks()
sublime.active_window().show_quick_panel(notebooklist, self.list_notes, sublime.KEEP_OPEN_ON_FOCUS_LOST)
def list_notes(self, index):
if index == -1:
return
paper = PaperworkAPI()
notebooklist = paper.list_notebooks()
notebooktitle = notebooklist[index]
self.notebookid = paper.notebook_to_id(notebooktitle)
self.notelist = paper.list_notes(self.notebookid)
sublime.active_window().show_quick_panel(self.notelist, self.on_done, sublime.KEEP_OPEN_ON_FOCUS_LOST, 0)
def on_done(self, index):
paper = PaperworkAPI()
notelist = paper.list_notes(self.notebookid)
notetitle = notelist[index]
noteid = paper.note_to_id(notetitle)
# This isn't being executed, or if it is, it's not throwing any errors
# This should open a note with noteid that resides in notebook with notebookid
self.view.run_command("View_Note", {'noteid': noteid})
class ViewNoteCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("test")
paper = PaperworkAPI()
# Get list of notes in notebookid
notelist = paper.list_notes(self.notebookid)
# Get title of note selected in quick panel
notetitle = notelist[index]
# Get noteid for note with title notetitle
noteid = paper.note_to_id(notetitle)
# Get note with id noteid in notebook with id notebookid
note = paper.get_note(self.notebookid, noteid)
# Convert HTML in note to plain text
note = paper.html2text(note)
self.view = self.view.window().new_file()
windowtitle = paper.get_note_title(self.notebookid, noteid)
self.view.set_name(windowtitle)
# Display note in new view with title windowtitle
self.view.insert(edit, self.view.sel()[0].begin(), note)