/* math-variable-popover.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from math-variable-popover.vala, do not modify */

/*
 * Copyright (C) 2008-2012 Robert Ancell
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
 * license.
 */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "calculator.h"
#include <gtk/gtk.h>
#include <gio/gio.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_MATH_VARIABLE (math_variable_get_type ())
#define MATH_VARIABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MATH_VARIABLE, MathVariable))
#define MATH_VARIABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MATH_VARIABLE, MathVariableClass))
#define IS_MATH_VARIABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MATH_VARIABLE))
#define IS_MATH_VARIABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MATH_VARIABLE))
#define MATH_VARIABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MATH_VARIABLE, MathVariableClass))

typedef struct _MathVariable MathVariable;
typedef struct _MathVariableClass MathVariableClass;
typedef struct _MathVariablePrivate MathVariablePrivate;
enum  {
	MATH_VARIABLE_0_PROPERTY,
	MATH_VARIABLE_NUM_PROPERTIES
};
static GParamSpec* math_variable_properties[MATH_VARIABLE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_MATH_POPOVER (math_popover_get_type ())
#define MATH_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MATH_POPOVER, MathPopover))
#define MATH_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MATH_POPOVER, MathPopoverClass))
#define IS_MATH_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MATH_POPOVER))
#define IS_MATH_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MATH_POPOVER))
#define MATH_POPOVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MATH_POPOVER, MathPopoverClass))

typedef struct _MathPopover MathPopover;
typedef struct _MathPopoverClass MathPopoverClass;
typedef struct _MathPopoverPrivate MathPopoverPrivate;

#define TYPE_MATH_VARIABLE_POPOVER (math_variable_popover_get_type ())
#define MATH_VARIABLE_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MATH_VARIABLE_POPOVER, MathVariablePopover))
#define MATH_VARIABLE_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MATH_VARIABLE_POPOVER, MathVariablePopoverClass))
#define IS_MATH_VARIABLE_POPOVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MATH_VARIABLE_POPOVER))
#define IS_MATH_VARIABLE_POPOVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MATH_VARIABLE_POPOVER))
#define MATH_VARIABLE_POPOVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MATH_VARIABLE_POPOVER, MathVariablePopoverClass))

typedef struct _MathVariablePopover MathVariablePopover;
typedef struct _MathVariablePopoverClass MathVariablePopoverClass;
typedef struct _MathVariablePopoverPrivate MathVariablePopoverPrivate;
enum  {
	MATH_VARIABLE_POPOVER_0_PROPERTY,
	MATH_VARIABLE_POPOVER_NUM_PROPERTIES
};
static GParamSpec* math_variable_popover_properties[MATH_VARIABLE_POPOVER_NUM_PROPERTIES];
typedef struct _Block10Data Block10Data;
typedef struct _Block11Data Block11Data;

struct _MathVariable {
	GObject parent_instance;
	MathVariablePrivate * priv;
	gchar* name;
	Number* value;
	gboolean is_custom;
};

struct _MathVariableClass {
	GObjectClass parent_class;
};

struct _MathPopover {
	GtkPopover parent_instance;
	MathPopoverPrivate * priv;
	MathEquation* equation;
	GListStore* model;
};

struct _MathPopoverClass {
	GtkPopoverClass parent_class;
	gboolean (*is_deletable) (MathPopover* self, gconstpointer item);
	gboolean (*is_editable) (MathPopover* self, gconstpointer item);
	gchar* (*get_item_text) (MathPopover* self, gconstpointer item);
	gint (*get_item_index) (MathPopover* self, gconstpointer item);
	gchar* (*validate_name) (MathPopover* self, const gchar* name);
	GtkEntry* (*get_name_entry) (MathPopover* self);
	GtkButton* (*get_add_button) (MathPopover* self);
	GtkLabel* (*get_error_label) (MathPopover* self);
};

struct _MathVariablePopover {
	MathPopover parent_instance;
	MathVariablePopoverPrivate * priv;
};

struct _MathVariablePopoverClass {
	MathPopoverClass parent_class;
};

struct _MathVariablePopoverPrivate {
	GtkStack* stack;
	GtkListBox* variable_list;
	GtkListBox* constant_list;
	GtkEntry* _name_entry;
	GtkButton* _add_button;
	GtkLabel* _error_label;
};

struct _Block10Data {
	int _ref_count_;
	MathVariablePopover* self;
	gchar* name;
};

struct _Block11Data {
	int _ref_count_;
	Block10Data * _data10_;
	gulong answer_handler;
	gulong error_handler;
};

static gpointer math_variable_parent_class = NULL;
static gint MathVariablePopover_private_offset;
static gpointer math_variable_popover_parent_class = NULL;
VALA_EXTERN gchar** math_popover_RESERVED_VARIABLE_NAMES;
VALA_EXTERN gint math_popover_RESERVED_VARIABLE_NAMES_length1;
VALA_EXTERN gchar** math_popover_OPERATORS;
VALA_EXTERN gint math_popover_OPERATORS_length1;

VALA_EXTERN GType math_variable_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MathVariable, g_object_unref)
VALA_EXTERN MathVariable* math_variable_new (const gchar* name,
                                 Number* value,
                                 gboolean is_custom);
VALA_EXTERN MathVariable* math_variable_construct (GType object_type,
                                       const gchar* name,
                                       Number* value,
                                       gboolean is_custom);
VALA_EXTERN gint math_variable_name_compare_func (MathVariable* var1,
                                      MathVariable* var2);
VALA_EXTERN gboolean math_variable_name_equal_func (MathVariable* var1,
                                        MathVariable* var2);
static void math_variable_finalize (GObject * obj);
static GType math_variable_get_type_once (void);
VALA_EXTERN GType math_popover_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MathPopover, g_object_unref)
VALA_EXTERN GType math_variable_popover_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MathVariablePopover, g_object_unref)
VALA_EXTERN gboolean math_popover_is_deletable (MathPopover* self,
                                    gconstpointer item);
VALA_EXTERN gboolean math_popover_is_editable (MathPopover* self,
                                   gconstpointer item);
VALA_EXTERN gchar* math_popover_get_item_text (MathPopover* self,
                                   gconstpointer item);
VALA_EXTERN gint math_popover_get_item_index (MathPopover* self,
                                  gconstpointer item);
VALA_EXTERN gchar* math_popover_validate_name (MathPopover* self,
                                   const gchar* name);
VALA_EXTERN GtkEntry* math_popover_get_name_entry (MathPopover* self);
VALA_EXTERN GtkButton* math_popover_get_add_button (MathPopover* self);
VALA_EXTERN GtkLabel* math_popover_get_error_label (MathPopover* self);
VALA_EXTERN MathVariablePopover* math_variable_popover_new (MathEquation* equation);
VALA_EXTERN MathVariablePopover* math_variable_popover_construct (GType object_type,
                                                      MathEquation* equation);
