[geany/geany] da5bb7: Don't access GtkColorSelectionDialog fields directly

Colomban Wendling git-noreply at xxxxx
Thu Sep 13 14:34:18 UTC 2012


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Thu, 13 Sep 2012 14:34:18
Commit:      da5bb7f0e1aa5d5bf861697d6d54bff88b177a34
             https://github.com/geany/geany/commit/da5bb7f0e1aa5d5bf861697d6d54bff88b177a34

Log Message:
-----------
Don't access GtkColorSelectionDialog fields directly

Also don't hack around and handle clicks on the dialog's buttons but
rather simply handler the dialog's response.


Modified Paths:
--------------
    src/tools.c

Modified: src/tools.c
58 files changed, 30 insertions(+), 28 deletions(-)
===================================================================
@@ -932,29 +932,32 @@ void tools_word_count(void)
  * color dialog callbacks
  */
 #ifndef G_OS_WIN32
-static void
-on_color_cancel_button_clicked(GtkButton *button, gpointer user_data)
+static void on_color_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
 {
-	gtk_widget_hide(ui_widgets.open_colorsel);
-}
-
+	switch (response)
+	{
+		case GTK_RESPONSE_OK:
+		{
+			GdkColor color;
+			GeanyDocument *doc = document_get_current();
+			gchar *hex;
+			GtkWidget *colorsel;
 
-static void
-on_color_ok_button_clicked(GtkButton *button, gpointer user_data)
-{
-	GdkColor color;
-	GeanyDocument *doc = document_get_current();
-	gchar *hex;
+			gtk_widget_hide(ui_widgets.open_colorsel);
+			g_return_if_fail(doc != NULL);
 
-	gtk_widget_hide(ui_widgets.open_colorsel);
-	g_return_if_fail(doc != NULL);
+			colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel));
+			gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), &color);
 
-	gtk_color_selection_get_current_color(
-			GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->colorsel), &color);
+			hex = utils_get_hex_from_color(&color);
+			editor_insert_color(doc->editor, hex);
+			g_free(hex);
+			break;
+		}
 
-	hex = utils_get_hex_from_color(&color);
-	editor_insert_color(doc->editor, hex);
-	g_free(hex);
+		default:
+			gtk_widget_hide(ui_widgets.open_colorsel);
+	}
 }
 #endif
 
@@ -966,22 +969,23 @@ void tools_color_chooser(const gchar *color)
 	win32_show_color_dialog(color);
 #else
 	gchar *c = (gchar*) color;
+	GtkWidget *colorsel;
 
 	if (ui_widgets.open_colorsel == NULL)
 	{
 		ui_widgets.open_colorsel = gtk_color_selection_dialog_new(_("Color Chooser"));
 		gtk_widget_set_name(ui_widgets.open_colorsel, "GeanyDialog");
 		gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.open_colorsel), GTK_WINDOW(main_widgets.window));
-		gtk_color_selection_set_has_palette(
-			GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->colorsel), TRUE);
+		colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel));
+		gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(colorsel), TRUE);
 
-		g_signal_connect(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->cancel_button, "clicked",
-						G_CALLBACK(on_color_cancel_button_clicked), NULL);
-		g_signal_connect(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->ok_button, "clicked",
-						G_CALLBACK(on_color_ok_button_clicked), NULL);
+		g_signal_connect(ui_widgets.open_colorsel, "response",
+						G_CALLBACK(on_color_dialog_response), NULL);
 		g_signal_connect(ui_widgets.open_colorsel, "delete-event",
 						G_CALLBACK(gtk_widget_hide_on_delete), NULL);
 	}
+	else
+		colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel));
 	/* if color is non-NULL set it in the dialog as preselected color */
 	if (c != NULL && (c[0] == '0' || c[0] == '#'))
 	{
@@ -993,10 +997,8 @@ void tools_color_chooser(const gchar *color)
 			c++;
 		}
 		gdk_color_parse(c, &gc);
-		gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(
-							GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->colorsel), &gc);
-		gtk_color_selection_set_previous_color(GTK_COLOR_SELECTION(
-							GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->colorsel), &gc);
+		gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &gc);
+		gtk_color_selection_set_previous_color(GTK_COLOR_SELECTION(colorsel), &gc);
 	}
 
 	/* We make sure the dialog is visible. */


@@ Diff output truncated at 100000 characters. @@


--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).



More information about the Commits mailing list