From 6b74683fb45c315224fdeab4894f0e3ef7bc3bd4 Mon Sep 17 00:00:00 2001 From: "Amlesh Sivanantham (zamlz)" Date: Mon, 11 Mar 2019 12:29:19 -0700 Subject: [PATCH] Added events for edit command also added comments to events functions to list what uses them --- pubs/commands/edit_cmd.py | 5 +++++ pubs/events.py | 27 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pubs/commands/edit_cmd.py b/pubs/commands/edit_cmd.py index 8cc175b..431d19c 100644 --- a/pubs/commands/edit_cmd.py +++ b/pubs/commands/edit_cmd.py @@ -7,6 +7,7 @@ from ..uis import get_ui from ..endecoder import EnDecoder from ..utils import resolve_citekey from ..completion import CiteKeyCompletion +from ..events import ModifyEvent def parser(subparsers, conf): @@ -88,4 +89,8 @@ def command(conf, args): # else edit again # Also handle malformed bibtex and metadata + if meta: + ModifyEvent(citekey, "metadata").send() + else: + ModifyEvent(citekey, "bibtex").send() rp.close() diff --git a/pubs/events.py b/pubs/events.py index df8fec4..a31c69e 100644 --- a/pubs/events.py +++ b/pubs/events.py @@ -35,27 +35,35 @@ class PaperEvent(Event): def description(self): return self._format.format(citekey=self.citekey) - +# Used by repo.push_paper() class AddEvent(PaperEvent): _format = "Adds paper {citekey}." - +# Used by repo.push_doc() class DocAddEvent(PaperEvent): - _format = "Adds document {citekey}." - + _format = "Adds document for {citekey}." +# Used by repo.remove_paper() class RemoveEvent(PaperEvent): - _format = "Removes paper {citekey}." - + _format = "Removes paper for {citekey}." +# Used by repo.remove_doc() class DocRemoveEvent(PaperEvent): - _format = "Removes document {citekey}." - + _format = "Removes document for {citekey}." +# Used by commands.edit_cmd.command() class ModifyEvent(PaperEvent): - _format = "Modifies paper {citekey}." + _format = "Modifies {file_type} file of {citekey}." + + def __init__(self, citekey, file_type): + super(ModifyEvent, self).__init__(citekey) + self.file_type = file_type + @property + def description(self): + return self._format.format(citekey=self.citekey, file_type=self.file_type) +# Used by repo.rename_paper() class RenameEvent(PaperEvent): _format = "Renames paper {old_citekey} to {citekey}." @@ -68,5 +76,6 @@ class RenameEvent(PaperEvent): def description(self): return self._format.format(citekey=self.citekey, old_citekey=self.old_citekey) +# Used by commands.note_cmd.command() class NoteEvent(PaperEvent): _format = "Modifies note {citekey}"