file chooser error stack: Don't derive from stack

We can just have a GtkStack, instead.
This commit is contained in:
Matthias Clasen 2019-05-28 22:12:20 +00:00
parent bc739e607b
commit 055a991e08
2 changed files with 26 additions and 8 deletions

View File

@ -17,19 +17,35 @@
#include "gtklabel.h" #include "gtklabel.h"
#include "gtkintl.h" #include "gtkintl.h"
G_DEFINE_TYPE (GtkFileChooserErrorStack, gtk_file_chooser_error_stack, GTK_TYPE_STACK) G_DEFINE_TYPE (GtkFileChooserErrorStack, gtk_file_chooser_error_stack, GTK_TYPE_WIDGET)
static void
gtk_file_chooser_error_stack_finalize (GObject *object)
{
GtkFileChooserErrorStack *self = GTK_FILE_CHOOSER_ERROR_STACK (object);
g_clear_pointer (&self->stack, gtk_widget_unparent);
G_OBJECT_CLASS (gtk_file_chooser_error_stack_parent_class)->finalize (object);
}
static void static void
gtk_file_chooser_error_stack_class_init (GtkFileChooserErrorStackClass *class) gtk_file_chooser_error_stack_class_init (GtkFileChooserErrorStackClass *class)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = gtk_file_chooser_error_stack_finalize;
} }
static void static void
gtk_file_chooser_error_stack_init (GtkFileChooserErrorStack *self) gtk_file_chooser_error_stack_init (GtkFileChooserErrorStack *self)
{ {
GtkWidget *label; GtkWidget *label;
GtkStack *stack = GTK_STACK (self); GtkStack *stack;
self->stack = gtk_stack_new ();
gtk_widget_set_parent (self->stack, GTK_WIDGET (self));
stack = GTK_STACK (self->stack);
gtk_stack_set_transition_type (stack, GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_stack_set_transition_type (stack, GTK_STACK_TRANSITION_TYPE_CROSSFADE);
gtk_stack_set_transition_duration (stack, 50); gtk_stack_set_transition_duration (stack, 50);
@ -110,7 +126,7 @@ gtk_file_chooser_error_stack_set_error (GtkFileChooserErrorStack *self,
if (g_strcmp0 (label_name, "no-error") == 0) if (g_strcmp0 (label_name, "no-error") == 0)
{ {
gtk_stack_set_visible_child_name (GTK_STACK (self), "no-error"); gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "no-error");
return; return;
} }
@ -118,7 +134,7 @@ gtk_file_chooser_error_stack_set_error (GtkFileChooserErrorStack *self,
is_folder ? "folder" : "file", is_folder ? "folder" : "file",
label_name); label_name);
gtk_stack_set_visible_child_name (GTK_STACK (self), child_name); gtk_stack_set_visible_child_name (GTK_STACK (self->stack), child_name);
g_free (child_name); g_free (child_name);
} }
@ -128,9 +144,9 @@ void
gtk_file_chooser_error_stack_set_custom_error (GtkFileChooserErrorStack *self, gtk_file_chooser_error_stack_set_custom_error (GtkFileChooserErrorStack *self,
const char *label_text) const char *label_text)
{ {
GtkWidget *label = gtk_stack_get_child_by_name (GTK_STACK (self), "cutsom"); GtkWidget *label = gtk_stack_get_child_by_name (GTK_STACK (self->stack), "cutsom");
gtk_label_set_text (GTK_LABEL (label), label_text); gtk_label_set_text (GTK_LABEL (label), label_text);
gtk_stack_set_visible_child_name (GTK_STACK (self), "custom"); gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "custom");
} }

View File

@ -36,12 +36,14 @@ typedef struct _GtkFileChooserErrorStackClass GtkFileChooserErrorStackCla
struct _GtkFileChooserErrorStack struct _GtkFileChooserErrorStack
{ {
GtkStack parent_instance; GtkWidget parent_instance;
GtkWidget *stack;
}; };
struct _GtkFileChooserErrorStackClass struct _GtkFileChooserErrorStackClass
{ {
GtkStackClass parent_class; GtkWidgetClass parent_class;
}; };
GType gtk_file_chooser_error_stack_get_type (void) G_GNUC_CONST; GType gtk_file_chooser_error_stack_get_type (void) G_GNUC_CONST;