diff options
author | hut <hut@lavabit.com> | 2011-05-20 18:25:01 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-05-20 18:25:01 +0200 |
commit | 43153a6d91459a825e3dcc528cc340abe780d6af (patch) | |
tree | 1ff78e0d54f5471316b08489dced4ed20c8f648a | |
parent | 71569b7201925274f3a97dd24e8e735f50bc9a53 (diff) | |
download | ranger-43153a6d91459a825e3dcc528cc340abe780d6af.tar.gz |
api.commands: implemented command.cancel()
-rw-r--r-- | ranger/api/commands.py | 3 | ||||
-rw-r--r-- | ranger/defaults/commands.py | 1 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 13 |
3 files changed, 14 insertions, 3 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 80827c4f..9a353eef 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -85,6 +85,9 @@ class Command(FileManagerAware): def quick(self): """Override this""" + def cancel(self): + """Override this""" + # COMPAT: this is still used in old commands.py configs def _tab_only_directories(self): from os.path import dirname, basename, expanduser, join, isdir diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index e9572d3e..ad3fa0e5 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -19,6 +19,7 @@ This is the default file for command definitions. Each command is a subclass of `Command'. Several methods are defined to interface with the console: execute: call this method when the command is executed. + cancel: call this method when closing the console without executing. tab: call this method when tab is pressed. quick: call this method after each keypress. diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 12f685d4..a575405d 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -123,7 +123,14 @@ class Console(Widget): self.history.add('') return True - def close(self): + def close(self, trigger_cancel_function=True): + if trigger_cancel_function: + cmd = self._get_cmd() + if cmd: + try: + cmd.cancel() + except Exception as error: + self.fm.notify(error) if self.last_cursor_mode is not None: try: curses.curs_set(self.last_cursor_mode) @@ -288,7 +295,7 @@ class Console(Widget): self.tab_deque = None if mod == -1 and self.pos == 0: if not self.line: - self.close() + self.close(trigger_cancel_function=False) return # Delete utf-char-wise if self.fm.py3: @@ -315,7 +322,7 @@ class Console(Widget): self.fm.notify(error) if self.allow_close: - self.close() + self.close(trigger_cancel_function=False) def _get_cmd(self): try: |