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 | |
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')
-rw-r--r-- | alot/commands/common.py | 25 | ||||
-rw-r--r-- | alot/commands/search.py | 19 |
2 files changed, 27 insertions, 17 deletions
diff --git a/alot/commands/common.py b/alot/commands/common.py new file mode 100644 index 00000000..64e68d49 --- /dev/null +++ b/alot/commands/common.py @@ -0,0 +1,25 @@ +# Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com> +# This file is released under the GNU GPL, version 3 or a later revision. +# For further details see the COPYING file + +from . import Command + +from .globals import PromptCommand + + +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)) 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( |