Skip to content

Commit

Permalink
Add primary action preference
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 9, 2024
1 parent 27b19ef commit 536ad33
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
3 changes: 3 additions & 0 deletions data/io.github.mrvladus.List.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
<key name="sync-cal-name" type="s">
<default>""</default>
</key>
<key name="primary-action-show-sub-tasks" type="b">
<default>false</default>
</key>
</schema>
</schemalist>
33 changes: 33 additions & 0 deletions errands/widgets/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,41 @@ def _build_ui(self):
right_sidebar_row.set_activatable_widget(self.right_sidebar_btn)
details_group.add(right_sidebar_row)

# Primary action group
primary_action_group = Adw.PreferencesGroup(
title=_("Primary Action"),
)
# Open Details Panel
self.open_details_panel_btn = Gtk.CheckButton(
active=not GSettings.get("primary-action-show-sub-tasks")
)
self.open_details_panel_btn.connect("toggled", self.on_primary_action_change, False)
open_details_panel_row = Adw.ActionRow(
title=_("Open Details Panel"),
icon_name="errands-info-symbolic",
)
open_details_panel_row.add_suffix(self.open_details_panel_btn)
open_details_panel_row.set_activatable_widget(self.open_details_panel_btn)
primary_action_group.add(open_details_panel_row)
# Show Sub-Tasks Row
self.show_sub_tasks_btn = Gtk.CheckButton(
group=self.open_details_panel_btn, active=GSettings.get("primary-action-show-sub-tasks")
)
self.show_sub_tasks_btn.connect("toggled", self.on_primary_action_change, True)
show_sub_tasks_row = Adw.ActionRow(
title=_("Show Sub-Tasks"),
icon_name="view-list-bullet-symbolic",
)
show_sub_tasks_row.add_suffix(self.show_sub_tasks_btn)
show_sub_tasks_row.set_activatable_widget(self.show_sub_tasks_btn)
primary_action_group.add(show_sub_tasks_row)

# Page
page = Adw.PreferencesPage()
page.add(theme_group)
page.add(sync_group)
page.add(details_group)
page.add(primary_action_group)
self.add(page)

def _setup_sync(self):
Expand Down Expand Up @@ -173,3 +203,6 @@ def on_theme_change(self, btn: Gtk.Button, theme: int) -> None:
def on_details_change(self, btn: Gtk.Button, right: bool) -> None:
self.window.update_details(right)
GSettings.set("right-sidebar", "b", right)

def on_primary_action_change(self, btn: Gtk.Button, show_subtasks: bool) -> None:
GSettings.set("primary-action-show-sub-tasks", "b", show_subtasks)
33 changes: 28 additions & 5 deletions errands/widgets/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from errands.utils.data import UserData
from errands.utils.markup import Markup
from errands.utils.functions import get_children
from errands.utils.gsettings import GSettings


class Task(Gtk.Revealer):
Expand Down Expand Up @@ -122,23 +123,36 @@ def build_ui(self):
task_row_drop_target.connect("drop", self.on_drop)
self.task_row.add_controller(task_row_drop_target)
task_row_click_ctrl = Gtk.GestureClick.new()
task_row_click_ctrl.connect("released", self.on_details_clicked)
task_row_click_ctrl.connect("released", self.on_row_clicked)
self.task_row.add_controller(task_row_click_ctrl)
# Sub-tasks entry
sub_tasks_entry = Gtk.Entry(
hexpand=True,
margin_bottom=6,
margin_start=12,
margin_end=12,
placeholder_text=_("Add new Sub-Task"),
)
sub_tasks_entry.connect("activate", self.on_sub_task_added)
# Details panel button
details_btn = Gtk.Button(
icon_name="errands-info-symbolic",
tooltip_text=_("Details"),
margin_start=12
)
details_btn.connect("clicked", self.on_details_clicked)
GSettings.bind("primary-action-show-sub-tasks", details_btn, "visible")
sub_tasks_entry_box = Gtk.Box(
orientation="horizontal",
margin_bottom=6,
margin_start=12,
margin_end=12,
)
sub_tasks_entry_box.append(sub_tasks_entry)
sub_tasks_entry_box.append(details_btn)
# Sub-tasks
self.tasks_list = Box(orientation="vertical", css_classes=["sub-tasks"])
# Sub-tasks revealer
self.sub_tasks_revealer = Gtk.Revealer(
child=Box(
children=[sub_tasks_entry, self.tasks_list], orientation="vertical"
children=[sub_tasks_entry_box, self.tasks_list], orientation="vertical"
)
)
# Task card
Expand Down Expand Up @@ -280,6 +294,15 @@ def set_text():
self.task_list.update_status()
Sync.sync()

def on_row_clicked(self, *args):
# Show sub-tasks if this is primary action
if GSettings.get("primary-action-show-sub-tasks"):
self.expand(
not self.sub_tasks_revealer.get_child_revealed()
)
else:
self.on_details_clicked()

def on_details_clicked(self, *args):
# Close details on second click
if (
Expand Down

0 comments on commit 536ad33

Please sign in to comment.