Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround: Separate saved searches with tags name #703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion GTG/backends/backend_localfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from GTG.core import xml
from GTG.core import firstrun_tasks
from GTG.core import versioning
from GTG.core.tag import SEARCH_TAG_PREFIX

from typing import Dict
from lxml import etree as et
Expand Down Expand Up @@ -257,7 +258,7 @@ def save_tags(self, tagnames, tagstore) -> None:

# Don't save the @ in the name
element.set('id', tid)
element.set('name', tagname)
element.set('name', tag.get_friendly_name())

# Remove these and don't re-add them if not needed
element.attrib.pop('icon', None)
Expand Down
5 changes: 3 additions & 2 deletions GTG/core/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from GTG.core.config import CoreConfig
from GTG.core import requester
from GTG.core.search import parse_search_query, search_filter, InvalidQuery
from GTG.core.tag import Tag, SEARCH_TAG
from GTG.core.tag import Tag, SEARCH_TAG, SEARCH_TAG_PREFIX
from GTG.core.task import Task
from GTG.core.treefactory import TreeFactory
from GTG.core.borg import Borg
Expand Down Expand Up @@ -139,6 +139,7 @@ def new_search_tag(self, name, query, attributes={}, tid=None, save=True):
init_attr["label"] = name
init_attr["query"] = query

name = SEARCH_TAG_PREFIX + name
tag = Tag(name, req=self.requester, attributes=init_attr, tid=tid)
self._add_new_tag(name, tag, search_filter, parameters,
parent_id=SEARCH_TAG)
Expand Down Expand Up @@ -206,7 +207,7 @@ def rename_tag(self, oldname, newname):
newname = '_' + newname

label, num = newname, 1
while self._tagstore.has_node(label):
while self._tagstore.has_node(SEARCH_TAG_PREFIX + label):
num += 1
label = newname + " " + str(num)

Expand Down
6 changes: 3 additions & 3 deletions GTG/core/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import logging
from gi.repository import GObject

from GTG.core.tag import Tag
from GTG.core.tag import Tag, SEARCH_TAG_PREFIX

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -192,7 +192,7 @@ def new_search_tag(self, query):
name, number = label, 1
already_search = False
while True:
tag = self.get_tag(name)
tag = self.get_tag(SEARCH_TAG_PREFIX + name)
if tag is None:
break

Expand All @@ -207,7 +207,7 @@ def new_search_tag(self, query):
if not already_search:
tag = self.ds.new_search_tag(name, query)

return name
return SEARCH_TAG_PREFIX + name

def remove_tag(self, name):
""" calls datastore to remove a given tag """
Expand Down
10 changes: 9 additions & 1 deletion GTG/core/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
SEP_TAG = "gtg-tags-sep"
SEARCH_TAG = "search"

SEARCH_TAG_PREFIX = "__SAVED_SEARCH_" # For name inside the tagtree

def extract_tags_from_text(text):
""" Given a string, returns a list of the @tags contained in that """
Expand Down Expand Up @@ -140,9 +141,16 @@ def add_child(self, child_id):
TreeNode.add_child(self, child_id)

def get_name(self):
"""Return the name of the tag."""
"""Return the internal name of the tag, as saved in the tree."""
return self.get_attribute("name")

def get_friendly_name(self):
"""Return the name of the tag, but without the internal search tag prefix."""
if self.is_search_tag():
return self.get_attribute("name")[len(SEARCH_TAG_PREFIX):]
else:
return self.get_attribute("name")

def set_save_callback(self, save):
self._save = save

Expand Down
7 changes: 3 additions & 4 deletions GTG/gtk/browser/tag_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def set_tag(self, tag):
icon = tag.get_attribute('icon')
self._set_emoji(self._emoji_entry, text=icon if icon else '')

self.tag_name = tag.get_name()
self.set_title(self._title_format % ('@' + tag.get_name(),))
self.tag_name = tag.get_friendly_name()
self.set_title(self._title_format % ('@' + self.tag_name,))

rgba = Gdk.RGBA(1.0, 1.0, 1.0, 1.0)
if color := tag.get_attribute('color'):
Expand All @@ -187,7 +187,6 @@ def set_tag(self, tag):
tag.get_name(), color)
self.has_color = bool(color)
self.tag_rgba = rgba
self.tag_name = tag.get_name()
self.tag_is_actionable = \
self.tag.get_attribute("nonactionable") != "True"

Expand Down Expand Up @@ -238,7 +237,7 @@ def _apply(self, widget: GObject.Object):

self.tag.set_attribute('nonactionable', str(not self.tag_is_actionable))

if self.tag_name != self.tag.get_name():
if self.tag_name != self.tag.get_friendly_name():
log.debug("Renaming %r → %r", self.tag.get_name(), self.tag_name)
self.req.rename_tag(self.tag.get_name(), self.tag_name)
self.tag = self.req.get_tag(self.tag_name)
Expand Down
2 changes: 1 addition & 1 deletion GTG/plugins/export/export_templates/template_simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@


## #for $tag in $plugin_api.get_requester().get_tag_tree().get_all_nodes()
## $tag.get_name()
## $tag.get_friendly_name()
## #end for

-->
Expand Down