[recipes] Don't show a dialog when one is already shown
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Don't show a dialog when one is already shown
- Date: Thu, 9 Feb 2017 23:55:38 +0000 (UTC)
commit 977136e334701685bcb2c6f616b9d6f8d0ae725f
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Wed Feb 8 20:50:48 2017 +0530
Don't show a dialog when one is already shown
The dialog windows can pile up each time chef information
was clicked in applicaton menu.
So, instead of always creating a new dialog, check if there is already one,
and create only if there is none.
https://bugzilla.gnome.org/show_bug.cgi?id=778340
We also take this opportunity to fix a few details in
the chef dialog: Always emit the done signal when the
dialog is dismissed, and leave the destruction of the
dialog to the outside code that created the dialog in
the first place.
src/gr-app.c | 19 ++-----------------
src/gr-chef-dialog.c | 4 ++--
src/gr-edit-page.c | 10 ++++++----
src/gr-window.c | 38 ++++++++++++++++++++++++++++++++++++++
src/gr-window.h | 2 ++
5 files changed, 50 insertions(+), 23 deletions(-)
---
diff --git a/src/gr-app.c b/src/gr-app.c
index 79cd0bb..aac8a1a 100644
--- a/src/gr-app.c
+++ b/src/gr-app.c
@@ -72,26 +72,11 @@ chef_information_activated (GSimpleAction *action,
GVariant *parameter,
gpointer app)
{
- GrRecipeStore *store;
- const char *id;
- g_autoptr(GrChef) chef = NULL;
- GrChefDialog *dialog;
GtkWindow *win;
- store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
-
- id = gr_recipe_store_get_user_key (store);
-
- if (id != NULL && id[0] != '\0')
- chef = gr_recipe_store_get_chef (store, id);
- else
- chef = gr_chef_new ();
-
win = gtk_application_get_active_window (GTK_APPLICATION (app));
- dialog = gr_chef_dialog_new (win, chef);
- gr_chef_dialog_can_create (dialog, FALSE);
- gtk_window_set_title (GTK_WINDOW (dialog), _("My Chef Information"));
- gtk_window_present (GTK_WINDOW (dialog));
+
+ gr_window_show_my_chef_information (GR_WINDOW (win));
}
static GtkWidget *
diff --git a/src/gr-chef-dialog.c b/src/gr-chef-dialog.c
index af437db..2228434 100644
--- a/src/gr-chef-dialog.c
+++ b/src/gr-chef-dialog.c
@@ -31,6 +31,7 @@
#include "gr-chef.h"
#include "gr-recipe-store.h"
#include "gr-app.h"
+#include "gr-window.h"
#include "gr-utils.h"
@@ -203,13 +204,12 @@ save_chef (GrChefDialog *self)
}
g_signal_emit (self, done_signal, 0, self->chef);
- gtk_widget_destroy (GTK_WIDGET (self));
}
static void
close_dialog (GrChefDialog *self)
{
- gtk_widget_destroy (GTK_WIDGET (self));
+ g_signal_emit (self, done_signal, 0, NULL);
}
static void
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 16fbc3f..69ae7be 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -1125,10 +1125,12 @@ static void update_author_label (GrEditPage *page,
static void
chef_done (GrChefDialog *dialog, GrChef *chef, GrEditPage *page)
{
- g_free (page->author);
- page->author = g_strdup (gr_chef_get_id (chef));
-
- update_author_label (page, chef);
+ if (chef) {
+ g_free (page->author);
+ page->author = g_strdup (gr_chef_get_id (chef));
+ update_author_label (page, chef);
+ }
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static gboolean
diff --git a/src/gr-window.c b/src/gr-window.c
index ef212be..d9e2436 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -26,6 +26,7 @@
#include "gr-window.h"
#include "gr-details-page.h"
+#include "gr-chef-dialog.h"
#include "gr-edit-page.h"
#include "gr-list-page.h"
#include "gr-cuisine-page.h"
@@ -73,6 +74,8 @@ struct _GrWindow
GObject *file_chooser;
GrRecipeImporter *importer;
+ GtkWidget *chef_dialog;
+
GQueue *back_entry_stack;
gboolean is_fullscreen;
};
@@ -662,6 +665,41 @@ file_chooser_response (GtkNativeDialog *self,
window->file_chooser = NULL;
}
+static void
+chef_done (GrChefDialog *dialog,
+ GrChef *chef,
+ GrWindow *window)
+{
+ window->chef_dialog = NULL;
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+void
+gr_window_show_my_chef_information (GrWindow *window)
+{
+ GrRecipeStore *store;
+ const char *id;
+ g_autoptr(GrChef) chef = NULL;
+
+ if (window->chef_dialog)
+ return;
+
+ store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
+
+ id = gr_recipe_store_get_user_key (store);
+
+ if (id != NULL && id[0] != '\0')
+ chef = gr_recipe_store_get_chef (store, id);
+ else
+ chef = gr_chef_new ();
+
+ window->chef_dialog = (GtkWidget *)gr_chef_dialog_new (GTK_WINDOW (window), chef);
+ gr_chef_dialog_can_create (GR_CHEF_DIALOG (window->chef_dialog), FALSE);
+ gtk_window_set_title (GTK_WINDOW (window->chef_dialog), _("My Chef Information"));
+ g_signal_connect (window->chef_dialog, "done", G_CALLBACK (chef_done), window);
+ gtk_window_present (GTK_WINDOW (window->chef_dialog));
+}
+
void
gr_window_load_recipe (GrWindow *window,
GFile *file)
diff --git a/src/gr-window.h b/src/gr-window.h
index 9e65768..fe753a2 100644
--- a/src/gr-window.h
+++ b/src/gr-window.h
@@ -71,4 +71,6 @@ void gr_window_show_image (GrWindow *window,
void gr_window_offer_shopping (GrWindow *window);
+void gr_window_show_my_chef_information (GrWindow *window);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]