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

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

#include <tepl/tepl.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <latexila.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_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;
typedef struct _DocumentTabPrivate DocumentTabPrivate;
enum  {
	DOCUMENT_TAB_0_PROPERTY,
	DOCUMENT_TAB_DOCUMENT_VIEW_PROPERTY,
	DOCUMENT_TAB_DOCUMENT_PROPERTY,
	DOCUMENT_TAB_AUTO_SAVE_INTERVAL_PROPERTY,
	DOCUMENT_TAB_AUTO_SAVE_PROPERTY,
	DOCUMENT_TAB_NUM_PROPERTIES
};
static GParamSpec* document_tab_properties[DOCUMENT_TAB_NUM_PROPERTIES];

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

#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 _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _DocumentPrivate DocumentPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block14Data Block14Data;

struct _DocumentTab {
	TeplTab parent_instance;
	DocumentTabPrivate * priv;
};

struct _DocumentTabClass {
	TeplTabClass parent_class;
};

struct _DocumentTabPrivate {
	gboolean ask_if_externally_modified;
	guint auto_save_timeout;
	guint _auto_save_interval;
	gboolean _auto_save;
};

struct _Document {
	TeplBuffer parent_instance;
	DocumentPrivate * priv;
	DocumentTab* tab;
};

struct _DocumentClass {
	TeplBufferClass parent_class;
};

struct _Block14Data {
	int _ref_count_;
	DocumentTab* self;
	TeplInfoBar* infobar;
};

static gint DocumentTab_private_offset;
static gpointer document_tab_parent_class = NULL;

VALA_EXTERN GType document_tab_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DocumentTab, g_object_unref)
VALA_EXTERN DocumentTab* document_tab_new (void);
VALA_EXTERN DocumentTab* document_tab_construct (GType object_type);
VALA_EXTERN GType document_view_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DocumentView, g_object_unref)
VALA_EXTERN Document* document_new (void);
VALA_EXTERN Document* document_construct (GType object_type);
VALA_EXTERN GType document_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Document, g_object_unref)
VALA_EXTERN DocumentView* document_view_new (Document* doc);
VALA_EXTERN DocumentView* document_view_construct (GType object_type,
                                       Document* doc);
static void document_tab_initialize (DocumentTab* self);
VALA_EXTERN DocumentTab* document_tab_new_from_location (GFile* location);
VALA_EXTERN DocumentTab* document_tab_construct_from_location (GType object_type,
                                                   GFile* location);
VALA_EXTERN Document* document_tab_get_document (DocumentTab* self);
VALA_EXTERN void document_load (Document* self,
                    GFile* location);
VALA_EXTERN DocumentTab* document_tab_new_with_view (DocumentView* document_view);
VALA_EXTERN DocumentTab* document_tab_construct_with_view (GType object_type,
                                               DocumentView* document_view);
VALA_EXTERN DocumentView* document_tab_get_document_view (DocumentTab* self);
static gboolean document_tab_view_focused_in (DocumentTab* self);
static gboolean _document_tab_view_focused_in_gtk_widget_focus_in_event (GtkWidget* _sender,
                                                                  GdkEventFocus* event,
                                                                  gpointer self);
VALA_EXTERN TeplView* tepl_tab_get_view (TeplTab* self);
static gboolean document_tab_install_auto_save_timeout_if_needed (DocumentTab* self);
static void __lambda43_ (DocumentTab* self);
static void ___lambda43__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
VALA_EXTERN gchar* document_tab_get_menu_tip (DocumentTab* self);
VALA_EXTERN gchar* document_get_uri_for_display (Document* self);
VALA_EXTERN gboolean document_is_externally_modified (Document* self);
static Block14Data* block14_data_ref (Block14Data* _data14_);
static void block14_data_unref (void * _userdata_);
VALA_EXTERN GFile* document_get_location (Document* self);
static void ___lambda42_ (Block14Data* _data14_,
                   gint response_id);
