[gnome-calendar/gbsneto/edit-dialog-cleanup: 2/7] event-editor-dialog: Unify set_event and set_event_is_new




commit ce54bb71648213cfcce1616b83a386c02020bedf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Oct 31 14:45:38 2020 -0300

    event-editor-dialog: Unify set_event and set_event_is_new
    
    The split is annoying, and a relic of time.

 src/gui/event-editor/gcal-event-editor-dialog.c | 29 +++++++------------------
 src/gui/event-editor/gcal-event-editor-dialog.h |  6 ++---
 src/gui/gcal-window.c                           | 14 ++++--------
 3 files changed, 14 insertions(+), 35 deletions(-)
---
diff --git a/src/gui/event-editor/gcal-event-editor-dialog.c b/src/gui/event-editor/gcal-event-editor-dialog.c
index 34d88a48..18840af9 100644
--- a/src/gui/event-editor/gcal-event-editor-dialog.c
+++ b/src/gui/event-editor/gcal-event-editor-dialog.c
@@ -208,7 +208,7 @@ set_writable (GcalEventEditorDialog *self,
 static void
 clear_and_hide_dialog (GcalEventEditorDialog *self)
 {
-  gcal_event_editor_dialog_set_event (self, NULL);
+  gcal_event_editor_dialog_set_event (self, NULL, FALSE);
   gtk_widget_hide (GTK_WIDGET (self));
 }
 
@@ -459,7 +459,7 @@ gcal_event_editor_dialog_set_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_EVENT:
-      gcal_event_editor_dialog_set_event (self, g_value_get_object (value));
+      gcal_event_editor_dialog_set_event (self, g_value_get_object (value), FALSE);
       break;
 
     case PROP_CONTEXT:
@@ -593,23 +593,6 @@ gcal_event_editor_dialog_new (void)
   return g_object_new (GCAL_TYPE_EVENT_EDITOR_DIALOG, NULL);
 }
 
-/**
- * gcal_event_editor_dialog_set_event_is_new:
- * @dialog: a #GcalDialog
- * @event_is_new: %TRUE if the event is new, %FALSE otherwise
- *
- * Sets whether the currently edited event is a new event, or not.
- * The @dialog will adapt it's UI elements to reflect that.
- */
-void
-gcal_event_editor_dialog_set_event_is_new (GcalEventEditorDialog *self,
-                                           gboolean               event_is_new)
-{
-  self->event_is_new = event_is_new;
-
-  gtk_widget_set_visible (self->delete_button, !event_is_new);
-}
-
 /**
  * gcal_event_editor_dialog_set_event:
  * @dialog: a #GcalDialog
@@ -620,7 +603,8 @@ gcal_event_editor_dialog_set_event_is_new (GcalEventEditorDialog *self,
  */
 void
 gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
-                                    GcalEvent             *event)
+                                    GcalEvent             *event,
+                                    gboolean               new_event)
 {
   g_autoptr (GcalEvent) cloned_event = NULL;
   GcalEventEditorFlags flags;
@@ -671,10 +655,13 @@ gcal_event_editor_dialog_set_event (GcalEventEditorDialog *self,
 
   set_writable (self, !gcal_calendar_is_read_only (calendar));
 
+  self->event_is_new = new_event;
+  gtk_widget_set_visible (self->delete_button, !new_event);
+
 out:
   flags = GCAL_EVENT_EDITOR_FLAG_NONE;
 
-  if (self->event_is_new)
+  if (new_event)
     flags |= GCAL_EVENT_EDITOR_FLAG_NEW_EVENT;
 
   for (i = 0; i < G_N_ELEMENTS (self->sections); i++)
diff --git a/src/gui/event-editor/gcal-event-editor-dialog.h b/src/gui/event-editor/gcal-event-editor-dialog.h
index 16c16d1f..3b574b7f 100644
--- a/src/gui/event-editor/gcal-event-editor-dialog.h
+++ b/src/gui/event-editor/gcal-event-editor-dialog.h
@@ -30,10 +30,8 @@ G_DECLARE_FINAL_TYPE (GcalEventEditorDialog, gcal_event_editor_dialog, GCAL, EVE
 
 GtkWidget*           gcal_event_editor_dialog_new                (void);
 
-void                 gcal_event_editor_dialog_set_event_is_new   (GcalEventEditorDialog *dialog,
-                                                                  gboolean               event_is_new);
-
 void                 gcal_event_editor_dialog_set_event          (GcalEventEditorDialog *self,
-                                                                  GcalEvent             *event);
+                                                                  GcalEvent             *event,
+                                                                  gboolean               new_event);
 
 G_END_DECLS
diff --git a/src/gui/gcal-window.c b/src/gui/gcal-window.c
index 493295d6..a7e59afb 100644
--- a/src/gui/gcal-window.c
+++ b/src/gui/gcal-window.c
@@ -392,8 +392,7 @@ on_window_new_event_cb (GSimpleAction *action,
   default_calendar = gcal_manager_get_default_calendar (manager);
   event = gcal_event_new (default_calendar, comp, NULL);
 
-  gcal_event_editor_dialog_set_event_is_new (GCAL_EVENT_EDITOR_DIALOG (self->event_editor), TRUE);
-  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (self->event_editor), event);
+  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (self->event_editor), event, TRUE);
 
   gtk_widget_show (self->event_editor);
 }
@@ -610,9 +609,7 @@ edit_event (GcalQuickAddPopover *popover,
             GcalEvent           *event,
             GcalWindow          *window)
 {
-  gcal_event_editor_dialog_set_event_is_new (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), TRUE);
-  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), event);
-
+  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), event, TRUE);
   gtk_widget_show (window->event_editor);
 }
 
@@ -633,9 +630,7 @@ create_event_detailed_cb (GcalView *view,
   default_calendar = gcal_manager_get_default_calendar (manager);
   event = gcal_event_new (default_calendar, comp, NULL);
 
-  gcal_event_editor_dialog_set_event_is_new (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), TRUE);
-  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), event);
-
+  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), event, TRUE);
   gtk_widget_show (window->event_editor);
 
   g_clear_object (&comp);
@@ -650,8 +645,7 @@ event_activated (GcalView        *view,
   GcalEvent *event;
 
   event = gcal_event_widget_get_event (event_widget);
-  gcal_event_editor_dialog_set_event_is_new (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), FALSE);
-  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), event);
+  gcal_event_editor_dialog_set_event (GCAL_EVENT_EDITOR_DIALOG (window->event_editor), event, FALSE);
 
   gtk_widget_show (window->event_editor);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]