Add a "directory:" tag for the game search

This commit is contained in:
Daniel Johnson 2024-04-18 18:52:50 -04:00 committed by Mathieu Comandon
parent 7d38dd032d
commit 3c3480322a
2 changed files with 16 additions and 2 deletions

View file

@ -191,7 +191,9 @@ class BaseSearch:
class GameSearch(BaseSearch):
tags = set(["installed", "hidden", "favorite", "categorized", "category", "runner", "platform", "playtime"])
tags = set(
["installed", "hidden", "favorite", "categorized", "category", "runner", "platform", "playtime", "directory"]
)
def __init__(self, text: str, service) -> None:
self.service = service
@ -216,6 +218,10 @@ class GameSearch(BaseSearch):
if name == "playtime":
return self.get_playtime_predicate(tokens)
if name == "directory":
directory = tokens.get_cleaned_token_sequence(stop_tokens=ITEM_STOP_TOKENS) or ""
return self.get_directory_predicate(directory)
# All flags handle the 'maybe' option the same way, so we'll
# group them at the end.
flag = read_flag_token(tokens)
@ -281,6 +287,13 @@ class GameSearch(BaseSearch):
return matcher
def get_directory_predicate(self, directory: str) -> Callable:
def match_directory(db_game):
game_dir = db_game.get("directory")
return game_dir and directory in game_dir
return match_directory
def get_installed_predicate(self, installed: bool) -> Callable:
def match_installed(db_game):
is_installed = self._is_installed(db_game)

View file

@ -313,7 +313,8 @@
<b>category:</b><i>x</i> Only games in cateogry <i>x</i>.
<b>runner:</b><i>wine</i> Only Wine games
<b>platform:</b><i>windows</i> Only Windows games
&lt;b&gt;playtime:&lt;/b&gt;&lt;i&gt;&amp;gt;2 hours&lt;/i&gt; Only games played for more than 2 hours.</property>
&lt;b&gt;playtime:&lt;/b&gt;&lt;i&gt;&amp;gt;2 hours&lt;/i&gt; Only games played for more than 2 hours.
&lt;b&gt;directory:&lt;/b&gt;&lt;i&gt;game/dir&lt;/i&gt; Only games at the path.</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="width-chars">30</property>