static void ____lambda42__gtk_info_bar_response (GtkInfoBar* _sender,
                                          gint response_id,
                                          gpointer self);
static void document_tab_install_auto_save_timeout (DocumentTab* self);
VALA_EXTERN gboolean document_tab_get_auto_save (DocumentTab* self);
VALA_EXTERN guint document_tab_get_auto_save_interval (DocumentTab* self);
static gboolean document_tab_on_auto_save (DocumentTab* self);
static gboolean _document_tab_on_auto_save_gsource_func (gpointer self);
VALA_EXTERN gboolean document_get_readonly (Document* self);
static void document_tab_remove_auto_save_timeout (DocumentTab* self);
VALA_EXTERN void document_save (Document* self,
                    gboolean check_file_changed_on_disk,
                    gboolean force);
VALA_EXTERN void document_tab_set_auto_save_interval (DocumentTab* self,
                                          guint value);
VALA_EXTERN void document_tab_set_auto_save (DocumentTab* self,
                                 gboolean value);
static void document_tab_finalize (GObject * obj);
static GType document_tab_get_type_once (void);
static void _vala_document_tab_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec);
static void _vala_document_tab_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec);

static inline gpointer
document_tab_get_instance_private (DocumentTab* self)
{
	return G_STRUCT_MEMBER_P (self, DocumentTab_private_offset);
}

DocumentTab*
document_tab_construct (GType object_type)
{
	DocumentTab * self = NULL;
	DocumentView* document_view = NULL;
	Document* _tmp0_;
	Document* _tmp1_;
	DocumentView* _tmp2_;
	DocumentView* _tmp3_;
	_tmp0_ = document_new ();
	_tmp1_ = _tmp0_;
	_tmp2_ = document_view_new (_tmp1_);
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp1_);
	document_view = _tmp3_;
	self = (DocumentTab*) g_object_new (object_type, "view", document_view, NULL);
	document_tab_initialize (self);
	_g_object_unref0 (document_view);
	return self;
}

DocumentTab*
document_tab_new (void)
{
	return document_tab_construct (TYPE_DOCUMENT_TAB);
}

DocumentTab*
document_tab_construct_from_location (GType object_type,
                                      GFile* location)
{
	DocumentTab * self = NULL;
	Document* _tmp0_;
	Document* _tmp1_;
	g_return_val_if_fail (location != NULL, NULL);
	self = (DocumentTab*) document_tab_construct (object_type);
	_tmp0_ = document_tab_get_document (self);
	_tmp1_ = _tmp0_;
	document_load (_tmp1_, location);
	return self;
}

DocumentTab*
document_tab_new_from_location (GFile* location)
{
	return document_tab_construct_from_location (TYPE_DOCUMENT_TAB, location);
}

DocumentTab*
document_tab_construct_with_view (GType object_type,
                                  DocumentView* document_view)
{
	DocumentTab * self = NULL;
	g_return_val_if_fail (document_view != NULL, NULL);
	self = (DocumentTab*) g_object_new (object_type, "view", document_view, NULL);
	document_tab_initialize (self);
	return self;
}

DocumentTab*
document_tab_new_with_view (DocumentView* document_view)
{
	return document_tab_construct_with_view (TYPE_DOCUMENT_TAB, document_view);
}

static gboolean
_document_tab_view_focused_in_gtk_widget_focus_in_event (GtkWidget* _sender,
                                                         GdkEventFocus* event,
                                                         gpointer self)
{
	gboolean result;
	result = document_tab_view_focused_in ((DocumentTab*) self);
	return result;
}

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

static void
__lambda43_ (DocumentTab* self)
{
	if (self->priv->auto_save_timeout <= ((guint) 0)) {
		document_tab_install_auto_save_timeout_if_needed (self);
	}
}

static void
___lambda43__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda43_ ((DocumentTab*) self);
}

