/* BranchCreatePage.c generated by valac 0.56.19, the Vala compiler
 * generated from BranchCreatePage.vala, do not modify */

/*
 * Copyright 2025 elementary, Inc. <https://elementary.io>
 * SPDX-License-Identifier: GPL-3.0-or-later
*
* Authored by: Jeremy Wootten <jeremywootten@gmail.com>
*/

#include "codecore.h"
#include <granite.h>
#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_0_PROPERTY,
	SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_ACTION_PROPERTY,
	SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_BRANCH_REF_PROPERTY,
	SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_NEW_BRANCH_NAME_PROPERTY,
	SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_DIALOG_PROPERTY,
	SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_NUM_PROPERTIES
};
static GParamSpec* scratch_dialogs_branch_create_page_properties[SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _ScratchDialogsBranchCreatePagePrivate {
	ScratchDialogsBranchActionDialog* _dialog;
	GraniteValidatedEntry* new_branch_name_entry;
};

static gint ScratchDialogsBranchCreatePage_private_offset;
static gpointer scratch_dialogs_branch_create_page_parent_class = NULL;
static ScratchBranchActionPageIface * scratch_dialogs_branch_create_page_scratch_branch_action_page_parent_iface = NULL;

static GObject * scratch_dialogs_branch_create_page_constructor (GType type,
                                                          guint n_construct_properties,
                                                          GObjectConstructParam * construct_properties);
static void _scratch_dialogs_branch_create_page___lambda108_ (ScratchDialogsBranchCreatePage* self);
static void __scratch_dialogs_branch_create_page___lambda108__gtk_editable_changed (GtkEditable* _sender,
                                                                             gpointer self);
static void scratch_dialogs_branch_create_page_finalize (GObject * obj);
static GType scratch_dialogs_branch_create_page_get_type_once (void);
static void _vala_scratch_dialogs_branch_create_page_get_property (GObject * object,
                                                            guint property_id,
                                                            GValue * value,
                                                            GParamSpec * pspec);
static void _vala_scratch_dialogs_branch_create_page_set_property (GObject * object,
                                                            guint property_id,
                                                            const GValue * value,
                                                            GParamSpec * pspec);

static inline gpointer
scratch_dialogs_branch_create_page_get_instance_private (ScratchDialogsBranchCreatePage* self)
{
	return G_STRUCT_MEMBER_P (self, ScratchDialogsBranchCreatePage_private_offset);
}

ScratchDialogsBranchCreatePage*
scratch_dialogs_branch_create_page_construct (GType object_type,
                                              ScratchDialogsBranchActionDialog* dialog)
{
	ScratchDialogsBranchCreatePage * self = NULL;
	g_return_val_if_fail (dialog != NULL, NULL);
	self = (ScratchDialogsBranchCreatePage*) g_object_new (object_type, "dialog", dialog, NULL);
	return self;
}

ScratchDialogsBranchCreatePage*
scratch_dialogs_branch_create_page_new (ScratchDialogsBranchActionDialog* dialog)
{
	return scratch_dialogs_branch_create_page_construct (SCRATCH_DIALOGS_TYPE_BRANCH_CREATE_PAGE, dialog);
}

static ScratchBranchAction
scratch_dialogs_branch_create_page_real_get_action (ScratchBranchActionPage* base)
{
	ScratchBranchAction result;
	ScratchDialogsBranchCreatePage* self;
	self = (ScratchDialogsBranchCreatePage*) base;
	result = SCRATCH_BRANCH_ACTION_CREATE;
	return result;
}

static GgitRef*
scratch_dialogs_branch_create_page_real_get_branch_ref (ScratchBranchActionPage* base)
{
	GgitRef* result;
	ScratchDialogsBranchCreatePage* self;
	self = (ScratchDialogsBranchCreatePage*) base;
	result = NULL;
	return result;
}

static const gchar*
scratch_dialogs_branch_create_page_real_get_new_branch_name (ScratchBranchActionPage* base)
{
	const gchar* result;
	ScratchDialogsBranchCreatePage* self;
	GraniteValidatedEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (ScratchDialogsBranchCreatePage*) base;
	_tmp0_ = self->priv->new_branch_name_entry;
	_tmp1_ = gtk_entry_get_text ((GtkEntry*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

ScratchDialogsBranchActionDialog*
scratch_dialogs_branch_create_page_get_dialog (ScratchDialogsBranchCreatePage* self)
{
	ScratchDialogsBranchActionDialog* result;
	ScratchDialogsBranchActionDialog* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_dialog;
	result = _tmp0_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
scratch_dialogs_branch_create_page_set_dialog (ScratchDialogsBranchCreatePage* self,
                                               ScratchDialogsBranchActionDialog* value)
{
	ScratchDialogsBranchActionDialog* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_dialogs_branch_create_page_get_dialog (self);
	if (old_value != value) {
		ScratchDialogsBranchActionDialog* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_dialog);
		self->priv->_dialog = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_dialogs_branch_create_page_properties[SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_DIALOG_PROPERTY]);
	}
}

static void
_scratch_dialogs_branch_create_page___lambda108_ (ScratchDialogsBranchCreatePage* self)
{
	const gchar* new_name = NULL;
	GraniteValidatedEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	ScratchDialogsBranchActionDialog* _tmp3_;
	ScratchFolderManagerProjectFolderItem* _tmp4_;
	ScratchFolderManagerProjectFolderItem* _tmp5_;
	const gchar* _tmp6_;
	ScratchDialogsBranchActionDialog* _tmp8_;
	ScratchFolderManagerProjectFolderItem* _tmp9_;
	ScratchFolderManagerProjectFolderItem* _tmp10_;
	const gchar* _tmp11_;
	GraniteValidatedEntry* _tmp13_;
	_tmp0_ = self->priv->new_branch_name_entry;
	_tmp1_ = gtk_entry_get_text ((GtkEntry*) _tmp0_);
	_tmp2_ = _tmp1_;
	new_name = _tmp2_;
	_tmp3_ = self->priv->_dialog;
	_tmp4_ = scratch_dialogs_branch_action_dialog_get_project (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = new_name;
	if (!scratch_folder_manager_project_folder_item_is_valid_new_branch_name (_tmp5_, _tmp6_)) {
		GraniteValidatedEntry* _tmp7_;
		_tmp7_ = self->priv->new_branch_name_entry;
		granite_validated_entry_set_is_valid (_tmp7_, FALSE);
		return;
	}
	_tmp8_ = self->priv->_dialog;
	_tmp9_ = scratch_dialogs_branch_action_dialog_get_project (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = new_name;
	if (scratch_folder_manager_project_folder_item_has_local_branch_name (_tmp10_, _tmp11_)) {
		GraniteValidatedEntry* _tmp12_;
		_tmp12_ = self->priv->new_branch_name_entry;
		granite_validated_entry_set_is_valid (_tmp12_, FALSE);
		return;
	}
	_tmp13_ = self->priv->new_branch_name_entry;
	granite_validated_entry_set_is_valid (_tmp13_, TRUE);
}

static void
__scratch_dialogs_branch_create_page___lambda108__gtk_editable_changed (GtkEditable* _sender,
                                                                        gpointer self)
{
	_scratch_dialogs_branch_create_page___lambda108_ ((ScratchDialogsBranchCreatePage*) self);
}

static GObject *
scratch_dialogs_branch_create_page_constructor (GType type,
                                                guint n_construct_properties,
                                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ScratchDialogsBranchCreatePage * self;
	GraniteHeaderLabel* label = NULL;
	GraniteHeaderLabel* _tmp0_;
	gchar* _tmp1_;
	GraniteValidatedEntry* _tmp2_ = NULL;
	GraniteHeaderLabel* _tmp3_;
	GraniteValidatedEntry* _tmp4_;
	GraniteValidatedEntry* _tmp5_;
	ScratchDialogsBranchActionDialog* _tmp6_;
	GraniteValidatedEntry* _tmp7_;
	parent_class = G_OBJECT_CLASS (scratch_dialogs_branch_create_page_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_DIALOGS_TYPE_BRANCH_CREATE_PAGE, ScratchDialogsBranchCreatePage);
	gtk_orientable_set_orientation ((GtkOrientable*) self, GTK_ORIENTATION_VERTICAL);
	gtk_widget_set_vexpand ((GtkWidget*) self, FALSE);
	gtk_widget_set_hexpand ((GtkWidget*) self, TRUE);
	gtk_widget_set_margin_start ((GtkWidget*) self, 24);
	gtk_box_set_spacing ((GtkBox*) self, 12);
	gtk_widget_set_valign ((GtkWidget*) self, GTK_ALIGN_CENTER);
	_tmp0_ = granite_header_label_new (_ ("Name of branch to create"));
	g_object_ref_sink (_tmp0_);
	label = _tmp0_;
	_tmp1_ = g_strdup (_ ("Enter new branch name"));
	_tmp2_ = granite_validated_entry_new ();
	gtk_entry_set_activates_default ((GtkEntry*) _tmp2_, TRUE);
	gtk_entry_set_placeholder_text ((GtkEntry*) _tmp2_, _tmp1_);
	_g_free0 (_tmp1_);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->new_branch_name_entry);
	self->priv->new_branch_name_entry = _tmp2_;
	_tmp3_ = label;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp3_);
	_tmp4_ = self->priv->new_branch_name_entry;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp4_);
	_tmp5_ = self->priv->new_branch_name_entry;
	_tmp6_ = self->priv->_dialog;
	g_object_bind_property_with_closures ((GObject*) _tmp5_, "is-valid", (GObject*) _tmp6_, "can-apply", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp7_ = self->priv->new_branch_name_entry;
	g_signal_connect_object ((GtkEditable*) _tmp7_, "changed", (GCallback) __scratch_dialogs_branch_create_page___lambda108__gtk_editable_changed, self, 0);
	_g_object_unref0 (label);
	return obj;
}

static void
scratch_dialogs_branch_create_page_class_init (ScratchDialogsBranchCreatePageClass * klass,
                                               gpointer klass_data)
{
	scratch_dialogs_branch_create_page_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ScratchDialogsBranchCreatePage_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_scratch_dialogs_branch_create_page_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_scratch_dialogs_branch_create_page_set_property;
	G_OBJECT_CLASS (klass)->constructor = scratch_dialogs_branch_create_page_constructor;
	G_OBJECT_CLASS (klass)->finalize = scratch_dialogs_branch_create_page_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_ACTION_PROPERTY, scratch_dialogs_branch_create_page_properties[SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_ACTION_PROPERTY] = g_param_spec_enum ("action", "action", "action", SCRATCH_TYPE_BRANCH_ACTION, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_BRANCH_REF_PROPERTY, scratch_dialogs_branch_create_page_properties[SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_BRANCH_REF_PROPERTY] = g_param_spec_object ("branch-ref", "branch-ref", "branch-ref", ggit_ref_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_NEW_BRANCH_NAME_PROPERTY, scratch_dialogs_branch_create_page_properties[SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_NEW_BRANCH_NAME_PROPERTY] = g_param_spec_string ("new-branch-name", "new-branch-name", "new-branch-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_DIALOG_PROPERTY, scratch_dialogs_branch_create_page_properties[SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_DIALOG_PROPERTY] = g_param_spec_object ("dialog", "dialog", "dialog", SCRATCH_DIALOGS_TYPE_BRANCH_ACTION_DIALOG, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
scratch_dialogs_branch_create_page_scratch_branch_action_page_interface_init (ScratchBranchActionPageIface * iface,
                                                                              gpointer iface_data)
{
	scratch_dialogs_branch_create_page_scratch_branch_action_page_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_action = scratch_dialogs_branch_create_page_real_get_action;
	iface->get_branch_ref = scratch_dialogs_branch_create_page_real_get_branch_ref;
	iface->get_new_branch_name = scratch_dialogs_branch_create_page_real_get_new_branch_name;
}

static void
scratch_dialogs_branch_create_page_instance_init (ScratchDialogsBranchCreatePage * self,
                                                  gpointer klass)
{
	self->priv = scratch_dialogs_branch_create_page_get_instance_private (self);
}

static void
scratch_dialogs_branch_create_page_finalize (GObject * obj)
{
	ScratchDialogsBranchCreatePage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_DIALOGS_TYPE_BRANCH_CREATE_PAGE, ScratchDialogsBranchCreatePage);
	_g_object_unref0 (self->priv->_dialog);
	_g_object_unref0 (self->priv->new_branch_name_entry);
	G_OBJECT_CLASS (scratch_dialogs_branch_create_page_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
scratch_dialogs_branch_create_page_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchDialogsBranchCreatePageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_dialogs_branch_create_page_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchDialogsBranchCreatePage), 0, (GInstanceInitFunc) scratch_dialogs_branch_create_page_instance_init, NULL };
	static const GInterfaceInfo scratch_branch_action_page_info = { (GInterfaceInitFunc) scratch_dialogs_branch_create_page_scratch_branch_action_page_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType scratch_dialogs_branch_create_page_type_id;
	scratch_dialogs_branch_create_page_type_id = g_type_register_static (gtk_box_get_type (), "ScratchDialogsBranchCreatePage", &g_define_type_info, G_TYPE_FLAG_NONE);
	g_type_add_interface_static (scratch_dialogs_branch_create_page_type_id, SCRATCH_TYPE_BRANCH_ACTION_PAGE, &scratch_branch_action_page_info);
	ScratchDialogsBranchCreatePage_private_offset = g_type_add_instance_private (scratch_dialogs_branch_create_page_type_id, sizeof (ScratchDialogsBranchCreatePagePrivate));
	return scratch_dialogs_branch_create_page_type_id;
}

GType
scratch_dialogs_branch_create_page_get_type (void)
{
	static gsize scratch_dialogs_branch_create_page_type_id__once = 0;
	if (g_once_init_enter (&scratch_dialogs_branch_create_page_type_id__once)) {
		GType scratch_dialogs_branch_create_page_type_id;
		scratch_dialogs_branch_create_page_type_id = scratch_dialogs_branch_create_page_get_type_once ();
		g_once_init_leave (&scratch_dialogs_branch_create_page_type_id__once, scratch_dialogs_branch_create_page_type_id);
	}
	return scratch_dialogs_branch_create_page_type_id__once;
}

static void
_vala_scratch_dialogs_branch_create_page_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec)
{
	ScratchDialogsBranchCreatePage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_DIALOGS_TYPE_BRANCH_CREATE_PAGE, ScratchDialogsBranchCreatePage);
	switch (property_id) {
		case SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_ACTION_PROPERTY:
		g_value_set_enum (value, scratch_branch_action_page_get_action ((ScratchBranchActionPage*) self));
		break;
		case SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_BRANCH_REF_PROPERTY:
		g_value_set_object (value, scratch_branch_action_page_get_branch_ref ((ScratchBranchActionPage*) self));
		break;
		case SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_NEW_BRANCH_NAME_PROPERTY:
		g_value_set_string (value, scratch_branch_action_page_get_new_branch_name ((ScratchBranchActionPage*) self));
		break;
		case SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_DIALOG_PROPERTY:
		g_value_set_object (value, scratch_dialogs_branch_create_page_get_dialog (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_scratch_dialogs_branch_create_page_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec)
{
	ScratchDialogsBranchCreatePage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_DIALOGS_TYPE_BRANCH_CREATE_PAGE, ScratchDialogsBranchCreatePage);
	switch (property_id) {
		case SCRATCH_DIALOGS_BRANCH_CREATE_PAGE_DIALOG_PROPERTY:
		scratch_dialogs_branch_create_page_set_dialog (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

