diff options
author | hut <hut@lepus.uberspace.de> | 2015-01-13 14:50:50 +0100 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2015-01-16 23:39:34 +0100 |
commit | a80476a18786dab8db008c3254e73e40ca59856b (patch) | |
tree | a5da4e3c2a5e75fafa1faffc62d70718310eff7e /ranger | |
parent | 90d0eb6ed3211022c3b600521aee85568b9ed905 (diff) | |
download | ranger-a80476a18786dab8db008c3254e73e40ca59856b.tar.gz |
adapted commands for MetadataManager
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/config/commands.py | 84 | ||||
-rw-r--r-- | ranger/config/rc.conf | 2 | ||||
-rw-r--r-- | ranger/container/fsobject.py | 2 | ||||
-rw-r--r-- | ranger/core/actions.py | 4 | ||||
-rw-r--r-- | ranger/gui/widgets/browsercolumn.py | 22 |
5 files changed, 42 insertions, 72 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 5d303b86..29b0d12b 100644 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -1348,87 +1348,57 @@ class flat(Command): self.fm.thisdir.load_content() -# Papermanager commands +# Metadata commands # -------------------------------- -class paper(Command): + +class prompt_metadata(Command): """ - :paper + :prompt_metadata <key1> [<key2> [<key3> ...]] - 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". + Prompt the user to input metadata for multiple keys in a row. """ - _paper_console_chain = None - 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"] + _command_name = "meta" + _console_chain = None + def execute(self): + prompt_metadata._console_chain = self.args[1:] 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) + if prompt_metadata._console_chain: + key = prompt_metadata._console_chain.pop() + self._fill_console(key) else: for col in self.fm.ui.browser.columns: col.need_redraw = True - def _paper_fill_console(self, key): - paperinfo = self.fm.metadata.get_metadata(self.fm.thisfile.path) - if key in paperinfo and paperinfo[key]: - existing_value = paperinfo[key] + def _fill_console(self, key): + metadata = self.fm.metadata.get_metadata(self.fm.thisfile.path) + if key in metadata and metadata[key]: + existing_value = metadata[key] else: existing_value = "" - text = "paper_%s %s" % (key, existing_value) + text = "%s %s %s" % (self._command_name, key, existing_value) self.fm.open_console(text, position=len(text)) -class paper_title(paper): +class meta(prompt_metadata): """ - :paper_title <title> + :meta <key> [<value>] - Tells the paper manager to set/update the title of the current file + Change metadata of a file. Deletes the key if value is empty. """ - _key = "title" def execute(self): + key = self.arg(1) + value = self.rest(1) update_dict = dict() - update_dict[self._key] = self.rest(1) + update_dict[key] = self.rest(2) self.fm.metadata.set_metadata(self.fm.thisfile.path, update_dict) self._process_command_stack() def tab(self): - paperinfo = self.fm.metadata.get_metadata(self.fm.thisfile.path) - if paperinfo[self._key]: - return self.arg(0) + " " + paperinfo[self._key] - - -class paper_authors(paper_title): - """ - :paper_authors <authors> - - Tells the paper manager to set/update the authors of the current file - """ - _key = "authors" - - -class paper_url(paper_title): - """ - :paper_url <authors> - - Tells the paper manager to set/update the url of the current file - """ - _key = "url" - - -class paper_year(paper_title): - """ - :paper_year <authors> - - Tells the paper manager to set/update the year of the current file - """ - _key = "year" + key = self.arg(1) + metadata = self.fm.metadata.get_metadata(self.fm.thisfile.path) + if metadata[key]: + return self.arg(0) + " " + metadata[key] diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index a9e1fa23..687d591e 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -240,7 +240,7 @@ map cd console cd # Change the line mode map Mf linemode filename map Mp linemode permissions -map Mt linemode papertitle +map Mt linemode metatitle # Tagging / Marking map t tag_toggle diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index 2aba1bfb..08161c3c 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -12,7 +12,7 @@ DOCUMENT_BASENAMES = ('bugs', 'bugs', 'changelog', 'copying', 'credits', BAD_INFO = '?' -POSSIBLE_LINEMODES = ("filename", "papertitle", "permissions") +POSSIBLE_LINEMODES = ("filename", "metatitle", "permissions") DEFAULT_LINEMODE = "filename" import re diff --git a/ranger/core/actions.py b/ranger/core/actions.py index c7468be9..62092617 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -158,8 +158,8 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): """ Change what is displayed as a filename. - - "mode" may be: "filename", "permissions", "papertitle", the mode "normal" - is mapped to "filename". + - "mode" may be: "filename", "permissions", "metatitle", the mode + "normal" is mapped to "filename". - "directory" specifies the directory. None means the current directory - "depth" specifies the recursion depth """ diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index 1dcfa40b..b4f8d673 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -249,11 +249,11 @@ class BrowserColumn(Pager): tagged_marker = " " # Extract linemode-related information from the drawn object - paperinfo = None + metadata = None use_linemode = drawn._linemode - if use_linemode == "papertitle": - paperinfo = self.fm.metadata.get_metadata(drawn.path) - if not paperinfo.title: + if use_linemode == "metatitle": + metadata = self.fm.metadata.get_metadata(drawn.path) + if not metadata.title: use_linemode = "filename" key = (self.wid, selected_i == i, drawn.marked, self.main_column, @@ -268,11 +268,11 @@ class BrowserColumn(Pager): # Deal with the line mode - if use_linemode == "papertitle": - if paperinfo.year: - text = "%s - %s" % (paperinfo.year, paperinfo.title) + if use_linemode == "metatitle": + if metadata.year: + text = "%s - %s" % (metadata.year, metadata.title) else: - text = paperinfo.title + text = metadata.title if use_linemode == "filename": text = drawn.drawn_basename elif use_linemode == "permissions": @@ -311,9 +311,9 @@ class BrowserColumn(Pager): infostringlen = 0 if use_linemode == "filename": infostring = self._draw_infostring_display(drawn, space) - elif use_linemode == "papertitle": - if paperinfo and paperinfo.authors: - authorstring = paperinfo.authors + elif use_linemode == "metatitle": + if metadata and metadata.authors: + authorstring = metadata.authors if ',' in authorstring: authorstring = authorstring[0:authorstring.find(",")] infostring.append([" " + authorstring + " ", ["infostring"]]) |