Update list UI when details change

This commit is contained in:
Jeena 2024-03-15 16:03:50 +09:00
parent ed63ac8e78
commit 5fbcb03d73
6 changed files with 40 additions and 16 deletions

View file

@ -100,8 +100,10 @@ class JnotesApplication(Adw.Application):
def on_calendar_selected(self, container, row):
notes_list = self.props.active_window.notes_list
cal_row = self.calendar_set[row.get_index()]
self.props.active_window.notes_list_page.set_title(cal_row.displayname)
Sync.get_calenndar_notes(
self.calendar_set[row.get_index()],
cal_row,
lambda calendar: notes_list.set_calendar(calendar)
)

View file

@ -37,14 +37,12 @@ class NoteEdit(Gtk.ScrolledWindow):
@Gtk.Template.Callback()
def on_summary_changed(self, s):
pass
summary = s.get_text(s.get_start_iter(), s.get_end_iter(), False)
if self.note.summary != summary:
self.note.set_property("summary", summary)
@Gtk.Template.Callback()
def on_description_changed(self, d):
pass
description = d.get_text(d.get_start_iter(), d.get_end_iter(), False)
if self.note.description != description:
self.note.description = description
self.note.set_property("description", description)

View file

@ -104,6 +104,10 @@ class Sync():
callback(calendar)
class CalendarSet(Gio.ListStore):
def __init__(self):
super().__init__(item_type=Calendar)
def add_calendar(self, calendar):
self.append(calendar)
@ -111,22 +115,32 @@ class CalendarSet(Gio.ListStore):
self.remove(calendar)
class Calendar(Gio.ListStore):
__gtype_name__ = "Calendar"
displayname = None
cal_id = None
def __init__(self, displayname, cal_id):
super().__init__()
super().__init__(item_type=Note)
self.displayname = displayname
self.cal_id = cal_id
def add_note(self, note):
# Listen for changes in note to update the list UI
note.connect("notify::summary", self.on_notify_note_changed)
note.connect("notify::description", self.on_notify_note_changed)
self.append(note)
def on_notify_note_changed(self, note, gparamstring):
(found, position) = self.find(note)
if found:
self.items_changed(position, 1, 1)
class Note(GObject.GObject):
__gtype_name__ = "Note"
uid = None
calendar = None
summary = None
description = None
summary = GObject.property(type=str)
description = GObject.property(type=str)
def __init__(self, calendar, summary, description):
super().__init__()

View file

@ -5,7 +5,7 @@
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">24</property>
<property name="margin-top">-12</property>
<property name="margin-top">0</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
@ -21,7 +21,11 @@
<property name="right-margin">12</property>
<property name="wrap-mode">3</property>
<property name="css-classes">card</property>
<signal name="preedit-changed" handler="on_summary_changed" swapped="no" />
<property name="buffer">
<object class="GtkTextBuffer">
<signal name="changed" handler="on_summary_changed" swapped="no" />"
</object>
</property>
</object>"
</child>
</object>
@ -38,7 +42,11 @@
<property name="right-margin">12</property>
<property name="wrap-mode">3</property>
<property name="css-classes">card</property>
<signal name="preedit-changed" handler="on_description_changed" swapped="no" />
<property name="buffer">
<object class="GtkTextBuffer">
<signal name="changed" handler="on_description_changed" swapped="no" />"
</object>
</property>
</object>
</child>
</object>

View file

@ -35,16 +35,16 @@
</object>
</property>
<property name="content">
<object class="AdwNavigationPage">
<property name="title" translatable="yes">Note</property>
<object class="AdwNavigationPage" id="notes_list_page">
<property name="title" translatable="no">Notes</property>
<property name="child">
<object class="AdwOverlaySplitView" id="split_view2">
<object class="AdwOverlaySplitView">
<property name="sidebar-position">1</property>
<property name="content">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar" id="header_bar3">
<property name="show-title">False</property>
<object class="AdwHeaderBar">
<property name="show-title">True</property>
</object>
</child>
<property name="content">
@ -55,7 +55,7 @@
<property name="sidebar">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar" id="header_bar2">
<object class="AdwHeaderBar">
<property name="show-title">False</property>
</object>
</child>

View file

@ -26,10 +26,12 @@ class JnotesWindow(Adw.ApplicationWindow):
__gtype_name__ = 'JnotesWindow'
sidebar = Gtk.Template.Child()
notes_list_page = Gtk.Template.Child()
notes_list = Gtk.Template.Child()
note_edit = Gtk.Template.Child()
spinner = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)