summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/keys.py1
-rw-r--r--ranger/container/tags.py55
-rw-r--r--ranger/core/actions.py6
-rw-r--r--ranger/defaults/keys.py2
-rw-r--r--ranger/gui/widgets/browsercolumn.py8
5 files changed, 51 insertions, 21 deletions
diff --git a/ranger/api/keys.py b/ranger/api/keys.py
index 7ba05c73..75de6237 100644
--- a/ranger/api/keys.py
+++ b/ranger/api/keys.py
@@ -21,6 +21,7 @@ from inspect import getargspec, ismethod
 from ranger import RANGERDIR
 from ranger.api import *
 from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
+from ranger.container.tags import ALLOWED_KEYS as ALLOWED_TAGS_KEYS
 from ranger.container.keymap import KeyMap, Direction, KeyMapWithDirections
 
 # A dummy that allows the generation of docstrings in ranger.defaults.keys
diff --git a/ranger/container/tags.py b/ranger/container/tags.py
index 9ef8a1b2..ed015d16 100644
--- a/ranger/container/tags.py
+++ b/ranger/container/tags.py
@@ -14,8 +14,12 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from os.path import isdir, exists, dirname, abspath, realpath, expanduser
+import string
+
+ALLOWED_KEYS = string.ascii_letters + string.digits + string.punctuation
 
 class Tags(object):
+
 	def __init__(self, filename):
 
 		self._filename = realpath(abspath(expanduser(filename)))
@@ -28,33 +32,47 @@ class Tags(object):
 	def __contains__(self, item):
 		return item in self.tags
 
-	def add(self, *items):
+	def add(self, *items, **others):
+		if 'mark' in others:
+			mark = others['mark']
+		else:
+			mark = '*'
 		self.sync()
 		for item in items:
-			self.tags.add(item)
+			self.tags[item] = mark
 		self.dump()
 
 	def remove(self, *items):
 		self.sync()
 		for item in items:
 			try:
-				self.tags.remove(item)
+				del(self.tags[item])
 			except KeyError:
 				pass
 		self.dump()
 
-	def toggle(self, *items):
+	def toggle(self, *items, **others):
+		if 'mark' in others:
+			mark = others['mark']
+		else:
+			mark = '*'
 		self.sync()
 		for item in items:
-			if item in self:
-				try:
-					self.tags.remove(item)
-				except KeyError:
-					pass
-			else:
-				self.tags.add(item)
+			try:
+				if item in self and self.tags[item] == mark:
+					del(self.tags[item])
+				else:
+					self.tags[item] = mark
+			except KeyError:
+				pass
 		self.dump()
 
+	def marker(self, item):
+		if item in self.tags:
+			return self.tags[item]
+		else:
+			return '*'
+
 	def sync(self):
 		try:
 			f = open(self._filename, 'r')
@@ -74,13 +92,20 @@ class Tags(object):
 			f.close()
 
 	def _compile(self, f):
-		for line in self.tags:
-			f.write(line + '\n')
+		for path, mark in self.tags.items():
+			if mark in ALLOWED_KEYS:
+				f.write('{0}:{1}\n'.format(mark, path))
 
 	def _parse(self, f):
-		result = set()
+		result = dict()
 		for line in f:
-			result.add(line.strip())
+			line = line.strip()
+			if len(line) > 2 and line[1] == ':':
+				mark, path = line[0], line[2:]
+				if mark in ALLOWED_KEYS:
+					result[path] = mark
+			else:
+				result[line] = '*'
 		return result
 
 	def __nonzero__(self):
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 89bd9389..8cecf077 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -430,7 +430,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	# Tags are saved in ~/.config/ranger/tagged and simply mark if a
 	# file is important to you in any context.
 
-	def tag_toggle(self, paths=None, value=None, movedown=None):
+	def tag_toggle(self, paths=None, value=None, movedown=None, mark='*'):
 		if not self.tags:
 			return
 		if paths is None:
@@ -438,11 +438,11 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 		else:
 			tags = [realpath(path) for path in paths]
 		if value is True:
-			self.tags.add(*tags)
+			self.tags.add(*tags, mark=mark)
 		elif value is False:
 			self.tags.remove(*tags)
 		else:
-			self.tags.toggle(*tags)
+			self.tags.toggle(*tags, mark=mark)
 
 		if movedown is None:
 			movedown = len(tags) == 1 and paths is None
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index fef678c1..15aab318 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -159,6 +159,8 @@ map('L', fm.history_go(1))
 # ----------------------------------------------- tagging / marking
 map('t', fm.tag_toggle())
 map('T', fm.tag_remove())
+for key in ALLOWED_TAGS_KEYS:
+		map('"' + key, fm.tag_toggle(mark=key))
 
 map(' ', fm.mark(toggle=True))
 map('v', fm.mark(all=True, toggle=True))
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 2928af23..801b79fd 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -27,7 +27,6 @@ class BrowserColumn(Pager):
 	display_infostring = False
 	scroll_begin = 0
 	target = None
-	tagged_marker = '*'
 	last_redraw_time = -1
 	ellipsis = { False: '~', True: '…' }
 
@@ -228,6 +227,9 @@ class BrowserColumn(Pager):
 			text = drawn.basename
 			tagged = self.fm.tags and drawn.realpath in self.fm.tags
 
+			if tagged:
+				tagged_marker = self.fm.tags.marker(drawn.realpath)
+
 			space = self.wid - len(infostring)
 			if self.main_column:
 				space -= 2
@@ -248,7 +250,7 @@ class BrowserColumn(Pager):
 			if tagged:
 				this_color.append('tagged')
 				if self.main_column or self.settings.display_tags_in_all_columns:
-					text = self.tagged_marker + text
+					text = tagged_marker + text
 
 			if drawn.is_directory:
 				this_color.append('directory')
@@ -301,7 +303,7 @@ class BrowserColumn(Pager):
 			if (self.main_column or self.settings.display_tags_in_all_columns) \
 					and tagged and self.wid > 2:
 				this_color.append('tag_marker')
-				self.color_at(line, 0, len(self.tagged_marker), this_color)
+				self.color_at(line, 0, len(tagged_marker), this_color)
 
 			self.color_reset()