event-editor: Improve event name validation handling
- Fix a bug where clicking the "Add Event" button created an empty title in the event editor dialog. - Add "error" class when the user writes an invalid event name. - Add new function to validate event name. Because the sections are split into files, the event editor will need a signal to check that each section is correct, and each section will have to emit the signal. This will need to be done in a future commit.
This commit is contained in:
@@ -773,6 +773,10 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
|
||||
g_object_add_weak_pointer (G_OBJECT (self->event_title_binding),
|
||||
(gpointer*) &self->event_title_binding);
|
||||
|
||||
/* change title when event name is empty */
|
||||
if (!gcal_is_valid_event_name (gtk_label_get_label (GTK_LABEL (self->title_label))))
|
||||
gtk_label_set_label (GTK_LABEL (self->title_label), _("New Event"));
|
||||
|
||||
gtk_label_set_label (GTK_LABEL (self->subtitle_label), gcal_calendar_get_name (calendar));
|
||||
self->selected_calendar = calendar;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-event-editor-section.h"
|
||||
#include "gcal-summary-section.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
@@ -61,7 +62,6 @@ gcal_reminders_section_set_event (GcalEventEditorSection *section,
|
||||
GcalEventEditorFlags flags)
|
||||
{
|
||||
GcalSummarySection *self;
|
||||
const gchar *summary;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
@@ -72,20 +72,25 @@ gcal_reminders_section_set_event (GcalEventEditorSection *section,
|
||||
if (!event)
|
||||
GCAL_RETURN ();
|
||||
|
||||
summary = gcal_event_get_summary (event);
|
||||
|
||||
if (g_strcmp0 (summary, "") == 0)
|
||||
gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), _("Unnamed event"));
|
||||
else
|
||||
gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), summary);
|
||||
|
||||
gtk_editable_set_text (GTK_EDITABLE (self->summary_entry), gcal_event_get_summary (event));
|
||||
gtk_editable_set_text (GTK_EDITABLE (self->location_entry), gcal_event_get_location (event));
|
||||
|
||||
adw_entry_row_grab_focus_without_selecting (self->summary_entry);
|
||||
|
||||
gtk_widget_remove_css_class (GTK_WIDGET (self->summary_entry), "error");
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
on_summary_entry_text_changed_cb (AdwEntryRow *entry_row)
|
||||
{
|
||||
if (gcal_is_valid_event_name (gtk_editable_get_text (GTK_EDITABLE (entry_row))))
|
||||
gtk_widget_remove_css_class (GTK_WIDGET (entry_row), "error");
|
||||
else
|
||||
gtk_widget_add_css_class (GTK_WIDGET (entry_row), "error");
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_reminders_section_apply (GcalEventEditorSection *section)
|
||||
{
|
||||
@@ -197,6 +202,8 @@ gcal_summary_section_class_init (GcalSummarySectionClass *klass)
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, location_entry);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalSummarySection, summary_entry);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_summary_entry_text_changed_cb);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<child>
|
||||
<object class="AdwEntryRow" id="summary_entry">
|
||||
<property name="title" translatable="yes">Title</property>
|
||||
<signal name="changed" handler="on_summary_entry_text_changed_cb" object="GcalSummarySection" swapped="no" />
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
||||
@@ -687,10 +687,7 @@ edit_or_create_event (GcalQuickAddPopover *self,
|
||||
}
|
||||
|
||||
/* Gather the summary */
|
||||
if (gtk_entry_get_text_length (GTK_ENTRY (self->summary_entry)) > 0)
|
||||
summary = gtk_editable_get_text (GTK_EDITABLE (self->summary_entry));
|
||||
else
|
||||
summary = _("Unnamed event");
|
||||
summary = gtk_editable_get_text (GTK_EDITABLE (self->summary_entry));
|
||||
|
||||
/* Create an ECalComponent from the data above */
|
||||
component = build_component_from_details (summary, date_start, date_end);
|
||||
@@ -717,14 +714,23 @@ summary_entry_text_changed (GtkEntry *entry,
|
||||
GParamSpec *pspec,
|
||||
GcalQuickAddPopover *self)
|
||||
{
|
||||
gtk_widget_set_sensitive (self->add_button, gtk_entry_get_text_length (entry) > 0);
|
||||
gboolean is_valid_event_name;
|
||||
|
||||
is_valid_event_name = gcal_is_valid_event_name (gtk_editable_get_text (GTK_EDITABLE (entry)));
|
||||
|
||||
if (is_valid_event_name)
|
||||
gtk_widget_remove_css_class (GTK_WIDGET (entry), "error");
|
||||
else
|
||||
gtk_widget_add_css_class (GTK_WIDGET (entry), "error");
|
||||
|
||||
gtk_widget_set_sensitive (self->add_button, is_valid_event_name);
|
||||
}
|
||||
|
||||
static void
|
||||
summary_entry_activated (GtkEntry *entry,
|
||||
GcalQuickAddPopover *self)
|
||||
{
|
||||
if (gtk_entry_get_text_length (entry) > 0)
|
||||
if (gcal_is_valid_event_name (gtk_editable_get_text (GTK_EDITABLE (entry))))
|
||||
edit_or_create_event (self, self->add_button);
|
||||
}
|
||||
|
||||
@@ -828,6 +834,9 @@ gcal_quick_add_popover_closed (GtkPopover *popover)
|
||||
/* Select the default row again */
|
||||
update_default_calendar_row (self);
|
||||
|
||||
/* Remove "error" class */
|
||||
gtk_widget_remove_css_class (self->summary_entry, "error");
|
||||
|
||||
g_clear_pointer (&self->range, gcal_range_unref);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user