VALA_EXTERN MathPopover* math_popover_construct (GType object_type,
                                     GType t_type,
                                     GBoxedCopyFunc t_dup_func,
                                     GDestroyNotify t_destroy_func,
                                     MathEquation* equation,
                                     GListStore* model,
                                     GCompareDataFunc compare_func,
                                     gpointer compare_func_target);
static GtkWidget* __lambda18_ (MathVariablePopover* self,
                        GObject* variable);
VALA_EXTERN GtkWidget* math_popover_make_item_row (MathPopover* self,
                                       gconstpointer item);
static GtkWidget* ___lambda18__gtk_list_box_create_widget_func (GObject* item,
                                                         gpointer self);
static void __lambda19_ (MathVariablePopover* self);
static void ___lambda19__gtk_popover_closed (GtkPopover* _sender,
                                      gpointer self);
static void math_variable_popover_history_cb (MathVariablePopover* self,
                                       const gchar* answer,
                                       Number* number,
                                       gint number_base,
                                       guint representation_base);
static void _math_variable_popover_history_cb_math_equation_history_signal (MathEquation* _sender,
                                                                     const gchar* answer,
                                                                     Number* number,
                                                                     gint number_base,
                                                                     guint representation_base,
                                                                     gpointer self);
static void math_variable_popover_delete_variable_cb (MathVariablePopover* self,
                                               MathVariable* variable);
static void _math_variable_popover_delete_variable_cb_math_popover_item_deleted (MathPopover* _sender,
                                                                          gconstpointer item,
                                                                          gpointer self);
static void math_variable_popover_load_variables (MathVariablePopover* self);
static void math_variable_popover_load_constants (MathVariablePopover* self);
VALA_EXTERN void math_popover_item_added_cb (MathPopover* self,
                                 gconstpointer item);
static void __lambda20_ (MathVariablePopover* self,
                  const gchar* name,
                  Number* value);
static void ___lambda20__math_variables_variable_added (MathVariables* _sender,
                                                 const gchar* name,
                                                 Number* value,
                                                 gpointer self);
static void __lambda21_ (MathVariablePopover* self,
                  const gchar* name,
                  Number* value);
VALA_EXTERN void math_popover_item_edited_cb (MathPopover* self,
                                  gconstpointer item);
static void ___lambda21__math_variables_variable_edited (MathVariables* _sender,
                                                  const gchar* name,
                                                  Number* new_value,
                                                  gpointer self);
static void __lambda22_ (MathVariablePopover* self,
                  const gchar* name);
VALA_EXTERN void math_popover_item_deleted_cb (MathPopover* self,
                                   gconstpointer item);
static void ___lambda22__math_variables_variable_deleted (MathVariables* _sender,
                                                   const gchar* name,
                                                   gpointer self);
VALA_EXTERN GtkWidget* math_popover_make_category_row (MathPopover* self,
                                           const gchar* name,
                                           GtkListBox** submenu);
static void math_variable_popover_insert_constant_cb (MathVariablePopover* self,
                                               GtkListBoxRow* row);
static void _math_variable_popover_insert_constant_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                           GtkListBoxRow* row,
                                                                           gpointer self);
static void math_variable_popover_insert_variable_cb (MathVariablePopover* self,
                                               GtkListBoxRow* row);
VALA_EXTERN void math_popover_close_popover (MathPopover* self);
static void _math_variable_popover_insert_variable_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                           GtkListBoxRow* row,
                                                                           gpointer self);
static void math_variable_popover_open_submenu_cb (MathVariablePopover* self,
                                            GtkListBoxRow* row);
static void _math_variable_popover_open_submenu_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                        GtkListBoxRow* row,
                                                                        gpointer self);
static void math_variable_popover_store_variable_cb (MathVariablePopover* self,
                                              GtkWidget* widget);
static Block10Data* block10_data_ref (Block10Data* _data10_);
static void block10_data_unref (void * _userdata_);
static Block11Data* block11_data_ref (Block11Data* _data11_);
static void block11_data_unref (void * _userdata_);
static void ____lambda23_ (Block11Data* _data11_,
                    const gchar* answer,
                    Number* number);
static void _____lambda23__math_equation_history_signal (MathEquation* _sender,
                                                  const gchar* answer,
                                                  Number* number,
                                                  gint number_base,
                                                  guint representation_base,
                                                  gpointer self);
static void ____lambda24_ (Block11Data* _data11_);
static void _____lambda24__g_object_notify (GObject* _sender,
                                     GParamSpec* pspec,
                                     gpointer self);
static void _math_variable_popover_store_variable_cb_gtk_button_clicked (GtkButton* _sender,
                                                                  gpointer self);
static gboolean math_variable_popover_real_is_deletable (MathPopover* base,
                                                  MathVariable* variable);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      gssize stack_length,
                                      const gchar* needle);
static gboolean math_variable_popover_real_is_editable (MathPopover* base,
                                                 MathVariable* variable);
static gchar* math_variable_popover_real_get_item_text (MathPopover* base,
                                                 MathVariable* variable);
static gint math_variable_popover_real_get_item_index (MathPopover* base,
                                                MathVariable* item);
static gboolean __lambda25_ (GObject* a,
                      GObject* b);
static gboolean ___lambda25__gequal_func (gconstpointer a,
                                   gconstpointer b);
static gchar* math_variable_popover_real_validate_name (MathPopover* base,
                                                 const gchar* name);
static void math_variable_popover_finalize (GObject * obj);
static GType math_variable_popover_get_type_once (void);
static void _vala_math_variable_popover_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

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

MathVariable*
math_variable_construct (GType object_type,
                         const gchar* name,
                         Number* value,
                         gboolean is_custom)
{
	MathVariable * self = NULL;
	gchar* _tmp0_;
	Number* _tmp1_;
	g_return_val_if_fail (name != NULL, NULL);
	self = (MathVariable*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (name);
	_g_free0 (self->name);
	self->name = _tmp0_;
	_tmp1_ = _g_object_ref0 (value);
	_g_object_unref0 (self->value);
	self->value = _tmp1_;
	self->is_custom = is_custom;
	return self;
}

MathVariable*
math_variable_new (const gchar* name,
                   Number* value,
                   gboolean is_custom)
{
	return math_variable_construct (TYPE_MATH_VARIABLE, name, value, is_custom);
}

gint
math_variable_name_compare_func (MathVariable* var1,
                                 MathVariable* var2)
{
	GCompareFunc _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gint result;
	g_return_val_if_fail (var1 != NULL, 0);
	g_return_val_if_fail (var2 != NULL, 0);
	if (var1->is_custom != var2->is_custom) {
		gint _tmp0_ = 0;
		if (var1->is_custom) {
			_tmp0_ = 1;
		} else {
			_tmp0_ = -1;
		}
		result = _tmp0_;
		return result;
	}
	_tmp1_ = ((GCompareFunc) g_strcmp0);
	_tmp2_ = var1->name;
	_tmp3_ = var2->name;
	result = _tmp1_ (_tmp2_, _tmp3_);
	return result;
}

gboolean
math_variable_name_equal_func (MathVariable* var1,
                               MathVariable* var2)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gboolean result;
	g_return_val_if_fail (var1 != NULL, FALSE);
	g_return_val_if_fail (var2 != NULL, FALSE);
	_tmp0_ = var1->name;
	_tmp1_ = var2->name;
	result = g_strcmp0 (_tmp0_, _tmp1_) == 0;
	return result;
}

