Skip to content

Commit

Permalink
config/commands.py: added :paper command
Browse files Browse the repository at this point in the history
This uses a hacky workaround for command chaining using global varibales
which should be turned into proper OOP code at some point.  I don't have
the time to redesign ranger/gui/widgets/console.py at this point.
  • Loading branch information
hut committed Dec 3, 2014
1 parent 90f9bac commit 2d7dc04
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ranger/config/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,35 @@ def execute(self):

# Papermanager commands
# --------------------------------
class paper_title(Command):
class paper(Command):
"""
:paper
This command opens a series of commands on the console that will ask the
user to input metadata about the current file. This is used by the paper
manager module of ranger and can be later displayed in ranger, for example
by setting the option "linemode" to "papertitle".
"""
def execute(self):
# TODO: This sets a pseudo-global variable containing a stack of
# commands that should be opened in the console next. It's a
# work-around for ranger's lack of inherent console command chaining
# and will hopefully be implemented properly in the future.
paper._paper_console_chain = ["url", "year", "authors", "title"]

self._process_command_stack()

def _process_command_stack(self):
if paper._paper_console_chain:
key = paper._paper_console_chain.pop()
self._paper_fill_console(key)

def _paper_fill_console(self, key):
text = "paper_%s %s" % (key, "foo")
self.fm.open_console(text, position=len(text))


class paper_title(paper):
"""
:paper_title <title>
Expand All @@ -1296,6 +1324,7 @@ def execute(self):
update_dict = dict()
update_dict[self._key] = self.rest(1)
self.fm.papermanager.set_paper_info(self.fm.thisfile.path, update_dict)
self._process_command_stack()

def tab(self):
paperinfo = self.fm.papermanager.get_paper_info(self.fm.thisfile.path)
Expand Down

0 comments on commit 2d7dc04

Please sign in to comment.