Replace Notes window with sidebar

This commit is contained in:
Jeena 2024-03-01 16:57:22 +09:00
parent 595c456518
commit c0d9da7947
5 changed files with 53 additions and 23 deletions

View file

@ -29,7 +29,7 @@ from .preferences import PreferencesWindow
from .sidebar import Sidebar from .sidebar import Sidebar
from .sync import Sync from .sync import Sync
from .notes_list import NotesList from .notes_list import NotesList
from .note_edit import NoteEditWindow from .note_edit import NoteEdit
class JnotesApplication(Adw.Application): class JnotesApplication(Adw.Application):
@ -108,10 +108,7 @@ class JnotesApplication(Adw.Application):
def on_note_selected(self, container, row): def on_note_selected(self, container, row):
calendar = self.props.active_window.notes_list.calendar calendar = self.props.active_window.notes_list.calendar
note = calendar[row.get_index()] note = calendar[row.get_index()]
edit_dialog = NoteEditWindow(transient_for=self.props.active_window) self.props.active_window.note_edit.set_note(note)
edit_dialog.set_note(note)
edit_dialog.present()
def main(version): def main(version):
"""The application's entry point.""" """The application's entry point."""

View file

@ -21,8 +21,8 @@ from gi.repository import Adw
from gi.repository import Gtk from gi.repository import Gtk
@Gtk.Template(resource_path='/net/jeena/jnotes/ui/note_edit.ui') @Gtk.Template(resource_path='/net/jeena/jnotes/ui/note_edit.ui')
class NoteEditWindow(Adw.Window): class NoteEdit(Gtk.ScrolledWindow):
__gtype_name__ = 'NoteEditWindow' __gtype_name__ = 'NoteEdit'
summary = Gtk.Template.Child() summary = Gtk.Template.Child()
description = Gtk.Template.Child() description = Gtk.Template.Child()
@ -32,9 +32,8 @@ class NoteEditWindow(Adw.Window):
def set_note(self, note): def set_note(self, note):
self.note = note self.note = note
self.summary.set_text(self.note.summary) self.summary.get_buffer().set_text(self.note.summary)
buffer = self.description.get_buffer() self.description.get_buffer().set_text(self.note.description)
buffer.set_text(self.note.description)
def on_save_button_pressed(self, widget): def on_save_button_pressed(self, widget):
print("save button pressed") print("save button pressed")

View file

@ -1,22 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<template class="NoteEditWindow" parent="AdwWindow"> <template class="NoteEdit" parent="GtkScrolledWindow">
<property name="title" translatable="yes">Notes</property> <property name="child">
<property name="width-request">400</property>
<property name="height-request">400</property>
<property name="content">
<object class="GtkBox"> <object class="GtkBox">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">24</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<child> <child>
<object class="GtkHeaderBar"/> <object class="AdwPreferencesGroup">
<property name="title">Summary</property>
<child>
<object class="GtkTextView" id="summary">
<property name="height-request">42</property>
<property name="top-margin">12</property>
<property name="bottom-margin">12</property>
<property name="left-margin">12</property>
<property name="right-margin">12</property>
<property name="wrap-mode">3</property>
<property name="css-classes">card</property>
</object>"
</child>
</object>
</child> </child>
<child> <child>
<object class="GtkEntry" id="summary"></object> <object class="AdwPreferencesGroup">
</child> <property name="title">Description</property>
<child> <child>
<object class="GtkTextView" id="description"> <object class="GtkTextView" id="description">
<property name="width-request">100%</property> <property name="height-request">200</property>
<property name="height-request">100%</property> <property name="top-margin">12</property>
<property name="bottom-margin">12</property>
<property name="left-margin">12</property>
<property name="right-margin">12</property>
<property name="wrap-mode">3</property>
<property name="css-classes">card</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>

View file

@ -56,7 +56,18 @@
</object> </object>
</child> </child>
<property name="content"> <property name="content">
<object class="NotesList" id="notes_list"></object> <object class="AdwOverlaySplitView" id="content_split_view">
<property name="min-sidebar-width">200</property>
<property name="max-sidebar-width">400</property>
<property name="sidebar-width-fraction">0.40</property>
<property name="sidebar-position">1</property>
<property name="content">
<object class="NotesList" id="notes_list"></object>
</property>
<property name="sidebar">
<object class="NoteEdit" id="note_edit"></object>
</property>
</object>
</property> </property>
</object> </object>
</property> </property>

View file

@ -27,6 +27,7 @@ class JnotesWindow(Adw.ApplicationWindow):
sidebar = Gtk.Template.Child() sidebar = Gtk.Template.Child()
notes_list = Gtk.Template.Child() notes_list = Gtk.Template.Child()
note_edit = Gtk.Template.Child()
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)