static void
math_variable_class_init (MathVariableClass * klass,
                          gpointer klass_data)
{
	math_variable_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = math_variable_finalize;
}

static void
math_variable_instance_init (MathVariable * self,
                             gpointer klass)
{
}

static void
math_variable_finalize (GObject * obj)
{
	MathVariable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MATH_VARIABLE, MathVariable);
	_g_free0 (self->name);
	_g_object_unref0 (self->value);
	G_OBJECT_CLASS (math_variable_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
math_variable_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MathVariableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) math_variable_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MathVariable), 0, (GInstanceInitFunc) math_variable_instance_init, NULL };
	GType math_variable_type_id;
	math_variable_type_id = g_type_register_static (G_TYPE_OBJECT, "MathVariable", &g_define_type_info, 0);
	return math_variable_type_id;
}

GType
math_variable_get_type (void)
{
	static gsize math_variable_type_id__once = 0;
	if (g_once_init_enter (&math_variable_type_id__once)) {
		GType math_variable_type_id;
		math_variable_type_id = math_variable_get_type_once ();
		g_once_init_leave (&math_variable_type_id__once, math_variable_type_id);
	}
	return math_variable_type_id__once;
}

static inline gpointer
math_variable_popover_get_instance_private (MathVariablePopover* self)
{
	return G_STRUCT_MEMBER_P (self, MathVariablePopover_private_offset);
}

static GtkWidget*
__lambda18_ (MathVariablePopover* self,
             GObject* variable)
{
	GtkWidget* _tmp0_;
	GtkWidget* result;
	g_return_val_if_fail (variable != NULL, NULL);
	_tmp0_ = math_popover_make_item_row ((MathPopover*) self, IS_MATH_VARIABLE (variable) ? ((MathVariable*) variable) : NULL);
	result = _tmp0_;
	return result;
}

static GtkWidget*
___lambda18__gtk_list_box_create_widget_func (GObject* item,
                                              gpointer self)
{
	GtkWidget* result;
	result = __lambda18_ ((MathVariablePopover*) self, item);
	return result;
}

