/* templates_dialogs.c generated by valac 0.29.2.2-472d4, the Vala compiler
 * generated from templates_dialogs.vala, do not modify */

/*
 * This file is part of LaTeXila.
 *
 * Copyright © 2012 Sébastien Wilmet
 *
 * LaTeXila 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.
 *
 * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <gtksourceview/gtksource.h>
#include <gobject/gvaluecollector.h>


#define TYPE_OPEN_TEMPLATE_DIALOG (open_template_dialog_get_type ())
#define OPEN_TEMPLATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_OPEN_TEMPLATE_DIALOG, OpenTemplateDialog))
#define OPEN_TEMPLATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_OPEN_TEMPLATE_DIALOG, OpenTemplateDialogClass))
#define IS_OPEN_TEMPLATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_OPEN_TEMPLATE_DIALOG))
#define IS_OPEN_TEMPLATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_OPEN_TEMPLATE_DIALOG))
#define OPEN_TEMPLATE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_OPEN_TEMPLATE_DIALOG, OpenTemplateDialogClass))

typedef struct _OpenTemplateDialog OpenTemplateDialog;
typedef struct _OpenTemplateDialogClass OpenTemplateDialogClass;
typedef struct _OpenTemplateDialogPrivate OpenTemplateDialogPrivate;

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define TYPE_TEMPLATES (templates_get_type ())
#define TEMPLATES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEMPLATES, Templates))
#define TEMPLATES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEMPLATES, TemplatesClass))
#define IS_TEMPLATES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEMPLATES))
#define IS_TEMPLATES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEMPLATES))
#define TEMPLATES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEMPLATES, TemplatesClass))

typedef struct _Templates Templates;
typedef struct _TemplatesClass TemplatesClass;
typedef struct _Block32Data Block32Data;
#define _open_template_dialog_unref0(var) ((var == NULL) ? NULL : (var = (open_template_dialog_unref (var), NULL)))
#define __g_list_free__gtk_tree_path_free0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__gtk_tree_path_free0_ (var), NULL)))
#define _gtk_tree_path_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define TYPE_DOCUMENT_TAB (document_tab_get_type ())
#define DOCUMENT_TAB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT_TAB, DocumentTab))
#define DOCUMENT_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_TAB, DocumentTabClass))
#define IS_DOCUMENT_TAB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT_TAB))
#define IS_DOCUMENT_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_TAB))
#define DOCUMENT_TAB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_TAB, DocumentTabClass))

typedef struct _DocumentTab DocumentTab;
typedef struct _DocumentTabClass DocumentTabClass;

#define TYPE_DOCUMENT (document_get_type ())
#define DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT, Document))
#define DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT, DocumentClass))
#define IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT))
#define IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT))
#define DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT, DocumentClass))

typedef struct _Document Document;
typedef struct _DocumentClass DocumentClass;
typedef struct _ParamSpecOpenTemplateDialog ParamSpecOpenTemplateDialog;

#define TYPE_CREATE_TEMPLATE_DIALOG (create_template_dialog_get_type ())
#define CREATE_TEMPLATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CREATE_TEMPLATE_DIALOG, CreateTemplateDialog))
#define CREATE_TEMPLATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CREATE_TEMPLATE_DIALOG, CreateTemplateDialogClass))
#define IS_CREATE_TEMPLATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CREATE_TEMPLATE_DIALOG))
#define IS_CREATE_TEMPLATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CREATE_TEMPLATE_DIALOG))
#define CREATE_TEMPLATE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CREATE_TEMPLATE_DIALOG, CreateTemplateDialogClass))

typedef struct _CreateTemplateDialog CreateTemplateDialog;
typedef struct _CreateTemplateDialogClass CreateTemplateDialogClass;
typedef struct _CreateTemplateDialogPrivate CreateTemplateDialogPrivate;

#define TYPE_DELETE_TEMPLATE_DIALOG (delete_template_dialog_get_type ())
#define DELETE_TEMPLATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DELETE_TEMPLATE_DIALOG, DeleteTemplateDialog))
#define DELETE_TEMPLATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DELETE_TEMPLATE_DIALOG, DeleteTemplateDialogClass))
#define IS_DELETE_TEMPLATE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DELETE_TEMPLATE_DIALOG))
#define IS_DELETE_TEMPLATE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DELETE_TEMPLATE_DIALOG))
#define DELETE_TEMPLATE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DELETE_TEMPLATE_DIALOG, DeleteTemplateDialogClass))

typedef struct _DeleteTemplateDialog DeleteTemplateDialog;
typedef struct _DeleteTemplateDialogClass DeleteTemplateDialogClass;
typedef struct _DeleteTemplateDialogPrivate DeleteTemplateDialogPrivate;
#define _gtk_tree_row_reference_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_row_reference_free (var), NULL)))
#define __g_list_free__gtk_tree_row_reference_free0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__gtk_tree_row_reference_free0_ (var), NULL)))

struct _OpenTemplateDialog {
	GTypeInstance parent_instance;
	volatile int ref_count;
	OpenTemplateDialogPrivate * priv;
};

struct _OpenTemplateDialogClass {
	GTypeClass parent_class;
	void (*finalize) (OpenTemplateDialog *self);
};

struct _OpenTemplateDialogPrivate {
	MainWindow* _main_window;
	GtkDialog* _dialog;
	GtkTreeView* _default_templates;
	GtkTreeView* _personal_templates;
};

struct _Block32Data {
	int _ref_count_;
	OpenTemplateDialog* self;
	GtkTreeSelection* default_select;
	GtkTreeSelection* personal_select;
};

struct _ParamSpecOpenTemplateDialog {
	GParamSpec parent_instance;
};

struct _CreateTemplateDialog {
	GtkDialog parent_instance;
	CreateTemplateDialogPrivate * priv;
};

struct _CreateTemplateDialogClass {
	GtkDialogClass parent_class;
};

struct _DeleteTemplateDialog {
	GtkDialog parent_instance;
	DeleteTemplateDialogPrivate * priv;
};

struct _DeleteTemplateDialogClass {
	GtkDialogClass parent_class;
};


static gpointer open_template_dialog_parent_class = NULL;
static gpointer create_template_dialog_parent_class = NULL;
static gpointer delete_template_dialog_parent_class = NULL;

gpointer open_template_dialog_ref (gpointer instance);
void open_template_dialog_unref (gpointer instance);
GParamSpec* param_spec_open_template_dialog (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_open_template_dialog (GValue* value, gpointer v_object);
void value_take_open_template_dialog (GValue* value, gpointer v_object);
gpointer value_get_open_template_dialog (const GValue* value);
GType open_template_dialog_get_type (void) G_GNUC_CONST;
GType main_window_get_type (void) G_GNUC_CONST;
#define OPEN_TEMPLATE_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_OPEN_TEMPLATE_DIALOG, OpenTemplateDialogPrivate))
enum  {
	OPEN_TEMPLATE_DIALOG_DUMMY_PROPERTY
};
OpenTemplateDialog* open_template_dialog_new (MainWindow* main_window);
OpenTemplateDialog* open_template_dialog_construct (GType object_type, MainWindow* main_window);
GType templates_get_type (void) G_GNUC_CONST;
Templates* templates_get_default (void);
GtkTreeView* templates_get_default_templates_list (Templates* self);
GtkScrolledWindow* utils_add_scrollbar (GtkWidget* child);
GtkGrid* utils_get_dialog_component (const gchar* title, GtkWidget* widget);
GtkTreeView* templates_get_personal_templates_list (Templates* self);
static void open_template_dialog_connect_to_signals (OpenTemplateDialog* self);
static void open_template_dialog_run_me (OpenTemplateDialog* self);
static Block32Data* block32_data_ref (Block32Data* _data32_);
static void block32_data_unref (void * _userdata_);
static void __lambda95_ (Block32Data* _data32_);
static void open_template_dialog_on_list_selection_changed (OpenTemplateDialog* self, GtkTreeSelection* select, GtkTreeSelection* other_select);
static void ___lambda95__gtk_tree_selection_changed (GtkTreeSelection* _sender, gpointer self);
static void __lambda96_ (Block32Data* _data32_);
static void ___lambda96__gtk_tree_selection_changed (GtkTreeSelection* _sender, gpointer self);
static void __lambda97_ (OpenTemplateDialog* self, GtkTreePath* path);
static void open_template_dialog_open_default_template (OpenTemplateDialog* self, GtkTreePath* path);
static void ___lambda97__gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self);
static void __lambda98_ (OpenTemplateDialog* self, GtkTreePath* path);
static void open_template_dialog_open_personal_template (OpenTemplateDialog* self, GtkTreePath* path);
static void ___lambda98__gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self);
static void _gtk_tree_path_free0_ (gpointer var);
static void _g_list_free__gtk_tree_path_free0_ (GList* self);
static void open_template_dialog_create_document (OpenTemplateDialog* self, const gchar* contents);
gchar* templates_get_default_template_contents (Templates* self, GtkTreePath* path);
gchar* templates_get_personal_template_contents (Templates* self, GtkTreePath* path);
GType document_tab_get_type (void) G_GNUC_CONST;
DocumentTab* main_window_create_tab (MainWindow* self, gboolean jump_to);
GType document_get_type (void) G_GNUC_CONST;
Document* document_tab_get_document (DocumentTab* self);
void document_set_contents (Document* self, const gchar* contents);
static void open_template_dialog_finalize (OpenTemplateDialog* obj);
GType create_template_dialog_get_type (void) G_GNUC_CONST;
enum  {
	CREATE_TEMPLATE_DIALOG_DUMMY_PROPERTY
};
CreateTemplateDialog* create_template_dialog_new (MainWindow* parent);
CreateTemplateDialog* create_template_dialog_construct (GType object_type, MainWindow* parent);
DocumentTab* main_window_get_active_tab (MainWindow* self);
static void create_template_dialog_run_me (CreateTemplateDialog* self, MainWindow* parent, GtkEntry* entry, GtkTreeView* templates_list);
Document* main_window_get_active_document (MainWindow* self);
gchar* templates_get_icon_id (Templates* self, GtkTreePath* default_template_path);
void templates_create_personal_template (Templates* self, const gchar* name, const gchar* icon_id, const gchar* contents);
GType delete_template_dialog_get_type (void) G_GNUC_CONST;
enum  {
	DELETE_TEMPLATE_DIALOG_DUMMY_PROPERTY
};
DeleteTemplateDialog* delete_template_dialog_new (MainWindow* parent);
DeleteTemplateDialog* delete_template_dialog_construct (GType object_type, MainWindow* parent);
static void delete_template_dialog_run_me (DeleteTemplateDialog* self, GtkTreeView* templates_list);
void templates_delete_personal_template (Templates* self, GtkTreePath* template_path);
static void _gtk_tree_row_reference_free0_ (gpointer var);
static void _g_list_free__gtk_tree_row_reference_free0_ (GList* self);
void templates_save_rc_file (Templates* self);


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


OpenTemplateDialog* open_template_dialog_construct (GType object_type, MainWindow* main_window) {
	OpenTemplateDialog* self = NULL;
	MainWindow* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	MainWindow* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	GtkDialog* _tmp5_ = NULL;
	GtkBox* content_area = NULL;
	GtkDialog* _tmp6_ = NULL;
	GtkBox* _tmp7_ = NULL;
	GtkBox* _tmp8_ = NULL;
	GtkGrid* hgrid = NULL;
	GtkGrid* _tmp9_ = NULL;
	Templates* templates = NULL;
	Templates* _tmp10_ = NULL;
	GtkTreeView* _tmp11_ = NULL;
	GtkScrolledWindow* scrollbar = NULL;
	GtkTreeView* _tmp12_ = NULL;
	GtkScrolledWindow* _tmp13_ = NULL;
	GtkScrolledWindow* _tmp14_ = NULL;
	GtkScrolledWindow* _tmp15_ = NULL;
	GtkWidget* component = NULL;
	const gchar* _tmp16_ = NULL;
	GtkScrolledWindow* _tmp17_ = NULL;
	GtkGrid* _tmp18_ = NULL;
	GtkWidget* _tmp19_ = NULL;
	GtkTreeView* _tmp20_ = NULL;
	GtkTreeView* _tmp21_ = NULL;
	GtkScrolledWindow* _tmp22_ = NULL;
	GtkScrolledWindow* _tmp23_ = NULL;
	GtkScrolledWindow* _tmp24_ = NULL;
	const gchar* _tmp25_ = NULL;
	GtkScrolledWindow* _tmp26_ = NULL;
	GtkGrid* _tmp27_ = NULL;
	GtkWidget* _tmp28_ = NULL;
	GtkDialog* _tmp29_ = NULL;
	g_return_val_if_fail (main_window != NULL, NULL);
	self = (OpenTemplateDialog*) g_type_create_instance (object_type);
	_tmp0_ = main_window;
	self->priv->_main_window = _tmp0_;
	_tmp1_ = _ ("New File...");
	_tmp2_ = main_window;
	_tmp3_ = _ ("_Cancel");
	_tmp4_ = _ ("_OK");
	_tmp5_ = (GtkDialog*) gtk_dialog_new_with_buttons (_tmp1_, (GtkWindow*) _tmp2_, GTK_DIALOG_DESTROY_WITH_PARENT, _tmp3_, GTK_RESPONSE_REJECT, _tmp4_, GTK_RESPONSE_ACCEPT, NULL);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->_dialog);
	self->priv->_dialog = _tmp5_;
	_tmp6_ = self->priv->_dialog;
	_tmp7_ = (GtkBox*) gtk_dialog_get_content_area (_tmp6_);
	_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, gtk_box_get_type ()) ? ((GtkBox*) _tmp7_) : NULL);
	content_area = _tmp8_;
	_tmp9_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp9_);
	hgrid = _tmp9_;
	gtk_orientable_set_orientation ((GtkOrientable*) hgrid, GTK_ORIENTATION_HORIZONTAL);
	gtk_grid_set_column_spacing (hgrid, (guint) 10);
	gtk_box_pack_start (content_area, (GtkWidget*) hgrid, TRUE, TRUE, (guint) 0);
	_tmp10_ = templates_get_default ();
	templates = _tmp10_;
	_tmp11_ = templates_get_default_templates_list (templates);
	_g_object_unref0 (self->priv->_default_templates);
	self->priv->_default_templates = _tmp11_;
	_tmp12_ = self->priv->_default_templates;
	_tmp13_ = utils_add_scrollbar ((GtkWidget*) _tmp12_);
	scrollbar = _tmp13_;
	_tmp14_ = scrollbar;
	gtk_scrolled_window_set_shadow_type (_tmp14_, GTK_SHADOW_IN);
	_tmp15_ = scrollbar;
	gtk_widget_set_size_request ((GtkWidget*) _tmp15_, 250, 200);
	_tmp16_ = _ ("Default templates");
	_tmp17_ = scrollbar;
	_tmp18_ = utils_get_dialog_component (_tmp16_, (GtkWidget*) _tmp17_);
	component = (GtkWidget*) _tmp18_;
	_tmp19_ = component;
	gtk_container_add ((GtkContainer*) hgrid, _tmp19_);
	_tmp20_ = templates_get_personal_templates_list (templates);
	_g_object_unref0 (self->priv->_personal_templates);
	self->priv->_personal_templates = _tmp20_;
	_tmp21_ = self->priv->_personal_templates;
	_tmp22_ = utils_add_scrollbar ((GtkWidget*) _tmp21_);
	_g_object_unref0 (scrollbar);
	scrollbar = _tmp22_;
	_tmp23_ = scrollbar;
	gtk_scrolled_window_set_shadow_type (_tmp23_, GTK_SHADOW_IN);
	_tmp24_ = scrollbar;
	gtk_widget_set_size_request ((GtkWidget*) _tmp24_, 250, 200);
	_tmp25_ = _ ("Your personal templates");
	_tmp26_ = scrollbar;
	_tmp27_ = utils_get_dialog_component (_tmp25_, (GtkWidget*) _tmp26_);
	_g_object_unref0 (component);
	component = (GtkWidget*) _tmp27_;
	_tmp28_ = component;
	gtk_container_add ((GtkContainer*) hgrid, _tmp28_);
	gtk_widget_show_all ((GtkWidget*) content_area);
	open_template_dialog_connect_to_signals (self);
	open_template_dialog_run_me (self);
	_tmp29_ = self->priv->_dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp29_);
	_g_object_unref0 (component);
	_g_object_unref0 (scrollbar);
	_g_object_unref0 (templates);
	_g_object_unref0 (hgrid);
	_g_object_unref0 (content_area);
	return self;
}


OpenTemplateDialog* open_template_dialog_new (MainWindow* main_window) {
	return open_template_dialog_construct (TYPE_OPEN_TEMPLATE_DIALOG, main_window);
}


static Block32Data* block32_data_ref (Block32Data* _data32_) {
	g_atomic_int_inc (&_data32_->_ref_count_);
	return _data32_;
}


static void block32_data_unref (void * _userdata_) {
	Block32Data* _data32_;
	_data32_ = (Block32Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data32_->_ref_count_)) {
		OpenTemplateDialog* self;
		self = _data32_->self;
		_g_object_unref0 (_data32_->personal_select);
		_g_object_unref0 (_data32_->default_select);
		_open_template_dialog_unref0 (self);
		g_slice_free (Block32Data, _data32_);
	}
}


static void __lambda95_ (Block32Data* _data32_) {
	OpenTemplateDialog* self;
	self = _data32_->self;
	open_template_dialog_on_list_selection_changed (self, _data32_->default_select, _data32_->personal_select);
}


static void ___lambda95__gtk_tree_selection_changed (GtkTreeSelection* _sender, gpointer self) {
	__lambda95_ (self);
}


static void __lambda96_ (Block32Data* _data32_) {
	OpenTemplateDialog* self;
	self = _data32_->self;
	open_template_dialog_on_list_selection_changed (self, _data32_->personal_select, _data32_->default_select);
}


static void ___lambda96__gtk_tree_selection_changed (GtkTreeSelection* _sender, gpointer self) {
	__lambda96_ (self);
}


static void __lambda97_ (OpenTemplateDialog* self, GtkTreePath* path) {
	GtkTreePath* _tmp0_ = NULL;
	GtkDialog* _tmp1_ = NULL;
	g_return_if_fail (path != NULL);
	_tmp0_ = path;
	open_template_dialog_open_default_template (self, _tmp0_);
	_tmp1_ = self->priv->_dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp1_);
}


static void ___lambda97__gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self) {
	__lambda97_ ((OpenTemplateDialog*) self, path);
}


static void __lambda98_ (OpenTemplateDialog* self, GtkTreePath* path) {
	GtkTreePath* _tmp0_ = NULL;
	GtkDialog* _tmp1_ = NULL;
	g_return_if_fail (path != NULL);
	_tmp0_ = path;
	open_template_dialog_open_personal_template (self, _tmp0_);
	_tmp1_ = self->priv->_dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp1_);
}


static void ___lambda98__gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self) {
	__lambda98_ ((OpenTemplateDialog*) self, path);
}


static void open_template_dialog_connect_to_signals (OpenTemplateDialog* self) {
	Block32Data* _data32_;
	GtkTreeView* _tmp0_ = NULL;
	GtkTreeSelection* _tmp1_ = NULL;
	GtkTreeSelection* _tmp2_ = NULL;
	GtkTreeView* _tmp3_ = NULL;
	GtkTreeSelection* _tmp4_ = NULL;
	GtkTreeSelection* _tmp5_ = NULL;
	GtkTreeView* _tmp6_ = NULL;
	GtkTreeView* _tmp7_ = NULL;
	g_return_if_fail (self != NULL);
	_data32_ = g_slice_new0 (Block32Data);
	_data32_->_ref_count_ = 1;
	_data32_->self = open_template_dialog_ref (self);
	_tmp0_ = self->priv->_default_templates;
	_tmp1_ = gtk_tree_view_get_selection (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_data32_->default_select = _tmp2_;
	_tmp3_ = self->priv->_personal_templates;
	_tmp4_ = gtk_tree_view_get_selection (_tmp3_);
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_data32_->personal_select = _tmp5_;
	g_signal_connect_data (_data32_->default_select, "changed", (GCallback) ___lambda95__gtk_tree_selection_changed, block32_data_ref (_data32_), (GClosureNotify) block32_data_unref, 0);
	g_signal_connect_data (_data32_->personal_select, "changed", (GCallback) ___lambda96__gtk_tree_selection_changed, block32_data_ref (_data32_), (GClosureNotify) block32_data_unref, 0);
	_tmp6_ = self->priv->_default_templates;
	g_signal_connect (_tmp6_, "row-activated", (GCallback) ___lambda97__gtk_tree_view_row_activated, self);
	_tmp7_ = self->priv->_personal_templates;
	g_signal_connect (_tmp7_, "row-activated", (GCallback) ___lambda98__gtk_tree_view_row_activated, self);
	block32_data_unref (_data32_);
	_data32_ = NULL;
}


static void _gtk_tree_path_free0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL));
}


static void _g_list_free__gtk_tree_path_free0_ (GList* self) {
	g_list_foreach (self, (GFunc) _gtk_tree_path_free0_, NULL);
	g_list_free (self);
}


static void open_template_dialog_on_list_selection_changed (OpenTemplateDialog* self, GtkTreeSelection* select, GtkTreeSelection* other_select) {
	GList* selected_items = NULL;
	GtkTreeSelection* _tmp0_ = NULL;
	GList* _tmp1_ = NULL;
	GList* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	g_return_if_fail (self != NULL);
	g_return_if_fail (select != NULL);
	g_return_if_fail (other_select != NULL);
	_tmp0_ = select;
	_tmp1_ = gtk_tree_selection_get_selected_rows (_tmp0_, NULL);
	selected_items = _tmp1_;
	_tmp2_ = selected_items;
	_tmp3_ = g_list_length (_tmp2_);
	if (_tmp3_ > ((guint) 0)) {
		GtkTreeSelection* _tmp4_ = NULL;
		_tmp4_ = other_select;
		gtk_tree_selection_unselect_all (_tmp4_);
	}
	__g_list_free__gtk_tree_path_free0_0 (selected_items);
}


static gpointer _gtk_tree_path_copy0 (gpointer self) {
	return self ? gtk_tree_path_copy (self) : NULL;
}


static void open_template_dialog_run_me (OpenTemplateDialog* self) {
	GtkDialog* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	GtkTreeSelection* select = NULL;
	GtkTreeView* _tmp2_ = NULL;
	GtkTreeSelection* _tmp3_ = NULL;
	GtkTreeSelection* _tmp4_ = NULL;
	GList* selected_items = NULL;
	GtkTreeSelection* _tmp5_ = NULL;
	GList* _tmp6_ = NULL;
	GList* _tmp7_ = NULL;
	guint _tmp8_ = 0U;
	GtkTreeView* _tmp13_ = NULL;
	GtkTreeSelection* _tmp14_ = NULL;
	GtkTreeSelection* _tmp15_ = NULL;
	GtkTreeSelection* _tmp16_ = NULL;
	GList* _tmp17_ = NULL;
	GList* _tmp18_ = NULL;
	guint _tmp19_ = 0U;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_dialog;
	_tmp1_ = gtk_dialog_run (_tmp0_);
	if (_tmp1_ != ((gint) GTK_RESPONSE_ACCEPT)) {
		return;
	}
	_tmp2_ = self->priv->_default_templates;
	_tmp3_ = gtk_tree_view_get_selection (_tmp2_);
	_tmp4_ = _g_object_ref0 (_tmp3_);
	select = _tmp4_;
	_tmp5_ = select;
	_tmp6_ = gtk_tree_selection_get_selected_rows (_tmp5_, NULL);
	selected_items = _tmp6_;
	_tmp7_ = selected_items;
	_tmp8_ = g_list_length (_tmp7_);
	if (_tmp8_ > ((guint) 0)) {
		GtkTreePath* path = NULL;
		GList* _tmp9_ = NULL;
		gconstpointer _tmp10_ = NULL;
		GtkTreePath* _tmp11_ = NULL;
		GtkTreePath* _tmp12_ = NULL;
		_tmp9_ = selected_items;
		_tmp10_ = g_list_nth_data (_tmp9_, (guint) 0);
		_tmp11_ = _gtk_tree_path_copy0 ((GtkTreePath*) _tmp10_);
		path = _tmp11_;
		_tmp12_ = path;
		open_template_dialog_open_default_template (self, _tmp12_);
		_gtk_tree_path_free0 (path);
		__g_list_free__gtk_tree_path_free0_0 (selected_items);
		_g_object_unref0 (select);
		return;
	}
	_tmp13_ = self->priv->_personal_templates;
	_tmp14_ = gtk_tree_view_get_selection (_tmp13_);
	_tmp15_ = _g_object_ref0 (_tmp14_);
	_g_object_unref0 (select);
	select = _tmp15_;
	_tmp16_ = select;
	_tmp17_ = gtk_tree_selection_get_selected_rows (_tmp16_, NULL);
	__g_list_free__gtk_tree_path_free0_0 (selected_items);
	selected_items = _tmp17_;
	_tmp18_ = selected_items;
	_tmp19_ = g_list_length (_tmp18_);
	if (_tmp19_ > ((guint) 0)) {
		GtkTreePath* path = NULL;
		GList* _tmp20_ = NULL;
		gconstpointer _tmp21_ = NULL;
		GtkTreePath* _tmp22_ = NULL;
		GtkTreePath* _tmp23_ = NULL;
		_tmp20_ = selected_items;
		_tmp21_ = g_list_nth_data (_tmp20_, (guint) 0);
		_tmp22_ = _gtk_tree_path_copy0 ((GtkTreePath*) _tmp21_);
		path = _tmp22_;
		_tmp23_ = path;
		open_template_dialog_open_personal_template (self, _tmp23_);
		_gtk_tree_path_free0 (path);
		__g_list_free__gtk_tree_path_free0_0 (selected_items);
		_g_object_unref0 (select);
		return;
	}
	open_template_dialog_create_document (self, "");
	__g_list_free__gtk_tree_path_free0_0 (selected_items);
	_g_object_unref0 (select);
}


static void open_template_dialog_open_default_template (OpenTemplateDialog* self, GtkTreePath* path) {
	Templates* templates = NULL;
	Templates* _tmp0_ = NULL;
	GtkTreePath* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	_tmp0_ = templates_get_default ();
	templates = _tmp0_;
	_tmp1_ = path;
	_tmp2_ = templates_get_default_template_contents (templates, _tmp1_);
	_tmp3_ = _tmp2_;
	open_template_dialog_create_document (self, _tmp3_);
	_g_free0 (_tmp3_);
	_g_object_unref0 (templates);
}


static void open_template_dialog_open_personal_template (OpenTemplateDialog* self, GtkTreePath* path) {
	Templates* templates = NULL;
	Templates* _tmp0_ = NULL;
	GtkTreePath* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	_tmp0_ = templates_get_default ();
	templates = _tmp0_;
	_tmp1_ = path;
	_tmp2_ = templates_get_personal_template_contents (templates, _tmp1_);
	_tmp3_ = _tmp2_;
	open_template_dialog_create_document (self, _tmp3_);
	_g_free0 (_tmp3_);
	_g_object_unref0 (templates);
}


static void open_template_dialog_create_document (OpenTemplateDialog* self, const gchar* contents) {
	DocumentTab* tab = NULL;
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	Document* _tmp2_ = NULL;
	Document* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (contents != NULL);
	_tmp0_ = self->priv->_main_window;
	_tmp1_ = main_window_create_tab (_tmp0_, TRUE);
	tab = _tmp1_;
	_tmp2_ = document_tab_get_document (tab);
	_tmp3_ = _tmp2_;
	_tmp4_ = contents;
	document_set_contents (_tmp3_, _tmp4_);
	_g_object_unref0 (tab);
}


static void value_open_template_dialog_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void value_open_template_dialog_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		open_template_dialog_unref (value->data[0].v_pointer);
	}
}


static void value_open_template_dialog_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = open_template_dialog_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer value_open_template_dialog_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* value_open_template_dialog_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		OpenTemplateDialog* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = open_template_dialog_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_open_template_dialog_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	OpenTemplateDialog** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = open_template_dialog_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_open_template_dialog (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecOpenTemplateDialog* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_OPEN_TEMPLATE_DIALOG), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer value_get_open_template_dialog (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_OPEN_TEMPLATE_DIALOG), NULL);
	return value->data[0].v_pointer;
}


void value_set_open_template_dialog (GValue* value, gpointer v_object) {
	OpenTemplateDialog* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_OPEN_TEMPLATE_DIALOG));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_OPEN_TEMPLATE_DIALOG));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		open_template_dialog_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		open_template_dialog_unref (old);
	}
}


void value_take_open_template_dialog (GValue* value, gpointer v_object) {
	OpenTemplateDialog* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_OPEN_TEMPLATE_DIALOG));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_OPEN_TEMPLATE_DIALOG));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		open_template_dialog_unref (old);
	}
}


static void open_template_dialog_class_init (OpenTemplateDialogClass * klass) {
	open_template_dialog_parent_class = g_type_class_peek_parent (klass);
	((OpenTemplateDialogClass *) klass)->finalize = open_template_dialog_finalize;
	g_type_class_add_private (klass, sizeof (OpenTemplateDialogPrivate));
}


static void open_template_dialog_instance_init (OpenTemplateDialog * self) {
	self->priv = OPEN_TEMPLATE_DIALOG_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void open_template_dialog_finalize (OpenTemplateDialog* obj) {
	OpenTemplateDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_OPEN_TEMPLATE_DIALOG, OpenTemplateDialog);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->_dialog);
	_g_object_unref0 (self->priv->_default_templates);
	_g_object_unref0 (self->priv->_personal_templates);
}


GType open_template_dialog_get_type (void) {
	static volatile gsize open_template_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&open_template_dialog_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_open_template_dialog_init, value_open_template_dialog_free_value, value_open_template_dialog_copy_value, value_open_template_dialog_peek_pointer, "p", value_open_template_dialog_collect_value, "p", value_open_template_dialog_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (OpenTemplateDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) open_template_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (OpenTemplateDialog), 0, (GInstanceInitFunc) open_template_dialog_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType open_template_dialog_type_id;
		open_template_dialog_type_id = g_type_register_fundamental (g_type_fundamental_next (), "OpenTemplateDialog", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&open_template_dialog_type_id__volatile, open_template_dialog_type_id);
	}
	return open_template_dialog_type_id__volatile;
}


gpointer open_template_dialog_ref (gpointer instance) {
	OpenTemplateDialog* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void open_template_dialog_unref (gpointer instance) {
	OpenTemplateDialog* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		OPEN_TEMPLATE_DIALOG_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


CreateTemplateDialog* create_template_dialog_construct (GType object_type, MainWindow* parent) {
	CreateTemplateDialog * self = NULL;
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	MainWindow* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	GtkBox* content_area = NULL;
	GtkBox* _tmp7_ = NULL;
	GtkBox* _tmp8_ = NULL;
	GtkEntry* entry = NULL;
	GtkEntry* _tmp9_ = NULL;
	GtkWidget* component = NULL;
	const gchar* _tmp10_ = NULL;
	GtkGrid* _tmp11_ = NULL;
	GtkWidget* _tmp12_ = NULL;
	Templates* templates = NULL;
	Templates* _tmp13_ = NULL;
	GtkTreeView* templates_list = NULL;
	GtkTreeView* _tmp14_ = NULL;
	GtkScrolledWindow* scrollbar = NULL;
	GtkScrolledWindow* _tmp15_ = NULL;
	const gchar* _tmp16_ = NULL;
	GtkGrid* _tmp17_ = NULL;
	GtkWidget* _tmp18_ = NULL;
	MainWindow* _tmp19_ = NULL;
	g_return_val_if_fail (parent != NULL, NULL);
	self = (CreateTemplateDialog*) g_object_new (object_type, NULL);
	_tmp0_ = parent;
	_tmp1_ = main_window_get_active_tab (_tmp0_);
	_tmp2_ = _tmp1_;
	g_return_val_if_fail (_tmp2_ != NULL, NULL);
	_tmp3_ = _ ("New Template...");
	gtk_window_set_title ((GtkWindow*) self, _tmp3_);
	_tmp4_ = parent;
	gtk_window_set_transient_for ((GtkWindow*) self, (GtkWindow*) _tmp4_);
	gtk_window_set_destroy_with_parent ((GtkWindow*) self, TRUE);
	_tmp5_ = _ ("_Cancel");
	gtk_dialog_add_button ((GtkDialog*) self, _tmp5_, (gint) GTK_RESPONSE_REJECT);
	_tmp6_ = _ ("_OK");
	gtk_dialog_add_button ((GtkDialog*) self, _tmp6_, (gint) GTK_RESPONSE_ACCEPT);
	_tmp7_ = (GtkBox*) gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp7_, gtk_box_get_type ()) ? ((GtkBox*) _tmp7_) : NULL);
	content_area = _tmp8_;
	gtk_box_set_homogeneous (content_area, FALSE);
	_tmp9_ = (GtkEntry*) gtk_entry_new ();
	g_object_ref_sink (_tmp9_);
	entry = _tmp9_;
	gtk_widget_set_hexpand ((GtkWidget*) entry, TRUE);
	_tmp10_ = _ ("Name of the new template");
	_tmp11_ = utils_get_dialog_component (_tmp10_, (GtkWidget*) entry);
	component = (GtkWidget*) _tmp11_;
	_tmp12_ = component;
	gtk_box_pack_start (content_area, _tmp12_, FALSE, TRUE, (guint) 0);
	_tmp13_ = templates_get_default ();
	templates = _tmp13_;
	_tmp14_ = templates_get_default_templates_list (templates);
	templates_list = _tmp14_;
	_tmp15_ = utils_add_scrollbar ((GtkWidget*) templates_list);
	scrollbar = _tmp15_;
	gtk_scrolled_window_set_shadow_type (scrollbar, GTK_SHADOW_IN);
	gtk_widget_set_size_request ((GtkWidget*) scrollbar, 250, 200);
	_tmp16_ = _ ("Choose an icon");
	_tmp17_ = utils_get_dialog_component (_tmp16_, (GtkWidget*) scrollbar);
	_g_object_unref0 (component);
	component = (GtkWidget*) _tmp17_;
	_tmp18_ = component;
	gtk_box_pack_start (content_area, _tmp18_, TRUE, TRUE, (guint) 0);
	gtk_widget_show_all ((GtkWidget*) content_area);
	_tmp19_ = parent;
	create_template_dialog_run_me (self, _tmp19_, entry, templates_list);
	_g_object_unref0 (scrollbar);
	_g_object_unref0 (templates_list);
	_g_object_unref0 (templates);
	_g_object_unref0 (component);
	_g_object_unref0 (entry);
	_g_object_unref0 (content_area);
	return self;
}


CreateTemplateDialog* create_template_dialog_new (MainWindow* parent) {
	return create_template_dialog_construct (TYPE_CREATE_TEMPLATE_DIALOG, parent);
}


static void create_template_dialog_run_me (CreateTemplateDialog* self, MainWindow* parent, GtkEntry* entry, GtkTreeView* templates_list) {
	Templates* templates = NULL;
	Templates* _tmp0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (parent != NULL);
	g_return_if_fail (entry != NULL);
	g_return_if_fail (templates_list != NULL);
	_tmp0_ = templates_get_default ();
	templates = _tmp0_;
	while (TRUE) {
		gint _tmp1_ = 0;
		GtkEntry* _tmp2_ = NULL;
		guint _tmp3_ = 0U;
		guint _tmp4_ = 0U;
		GtkTreeSelection* select = NULL;
		GtkTreeView* _tmp5_ = NULL;
		GtkTreeSelection* _tmp6_ = NULL;
		GtkTreeSelection* _tmp7_ = NULL;
		GList* selected_items = NULL;
		GtkTreeSelection* _tmp8_ = NULL;
		GList* _tmp9_ = NULL;
		GList* _tmp10_ = NULL;
		guint _tmp11_ = 0U;
		GtkTextIter start = {0};
		GtkTextIter end = {0};
		MainWindow* _tmp12_ = NULL;
		Document* _tmp13_ = NULL;
		Document* _tmp14_ = NULL;
		GtkTextIter _tmp15_ = {0};
		GtkTextIter _tmp16_ = {0};
		gchar* contents = NULL;
		MainWindow* _tmp17_ = NULL;
		Document* _tmp18_ = NULL;
		Document* _tmp19_ = NULL;
		GtkTextIter _tmp20_ = {0};
		GtkTextIter _tmp21_ = {0};
		gchar* _tmp22_ = NULL;
		GtkTreePath* path = NULL;
		GList* _tmp23_ = NULL;
		gconstpointer _tmp24_ = NULL;
		GtkTreePath* _tmp25_ = NULL;
		gchar* icon_id = NULL;
		Templates* _tmp26_ = NULL;
		GtkTreePath* _tmp27_ = NULL;
		gchar* _tmp28_ = NULL;
		Templates* _tmp29_ = NULL;
		GtkEntry* _tmp30_ = NULL;
		const gchar* _tmp31_ = NULL;
		const gchar* _tmp32_ = NULL;
		const gchar* _tmp33_ = NULL;
		const gchar* _tmp34_ = NULL;
		_tmp1_ = gtk_dialog_run ((GtkDialog*) self);
		if (!(_tmp1_ == ((gint) GTK_RESPONSE_ACCEPT))) {
			break;
		}
		_tmp2_ = entry;
		_tmp3_ = gtk_entry_get_text_length (_tmp2_);
		_tmp4_ = _tmp3_;
		if (_tmp4_ == ((guint) 0)) {
			continue;
		}
		_tmp5_ = templates_list;
		_tmp6_ = gtk_tree_view_get_selection (_tmp5_);
		_tmp7_ = _g_object_ref0 (_tmp6_);
		select = _tmp7_;
		_tmp8_ = select;
		_tmp9_ = gtk_tree_selection_get_selected_rows (_tmp8_, NULL);
		selected_items = _tmp9_;
		_tmp10_ = selected_items;
		_tmp11_ = g_list_length (_tmp10_);
		if (_tmp11_ == ((guint) 0)) {
			__g_list_free__gtk_tree_path_free0_0 (selected_items);
			_g_object_unref0 (select);
			continue;
		}
		_tmp12_ = parent;
		_tmp13_ = main_window_get_active_document (_tmp12_);
		_tmp14_ = _tmp13_;
		gtk_text_buffer_get_bounds ((GtkTextBuffer*) _tmp14_, &_tmp15_, &_tmp16_);
		start = _tmp15_;
		end = _tmp16_;
		_tmp17_ = parent;
		_tmp18_ = main_window_get_active_document (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = start;
		_tmp21_ = end;
		_tmp22_ = gtk_text_buffer_get_text ((GtkTextBuffer*) _tmp19_, &_tmp20_, &_tmp21_, FALSE);
		contents = _tmp22_;
		_tmp23_ = selected_items;
		_tmp24_ = g_list_nth_data (_tmp23_, (guint) 0);
		_tmp25_ = _gtk_tree_path_copy0 ((GtkTreePath*) _tmp24_);
		path = _tmp25_;
		_tmp26_ = templates;
		_tmp27_ = path;
		_tmp28_ = templates_get_icon_id (_tmp26_, _tmp27_);
		icon_id = _tmp28_;
		_tmp29_ = templates;
		_tmp30_ = entry;
		_tmp31_ = gtk_entry_get_text (_tmp30_);
		_tmp32_ = _tmp31_;
		_tmp33_ = icon_id;
		_tmp34_ = contents;
		templates_create_personal_template (_tmp29_, _tmp32_, _tmp33_, _tmp34_);
		_g_free0 (icon_id);
		_gtk_tree_path_free0 (path);
		_g_free0 (contents);
		__g_list_free__gtk_tree_path_free0_0 (selected_items);
		_g_object_unref0 (select);
		break;
	}
	_g_object_unref0 (templates);
}


static void create_template_dialog_class_init (CreateTemplateDialogClass * klass) {
	create_template_dialog_parent_class = g_type_class_peek_parent (klass);
}


static void create_template_dialog_instance_init (CreateTemplateDialog * self) {
}


GType create_template_dialog_get_type (void) {
	static volatile gsize create_template_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&create_template_dialog_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (CreateTemplateDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) create_template_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CreateTemplateDialog), 0, (GInstanceInitFunc) create_template_dialog_instance_init, NULL };
		GType create_template_dialog_type_id;
		create_template_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "CreateTemplateDialog", &g_define_type_info, 0);
		g_once_init_leave (&create_template_dialog_type_id__volatile, create_template_dialog_type_id);
	}
	return create_template_dialog_type_id__volatile;
}


DeleteTemplateDialog* delete_template_dialog_construct (GType object_type, MainWindow* parent) {
	DeleteTemplateDialog * self = NULL;
	const gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	MainWindow* _tmp3_ = NULL;
	Templates* templates = NULL;
	Templates* _tmp4_ = NULL;
	GtkTreeView* templates_list = NULL;
	GtkTreeView* _tmp5_ = NULL;
	GtkTreeSelection* select = NULL;
	GtkTreeSelection* _tmp6_ = NULL;
	GtkTreeSelection* _tmp7_ = NULL;
	GtkScrolledWindow* scrollbar = NULL;
	GtkScrolledWindow* _tmp8_ = NULL;
	GtkWidget* component = NULL;
	const gchar* _tmp9_ = NULL;
	GtkGrid* _tmp10_ = NULL;
	GtkBox* content_area = NULL;
	GtkBox* _tmp11_ = NULL;
	GtkBox* _tmp12_ = NULL;
	g_return_val_if_fail (parent != NULL, NULL);
	self = (DeleteTemplateDialog*) g_object_new (object_type, NULL);
	_tmp0_ = _ ("Delete Template(s)...");
	gtk_window_set_title ((GtkWindow*) self, _tmp0_);
	_tmp1_ = _ ("_Delete");
	gtk_dialog_add_button ((GtkDialog*) self, _tmp1_, (gint) GTK_RESPONSE_ACCEPT);
	_tmp2_ = _ ("_Close");
	gtk_dialog_add_button ((GtkDialog*) self, _tmp2_, (gint) GTK_RESPONSE_REJECT);
	_tmp3_ = parent;
	gtk_window_set_transient_for ((GtkWindow*) self, (GtkWindow*) _tmp3_);
	gtk_window_set_destroy_with_parent ((GtkWindow*) self, TRUE);
	_tmp4_ = templates_get_default ();
	templates = _tmp4_;
	_tmp5_ = templates_get_personal_templates_list (templates);
	templates_list = _tmp5_;
	_tmp6_ = gtk_tree_view_get_selection (templates_list);
	_tmp7_ = _g_object_ref0 (_tmp6_);
	select = _tmp7_;
	gtk_tree_selection_set_mode (select, GTK_SELECTION_MULTIPLE);
	_tmp8_ = utils_add_scrollbar ((GtkWidget*) templates_list);
	scrollbar = _tmp8_;
	gtk_scrolled_window_set_shadow_type (scrollbar, GTK_SHADOW_IN);
	gtk_widget_set_size_request ((GtkWidget*) scrollbar, 250, 150);
	_tmp9_ = _ ("Personal templates");
	_tmp10_ = utils_get_dialog_component (_tmp9_, (GtkWidget*) scrollbar);
	component = (GtkWidget*) _tmp10_;
	_tmp11_ = (GtkBox*) gtk_dialog_get_content_area ((GtkDialog*) self);
	_tmp12_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp11_, gtk_box_get_type ()) ? ((GtkBox*) _tmp11_) : NULL);
	content_area = _tmp12_;
	gtk_box_pack_start (content_area, component, TRUE, TRUE, (guint) 0);
	gtk_widget_show_all ((GtkWidget*) content_area);
	delete_template_dialog_run_me (self, templates_list);
	_g_object_unref0 (content_area);
	_g_object_unref0 (component);
	_g_object_unref0 (scrollbar);
	_g_object_unref0 (select);
	_g_object_unref0 (templates_list);
	_g_object_unref0 (templates);
	return self;
}


DeleteTemplateDialog* delete_template_dialog_new (MainWindow* parent) {
	return delete_template_dialog_construct (TYPE_DELETE_TEMPLATE_DIALOG, parent);
}


static gpointer _gtk_tree_row_reference_copy0 (gpointer self) {
	return self ? gtk_tree_row_reference_copy (self) : NULL;
}


static void _gtk_tree_row_reference_free0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (gtk_tree_row_reference_free (var), NULL));
}


static void _g_list_free__gtk_tree_row_reference_free0_ (GList* self) {
	g_list_foreach (self, (GFunc) _gtk_tree_row_reference_free0_, NULL);
	g_list_free (self);
}


static void delete_template_dialog_run_me (DeleteTemplateDialog* self, GtkTreeView* templates_list) {
	Templates* templates = NULL;
	Templates* _tmp0_ = NULL;
	gboolean template_deleted = FALSE;
	gboolean _tmp19_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (templates_list != NULL);
	_tmp0_ = templates_get_default ();
	templates = _tmp0_;
	template_deleted = FALSE;
	while (TRUE) {
		gint _tmp1_ = 0;
		GtkTreeSelection* select = NULL;
		GtkTreeView* _tmp2_ = NULL;
		GtkTreeSelection* _tmp3_ = NULL;
		GtkTreeSelection* _tmp4_ = NULL;
		GtkTreeModel* model = NULL;
		GList* selected_rows = NULL;
		GtkTreeSelection* _tmp5_ = NULL;
		GtkTreeModel* _tmp6_ = NULL;
		GList* _tmp7_ = NULL;
		GList* row_refs = NULL;
		GList* _tmp8_ = NULL;
		GList* _tmp13_ = NULL;
		_tmp1_ = gtk_dialog_run ((GtkDialog*) self);
		if (!(_tmp1_ == ((gint) GTK_RESPONSE_ACCEPT))) {
			break;
		}
		_tmp2_ = templates_list;
		_tmp3_ = gtk_tree_view_get_selection (_tmp2_);
		_tmp4_ = _g_object_ref0 (_tmp3_);
		select = _tmp4_;
		_tmp5_ = select;
		_tmp7_ = gtk_tree_selection_get_selected_rows (_tmp5_, &_tmp6_);
		model = _tmp6_;
		selected_rows = _tmp7_;
		row_refs = NULL;
		_tmp8_ = selected_rows;
		{
			GList* path_collection = NULL;
			GList* path_it = NULL;
			path_collection = _tmp8_;
			for (path_it = path_collection; path_it != NULL; path_it = path_it->next) {
				GtkTreePath* _tmp9_ = NULL;
				GtkTreePath* path = NULL;
				_tmp9_ = _gtk_tree_path_copy0 ((GtkTreePath*) path_it->data);
				path = _tmp9_;
				{
					GtkTreeModel* _tmp10_ = NULL;
					GtkTreePath* _tmp11_ = NULL;
					GtkTreeRowReference* _tmp12_ = NULL;
					_tmp10_ = model;
					_tmp11_ = path;
					_tmp12_ = gtk_tree_row_reference_new (_tmp10_, _tmp11_);
					row_refs = g_list_prepend (row_refs, _tmp12_);
					_gtk_tree_path_free0 (path);
				}
			}
		}
		_tmp13_ = row_refs;
		{
			GList* row_ref_collection = NULL;
			GList* row_ref_it = NULL;
			row_ref_collection = _tmp13_;
			for (row_ref_it = row_ref_collection; row_ref_it != NULL; row_ref_it = row_ref_it->next) {
				GtkTreeRowReference* _tmp14_ = NULL;
				GtkTreeRowReference* row_ref = NULL;
				_tmp14_ = _gtk_tree_row_reference_copy0 ((const GtkTreeRowReference*) row_ref_it->data);
				row_ref = _tmp14_;
				{
					GtkTreePath* path = NULL;
					const GtkTreeRowReference* _tmp15_ = NULL;
					GtkTreePath* _tmp16_ = NULL;
					Templates* _tmp17_ = NULL;
					GtkTreePath* _tmp18_ = NULL;
					_tmp15_ = row_ref;
					_tmp16_ = gtk_tree_row_reference_get_path (_tmp15_);
					path = _tmp16_;
					_tmp17_ = templates;
					_tmp18_ = path;
					templates_delete_personal_template (_tmp17_, _tmp18_);
					template_deleted = TRUE;
					_gtk_tree_path_free0 (path);
					_gtk_tree_row_reference_free0 (row_ref);
				}
			}
		}
		__g_list_free__gtk_tree_row_reference_free0_0 (row_refs);
		__g_list_free__gtk_tree_path_free0_0 (selected_rows);
		_g_object_unref0 (select);
	}
	_tmp19_ = template_deleted;
	if (_tmp19_) {
		Templates* _tmp20_ = NULL;
		_tmp20_ = templates;
		templates_save_rc_file (_tmp20_);
	}
	_g_object_unref0 (templates);
}


static void delete_template_dialog_class_init (DeleteTemplateDialogClass * klass) {
	delete_template_dialog_parent_class = g_type_class_peek_parent (klass);
}


static void delete_template_dialog_instance_init (DeleteTemplateDialog * self) {
}


GType delete_template_dialog_get_type (void) {
	static volatile gsize delete_template_dialog_type_id__volatile = 0;
	if (g_once_init_enter (&delete_template_dialog_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DeleteTemplateDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) delete_template_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DeleteTemplateDialog), 0, (GInstanceInitFunc) delete_template_dialog_instance_init, NULL };
		GType delete_template_dialog_type_id;
		delete_template_dialog_type_id = g_type_register_static (gtk_dialog_get_type (), "DeleteTemplateDialog", &g_define_type_info, 0);
		g_once_init_leave (&delete_template_dialog_type_id__volatile, delete_template_dialog_type_id);
	}
	return delete_template_dialog_type_id__volatile;
}



