diff options
author | jghauser <julian@julianhauser.com> | 2021-02-22 10:12:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 11:12:00 +0100 |
commit | 50d7b1b47b72c8f54fde897bb7fc18d83ac67adf (patch) | |
tree | b67c4331e9103e050051a133d29372e28688971c | |
parent | e6746068304fdba514e85e7f6e4a7902ad66c8ae (diff) |
Add edit notes functionality to picker (#319)
Add edit notes functionality to picker
Clean up PR
Fix logging and keybinding in edit notes
-rw-r--r-- | papis/commands/edit.py | 50 | ||||
-rw-r--r-- | papis/tui/__init__.py | 1 | ||||
-rw-r--r-- | papis/tui/app.py | 13 |
3 files changed, 40 insertions, 24 deletions
diff --git a/papis/commands/edit.py b/papis/commands/edit.py index eb3adf54..4fcaff8f 100644 --- a/papis/commands/edit.py +++ b/papis/commands/edit.py @@ -42,6 +42,31 @@ def run(document: papis.document.Document, papis.document.describe(document))) +def edit_notes(document: papis.document.Document, + git: bool = False) -> None: + logger = logging.getLogger('edit:notes') + logger.debug("Editing notes") + if not document.has("notes"): + document["notes"] = papis.config.getstring("notes-name") + document.save() + notes_path = os.path.join( + str(document.get_main_folder()), + document["notes"] + ) + + if not os.path.exists(notes_path): + logger.debug("Creating {0}".format(notes_path)) + open(notes_path, "w+").close() + + papis.api.edit_file(notes_path) + if git: + papis.git.add_and_commit_resource( + str(document.get_main_folder()), + str(document.get_info_file()), + "Update notes for '{0}'".format( + papis.document.describe(document))) + + @click.command("edit") @click.help_option('-h', '--help') @papis.cli.query_option() @@ -92,30 +117,7 @@ def cli(query: str, for document in documents: if notes: - logger.debug("Editing notes") - if not document.has("notes"): - logger.warning( - "The document selected has no notes attached, \n" - "creating a notes files" - ) - document["notes"] = papis.config.getstring("notes-name") - document.save() - notes_path = os.path.join( - str(document.get_main_folder()), - document["notes"] - ) - - if not os.path.exists(notes_path): - logger.info("Creating {0}".format(notes_path)) - open(notes_path, "w+").close() - - papis.api.edit_file(notes_path) - if git: - papis.git.add_and_commit_resource( - str(document.get_main_folder()), - str(document.get_info_file()), - "Update notes for '{0}'".format( - papis.document.describe(document))) + edit_notes(document, git=git) else: run(document, git=git) diff --git a/papis/tui/__init__.py b/papis/tui/__init__.py index db11b8a5..dfd71b50 100644 --- a/papis/tui/__init__.py +++ b/papis/tui/__init__.py @@ -22,6 +22,7 @@ def get_default_settings() -> PapisConfigType: 'move_up_while_info_window_active_key': 'c-p', 'focus_command_line_key': 'tab', 'edit_document_key': 'c-e', + 'edit_notes_key': 'c-q', 'open_document_key': 'c-o', 'show_help_key': 'f1', 'show_info_key': 's-tab', diff --git a/papis/tui/app.py b/papis/tui/app.py index 5427ae0e..a0f7f6e9 100644 --- a/papis/tui/app.py +++ b/papis/tui/app.py @@ -67,6 +67,10 @@ def get_keys_info() -> Dict[str, KeyInfo]: 'key': config.getstring('edit_document_key', section='tui'), 'help': 'Edit currently selected document', }, + "edit_notes_key": { + 'key': config.getstring('edit_notes_key', section='tui'), + 'help': 'Edit notes of currently selected document', + }, "open_document_key": { 'key': config.getstring('open_document_key', section='tui'), 'help': 'Open currently selected document', @@ -210,6 +214,15 @@ def get_commands(app: Application) -> Tuple[List[Command], KeyBindings]: run(doc) cmd.app.renderer.clear() + @kb.add(keys_info["edit_notes_key"]["key"], # type: ignore + filter=has_focus(app.options_list.search_buffer)) + def edit_notes(cmd: Command) -> None: + from papis.commands.edit import edit_notes + docs = cmd.app.get_selection() + for doc in docs: + edit_notes(doc) + cmd.app.renderer.clear() + @kb.add(keys_info["show_help_key"]["key"], # type: ignore filter=~has_focus(app.help_window)) def help(event: Event) -> None: |