static void
__lambda19_ (MathVariablePopover* self)
{
	GtkEntry* _tmp0_;
	GtkEntry* _tmp1_;
	GtkStack* _tmp2_;
	GtkSelectionModel* _tmp3_;
	GtkSelectionModel* _tmp4_;
	GtkSelectionModel* _tmp5_;
	_tmp0_ = math_popover_get_name_entry ((MathPopover*) self);
	_tmp1_ = _tmp0_;
	gtk_editable_set_text ((GtkEditable*) _tmp1_, "");
	_tmp2_ = self->priv->stack;
	_tmp3_ = gtk_stack_get_pages (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	gtk_selection_model_select_item (_tmp5_, (guint) 0, TRUE);
	_g_object_unref0 (_tmp5_);
}

static void
___lambda19__gtk_popover_closed (GtkPopover* _sender,
                                 gpointer self)
{
	__lambda19_ ((MathVariablePopover*) self);
}

static void
_math_variable_popover_history_cb_math_equation_history_signal (MathEquation* _sender,
                                                                const gchar* answer,
                                                                Number* number,
                                                                gint number_base,
                                                                guint representation_base,
                                                                gpointer self)
{
	math_variable_popover_history_cb ((MathVariablePopover*) self, answer, number, number_base, representation_base);
}

static void
_math_variable_popover_delete_variable_cb_math_popover_item_deleted (MathPopover* _sender,
                                                                     gconstpointer item,
                                                                     gpointer self)
{
	math_variable_popover_delete_variable_cb ((MathVariablePopover*) self, (MathVariable*) item);
}

MathVariablePopover*
math_variable_popover_construct (GType object_type,
                                 MathEquation* equation)
{
	MathVariablePopover * self = NULL;
	GListStore* _tmp0_;
	GListStore* _tmp1_;
	GtkListBox* _tmp2_;
	GListStore* _tmp3_;
	g_return_val_if_fail (equation != NULL, NULL);
	_tmp0_ = g_list_store_new (TYPE_MATH_VARIABLE);
	_tmp1_ = _tmp0_;
	self = (MathVariablePopover*) math_popover_construct (object_type, TYPE_MATH_VARIABLE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, equation, _tmp1_, (GCompareDataFunc) math_variable_name_compare_func, NULL);
	_g_object_unref0 (_tmp1_);
	_tmp2_ = self->priv->variable_list;
	_tmp3_ = ((MathPopover*) self)->model;
	gtk_list_box_bind_model (_tmp2_, (GListModel*) _tmp3_, ___lambda18__gtk_list_box_create_widget_func, g_object_ref (self), g_object_unref);
	g_signal_connect_object ((GtkPopover*) self, "closed", (GCallback) ___lambda19__gtk_popover_closed, self, 0);
	g_signal_connect_object (equation, "history-signal", (GCallback) _math_variable_popover_history_cb_math_equation_history_signal, self, 0);
	g_signal_connect_object ((MathPopover*) self, "item-deleted", (GCallback) _math_variable_popover_delete_variable_cb_math_popover_item_deleted, self, 0);
	math_variable_popover_load_variables (self);
	math_variable_popover_load_constants (self);
	return self;
}

MathVariablePopover*
math_variable_popover_new (MathEquation* equation)
{
	return math_variable_popover_construct (TYPE_MATH_VARIABLE_POPOVER, equation);
}

static void
__lambda20_ (MathVariablePopover* self,
             const gchar* name,
             Number* value)
{
	MathVariable* _tmp0_;
	MathVariable* _tmp1_;
	g_return_if_fail (name != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = math_variable_new (name, value, TRUE);
	_tmp1_ = _tmp0_;
	math_popover_item_added_cb ((MathPopover*) self, _tmp1_);
	_g_object_unref0 (_tmp1_);
}

static void
___lambda20__math_variables_variable_added (MathVariables* _sender,
                                            const gchar* name,
                                            Number* value,
                                            gpointer self)
{
	__lambda20_ ((MathVariablePopover*) self, name, value);
}

static void
__lambda21_ (MathVariablePopover* self,
             const gchar* name,
             Number* value)
{
	MathVariable* _tmp0_;
	MathVariable* _tmp1_;
	g_return_if_fail (name != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = math_variable_new (name, value, TRUE);
	_tmp1_ = _tmp0_;
	math_popover_item_edited_cb ((MathPopover*) self, _tmp1_);
	_g_object_unref0 (_tmp1_);
}

static void
___lambda21__math_variables_variable_edited (MathVariables* _sender,
                                             const gchar* name,
                                             Number* new_value,
                                             gpointer self)
{
	__lambda21_ ((MathVariablePopover*) self, name, new_value);
}

static void
__lambda22_ (MathVariablePopover* self,
             const gchar* name)
{
	MathVariable* _tmp0_;
	MathVariable* _tmp1_;
	g_return_if_fail (name != NULL);
	_tmp0_ = math_variable_new (name, NULL, TRUE);
	_tmp1_ = _tmp0_;
	math_popover_item_deleted_cb ((MathPopover*) self, _tmp1_);
	_g_object_unref0 (_tmp1_);
}

static void
___lambda22__math_variables_variable_deleted (MathVariables* _sender,
                                              const gchar* name,
                                              gpointer self)
{
	__lambda22_ ((MathVariablePopover*) self, name);
}

static void
math_variable_popover_load_variables (MathVariablePopover* self)
{
	gchar** names = NULL;
	MathEquation* _tmp0_;
	MathVariables* _tmp1_;
	MathVariables* _tmp2_;
	gint _tmp3_ = 0;
	gchar** _tmp4_;
	gint names_length1;
	gint _names_size_;
	MathVariable* _tmp20_;
	MathVariable* _tmp21_;
	MathEquation* _tmp22_;
	Number* _tmp23_;
	Number* _tmp24_;
	MathVariable* _tmp25_;
	MathVariable* _tmp26_;
	MathEquation* _tmp27_;
	MathVariables* _tmp28_;
	MathVariables* _tmp29_;
	MathEquation* _tmp30_;
	MathVariables* _tmp31_;
	MathVariables* _tmp32_;
	MathEquation* _tmp33_;
	MathVariables* _tmp34_;
	MathVariables* _tmp35_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ((MathPopover*) self)->equation;
	_tmp1_ = math_equation_get_variables (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp4_ = math_variables_get_names (_tmp2_, &_tmp3_);
	names = _tmp4_;
	names_length1 = _tmp3_;
	_names_size_ = names_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				gchar** _tmp7_;
				gint _tmp7__length1;
				const gchar* _tmp8_;
				Number* value = NULL;
				MathEquation* _tmp9_;
				MathVariables* _tmp10_;
				MathVariables* _tmp11_;
				gchar** _tmp12_;
				gint _tmp12__length1;
				const gchar* _tmp13_;
				Number* _tmp14_;
				gchar** _tmp15_;
				gint _tmp15__length1;
				const gchar* _tmp16_;
				Number* _tmp17_;
				MathVariable* _tmp18_;
				MathVariable* _tmp19_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = names;
				_tmp7__length1 = names_length1;
				_tmp8_ = _tmp7_[i];
				if (!(_tmp8_ != NULL)) {
					break;
				}
				_tmp9_ = ((MathPopover*) self)->equation;
				_tmp10_ = math_equation_get_variables (_tmp9_);
				_tmp11_ = _tmp10_;
				_tmp12_ = names;
				_tmp12__length1 = names_length1;
				_tmp13_ = _tmp12_[i];
				_tmp14_ = math_variables_get (_tmp11_, _tmp13_);
				value = _tmp14_;
				_tmp15_ = names;
				_tmp15__length1 = names_length1;
				_tmp16_ = _tmp15_[i];
				_tmp17_ = value;
				_tmp18_ = math_variable_new (_tmp16_, _tmp17_, TRUE);
				_tmp19_ = _tmp18_;
				math_popover_item_added_cb ((MathPopover*) self, _tmp19_);
				_g_object_unref0 (_tmp19_);
				_g_object_unref0 (value);
			}
		}
	}
	_tmp20_ = math_variable_new ("rand", NULL, FALSE);
	_tmp21_ = _tmp20_;
	math_popover_item_added_cb ((MathPopover*) self, _tmp21_);
	_g_object_unref0 (_tmp21_);
	_tmp22_ = ((MathPopover*) self)->equation;
	_tmp23_ = math_equation_get_answer (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = math_variable_new ("_", _tmp24_, FALSE);
	_tmp26_ = _tmp25_;
	math_popover_item_added_cb ((MathPopover*) self, _tmp26_);
	_g_object_unref0 (_tmp26_);
	_tmp27_ = ((MathPopover*) self)->equation;
	_tmp28_ = math_equation_get_variables (_tmp27_);
	_tmp29_ = _tmp28_;
	g_signal_connect_object (_tmp29_, "variable-added", (GCallback) ___lambda20__math_variables_variable_added, self, 0);
	_tmp30_ = ((MathPopover*) self)->equation;
	_tmp31_ = math_equation_get_variables (_tmp30_);
	_tmp32_ = _tmp31_;
	g_signal_connect_object (_tmp32_, "variable-edited", (GCallback) ___lambda21__math_variables_variable_edited, self, 0);
	_tmp33_ = ((MathPopover*) self)->equation;
	_tmp34_ = math_equation_get_variables (_tmp33_);
	_tmp35_ = _tmp34_;
	g_signal_connect_object (_tmp35_, "variable-deleted", (GCallback) ___lambda22__math_variables_variable_deleted, self, 0);
	names = (_vala_array_free (names, names_length1, (GDestroyNotify) g_free), NULL);
}

static void
_math_variable_popover_insert_constant_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                      GtkListBoxRow* row,
                                                                      gpointer self)
{
	math_variable_popover_insert_constant_cb ((MathVariablePopover*) self, row);
}

static void
math_variable_popover_load_constants (MathVariablePopover* self)
{
	ConstantCategory* _tmp0_;
	gint _tmp0__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = parser_CONSTANT_CATEGORIES;
	_tmp0__length1 = parser_CONSTANT_CATEGORIES_length1;
	{
		ConstantCategory* category_collection = NULL;
		gint category_collection_length1 = 0;
		gint _category_collection_size_ = 0;
		gint category_it = 0;
		category_collection = _tmp0_;
		category_collection_length1 = _tmp0__length1;
		for (category_it = 0; category_it < category_collection_length1; category_it = category_it + 1) {
			ConstantCategory _tmp1_;
			ConstantCategory _tmp2_ = {0};
			ConstantCategory category = {0};
			_tmp1_ = category_collection[category_it];
			constant_category_copy (&_tmp1_, &_tmp2_);
			category = _tmp2_;
			{
				GtkListBox* submenu = NULL;
				GtkWidget* category_row = NULL;
				ConstantCategory _tmp3_;
				const gchar* _tmp4_;
				GtkListBox* _tmp5_ = NULL;
				GtkWidget* _tmp6_;
				GtkListBox* _tmp7_;
				GtkWidget* _tmp8_;
				GtkListBox* _tmp9_;
				GtkListBox* _tmp10_;
				GtkStack* _tmp11_;
				GtkListBox* _tmp12_;
				ConstantCategory _tmp13_;
				Constant* _tmp14_;
				gint _tmp14__length1;
				_tmp3_ = category;
				_tmp4_ = _tmp3_.name;
				_tmp6_ = math_popover_make_category_row ((MathPopover*) self, _tmp4_, &_tmp5_);
				_g_object_unref0 (submenu);
				submenu = _tmp5_;
				category_row = _tmp6_;
				_tmp7_ = self->priv->constant_list;
				_tmp8_ = category_row;
				gtk_list_box_append (_tmp7_, _tmp8_);
				_tmp9_ = submenu;
				gtk_widget_add_css_class ((GtkWidget*) _tmp9_, "category-list");
				_tmp10_ = submenu;
				g_signal_connect_object (_tmp10_, "row-activated", (GCallback) _math_variable_popover_insert_constant_cb_gtk_list_box_row_activated, self, 0);
				_tmp11_ = self->priv->stack;
				_tmp12_ = submenu;
				gtk_stack_add_child (_tmp11_, (GtkWidget*) _tmp12_);
				_tmp13_ = category;
				_tmp14_ = _tmp13_.constants;
				_tmp14__length1 = _tmp13_.constants_length1;
				{
					Constant* constant_collection = NULL;
					gint constant_collection_length1 = 0;
					gint _constant_collection_size_ = 0;
					gint constant_it = 0;
					constant_collection = _tmp14_;
					constant_collection_length1 = _tmp14__length1;
					for (constant_it = 0; constant_it < constant_collection_length1; constant_it = constant_it + 1) {
						Constant _tmp15_;
						Constant _tmp16_ = {0};
						Constant constant = {0};
						_tmp15_ = constant_collection[constant_it];
						constant_copy (&_tmp15_, &_tmp16_);
						constant = _tmp16_;
						{
							GtkBox* constant_row = NULL;
							GtkBox* _tmp17_;
							GtkBox* _tmp18_;
							Constant _tmp19_;
							const gchar* _tmp20_;
							GtkLabel* _tmp21_;
							GtkLabel* _tmp22_;
							GtkLabel* symbol_label = NULL;
							Constant _tmp23_;
							const gchar* _tmp24_;
							GtkLabel* _tmp25_;
							GtkLabel* _tmp26_;
							GtkLabel* _tmp27_;
							GtkLabel* _tmp28_;
							GtkBox* _tmp29_;
							GtkLabel* _tmp30_;
							GtkBox* _tmp31_;
							Constant _tmp32_;
							const gchar* _tmp33_;
							gchar* _tmp34_;
							GtkListBox* _tmp35_;
							GtkBox* _tmp36_;
							_tmp17_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
							g_object_ref_sink (_tmp17_);
							constant_row = _tmp17_;
							_tmp18_ = constant_row;
							_tmp19_ = constant;
							_tmp20_ = _tmp19_.name;
							_tmp21_ = (GtkLabel*) gtk_label_new (_tmp20_);
							g_object_ref_sink (_tmp21_);
							_tmp22_ = _tmp21_;
							gtk_box_append (_tmp18_, (GtkWidget*) _tmp22_);
							_g_object_unref0 (_tmp22_);
							_tmp23_ = constant;
							_tmp24_ = _tmp23_.symbol;
							_tmp25_ = (GtkLabel*) gtk_label_new (_tmp24_);
							g_object_ref_sink (_tmp25_);
							symbol_label = _tmp25_;
							_tmp26_ = symbol_label;
							gtk_widget_set_halign ((GtkWidget*) _tmp26_, GTK_ALIGN_END);
							_tmp27_ = symbol_label;
							gtk_widget_set_hexpand ((GtkWidget*) _tmp27_, TRUE);
							_tmp28_ = symbol_label;
							gtk_widget_add_css_class ((GtkWidget*) _tmp28_, "dimmed");
							_tmp29_ = constant_row;
							_tmp30_ = symbol_label;
							gtk_box_append (_tmp29_, (GtkWidget*) _tmp30_);
							_tmp31_ = constant_row;
							_tmp32_ = constant;
							_tmp33_ = _tmp32_.symbol;
							_tmp34_ = g_strdup (_tmp33_);
							g_object_set_data_full ((GObject*) _tmp31_, "symbol", _tmp34_, g_free);
							_tmp35_ = submenu;
							_tmp36_ = constant_row;
							gtk_list_box_append (_tmp35_, (GtkWidget*) _tmp36_);
							_g_object_unref0 (symbol_label);
							_g_object_unref0 (constant_row);
							constant_destroy (&constant);
						}
					}
				}
				_g_object_unref0 (category_row);
				_g_object_unref0 (submenu);
				constant_category_destroy (&category);
			}
		}
	}
}

static void
math_variable_popover_history_cb (MathVariablePopover* self,
                                  const gchar* answer,
                                  Number* number,
                                  gint number_base,
                                  guint representation_base)
{
	MathVariable* _tmp0_;
	MathVariable* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (answer != NULL);
	g_return_if_fail (number != NULL);
	_tmp0_ = math_variable_new ("_", number, FALSE);
	_tmp1_ = _tmp0_;
	math_popover_item_edited_cb ((MathPopover*) self, _tmp1_);
	_g_object_unref0 (_tmp1_);
}

static void
math_variable_popover_insert_variable_cb (MathVariablePopover* self,
                                          GtkListBoxRow* row)
{
	MathVariable* variable = NULL;
	GListStore* _tmp0_;
	GObject* _tmp1_;
	MathVariable* _tmp2_;
	MathEquation* _tmp3_;
	const gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = ((MathPopover*) self)->model;
	_tmp1_ = g_list_model_get_item ((GListModel*) _tmp0_, (guint) gtk_list_box_row_get_index (row));
	_tmp2_ = IS_MATH_VARIABLE (_tmp1_) ? ((MathVariable*) _tmp1_) : NULL;
	if (_tmp2_ == NULL) {
		_g_object_unref0 (_tmp1_);
	}
	variable = _tmp2_;
	_tmp3_ = ((MathPopover*) self)->equation;
	_tmp4_ = variable->name;
	math_equation_insert_alpha (_tmp3_, _tmp4_);
	math_popover_close_popover ((MathPopover*) self);
	_g_object_unref0 (variable);
}

static void
_math_variable_popover_insert_variable_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                      GtkListBoxRow* row,
                                                                      gpointer self)
{
	math_variable_popover_insert_variable_cb ((MathVariablePopover*) self, row);
}

