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

/*
* Copyright (c) 2016 Felipe Escoto (https://github.com/Philip-Scott/Notes-up)
*
* 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 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authored by: Felipe Escoto <felescoto95@hotmail.com>
*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gee.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.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 ENOTES_TYPE_PLUGIN (enotes_plugin_get_type ())
#define ENOTES_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_PLUGIN, ENotesPlugin))
#define ENOTES_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_PLUGIN, ENotesPluginClass))
#define ENOTES_IS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_PLUGIN))
#define ENOTES_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_PLUGIN))
#define ENOTES_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_PLUGIN, ENotesPluginClass))

typedef struct _ENotesPlugin ENotesPlugin;
typedef struct _ENotesPluginClass ENotesPluginClass;
typedef struct _ENotesPluginPrivate ENotesPluginPrivate;

#define TYPE_BL_MEMBER (bl_member_get_type ())
#define BL_MEMBER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BL_MEMBER, BLMember))
#define BL_MEMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BL_MEMBER, BLMemberClass))
#define IS_BL_MEMBER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BL_MEMBER))
#define IS_BL_MEMBER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BL_MEMBER))
#define BL_MEMBER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BL_MEMBER, BLMemberClass))

typedef struct _BLMember BLMember;
typedef struct _BLMemberClass BLMemberClass;

#define ENOTES_TYPE_COLOR (enotes_color_get_type ())
#define ENOTES_COLOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_COLOR, ENotesColor))
#define ENOTES_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_COLOR, ENotesColorClass))
#define ENOTES_IS_COLOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_COLOR))
#define ENOTES_IS_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_COLOR))
#define ENOTES_COLOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_COLOR, ENotesColorClass))

typedef struct _ENotesColor ENotesColor;
typedef struct _ENotesColorClass ENotesColorClass;
typedef struct _ENotesColorPrivate ENotesColorPrivate;
enum  {
	ENOTES_COLOR_0_PROPERTY,
	ENOTES_COLOR_NUM_PROPERTIES
};
static GParamSpec* enotes_color_properties[ENOTES_COLOR_NUM_PROPERTIES];
#define _g_pattern_spec_free0(var) ((var == NULL) ? NULL : (var = (g_pattern_spec_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _bl_member_unref0(var) ((var == NULL) ? NULL : (var = (bl_member_unref (var), NULL)))

struct _ENotesPlugin {
	GObject parent_instance;
	ENotesPluginPrivate * priv;
	gboolean state;
	gchar* code_name;
};

struct _ENotesPluginClass {
	GObjectClass parent_class;
	gchar* (*get_desctiption) (ENotesPlugin* self);
	gchar* (*get_name) (ENotesPlugin* self);
	gboolean (*has_match) (ENotesPlugin* self, const gchar* text);
	gchar* (*convert) (ENotesPlugin* self, const gchar* line);
	GtkWidget* (*editor_button) (ENotesPlugin* self);
	gchar* (*get_button_desctiption) (ENotesPlugin* self);
	gchar* (*request_string) (ENotesPlugin* self, const gchar* selection);
	GeeList* (*get_blacklist_members) (ENotesPlugin* self);
};

struct _ENotesColor {
	ENotesPlugin parent_instance;
	ENotesColorPrivate * priv;
};

struct _ENotesColorClass {
	ENotesPluginClass parent_class;
};

struct _ENotesColorPrivate {
	GPatternSpec* spec;
	GtkColorChooserWidget* color_selector;
	GtkPopover* popover;
	gchar* selection;
};

static gint ENotesColor_private_offset;
static gpointer enotes_color_parent_class = NULL;

VALA_EXTERN GType enotes_plugin_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPlugin, g_object_unref)
VALA_EXTERN gpointer bl_member_ref (gpointer instance);
VALA_EXTERN void bl_member_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_bl_member (const gchar* name,
                                  const gchar* nick,
                                  const gchar* blurb,
                                  GType object_type,
                                  GParamFlags flags);
VALA_EXTERN void value_set_bl_member (GValue* value,
                          gpointer v_object);
VALA_EXTERN void value_take_bl_member (GValue* value,
                           gpointer v_object);
VALA_EXTERN gpointer value_get_bl_member (const GValue* value);
VALA_EXTERN GType bl_member_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BLMember, bl_member_unref)
VALA_EXTERN GType enotes_color_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesColor, g_object_unref)
VALA_EXTERN gchar* enotes_plugin_get_desctiption (ENotesPlugin* self);
VALA_EXTERN gchar* enotes_plugin_get_name (ENotesPlugin* self);
VALA_EXTERN GtkWidget* enotes_plugin_editor_button (ENotesPlugin* self);
VALA_EXTERN gchar* enotes_plugin_get_button_desctiption (ENotesPlugin* self);
VALA_EXTERN gchar* enotes_plugin_request_string (ENotesPlugin* self,
                                     const gchar* selection);
VALA_EXTERN gboolean enotes_plugin_has_match (ENotesPlugin* self,
                                  const gchar* text);
VALA_EXTERN gchar* enotes_plugin_convert (ENotesPlugin* self,
                              const gchar* line);
VALA_EXTERN GeeList* enotes_plugin_get_blacklist_members (ENotesPlugin* self);
static gchar* enotes_color_real_get_desctiption (ENotesPlugin* base);
static gchar* enotes_color_real_get_name (ENotesPlugin* base);
static GtkWidget* enotes_color_real_editor_button (ENotesPlugin* base);
static void __lambda4_ (ENotesColor* self);
static void ___lambda4__gtk_widget_hide (GtkWidget* _sender,
                                  gpointer self);
static void __lambda5_ (ENotesColor* self);
static void ___lambda5__gtk_color_chooser_color_activated (GtkColorChooser* _sender,
                                                    GdkRGBA* color,
                                                    gpointer self);
static gchar* enotes_color_real_get_button_desctiption (ENotesPlugin* base);
static gchar* enotes_color_real_request_string (ENotesPlugin* base,
                                         const gchar* selection);
static gboolean enotes_color_real_has_match (ENotesPlugin* base,
                                      const gchar* text);
static gchar* enotes_color_real_convert (ENotesPlugin* base,
                                  const gchar* line_);
static GeeList* enotes_color_real_get_blacklist_members (ENotesPlugin* base);
VALA_EXTERN BLMember* bl_member_new (GRegex* reg,
                         const gchar* replace);
VALA_EXTERN BLMember* bl_member_construct (GType object_type,
                               GRegex* reg,
                               const gchar* replace);
VALA_EXTERN ENotesColor* enotes_color_new (void);
VALA_EXTERN ENotesColor* enotes_color_construct (GType object_type);
VALA_EXTERN ENotesPlugin* enotes_plugin_construct (GType object_type);
static GObject * enotes_color_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties);
static void enotes_color_finalize (GObject * obj);
static GType enotes_color_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GRegex* _tmp_regex_0 = NULL;

static inline gpointer
enotes_color_get_instance_private (ENotesColor* self)
{
	return G_STRUCT_MEMBER_P (self, ENotesColor_private_offset);
}

static gchar*
enotes_color_real_get_desctiption (ENotesPlugin* base)
{
	ENotesColor * self;
	gchar* _tmp0_;
	gchar* result;
	self = (ENotesColor*) base;
	_tmp0_ = g_strdup (_ ("Set font color for the line with <color [#color]> or for some text wit" \
"h <color [color] [text]>"));
	result = _tmp0_;
	return result;
}

static gchar*
enotes_color_real_get_name (ENotesPlugin* base)
{
	ENotesColor * self;
	gchar* _tmp0_;
	gchar* result;
	self = (ENotesColor*) base;
	_tmp0_ = g_strdup (_ ("Font color"));
	result = _tmp0_;
	return result;
}

static void
__lambda4_ (ENotesColor* self)
{
	GtkColorChooserWidget* _tmp0_;
	_tmp0_ = self->priv->color_selector;
	g_object_set (_tmp0_, "show-editor", FALSE, NULL);
}

static void
___lambda4__gtk_widget_hide (GtkWidget* _sender,
                             gpointer self)
{
	__lambda4_ ((ENotesColor*) self);
}

static void
__lambda5_ (ENotesColor* self)
{
	GtkPopover* _tmp0_;
	const gchar* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	_tmp0_ = self->priv->popover;
	gtk_widget_hide ((GtkWidget*) _tmp0_);
	_tmp1_ = self->priv->selection;
	_tmp2_ = strlen (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ > 0) {
		GtkColorChooserWidget* _tmp4_;
		GdkRGBA _tmp5_ = {0};
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		const gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp4_ = self->priv->color_selector;
		gtk_color_chooser_get_rgba ((GtkColorChooser*) _tmp4_, &_tmp5_);
		_tmp6_ = gdk_rgba_to_string (&_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_strconcat ("<color ", _tmp7_, NULL);
		_tmp9_ = _tmp8_;
		_tmp10_ = g_strconcat (_tmp9_, " ", NULL);
		_tmp11_ = _tmp10_;
		_tmp12_ = self->priv->selection;
		_tmp13_ = g_strconcat (_tmp11_, _tmp12_, NULL);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_strconcat (_tmp14_, ">", NULL);
		_tmp16_ = _tmp15_;
		g_signal_emit_by_name ((ENotesPlugin*) self, "string-cooked", _tmp16_);
		_g_free0 (_tmp16_);
		_g_free0 (_tmp14_);
		_g_free0 (_tmp11_);
		_g_free0 (_tmp9_);
		_g_free0 (_tmp7_);
	} else {
		GtkColorChooserWidget* _tmp17_;
		GdkRGBA _tmp18_ = {0};
		gchar* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		_tmp17_ = self->priv->color_selector;
		gtk_color_chooser_get_rgba ((GtkColorChooser*) _tmp17_, &_tmp18_);
		_tmp19_ = gdk_rgba_to_string (&_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = g_strconcat ("<color ", _tmp20_, NULL);
		_tmp22_ = _tmp21_;
		_tmp23_ = g_strconcat (_tmp22_, ">", NULL);
		_tmp24_ = _tmp23_;
		g_signal_emit_by_name ((ENotesPlugin*) self, "string-cooked", _tmp24_);
		_g_free0 (_tmp24_);
		_g_free0 (_tmp22_);
		_g_free0 (_tmp20_);
	}
}

static void
___lambda5__gtk_color_chooser_color_activated (GtkColorChooser* _sender,
                                               GdkRGBA* color,
                                               gpointer self)
{
	__lambda5_ ((ENotesColor*) self);
}

static GtkWidget*
enotes_color_real_editor_button (ENotesPlugin* base)
{
	ENotesColor * self;
	GtkImage* image = NULL;
	GtkImage* _tmp0_;
	GtkPopover* _tmp1_;
	GtkColorChooserWidget* _tmp2_;
	GtkColorChooserWidget* _tmp3_;
	GtkPopover* _tmp4_;
	GtkColorChooserWidget* _tmp5_;
	GtkPopover* _tmp6_;
	GtkColorChooserWidget* _tmp7_;
	GtkWidget* result;
	self = (ENotesColor*) base;
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("applications-graphics", (GtkIconSize) GTK_ICON_SIZE_SMALL_TOOLBAR);
	g_object_ref_sink (_tmp0_);
	image = _tmp0_;
	_tmp1_ = (GtkPopover*) gtk_popover_new ((GtkWidget*) image);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->popover);
	self->priv->popover = _tmp1_;
	_tmp2_ = (GtkColorChooserWidget*) gtk_color_chooser_widget_new ();
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->color_selector);
	self->priv->color_selector = _tmp2_;
	_tmp3_ = self->priv->color_selector;
	g_object_set ((GtkWidget*) _tmp3_, "margin", 6, NULL);
	_tmp4_ = self->priv->popover;
	_tmp5_ = self->priv->color_selector;
	gtk_container_add ((GtkContainer*) _tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->popover;
	g_signal_connect_object ((GtkWidget*) _tmp6_, "hide", (GCallback) ___lambda4__gtk_widget_hide, self, 0);
	_tmp7_ = self->priv->color_selector;
	g_signal_connect_object ((GtkColorChooser*) _tmp7_, "color-activated", (GCallback) ___lambda5__gtk_color_chooser_color_activated, self, 0);
	result = (GtkWidget*) image;
	return result;
}

static gchar*
enotes_color_real_get_button_desctiption (ENotesPlugin* base)
{
	ENotesColor * self;
	gchar* _tmp0_;
	gchar* result;
	self = (ENotesColor*) base;
	_tmp0_ = g_strdup (_ ("Font color"));
	result = _tmp0_;
	return result;
}

static gchar*
enotes_color_real_request_string (ENotesPlugin* base,
                                  const gchar* selection)
{
	ENotesColor * self;
	GtkPopover* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	self = (ENotesColor*) base;
	g_return_val_if_fail (selection != NULL, NULL);
	_tmp0_ = self->priv->popover;
	gtk_widget_show_all ((GtkWidget*) _tmp0_);
	_tmp1_ = g_strdup (selection);
	_g_free0 (self->priv->selection);
	self->priv->selection = _tmp1_;
	_tmp2_ = g_strdup ("");
	result = _tmp2_;
	return result;
}

static gboolean
enotes_color_real_has_match (ENotesPlugin* base,
                             const gchar* text)
{
	ENotesColor * self;
	GPatternSpec* _tmp0_;
	gboolean result;
	self = (ENotesColor*) base;
	g_return_val_if_fail (text != NULL, FALSE);
	_tmp0_ = self->priv->spec;
	result = g_pattern_match_string (_tmp0_, text);
	return result;
}

static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static gint
string_index_of_char (const gchar* self,
                      gunichar c,
                      gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_strchr (((gchar*) self) + start_index, (gssize) -1, c);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static gchar*
enotes_color_real_convert (ENotesPlugin* base,
                           const gchar* line_)
{
	ENotesColor * self;
	gint chars = 0;
	gint _tmp0_;
	gint _tmp1_;
	gchar* line = NULL;
	gchar* _tmp2_;
	gchar* builed = NULL;
	gchar* _tmp3_;
	gint initial = 0;
	gint final = 0;
	gint last = 0;
	gint i = 0;
	const gchar* _tmp48_;
	const gchar* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	gchar* _tmp52_;
	gchar* _tmp53_;
	gchar* result;
	self = (ENotesColor*) base;
	g_return_val_if_fail (line_ != NULL, NULL);
	_tmp0_ = strlen (line_);
	_tmp1_ = _tmp0_;
	chars = _tmp1_;
	_tmp2_ = g_strconcat (line_, "     ", NULL);
	line = _tmp2_;
	_tmp3_ = g_strdup ("");
	builed = _tmp3_;
	initial = 0;
	final = 0;
	last = 0;
	{
		gboolean _tmp4_ = FALSE;
		i = -1;
		_tmp4_ = TRUE;
		while (TRUE) {
			const gchar* _tmp6_;
			if (!_tmp4_) {
				gint _tmp5_;
				i = i + 1;
				_tmp5_ = i;
			}
			_tmp4_ = FALSE;
			if (!(i < chars)) {
				break;
			}
			_tmp6_ = line;
			if (string_get (_tmp6_, (glong) i) == '<') {
				initial = i;
			} else {
				const gchar* _tmp7_;
				_tmp7_ = line;
				if (string_get (_tmp7_, (glong) i) == '>') {
					gchar* cut = NULL;
					const gchar* _tmp8_;
					gchar* _tmp9_;
					const gchar* _tmp10_;
					final = i;
					_tmp8_ = line;
					_tmp9_ = string_slice (_tmp8_, (glong) initial, (glong) final);
					cut = _tmp9_;
					_tmp10_ = cut;
					if (string_contains (_tmp10_, "<color ")) {
						gint index = 0;
						const gchar* _tmp11_;
						_tmp11_ = cut;
						index = string_index_of_char (_tmp11_, (gunichar) ' ', 7);
						if (index == -1) {
							const gchar* _tmp12_;
							const gchar* _tmp13_;
							gchar* _tmp14_;
							gchar* _tmp15_;
							gchar* _tmp16_;
							gchar* _tmp17_;
							const gchar* _tmp18_;
							gchar* _tmp19_;
							gchar* _tmp20_;
							gchar* _tmp21_;
							gchar* _tmp22_;
							gchar* _tmp23_;
							_tmp12_ = builed;
							_tmp13_ = line;
							_tmp14_ = string_slice (_tmp13_, (glong) last, (glong) initial);
							_tmp15_ = _tmp14_;
							_tmp16_ = g_strconcat (_tmp12_, _tmp15_, NULL);
							_tmp17_ = _tmp16_;
							_tmp18_ = cut;
							_tmp19_ = string_replace (_tmp18_, "<color ", "<color style=\"color:");
							_tmp20_ = _tmp19_;
							_tmp21_ = g_strconcat (_tmp17_, _tmp20_, NULL);
							_tmp22_ = _tmp21_;
							_tmp23_ = g_strconcat (_tmp22_, "\"", NULL);
							_g_free0 (builed);
							builed = _tmp23_;
							_g_free0 (_tmp22_);
							_g_free0 (_tmp20_);
							_g_free0 (_tmp17_);
							_g_free0 (_tmp15_);
							last = final;
						} else {
							const gchar* _tmp24_;
							const gchar* _tmp25_;
							gchar* _tmp26_;
							gchar* _tmp27_;
							gchar* _tmp28_;
							gchar* _tmp29_;
							const gchar* _tmp30_;
							gchar* _tmp31_;
							gchar* _tmp32_;
							gchar* _tmp33_;
							gchar* _tmp34_;
							gchar* _tmp35_;
							gchar* _tmp36_;
							gchar* _tmp37_;
							gchar* _tmp38_;
							const gchar* _tmp39_;
							const gchar* _tmp40_;
							gint _tmp41_;
							gint _tmp42_;
							gchar* _tmp43_;
							gchar* _tmp44_;
							gchar* _tmp45_;
							gchar* _tmp46_;
							gchar* _tmp47_;
							_tmp24_ = builed;
							_tmp25_ = line;
							_tmp26_ = string_slice (_tmp25_, (glong) last, (glong) initial);
							_tmp27_ = _tmp26_;
							_tmp28_ = g_strconcat (_tmp24_, _tmp27_, NULL);
							_tmp29_ = _tmp28_;
							_tmp30_ = cut;
							_tmp31_ = string_slice (_tmp30_, (glong) 0, (glong) index);
							_tmp32_ = _tmp31_;
							_tmp33_ = string_replace (_tmp32_, "<color ", "<color style=\"color:");
							_tmp34_ = _tmp33_;
							_tmp35_ = g_strconcat (_tmp29_, _tmp34_, NULL);
							_tmp36_ = _tmp35_;
							_tmp37_ = g_strconcat (_tmp36_, "\">", NULL);
							_tmp38_ = _tmp37_;
							_tmp39_ = cut;
							_tmp40_ = cut;
							_tmp41_ = strlen (_tmp40_);
							_tmp42_ = _tmp41_;
							_tmp43_ = string_slice (_tmp39_, (glong) index, (glong) _tmp42_);
							_tmp44_ = _tmp43_;
							_tmp45_ = g_strconcat (_tmp38_, _tmp44_, NULL);
							_tmp46_ = _tmp45_;
							_tmp47_ = g_strconcat (_tmp46_, "</color>", NULL);
							_g_free0 (builed);
							builed = _tmp47_;
							_g_free0 (_tmp46_);
							_g_free0 (_tmp44_);
							_g_free0 (_tmp38_);
							_g_free0 (_tmp36_);
							_g_free0 (_tmp34_);
							_g_free0 (_tmp32_);
							_g_free0 (_tmp29_);
							_g_free0 (_tmp27_);
							last = final + 1;
						}
					}
					_g_free0 (cut);
				}
			}
		}
	}
	_tmp48_ = builed;
	_tmp49_ = line;
	_tmp50_ = string_slice (_tmp49_, (glong) last, (glong) i);
	_tmp51_ = _tmp50_;
	_tmp52_ = g_strconcat (_tmp48_, _tmp51_, NULL);
	_tmp53_ = _tmp52_;
	_g_free0 (_tmp51_);
	result = _tmp53_;
	_g_free0 (builed);
	_g_free0 (line);
	return result;
}

static inline GRegex*
_thread_safe_regex_init (GRegex** re,
                         const gchar * pattern,
                         GRegexCompileFlags compile_flags)
{
	if (g_once_init_enter ((volatile gsize*) re)) {
		GRegex* val = g_regex_new (pattern, compile_flags, 0, NULL);
		g_once_init_leave ((volatile gsize*) re, (gsize) val);
	}
	return *re;
}

static GeeList*
enotes_color_real_get_blacklist_members (ENotesPlugin* base)
{
	ENotesColor * self;
	GeeLinkedList* list = NULL;
	GeeLinkedList* _tmp0_;
	BLMember* _tmp1_;
	BLMember* _tmp2_;
	GeeList* result;
	self = (ENotesColor*) base;
	_tmp0_ = gee_linked_list_new (TYPE_BL_MEMBER, (GBoxedCopyFunc) bl_member_ref, (GDestroyNotify) bl_member_unref, NULL, NULL, NULL);
	list = _tmp0_;
	_tmp1_ = bl_member_new (_thread_safe_regex_init (&_tmp_regex_0, "<color #[\\d\\p{L}]{6}>", 0), "");
	_tmp2_ = _tmp1_;
	gee_abstract_collection_add ((GeeAbstractCollection*) list, _tmp2_);
	_bl_member_unref0 (_tmp2_);
	result = (GeeList*) list;
	return result;
}

ENotesColor*
enotes_color_construct (GType object_type)
{
	ENotesColor * self = NULL;
	self = (ENotesColor*) enotes_plugin_construct (object_type);
	return self;
}

ENotesColor*
enotes_color_new (void)
{
	return enotes_color_construct (ENOTES_TYPE_COLOR);
}

static GObject *
enotes_color_constructor (GType type,
                          guint n_construct_properties,
                          GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ENotesColor * self;
	gchar* _tmp0_;
	parent_class = G_OBJECT_CLASS (enotes_color_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_COLOR, ENotesColor);
	_tmp0_ = g_strdup ("ENOTES.COLORS");
	_g_free0 (((ENotesPlugin*) self)->code_name);
	((ENotesPlugin*) self)->code_name = _tmp0_;
	return obj;
}

static void
enotes_color_class_init (ENotesColorClass * klass,
                         gpointer klass_data)
{
	enotes_color_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ENotesColor_private_offset);
	((ENotesPluginClass *) klass)->get_desctiption = (gchar* (*) (ENotesPlugin*)) enotes_color_real_get_desctiption;
	((ENotesPluginClass *) klass)->get_name = (gchar* (*) (ENotesPlugin*)) enotes_color_real_get_name;
	((ENotesPluginClass *) klass)->editor_button = (GtkWidget* (*) (ENotesPlugin*)) enotes_color_real_editor_button;
	((ENotesPluginClass *) klass)->get_button_desctiption = (gchar* (*) (ENotesPlugin*)) enotes_color_real_get_button_desctiption;
	((ENotesPluginClass *) klass)->request_string = (gchar* (*) (ENotesPlugin*, const gchar*)) enotes_color_real_request_string;
	((ENotesPluginClass *) klass)->has_match = (gboolean (*) (ENotesPlugin*, const gchar*)) enotes_color_real_has_match;
	((ENotesPluginClass *) klass)->convert = (gchar* (*) (ENotesPlugin*, const gchar*)) enotes_color_real_convert;
	((ENotesPluginClass *) klass)->get_blacklist_members = (GeeList* (*) (ENotesPlugin*)) enotes_color_real_get_blacklist_members;
	G_OBJECT_CLASS (klass)->constructor = enotes_color_constructor;
	G_OBJECT_CLASS (klass)->finalize = enotes_color_finalize;
}

static void
enotes_color_instance_init (ENotesColor * self,
                            gpointer klass)
{
	GPatternSpec* _tmp0_;
	self->priv = enotes_color_get_instance_private (self);
	_tmp0_ = g_pattern_spec_new ("*<color *>*");
	self->priv->spec = _tmp0_;
}

static void
enotes_color_finalize (GObject * obj)
{
	ENotesColor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_COLOR, ENotesColor);
	_g_pattern_spec_free0 (self->priv->spec);
	_g_object_unref0 (self->priv->color_selector);
	_g_object_unref0 (self->priv->popover);
	_g_free0 (self->priv->selection);
	G_OBJECT_CLASS (enotes_color_parent_class)->finalize (obj);
}

static GType
enotes_color_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesColorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_color_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesColor), 0, (GInstanceInitFunc) enotes_color_instance_init, NULL };
	GType enotes_color_type_id;
	enotes_color_type_id = g_type_register_static (ENOTES_TYPE_PLUGIN, "ENotesColor", &g_define_type_info, 0);
	ENotesColor_private_offset = g_type_add_instance_private (enotes_color_type_id, sizeof (ENotesColorPrivate));
	return enotes_color_type_id;
}

GType
enotes_color_get_type (void)
{
	static volatile gsize enotes_color_type_id__once = 0;
	if (g_once_init_enter (&enotes_color_type_id__once)) {
		GType enotes_color_type_id;
		enotes_color_type_id = enotes_color_get_type_once ();
		g_once_init_leave (&enotes_color_type_id__once, enotes_color_type_id);
	}
	return enotes_color_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

