diff options
author | Michael J Gruber <github@grubix.eu> | 2018-03-09 16:20:06 +0100 |
---|---|---|
committer | Michael J Gruber <github@grubix.eu> | 2018-06-22 11:31:50 +0200 |
commit | 35ef660f7883428da3ba0ad27d267725293a65a9 (patch) | |
tree | 69154007f74d79610f787fd382103bac960610a1 /alot/commands/search.py | |
parent | e00653245e4cf4303a65eb46b045bd6bdfcf707d (diff) |
refactor common retagprompt
Introduce a new source file common.py for common commands and, as a
first example, define RetagPromptCommand there and register it from
search.py.
This shows how to "decorate" a class that is defined somewhere else, and
thus how to decorate it multiple times.
Diffstat (limited to 'alot/commands/search.py')
-rw-r--r-- | alot/commands/search.py | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/alot/commands/search.py b/alot/commands/search.py index 946749ec..3e172dd5 100644 --- a/alot/commands/search.py +++ b/alot/commands/search.py @@ -7,6 +7,7 @@ import logging from . import Command, registerCommand from .globals import PromptCommand from .globals import MoveCommand +from .common import RetagPromptCommand from .. import commands from .. import buffers @@ -91,23 +92,7 @@ class RefinePromptCommand(Command): return ui.apply_command(PromptCommand('refine ' + oldquery)) -@registerCommand(MODE, 'retagprompt') -class RetagPromptCommand(Command): - - """prompt to retag selected threads\' tags""" - def apply(self, ui): - thread = ui.current_buffer.get_selected_thread() - if not thread: - return - tags = [] - for tag in thread.get_tags(): - if ' ' in tag: - tags.append('"%s"' % tag) - # skip empty tags - elif tag: - tags.append(tag) - initial_tagstring = ','.join(sorted(tags)) + ',' - return ui.apply_command(PromptCommand('retag ' + initial_tagstring)) +RetagPromptCommand = registerCommand(MODE, 'retagprompt')(RetagPromptCommand) @registerCommand( |