static void
math_variable_popover_open_submenu_cb (MathVariablePopover* self,
                                       GtkListBoxRow* row)
{
	GtkEntry* _tmp0_;
	GtkEntry* _tmp1_;
	GtkStack* _tmp2_;
	GtkSelectionModel* _tmp3_;
	GtkSelectionModel* _tmp4_;
	GtkSelectionModel* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	_tmp0_ = math_popover_get_name_entry ((MathPopover*) self);
	_tmp1_ = _tmp0_;
	gtk_editable_set_text ((GtkEditable*) _tmp1_, "");
	_tmp2_ = self->priv->stack;
	_tmp3_ = gtk_stack_get_pages (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	gtk_selection_model_select_item (_tmp5_, (guint) (gtk_list_box_row_get_index (row) + 1), TRUE);
	_g_object_unref0 (_tmp5_);
}

static void
_math_variable_popover_open_submenu_cb_gtk_list_box_row_activated (GtkListBox* _sender,
                                                                   GtkListBoxRow* row,
                                                                   gpointer self)
{
	math_variable_popover_open_submenu_cb ((MathVariablePopover*) self, row);
}

static void
math_variable_popover_insert_constant_cb (MathVariablePopover* self,
                                          GtkListBoxRow* row)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	if (gtk_list_box_row_get_index (row) == 0) {
		GtkStack* _tmp0_;
		GtkSelectionModel* _tmp1_;
		GtkSelectionModel* _tmp2_;
		GtkSelectionModel* _tmp3_;
		_tmp0_ = self->priv->stack;
		_tmp1_ = gtk_stack_get_pages (_tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		gtk_selection_model_select_item (_tmp3_, (guint) 0, TRUE);
		_g_object_unref0 (_tmp3_);
	} else {
		MathEquation* _tmp4_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		gconstpointer _tmp7_;
		_tmp4_ = ((MathPopover*) self)->equation;
		_tmp5_ = gtk_list_box_row_get_child (row);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_object_get_data ((GObject*) _tmp6_, "symbol");
		math_equation_insert_alpha (_tmp4_, (const gchar*) _tmp7_);
		math_popover_close_popover ((MathPopover*) self);
	}
}

static Block10Data*
block10_data_ref (Block10Data* _data10_)
{
	g_atomic_int_inc (&_data10_->_ref_count_);
	return _data10_;
}

static void
block10_data_unref (void * _userdata_)
{
	Block10Data* _data10_;
	_data10_ = (Block10Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data10_->_ref_count_)) {
		MathVariablePopover* self;
		self = _data10_->self;
		_g_free0 (_data10_->name);
		_g_object_unref0 (self);
		g_slice_free (Block10Data, _data10_);
	}
}

