/* main_window_documents.c generated by valac 0.26.0.33-c448, the Vala compiler
 * generated from main_window_documents.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/>.
 *
 * Author: Sébastien Wilmet
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gtksourceview/gtksource.h>
#include <gobject/gvaluecollector.h>


#define TYPE_MAIN_WINDOW_DOCUMENTS (main_window_documents_get_type ())
#define MAIN_WINDOW_DOCUMENTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW_DOCUMENTS, MainWindowDocuments))
#define MAIN_WINDOW_DOCUMENTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW_DOCUMENTS, MainWindowDocumentsClass))
#define IS_MAIN_WINDOW_DOCUMENTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW_DOCUMENTS))
#define IS_MAIN_WINDOW_DOCUMENTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW_DOCUMENTS))
#define MAIN_WINDOW_DOCUMENTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW_DOCUMENTS, MainWindowDocumentsClass))

typedef struct _MainWindowDocuments MainWindowDocuments;
typedef struct _MainWindowDocumentsClass MainWindowDocumentsClass;
typedef struct _MainWindowDocumentsPrivate MainWindowDocumentsPrivate;

#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 TYPE_DOCUMENTS_PANEL (documents_panel_get_type ())
#define DOCUMENTS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENTS_PANEL, DocumentsPanel))
#define DOCUMENTS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENTS_PANEL, DocumentsPanelClass))
#define IS_DOCUMENTS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENTS_PANEL))
#define IS_DOCUMENTS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENTS_PANEL))
#define DOCUMENTS_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENTS_PANEL, DocumentsPanelClass))

typedef struct _DocumentsPanel DocumentsPanel;
typedef struct _DocumentsPanelClass DocumentsPanelClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_list_free0(var) ((var == NULL) ? NULL : (var = (g_list_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 _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#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;

#define TYPE_LATEXILA_APP (latexila_app_get_type ())
#define LATEXILA_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LATEXILA_APP, LatexilaApp))
#define LATEXILA_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LATEXILA_APP, LatexilaAppClass))
#define IS_LATEXILA_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LATEXILA_APP))
#define IS_LATEXILA_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LATEXILA_APP))
#define LATEXILA_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LATEXILA_APP, LatexilaAppClass))

typedef struct _LatexilaApp LatexilaApp;
typedef struct _LatexilaAppClass LatexilaAppClass;

#define TYPE_DOCUMENT_VIEW (document_view_get_type ())
#define DOCUMENT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT_VIEW, DocumentView))
#define DOCUMENT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_VIEW, DocumentViewClass))
#define IS_DOCUMENT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT_VIEW))
#define IS_DOCUMENT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_VIEW))
#define DOCUMENT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_VIEW, DocumentViewClass))

typedef struct _DocumentView DocumentView;
typedef struct _DocumentViewClass DocumentViewClass;
typedef struct _ParamSpecMainWindowDocuments ParamSpecMainWindowDocuments;

struct _MainWindowDocuments {
	GTypeInstance parent_instance;
	volatile int ref_count;
	MainWindowDocumentsPrivate * priv;
};

struct _MainWindowDocumentsClass {
	GTypeClass parent_class;
	void (*finalize) (MainWindowDocuments *self);
};

struct _MainWindowDocumentsPrivate {
	MainWindow* _main_window;
	GtkUIManager* _ui_manager;
	DocumentsPanel* _documents_panel;
	GtkActionGroup* _static_action_group;
	GtkActionGroup* _list_action_group;
	guint _list_id;
};

struct _ParamSpecMainWindowDocuments {
	GParamSpec parent_instance;
};


static gpointer main_window_documents_parent_class = NULL;

gpointer main_window_documents_ref (gpointer instance);
void main_window_documents_unref (gpointer instance);
GParamSpec* param_spec_main_window_documents (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_main_window_documents (GValue* value, gpointer v_object);
void value_take_main_window_documents (GValue* value, gpointer v_object);
gpointer value_get_main_window_documents (const GValue* value);
GType main_window_documents_get_type (void) G_GNUC_CONST;
GType main_window_get_type (void) G_GNUC_CONST;
GType documents_panel_get_type (void) G_GNUC_CONST;
#define MAIN_WINDOW_DOCUMENTS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MAIN_WINDOW_DOCUMENTS, MainWindowDocumentsPrivate))
enum  {
	MAIN_WINDOW_DOCUMENTS_DUMMY_PROPERTY
};
void main_window_documents_on_save_all (MainWindowDocuments* self);
static void _main_window_documents_on_save_all_gtk_action_callback (GtkAction* action, gpointer self);
void main_window_documents_on_close_all (MainWindowDocuments* self);
static void _main_window_documents_on_close_all_gtk_action_callback (GtkAction* action, gpointer self);
void main_window_documents_on_previous (MainWindowDocuments* self);
static void _main_window_documents_on_previous_gtk_action_callback (GtkAction* action, gpointer self);
void main_window_documents_on_next (MainWindowDocuments* self);
static void _main_window_documents_on_next_gtk_action_callback (GtkAction* action, gpointer self);
void main_window_documents_on_move_to_new_window (MainWindowDocuments* self);
static void _main_window_documents_on_move_to_new_window_gtk_action_callback (GtkAction* action, gpointer self);
MainWindowDocuments* main_window_documents_new (MainWindow* main_window, GtkUIManager* ui_manager);
MainWindowDocuments* main_window_documents_construct (GType object_type, MainWindow* main_window, GtkUIManager* ui_manager);
void main_window_documents_set_documents_panel (MainWindowDocuments* self, DocumentsPanel* documents_panel);
static void main_window_documents_connect_signals (MainWindowDocuments* self);
static void main_window_documents_update_sensitivity (MainWindowDocuments* self);
static void __lambda39_ (MainWindowDocuments* self);
static void main_window_documents_update_documents_list (MainWindowDocuments* self);
static void ___lambda39__gtk_notebook_page_reordered (GtkNotebook* _sender, GtkWidget* child, guint page_num, gpointer self);
static void __lambda40_ (MainWindowDocuments* self, GtkWidget* pg, guint page_num);
static void main_window_documents_set_active_document (MainWindowDocuments* self, guint doc_num);
static void ___lambda40__gtk_notebook_switch_page (GtkNotebook* _sender, GtkWidget* page, guint page_num, gpointer self);
static void __lambda41_ (MainWindowDocuments* self);
static void ___lambda41__gtk_notebook_page_removed (GtkNotebook* _sender, GtkWidget* child, guint page_num, gpointer self);
static void __lambda42_ (MainWindowDocuments* self);
static void ___lambda42__gtk_notebook_page_added (GtkNotebook* _sender, GtkWidget* child, guint page_num, gpointer self);
static void main_window_documents_list_action_activate (MainWindowDocuments* self, GtkAction* action);
static void _main_window_documents_list_action_activate_gtk_action_activate (GtkAction* _sender, gpointer self);
GType document_tab_get_type (void) G_GNUC_CONST;
static gchar* main_window_documents_get_list_action_name (MainWindowDocuments* self, guint doc_num);
gchar* document_tab_get_name (DocumentTab* self);
gchar* document_tab_get_menu_tip (DocumentTab* self);
DocumentTab* main_window_get_active_tab (MainWindow* self);
void main_window_documents_update_document_name (MainWindowDocuments* self, DocumentTab* tab);
static void main_window_documents_update_next_prev_doc_sensitivity (MainWindowDocuments* self);
GType document_get_type (void) G_GNUC_CONST;
GeeList* main_window_get_unsaved_documents (MainWindow* self);
void document_save (Document* self, gboolean check_file_changed_on_disk, gboolean force);
gboolean main_window_close_all_documents (MainWindow* self);
GType latexila_app_get_type (void) G_GNUC_CONST;
LatexilaApp* latexila_app_get_instance (void);
MainWindow* latexila_app_create_window (LatexilaApp* self);
GType document_view_get_type (void) G_GNUC_CONST;
DocumentView* document_tab_get_view (DocumentTab* self);
void documents_panel_remove_tab (DocumentsPanel* self, DocumentTab* tab);
void main_window_create_tab_with_view (MainWindow* self, DocumentView* view);
static void main_window_documents_finalize (MainWindowDocuments* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);

static const GtkActionEntry MAIN_WINDOW_DOCUMENTS__action_entries[6] = {{"Documents", NULL, "_Documents"}, {"DocumentsSaveAll", GTK_STOCK_SAVE, "_Save All", "<Shift><Control>L", "Save all open files", (GCallback) _main_window_documents_on_save_all_gtk_action_callback}, {"DocumentsCloseAll", GTK_STOCK_CLOSE, "_Close All", "<Shift><Control>W", "Close all open files", (GCallback) _main_window_documents_on_close_all_gtk_action_callback}, {"DocumentsPrevious", GTK_STOCK_GO_BACK, "_Previous Document", "<Control><Alt>Page_Up", "Activate previous document", (GCallback) _main_window_documents_on_previous_gtk_action_callback}, {"DocumentsNext", GTK_STOCK_GO_FORWARD, "_Next Document", "<Control><Alt>Page_Down", "Activate next document", (GCallback) _main_window_documents_on_next_gtk_action_callback}, {"DocumentsMoveToNewWindow", NULL, "_Move to New Window", NULL, "Move the current document to a new window", (GCallback) _main_window_documents_on_move_to_new_window_gtk_action_callback}};

static void _main_window_documents_on_save_all_gtk_action_callback (GtkAction* action, gpointer self) {
	main_window_documents_on_save_all ((MainWindowDocuments*) self);
}


static void _main_window_documents_on_close_all_gtk_action_callback (GtkAction* action, gpointer self) {
	main_window_documents_on_close_all ((MainWindowDocuments*) self);
}


static void _main_window_documents_on_previous_gtk_action_callback (GtkAction* action, gpointer self) {
	main_window_documents_on_previous ((MainWindowDocuments*) self);
}


static void _main_window_documents_on_next_gtk_action_callback (GtkAction* action, gpointer self) {
	main_window_documents_on_next ((MainWindowDocuments*) self);
}


static void _main_window_documents_on_move_to_new_window_gtk_action_callback (GtkAction* action, gpointer self) {
	main_window_documents_on_move_to_new_window ((MainWindowDocuments*) self);
}


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


MainWindowDocuments* main_window_documents_construct (GType object_type, MainWindow* main_window, GtkUIManager* ui_manager) {
	MainWindowDocuments* self = NULL;
	MainWindow* _tmp0_ = NULL;
	GtkUIManager* _tmp1_ = NULL;
	GtkUIManager* _tmp2_ = NULL;
	GtkActionGroup* _tmp3_ = NULL;
	GtkActionGroup* _tmp4_ = NULL;
	GtkActionGroup* _tmp5_ = NULL;
	GtkUIManager* _tmp6_ = NULL;
	GtkActionGroup* _tmp7_ = NULL;
	GtkActionGroup* _tmp8_ = NULL;
	GtkUIManager* _tmp9_ = NULL;
	GtkActionGroup* _tmp10_ = NULL;
	g_return_val_if_fail (main_window != NULL, NULL);
	g_return_val_if_fail (ui_manager != NULL, NULL);
	self = (MainWindowDocuments*) g_type_create_instance (object_type);
	_tmp0_ = main_window;
	self->priv->_main_window = _tmp0_;
	_tmp1_ = ui_manager;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (self->priv->_ui_manager);
	self->priv->_ui_manager = _tmp2_;
	_tmp3_ = gtk_action_group_new ("DocumentsMenuActionGroup");
	_g_object_unref0 (self->priv->_static_action_group);
	self->priv->_static_action_group = _tmp3_;
	_tmp4_ = self->priv->_static_action_group;
	gtk_action_group_set_translation_domain (_tmp4_, GETTEXT_PACKAGE);
	_tmp5_ = self->priv->_static_action_group;
	gtk_action_group_add_actions (_tmp5_, MAIN_WINDOW_DOCUMENTS__action_entries, G_N_ELEMENTS (MAIN_WINDOW_DOCUMENTS__action_entries), self);
	_tmp6_ = ui_manager;
	_tmp7_ = self->priv->_static_action_group;
	gtk_ui_manager_insert_action_group (_tmp6_, _tmp7_, 0);
	_tmp8_ = gtk_action_group_new ("DocumentsListActionGroup");
	_g_object_unref0 (self->priv->_list_action_group);
	self->priv->_list_action_group = _tmp8_;
	_tmp9_ = ui_manager;
	_tmp10_ = self->priv->_list_action_group;
	gtk_ui_manager_insert_action_group (_tmp9_, _tmp10_, 0);
	return self;
}


MainWindowDocuments* main_window_documents_new (MainWindow* main_window, GtkUIManager* ui_manager) {
	return main_window_documents_construct (TYPE_MAIN_WINDOW_DOCUMENTS, main_window, ui_manager);
}


void main_window_documents_set_documents_panel (MainWindowDocuments* self, DocumentsPanel* documents_panel) {
	DocumentsPanel* _tmp0_ = NULL;
	DocumentsPanel* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (documents_panel != NULL);
	_tmp0_ = documents_panel;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_documents_panel);
	self->priv->_documents_panel = _tmp1_;
	main_window_documents_connect_signals (self);
	main_window_documents_update_sensitivity (self);
}


static void __lambda39_ (MainWindowDocuments* self) {
	main_window_documents_update_sensitivity (self);
	main_window_documents_update_documents_list (self);
}


static void ___lambda39__gtk_notebook_page_reordered (GtkNotebook* _sender, GtkWidget* child, guint page_num, gpointer self) {
	__lambda39_ ((MainWindowDocuments*) self);
}


static void __lambda40_ (MainWindowDocuments* self, GtkWidget* pg, guint page_num) {
	guint _tmp0_ = 0U;
	g_return_if_fail (pg != NULL);
	_tmp0_ = page_num;
	main_window_documents_set_active_document (self, _tmp0_);
	main_window_documents_update_sensitivity (self);
}


static void ___lambda40__gtk_notebook_switch_page (GtkNotebook* _sender, GtkWidget* page, guint page_num, gpointer self) {
	__lambda40_ ((MainWindowDocuments*) self, page, page_num);
}


static void __lambda41_ (MainWindowDocuments* self) {
	main_window_documents_update_documents_list (self);
	main_window_documents_update_sensitivity (self);
}


static void ___lambda41__gtk_notebook_page_removed (GtkNotebook* _sender, GtkWidget* child, guint page_num, gpointer self) {
	__lambda41_ ((MainWindowDocuments*) self);
}


static void __lambda42_ (MainWindowDocuments* self) {
	main_window_documents_update_documents_list (self);
	main_window_documents_update_sensitivity (self);
}


static void ___lambda42__gtk_notebook_page_added (GtkNotebook* _sender, GtkWidget* child, guint page_num, gpointer self) {
	__lambda42_ ((MainWindowDocuments*) self);
}


static void main_window_documents_connect_signals (MainWindowDocuments* self) {
	DocumentsPanel* _tmp0_ = NULL;
	DocumentsPanel* _tmp1_ = NULL;
	DocumentsPanel* _tmp2_ = NULL;
	DocumentsPanel* _tmp3_ = NULL;
	DocumentsPanel* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp0_ != NULL);
	_tmp1_ = self->priv->_documents_panel;
	g_signal_connect ((GtkNotebook*) _tmp1_, "page-reordered", (GCallback) ___lambda39__gtk_notebook_page_reordered, self);
	_tmp2_ = self->priv->_documents_panel;
	g_signal_connect ((GtkNotebook*) _tmp2_, "switch-page", (GCallback) ___lambda40__gtk_notebook_switch_page, self);
	_tmp3_ = self->priv->_documents_panel;
	g_signal_connect ((GtkNotebook*) _tmp3_, "page-removed", (GCallback) ___lambda41__gtk_notebook_page_removed, self);
	_tmp4_ = self->priv->_documents_panel;
	g_signal_connect ((GtkNotebook*) _tmp4_, "page-added", (GCallback) ___lambda42__gtk_notebook_page_added, self);
}


static void _main_window_documents_list_action_activate_gtk_action_activate (GtkAction* _sender, gpointer self) {
	main_window_documents_list_action_activate ((MainWindowDocuments*) self, _sender);
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	{
		GRegex* regex = NULL;
		const gchar* _tmp0_ = NULL;
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_ = NULL;
		GRegex* _tmp3_ = NULL;
		GRegex* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		GRegex* _tmp6_ = NULL;
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		_tmp0_ = old;
		_tmp1_ = g_regex_escape_string (_tmp0_, -1);
		_tmp2_ = _tmp1_;
		_tmp3_ = g_regex_new (_tmp2_, 0, 0, &_inner_error_);
		_tmp4_ = _tmp3_;
		_g_free0 (_tmp2_);
		regex = _tmp4_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch26_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp6_ = regex;
		_tmp7_ = replacement;
		_tmp8_ = g_regex_replace_literal (_tmp6_, self, (gssize) (-1), 0, _tmp7_, 0, &_inner_error_);
		_tmp5_ = _tmp8_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error_->domain == G_REGEX_ERROR) {
				goto __catch26_g_regex_error;
			}
			_g_regex_unref0 (regex);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
		_tmp9_ = _tmp5_;
		_tmp5_ = NULL;
		result = _tmp9_;
		_g_free0 (_tmp5_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally26;
	__catch26_g_regex_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally26:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
}


static void main_window_documents_update_documents_list (MainWindowDocuments* self) {
	GtkActionGroup* _tmp0_ = NULL;
	DocumentsPanel* _tmp1_ = NULL;
	guint _tmp2_ = 0U;
	GtkActionGroup* _tmp5_ = NULL;
	GList* _tmp6_ = NULL;
	gint nb_docs = 0;
	DocumentsPanel* _tmp12_ = NULL;
	gint _tmp13_ = 0;
	gint _tmp14_ = 0;
	GtkUIManager* _tmp15_ = NULL;
	guint _tmp16_ = 0U;
	GSList* group = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_list_action_group;
	g_return_if_fail (_tmp0_ != NULL);
	_tmp1_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp1_ != NULL);
	_tmp2_ = self->priv->_list_id;
	if (_tmp2_ != ((guint) 0)) {
		GtkUIManager* _tmp3_ = NULL;
		guint _tmp4_ = 0U;
		_tmp3_ = self->priv->_ui_manager;
		_tmp4_ = self->priv->_list_id;
		gtk_ui_manager_remove_ui (_tmp3_, _tmp4_);
	}
	_tmp5_ = self->priv->_list_action_group;
	_tmp6_ = gtk_action_group_list_actions (_tmp5_);
	{
		GList* action_collection = NULL;
		GList* action_it = NULL;
		action_collection = _tmp6_;
		for (action_it = action_collection; action_it != NULL; action_it = action_it->next) {
			GtkAction* _tmp7_ = NULL;
			GtkAction* action = NULL;
			_tmp7_ = _g_object_ref0 ((GtkAction*) action_it->data);
			action = _tmp7_;
			{
				GtkAction* _tmp8_ = NULL;
				guint _tmp9_ = 0U;
				GtkActionGroup* _tmp10_ = NULL;
				GtkAction* _tmp11_ = NULL;
				_tmp8_ = action;
				g_signal_parse_name ("activate", gtk_action_get_type (), &_tmp9_, NULL, FALSE);
				g_signal_handlers_disconnect_matched (_tmp8_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp9_, 0, NULL, (GCallback) _main_window_documents_list_action_activate_gtk_action_activate, self);
				_tmp10_ = self->priv->_list_action_group;
				_tmp11_ = action;
				gtk_action_group_remove_action (_tmp10_, _tmp11_);
				_g_object_unref0 (action);
			}
		}
		_g_list_free0 (action_collection);
	}
	self->priv->_list_id = (guint) 0;
	_tmp12_ = self->priv->_documents_panel;
	_tmp13_ = gtk_notebook_get_n_pages ((GtkNotebook*) _tmp12_);
	nb_docs = _tmp13_;
	_tmp14_ = nb_docs;
	if (_tmp14_ == 0) {
		return;
	}
	_tmp15_ = self->priv->_ui_manager;
	_tmp16_ = gtk_ui_manager_new_merge_id (_tmp15_);
	self->priv->_list_id = _tmp16_;
	group = NULL;
	{
		gint doc_num = 0;
		doc_num = 0;
		{
			gboolean _tmp17_ = FALSE;
			_tmp17_ = TRUE;
			while (TRUE) {
				gint _tmp19_ = 0;
				gint _tmp20_ = 0;
				DocumentTab* tab = NULL;
				DocumentsPanel* _tmp21_ = NULL;
				gint _tmp22_ = 0;
				GtkWidget* _tmp23_ = NULL;
				DocumentTab* _tmp24_ = NULL;
				gchar* action_name = NULL;
				gint _tmp25_ = 0;
				gchar* _tmp26_ = NULL;
				gchar* name = NULL;
				DocumentTab* _tmp27_ = NULL;
				gchar* _tmp28_ = NULL;
				gchar* _tmp29_ = NULL;
				gchar* _tmp30_ = NULL;
				gchar* _tmp31_ = NULL;
				gchar* tip = NULL;
				DocumentTab* _tmp32_ = NULL;
				gchar* _tmp33_ = NULL;
				gchar* accel = NULL;
				gint _tmp34_ = 0;
				GtkRadioAction* action = NULL;
				const gchar* _tmp37_ = NULL;
				const gchar* _tmp38_ = NULL;
				const gchar* _tmp39_ = NULL;
				gint _tmp40_ = 0;
				GtkRadioAction* _tmp41_ = NULL;
				GSList* _tmp42_ = NULL;
				GtkRadioAction* _tmp45_ = NULL;
				GSList* _tmp46_ = NULL;
				GtkActionGroup* _tmp47_ = NULL;
				GtkRadioAction* _tmp48_ = NULL;
				const gchar* _tmp49_ = NULL;
				GtkRadioAction* _tmp50_ = NULL;
				GtkUIManager* _tmp51_ = NULL;
				guint _tmp52_ = 0U;
				const gchar* _tmp53_ = NULL;
				const gchar* _tmp54_ = NULL;
				DocumentTab* _tmp55_ = NULL;
				MainWindow* _tmp56_ = NULL;
				DocumentTab* _tmp57_ = NULL;
				DocumentTab* _tmp58_ = NULL;
				if (!_tmp17_) {
					gint _tmp18_ = 0;
					_tmp18_ = doc_num;
					doc_num = _tmp18_ + 1;
				}
				_tmp17_ = FALSE;
				_tmp19_ = doc_num;
				_tmp20_ = nb_docs;
				if (!(_tmp19_ < _tmp20_)) {
					break;
				}
				_tmp21_ = self->priv->_documents_panel;
				_tmp22_ = doc_num;
				_tmp23_ = gtk_notebook_get_nth_page ((GtkNotebook*) _tmp21_, _tmp22_);
				_tmp24_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp23_, TYPE_DOCUMENT_TAB) ? ((DocumentTab*) _tmp23_) : NULL);
				tab = _tmp24_;
				_tmp25_ = doc_num;
				_tmp26_ = main_window_documents_get_list_action_name (self, (guint) _tmp25_);
				action_name = _tmp26_;
				_tmp27_ = tab;
				_tmp28_ = document_tab_get_name (_tmp27_);
				_tmp29_ = _tmp28_;
				_tmp30_ = string_replace (_tmp29_, "_", "__");
				_tmp31_ = _tmp30_;
				_g_free0 (_tmp29_);
				name = _tmp31_;
				_tmp32_ = tab;
				_tmp33_ = document_tab_get_menu_tip (_tmp32_);
				tip = _tmp33_;
				accel = NULL;
				_tmp34_ = doc_num;
				if (_tmp34_ < 10) {
					gint _tmp35_ = 0;
					gchar* _tmp36_ = NULL;
					_tmp35_ = doc_num;
					_tmp36_ = g_strdup_printf ("<alt>%d", (_tmp35_ + 1) % 10);
					_g_free0 (accel);
					accel = _tmp36_;
				}
				_tmp37_ = action_name;
				_tmp38_ = name;
				_tmp39_ = tip;
				_tmp40_ = doc_num;
				_tmp41_ = gtk_radio_action_new (_tmp37_, _tmp38_, _tmp39_, NULL, _tmp40_);
				action = _tmp41_;
				_tmp42_ = group;
				if (_tmp42_ != NULL) {
					GtkRadioAction* _tmp43_ = NULL;
					GSList* _tmp44_ = NULL;
					_tmp43_ = action;
					_tmp44_ = group;
					gtk_radio_action_set_group (_tmp43_, _tmp44_);
				}
				_tmp45_ = action;
				_tmp46_ = gtk_radio_action_get_group (_tmp45_);
				group = _tmp46_;
				_tmp47_ = self->priv->_list_action_group;
				_tmp48_ = action;
				_tmp49_ = accel;
				gtk_action_group_add_action_with_accel (_tmp47_, (GtkAction*) _tmp48_, _tmp49_);
				_tmp50_ = action;
				g_signal_connect ((GtkAction*) _tmp50_, "activate", (GCallback) _main_window_documents_list_action_activate_gtk_action_activate, self);
				_tmp51_ = self->priv->_ui_manager;
				_tmp52_ = self->priv->_list_id;
				_tmp53_ = action_name;
				_tmp54_ = action_name;
				gtk_ui_manager_add_ui (_tmp51_, _tmp52_, "/MainMenu/DocumentsMenu/DocumentsListPlaceholder", _tmp53_, _tmp54_, GTK_UI_MANAGER_MENUITEM, FALSE);
				_tmp55_ = tab;
				_tmp56_ = self->priv->_main_window;
				_tmp57_ = main_window_get_active_tab (_tmp56_);
				_tmp58_ = _tmp57_;
				if (_tmp55_ == _tmp58_) {
					GtkRadioAction* _tmp59_ = NULL;
					_tmp59_ = action;
					gtk_toggle_action_set_active ((GtkToggleAction*) _tmp59_, TRUE);
				}
				_g_object_unref0 (action);
				_g_free0 (accel);
				_g_free0 (tip);
				_g_free0 (name);
				_g_free0 (action_name);
				_g_object_unref0 (tab);
			}
		}
	}
}


static void main_window_documents_set_active_document (MainWindowDocuments* self, guint doc_num) {
	gchar* action_name = NULL;
	guint _tmp0_ = 0U;
	gchar* _tmp1_ = NULL;
	GtkRadioAction* action = NULL;
	GtkActionGroup* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	GtkAction* _tmp4_ = NULL;
	GtkRadioAction* _tmp5_ = NULL;
	GtkRadioAction* _tmp6_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = doc_num;
	_tmp1_ = main_window_documents_get_list_action_name (self, _tmp0_);
	action_name = _tmp1_;
	_tmp2_ = self->priv->_list_action_group;
	_tmp3_ = action_name;
	_tmp4_ = gtk_action_group_get_action (_tmp2_, _tmp3_);
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, gtk_radio_action_get_type ()) ? ((GtkRadioAction*) _tmp4_) : NULL);
	action = _tmp5_;
	_tmp6_ = action;
	if (_tmp6_ != NULL) {
		GtkRadioAction* _tmp7_ = NULL;
		guint _tmp8_ = 0U;
		GtkRadioAction* _tmp9_ = NULL;
		GtkRadioAction* _tmp10_ = NULL;
		_tmp7_ = action;
		g_signal_parse_name ("activate", gtk_action_get_type (), &_tmp8_, NULL, FALSE);
		g_signal_handlers_disconnect_matched ((GtkAction*) _tmp7_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp8_, 0, NULL, (GCallback) _main_window_documents_list_action_activate_gtk_action_activate, self);
		_tmp9_ = action;
		gtk_toggle_action_set_active ((GtkToggleAction*) _tmp9_, TRUE);
		_tmp10_ = action;
		g_signal_connect ((GtkAction*) _tmp10_, "activate", (GCallback) _main_window_documents_list_action_activate_gtk_action_activate, self);
	}
	_g_object_unref0 (action);
	_g_free0 (action_name);
}


void main_window_documents_update_document_name (MainWindowDocuments* self, DocumentTab* tab) {
	DocumentsPanel* _tmp0_ = NULL;
	gint doc_num = 0;
	DocumentsPanel* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	gint _tmp3_ = 0;
	gchar* action_name = NULL;
	gchar* _tmp4_ = NULL;
	GtkAction* action = NULL;
	GtkActionGroup* _tmp5_ = NULL;
	GtkAction* _tmp6_ = NULL;
	GtkAction* _tmp7_ = NULL;
	DocumentTab* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_ = NULL;
	DocumentTab* _tmp13_ = NULL;
	gchar* _tmp14_ = NULL;
	gchar* _tmp15_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (tab != NULL);
	_tmp0_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp0_ != NULL);
	_tmp1_ = self->priv->_documents_panel;
	_tmp2_ = tab;
	_tmp3_ = gtk_notebook_page_num ((GtkNotebook*) _tmp1_, (GtkWidget*) _tmp2_);
	doc_num = _tmp3_;
	_tmp4_ = main_window_documents_get_list_action_name (self, (guint) doc_num);
	action_name = _tmp4_;
	_tmp5_ = self->priv->_list_action_group;
	_tmp6_ = gtk_action_group_get_action (_tmp5_, action_name);
	_tmp7_ = _g_object_ref0 (_tmp6_);
	action = _tmp7_;
	g_return_if_fail (action != NULL);
	_tmp8_ = tab;
	_tmp9_ = document_tab_get_name (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = string_replace (_tmp10_, "_", "__");
	_tmp12_ = _tmp11_;
	gtk_action_set_label (action, _tmp12_);
	_g_free0 (_tmp12_);
	_g_free0 (_tmp10_);
	_tmp13_ = tab;
	_tmp14_ = document_tab_get_menu_tip (_tmp13_);
	_tmp15_ = _tmp14_;
	gtk_action_set_tooltip (action, _tmp15_);
	_g_free0 (_tmp15_);
	_g_object_unref0 (action);
	_g_free0 (action_name);
}


static void main_window_documents_list_action_activate (MainWindowDocuments* self, GtkAction* action) {
	DocumentsPanel* _tmp0_ = NULL;
	GtkRadioAction* radio_action = NULL;
	GtkAction* _tmp1_ = NULL;
	GtkRadioAction* _tmp2_ = NULL;
	GtkRadioAction* _tmp3_ = NULL;
	gboolean _tmp4_ = FALSE;
	DocumentsPanel* _tmp5_ = NULL;
	GtkRadioAction* _tmp6_ = NULL;
	gint _tmp7_ = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp0_ != NULL);
	_tmp1_ = action;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, gtk_radio_action_get_type ()) ? ((GtkRadioAction*) _tmp1_) : NULL);
	radio_action = _tmp2_;
	_tmp3_ = radio_action;
	_tmp4_ = gtk_toggle_action_get_active ((GtkToggleAction*) _tmp3_);
	if (!_tmp4_) {
		_g_object_unref0 (radio_action);
		return;
	}
	_tmp5_ = self->priv->_documents_panel;
	_tmp6_ = radio_action;
	_tmp7_ = gtk_radio_action_get_current_value (_tmp6_);
	gtk_notebook_set_current_page ((GtkNotebook*) _tmp5_, _tmp7_);
	_g_object_unref0 (radio_action);
}


static gchar* main_window_documents_get_list_action_name (MainWindowDocuments* self, guint doc_num) {
	gchar* result = NULL;
	guint _tmp0_ = 0U;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = doc_num;
	_tmp1_ = g_strdup_printf ("%u", _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat ("Tab_", _tmp2_, NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	result = _tmp4_;
	return result;
}


static void main_window_documents_update_sensitivity (MainWindowDocuments* self) {
	gboolean sensitive = FALSE;
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	gchar** action_names = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar** _tmp8_ = NULL;
	gint action_names_length1 = 0;
	gint _action_names_size_ = 0;
	gchar** _tmp9_ = NULL;
	gint _tmp9__length1 = 0;
	gboolean _tmp17_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_main_window;
	_tmp1_ = main_window_get_active_tab (_tmp0_);
	_tmp2_ = _tmp1_;
	sensitive = _tmp2_ != NULL;
	_tmp3_ = g_strdup ("DocumentsSaveAll");
	_tmp4_ = g_strdup ("DocumentsCloseAll");
	_tmp5_ = g_strdup ("DocumentsPrevious");
	_tmp6_ = g_strdup ("DocumentsNext");
	_tmp7_ = g_strdup ("DocumentsMoveToNewWindow");
	_tmp8_ = g_new0 (gchar*, 5 + 1);
	_tmp8_[0] = _tmp3_;
	_tmp8_[1] = _tmp4_;
	_tmp8_[2] = _tmp5_;
	_tmp8_[3] = _tmp6_;
	_tmp8_[4] = _tmp7_;
	action_names = _tmp8_;
	action_names_length1 = 5;
	_action_names_size_ = action_names_length1;
	_tmp9_ = action_names;
	_tmp9__length1 = action_names_length1;
	{
		gchar** action_name_collection = NULL;
		gint action_name_collection_length1 = 0;
		gint _action_name_collection_size_ = 0;
		gint action_name_it = 0;
		action_name_collection = _tmp9_;
		action_name_collection_length1 = _tmp9__length1;
		for (action_name_it = 0; action_name_it < _tmp9__length1; action_name_it = action_name_it + 1) {
			gchar* _tmp10_ = NULL;
			gchar* action_name = NULL;
			_tmp10_ = g_strdup (action_name_collection[action_name_it]);
			action_name = _tmp10_;
			{
				GtkAction* action = NULL;
				GtkActionGroup* _tmp11_ = NULL;
				const gchar* _tmp12_ = NULL;
				GtkAction* _tmp13_ = NULL;
				GtkAction* _tmp14_ = NULL;
				GtkAction* _tmp15_ = NULL;
				gboolean _tmp16_ = FALSE;
				_tmp11_ = self->priv->_static_action_group;
				_tmp12_ = action_name;
				_tmp13_ = gtk_action_group_get_action (_tmp11_, _tmp12_);
				_tmp14_ = _g_object_ref0 (_tmp13_);
				action = _tmp14_;
				_tmp15_ = action;
				_tmp16_ = sensitive;
				gtk_action_set_sensitive (_tmp15_, _tmp16_);
				_g_object_unref0 (action);
				_g_free0 (action_name);
			}
		}
	}
	_tmp17_ = sensitive;
	if (_tmp17_) {
		main_window_documents_update_next_prev_doc_sensitivity (self);
	}
	action_names = (_vala_array_free (action_names, action_names_length1, (GDestroyNotify) g_free), NULL);
}


static void main_window_documents_update_next_prev_doc_sensitivity (MainWindowDocuments* self) {
	DocumentsPanel* _tmp0_ = NULL;
	MainWindow* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	DocumentTab* _tmp3_ = NULL;
	GtkAction* action_prev = NULL;
	GtkActionGroup* _tmp4_ = NULL;
	GtkAction* _tmp5_ = NULL;
	GtkAction* _tmp6_ = NULL;
	GtkAction* action_next = NULL;
	GtkActionGroup* _tmp7_ = NULL;
	GtkAction* _tmp8_ = NULL;
	GtkAction* _tmp9_ = NULL;
	gint current_page = 0;
	DocumentsPanel* _tmp10_ = NULL;
	MainWindow* _tmp11_ = NULL;
	DocumentTab* _tmp12_ = NULL;
	DocumentTab* _tmp13_ = NULL;
	gint _tmp14_ = 0;
	GtkAction* _tmp15_ = NULL;
	gint _tmp16_ = 0;
	gint nb_pages = 0;
	DocumentsPanel* _tmp17_ = NULL;
	gint _tmp18_ = 0;
	GtkAction* _tmp19_ = NULL;
	gint _tmp20_ = 0;
	gint _tmp21_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp0_ != NULL);
	_tmp1_ = self->priv->_main_window;
	_tmp2_ = main_window_get_active_tab (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == NULL) {
		return;
	}
	_tmp4_ = self->priv->_static_action_group;
	_tmp5_ = gtk_action_group_get_action (_tmp4_, "DocumentsPrevious");
	_tmp6_ = _g_object_ref0 (_tmp5_);
	action_prev = _tmp6_;
	_tmp7_ = self->priv->_static_action_group;
	_tmp8_ = gtk_action_group_get_action (_tmp7_, "DocumentsNext");
	_tmp9_ = _g_object_ref0 (_tmp8_);
	action_next = _tmp9_;
	_tmp10_ = self->priv->_documents_panel;
	_tmp11_ = self->priv->_main_window;
	_tmp12_ = main_window_get_active_tab (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = gtk_notebook_page_num ((GtkNotebook*) _tmp10_, (GtkWidget*) _tmp13_);
	current_page = _tmp14_;
	_tmp15_ = action_prev;
	_tmp16_ = current_page;
	gtk_action_set_sensitive (_tmp15_, _tmp16_ > 0);
	_tmp17_ = self->priv->_documents_panel;
	_tmp18_ = gtk_notebook_get_n_pages ((GtkNotebook*) _tmp17_);
	nb_pages = _tmp18_;
	_tmp19_ = action_next;
	_tmp20_ = current_page;
	_tmp21_ = nb_pages;
	gtk_action_set_sensitive (_tmp19_, _tmp20_ < (_tmp21_ - 1));
	_g_object_unref0 (action_next);
	_g_object_unref0 (action_prev);
}


void main_window_documents_on_save_all (MainWindowDocuments* self) {
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_main_window;
	_tmp1_ = main_window_get_active_tab (_tmp0_);
	_tmp2_ = _tmp1_;
	g_return_if_fail (_tmp2_ != NULL);
	{
		GeeList* _doc_list = NULL;
		MainWindow* _tmp3_ = NULL;
		GeeList* _tmp4_ = NULL;
		gint _doc_size = 0;
		GeeList* _tmp5_ = NULL;
		gint _tmp6_ = 0;
		gint _tmp7_ = 0;
		gint _doc_index = 0;
		_tmp3_ = self->priv->_main_window;
		_tmp4_ = main_window_get_unsaved_documents (_tmp3_);
		_doc_list = _tmp4_;
		_tmp5_ = _doc_list;
		_tmp6_ = gee_collection_get_size ((GeeCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_doc_size = _tmp7_;
		_doc_index = -1;
		while (TRUE) {
			gint _tmp8_ = 0;
			gint _tmp9_ = 0;
			gint _tmp10_ = 0;
			Document* doc = NULL;
			GeeList* _tmp11_ = NULL;
			gint _tmp12_ = 0;
			gpointer _tmp13_ = NULL;
			Document* _tmp14_ = NULL;
			_tmp8_ = _doc_index;
			_doc_index = _tmp8_ + 1;
			_tmp9_ = _doc_index;
			_tmp10_ = _doc_size;
			if (!(_tmp9_ < _tmp10_)) {
				break;
			}
			_tmp11_ = _doc_list;
			_tmp12_ = _doc_index;
			_tmp13_ = gee_list_get (_tmp11_, _tmp12_);
			doc = (Document*) _tmp13_;
			_tmp14_ = doc;
			document_save (_tmp14_, TRUE, FALSE);
			_g_object_unref0 (doc);
		}
		_g_object_unref0 (_doc_list);
	}
}


void main_window_documents_on_close_all (MainWindowDocuments* self) {
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	MainWindow* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_main_window;
	_tmp1_ = main_window_get_active_tab (_tmp0_);
	_tmp2_ = _tmp1_;
	g_return_if_fail (_tmp2_ != NULL);
	_tmp3_ = self->priv->_main_window;
	main_window_close_all_documents (_tmp3_);
}


void main_window_documents_on_previous (MainWindowDocuments* self) {
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	DocumentsPanel* _tmp3_ = NULL;
	DocumentsPanel* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_main_window;
	_tmp1_ = main_window_get_active_tab (_tmp0_);
	_tmp2_ = _tmp1_;
	g_return_if_fail (_tmp2_ != NULL);
	_tmp3_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp3_ != NULL);
	_tmp4_ = self->priv->_documents_panel;
	gtk_notebook_prev_page ((GtkNotebook*) _tmp4_);
}


void main_window_documents_on_next (MainWindowDocuments* self) {
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	DocumentsPanel* _tmp3_ = NULL;
	DocumentsPanel* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_main_window;
	_tmp1_ = main_window_get_active_tab (_tmp0_);
	_tmp2_ = _tmp1_;
	g_return_if_fail (_tmp2_ != NULL);
	_tmp3_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp3_ != NULL);
	_tmp4_ = self->priv->_documents_panel;
	gtk_notebook_next_page ((GtkNotebook*) _tmp4_);
}


void main_window_documents_on_move_to_new_window (MainWindowDocuments* self) {
	DocumentTab* tab = NULL;
	MainWindow* _tmp0_ = NULL;
	DocumentTab* _tmp1_ = NULL;
	DocumentTab* _tmp2_ = NULL;
	DocumentTab* _tmp3_ = NULL;
	DocumentsPanel* _tmp4_ = NULL;
	MainWindow* new_window = NULL;
	LatexilaApp* _tmp5_ = NULL;
	LatexilaApp* _tmp6_ = NULL;
	MainWindow* _tmp7_ = NULL;
	MainWindow* _tmp8_ = NULL;
	DocumentView* view = NULL;
	DocumentView* _tmp9_ = NULL;
	DocumentView* _tmp10_ = NULL;
	DocumentView* _tmp11_ = NULL;
	DocumentsPanel* _tmp12_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_main_window;
	_tmp1_ = main_window_get_active_tab (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	tab = _tmp3_;
	g_return_if_fail (tab != NULL);
	_tmp4_ = self->priv->_documents_panel;
	g_return_if_fail (_tmp4_ != NULL);
	_tmp5_ = latexila_app_get_instance ();
	_tmp6_ = _tmp5_;
	_tmp7_ = latexila_app_create_window (_tmp6_);
	_tmp8_ = _tmp7_;
	_g_object_unref0 (_tmp6_);
	new_window = _tmp8_;
	_tmp9_ = document_tab_get_view (tab);
	_tmp10_ = _tmp9_;
	_tmp11_ = _g_object_ref0 (_tmp10_);
	view = _tmp11_;
	_tmp12_ = self->priv->_documents_panel;
	documents_panel_remove_tab (_tmp12_, tab);
	main_window_create_tab_with_view (new_window, view);
	_g_object_unref0 (view);
	_g_object_unref0 (new_window);
	_g_object_unref0 (tab);
}


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


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


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


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


static gchar* value_main_window_documents_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		MainWindowDocuments* 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 = main_window_documents_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_main_window_documents_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	MainWindowDocuments** 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 = main_window_documents_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_main_window_documents (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecMainWindowDocuments* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_MAIN_WINDOW_DOCUMENTS), 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_main_window_documents (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_MAIN_WINDOW_DOCUMENTS), NULL);
	return value->data[0].v_pointer;
}


void value_set_main_window_documents (GValue* value, gpointer v_object) {
	MainWindowDocuments* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_MAIN_WINDOW_DOCUMENTS));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_MAIN_WINDOW_DOCUMENTS));
		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;
		main_window_documents_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		main_window_documents_unref (old);
	}
}


void value_take_main_window_documents (GValue* value, gpointer v_object) {
	MainWindowDocuments* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_MAIN_WINDOW_DOCUMENTS));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_MAIN_WINDOW_DOCUMENTS));
		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) {
		main_window_documents_unref (old);
	}
}


static void main_window_documents_class_init (MainWindowDocumentsClass * klass) {
	main_window_documents_parent_class = g_type_class_peek_parent (klass);
	((MainWindowDocumentsClass *) klass)->finalize = main_window_documents_finalize;
	g_type_class_add_private (klass, sizeof (MainWindowDocumentsPrivate));
}


static void main_window_documents_instance_init (MainWindowDocuments * self) {
	self->priv = MAIN_WINDOW_DOCUMENTS_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void main_window_documents_finalize (MainWindowDocuments* obj) {
	MainWindowDocuments * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MAIN_WINDOW_DOCUMENTS, MainWindowDocuments);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->_ui_manager);
	_g_object_unref0 (self->priv->_documents_panel);
	_g_object_unref0 (self->priv->_static_action_group);
	_g_object_unref0 (self->priv->_list_action_group);
}


GType main_window_documents_get_type (void) {
	static volatile gsize main_window_documents_type_id__volatile = 0;
	if (g_once_init_enter (&main_window_documents_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_main_window_documents_init, value_main_window_documents_free_value, value_main_window_documents_copy_value, value_main_window_documents_peek_pointer, "p", value_main_window_documents_collect_value, "p", value_main_window_documents_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (MainWindowDocumentsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) main_window_documents_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MainWindowDocuments), 0, (GInstanceInitFunc) main_window_documents_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 main_window_documents_type_id;
		main_window_documents_type_id = g_type_register_fundamental (g_type_fundamental_next (), "MainWindowDocuments", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&main_window_documents_type_id__volatile, main_window_documents_type_id);
	}
	return main_window_documents_type_id__volatile;
}


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


void main_window_documents_unref (gpointer instance) {
	MainWindowDocuments* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		MAIN_WINDOW_DOCUMENTS_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