static void
document_tab_initialize (DocumentTab* self)
{
	Document* _tmp0_;
	Document* _tmp1_;
	DocumentView* _tmp2_;
	DocumentView* _tmp3_;
	TeplView* _tmp4_;
	TeplView* _tmp5_;
	LatexilaSettings* latexila_settings = NULL;
	LatexilaSettings* _tmp6_;
	LatexilaSettings* _tmp7_;
	GSettings* editor_settings = NULL;
	GSettings* _tmp8_;
	GSettings* _tmp9_;
	Document* _tmp10_;
	Document* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = document_tab_get_document (self);
	_tmp1_ = _tmp0_;
	_tmp1_->tab = self;
	_tmp2_ = document_tab_get_document_view (self);
	_tmp3_ = _tmp2_;
	g_signal_connect_object ((GtkWidget*) _tmp3_, "focus-in-event", (GCallback) _document_tab_view_focused_in_gtk_widget_focus_in_event, self, 0);
	_tmp4_ = tepl_tab_get_view ((TeplTab*) self);
	_tmp5_ = _tmp4_;
	gtk_widget_show_all ((GtkWidget*) _tmp5_);
	_tmp6_ = latexila_settings_get_singleton ();
	_tmp7_ = _g_object_ref0 (_tmp6_);
	latexila_settings = _tmp7_;
	_tmp8_ = latexila_settings_peek_editor_settings (latexila_settings);
	_tmp9_ = _g_object_ref0 (_tmp8_);
	editor_settings = _tmp9_;
	g_settings_bind (editor_settings, "auto-save", (GObject*) self, "auto-save", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
	g_settings_bind (editor_settings, "auto-save-interval", (GObject*) self, "auto-save-interval", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY);
	document_tab_install_auto_save_timeout_if_needed (self);
	_tmp10_ = document_tab_get_document (self);
	_tmp11_ = _tmp10_;
	g_signal_connect_object ((GObject*) _tmp11_, "notify::location", (GCallback) ___lambda43__g_object_notify, self, 0);
	_g_object_unref0 (editor_settings);
	_g_object_unref0 (latexila_settings);
}

gchar*
document_tab_get_menu_tip (DocumentTab* self)
{
	Document* _tmp0_;
	Document* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = document_tab_get_document (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = document_get_uri_for_display (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf (_ ("Activate “%s”"), _tmp3_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	result = _tmp5_;
	return result;
}

static Block14Data*
block14_data_ref (Block14Data* _data14_)
{
	g_atomic_int_inc (&_data14_->_ref_count_);
	return _data14_;
}

static void
block14_data_unref (void * _userdata_)
{
	Block14Data* _data14_;
	_data14_ = (Block14Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data14_->_ref_count_)) {
		DocumentTab* self;
		self = _data14_->self;
		_g_object_unref0 (_data14_->infobar);
		_g_object_unref0 (self);
		g_slice_free (Block14Data, _data14_);
	}
}

static void
___lambda42_ (Block14Data* _data14_,
              gint response_id)
{
	DocumentTab* self;
	TeplInfoBar* _tmp6_;
	DocumentView* _tmp7_;
	DocumentView* _tmp8_;
	self = _data14_->self;
	if (response_id == ((gint) GTK_RESPONSE_OK)) {
		Document* _tmp0_;
		Document* _tmp1_;
		Document* _tmp2_;
		Document* _tmp3_;
		GFile* _tmp4_;
		GFile* _tmp5_;
		_tmp0_ = document_tab_get_document (self);
		_tmp1_ = _tmp0_;
		_tmp2_ = document_tab_get_document (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = document_get_location (_tmp3_);
		_tmp5_ = _tmp4_;
		document_load (_tmp1_, _tmp5_);
		self->priv->ask_if_externally_modified = FALSE;
	}
	_tmp6_ = _data14_->infobar;
	gtk_widget_destroy ((GtkWidget*) _tmp6_);
	_tmp7_ = document_tab_get_document_view (self);
	_tmp8_ = _tmp7_;
	gtk_widget_grab_focus ((GtkWidget*) _tmp8_);
}

static void
____lambda42__gtk_info_bar_response (GtkInfoBar* _sender,
                                     gint response_id,
                                     gpointer self)
{
	___lambda42_ (self, response_id);
}

static gboolean
document_tab_view_focused_in (DocumentTab* self)
{
	GFile* location = NULL;
	TeplBuffer* _tmp0_;
	TeplFile* _tmp1_;
	GFile* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	GFile* _tmp5_;
	Document* _tmp6_;
	Document* _tmp7_;
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	if (self->priv->ask_if_externally_modified) {
		result = FALSE;
		return result;
	}
	_tmp0_ = tepl_tab_get_buffer ((TeplTab*) self);
	_tmp1_ = tepl_buffer_get_file (_tmp0_);
	_tmp2_ = tepl_file_get_location (_tmp1_);
	_tmp3_ = _g_object_ref0 (_tmp2_);
	location = _tmp3_;
	_tmp4_ = location;
	if (_tmp4_ == NULL) {
		result = FALSE;
		_g_object_unref0 (location);
		return result;
	}
	_tmp5_ = location;
	if (!g_file_has_uri_scheme (_tmp5_, "file")) {
		result = FALSE;
		_g_object_unref0 (location);
		return result;
	}
	_tmp6_ = document_tab_get_document (self);
	_tmp7_ = _tmp6_;
	if (document_is_externally_modified (_tmp7_)) {
		Block14Data* _data14_;
		Document* _tmp8_;
		Document* _tmp9_;
		GFile* _tmp10_;
		GFile* _tmp11_;
		Document* _tmp12_;
		Document* _tmp13_;
		TeplInfoBar* _tmp14_;
		TeplInfoBar* _tmp15_;
		TeplInfoBar* _tmp16_;
		TeplInfoBar* _tmp17_;
		TeplInfoBar* _tmp18_;
		_data14_ = g_slice_new0 (Block14Data);
		_data14_->_ref_count_ = 1;
		_data14_->self = g_object_ref (self);
		self->priv->ask_if_externally_modified = TRUE;
		_tmp8_ = document_tab_get_document (self);
		_tmp9_ = _tmp8_;
		_tmp10_ = document_get_location (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = document_tab_get_document (self);
		_tmp13_ = _tmp12_;
		_tmp14_ = tepl_io_error_info_bar_externally_modified (_tmp11_, gtk_text_buffer_get_modified ((GtkTextBuffer*) _tmp13_));
		_tmp15_ = _g_object_ref0 (_tmp14_);
		_data14_->infobar = _tmp15_;
		_tmp16_ = _data14_->infobar;
		tepl_tab_add_info_bar ((TeplTab*) self, (GtkInfoBar*) _tmp16_);
		_tmp17_ = _data14_->infobar;
		gtk_widget_show ((GtkWidget*) _tmp17_);
		_tmp18_ = _data14_->infobar;
		g_signal_connect_data ((GtkInfoBar*) _tmp18_, "response", (GCallback) ____lambda42__gtk_info_bar_response, block14_data_ref (_data14_), (GClosureNotify) block14_data_unref, 0);
		block14_data_unref (_data14_);
		_data14_ = NULL;
	}
	result = FALSE;
	_g_object_unref0 (location);
	return result;
}

static gboolean
_document_tab_on_auto_save_gsource_func (gpointer self)
{
	gboolean result;
	result = document_tab_on_auto_save ((DocumentTab*) self);
	return result;
}

static void
document_tab_install_auto_save_timeout (DocumentTab* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	guint _tmp2_;
	guint _tmp3_;
	guint _tmp4_;
	guint _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (self->priv->auto_save_timeout <= ((guint) 0));
	_tmp0_ = document_tab_get_auto_save (self);
	_tmp1_ = _tmp0_;
	g_return_if_fail (_tmp1_);
	_tmp2_ = document_tab_get_auto_save_interval (self);
	_tmp3_ = _tmp2_;
	g_return_if_fail (_tmp3_ > ((guint) 0));
	_tmp4_ = document_tab_get_auto_save_interval (self);
	_tmp5_ = _tmp4_;
	self->priv->auto_save_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, _tmp5_ * 60, _document_tab_on_auto_save_gsource_func, g_object_ref (self), g_object_unref);
}

static gboolean
document_tab_install_auto_save_timeout_if_needed (DocumentTab* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (self->priv->auto_save_timeout <= ((guint) 0), FALSE);
	_tmp2_ = document_tab_get_auto_save (self);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		Document* _tmp4_;
		Document* _tmp5_;
		GFile* _tmp6_;
		GFile* _tmp7_;
		_tmp4_ = document_tab_get_document (self);
		_tmp5_ = _tmp4_;
		_tmp6_ = document_get_location (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp1_ = _tmp7_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		Document* _tmp8_;
		Document* _tmp9_;
		gboolean _tmp10_;
		gboolean _tmp11_;
		_tmp8_ = document_tab_get_document (self);
		_tmp9_ = _tmp8_;
		_tmp10_ = document_get_readonly (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp0_ = !_tmp11_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		document_tab_install_auto_save_timeout (self);
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

static void
document_tab_remove_auto_save_timeout (DocumentTab* self)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (self->priv->auto_save_timeout > ((guint) 0));
	g_source_remove (self->priv->auto_save_timeout);
	self->priv->auto_save_timeout = (guint) 0;
}

static gboolean
document_tab_on_auto_save (DocumentTab* self)
{
	Document* _tmp0_;
	Document* _tmp1_;
	GFile* _tmp2_;
	GFile* _tmp3_;
	Document* _tmp4_;
	Document* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	guint _tmp10_;
	guint _tmp11_;
	Document* _tmp12_;
	Document* _tmp13_;
	gboolean result = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = document_tab_get_document (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = document_get_location (_tmp1_);
	_tmp3_ = _tmp2_;
	g_return_val_if_fail (_tmp3_ != NULL, FALSE);
	_tmp4_ = document_tab_get_document (self);
	_tmp5_ = _tmp4_;
	_tmp6_ = document_get_readonly (_tmp5_);
	_tmp7_ = _tmp6_;
	g_return_val_if_fail (!_tmp7_, FALSE);
	g_return_val_if_fail (self->priv->auto_save_timeout > ((guint) 0), FALSE);
	_tmp8_ = document_tab_get_auto_save (self);
	_tmp9_ = _tmp8_;
	g_return_val_if_fail (_tmp9_, FALSE);
	_tmp10_ = document_tab_get_auto_save_interval (self);
	_tmp11_ = _tmp10_;
	g_return_val_if_fail (_tmp11_ > ((guint) 0), FALSE);
	_tmp12_ = document_tab_get_document (self);
	_tmp13_ = _tmp12_;
	if (gtk_text_buffer_get_modified ((GtkTextBuffer*) _tmp13_)) {
		Document* _tmp14_;
		Document* _tmp15_;
		_tmp14_ = document_tab_get_document (self);
		_tmp15_ = _tmp14_;
		document_save (_tmp15_, TRUE, FALSE);
	}
	result = TRUE;
	return result;
}

DocumentView*
document_tab_get_document_view (DocumentTab* self)
{
	DocumentView* result;
	TeplView* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = tepl_tab_get_view ((TeplTab*) self);
	result = IS_DOCUMENT_VIEW (_tmp0_) ? ((DocumentView*) _tmp0_) : NULL;
	return result;
}

Document*
document_tab_get_document (DocumentTab* self)
{
	Document* result;
	TeplBuffer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = tepl_tab_get_buffer ((TeplTab*) self);
	result = IS_DOCUMENT (_tmp0_) ? ((Document*) _tmp0_) : NULL;
	return result;
}

guint
document_tab_get_auto_save_interval (DocumentTab* self)
{
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	result = self->priv->_auto_save_interval;
	return result;
}

void
document_tab_set_auto_save_interval (DocumentTab* self,
                                     guint value)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (value > ((guint) 0));
	if (self->priv->_auto_save_interval == value) {
		return;
	}
	self->priv->_auto_save_interval = value;
	if (!self->priv->_auto_save) {
		return;
	}
	if (self->priv->auto_save_timeout > ((guint) 0)) {
		Document* _tmp0_;
		Document* _tmp1_;
		GFile* _tmp2_;
		GFile* _tmp3_;
		Document* _tmp4_;
		Document* _tmp5_;
		gboolean _tmp6_;
		gboolean _tmp7_;
		_tmp0_ = document_tab_get_document (self);
		_tmp1_ = _tmp0_;
		_tmp2_ = document_get_location (_tmp1_);
		_tmp3_ = _tmp2_;
		g_return_if_fail (_tmp3_ != NULL);
		_tmp4_ = document_tab_get_document (self);
		_tmp5_ = _tmp4_;
		_tmp6_ = document_get_readonly (_tmp5_);
		_tmp7_ = _tmp6_;
		g_return_if_fail (!_tmp7_);
		document_tab_remove_auto_save_timeout (self);
		document_tab_install_auto_save_timeout (self);
	}
	g_object_notify_by_pspec ((GObject *) self, document_tab_properties[DOCUMENT_TAB_AUTO_SAVE_INTERVAL_PROPERTY]);
}

gboolean
document_tab_get_auto_save (DocumentTab* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_auto_save;
	return result;
}

void
document_tab_set_auto_save (DocumentTab* self,
                            gboolean value)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp11_ = FALSE;
	gboolean _tmp12_ = FALSE;
	gboolean _tmp13_ = FALSE;
	gboolean _tmp14_ = FALSE;
	g_return_if_fail (self != NULL);
	if (value == self->priv->_auto_save) {
		return;
	}
	self->priv->_auto_save = value;
	if (self->priv->_auto_save) {
		_tmp2_ = self->priv->auto_save_timeout <= ((guint) 0);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		Document* _tmp3_;
		Document* _tmp4_;
		GFile* _tmp5_;
		GFile* _tmp6_;
		_tmp3_ = document_tab_get_document (self);
		_tmp4_ = _tmp3_;
		_tmp5_ = document_get_location (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp1_ = _tmp6_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		Document* _tmp7_;
		Document* _tmp8_;
		gboolean _tmp9_;
		gboolean _tmp10_;
		_tmp7_ = document_tab_get_document (self);
		_tmp8_ = _tmp7_;
		_tmp9_ = document_get_readonly (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp0_ = !_tmp10_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		document_tab_install_auto_save_timeout (self);
		return;
	}
	if (!self->priv->_auto_save) {
		_tmp11_ = self->priv->auto_save_timeout > ((guint) 0);
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		document_tab_remove_auto_save_timeout (self);
		return;
	}
	if (!self->priv->_auto_save) {
		_tmp14_ = self->priv->auto_save_timeout <= ((guint) 0);
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		_tmp13_ = TRUE;
	} else {
		Document* _tmp15_;
		Document* _tmp16_;
		GFile* _tmp17_;
		GFile* _tmp18_;
		_tmp15_ = document_tab_get_document (self);
		_tmp16_ = _tmp15_;
		_tmp17_ = document_get_location (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp13_ = _tmp18_ == NULL;
	}
	if (_tmp13_) {
		_tmp12_ = TRUE;
	} else {
		Document* _tmp19_;
		Document* _tmp20_;
		gboolean _tmp21_;
		gboolean _tmp22_;
		_tmp19_ = document_tab_get_document (self);
		_tmp20_ = _tmp19_;
		_tmp21_ = document_get_readonly (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp12_ = _tmp22_;
	}
	g_return_if_fail (_tmp12_);
	g_object_notify_by_pspec ((GObject *) self, document_tab_properties[DOCUMENT_TAB_AUTO_SAVE_PROPERTY]);
}

static void
document_tab_class_init (DocumentTabClass * klass,
                         gpointer klass_data)
{
	document_tab_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DocumentTab_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_document_tab_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_document_tab_set_property;
	G_OBJECT_CLASS (klass)->finalize = document_tab_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DOCUMENT_TAB_DOCUMENT_VIEW_PROPERTY, document_tab_properties[DOCUMENT_TAB_DOCUMENT_VIEW_PROPERTY] = g_param_spec_object ("document-view", "document-view", "document-view", TYPE_DOCUMENT_VIEW, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DOCUMENT_TAB_DOCUMENT_PROPERTY, document_tab_properties[DOCUMENT_TAB_DOCUMENT_PROPERTY] = g_param_spec_object ("document", "document", "document", TYPE_DOCUMENT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DOCUMENT_TAB_AUTO_SAVE_INTERVAL_PROPERTY, document_tab_properties[DOCUMENT_TAB_AUTO_SAVE_INTERVAL_PROPERTY] = g_param_spec_uint ("auto-save-interval", "auto-save-interval", "auto-save-interval", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DOCUMENT_TAB_AUTO_SAVE_PROPERTY, document_tab_properties[DOCUMENT_TAB_AUTO_SAVE_PROPERTY] = g_param_spec_boolean ("auto-save", "auto-save", "auto-save", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
document_tab_instance_init (DocumentTab * self,
                            gpointer klass)
{
	self->priv = document_tab_get_instance_private (self);
	self->priv->ask_if_externally_modified = FALSE;
}

static void
document_tab_finalize (GObject * obj)
{
	DocumentTab * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DOCUMENT_TAB, DocumentTab);
	G_OBJECT_CLASS (document_tab_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
document_tab_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DocumentTabClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) document_tab_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DocumentTab), 0, (GInstanceInitFunc) document_tab_instance_init, NULL };
	GType document_tab_type_id;
	document_tab_type_id = g_type_register_static (tepl_tab_get_type (), "DocumentTab", &g_define_type_info, 0);
	DocumentTab_private_offset = g_type_add_instance_private (document_tab_type_id, sizeof (DocumentTabPrivate));
	return document_tab_type_id;
}

GType
document_tab_get_type (void)
{
	static gsize document_tab_type_id__volatile = 0;
	if (g_once_init_enter (&document_tab_type_id__volatile)) {
		GType document_tab_type_id;
		document_tab_type_id = document_tab_get_type_once ();
		g_once_init_leave (&document_tab_type_id__volatile, document_tab_type_id);
	}
	return document_tab_type_id__volatile;
}

static void
_vala_document_tab_get_property (GObject * object,
                                 guint property_id,
                                 GValue * value,
                                 GParamSpec * pspec)
{
	DocumentTab * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_DOCUMENT_TAB, DocumentTab);
	switch (property_id) {
		case DOCUMENT_TAB_DOCUMENT_VIEW_PROPERTY:
		g_value_set_object (value, document_tab_get_document_view (self));
		break;
		case DOCUMENT_TAB_DOCUMENT_PROPERTY:
		g_value_set_object (value, document_tab_get_document (self));
		break;
		case DOCUMENT_TAB_AUTO_SAVE_INTERVAL_PROPERTY:
		g_value_set_uint (value, document_tab_get_auto_save_interval (self));
		break;
		case DOCUMENT_TAB_AUTO_SAVE_PROPERTY:
		g_value_set_boolean (value, document_tab_get_auto_save (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_document_tab_set_property (GObject * object,
                                 guint property_id,
                                 const GValue * value,
                                 GParamSpec * pspec)
{
	DocumentTab * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_DOCUMENT_TAB, DocumentTab);
	switch (property_id) {
		case DOCUMENT_TAB_AUTO_SAVE_INTERVAL_PROPERTY:
		document_tab_set_auto_save_interval (self, g_value_get_uint (value));
		break;
		case DOCUMENT_TAB_AUTO_SAVE_PROPERTY:
		document_tab_set_auto_save (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