static Block11Data*
block11_data_ref (Block11Data* _data11_)
{
	g_atomic_int_inc (&_data11_->_ref_count_);
	return _data11_;
}

static void
block11_data_unref (void * _userdata_)
{
	Block11Data* _data11_;
	_data11_ = (Block11Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data11_->_ref_count_)) {
		MathVariablePopover* self;
		self = _data11_->_data10_->self;
		block10_data_unref (_data11_->_data10_);
		_data11_->_data10_ = NULL;
		g_slice_free (Block11Data, _data11_);
	}
}

static void
____lambda23_ (Block11Data* _data11_,
               const gchar* answer,
               Number* number)
{
	Block10Data* _data10_;
	MathVariablePopover* self;
	MathEquation* _tmp0_;
	MathVariables* _tmp1_;
	MathVariables* _tmp2_;
	const gchar* _tmp3_;
	MathEquation* _tmp4_;
	MathEquation* _tmp5_;
	_data10_ = _data11_->_data10_;
	self = _data10_->self;
	g_return_if_fail (answer != NULL);
	g_return_if_fail (number != NULL);
	_tmp0_ = ((MathPopover*) self)->equation;
	_tmp1_ = math_equation_get_variables (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _data10_->name;
	math_variables_set (_tmp2_, _tmp3_, number);
	_tmp4_ = ((MathPopover*) self)->equation;
	g_signal_handler_disconnect ((GObject*) _tmp4_, _data11_->answer_handler);
	_tmp5_ = ((MathPopover*) self)->equation;
	g_signal_handler_disconnect ((GObject*) _tmp5_, _data11_->error_handler);
}

static void
_____lambda23__math_equation_history_signal (MathEquation* _sender,
                                             const gchar* answer,
                                             Number* number,
                                             gint number_base,
                                             guint representation_base,
                                             gpointer self)
{
	____lambda23_ (self, answer, number);
}

static void
____lambda24_ (Block11Data* _data11_)
{
	Block10Data* _data10_;
	MathVariablePopover* self;
	MathEquation* _tmp0_;
	MathEquation* _tmp1_;
	_data10_ = _data11_->_data10_;
	self = _data10_->self;
	_tmp0_ = ((MathPopover*) self)->equation;
	g_signal_handler_disconnect ((GObject*) _tmp0_, _data11_->answer_handler);
	_tmp1_ = ((MathPopover*) self)->equation;
	g_signal_handler_disconnect ((GObject*) _tmp1_, _data11_->error_handler);
}

static void
_____lambda24__g_object_notify (GObject* _sender,
                                GParamSpec* pspec,
                                gpointer self)
{
	____lambda24_ (self);
}

static void
math_variable_popover_store_variable_cb (MathVariablePopover* self,
                                         GtkWidget* widget)
{
	Block10Data* _data10_;
	GtkButton* _tmp0_;
	GtkButton* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	GtkEntry* _tmp4_;
	GtkEntry* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	Number* z = NULL;
	MathEquation* _tmp9_;
	Number* _tmp10_;
	Number* _tmp11_;
	Number* _tmp12_;
	GtkEntry* _tmp33_;
	GtkEntry* _tmp34_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_data10_ = g_slice_new0 (Block10Data);
	_data10_->_ref_count_ = 1;
	_data10_->self = g_object_ref (self);
	_tmp0_ = math_popover_get_add_button ((MathPopover*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = gtk_widget_get_sensitive ((GtkWidget*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		block10_data_unref (_data10_);
		_data10_ = NULL;
		return;
	}
	_tmp4_ = math_popover_get_name_entry ((MathPopover*) self);
	_tmp5_ = _tmp4_;
	_tmp6_ = gtk_editable_get_text ((GtkEditable*) _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strdup (_tmp7_);
	_data10_->name = _tmp8_;
	_tmp9_ = ((MathPopover*) self)->equation;
	_tmp10_ = math_equation_get_number (_tmp9_);
	_tmp11_ = _tmp10_;
	z = _tmp11_;
	_tmp12_ = z;
	if (_tmp12_ != NULL) {
		MathEquation* _tmp13_;
		MathVariables* _tmp14_;
		MathVariables* _tmp15_;
		const gchar* _tmp16_;
		Number* _tmp17_;
		_tmp13_ = ((MathPopover*) self)->equation;
		_tmp14_ = math_equation_get_variables (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = _data10_->name;
		_tmp17_ = z;
		math_variables_set (_tmp15_, _tmp16_, _tmp17_);
	} else {
		MathEquation* _tmp18_;
		gboolean _tmp19_;
		gboolean _tmp20_;
		_tmp18_ = ((MathPopover*) self)->equation;
		_tmp19_ = math_equation_get_is_result (_tmp18_);
		_tmp20_ = _tmp19_;
		if (_tmp20_) {
			MathEquation* _tmp21_;
			MathVariables* _tmp22_;
			MathVariables* _tmp23_;
			const gchar* _tmp24_;
			MathEquation* _tmp25_;
			Number* _tmp26_;
			Number* _tmp27_;
			_tmp21_ = ((MathPopover*) self)->equation;
			_tmp22_ = math_equation_get_variables (_tmp21_);
			_tmp23_ = _tmp22_;
			_tmp24_ = _data10_->name;
			_tmp25_ = ((MathPopover*) self)->equation;
			_tmp26_ = math_equation_get_answer (_tmp25_);
			_tmp27_ = _tmp26_;
			math_variables_set (_tmp23_, _tmp24_, _tmp27_);
		} else {
			Block11Data* _data11_;
			MathEquation* _tmp28_;
			gulong _tmp29_;
			MathEquation* _tmp30_;
			gulong _tmp31_;
			MathEquation* _tmp32_;
			_data11_ = g_slice_new0 (Block11Data);
			_data11_->_ref_count_ = 1;
			_data11_->_data10_ = block10_data_ref (_data10_);
			_data11_->answer_handler = (gulong) 0;
			_data11_->error_handler = (gulong) 0;
			_tmp28_ = ((MathPopover*) self)->equation;
			_tmp29_ = g_signal_connect_data (_tmp28_, "history-signal", (GCallback) _____lambda23__math_equation_history_signal, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
			_data11_->answer_handler = _tmp29_;
			_tmp30_ = ((MathPopover*) self)->equation;
			_tmp31_ = g_signal_connect_data ((GObject*) _tmp30_, "notify::error-token-end", (GCallback) _____lambda24__g_object_notify, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
			_data11_->error_handler = _tmp31_;
			_tmp32_ = ((MathPopover*) self)->equation;
			math_equation_solve (_tmp32_);
			block11_data_unref (_data11_);
			_data11_ = NULL;
		}
	}
	_tmp33_ = math_popover_get_name_entry ((MathPopover*) self);
	_tmp34_ = _tmp33_;
	gtk_editable_set_text ((GtkEditable*) _tmp34_, "");
	_g_object_unref0 (z);
	block10_data_unref (_data10_);
	_data10_ = NULL;
}

static void
_math_variable_popover_store_variable_cb_gtk_button_clicked (GtkButton* _sender,
                                                             gpointer self)
{
	math_variable_popover_store_variable_cb ((MathVariablePopover*) self, _sender);
}

static void
math_variable_popover_delete_variable_cb (MathVariablePopover* self,
                                          MathVariable* variable)
{
	MathEquation* _tmp0_;
	MathVariables* _tmp1_;
	MathVariables* _tmp2_;
	const gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (variable != NULL);
	_tmp0_ = ((MathPopover*) self)->equation;
	_tmp1_ = math_equation_get_variables (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = variable->name;
	math_variables_delete (_tmp2_, _tmp3_);
}

static gboolean
_vala_string_array_contains (gchar* * stack,
                             gssize stack_length,
                             const gchar* needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}

static gboolean
math_variable_popover_real_is_deletable (MathPopover* base,
                                         MathVariable* variable)
{
	MathVariablePopover * self;
	const gchar* _tmp0_;
	gchar** _tmp1_;
	gint _tmp1__length1;
	gboolean result;
	self = (MathVariablePopover*) base;
	g_return_val_if_fail (variable != NULL, FALSE);
	_tmp0_ = variable->name;
	_tmp1_ = math_popover_RESERVED_VARIABLE_NAMES;
	_tmp1__length1 = math_popover_RESERVED_VARIABLE_NAMES_length1;
	result = !_vala_string_array_contains (_tmp1_, _tmp1__length1, _tmp0_);
	return result;
}

static gboolean
math_variable_popover_real_is_editable (MathPopover* base,
                                        MathVariable* variable)
{
	MathVariablePopover * self;
	gboolean result;
	self = (MathVariablePopover*) base;
	g_return_val_if_fail (variable != NULL, FALSE);
	result = FALSE;
	return result;
}

static gchar*
math_variable_popover_real_get_item_text (MathPopover* base,
                                          MathVariable* variable)
{
	MathVariablePopover * self;
	gchar* text = NULL;
	Number* _tmp0_;
	gchar* result;
	self = (MathVariablePopover*) base;
	g_return_val_if_fail (variable != NULL, NULL);
	_tmp0_ = variable->value;
	if (_tmp0_ != NULL) {
		gchar* value_text = NULL;
		MathEquation* _tmp1_;
		Serializer* _tmp2_;
		Serializer* _tmp3_;
		Number* _tmp4_;
		gchar* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		gchar* _tmp8_;
		_tmp1_ = ((MathPopover*) self)->equation;
		_tmp2_ = math_equation_get_serializer (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = variable->value;
		_tmp5_ = serializer_to_string (_tmp3_, _tmp4_);
		value_text = _tmp5_;
		_tmp6_ = variable->name;
		_tmp7_ = value_text;
		_tmp8_ = g_strdup_printf ("<b>%s</b> = %s", _tmp6_, _tmp7_);
		_g_free0 (text);
		text = _tmp8_;
		_g_free0 (value_text);
	} else {
		const gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp9_ = variable->name;
		_tmp10_ = g_strdup_printf ("<b>%s</b>", _tmp9_);
		_g_free0 (text);
		text = _tmp10_;
	}
	result = text;
	return result;
}

static gboolean
__lambda25_ (GObject* a,
             GObject* b)
{
	gboolean result;
	g_return_val_if_fail (a != NULL, FALSE);
	g_return_val_if_fail (b != NULL, FALSE);
	result = math_variable_name_equal_func (IS_MATH_VARIABLE (a) ? ((MathVariable*) a) : NULL, IS_MATH_VARIABLE (b) ? ((MathVariable*) b) : NULL);
	return result;
}

static gboolean
___lambda25__gequal_func (gconstpointer a,
                          gconstpointer b)
{
	gboolean result;
	result = __lambda25_ ((GObject*) a, (GObject*) b);
	return result;
}

static gint
math_variable_popover_real_get_item_index (MathPopover* base,
                                           MathVariable* item)
{
	MathVariablePopover * self;
	guint position = 0U;
	GListStore* _tmp0_;
	guint _tmp1_ = 0U;
	gboolean _tmp2_;
	gint result;
	self = (MathVariablePopover*) base;
	g_return_val_if_fail (item != NULL, 0);
	_tmp0_ = ((MathPopover*) self)->model;
	_tmp2_ = g_list_store_find_with_equal_func (_tmp0_, G_TYPE_CHECK_INSTANCE_TYPE (item, G_TYPE_OBJECT) ? ((GObject*) item) : NULL, ___lambda25__gequal_func, &_tmp1_);
	position = _tmp1_;
	if (_tmp2_) {
		result = (gint) position;
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gchar*
math_variable_popover_real_validate_name (MathPopover* base,
                                          const gchar* name)
{
	MathVariablePopover * self;
	gboolean _tmp0_ = FALSE;
	FunctionManager* _tmp1_;
	FunctionManager* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp8_ = FALSE;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar** _tmp11_;
	gint _tmp11__length1;
	gboolean _tmp12_;
	gchar* result;
	self = (MathVariablePopover*) base;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp1_ = function_manager_get_default_function_manager ();
	_tmp2_ = _tmp1_;
	_tmp3_ = function_manager_is_function_defined (_tmp2_, name);
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		_tmp0_ = TRUE;
	} else {
		gchar* _tmp4_;
		gchar* _tmp5_;
		gchar** _tmp6_;
		gint _tmp6__length1;
		_tmp4_ = g_utf8_strdown (name, (gssize) -1);
		_tmp5_ = _tmp4_;
		_tmp6_ = math_popover_OPERATORS;
		_tmp6__length1 = math_popover_OPERATORS_length1;
		_tmp0_ = _vala_string_array_contains (_tmp6_, _tmp6__length1, _tmp5_);
		_g_free0 (_tmp5_);
	}
	if (_tmp0_) {
		gchar* _tmp7_;
		_tmp7_ = g_strdup (_ ("Can not use defined function or operator names"));
		result = _tmp7_;
		return result;
	}
	_tmp9_ = g_utf8_strdown (name, (gssize) -1);
	_tmp10_ = _tmp9_;
	_tmp11_ = math_popover_RESERVED_VARIABLE_NAMES;
	_tmp11__length1 = math_popover_RESERVED_VARIABLE_NAMES_length1;
	_tmp12_ = _vala_string_array_contains (_tmp11_, _tmp11__length1, _tmp10_);
	_g_free0 (_tmp10_);
	if (_tmp12_) {
		_tmp8_ = TRUE;
	} else {
		GHashTable* _tmp13_;
		_tmp13_ = parser_CONSTANTS;
		_tmp8_ = g_hash_table_contains (_tmp13_, name);
	}
	if (_tmp8_) {
		gchar* _tmp14_;
		_tmp14_ = g_strdup (_ ("Can not use built-in variable or constant names"));
		result = _tmp14_;
		return result;
	}
	if (!g_regex_match_simple ("^\\D", name, 0, 0)) {
		gchar* _tmp15_;
		_tmp15_ = g_strdup (_ ("Variable name can not start with a digit"));
		result = _tmp15_;
		return result;
	}
	if (!g_regex_match_simple ("^\\w*$", name, 0, 0)) {
		gchar* _tmp16_;
		_tmp16_ = g_strdup (_ ("Variable name can only contain digits, letters and underscores"));
		result = _tmp16_;
		return result;
	}
	result = NULL;
	return result;
}

static GtkEntry*
math_variable_popover_real_get_name_entry (MathPopover* base)
{
	GtkEntry* result;
	MathVariablePopover* self;
	GtkEntry* _tmp0_;
	self = (MathVariablePopover*) base;
	_tmp0_ = self->priv->_name_entry;
	result = _tmp0_;
	return result;
}

static GtkButton*
math_variable_popover_real_get_add_button (MathPopover* base)
{
	GtkButton* result;
	MathVariablePopover* self;
	GtkButton* _tmp0_;
	self = (MathVariablePopover*) base;
	_tmp0_ = self->priv->_add_button;
	result = _tmp0_;
	return result;
}

static GtkLabel*
math_variable_popover_real_get_error_label (MathPopover* base)
{
	GtkLabel* result;
	MathVariablePopover* self;
	GtkLabel* _tmp0_;
	self = (MathVariablePopover*) base;
	_tmp0_ = self->priv->_error_label;
	result = _tmp0_;
	return result;
}

static void
math_variable_popover_class_init (MathVariablePopoverClass * klass,
                                  gpointer klass_data)
{
	math_variable_popover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &MathVariablePopover_private_offset);
	((MathPopoverClass *) klass)->is_deletable = (gboolean (*) (MathPopover*, gconstpointer)) math_variable_popover_real_is_deletable;
	((MathPopoverClass *) klass)->is_editable = (gboolean (*) (MathPopover*, gconstpointer)) math_variable_popover_real_is_editable;
	((MathPopoverClass *) klass)->get_item_text = (gchar* (*) (MathPopover*, gconstpointer)) math_variable_popover_real_get_item_text;
	((MathPopoverClass *) klass)->get_item_index = (gint (*) (MathPopover*, gconstpointer)) math_variable_popover_real_get_item_index;
	((MathPopoverClass *) klass)->validate_name = (gchar* (*) (MathPopover*, const gchar*)) math_variable_popover_real_validate_name;
	MATH_POPOVER_CLASS (klass)->get_name_entry = (GtkEntry* (*) (MathPopover*)) math_variable_popover_real_get_name_entry;
	MATH_POPOVER_CLASS (klass)->get_add_button = (GtkButton* (*) (MathPopover*)) math_variable_popover_real_get_add_button;
	MATH_POPOVER_CLASS (klass)->get_error_label = (GtkLabel* (*) (MathPopover*)) math_variable_popover_real_get_error_label;
	G_OBJECT_CLASS (klass)->get_property = _vala_math_variable_popover_get_property;
	G_OBJECT_CLASS (klass)->finalize = math_variable_popover_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/calculator/math-variable-popover.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "stack", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, stack));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "variable_list", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, variable_list));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "constant_list", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, constant_list));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "name_entry", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, _name_entry));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "add_button", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, _add_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "error_label", FALSE, MathVariablePopover_private_offset + G_STRUCT_OFFSET (MathVariablePopoverPrivate, _error_label));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "insert_variable_cb", G_CALLBACK(_math_variable_popover_insert_variable_cb_gtk_list_box_row_activated));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "open_submenu_cb", G_CALLBACK(_math_variable_popover_open_submenu_cb_gtk_list_box_row_activated));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "store_variable_cb", G_CALLBACK(_math_variable_popover_store_variable_cb_gtk_button_clicked));
}

