Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed May 10, 2023
1 parent cb5b9fd commit 61a3eb1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
7 changes: 7 additions & 0 deletions data/io.github.mrvladus.List.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
</screenshot>
</screenshots>
<releases>
<release version="44.4.2" date="2023-05-10">
<description>
<ul>
<li>Fixed another one bug with URL's</li>
</ul>
</description>
</release>
<release version="44.4.1" date="2023-05-08">
<description>
<ul>
Expand Down
57 changes: 44 additions & 13 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from gi.repository import Gio, Adw, Gtk, Gdk, GLib


VERSION = "44.4.1"
VERSION = "44.4.2"
APP_ID = "io.github.mrvladus.List"
gsettings = Gio.Settings.new(APP_ID)

Expand Down Expand Up @@ -164,15 +164,43 @@ class Todo(Adw.PreferencesGroup):

def __init__(self, text, color, sub_todos, parent):
super().__init__()
self.text = text
self.parent = parent
self.task_row.props.title = text
old_text = self.text
# Detect if text was escaped
if (
"&amp;" in old_text
or "&lt;" in old_text
or "&gt;" in old_text
or "&#39;" in old_text
):
self.text = old_text
# If not then escape it
else:
self.text = GLib.markup_escape_text(self.text)
self.update_data(old_text, self.text)
self.task_row.props.title = self.text
# Set accent color
if color != "":
self.task_row.add_css_class(f"row_{color}")
# Add sub tasks
for todo in sub_todos:
self.task_row.add_row(SubTodo(todo, self.task_row))
# Expand if sub tasks exists
if sub_todos != []:
self.task_row.props.expanded = True

def update_data(self, old_text: str, new_text: str):
new_data = UserData.get()
# Create new dict and change todo text
tmp = UserData.default_data
for key in new_data["todos"]:
if key == old_text:
tmp["todos"][new_text] = new_data["todos"][old_text]
else:
tmp["todos"][key] = new_data["todos"][key]
UserData.set(tmp)

@Gtk.Template.Callback()
def on_task_delete(self, _):
self.task_popover.popdown()
Expand All @@ -185,18 +213,11 @@ def on_task_delete(self, _):
def on_task_edited(self, entry):
# Get old and new text
old_text = self.task_row.props.title
new_text = entry.get_buffer().props.text
new_text = GLib.markup_escape_text(entry.get_buffer().props.text)
new_data = UserData.get()
if old_text == new_text or new_text in new_data["todos"] or new_text == "":
return
# Create new dict and change todo text
tmp = UserData.default_data
for key in new_data["todos"]:
if key == old_text:
tmp["todos"][new_text] = new_data["todos"][old_text]
else:
tmp["todos"][key] = new_data["todos"][key]
UserData.set(tmp)
self.update_data(old_text, new_text)
# Set new title
self.task_row.props.title = new_text
# Clear entry
Expand Down Expand Up @@ -249,7 +270,17 @@ def __init__(self, text, parent):
self.sub_task_completed_btn.props.active = True
else:
old_text = self.text
self.text = GLib.markup_escape_text(self.text)
# Detect if text was escaped
if (
"&amp;" in old_text
or "&lt;" in old_text
or "&gt;" in old_text
or "&#39;" in old_text
):
self.text = old_text
# If not then escape it
else:
self.text = GLib.markup_escape_text(self.text)
self.update_data(old_text, self.text)
self.props.title = self.text

Expand All @@ -270,7 +301,7 @@ def on_sub_task_delete(self, _):
@Gtk.Template.Callback()
def on_sub_task_edit(self, entry):
old_text = self.props.title
new_text = entry.get_buffer().props.text
new_text = GLib.markup_escape_text(entry.get_buffer().props.text)
if (
new_text == old_text
or new_text == ""
Expand Down
2 changes: 2 additions & 0 deletions src/res/ui/todo.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<!-- Expander row -->
<child>
<object class="AdwExpanderRow" id="task_row">
<property name="use-markup">true</property>
<property name="title-selectable">true</property>
<!-- Task menu -->
<child type="prefix">
<object class="GtkMenuButton" id="task_menu">
Expand Down

0 comments on commit 61a3eb1

Please sign in to comment.