From d451318029d4bbf2b649f81f70814b84213f40b4 Mon Sep 17 00:00:00 2001 From: Jeena Date: Mon, 19 Feb 2024 08:56:38 +0900 Subject: [PATCH] Add note edit window --- src/jnotes.gresource.xml | 1 + src/main.py | 11 ++++++++++- src/meson.build | 1 + src/note_edit.py | 40 ++++++++++++++++++++++++++++++++++++++++ src/notes_list.py | 7 ++++--- src/ui/note_edit.ui | 25 +++++++++++++++++++++++++ src/ui/notes_list.ui | 1 - src/ui/window.ui | 2 +- 8 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 src/note_edit.py create mode 100644 src/ui/note_edit.ui diff --git a/src/jnotes.gresource.xml b/src/jnotes.gresource.xml index 0f6b80e..e9488f4 100644 --- a/src/jnotes.gresource.xml +++ b/src/jnotes.gresource.xml @@ -6,5 +6,6 @@ ui/help-overlay.ui ui/sidebar.ui ui/notes_list.ui + ui/note_edit.ui diff --git a/src/main.py b/src/main.py index 10a8b4b..5011300 100644 --- a/src/main.py +++ b/src/main.py @@ -29,6 +29,7 @@ from .preferences import PreferencesWindow from .sidebar import Sidebar from .sync import Sync from .notes_list import NotesList +from .note_edit import NoteEditWindow class JnotesApplication(Adw.Application): @@ -36,7 +37,6 @@ class JnotesApplication(Adw.Application): calendar_set = None - def __init__(self): super().__init__(application_id='net.jeena.jnotes', flags=Gio.ApplicationFlags.DEFAULT_FLAGS) @@ -54,6 +54,7 @@ class JnotesApplication(Adw.Application): if not win: win = JnotesWindow(application=self) win.sidebar.calendar_set.connect('row-selected', self.on_calendar_selected) + win.notes_list.notes_list.connect('row-selected', self.on_note_selected) win.present() def callback(calendar_set): @@ -104,6 +105,14 @@ class JnotesApplication(Adw.Application): lambda calendar: notes_list.set_calendar(calendar) ) + def on_note_selected(self, container, row): + calendar = self.props.active_window.notes_list.calendar + note = calendar[row.get_index()] + edit_dialog = NoteEditWindow(transient_for=self.props.active_window) + edit_dialog.set_note(note) + edit_dialog.present() + + def main(version): """The application's entry point.""" app = JnotesApplication() diff --git a/src/meson.build b/src/meson.build index 5f883ca..84a5ddc 100644 --- a/src/meson.build +++ b/src/meson.build @@ -35,6 +35,7 @@ jnotes_sources = [ 'sync.py', 'sidebar.py', 'notes_list.py', + 'note_edit.py', ] install_data(jnotes_sources, install_dir: moduledir) diff --git a/src/note_edit.py b/src/note_edit.py new file mode 100644 index 0000000..94c438f --- /dev/null +++ b/src/note_edit.py @@ -0,0 +1,40 @@ +# note_edit.py +# +# Copyright 2024 Jeena +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from gi.repository import Adw +from gi.repository import Gtk + +@Gtk.Template(resource_path='/net/jeena/jnotes/ui/note_edit.ui') +class NoteEditWindow(Adw.Window): + __gtype_name__ = 'NoteEditWindow' + + summary = Gtk.Template.Child() + description = Gtk.Template.Child() + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + def set_note(self, note): + self.note = note + self.summary.set_text(self.note.summary) + buffer = self.description.get_buffer() + buffer.set_text(self.note.description) + + def on_save_button_pressed(self, widget): + print("save button pressed") diff --git a/src/notes_list.py b/src/notes_list.py index 8478eb9..a43cb7e 100644 --- a/src/notes_list.py +++ b/src/notes_list.py @@ -8,14 +8,15 @@ class NotesList(Gtk.ScrolledWindow): __gtype_name__ = 'NotesList' notes_list = Gtk.Template.Child() + calendar = None def __init__(self, **kwargs): super().__init__(**kwargs) def set_calendar(self, calendar): - self.notes_list.bind_model(calendar, self.create_item_widget) + self.calendar = calendar + self.notes_list.bind_model(self.calendar, self.create_item_widget) def create_item_widget(self, note): - return Adw.ActionRow(title=note.summary, - subtitle=note.description) + return Adw.ActionRow(title=note.summary, subtitle=note.description) diff --git a/src/ui/note_edit.ui b/src/ui/note_edit.ui new file mode 100644 index 0000000..06752d5 --- /dev/null +++ b/src/ui/note_edit.ui @@ -0,0 +1,25 @@ + + + + diff --git a/src/ui/notes_list.ui b/src/ui/notes_list.ui index a225633..d229c7b 100644 --- a/src/ui/notes_list.ui +++ b/src/ui/notes_list.ui @@ -15,7 +15,6 @@ True - none diff --git a/src/ui/window.ui b/src/ui/window.ui index b6d534f..d629be2 100644 --- a/src/ui/window.ui +++ b/src/ui/window.ui @@ -23,7 +23,7 @@