static void
math_variable_popover_instance_init (MathVariablePopover * self,
                                     gpointer klass)
{
	self->priv = math_variable_popover_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
math_variable_popover_finalize (GObject * obj)
{
	MathVariablePopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MATH_VARIABLE_POPOVER, MathVariablePopover);
	G_OBJECT_CLASS (math_variable_popover_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
math_variable_popover_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (MathVariablePopoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) math_variable_popover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MathVariablePopover), 0, (GInstanceInitFunc) math_variable_popover_instance_init, NULL };
	GType math_variable_popover_type_id;
	math_variable_popover_type_id = g_type_register_static (TYPE_MATH_POPOVER, "MathVariablePopover", &g_define_type_info, 0);
	MathVariablePopover_private_offset = g_type_add_instance_private (math_variable_popover_type_id, sizeof (MathVariablePopoverPrivate));
	return math_variable_popover_type_id;
}

GType
math_variable_popover_get_type (void)
{
	static gsize math_variable_popover_type_id__once = 0;
	if (g_once_init_enter (&math_variable_popover_type_id__once)) {
		GType math_variable_popover_type_id;
		math_variable_popover_type_id = math_variable_popover_get_type_once ();
		g_once_init_leave (&math_variable_popover_type_id__once, math_variable_popover_type_id);
	}
	return math_variable_popover_type_id__once;
}

static void
_vala_math_variable_popover_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	MathVariablePopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_MATH_VARIABLE_POPOVER, MathVariablePopover);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

