event-editor/notes-section: Subclass GcalEventEditorSection
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/711>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
using Gtk 4.0;
|
using Gtk 4.0;
|
||||||
using Adw 1;
|
using Adw 1;
|
||||||
|
|
||||||
template $GcalNotesSection: Adw.PreferencesGroup {
|
template $GcalNotesSection: $GcalEventEditorSection {
|
||||||
styles [
|
styles [
|
||||||
"notes-section",
|
"notes-section",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -21,19 +21,17 @@
|
|||||||
#define G_LOG_DOMAIN "GcalNotesSection"
|
#define G_LOG_DOMAIN "GcalNotesSection"
|
||||||
|
|
||||||
#include "gcal-debug.h"
|
#include "gcal-debug.h"
|
||||||
#include "gcal-event-editor-dialog.h"
|
|
||||||
#include "gcal-event-editor-section.h"
|
|
||||||
#include "gcal-notes-section.h"
|
#include "gcal-notes-section.h"
|
||||||
|
|
||||||
struct _GcalNotesSection
|
struct _GcalNotesSection
|
||||||
{
|
{
|
||||||
AdwPreferencesGroup parent;
|
GcalEventEditorSection parent;
|
||||||
|
|
||||||
GtkTextView *notes_text;
|
GtkTextView *notes_text;
|
||||||
GtkLabel *placeholder;
|
GtkLabel *placeholder;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_FINAL_TYPE (GcalNotesSection, gcal_notes_section, ADW_TYPE_PREFERENCES_GROUP)
|
G_DEFINE_FINAL_TYPE (GcalNotesSection, gcal_notes_section, GCAL_TYPE_EVENT_EDITOR_SECTION)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Callbacks
|
* Callbacks
|
||||||
@@ -45,14 +43,9 @@ on_notes_text_changed_cb (GcalNotesSection *self)
|
|||||||
g_autofree char *text = NULL;
|
g_autofree char *text = NULL;
|
||||||
GtkTextIter start, end;
|
GtkTextIter start, end;
|
||||||
GtkTextBuffer *buffer;
|
GtkTextBuffer *buffer;
|
||||||
GtkWidget *dialog;
|
|
||||||
GcalEvent *event;
|
GcalEvent *event;
|
||||||
|
|
||||||
dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
event = gcal_event_editor_section_get_event (GCAL_EVENT_EDITOR_SECTION (self));
|
||||||
|
|
||||||
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
|
||||||
|
|
||||||
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
|
||||||
|
|
||||||
buffer = gtk_text_view_get_buffer (self->notes_text);
|
buffer = gtk_text_view_get_buffer (self->notes_text);
|
||||||
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
||||||
@@ -101,56 +94,28 @@ on_row_pressed (GtkGestureClick *gesture,
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GtkWidget overrides
|
* GcalEventEditorSection overrides
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcal_notes_section_map (GtkWidget *widget)
|
gcal_notes_section_event_set_cb (GcalEventEditorSection *section,
|
||||||
|
GcalEvent *event)
|
||||||
{
|
{
|
||||||
GcalNotesSection *self = GCAL_NOTES_SECTION (widget);
|
GcalNotesSection *self = GCAL_NOTES_SECTION (section);
|
||||||
GtkTextBuffer *buffer;
|
|
||||||
GtkWidget *dialog;
|
|
||||||
GcalEvent *event;
|
|
||||||
|
|
||||||
dialog = gtk_widget_get_ancestor (widget, GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
|
||||||
|
|
||||||
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
|
||||||
|
|
||||||
event = gcal_event_editor_dialog_get_event (GCAL_EVENT_EDITOR_DIALOG (dialog));
|
|
||||||
|
|
||||||
buffer = gtk_text_view_get_buffer (self->notes_text);
|
|
||||||
|
|
||||||
g_signal_handlers_block_by_func (buffer, on_notes_text_changed_cb, self);
|
|
||||||
|
|
||||||
gtk_text_buffer_set_text (buffer, gcal_event_get_description (event), -1);
|
|
||||||
|
|
||||||
g_signal_handlers_unblock_by_func (buffer, on_notes_text_changed_cb, self);
|
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (gcal_notes_section_parent_class)->map (widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gcal_notes_section_unmap (GtkWidget *widget)
|
|
||||||
{
|
|
||||||
GcalNotesSection *self = GCAL_NOTES_SECTION (widget);
|
|
||||||
GtkTextIter start, end;
|
GtkTextIter start, end;
|
||||||
GtkTextBuffer *buffer;
|
GtkTextBuffer *buffer;
|
||||||
GtkWidget *dialog;
|
|
||||||
|
|
||||||
dialog = gtk_widget_get_ancestor (widget, GCAL_TYPE_EVENT_EDITOR_DIALOG);
|
|
||||||
|
|
||||||
g_assert (GCAL_IS_EVENT_EDITOR_DIALOG (dialog));
|
|
||||||
|
|
||||||
buffer = gtk_text_view_get_buffer (self->notes_text);
|
buffer = gtk_text_view_get_buffer (self->notes_text);
|
||||||
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
||||||
|
|
||||||
g_signal_handlers_block_by_func (buffer, on_notes_text_changed_cb, self);
|
g_signal_handlers_block_by_func (buffer, on_notes_text_changed_cb, self);
|
||||||
|
|
||||||
gtk_text_buffer_delete (buffer, &start, &end);
|
if (event)
|
||||||
|
gtk_text_buffer_set_text (buffer, gcal_event_get_description (event), -1);
|
||||||
|
else
|
||||||
|
gtk_text_buffer_delete (buffer, &start, &end);
|
||||||
|
|
||||||
g_signal_handlers_unblock_by_func (buffer, on_notes_text_changed_cb, self);
|
g_signal_handlers_unblock_by_func (buffer, on_notes_text_changed_cb, self);
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (gcal_notes_section_parent_class)->unmap (widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -162,9 +127,9 @@ static void
|
|||||||
gcal_notes_section_class_init (GcalNotesSectionClass *klass)
|
gcal_notes_section_class_init (GcalNotesSectionClass *klass)
|
||||||
{
|
{
|
||||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
GcalEventEditorSectionClass *section_class = GCAL_EVENT_EDITOR_SECTION_CLASS (klass);
|
||||||
|
|
||||||
widget_class->map = gcal_notes_section_map;
|
section_class->event_set_cb = gcal_notes_section_event_set_cb;
|
||||||
widget_class->unmap = gcal_notes_section_unmap;
|
|
||||||
|
|
||||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-notes-section.ui");
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-notes-section.ui");
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,11 @@
|
|||||||
|
|
||||||
#include <adwaita.h>
|
#include <adwaita.h>
|
||||||
|
|
||||||
|
#include "gcal-event-editor-section.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GCAL_TYPE_NOTES_SECTION (gcal_notes_section_get_type())
|
#define GCAL_TYPE_NOTES_SECTION (gcal_notes_section_get_type())
|
||||||
G_DECLARE_FINAL_TYPE (GcalNotesSection, gcal_notes_section, GCAL, NOTES_SECTION, AdwPreferencesGroup)
|
G_DECLARE_FINAL_TYPE (GcalNotesSection, gcal_notes_section, GCAL, NOTES_SECTION, GcalEventEditorSection)
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
Reference in New Issue
Block a user