event-editor-dialog: Move notes to GcalNotesSection
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<file compressed="true">gcal-date-selector.ui</file>
|
||||
<file compressed="true">gcal-event-editor-dialog.ui</file>
|
||||
<file compressed="true">gcal-multi-choice.ui</file>
|
||||
<file compressed="true">gcal-notes-section.ui</file>
|
||||
<file compressed="true">gcal-reminders-section.ui</file>
|
||||
<file compressed="true">gcal-schedule-section.ui</file>
|
||||
<file compressed="true">gcal-summary-section.ui</file>
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "gcal-event-editor-section.h"
|
||||
#include "gcal-utils.h"
|
||||
#include "gcal-event.h"
|
||||
#include "gcal-notes-section.h"
|
||||
#include "gcal-reminders-section.h"
|
||||
#include "gcal-schedule-section.h"
|
||||
#include "gcal-summary-section.h"
|
||||
@@ -64,6 +65,7 @@ struct _GcalEventEditorDialog
|
||||
GcalEventEditorSection *reminders_section;
|
||||
GcalEventEditorSection *schedule_section;
|
||||
GcalEventEditorSection *summary_section;
|
||||
GcalEventEditorSection *notes_section;
|
||||
|
||||
GtkWidget *lock;
|
||||
GtkWidget *source_image;
|
||||
@@ -75,8 +77,6 @@ struct _GcalEventEditorDialog
|
||||
GtkWidget *sources_button;
|
||||
GtkWidget *sources_popover;
|
||||
|
||||
GtkWidget *notes_text;
|
||||
|
||||
GBinding *event_title_binding;
|
||||
|
||||
/* actions */
|
||||
@@ -206,26 +206,10 @@ set_writable (GcalEventEditorDialog *self,
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WRITABLE]);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_event_editor_dialog_clear_data (GcalEventEditorDialog *self)
|
||||
{
|
||||
/* notes */
|
||||
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->notes_text)), "", -1);
|
||||
}
|
||||
|
||||
static void
|
||||
apply_changes_to_event (GcalEventEditorDialog *self)
|
||||
{
|
||||
gchar *note_text;
|
||||
|
||||
/* Update description */
|
||||
g_object_get (G_OBJECT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->notes_text))),
|
||||
"text", ¬e_text,
|
||||
NULL);
|
||||
|
||||
gcal_event_set_description (self->event, note_text);
|
||||
g_free (note_text);
|
||||
|
||||
gcal_event_editor_section_apply (self->notes_section);
|
||||
gcal_event_editor_section_apply (self->reminders_section);
|
||||
gcal_event_editor_section_apply (self->schedule_section);
|
||||
gcal_event_editor_section_apply (self->summary_section);
|
||||
@@ -479,6 +463,7 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
g_type_ensure (GCAL_TYPE_NOTES_SECTION);
|
||||
g_type_ensure (GCAL_TYPE_REMINDERS_SECTION);
|
||||
g_type_ensure (GCAL_TYPE_SCHEDULE_SECTION);
|
||||
g_type_ensure (GCAL_TYPE_SUMMARY_SECTION);
|
||||
@@ -531,7 +516,6 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, delete_button);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, sources_button);
|
||||
/* Other */
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, notes_text);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, titlebar);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, title_label);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, subtitle_label);
|
||||
@@ -539,6 +523,7 @@ gcal_event_editor_dialog_class_init (GcalEventEditorDialogClass *klass)
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, scrolled_window);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, source_image);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, sources_popover);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, notes_section);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, reminders_section);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, schedule_section);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalEventEditorDialog, summary_section);
|
||||
@@ -556,6 +541,7 @@ gcal_event_editor_dialog_init (GcalEventEditorDialog *self)
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
g_object_bind_property (self, "context", self->notes_section, "context", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "context", self->reminders_section, "context", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "context", self->schedule_section, "context", G_BINDING_DEFAULT);
|
||||
g_object_bind_property (self, "context", self->summary_section, "context", G_BINDING_DEFAULT);
|
||||
@@ -641,9 +627,6 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
|
||||
|
||||
calendar = gcal_event_get_calendar (cloned_event);
|
||||
|
||||
/* Clear event data */
|
||||
gcal_event_editor_dialog_clear_data (self);
|
||||
|
||||
/* update sources list */
|
||||
if (self->sources_menu != NULL)
|
||||
g_menu_remove_all (self->sources_menu);
|
||||
@@ -670,11 +653,6 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
|
||||
/* recurrence_changed */
|
||||
self->recurrence_changed = FALSE;
|
||||
|
||||
/* notes */
|
||||
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->notes_text)),
|
||||
gcal_event_get_description (cloned_event),
|
||||
-1);
|
||||
|
||||
set_writable (self, !gcal_calendar_is_read_only (calendar));
|
||||
|
||||
out:
|
||||
@@ -683,6 +661,7 @@ out:
|
||||
if (self->event_is_new)
|
||||
flags |= GCAL_EVENT_EDITOR_FLAG_NEW_EVENT;
|
||||
|
||||
gcal_event_editor_section_set_event (self->notes_section, cloned_event, flags);
|
||||
gcal_event_editor_section_set_event (self->reminders_section, cloned_event, flags);
|
||||
gcal_event_editor_section_set_event (self->schedule_section, cloned_event, flags);
|
||||
gcal_event_editor_section_set_event (self->summary_section, cloned_event, flags);
|
||||
|
||||
@@ -206,31 +206,12 @@
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="min_content_height">120</property>
|
||||
<object class="GcalNotesSection" id="notes_section">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTextView" id="notes_text">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="top_margin">6</property>
|
||||
<property name="bottom_margin">6</property>
|
||||
<property name="left_margin">6</property>
|
||||
<property name="right_margin">6</property>
|
||||
<property name="sensitive">True</property>
|
||||
<property name="editable" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
|
||||
<property name="cursor_visible" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
|
||||
<property name="wrap_mode">GTK_WRAP_WORD_CHAR</property>
|
||||
</object>
|
||||
</child>
|
||||
<property name="sensitive" bind-source="GcalEventEditorDialog" bind-property="writable" bind-flags="default" />
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
||||
<!-- Delete Button -->
|
||||
<child>
|
||||
<object class="GtkButton" id="delete_button">
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/* gcal-notes-section.c
|
||||
*
|
||||
* Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "GcalNotesSection"
|
||||
|
||||
#include "gcal-context.h"
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-event-editor-section.h"
|
||||
#include "gcal-notes-section.h"
|
||||
|
||||
struct _GcalNotesSection
|
||||
{
|
||||
GtkBin parent;
|
||||
|
||||
GtkTextView *notes_text;
|
||||
|
||||
GcalContext *context;
|
||||
GcalEvent *event;
|
||||
};
|
||||
|
||||
static void gcal_event_editor_section_iface_init (GcalEventEditorSectionInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GcalNotesSection, gcal_notes_section, GTK_TYPE_BIN,
|
||||
G_IMPLEMENT_INTERFACE (GCAL_TYPE_EVENT_EDITOR_SECTION, gcal_event_editor_section_iface_init))
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONTEXT,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
/*
|
||||
* GcalEventEditorSection interface
|
||||
*/
|
||||
|
||||
static void
|
||||
gcal_notes_section_set_event (GcalEventEditorSection *section,
|
||||
GcalEvent *event,
|
||||
GcalEventEditorFlags flags)
|
||||
{
|
||||
GcalNotesSection *self;
|
||||
GtkTextBuffer *buffer;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
self = GCAL_NOTES_SECTION (section);
|
||||
|
||||
g_set_object (&self->event, event);
|
||||
|
||||
if (!event)
|
||||
GCAL_RETURN ();
|
||||
|
||||
buffer = gtk_text_view_get_buffer (self->notes_text);
|
||||
gtk_text_buffer_set_text (buffer, gcal_event_get_description (event), -1);
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_notes_section_apply (GcalEventEditorSection *section)
|
||||
{
|
||||
g_autofree gchar *note_text = NULL;
|
||||
GcalNotesSection *self;
|
||||
GtkTextBuffer *buffer;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
self = GCAL_NOTES_SECTION (section);
|
||||
|
||||
/* Update description */
|
||||
buffer = gtk_text_view_get_buffer (self->notes_text);
|
||||
g_object_get (G_OBJECT (buffer), "text", ¬e_text, NULL);
|
||||
|
||||
gcal_event_set_description (self->event, note_text);
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_event_editor_section_iface_init (GcalEventEditorSectionInterface *iface)
|
||||
{
|
||||
iface->set_event = gcal_notes_section_set_event;
|
||||
iface->apply = gcal_notes_section_apply;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GObject overrides
|
||||
*/
|
||||
|
||||
static void
|
||||
gcal_notes_section_finalize (GObject *object)
|
||||
{
|
||||
GcalNotesSection *self = (GcalNotesSection *)object;
|
||||
|
||||
g_clear_object (&self->context);
|
||||
g_clear_object (&self->event);
|
||||
|
||||
G_OBJECT_CLASS (gcal_notes_section_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_notes_section_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalNotesSection *self = GCAL_NOTES_SECTION (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_value_set_object (value, self->context);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_notes_section_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalNotesSection *self = GCAL_NOTES_SECTION (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_assert (self->context == NULL);
|
||||
self->context = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_notes_section_class_init (GcalNotesSectionClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->finalize = gcal_notes_section_finalize;
|
||||
object_class->get_property = gcal_notes_section_get_property;
|
||||
object_class->set_property = gcal_notes_section_set_property;
|
||||
|
||||
g_object_class_override_property (object_class, PROP_CONTEXT, "context");
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-notes-section.ui");
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalNotesSection, notes_text);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_notes_section_init (GcalNotesSection *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* gcal-notes-section.h
|
||||
*
|
||||
* Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_NOTES_SECTION (gcal_notes_section_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GcalNotesSection, gcal_notes_section, GCAL, NOTES_SECTION, GtkBin)
|
||||
|
||||
G_END_DECLS
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="GcalNotesSection" parent="GtkBin">
|
||||
<property name="can_focus">False</property>
|
||||
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="min_content_height">120</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTextView" id="notes_text">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="top_margin">6</property>
|
||||
<property name="bottom_margin">6</property>
|
||||
<property name="left_margin">6</property>
|
||||
<property name="right_margin">6</property>
|
||||
<property name="sensitive">True</property>
|
||||
<property name="wrap_mode">word-char</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</template>
|
||||
</interface>
|
||||
@@ -14,6 +14,7 @@ sources += files(
|
||||
'gcal-event-editor-dialog.c',
|
||||
'gcal-event-editor-section.c',
|
||||
'gcal-multi-choice.c',
|
||||
'gcal-notes-section.c',
|
||||
'gcal-reminders-section.c',
|
||||
'gcal-schedule-section.c',
|
||||
'gcal-summary-section.c',
|
||||
|
||||
Reference in New Issue
Block a user