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

/* -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-*/

#include "codecore.h"
#include <gio/gio.h>
#include <handy.h>
#include <gtksourceview/gtksource.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <pango/pango.h>
#include <glib-object.h>
#include <glib/gstdio.h>
#include <granite.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h>
#include <fontconfig/fontconfig.h>
#include <pango/pangocairo.h>
#include <cairo-gobject.h>
#include <pango/pangofc-fontmap.h>

#define SCRATCH_SERVICES_DOCUMENT_LOAD_TIMEOUT_MSEC ((guint) 5000)
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	SCRATCH_SERVICES_DOCUMENT_0_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_ACTIONS_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_TAB_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_IS_FILE_TEMPORARY_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_FILE_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_PROJECT_PATH_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_TITLE_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_MIME_TYPE_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_ICON_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_LOCKED_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_LOADING_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_CLOSING_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_SOURCE_VIEW_PROPERTY,
	SCRATCH_SERVICES_DOCUMENT_NUM_PROPERTIES
};
static GParamSpec* scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block34Data Block34Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block35Data Block35Data;
typedef struct _ScratchServicesDocumentOpenData ScratchServicesDocumentOpenData;
typedef struct _ScratchServicesDocumentDoCloseData ScratchServicesDocumentDoCloseData;
typedef struct _ScratchServicesDocumentSaveWithHoldData ScratchServicesDocumentSaveWithHoldData;
typedef struct _ScratchServicesDocumentSaveAsWithHoldData ScratchServicesDocumentSaveAsWithHoldData;
typedef struct _Block36Data Block36Data;
typedef struct _ScratchServicesDocumentSaveData ScratchServicesDocumentSaveData;
typedef struct _ScratchServicesDocumentSaveAsData ScratchServicesDocumentSaveAsData;
typedef struct _Block37Data Block37Data;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
typedef struct _ScratchServicesDocumentCheckFileStatusData ScratchServicesDocumentCheckFileStatusData;
typedef struct _Block38Data Block38Data;
typedef struct _Block39Data Block39Data;
typedef struct _Block40Data Block40Data;
typedef struct _Block41Data Block41Data;
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_match_info_unref0(var) ((var == NULL) ? NULL : (var = (g_match_info_unref (var), NULL)))
#define __vala_PangoFontDescription_free0(var) ((var == NULL) ? NULL : (var = (_vala_PangoFontDescription_free (var), NULL)))
enum  {
	SCRATCH_SERVICES_DOCUMENT_DOC_OPENED_SIGNAL,
	SCRATCH_SERVICES_DOCUMENT_DOC_CLOSED_SIGNAL,
	SCRATCH_SERVICES_DOCUMENT_NUM_SIGNALS
};
static guint scratch_services_document_signals[SCRATCH_SERVICES_DOCUMENT_NUM_SIGNALS] = {0};
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _ScratchServicesDocumentPrivate {
	GSimpleActionGroup* _actions;
	HdyTabPage* _tab;
	GtkSourceFile* source_file;
	gchar* _title;
	gchar* _mime_type;
	GIcon* _icon;
	gboolean _locked;
	gboolean _closing;
	ScratchWidgetsSourceView* _source_view;
	ScratchServicesSymbolOutline* outline;
	gchar* last_save_content;
	gboolean completion_shown;
	GtkScrolledWindow* scroll;
	GtkSourceMap* source_map;
	GtkPaned* outline_widget_pane;
	GCancellable* save_cancellable;
	GCancellable* load_cancellable;
	gulong onchange_handler_id;
	gboolean loaded;
	gboolean mounted;
	GMount* mount;
	GIcon* locked_icon;
	guint load_timout_id;
	gboolean is_saving;
	GRecMutex __lock_is_saving;
	GRecMutex __lock_source_view;
};

struct _Block34Data {
	int _ref_count_;
	ScratchServicesDocument* self;
	guint timeout_saving;
};

struct _Block35Data {
	int _ref_count_;
	ScratchServicesDocument* self;
	GraniteWidgetsAlertView* alert_view;
};

struct _ScratchServicesDocumentOpenData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchServicesDocument* self;
	gboolean force;
	GCancellable* _tmp0_;
	GCancellable* _tmp1_;
	GCancellable* _tmp2_;
	GCancellable* _tmp3_;
	GFile* _tmp4_;
	GFile* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GError* e;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GError* _tmp10_;
	const gchar* _tmp11_;
	ScratchWidgetsSourceView* _tmp12_;
	gchar* content_type;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gboolean _tmp16_;
	gboolean _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	Block35Data* _data35_;
	gchar* title;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* description;
	gchar* _tmp24_;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	GraniteWidgetsAlertView* _tmp27_;
	GraniteWidgetsAlertView* _tmp28_;
	GraniteWidgetsAlertView* _tmp29_;
	GtkStack* _tmp30_;
	GraniteWidgetsAlertView* _tmp31_;
	GtkStack* _tmp32_;
	GraniteWidgetsAlertView* _tmp33_;
	GraniteWidgetsAlertView* _tmp34_;
	GtkSourceBuffer* buffer;
	GtkSourceBuffer* _tmp35_;
	GtkSourceFileLoader* source_file_loader;
	GtkSourceBuffer* _tmp36_;
	GtkSourceFile* _tmp37_;
	GtkSourceFileLoader* _tmp38_;
	GtkSourceFileLoader* _tmp39_;
	GCancellable* _tmp40_;
	GtkSourceBuffer* source_buffer;
	ScratchWidgetsSourceView* _tmp41_;
	GtkTextBuffer* _tmp42_;
	GtkTextBuffer* _tmp43_;
	GtkSourceBuffer* _tmp44_;
	GtkSourceBuffer* _tmp45_;
	GtkSourceBuffer* _tmp46_;
	GtkSourceBuffer* _tmp47_;
	GtkSourceBuffer* _tmp48_;
	gchar* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	GtkSourceBuffer* _tmp52_;
	ScratchWidgetsSourceView* _tmp53_;
	GtkTextBuffer* _tmp54_;
	GtkTextBuffer* _tmp55_;
	GtkSourceBuffer* _tmp56_;
	gchar* _tmp57_;
	gchar* _tmp58_;
	gchar* _tmp59_;
	GError* _vala1_e;
	GError* _tmp60_;
	const gchar* _tmp61_;
	ScratchWidgetsSourceView* _tmp62_;
	GtkTextBuffer* _tmp63_;
	GtkTextBuffer* _tmp64_;
	GtkSourceBuffer* _tmp65_;
	gchar* _tmp66_;
	gchar* _tmp67_;
	gchar* _tmp68_;
	GError* _inner_error1_;
	ScratchWidgetsSourceView* _tmp69_;
	GFile* _tmp70_;
	GFile* _tmp71_;
	ScratchWidgetsSourceView* _tmp72_;
	GtkTextBuffer* _tmp73_;
	GtkTextBuffer* _tmp74_;
	ScratchWidgetsSourceView* _tmp75_;
	GtkTextBuffer* _tmp76_;
	GtkTextBuffer* _tmp77_;
	gchar* _tmp78_;
	gchar* _tmp79_;
	ScratchWidgetsSourceView* _tmp80_;
	GtkTextBuffer* _tmp81_;
	GtkTextBuffer* _tmp82_;
	gchar* _tmp83_;
	gchar* _tmp84_;
	ScratchWidgetsSourceView* _tmp85_;
	GError* _inner_error0_;
};

struct _ScratchServicesDocumentDoCloseData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchServicesDocument* self;
	gboolean app_closing;
	gboolean result;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	GCancellable* _tmp3_;
	gboolean ret_value;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	GSettings* _tmp8_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	gboolean _tmp12_;
	gboolean _tmp13_;
	gboolean _tmp14_;
	gboolean _tmp15_;
	gboolean _tmp16_;
	gboolean _tmp17_;
	gboolean _tmp18_;
	gboolean _tmp19_;
	gboolean _tmp20_;
	GtkWindow* parent_window;
	ScratchWidgetsSourceView* _tmp21_;
	GtkWidget* _tmp22_;
	GtkWindow* _tmp23_;
	GraniteMessageDialog* dialog;
	gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	GThemedIcon* _tmp28_;
	GThemedIcon* _tmp29_;
	GraniteMessageDialog* _tmp30_;
	GraniteMessageDialog* _tmp31_;
	GraniteMessageDialog* _tmp32_;
	GtkWindow* _tmp33_;
	GtkButton* no_save_button;
	GraniteMessageDialog* _tmp34_;
	GtkWidget* _tmp35_;
	GtkButton* _tmp36_;
	GtkButton* _tmp37_;
	GtkStyleContext* _tmp38_;
	GraniteMessageDialog* _tmp39_;
	GraniteMessageDialog* _tmp40_;
	GraniteMessageDialog* _tmp41_;
	gint response;
	GraniteMessageDialog* _tmp42_;
	gboolean _tmp43_;
	gboolean _tmp44_;
	gboolean _tmp45_;
	gboolean _tmp46_;
	gboolean _tmp47_;
	gboolean _tmp48_;
	gboolean _tmp49_;
	GraniteMessageDialog* _tmp50_;
	guint _tmp51_;
	GQuark _tmp52_;
};

struct _ScratchServicesDocumentSaveWithHoldData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchServicesDocument* self;
	gboolean force;
	gboolean saving_as;
	gboolean result;
	gboolean _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean _result_;
	GApplication* _tmp3_;
	GApplication* _tmp4_;
	GError* _inner_error0_;
};

struct _ScratchServicesDocumentSaveAsWithHoldData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchServicesDocument* self;
	gboolean result;
	gchar* old_uri;
	GFile* _tmp0_;
	GFile* _tmp1_;
	gchar* _tmp2_;
	gboolean old_locked;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gboolean _result_;
	const gchar* _tmp5_;
	GFile* _tmp6_;
	GFile* _tmp7_;
};

struct _Block36Data {
	int _ref_count_;
	ScratchServicesDocument* self;
	gchar* _error_;
	gpointer _async_data_;
};

struct _ScratchServicesDocumentSaveData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchServicesDocument* self;
	gboolean force;
	gboolean saving_as;
	gboolean result;
	gboolean _tmp0_;
	gboolean _tmp1_;
	Block36Data* _data36_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	ScratchWidgetsSourceView* _tmp5_;
	GtkTextBuffer* _tmp6_;
	GtkTextBuffer* _tmp7_;
	ScratchWidgetsSourceView* _tmp8_;
	GtkTextBuffer* _tmp9_;
	GtkTextBuffer* _tmp10_;
	gboolean _tmp11_;
	GSettings* _tmp12_;
	GCancellable* _tmp13_;
	GCancellable* _tmp14_;
	GtkSourceFileSaver* source_file_saver;
	ScratchWidgetsSourceView* _tmp15_;
	GtkTextBuffer* _tmp16_;
	GtkTextBuffer* _tmp17_;
	GtkSourceFile* _tmp18_;
	GtkSourceFileSaver* _tmp19_;
	gboolean success;
	gchar* _tmp20_;
	gboolean _tmp21_;
	GtkSourceFileSaver* _tmp22_;
	GCancellable* _tmp23_;
	ScratchWidgetsSourceView* _tmp24_;
	GtkTextBuffer* _tmp25_;
	GtkTextBuffer* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	GError* e;
	GError* _tmp29_;
	GError* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	const gchar* _tmp35_;
	ScratchWidgetsSourceView* _tmp36_;
	GtkTextBuffer* _tmp37_;
	GtkTextBuffer* _tmp38_;
	ScratchServicesSymbolOutline* _tmp39_;
	ScratchServicesSymbolOutline* _tmp40_;
	GtkRecentManager* _tmp41_;
	gchar* _tmp42_;
	gchar* _tmp43_;
	gchar* _tmp44_;
	gchar* _tmp45_;
	GError* _inner_error0_;
};

struct _ScratchServicesDocumentSaveAsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchServicesDocument* self;
	gboolean result;
	gboolean _tmp0_;
	gboolean _tmp1_;
	GtkFileFilter* all_files_filter;
	GtkFileFilter* _tmp2_;
	GtkFileFilter* _tmp3_;
	GtkFileFilter* _tmp4_;
	GtkFileFilter* text_files_filter;
	GtkFileFilter* _tmp5_;
	GtkFileFilter* _tmp6_;
	GtkFileFilter* _tmp7_;
	GtkFileChooserNative* file_chooser;
	GtkWidget* _tmp8_;
	GtkFileChooserNative* _tmp9_;
	GtkFileChooserNative* _tmp10_;
	GtkFileFilter* _tmp11_;
	GtkFileFilter* _tmp12_;
	GtkFileChooserNative* _tmp13_;
	GtkFileFilter* _tmp14_;
	GtkFileFilter* _tmp15_;
	GtkFileChooserNative* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	GtkFileChooserNative* _tmp20_;
	gboolean success;
	GFile* current_file;
	GFile* _tmp21_;
	GFile* _tmp22_;
	GFile* _tmp23_;
	gboolean is_current_file_temporary;
	gboolean _tmp24_;
	gboolean _tmp25_;
	GtkFileChooserNative* _tmp26_;
	GtkFileChooserNative* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	GFile* _tmp30_;
	GFile* _tmp31_;
	GtkFileChooserNative* _tmp32_;
	GFile* _tmp33_;
	GFile* _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	gboolean is_saved;
	ScratchWidgetsSourceView* _tmp38_;
	GtkTextBuffer* _tmp39_;
	GtkTextBuffer* _tmp40_;
	GFile* _tmp41_;
	GFile* _tmp42_;
	gchar* _tmp43_;
	gchar* _tmp44_;
	GFile* _tmp45_;
	gchar* _tmp46_;
	gchar* _tmp47_;
	gchar* _tmp48_;
	gchar* _tmp49_;
	ScratchWidgetsSourceView* _tmp50_;
	GFile* _tmp51_;
	GFile* _tmp52_;
	GtkFileChooserNative* _tmp53_;
	GError* _inner_error0_;
};

struct _Block37Data {
	int _ref_count_;
	ScratchServicesDocument* self;
	gchar* invalid_content;
};

struct _ScratchServicesDocumentCheckFileStatusData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchServicesDocument* self;
	ScratchWidgetsSourceView* _tmp0_;
	GtkTextBuffer* _tmp1_;
	GtkTextBuffer* _tmp2_;
	gchar* details;
	gchar* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	GSimpleAction* close_tab_action;
	GSimpleActionGroup* _tmp12_;
	GSimpleAction* _tmp13_;
	GSimpleAction* _tmp14_;
	GSimpleAction* _tmp15_;
	GFile* _tmp16_;
	GFile* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	GVariant* _tmp20_;
	GVariant* _tmp21_;
	gboolean _tmp22_;
	gboolean _tmp23_;
	gboolean _tmp24_;
	gboolean _tmp25_;
	gboolean _tmp26_;
	ScratchWidgetsSourceView* _tmp27_;
	GtkTextBuffer* _tmp28_;
	GtkTextBuffer* _tmp29_;
	gchar* _vala1_details;
	gchar* _tmp30_;
	const gchar* _tmp31_;
	gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	gchar* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	GtkSourceBuffer* new_buffer;
	GtkSourceBuffer* _tmp38_;
	GtkSourceFileLoader* source_file_loader;
	GtkSourceBuffer* _tmp39_;
	GtkSourceFile* _tmp40_;
	GtkSourceFileLoader* _tmp41_;
	GtkSourceFileLoader* _tmp42_;
	GError* e;
	GError* _tmp43_;
	const gchar* _tmp44_;
	const gchar* _tmp45_;
	GtkSourceBuffer* _tmp46_;
	gchar* _tmp47_;
	gchar* _tmp48_;
	gchar* _tmp49_;
	gboolean _tmp50_;
	const gchar* _tmp51_;
	ScratchWidgetsSourceView* _tmp52_;
	GtkTextBuffer* _tmp53_;
	GtkTextBuffer* _tmp54_;
	gchar* _tmp55_;
	gchar* _tmp56_;
	gchar* _tmp57_;
	gboolean _tmp58_;
	ScratchWidgetsSourceView* _tmp59_;
	GtkSourceBuffer* _tmp60_;
	gchar* _tmp61_;
	gchar* _tmp62_;
	gchar* _tmp63_;
	GtkSourceBuffer* _tmp64_;
	gchar* _tmp65_;
	gchar* _tmp66_;
	ScratchWidgetsSourceView* _tmp67_;
	GtkTextBuffer* _tmp68_;
	GtkTextBuffer* _tmp69_;
	ScratchServicesSymbolOutline* _tmp70_;
	ScratchServicesSymbolOutline* _tmp71_;
	gchar* primary_text;
	GFile* _tmp72_;
	GFile* _tmp73_;
	gchar* _tmp74_;
	gchar* _tmp75_;
	gchar* _tmp76_;
	gchar* _tmp77_;
	gchar* secondary_text;
	ScratchWidgetsSourceView* _tmp78_;
	GtkTextBuffer* _tmp79_;
	GtkTextBuffer* _tmp80_;
	gchar* _tmp81_;
	gchar* _tmp82_;
	const gchar* _tmp83_;
	const gchar* _tmp84_;
	GtkSourceBuffer* _tmp85_;
	gchar* _tmp86_;
	gchar* _tmp87_;
	gchar* _tmp88_;
	GError* _inner_error0_;
};

struct _Block38Data {
	int _ref_count_;
	ScratchServicesDocument* self;
	GraniteMessageDialog* dialog;
};

struct _Block39Data {
	int _ref_count_;
	Block38Data * _data38_;
	gint id;
};

struct _Block40Data {
	int _ref_count_;
	ScratchServicesDocument* self;
	GraniteMessageDialog* dialog;
	gchar* external_content;
};

struct _Block41Data {
	int _ref_count_;
	Block40Data * _data40_;
	gint id;
};

static gint ScratchServicesDocument_private_offset;
static gpointer scratch_services_document_parent_class = NULL;
static PangoFontDescription* scratch_services_document_builder_blocks_font;
static PangoFontDescription* scratch_services_document_builder_blocks_font = NULL;
static PangoFontMap* scratch_services_document_builder_font_map;
static PangoFontMap* scratch_services_document_builder_font_map = NULL;

static void scratch_services_document_set_file (ScratchServicesDocument* self,
                                         GFile* value);
static void scratch_services_document_set_tab (ScratchServicesDocument* self,
                                        HdyTabPage* value);
static void scratch_services_document_on_tab_loading_change (ScratchServicesDocument* self);
static void _scratch_services_document_on_tab_loading_change_g_object_notify (GObject* _sender,
                                                                       GParamSpec* pspec,
                                                                       gpointer self);
static void ___lambda21_ (ScratchServicesDocument* self);
static Block34Data* block34_data_ref (Block34Data* _data34_);
static void block34_data_unref (void * _userdata_);
static void __lambda22_ (Block34Data* _data34_);
static gboolean ___lambda23_ (Block34Data* _data34_);
static gboolean ____lambda23__gsource_func (gpointer self);
static void ___lambda22__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                           gpointer self);
static void ____lambda21__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                            gpointer self);
static void scratch_services_document_open_data_free (gpointer _data);
static gboolean scratch_services_document_open_co (ScratchServicesDocumentOpenData* _data_);
static Block35Data* block35_data_ref (Block35Data* _data35_);
static void block35_data_unref (void * _userdata_);
static void ___lambda51_ (Block35Data* _data35_);
static void ____lambda51__granite_widgets_alert_view_action_activated (GraniteWidgetsAlertView* _sender,
                                                                gpointer self);
static gboolean __lambda52_ (ScratchServicesDocument* self);
static void ___lambda53_ (ScratchServicesDocument* self);
static void ____lambda53__granite_widgets_alert_view_action_activated (GraniteWidgetsAlertView* _sender,
                                                                gpointer self);
static gboolean ___lambda52__gsource_func (gpointer self);
static void scratch_services_document_open_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void scratch_services_document_show_default_load_error_view (ScratchServicesDocument* self,
                                                             const gchar* invalid_content);
static gboolean __lambda54_ (ScratchServicesDocument* self);
static void scratch_services_document_check_file_status (ScratchServicesDocument* self,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static void scratch_services_document_check_file_status_finish (ScratchServicesDocument* self,
                                                         GAsyncResult* _res_);
static gboolean ___lambda54__gsource_func (gpointer self);
static void scratch_services_document_do_close_data_free (gpointer _data);
static gboolean scratch_services_document_do_close_co (ScratchServicesDocumentDoCloseData* _data_);
static void scratch_services_document_do_close_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static gboolean scratch_services_document_delete_temporary_file (ScratchServicesDocument* self,
                                                          gboolean force);
static void scratch_services_document_set_closing (ScratchServicesDocument* self,
                                            gboolean value);
static void scratch_services_document_delete_backup (ScratchServicesDocument* self,
                                              const gchar* backup_path);
static void scratch_services_document_save_with_hold_data_free (gpointer _data);
static gboolean scratch_services_document_save_with_hold_co (ScratchServicesDocumentSaveWithHoldData* _data_);
static void scratch_services_document_save_with_hold_ready (GObject* source_object,
                                                     GAsyncResult* _res_,
                                                     gpointer _user_data_);
static void scratch_services_document_save_as (ScratchServicesDocument* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
static gboolean scratch_services_document_save_as_finish (ScratchServicesDocument* self,
                                                   GAsyncResult* _res_);
static void scratch_services_document_save (ScratchServicesDocument* self,
                                     gboolean force,
                                     gboolean saving_as,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
static gboolean scratch_services_document_save_finish (ScratchServicesDocument* self,
                                                GAsyncResult* _res_);
static void scratch_services_document_save_as_with_hold_data_free (gpointer _data);
static gboolean scratch_services_document_save_as_with_hold_co (ScratchServicesDocumentSaveAsWithHoldData* _data_);
static void scratch_services_document_save_as_with_hold_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void scratch_services_document_save_data_free (gpointer _data);
static gboolean scratch_services_document_save_co (ScratchServicesDocumentSaveData* _data_);
static Block36Data* block36_data_ref (Block36Data* _data36_);
static void block36_data_unref (void * _userdata_);
static void scratch_services_document_strip_trailing_spaces (ScratchServicesDocument* self);
static void scratch_services_document_save_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void scratch_services_document_create_backup (ScratchServicesDocument* self);
static gboolean ___lambda37_ (Block36Data* _data36_);
static void scratch_services_document_ask_save_location (ScratchServicesDocument* self,
                                                  const gchar* details,
                                                  const gchar* error_text);
static gboolean ____lambda37__gsource_func (gpointer self);
static void scratch_services_document_save_as_data_free (gpointer _data);
static gboolean scratch_services_document_save_as_co (ScratchServicesDocumentSaveAsData* _data_);
static void scratch_services_document_save_as_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void scratch_services_document_set_minimap (ScratchServicesDocument* self);
static void scratch_services_document_set_strip_trailing_whitespace (ScratchServicesDocument* self);
static Block37Data* block37_data_ref (Block37Data* _data37_);
static void block37_data_unref (void * _userdata_);
static void ___lambda27_ (Block37Data* _data37_);
static gboolean __lambda28_ (Block37Data* _data37_);
static gboolean ___lambda28__gsource_func (gpointer self);
static void ____lambda27__granite_widgets_alert_view_action_activated (GraniteWidgetsAlertView* _sender,
                                                                gpointer self);
static void scratch_services_document_check_file_status_data_free (gpointer _data);
static gboolean scratch_services_document_check_file_status_co (ScratchServicesDocumentCheckFileStatusData* _data_);
static void scratch_services_document_check_file_status_ready (GObject* source_object,
                                                        GAsyncResult* _res_,
                                                        gpointer _user_data_);
static void scratch_services_document_ask_external_changes (ScratchServicesDocument* self,
                                                     const gchar* primary_text,
                                                     const gchar* secondary_text,
                                                     const gchar* external_content);
static Block38Data* block38_data_ref (Block38Data* _data38_);
static void block38_data_unref (void * _userdata_);
static void __lambda24_ (Block38Data* _data38_,
                  gint id);
static Block39Data* block39_data_ref (Block39Data* _data39_);
static void block39_data_unref (void * _userdata_);
static gboolean __lambda25_ (Block39Data* _data39_);
static void ___lambda26_ (ScratchServicesDocument* self,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda26__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static gboolean ___lambda25__gsource_func (gpointer self);
static void ___lambda24__gtk_dialog_response (GtkDialog* _sender,
                                       gint response_id,
                                       gpointer self);
static Block40Data* block40_data_ref (Block40Data* _data40_);
static void block40_data_unref (void * _userdata_);
static void __lambda33_ (Block40Data* _data40_,
                  gint id);
static Block41Data* block41_data_ref (Block41Data* _data41_);
static void block41_data_unref (void * _userdata_);
static gboolean __lambda34_ (Block41Data* _data41_);
static void ___lambda35_ (ScratchServicesDocument* self,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda35__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void ___lambda36_ (ScratchServicesDocument* self,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda36__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static gboolean ___lambda34__gsource_func (gpointer self);
static void ___lambda33__gtk_dialog_response (GtkDialog* _sender,
                                       gint response_id,
                                       gpointer self);
static void scratch_services_document_file_changed (ScratchServicesDocument* self);
static void scratch_services_document_unmounted_cb (ScratchServicesDocument* self);
static void _scratch_services_document_unmounted_cb_g_mount_unmounted (GMount* _sender,
                                                                gpointer self);
static gboolean ____lambda50_ (ScratchServicesDocument* self);
static ScratchWidgetsDocumentView* scratch_services_document_get_doc_view (ScratchServicesDocument* self);
static void scratch_services_document_sync_outline_width (ScratchServicesDocument* self);
static void _scratch_services_document_sync_outline_width_g_object_notify (GObject* _sender,
                                                                    GParamSpec* pspec,
                                                                    gpointer self);
static gboolean _____lambda50__gsource_func (gpointer self);
static GObject * scratch_services_document_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void _scratch_services_document_set_minimap_g_settings_changed (GSettings* _sender,
                                                                const gchar* key,
                                                                gpointer self);
static void _scratch_services_document_set_strip_trailing_whitespace_g_settings_changed (GSettings* _sender,
                                                                                  const gchar* key,
                                                                                  gpointer self);
static gboolean _scratch_services_document___lambda131_ (ScratchServicesDocument* self);
static gboolean __scratch_services_document___lambda131__gtk_widget_focus_in_event (GtkWidget* _sender,
                                                                             GdkEventFocus* event,
                                                                             gpointer self);
static gboolean _scratch_services_document___lambda132_ (ScratchServicesDocument* self);
static gboolean __scratch_services_document___lambda132__gtk_widget_focus_out_event (GtkWidget* _sender,
                                                                              GdkEventFocus* event,
                                                                              gpointer self);
static void _scratch_services_document___lambda133_ (ScratchServicesDocument* self);
static void __scratch_services_document___lambda133__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                                                       gpointer self);
static void _scratch_services_document___lambda134_ (ScratchServicesDocument* self);
static void __scratch_services_document___lambda134__gtk_source_completion_show (GtkSourceCompletion* _sender,
                                                                          gpointer self);
static void _scratch_services_document___lambda135_ (ScratchServicesDocument* self);
static void __scratch_services_document___lambda135__gtk_source_completion_hide (GtkSourceCompletion* _sender,
                                                                          gpointer self);
static gboolean _scratch_services_document___lambda136_ (ScratchServicesDocument* self);
static gboolean __scratch_services_document___lambda136__gtk_widget_enter_notify_event (GtkWidget* _sender,
                                                                                 GdkEventCrossing* event,
                                                                                 gpointer self);
static gboolean _scratch_services_document___lambda137_ (ScratchServicesDocument* self);
static gboolean __scratch_services_document___lambda137__gtk_widget_focus_out_event (GtkWidget* _sender,
                                                                              GdkEventFocus* event,
                                                                              gpointer self);
static void _vala_PangoFontDescription_free (PangoFontDescription* self);
static void scratch_services_document_finalize (GObject * obj);
static GType scratch_services_document_get_type_once (void);
static void _vala_scratch_services_document_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_scratch_services_document_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

 G_GNUC_NO_INLINE static GType
scratch_services_document_states_get_type_once (void)
{
	static const GEnumValue values[] = {{SCRATCH_SERVICES_DOCUMENT_STATES_NORMAL, "SCRATCH_SERVICES_DOCUMENT_STATES_NORMAL", "normal"}, {SCRATCH_SERVICES_DOCUMENT_STATES_READONLY, "SCRATCH_SERVICES_DOCUMENT_STATES_READONLY", "readonly"}, {0, NULL, NULL}};
	GType scratch_services_document_states_type_id;
	scratch_services_document_states_type_id = g_enum_register_static ("ScratchServicesDocumentStates", values);
	return scratch_services_document_states_type_id;
}

GType
scratch_services_document_states_get_type (void)
{
	static gsize scratch_services_document_states_type_id__once = 0;
	if (g_once_init_enter (&scratch_services_document_states_type_id__once)) {
		GType scratch_services_document_states_type_id;
		scratch_services_document_states_type_id = scratch_services_document_states_get_type_once ();
		g_once_init_leave (&scratch_services_document_states_type_id__once, scratch_services_document_states_type_id);
	}
	return scratch_services_document_states_type_id__once;
}

static inline gpointer
scratch_services_document_get_instance_private (ScratchServicesDocument* self)
{
	return G_STRUCT_MEMBER_P (self, ScratchServicesDocument_private_offset);
}

ScratchServicesDocument*
scratch_services_document_construct (GType object_type,
                                     GSimpleActionGroup* actions,
                                     GFile* file)
{
	ScratchServicesDocument * self = NULL;
	g_return_val_if_fail (actions != NULL, NULL);
	g_return_val_if_fail (file != NULL, NULL);
	self = (ScratchServicesDocument*) g_object_new (object_type, "actions", actions, NULL);
	scratch_services_document_set_file (self, file);
	return self;
}

ScratchServicesDocument*
scratch_services_document_new (GSimpleActionGroup* actions,
                               GFile* file)
{
	return scratch_services_document_construct (SCRATCH_SERVICES_TYPE_DOCUMENT, actions, file);
}

static void
_scratch_services_document_on_tab_loading_change_g_object_notify (GObject* _sender,
                                                                  GParamSpec* pspec,
                                                                  gpointer self)
{
	scratch_services_document_on_tab_loading_change ((ScratchServicesDocument*) self);
}

void
scratch_services_document_init_tab (ScratchServicesDocument* self,
                                    HdyTabPage* tab)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GIcon* _tmp2_;
	GIcon* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (tab != NULL);
	scratch_services_document_set_tab (self, tab);
	g_signal_connect_object ((GObject*) tab, "notify::loading", (GCallback) _scratch_services_document_on_tab_loading_change_g_object_notify, self, 0);
	_tmp0_ = scratch_services_document_get_title (self);
	_tmp1_ = _tmp0_;
	hdy_tab_page_set_title (tab, _tmp1_);
	_tmp2_ = scratch_services_document_get_icon (self);
	_tmp3_ = _tmp2_;
	hdy_tab_page_set_icon (tab, _tmp3_);
	_tmp4_ = scratch_services_document_get_tab_tooltip (self);
	_tmp5_ = _tmp4_;
	hdy_tab_page_set_tooltip (tab, _tmp5_);
	_g_free0 (_tmp5_);
}

static Block34Data*
block34_data_ref (Block34Data* _data34_)
{
	g_atomic_int_inc (&_data34_->_ref_count_);
	return _data34_;
}

static void
block34_data_unref (void * _userdata_)
{
	Block34Data* _data34_;
	_data34_ = (Block34Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data34_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data34_->self;
		_g_object_unref0 (self);
		g_slice_free (Block34Data, _data34_);
	}
}

static gboolean
___lambda23_ (Block34Data* _data34_)
{
	ScratchServicesDocument* self;
	gboolean result;
	self = _data34_->self;
	scratch_services_document_save_with_hold (self, FALSE, FALSE, NULL, NULL);
	_data34_->timeout_saving = (guint) 0;
	result = FALSE;
	return result;
}

static gboolean
____lambda23__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda23_ (self);
	return result;
}

static void
__lambda22_ (Block34Data* _data34_)
{
	ScratchServicesDocument* self;
	GSettings* _tmp0_;
	ScratchWidgetsSourceView* _tmp1_;
	self = _data34_->self;
	scratch_services_document_check_undoable_actions (self);
	_tmp0_ = scratch_settings;
	if (g_settings_get_boolean (_tmp0_, "autosave")) {
		if (_data34_->timeout_saving > ((guint) 0)) {
			g_source_remove (_data34_->timeout_saving);
			_data34_->timeout_saving = (guint) 0;
		}
		_data34_->timeout_saving = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 1000, ____lambda23__gsource_func, block34_data_ref (_data34_), block34_data_unref);
	}
	_tmp1_ = self->priv->_source_view;
	scratch_widgets_source_view_schedule_refresh (_tmp1_);
}

static void
___lambda22__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                      gpointer self)
{
	__lambda22_ (self);
}

static void
___lambda21_ (ScratchServicesDocument* self)
{
	Block34Data* _data34_;
	ScratchWidgetsSourceView* _tmp3_;
	GtkTextBuffer* _tmp4_;
	GtkTextBuffer* _tmp5_;
	gulong _tmp6_;
	_data34_ = g_slice_new0 (Block34Data);
	_data34_->_ref_count_ = 1;
	_data34_->self = g_object_ref (self);
	if (self->priv->onchange_handler_id != ((gulong) 0)) {
		ScratchWidgetsSourceView* _tmp0_;
		GtkTextBuffer* _tmp1_;
		GtkTextBuffer* _tmp2_;
		_tmp0_ = self->priv->_source_view;
		_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp0_);
		_tmp2_ = _tmp1_;
		g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->onchange_handler_id);
	}
	_data34_->timeout_saving = (guint) 0;
	scratch_services_document_check_undoable_actions (self);
	_tmp3_ = self->priv->_source_view;
	_tmp4_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_signal_connect_data (_tmp5_, "changed", (GCallback) ___lambda22__gtk_text_buffer_changed, block34_data_ref (_data34_), (GClosureNotify) block34_data_unref, 0);
	self->priv->onchange_handler_id = _tmp6_;
	block34_data_unref (_data34_);
	_data34_ = NULL;
}

static void
____lambda21__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                       gpointer self)
{
	___lambda21_ ((ScratchServicesDocument*) self);
}

void
scratch_services_document_toggle_changed_handlers (ScratchServicesDocument* self,
                                                   gboolean enabled)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (enabled) {
		_tmp0_ = self->priv->onchange_handler_id == ((gulong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ScratchWidgetsSourceView* _tmp1_;
		GtkTextBuffer* _tmp2_;
		GtkTextBuffer* _tmp3_;
		gulong _tmp4_;
		_tmp1_ = self->priv->_source_view;
		_tmp2_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_signal_connect_object (_tmp3_, "changed", (GCallback) ____lambda21__gtk_text_buffer_changed, self, 0);
		self->priv->onchange_handler_id = _tmp4_;
	} else {
		gboolean _tmp5_ = FALSE;
		if (!enabled) {
			_tmp5_ = self->priv->onchange_handler_id != ((gulong) 0);
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			ScratchWidgetsSourceView* _tmp6_;
			GtkTextBuffer* _tmp7_;
			GtkTextBuffer* _tmp8_;
			_tmp6_ = self->priv->_source_view;
			_tmp7_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp6_);
			_tmp8_ = _tmp7_;
			g_signal_handler_disconnect ((GObject*) _tmp8_, self->priv->onchange_handler_id);
			self->priv->onchange_handler_id = (gulong) 0;
		}
	}
}

static void
scratch_services_document_open_data_free (gpointer _data)
{
	ScratchServicesDocumentOpenData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchServicesDocumentOpenData, _data_);
}

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

void
scratch_services_document_open (ScratchServicesDocument* self,
                                gboolean force,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	ScratchServicesDocumentOpenData* _data_;
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchServicesDocumentOpenData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_services_document_open_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->force = force;
	scratch_services_document_open_co (_data_);
}

void
scratch_services_document_open_finish (ScratchServicesDocument* self,
                                       GAsyncResult* _res_)
{
	ScratchServicesDocumentOpenData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static Block35Data*
block35_data_ref (Block35Data* _data35_)
{
	g_atomic_int_inc (&_data35_->_ref_count_);
	return _data35_;
}

static void
block35_data_unref (void * _userdata_)
{
	Block35Data* _data35_;
	_data35_ = (Block35Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data35_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data35_->self;
		_g_object_unref0 (_data35_->alert_view);
		_g_object_unref0 (self);
		g_slice_free (Block35Data, _data35_);
	}
}

static void
___lambda51_ (Block35Data* _data35_)
{
	ScratchServicesDocument* self;
	GraniteWidgetsAlertView* _tmp0_;
	self = _data35_->self;
	scratch_services_document_open (self, TRUE, NULL, NULL);
	_tmp0_ = _data35_->alert_view;
	gtk_widget_destroy ((GtkWidget*) _tmp0_);
}

static void
____lambda51__granite_widgets_alert_view_action_activated (GraniteWidgetsAlertView* _sender,
                                                           gpointer self)
{
	___lambda51_ (self);
}

static void
___lambda53_ (ScratchServicesDocument* self)
{
	GCancellable* _tmp0_;
	_tmp0_ = self->priv->load_cancellable;
	g_cancellable_cancel (_tmp0_);
	g_signal_emit (self, scratch_services_document_signals[SCRATCH_SERVICES_DOCUMENT_DOC_CLOSED_SIGNAL], 0);
}

static void
____lambda53__granite_widgets_alert_view_action_activated (GraniteWidgetsAlertView* _sender,
                                                           gpointer self)
{
	___lambda53_ ((ScratchServicesDocument*) self);
}

static gboolean
__lambda52_ (ScratchServicesDocument* self)
{
	gboolean _tmp0_ = FALSE;
	GCancellable* _tmp1_;
	gboolean result;
	_tmp1_ = self->priv->load_cancellable;
	if (_tmp1_ != NULL) {
		GCancellable* _tmp2_;
		_tmp2_ = self->priv->load_cancellable;
		_tmp0_ = !g_cancellable_is_cancelled (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* title = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* description = NULL;
		gchar* _tmp7_;
		GraniteWidgetsAlertView* alert_view = NULL;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		GraniteWidgetsAlertView* _tmp10_;
		GraniteWidgetsAlertView* _tmp11_;
		GraniteWidgetsAlertView* _tmp12_;
		GtkStack* _tmp13_;
		GraniteWidgetsAlertView* _tmp14_;
		GtkStack* _tmp15_;
		GraniteWidgetsAlertView* _tmp16_;
		GraniteWidgetsAlertView* _tmp17_;
		_tmp3_ = scratch_services_document_get_basename (self);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_strdup_printf (_ ("Loading File “%s” Is Taking a Long Time"), _tmp4_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		title = _tmp6_;
		_tmp7_ = g_strdup (_ ("Please wait while Code is loading the file."));
		description = _tmp7_;
		_tmp8_ = title;
		_tmp9_ = description;
		_tmp10_ = granite_widgets_alert_view_new (_tmp8_, _tmp9_, "dialog-information");
		g_object_ref_sink (_tmp10_);
		alert_view = _tmp10_;
		_tmp11_ = alert_view;
		granite_widgets_alert_view_show_action (_tmp11_, _ ("Cancel Loading"));
		_tmp12_ = alert_view;
		gtk_widget_show_all ((GtkWidget*) _tmp12_);
		_tmp13_ = self->main_stack;
		_tmp14_ = alert_view;
		gtk_stack_add_named (_tmp13_, (GtkWidget*) _tmp14_, "wait_alert");
		_tmp15_ = self->main_stack;
		_tmp16_ = alert_view;
		gtk_stack_set_visible_child (_tmp15_, (GtkWidget*) _tmp16_);
		_tmp17_ = alert_view;
		g_signal_connect_object (_tmp17_, "action-activated", (GCallback) ____lambda53__granite_widgets_alert_view_action_activated, self, 0);
		self->priv->load_timout_id = (guint) 0;
		result = G_SOURCE_REMOVE;
		_g_object_unref0 (alert_view);
		_g_free0 (description);
		_g_free0 (title);
		return result;
	}
	self->priv->load_timout_id = (guint) 0;
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda52__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda52_ ((ScratchServicesDocument*) self);
	return result;
}

static void
scratch_services_document_open_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	ScratchServicesDocumentOpenData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_services_document_open_co (_data_);
}

static gboolean
__lambda54_ (ScratchServicesDocument* self)
{
	gboolean result;
	scratch_services_document_set_loading (self, FALSE);
	self->priv->loaded = TRUE;
	scratch_services_document_set_locked (self, FALSE);
	scratch_services_document_check_file_status (self, NULL, NULL);
	result = FALSE;
	return result;
}

static gboolean
___lambda54__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda54_ ((ScratchServicesDocument*) self);
	return result;
}

static gboolean
scratch_services_document_open_co (ScratchServicesDocumentOpenData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	scratch_services_document_set_locked (_data_->self, TRUE);
	_data_->self->priv->loaded = FALSE;
	_data_->_tmp0_ = _data_->self->priv->load_cancellable;
	if (_data_->_tmp0_ != NULL) {
		_data_->_tmp1_ = _data_->self->priv->load_cancellable;
		g_cancellable_cancel (_data_->_tmp1_);
	}
	_data_->_tmp2_ = g_cancellable_new ();
	_g_object_unref0 (_data_->self->priv->load_cancellable);
	_data_->self->priv->load_cancellable = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->self->priv->load_cancellable;
	if (!scratch_services_document_exists (_data_->self, _data_->_tmp3_)) {
		{
			_data_->_tmp4_ = scratch_services_document_get_file (_data_->self);
			_data_->_tmp5_ = _data_->_tmp4_;
			_data_->_tmp6_ = g_file_get_path (_data_->_tmp5_);
			_data_->_tmp7_ = _data_->_tmp6_;
			g_file_set_contents (_data_->_tmp7_, "", (gssize) -1, &_data_->_inner_error0_);
			_g_free0 (_data_->_tmp7_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				if (_data_->_inner_error0_->domain == G_FILE_ERROR) {
					goto __catch0_g_file_error;
				}
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
		}
		goto __finally0;
		__catch0_g_file_error:
		{
			_data_->e = _data_->_inner_error0_;
			_data_->_inner_error0_ = NULL;
			_data_->_tmp8_ = scratch_services_document_get_basename (_data_->self);
			_data_->_tmp9_ = _data_->_tmp8_;
			_data_->_tmp10_ = _data_->e;
			_data_->_tmp11_ = _data_->_tmp10_->message;
			g_warning ("Document.vala:383: Cannot create file “%s”: %s", _data_->_tmp9_, _data_->_tmp11_);
			_g_free0 (_data_->_tmp9_);
			_g_error_free0 (_data_->e);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		__finally0:
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp12_ = _data_->self->priv->_source_view;
	gtk_widget_set_sensitive ((GtkWidget*) _data_->_tmp12_, FALSE);
	scratch_services_document_set_loading (_data_->self, TRUE);
	_data_->_tmp13_ = scratch_services_document_get_mime_type (_data_->self);
	_data_->_tmp14_ = _data_->_tmp13_;
	_data_->_tmp15_ = g_content_type_from_mime_type (_data_->_tmp14_);
	_data_->content_type = _data_->_tmp15_;
	if (_data_->force) {
		_data_->_tmp17_ = TRUE;
	} else {
		_data_->_tmp18_ = _data_->content_type;
		_data_->_tmp17_ = g_content_type_is_a (_data_->_tmp18_, "text/plain");
	}
	if (_data_->_tmp17_) {
		_data_->_tmp16_ = TRUE;
	} else {
		_data_->_tmp19_ = _data_->content_type;
		_data_->_tmp16_ = g_content_type_is_a (_data_->_tmp19_, "application/x-zerosize");
	}
	if (!_data_->_tmp16_) {
		_data_->_data35_ = g_slice_new0 (Block35Data);
		_data_->_data35_->_ref_count_ = 1;
		_data_->_data35_->self = g_object_ref (_data_->self);
		_data_->_tmp20_ = scratch_services_document_get_basename (_data_->self);
		_data_->_tmp21_ = _data_->_tmp20_;
		_data_->_tmp22_ = g_strdup_printf (_ ("%s Is Not a Text File"), _data_->_tmp21_);
		_data_->_tmp23_ = _data_->_tmp22_;
		_g_free0 (_data_->_tmp21_);
		_data_->title = _data_->_tmp23_;
		_data_->_tmp24_ = g_strdup (_ ("Code will not load this type of file."));
		_data_->description = _data_->_tmp24_;
		_data_->_tmp25_ = _data_->title;
		_data_->_tmp26_ = _data_->description;
		_data_->_tmp27_ = granite_widgets_alert_view_new (_data_->_tmp25_, _data_->_tmp26_, "dialog-warning");
		g_object_ref_sink (_data_->_tmp27_);
		_data_->_data35_->alert_view = _data_->_tmp27_;
		_data_->_tmp28_ = _data_->_data35_->alert_view;
		granite_widgets_alert_view_show_action (_data_->_tmp28_, _ ("Load Anyway"));
		_data_->_tmp29_ = _data_->_data35_->alert_view;
		gtk_widget_show_all ((GtkWidget*) _data_->_tmp29_);
		_data_->_tmp30_ = _data_->self->main_stack;
		_data_->_tmp31_ = _data_->_data35_->alert_view;
		gtk_stack_add_named (_data_->_tmp30_, (GtkWidget*) _data_->_tmp31_, "load_alert");
		_data_->_tmp32_ = _data_->self->main_stack;
		_data_->_tmp33_ = _data_->_data35_->alert_view;
		gtk_stack_set_visible_child (_data_->_tmp32_, (GtkWidget*) _data_->_tmp33_);
		_data_->_tmp34_ = _data_->_data35_->alert_view;
		g_signal_connect_data (_data_->_tmp34_, "action-activated", (GCallback) ____lambda51__granite_widgets_alert_view_action_activated, block35_data_ref (_data_->_data35_), (GClosureNotify) block35_data_unref, 0);
		scratch_services_document_set_loading (_data_->self, FALSE);
		_g_free0 (_data_->description);
		_g_free0 (_data_->title);
		block35_data_unref (_data_->_data35_);
		_data_->_data35_ = NULL;
		_g_free0 (_data_->content_type);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	while (TRUE) {
		if (!gtk_events_pending ()) {
			break;
		}
		gtk_main_iteration ();
	}
	_data_->_tmp35_ = gtk_source_buffer_new (NULL);
	_data_->buffer = _data_->_tmp35_;
	_data_->self->priv->load_timout_id = g_timeout_add_seconds_full (G_PRIORITY_HIGH, (guint) 5, ___lambda52__gsource_func, g_object_ref (_data_->self), g_object_unref);
	{
		_data_->_tmp36_ = _data_->buffer;
		_data_->_tmp37_ = _data_->self->priv->source_file;
		_data_->_tmp38_ = gtk_source_file_loader_new (_data_->_tmp36_, _data_->_tmp37_);
		_data_->source_file_loader = _data_->_tmp38_;
		_data_->_tmp39_ = _data_->source_file_loader;
		_data_->_tmp40_ = _data_->self->priv->load_cancellable;
		_data_->_state_ = 1;
		gtk_source_file_loader_load_async (_data_->_tmp39_, G_PRIORITY_LOW, _data_->_tmp40_, NULL, NULL, NULL, scratch_services_document_open_ready, _data_);
		return FALSE;
		_state_1:
		gtk_source_file_loader_load_finish (_data_->_tmp39_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->source_file_loader);
			goto __catch1_g_error;
		}
		_data_->_tmp41_ = _data_->self->priv->_source_view;
		_data_->_tmp42_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp41_);
		_data_->_tmp43_ = _data_->_tmp42_;
		_data_->_tmp44_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp43_, gtk_source_buffer_get_type ()) ? ((GtkSourceBuffer*) _data_->_tmp43_) : NULL);
		_data_->source_buffer = _data_->_tmp44_;
		_data_->_tmp45_ = _data_->source_buffer;
		if (_data_->_tmp45_ != NULL) {
			_data_->_tmp46_ = _data_->source_buffer;
			gtk_source_buffer_begin_not_undoable_action (_data_->_tmp46_);
			_data_->_tmp47_ = _data_->source_buffer;
			_data_->_tmp48_ = _data_->buffer;
			g_object_get ((GtkTextBuffer*) _data_->_tmp48_, "text", &_data_->_tmp49_, NULL);
			_data_->_tmp50_ = _data_->_tmp49_;
			_data_->_tmp51_ = _data_->_tmp50_;
			g_object_set ((GtkTextBuffer*) _data_->_tmp47_, "text", _data_->_tmp51_, NULL);
			_g_free0 (_data_->_tmp51_);
			_data_->_tmp52_ = _data_->source_buffer;
			gtk_source_buffer_end_not_undoable_action (_data_->_tmp52_);
		} else {
			_data_->_tmp53_ = _data_->self->priv->_source_view;
			_data_->_tmp54_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp53_);
			_data_->_tmp55_ = _data_->_tmp54_;
			_data_->_tmp56_ = _data_->buffer;
			g_object_get ((GtkTextBuffer*) _data_->_tmp56_, "text", &_data_->_tmp57_, NULL);
			_data_->_tmp58_ = _data_->_tmp57_;
			_data_->_tmp59_ = _data_->_tmp58_;
			g_object_set (_data_->_tmp55_, "text", _data_->_tmp59_, NULL);
			_g_free0 (_data_->_tmp59_);
		}
		_g_object_unref0 (_data_->source_buffer);
		_g_object_unref0 (_data_->source_file_loader);
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp60_ = _data_->_vala1_e;
		_data_->_tmp61_ = _data_->_tmp60_->message;
		g_critical ("Document.vala:453: %s", _data_->_tmp61_);
		_data_->_tmp62_ = _data_->self->priv->_source_view;
		_data_->_tmp63_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp62_);
		_data_->_tmp64_ = _data_->_tmp63_;
		g_object_set (_data_->_tmp64_, "text", "", NULL);
		scratch_services_document_set_loading (_data_->self, FALSE);
		_data_->_tmp65_ = _data_->buffer;
		g_object_get ((GtkTextBuffer*) _data_->_tmp65_, "text", &_data_->_tmp66_, NULL);
		_data_->_tmp67_ = _data_->_tmp66_;
		_data_->_tmp68_ = _data_->_tmp67_;
		scratch_services_document_show_default_load_error_view (_data_->self, _data_->_tmp68_);
		_g_free0 (_data_->_tmp68_);
		_g_error_free0 (_data_->_vala1_e);
		{
			_g_object_unref0 (_data_->self->priv->load_cancellable);
			_data_->self->priv->load_cancellable = NULL;
			if (_data_->self->priv->load_timout_id > ((guint) 0)) {
				g_source_remove (_data_->self->priv->load_timout_id);
			}
		}
		_g_object_unref0 (_data_->buffer);
		_g_free0 (_data_->content_type);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally1:
	{
		_g_object_unref0 (_data_->self->priv->load_cancellable);
		_data_->self->priv->load_cancellable = NULL;
		if (_data_->self->priv->load_timout_id > ((guint) 0)) {
			g_source_remove (_data_->self->priv->load_timout_id);
		}
	}
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->buffer);
		_g_free0 (_data_->content_type);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp69_ = _data_->self->priv->_source_view;
	_data_->_tmp70_ = scratch_services_document_get_file (_data_->self);
	_data_->_tmp71_ = _data_->_tmp70_;
	scratch_widgets_source_view_change_syntax_highlight_from_file (_data_->_tmp69_, _data_->_tmp71_);
	_data_->_tmp72_ = _data_->self->priv->_source_view;
	_data_->_tmp73_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp72_);
	_data_->_tmp74_ = _data_->_tmp73_;
	gtk_text_buffer_set_modified (_data_->_tmp74_, FALSE);
	_data_->_tmp75_ = _data_->self->priv->_source_view;
	_data_->_tmp76_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp75_);
	_data_->_tmp77_ = _data_->_tmp76_;
	g_object_get (_data_->_tmp77_, "text", &_data_->_tmp78_, NULL);
	_data_->_tmp79_ = _data_->_tmp78_;
	_g_free0 (_data_->self->original_content);
	_data_->self->original_content = _data_->_tmp79_;
	_data_->_tmp80_ = _data_->self->priv->_source_view;
	_data_->_tmp81_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp80_);
	_data_->_tmp82_ = _data_->_tmp81_;
	g_object_get (_data_->_tmp82_, "text", &_data_->_tmp83_, NULL);
	_data_->_tmp84_ = _data_->_tmp83_;
	_g_free0 (_data_->self->priv->last_save_content);
	_data_->self->priv->last_save_content = _data_->_tmp84_;
	scratch_services_document_set_saved_status (_data_->self, TRUE);
	g_signal_emit (_data_->self, scratch_services_document_signals[SCRATCH_SERVICES_DOCUMENT_DOC_OPENED_SIGNAL], 0);
	_data_->_tmp85_ = _data_->self->priv->_source_view;
	gtk_widget_set_sensitive ((GtkWidget*) _data_->_tmp85_, TRUE);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda54__gsource_func, g_object_ref (_data_->self), g_object_unref);
	_g_object_unref0 (_data_->buffer);
	_g_free0 (_data_->content_type);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
scratch_services_document_do_close_data_free (gpointer _data)
{
	ScratchServicesDocumentDoCloseData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchServicesDocumentDoCloseData, _data_);
}

void
scratch_services_document_do_close (ScratchServicesDocument* self,
                                    gboolean app_closing,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	ScratchServicesDocumentDoCloseData* _data_;
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchServicesDocumentDoCloseData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_services_document_do_close_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->app_closing = app_closing;
	scratch_services_document_do_close_co (_data_);
}

gboolean
scratch_services_document_do_close_finish (ScratchServicesDocument* self,
                                           GAsyncResult* _res_)
{
	gboolean result;
	ScratchServicesDocumentDoCloseData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
scratch_services_document_do_close_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	ScratchServicesDocumentDoCloseData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_services_document_do_close_co (_data_);
}

static gboolean
scratch_services_document_do_close_co (ScratchServicesDocumentDoCloseData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = scratch_services_document_get_basename (_data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	g_debug ("Document.vala:490: Closing \"%s\"", _data_->_tmp1_);
	_g_free0 (_data_->_tmp1_);
	_data_->_tmp2_ = _data_->self->priv->_closing;
	if (_data_->_tmp2_) {
		_data_->result = TRUE;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (!_data_->self->priv->loaded) {
		_data_->_tmp3_ = _data_->self->priv->load_cancellable;
		g_cancellable_cancel (_data_->_tmp3_);
		_data_->result = TRUE;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->ret_value = TRUE;
	_data_->_tmp6_ = scratch_services_document_get_locked (_data_->self);
	_data_->_tmp7_ = _data_->_tmp6_;
	if (!_data_->_tmp7_) {
		_data_->_tmp8_ = scratch_settings;
		_data_->_tmp5_ = g_settings_get_boolean (_data_->_tmp8_, "autosave");
	} else {
		_data_->_tmp5_ = FALSE;
	}
	if (_data_->_tmp5_) {
		_data_->_tmp4_ = !_data_->self->saved;
	} else {
		_data_->_tmp4_ = FALSE;
	}
	if (_data_->_tmp4_) {
		_data_->_state_ = 1;
		scratch_services_document_save_with_hold (_data_->self, FALSE, FALSE, scratch_services_document_do_close_ready, _data_);
		return FALSE;
		_state_1:
		_data_->ret_value = scratch_services_document_save_with_hold_finish (_data_->self, _data_->_res_);
	} else {
		_data_->_tmp12_ = scratch_services_document_get_locked (_data_->self);
		_data_->_tmp13_ = _data_->_tmp12_;
		if (!_data_->_tmp13_) {
			_data_->_tmp11_ = _data_->app_closing;
		} else {
			_data_->_tmp11_ = FALSE;
		}
		if (_data_->_tmp11_) {
			_data_->_tmp14_ = scratch_services_document_get_is_file_temporary (_data_->self);
			_data_->_tmp15_ = _data_->_tmp14_;
			_data_->_tmp10_ = _data_->_tmp15_;
		} else {
			_data_->_tmp10_ = FALSE;
		}
		if (_data_->_tmp10_) {
			_data_->_tmp9_ = !scratch_services_document_delete_temporary_file (_data_->self, FALSE);
		} else {
			_data_->_tmp9_ = FALSE;
		}
		if (_data_->_tmp9_) {
			g_debug ("Document.vala:505: Save temporary file!");
			_data_->_state_ = 2;
			scratch_services_document_save_with_hold (_data_->self, FALSE, FALSE, scratch_services_document_do_close_ready, _data_);
			return FALSE;
			_state_2:
			_data_->ret_value = scratch_services_document_save_with_hold_finish (_data_->self, _data_->_res_);
		} else {
			if (!_data_->self->saved) {
				_data_->_tmp16_ = TRUE;
			} else {
				if (!_data_->app_closing) {
					_data_->_tmp19_ = scratch_services_document_get_is_file_temporary (_data_->self);
					_data_->_tmp20_ = _data_->_tmp19_;
					_data_->_tmp18_ = _data_->_tmp20_;
				} else {
					_data_->_tmp18_ = FALSE;
				}
				if (_data_->_tmp18_) {
					_data_->_tmp17_ = !scratch_services_document_delete_temporary_file (_data_->self, FALSE);
				} else {
					_data_->_tmp17_ = FALSE;
				}
				_data_->_tmp16_ = _data_->_tmp17_;
			}
			if (_data_->_tmp16_) {
				_data_->_tmp21_ = _data_->self->priv->_source_view;
				_data_->_tmp22_ = gtk_widget_get_toplevel ((GtkWidget*) _data_->_tmp21_);
				_data_->_tmp23_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp22_, gtk_window_get_type ()) ? ((GtkWindow*) _data_->_tmp22_) : NULL);
				_data_->parent_window = _data_->_tmp23_;
				_data_->_tmp24_ = scratch_services_document_get_basename (_data_->self);
				_data_->_tmp25_ = _data_->_tmp24_;
				_data_->_tmp26_ = g_strdup_printf (_ ("Save changes to “%s” before closing?"), _data_->_tmp25_);
				_data_->_tmp27_ = _data_->_tmp26_;
				_data_->_tmp28_ = (GThemedIcon*) g_themed_icon_new ("dialog-warning");
				_data_->_tmp29_ = _data_->_tmp28_;
				_data_->_tmp30_ = granite_message_dialog_new (_data_->_tmp27_, _ ("If you don't save, changes will be permanently lost."), (GIcon*) _data_->_tmp29_, GTK_BUTTONS_NONE);
				g_object_ref_sink (_data_->_tmp30_);
				_data_->_tmp31_ = _data_->_tmp30_;
				_g_object_unref0 (_data_->_tmp29_);
				_g_free0 (_data_->_tmp27_);
				_g_free0 (_data_->_tmp25_);
				_data_->dialog = _data_->_tmp31_;
				_data_->_tmp32_ = _data_->dialog;
				_data_->_tmp33_ = _data_->parent_window;
				gtk_window_set_transient_for ((GtkWindow*) _data_->_tmp32_, _data_->_tmp33_);
				_data_->_tmp34_ = _data_->dialog;
				_data_->_tmp35_ = gtk_dialog_add_button ((GtkDialog*) _data_->_tmp34_, _ ("Close Without Saving"), (gint) GTK_RESPONSE_NO);
				_data_->_tmp36_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp35_, gtk_button_get_type (), GtkButton));
				_data_->no_save_button = _data_->_tmp36_;
				_data_->_tmp37_ = _data_->no_save_button;
				_data_->_tmp38_ = gtk_widget_get_style_context ((GtkWidget*) _data_->_tmp37_);
				gtk_style_context_add_class (_data_->_tmp38_, GTK_STYLE_CLASS_DESTRUCTIVE_ACTION);
				_data_->_tmp39_ = _data_->dialog;
				gtk_dialog_add_button ((GtkDialog*) _data_->_tmp39_, _ ("Cancel"), (gint) GTK_RESPONSE_CANCEL);
				_data_->_tmp40_ = _data_->dialog;
				gtk_dialog_add_button ((GtkDialog*) _data_->_tmp40_, _ ("Save"), (gint) GTK_RESPONSE_YES);
				_data_->_tmp41_ = _data_->dialog;
				gtk_dialog_set_default_response ((GtkDialog*) _data_->_tmp41_, (gint) GTK_RESPONSE_YES);
				_data_->_tmp42_ = _data_->dialog;
				_data_->response = gtk_dialog_run ((GtkDialog*) _data_->_tmp42_);
				switch (_data_->response) {
					case GTK_RESPONSE_CANCEL:
					case GTK_RESPONSE_DELETE_EVENT:
					{
						_data_->ret_value = FALSE;
						break;
					}
					case GTK_RESPONSE_YES:
					{
						_data_->_tmp44_ = scratch_services_document_get_locked (_data_->self);
						_data_->_tmp45_ = _data_->_tmp44_;
						if (_data_->_tmp45_) {
							_data_->_tmp43_ = TRUE;
						} else {
							_data_->_tmp46_ = scratch_services_document_get_is_file_temporary (_data_->self);
							_data_->_tmp47_ = _data_->_tmp46_;
							_data_->_tmp43_ = _data_->_tmp47_;
						}
						if (_data_->_tmp43_) {
							_data_->_state_ = 3;
							scratch_services_document_save_as_with_hold (_data_->self, scratch_services_document_do_close_ready, _data_);
							return FALSE;
							_state_3:
							_data_->ret_value = scratch_services_document_save_as_with_hold_finish (_data_->self, _data_->_res_);
						} else {
							_data_->_state_ = 4;
							scratch_services_document_save_with_hold (_data_->self, FALSE, FALSE, scratch_services_document_do_close_ready, _data_);
							return FALSE;
							_state_4:
							_data_->ret_value = scratch_services_document_save_with_hold_finish (_data_->self, _data_->_res_);
						}
						break;
					}
					case GTK_RESPONSE_NO:
					{
						_data_->ret_value = TRUE;
						_data_->_tmp48_ = scratch_services_document_get_is_file_temporary (_data_->self);
						_data_->_tmp49_ = _data_->_tmp48_;
						if (_data_->_tmp49_) {
							scratch_services_document_delete_temporary_file (_data_->self, TRUE);
						}
						break;
					}
					default:
					break;
				}
				_data_->_tmp50_ = _data_->dialog;
				gtk_widget_destroy ((GtkWidget*) _data_->_tmp50_);
				_g_object_unref0 (_data_->no_save_button);
				_g_object_unref0 (_data_->dialog);
				_g_object_unref0 (_data_->parent_window);
			}
		}
	}
	if (_data_->ret_value) {
		scratch_services_document_set_closing (_data_->self, TRUE);
		scratch_services_document_delete_backup (_data_->self, NULL);
		g_signal_parse_name ("notify::tab.loading", G_TYPE_OBJECT, &_data_->_tmp51_, &_data_->_tmp52_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _data_->self, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _data_->_tmp51_, _data_->_tmp52_, NULL, (GCallback) _scratch_services_document_on_tab_loading_change_g_object_notify, _data_->self);
		g_signal_emit (_data_->self, scratch_services_document_signals[SCRATCH_SERVICES_DOCUMENT_DOC_CLOSED_SIGNAL], 0);
	}
	_data_->result = _data_->ret_value;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
scratch_services_document_save_request (ScratchServicesDocument* self)
{
	g_return_if_fail (self != NULL);
	scratch_services_document_check_undoable_actions (self);
	scratch_services_document_save_with_hold (self, TRUE, FALSE, NULL, NULL);
}

static void
scratch_services_document_save_with_hold_data_free (gpointer _data)
{
	ScratchServicesDocumentSaveWithHoldData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchServicesDocumentSaveWithHoldData, _data_);
}

void
scratch_services_document_save_with_hold (ScratchServicesDocument* self,
                                          gboolean force,
                                          gboolean saving_as,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_)
{
	ScratchServicesDocumentSaveWithHoldData* _data_;
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchServicesDocumentSaveWithHoldData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_services_document_save_with_hold_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->force = force;
	_data_->saving_as = saving_as;
	scratch_services_document_save_with_hold_co (_data_);
}

gboolean
scratch_services_document_save_with_hold_finish (ScratchServicesDocument* self,
                                                 GAsyncResult* _res_)
{
	gboolean result;
	ScratchServicesDocumentSaveWithHoldData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
scratch_services_document_save_with_hold_ready (GObject* source_object,
                                                GAsyncResult* _res_,
                                                gpointer _user_data_)
{
	ScratchServicesDocumentSaveWithHoldData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_services_document_save_with_hold_co (_data_);
}

static gboolean
scratch_services_document_save_with_hold_co (ScratchServicesDocumentSaveWithHoldData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->is_saving) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp1_ = scratch_services_document_get_locked (_data_->self);
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp0_ = _data_->_tmp2_;
	}
	if (_data_->_tmp0_) {
		_data_->result = TRUE;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	} else {
		_data_->self->priv->is_saving = TRUE;
	}
	_data_->_state_ = 1;
	scratch_services_document_check_file_status (_data_->self, scratch_services_document_save_with_hold_ready, _data_);
	return FALSE;
	_state_1:
	scratch_services_document_check_file_status_finish (_data_->self, _data_->_res_);
	{
		g_rec_mutex_lock (&_data_->self->priv->__lock_is_saving);
		{
			_data_->_tmp3_ = g_application_get_default ();
			g_application_hold (_data_->_tmp3_);
			if (_data_->saving_as) {
				_data_->_state_ = 2;
				scratch_services_document_save_as (_data_->self, scratch_services_document_save_with_hold_ready, _data_);
				return FALSE;
				_state_2:
				_data_->_result_ = scratch_services_document_save_as_finish (_data_->self, _data_->_res_);
			} else {
				_data_->_state_ = 3;
				scratch_services_document_save (_data_->self, _data_->force, FALSE, scratch_services_document_save_with_hold_ready, _data_);
				return FALSE;
				_state_3:
				_data_->_result_ = scratch_services_document_save_finish (_data_->self, _data_->_res_);
			}
			_data_->_tmp4_ = g_application_get_default ();
			g_application_release (_data_->_tmp4_);
			_data_->self->priv->is_saving = FALSE;
		}
		__finally0:
		{
			g_rec_mutex_unlock (&_data_->self->priv->__lock_is_saving);
		}
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->result = _data_->_result_;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
scratch_services_document_save_as_with_hold_data_free (gpointer _data)
{
	ScratchServicesDocumentSaveAsWithHoldData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchServicesDocumentSaveAsWithHoldData, _data_);
}

void
scratch_services_document_save_as_with_hold (ScratchServicesDocument* self,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	ScratchServicesDocumentSaveAsWithHoldData* _data_;
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchServicesDocumentSaveAsWithHoldData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_services_document_save_as_with_hold_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	scratch_services_document_save_as_with_hold_co (_data_);
}

gboolean
scratch_services_document_save_as_with_hold_finish (ScratchServicesDocument* self,
                                                    GAsyncResult* _res_)
{
	gboolean result;
	ScratchServicesDocumentSaveAsWithHoldData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
scratch_services_document_save_as_with_hold_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	ScratchServicesDocumentSaveAsWithHoldData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_services_document_save_as_with_hold_co (_data_);
}

static gboolean
scratch_services_document_save_as_with_hold_co (ScratchServicesDocumentSaveAsWithHoldData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = scratch_services_document_get_file (_data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = g_file_get_uri (_data_->_tmp1_);
	_data_->old_uri = _data_->_tmp2_;
	_data_->_tmp3_ = scratch_services_document_get_locked (_data_->self);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->old_locked = _data_->_tmp4_;
	scratch_services_document_set_locked (_data_->self, FALSE);
	scratch_services_document_set_loading (_data_->self, TRUE);
	_data_->_state_ = 1;
	scratch_services_document_save_with_hold (_data_->self, TRUE, TRUE, scratch_services_document_save_as_with_hold_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_result_ = scratch_services_document_save_with_hold_finish (_data_->self, _data_->_res_);
	if (!_data_->_result_) {
		_data_->_tmp5_ = _data_->old_uri;
		_data_->_tmp6_ = g_file_new_for_uri (_data_->_tmp5_);
		_data_->_tmp7_ = _data_->_tmp6_;
		scratch_services_document_set_file (_data_->self, _data_->_tmp7_);
		_g_object_unref0 (_data_->_tmp7_);
		scratch_services_document_set_locked (_data_->self, _data_->old_locked);
	}
	scratch_services_document_set_loading (_data_->self, FALSE);
	_data_->_state_ = 2;
	scratch_services_document_check_file_status (_data_->self, scratch_services_document_save_as_with_hold_ready, _data_);
	return FALSE;
	_state_2:
	scratch_services_document_check_file_status_finish (_data_->self, _data_->_res_);
	_data_->result = _data_->_result_;
	_g_free0 (_data_->old_uri);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
scratch_services_document_save_data_free (gpointer _data)
{
	ScratchServicesDocumentSaveData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchServicesDocumentSaveData, _data_);
}

static void
scratch_services_document_save (ScratchServicesDocument* self,
                                gboolean force,
                                gboolean saving_as,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	ScratchServicesDocumentSaveData* _data_;
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchServicesDocumentSaveData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_services_document_save_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->force = force;
	_data_->saving_as = saving_as;
	scratch_services_document_save_co (_data_);
}

static gboolean
scratch_services_document_save_finish (ScratchServicesDocument* self,
                                       GAsyncResult* _res_)
{
	gboolean result;
	ScratchServicesDocumentSaveData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static Block36Data*
block36_data_ref (Block36Data* _data36_)
{
	g_atomic_int_inc (&_data36_->_ref_count_);
	return _data36_;
}

static void
block36_data_unref (void * _userdata_)
{
	Block36Data* _data36_;
	_data36_ = (Block36Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data36_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data36_->self;
		_g_free0 (_data36_->_error_);
		_g_object_unref0 (self);
		g_slice_free (Block36Data, _data36_);
	}
}

static void
scratch_services_document_save_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	ScratchServicesDocumentSaveData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_services_document_save_co (_data_);
}

static gboolean
___lambda37_ (Block36Data* _data36_)
{
	ScratchServicesDocument* self;
	GFile* _tmp0_;
	GFile* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	gboolean result;
	self = _data36_->self;
	_tmp0_ = scratch_services_document_get_file (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_file_get_path (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup_printf (_ ("Saving to “%s” failed."), _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _data36_->_error_;
	scratch_services_document_ask_save_location (self, _tmp5_, _tmp6_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
____lambda37__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda37_ (self);
	return result;
}

static gboolean
scratch_services_document_save_co (ScratchServicesDocumentSaveData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = scratch_services_document_get_locked (_data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_vala_return_val_if_fail ((!_data_->_tmp1_) && _data_->self->priv->is_saving, "!locked && is_saving", FALSE);
	_data_->_data36_ = g_slice_new0 (Block36Data);
	_data_->_data36_->_ref_count_ = 1;
	_data_->_data36_->self = g_object_ref (_data_->self);
	_data_->_data36_->_async_data_ = _data_;
	if (_data_->self->priv->completion_shown) {
		_data_->_tmp2_ = TRUE;
	} else {
		if (!_data_->force) {
			_data_->_tmp5_ = _data_->self->priv->_source_view;
			_data_->_tmp6_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp5_);
			_data_->_tmp7_ = _data_->_tmp6_;
			if (gtk_text_buffer_get_modified (_data_->_tmp7_) == FALSE) {
				_data_->_tmp4_ = TRUE;
			} else {
				_data_->_tmp4_ = !_data_->self->priv->loaded;
			}
			_data_->_tmp3_ = _data_->_tmp4_;
		} else {
			_data_->_tmp3_ = FALSE;
		}
		_data_->_tmp2_ = _data_->_tmp3_;
	}
	if (_data_->_tmp2_) {
		_data_->_tmp8_ = _data_->self->priv->_source_view;
		_data_->_tmp9_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->result = gtk_text_buffer_get_modified (_data_->_tmp10_) == FALSE;
		block36_data_unref (_data_->_data36_);
		_data_->_data36_ = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp12_ = scratch_settings;
	if (g_settings_get_boolean (_data_->_tmp12_, "strip-trailing-on-save")) {
		_data_->_tmp11_ = _data_->force;
	} else {
		_data_->_tmp11_ = FALSE;
	}
	if (_data_->_tmp11_) {
		scratch_services_document_strip_trailing_spaces (_data_->self);
	}
	_data_->_tmp13_ = _data_->self->priv->save_cancellable;
	g_cancellable_cancel (_data_->_tmp13_);
	_data_->_tmp14_ = g_cancellable_new ();
	_g_object_unref0 (_data_->self->priv->save_cancellable);
	_data_->self->priv->save_cancellable = _data_->_tmp14_;
	_data_->_tmp15_ = _data_->self->priv->_source_view;
	_data_->_tmp16_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp15_);
	_data_->_tmp17_ = _data_->_tmp16_;
	_data_->_tmp18_ = _data_->self->priv->source_file;
	_data_->_tmp19_ = gtk_source_file_saver_new (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp17_, gtk_source_buffer_get_type (), GtkSourceBuffer), _data_->_tmp18_);
	_data_->source_file_saver = _data_->_tmp19_;
	_data_->success = FALSE;
	_data_->_tmp20_ = g_strdup ("");
	_data_->_data36_->_error_ = _data_->_tmp20_;
	{
		_data_->_tmp22_ = _data_->source_file_saver;
		_data_->_tmp23_ = _data_->self->priv->save_cancellable;
		_data_->_state_ = 1;
		gtk_source_file_saver_save_async (_data_->_tmp22_, G_PRIORITY_DEFAULT, _data_->_tmp23_, NULL, NULL, NULL, scratch_services_document_save_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp21_ = gtk_source_file_saver_save_finish (_data_->_tmp22_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->success = _data_->_tmp21_;
		if (_data_->success) {
			scratch_services_document_set_saved_status (_data_->self, TRUE);
			_data_->_tmp24_ = _data_->self->priv->_source_view;
			_data_->_tmp25_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp24_);
			_data_->_tmp26_ = _data_->_tmp25_;
			g_object_get (_data_->_tmp26_, "text", &_data_->_tmp27_, NULL);
			_data_->_tmp28_ = _data_->_tmp27_;
			_g_free0 (_data_->self->priv->last_save_content);
			_data_->self->priv->last_save_content = _data_->_tmp28_;
			scratch_services_document_create_backup (_data_->self);
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp29_ = _data_->e;
		if (_data_->_tmp29_->code != 19) {
			_data_->_tmp30_ = _data_->e;
			_data_->_tmp31_ = _data_->_tmp30_->message;
			_data_->_tmp32_ = g_strdup (_data_->_tmp31_);
			_g_free0 (_data_->_data36_->_error_);
			_data_->_data36_->_error_ = _data_->_tmp32_;
		} else {
			_data_->result = FALSE;
			_g_error_free0 (_data_->e);
			_g_object_unref0 (_data_->source_file_saver);
			block36_data_unref (_data_->_data36_);
			_data_->_data36_ = NULL;
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->source_file_saver);
		block36_data_unref (_data_->_data36_);
		_data_->_data36_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	if (!_data_->success) {
		_data_->_tmp33_ = scratch_services_document_get_uri (_data_->self);
		_data_->_tmp34_ = _data_->_tmp33_;
		_data_->_tmp35_ = _data_->_data36_->_error_;
		g_warning ("Document.vala:646: Cannot save “%s”: %s", _data_->_tmp34_, _data_->_tmp35_);
		_g_free0 (_data_->_tmp34_);
		scratch_services_document_set_locked (_data_->self, TRUE);
		g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ____lambda37__gsource_func, block36_data_ref (_data_->_data36_), block36_data_unref);
		_data_->result = FALSE;
		_g_object_unref0 (_data_->source_file_saver);
		block36_data_unref (_data_->_data36_);
		_data_->_data36_ = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp36_ = _data_->self->priv->_source_view;
	_data_->_tmp37_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp36_);
	_data_->_tmp38_ = _data_->_tmp37_;
	gtk_text_buffer_set_modified (_data_->_tmp38_, FALSE);
	_data_->_tmp39_ = _data_->self->priv->outline;
	if (_data_->_tmp39_ != NULL) {
		_data_->_tmp40_ = _data_->self->priv->outline;
		scratch_services_symbol_outline_parse_symbols (_data_->_tmp40_);
	}
	_data_->_tmp41_ = gtk_recent_manager_get_default ();
	_data_->_tmp42_ = scratch_services_document_get_uri (_data_->self);
	_data_->_tmp43_ = _data_->_tmp42_;
	gtk_recent_manager_add_item (_data_->_tmp41_, _data_->_tmp43_);
	_g_free0 (_data_->_tmp43_);
	_data_->_tmp44_ = scratch_services_document_get_basename (_data_->self);
	_data_->_tmp45_ = _data_->_tmp44_;
	g_debug ("Document.vala:669: File “%s” saved successfully", _data_->_tmp45_);
	_g_free0 (_data_->_tmp45_);
	_data_->result = TRUE;
	_g_object_unref0 (_data_->source_file_saver);
	block36_data_unref (_data_->_data36_);
	_data_->_data36_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
scratch_services_document_save_as_data_free (gpointer _data)
{
	ScratchServicesDocumentSaveAsData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchServicesDocumentSaveAsData, _data_);
}

static void
scratch_services_document_save_as (ScratchServicesDocument* self,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	ScratchServicesDocumentSaveAsData* _data_;
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchServicesDocumentSaveAsData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_services_document_save_as_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	scratch_services_document_save_as_co (_data_);
}

static gboolean
scratch_services_document_save_as_finish (ScratchServicesDocument* self,
                                          GAsyncResult* _res_)
{
	gboolean result;
	ScratchServicesDocumentSaveAsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
scratch_services_document_save_as_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	ScratchServicesDocumentSaveAsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_services_document_save_as_co (_data_);
}

static gboolean
scratch_services_document_save_as_co (ScratchServicesDocumentSaveAsData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = scratch_services_document_get_locked (_data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_vala_return_val_if_fail ((!_data_->_tmp1_) && _data_->self->priv->is_saving, "!locked && is_saving", FALSE);
	if (!_data_->self->priv->loaded) {
		_data_->result = FALSE;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp2_ = gtk_file_filter_new ();
	g_object_ref_sink (_data_->_tmp2_);
	_data_->all_files_filter = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->all_files_filter;
	gtk_file_filter_set_name (_data_->_tmp3_, _ ("All files"));
	_data_->_tmp4_ = _data_->all_files_filter;
	gtk_file_filter_add_pattern (_data_->_tmp4_, "*");
	_data_->_tmp5_ = gtk_file_filter_new ();
	g_object_ref_sink (_data_->_tmp5_);
	_data_->text_files_filter = _data_->_tmp5_;
	_data_->_tmp6_ = _data_->text_files_filter;
	gtk_file_filter_set_name (_data_->_tmp6_, _ ("Text files"));
	_data_->_tmp7_ = _data_->text_files_filter;
	gtk_file_filter_add_mime_type (_data_->_tmp7_, "text/*");
	_data_->_tmp8_ = gtk_widget_get_toplevel ((GtkWidget*) _data_->self);
	_data_->_tmp9_ = gtk_file_chooser_native_new (_ ("Save File"), G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, gtk_window_get_type (), GtkWindow), GTK_FILE_CHOOSER_ACTION_SAVE, _ ("Save"), _ ("Cancel"));
	_data_->file_chooser = _data_->_tmp9_;
	_data_->_tmp10_ = _data_->file_chooser;
	_data_->_tmp11_ = _data_->all_files_filter;
	_data_->_tmp12_ = _g_object_ref0 (_data_->_tmp11_);
	gtk_file_chooser_add_filter ((GtkFileChooser*) _data_->_tmp10_, _data_->_tmp12_);
	_data_->_tmp13_ = _data_->file_chooser;
	_data_->_tmp14_ = _data_->text_files_filter;
	_data_->_tmp15_ = _g_object_ref0 (_data_->_tmp14_);
	gtk_file_chooser_add_filter ((GtkFileChooser*) _data_->_tmp13_, _data_->_tmp15_);
	_data_->_tmp16_ = _data_->file_chooser;
	gtk_file_chooser_set_do_overwrite_confirmation ((GtkFileChooser*) _data_->_tmp16_, TRUE);
	_data_->_tmp18_ = scratch_utils_last_path;
	_data_->_tmp17_ = _data_->_tmp18_;
	if (_data_->_tmp17_ == NULL) {
		_data_->_tmp19_ = g_get_home_dir ();
		_data_->_tmp17_ = _data_->_tmp19_;
	}
	_data_->_tmp20_ = _data_->file_chooser;
	gtk_file_chooser_set_current_folder_uri ((GtkFileChooser*) _data_->_tmp20_, _data_->_tmp17_);
	_data_->success = FALSE;
	_data_->_tmp21_ = scratch_services_document_get_file (_data_->self);
	_data_->_tmp22_ = _data_->_tmp21_;
	_data_->_tmp23_ = g_file_dup (_data_->_tmp22_);
	_data_->current_file = _data_->_tmp23_;
	_data_->_tmp24_ = scratch_services_document_get_is_file_temporary (_data_->self);
	_data_->_tmp25_ = _data_->_tmp24_;
	_data_->is_current_file_temporary = _data_->_tmp25_;
	_data_->_tmp26_ = _data_->file_chooser;
	if (gtk_native_dialog_run ((GtkNativeDialog*) _data_->_tmp26_) == ((gint) GTK_RESPONSE_ACCEPT)) {
		_data_->_tmp27_ = _data_->file_chooser;
		_data_->_tmp28_ = gtk_file_chooser_get_uri ((GtkFileChooser*) _data_->_tmp27_);
		_data_->_tmp29_ = _data_->_tmp28_;
		_data_->_tmp30_ = g_file_new_for_uri (_data_->_tmp29_);
		_data_->_tmp31_ = _data_->_tmp30_;
		scratch_services_document_set_file (_data_->self, _data_->_tmp31_);
		_g_object_unref0 (_data_->_tmp31_);
		_g_free0 (_data_->_tmp29_);
		_data_->_tmp32_ = _data_->file_chooser;
		_data_->_tmp33_ = gtk_file_chooser_get_file ((GtkFileChooser*) _data_->_tmp32_);
		_data_->_tmp34_ = _data_->_tmp33_;
		_data_->_tmp35_ = g_file_get_uri (_data_->_tmp34_);
		_data_->_tmp36_ = _data_->_tmp35_;
		_data_->_tmp37_ = g_path_get_dirname (_data_->_tmp36_);
		_g_free0 (scratch_utils_last_path);
		scratch_utils_last_path = _data_->_tmp37_;
		_g_free0 (_data_->_tmp36_);
		_g_object_unref0 (_data_->_tmp34_);
		_data_->success = TRUE;
	}
	_data_->is_saved = FALSE;
	if (_data_->success) {
		_data_->_state_ = 1;
		scratch_services_document_save (_data_->self, TRUE, TRUE, scratch_services_document_save_as_ready, _data_);
		return FALSE;
		_state_1:
		_data_->is_saved = scratch_services_document_save_finish (_data_->self, _data_->_res_);
		if (_data_->is_saved) {
			_data_->_tmp38_ = _data_->self->priv->_source_view;
			_data_->_tmp39_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp38_);
			_data_->_tmp40_ = _data_->_tmp39_;
			gtk_text_buffer_set_modified (_data_->_tmp40_, FALSE);
			if (_data_->is_current_file_temporary) {
				{
					_data_->_tmp41_ = _data_->current_file;
					g_file_delete (_data_->_tmp41_, NULL, &_data_->_inner_error0_);
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						goto __catch0_g_error;
					}
				}
				goto __finally0;
				__catch0_g_error:
				{
					g_clear_error (&_data_->_inner_error0_);
					_data_->_tmp42_ = _data_->current_file;
					_data_->_tmp43_ = g_file_get_uri (_data_->_tmp42_);
					_data_->_tmp44_ = _data_->_tmp43_;
					g_warning ("Document.vala:722: Temporary file cannot be deleted: %s", _data_->_tmp44_);
					_g_free0 (_data_->_tmp44_);
				}
				__finally0:
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_object_unref0 (_data_->current_file);
					_g_object_unref0 (_data_->file_chooser);
					_g_object_unref0 (_data_->text_files_filter);
					_g_object_unref0 (_data_->all_files_filter);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
					g_clear_error (&_data_->_inner_error0_);
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
			}
			_data_->_tmp45_ = _data_->current_file;
			_data_->_tmp46_ = g_file_get_uri (_data_->_tmp45_);
			_data_->_tmp47_ = _data_->_tmp46_;
			_data_->_tmp48_ = g_strconcat (_data_->_tmp47_, "~", NULL);
			_data_->_tmp49_ = _data_->_tmp48_;
			scratch_services_document_delete_backup (_data_->self, _data_->_tmp49_);
			_g_free0 (_data_->_tmp49_);
			_g_free0 (_data_->_tmp47_);
			_data_->_tmp50_ = _data_->self->priv->_source_view;
			_data_->_tmp51_ = scratch_services_document_get_file (_data_->self);
			_data_->_tmp52_ = _data_->_tmp51_;
			scratch_widgets_source_view_change_syntax_highlight_from_file (_data_->_tmp50_, _data_->_tmp52_);
		}
	}
	_data_->_tmp53_ = _data_->file_chooser;
	gtk_native_dialog_destroy ((GtkNativeDialog*) _data_->_tmp53_);
	_data_->result = _data_->is_saved;
	_g_object_unref0 (_data_->current_file);
	_g_object_unref0 (_data_->file_chooser);
	_g_object_unref0 (_data_->text_files_filter);
	_g_object_unref0 (_data_->all_files_filter);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

gboolean
scratch_services_document_move (ScratchServicesDocument* self,
                                GFile* new_dest)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (new_dest != NULL, FALSE);
	scratch_services_document_set_file (self, new_dest);
	scratch_services_document_save (self, FALSE, FALSE, NULL, NULL);
	result = TRUE;
	return result;
}

static void
scratch_services_document_set_minimap (ScratchServicesDocument* self)
{
	GSettings* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_settings;
	if (g_settings_get_boolean (_tmp0_, "show-mini-map")) {
		GtkSourceMap* _tmp1_;
		GtkScrolledWindow* _tmp2_;
		_tmp1_ = self->priv->source_map;
		gtk_widget_show ((GtkWidget*) _tmp1_);
		_tmp2_ = self->priv->scroll;
		g_object_set (_tmp2_, "vscrollbar-policy", GTK_POLICY_EXTERNAL, NULL);
	} else {
		GtkSourceMap* _tmp3_;
		GtkSourceMap* _tmp4_;
		GtkScrolledWindow* _tmp5_;
		_tmp3_ = self->priv->source_map;
		gtk_widget_hide ((GtkWidget*) _tmp3_);
		_tmp4_ = self->priv->source_map;
		gtk_widget_set_no_show_all ((GtkWidget*) _tmp4_, TRUE);
		_tmp5_ = self->priv->scroll;
		g_object_set (_tmp5_, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL);
	}
}

static void
scratch_services_document_set_strip_trailing_whitespace (ScratchServicesDocument* self)
{
	GSettings* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_settings;
	if (g_settings_get_boolean (_tmp0_, "strip-trailing-on-save")) {
		scratch_services_document_strip_trailing_spaces (self);
	}
}

void
scratch_services_document_focus (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	gtk_widget_grab_focus ((GtkWidget*) _tmp0_);
}

gchar*
scratch_services_document_get_uri (ScratchServicesDocument* self)
{
	GFile* _tmp0_;
	GFile* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = scratch_services_document_get_file (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_file_get_uri (_tmp1_);
	result = _tmp2_;
	return result;
}

gchar*
scratch_services_document_get_basename (ScratchServicesDocument* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = scratch_services_document_get_is_file_temporary (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (_ ("New Document"));
		result = _tmp2_;
		return result;
	} else {
		GFile* _tmp3_;
		GFile* _tmp4_;
		gchar* _tmp5_;
		_tmp3_ = scratch_services_document_get_file (self);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_file_get_basename (_tmp4_);
		result = _tmp5_;
		return result;
	}
}

gchar*
scratch_services_document_get_directory (ScratchServicesDocument* self)
{
	GFile* _tmp0_;
	GFile* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = scratch_services_document_get_file (self);
	_tmp1_ = _tmp0_;
	if (g_file_has_parent (_tmp1_, NULL)) {
		GFile* _tmp2_;
		GFile* _tmp3_;
		GFile* _tmp4_;
		GFile* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp2_ = scratch_services_document_get_file (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_file_get_parent (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_file_get_uri (_tmp5_);
		_tmp7_ = _tmp6_;
		_g_object_unref0 (_tmp5_);
		result = _tmp7_;
		return result;
	} else {
		gchar* _tmp8_;
		_tmp8_ = g_strdup ("");
		result = _tmp8_;
		return result;
	}
}

gchar*
scratch_services_document_get_tab_tooltip (ScratchServicesDocument* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = scratch_services_document_get_is_file_temporary (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (_ ("New Document"));
		result = _tmp2_;
		return result;
	} else {
		gboolean _tmp3_ = FALSE;
		GFile* _tmp4_;
		GFile* _tmp5_;
		_tmp4_ = scratch_services_document_get_file (self);
		_tmp5_ = _tmp4_;
		if (_tmp5_ != NULL) {
			gboolean _tmp6_;
			gboolean _tmp7_;
			_tmp6_ = scratch_services_document_get_locked (self);
			_tmp7_ = _tmp6_;
			_tmp3_ = _tmp7_;
		} else {
			_tmp3_ = FALSE;
		}
		if (_tmp3_) {
			GFile* _tmp8_;
			GFile* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			_tmp8_ = scratch_services_document_get_file (self);
			_tmp9_ = _tmp8_;
			_tmp10_ = g_file_get_path (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = scratch_utils_replace_home_with_tilde (_tmp11_);
			_tmp13_ = _tmp12_;
			_tmp14_ = g_strdup_printf (_ ("Cannot save this document to %s"), _tmp13_);
			_tmp15_ = _tmp14_;
			_g_free0 (_tmp13_);
			_g_free0 (_tmp11_);
			result = _tmp15_;
			return result;
		} else {
			GFile* _tmp16_;
			GFile* _tmp17_;
			_tmp16_ = scratch_services_document_get_file (self);
			_tmp17_ = _tmp16_;
			if (_tmp17_ != NULL) {
				GFile* _tmp18_;
				GFile* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				gchar* _tmp23_;
				_tmp18_ = scratch_services_document_get_file (self);
				_tmp19_ = _tmp18_;
				_tmp20_ = g_file_get_path (_tmp19_);
				_tmp21_ = _tmp20_;
				_tmp22_ = scratch_utils_replace_home_with_tilde (_tmp21_);
				_tmp23_ = _tmp22_;
				_g_free0 (_tmp21_);
				result = _tmp23_;
				return result;
			} else {
				gchar* _tmp24_;
				_tmp24_ = g_strdup ("");
				result = _tmp24_;
				return result;
			}
		}
	}
}

void
scratch_services_document_undo (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	g_signal_emit_by_name ((GtkSourceView*) _tmp0_, "undo");
	scratch_services_document_check_undoable_actions (self);
}

void
scratch_services_document_redo (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	g_signal_emit_by_name ((GtkSourceView*) _tmp0_, "redo");
	scratch_services_document_check_undoable_actions (self);
}

void
scratch_services_document_revert (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	const gchar* _tmp1_;
	ScratchServicesSymbolOutline* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = self->original_content;
	scratch_widgets_source_view_set_text (_tmp0_, _tmp1_, FALSE);
	scratch_services_document_check_undoable_actions (self);
	_tmp2_ = self->priv->outline;
	if (_tmp2_ != NULL) {
		ScratchServicesSymbolOutline* _tmp3_;
		_tmp3_ = self->priv->outline;
		scratch_services_symbol_outline_parse_symbols (_tmp3_);
	}
}

gchar*
scratch_services_document_get_text (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	GtkTextBuffer* _tmp1_;
	GtkTextBuffer* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp0_);
	_tmp2_ = _tmp1_;
	g_object_get (_tmp2_, "text", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	result = _tmp4_;
	return result;
}

gchar*
scratch_services_document_get_selected_text (ScratchServicesDocument* self,
                                             gboolean replace_newline)
{
	ScratchWidgetsSourceView* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = scratch_widgets_source_view_get_selected_text (_tmp0_, replace_newline);
	result = _tmp1_;
	return result;
}

gchar*
scratch_services_document_get_slice (ScratchServicesDocument* self,
                                     gint start_line,
                                     gint start_col,
                                     gint end_line,
                                     gint end_col)
{
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	{
		ScratchWidgetsSourceView* _tmp0_;
		_tmp0_ = self->priv->_source_view;
		g_rec_mutex_lock (&self->priv->__lock_source_view);
		{
			GtkTextIter iter = {0};
			ScratchWidgetsSourceView* _tmp1_;
			GtkTextBuffer* _tmp2_;
			GtkTextBuffer* _tmp3_;
			GtkTextIter _tmp4_ = {0};
			gboolean _tmp5_ = FALSE;
			GtkTextIter start = {0};
			GtkTextIter _tmp8_;
			ScratchWidgetsSourceView* _tmp9_;
			GtkTextBuffer* _tmp10_;
			GtkTextBuffer* _tmp11_;
			GtkTextIter _tmp12_ = {0};
			GtkTextIter end = {0};
			GtkTextIter _tmp15_;
			ScratchWidgetsSourceView* _tmp16_;
			GtkTextBuffer* _tmp17_;
			GtkTextBuffer* _tmp18_;
			GtkTextIter _tmp19_;
			GtkTextIter _tmp20_;
			gchar* _tmp21_;
			_tmp1_ = self->priv->_source_view;
			_tmp2_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp1_);
			_tmp3_ = _tmp2_;
			gtk_text_buffer_get_iter_at_line (_tmp3_, &_tmp4_, start_line - 1);
			iter = _tmp4_;
			if (start_col > 1) {
				_tmp5_ = !gtk_text_iter_forward_chars (&iter, start_col - 1);
			} else {
				_tmp5_ = FALSE;
			}
			if (_tmp5_) {
				gchar* _tmp6_;
				_tmp6_ = g_strdup ("");
				result = _tmp6_;
				{
					ScratchWidgetsSourceView* _tmp7_;
					_tmp7_ = self->priv->_source_view;
					g_rec_mutex_unlock (&self->priv->__lock_source_view);
				}
				return result;
			}
			_tmp8_ = iter;
			start = _tmp8_;
			_tmp9_ = self->priv->_source_view;
			_tmp10_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp9_);
			_tmp11_ = _tmp10_;
			gtk_text_buffer_get_iter_at_line (_tmp11_, &_tmp12_, end_line - 1);
			iter = _tmp12_;
			if (!gtk_text_iter_forward_to_line_end (&iter)) {
				gchar* _tmp13_;
				_tmp13_ = g_strdup ("");
				result = _tmp13_;
				{
					ScratchWidgetsSourceView* _tmp14_;
					_tmp14_ = self->priv->_source_view;
					g_rec_mutex_unlock (&self->priv->__lock_source_view);
				}
				return result;
			}
			_tmp15_ = iter;
			end = _tmp15_;
			_tmp16_ = self->priv->_source_view;
			_tmp17_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = start;
			_tmp20_ = end;
			_tmp21_ = gtk_text_buffer_get_text (_tmp18_, &_tmp19_, &_tmp20_, FALSE);
			result = _tmp21_;
			{
				ScratchWidgetsSourceView* _tmp22_;
				_tmp22_ = self->priv->_source_view;
				g_rec_mutex_unlock (&self->priv->__lock_source_view);
			}
			return result;
		}
		__finally0:
		{
			ScratchWidgetsSourceView* _tmp23_;
			_tmp23_ = self->priv->_source_view;
			g_rec_mutex_unlock (&self->priv->__lock_source_view);
		}
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
}

gchar*
scratch_services_document_get_language_name (ScratchServicesDocument* self)
{
	GtkSourceBuffer* source_buffer = NULL;
	ScratchWidgetsSourceView* _tmp0_;
	GtkTextBuffer* _tmp1_;
	GtkTextBuffer* _tmp2_;
	GtkSourceBuffer* _tmp3_;
	GtkSourceLanguage* lang = NULL;
	GtkSourceBuffer* _tmp4_;
	GtkSourceLanguage* _tmp5_;
	GtkSourceLanguage* _tmp6_;
	GtkSourceLanguage* _tmp7_;
	GtkSourceLanguage* _tmp8_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_source_buffer_get_type (), GtkSourceBuffer));
	source_buffer = _tmp3_;
	_tmp4_ = source_buffer;
	_tmp5_ = gtk_source_buffer_get_language (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	lang = _tmp7_;
	_tmp8_ = lang;
	if (_tmp8_ != NULL) {
		GtkSourceLanguage* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp9_ = lang;
		_tmp10_ = gtk_source_language_get_name (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = g_strdup (_tmp11_);
		result = _tmp12_;
		_g_object_unref0 (lang);
		_g_object_unref0 (source_buffer);
		return result;
	} else {
		gchar* _tmp13_;
		_tmp13_ = g_strdup ("");
		result = _tmp13_;
		_g_object_unref0 (lang);
		_g_object_unref0 (source_buffer);
		return result;
	}
}

gchar*
scratch_services_document_get_language_id (ScratchServicesDocument* self)
{
	GtkSourceBuffer* source_buffer = NULL;
	ScratchWidgetsSourceView* _tmp0_;
	GtkTextBuffer* _tmp1_;
	GtkTextBuffer* _tmp2_;
	GtkSourceBuffer* _tmp3_;
	GtkSourceLanguage* lang = NULL;
	GtkSourceBuffer* _tmp4_;
	GtkSourceLanguage* _tmp5_;
	GtkSourceLanguage* _tmp6_;
	GtkSourceLanguage* _tmp7_;
	GtkSourceLanguage* _tmp8_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_source_buffer_get_type (), GtkSourceBuffer));
	source_buffer = _tmp3_;
	_tmp4_ = source_buffer;
	_tmp5_ = gtk_source_buffer_get_language (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	lang = _tmp7_;
	_tmp8_ = lang;
	if (_tmp8_ != NULL) {
		GtkSourceLanguage* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		_tmp9_ = lang;
		_tmp10_ = gtk_source_language_get_id (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = g_strdup (_tmp11_);
		result = _tmp12_;
		_g_object_unref0 (lang);
		_g_object_unref0 (source_buffer);
		return result;
	} else {
		gchar* _tmp13_;
		_tmp13_ = g_strdup ("");
		result = _tmp13_;
		_g_object_unref0 (lang);
		_g_object_unref0 (source_buffer);
		return result;
	}
}

void
scratch_services_document_duplicate_selection (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	scratch_widgets_source_view_duplicate_selection (_tmp0_);
}

static Block37Data*
block37_data_ref (Block37Data* _data37_)
{
	g_atomic_int_inc (&_data37_->_ref_count_);
	return _data37_;
}

static void
block37_data_unref (void * _userdata_)
{
	Block37Data* _data37_;
	_data37_ = (Block37Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data37_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data37_->self;
		_g_free0 (_data37_->invalid_content);
		_g_object_unref0 (self);
		g_slice_free (Block37Data, _data37_);
	}
}

static gboolean
__lambda28_ (Block37Data* _data37_)
{
	ScratchServicesDocument* self;
	GtkClipboard* clipboard = NULL;
	GdkDisplay* _tmp0_;
	GtkClipboard* _tmp1_;
	GtkClipboard* _tmp2_;
	GSimpleAction* clipboard_action = NULL;
	GSimpleActionGroup* _tmp3_;
	GSimpleAction* _tmp4_;
	GSimpleAction* close_tab_action = NULL;
	GSimpleActionGroup* _tmp5_;
	GSimpleAction* _tmp6_;
	GFile* _tmp7_;
	GFile* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	GVariant* _tmp11_;
	GVariant* _tmp12_;
	gboolean result;
	self = _data37_->self;
	_tmp0_ = gtk_widget_get_display ((GtkWidget*) self);
	_tmp1_ = gtk_clipboard_get_for_display (_tmp0_, GDK_SELECTION_CLIPBOARD);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	clipboard = _tmp2_;
	gtk_clipboard_set_text (clipboard, _data37_->invalid_content, -1);
	_tmp3_ = self->priv->_actions;
	_tmp4_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_NEW_FROM_CLIPBOARD, _tmp3_);
	clipboard_action = _tmp4_;
	g_simple_action_set_enabled (clipboard_action, TRUE);
	g_signal_emit_by_name (clipboard_action, "activate", NULL);
	_tmp5_ = self->priv->_actions;
	_tmp6_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_CLOSE_TAB, _tmp5_);
	close_tab_action = _tmp6_;
	g_simple_action_set_enabled (close_tab_action, TRUE);
	_tmp7_ = scratch_services_document_get_file (self);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_file_get_path (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_variant_new ("s", _tmp10_, NULL);
	g_variant_ref_sink (_tmp11_);
	_tmp12_ = _tmp11_;
	g_signal_emit_by_name (close_tab_action, "activate", _tmp12_);
	_g_variant_unref0 (_tmp12_);
	_g_free0 (_tmp10_);
	result = FALSE;
	_g_object_unref0 (close_tab_action);
	_g_object_unref0 (clipboard_action);
	_g_object_unref0 (clipboard);
	return result;
}

static gboolean
___lambda28__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda28_ (self);
	return result;
}

static void
___lambda27_ (Block37Data* _data37_)
{
	ScratchServicesDocument* self;
	GtkStack* _tmp0_;
	self = _data37_->self;
	_tmp0_ = self->main_stack;
	gtk_stack_set_visible_child_name (_tmp0_, "content");
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda28__gsource_func, block37_data_ref (_data37_), block37_data_unref);
}

static void
____lambda27__granite_widgets_alert_view_action_activated (GraniteWidgetsAlertView* _sender,
                                                           gpointer self)
{
	___lambda27_ (self);
}

static void
scratch_services_document_show_default_load_error_view (ScratchServicesDocument* self,
                                                        const gchar* invalid_content)
{
	Block37Data* _data37_;
	gchar* _tmp0_;
	gchar* title = NULL;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* description = NULL;
	GraniteWidgetsAlertView* alert_view = NULL;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	GraniteWidgetsAlertView* _tmp9_;
	GraniteWidgetsAlertView* _tmp12_;
	GtkStack* _tmp13_;
	GraniteWidgetsAlertView* _tmp14_;
	GtkStack* _tmp15_;
	GraniteWidgetsAlertView* _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (invalid_content != NULL);
	_data37_ = g_slice_new0 (Block37Data);
	_data37_->_ref_count_ = 1;
	_data37_->self = g_object_ref (self);
	_tmp0_ = g_strdup (invalid_content);
	_g_free0 (_data37_->invalid_content);
	_data37_->invalid_content = _tmp0_;
	_tmp1_ = scratch_services_document_get_basename (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf (_ ("Cannot read text in file “%s”"), _tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	title = _tmp4_;
	if (g_strcmp0 (_data37_->invalid_content, "") == 0) {
		gchar* _tmp5_;
		_tmp5_ = g_strdup (_ ("You may not have permission to read the file."));
		_g_free0 (description);
		description = _tmp5_;
	} else {
		gchar* _tmp6_;
		_tmp6_ = g_strdup (_ ("The file may be corrupt or may not be a text file"));
		_g_free0 (description);
		description = _tmp6_;
	}
	_tmp7_ = title;
	_tmp8_ = description;
	_tmp9_ = granite_widgets_alert_view_new (_tmp7_, _tmp8_, "dialog-error");
	g_object_ref_sink (_tmp9_);
	alert_view = _tmp9_;
	if (g_strcmp0 (_data37_->invalid_content, "") != 0) {
		GraniteWidgetsAlertView* _tmp10_;
		GraniteWidgetsAlertView* _tmp11_;
		_tmp10_ = alert_view;
		granite_widgets_alert_view_show_action (_tmp10_, _ ("Show Anyway"));
		_tmp11_ = alert_view;
		g_signal_connect_data (_tmp11_, "action-activated", (GCallback) ____lambda27__granite_widgets_alert_view_action_activated, block37_data_ref (_data37_), (GClosureNotify) block37_data_unref, 0);
	}
	_tmp12_ = alert_view;
	gtk_widget_show_all ((GtkWidget*) _tmp12_);
	_tmp13_ = self->main_stack;
	_tmp14_ = alert_view;
	gtk_stack_add_named (_tmp13_, (GtkWidget*) _tmp14_, "error_alert");
	_tmp15_ = self->main_stack;
	_tmp16_ = alert_view;
	gtk_stack_set_visible_child (_tmp15_, (GtkWidget*) _tmp16_);
	_g_object_unref0 (alert_view);
	_g_free0 (description);
	_g_free0 (title);
	block37_data_unref (_data37_);
	_data37_ = NULL;
}

static void
scratch_services_document_check_file_status_data_free (gpointer _data)
{
	ScratchServicesDocumentCheckFileStatusData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchServicesDocumentCheckFileStatusData, _data_);
}

static void
scratch_services_document_check_file_status (ScratchServicesDocument* self,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	ScratchServicesDocumentCheckFileStatusData* _data_;
	ScratchServicesDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchServicesDocumentCheckFileStatusData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_services_document_check_file_status_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	scratch_services_document_check_file_status_co (_data_);
}

static void
scratch_services_document_check_file_status_finish (ScratchServicesDocument* self,
                                                    GAsyncResult* _res_)
{
	ScratchServicesDocumentCheckFileStatusData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
scratch_services_document_check_file_status_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_)
{
	ScratchServicesDocumentCheckFileStatusData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_services_document_check_file_status_co (_data_);
}

static gboolean
scratch_services_document_check_file_status_co (ScratchServicesDocumentCheckFileStatusData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (!scratch_services_document_exists (_data_->self, NULL)) {
		_data_->_tmp0_ = _data_->self->priv->_source_view;
		_data_->_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp0_);
		_data_->_tmp2_ = _data_->_tmp1_;
		if (gtk_text_buffer_get_modified (_data_->_tmp2_)) {
			scratch_services_document_set_locked (_data_->self, TRUE);
			if (_data_->self->priv->mounted == FALSE) {
				_data_->_tmp3_ = g_strdup (_ ("The location containing the file “%s” was unmounted and there are unsa" \
"ved changes."));
				_g_free0 (_data_->details);
				_data_->details = _data_->_tmp3_;
			} else {
				_data_->_tmp4_ = g_strdup (_ ("File “%s” was deleted, renamed or moved and there are unsaved changes."));
				_g_free0 (_data_->details);
				_data_->details = _data_->_tmp4_;
			}
			_data_->_tmp5_ = _data_->details;
			_data_->_tmp6_ = scratch_services_document_get_basename (_data_->self);
			_data_->_tmp7_ = _data_->_tmp6_;
			_data_->_tmp8_ = g_strdup_printf ("<b>%s</b>", _data_->_tmp7_);
			_data_->_tmp9_ = _data_->_tmp8_;
			_data_->_tmp10_ = g_strdup_printf (_data_->_tmp5_, _data_->_tmp9_);
			_data_->_tmp11_ = _data_->_tmp10_;
			scratch_services_document_ask_save_location (_data_->self, _data_->_tmp11_, "");
			_g_free0 (_data_->_tmp11_);
			_g_free0 (_data_->_tmp9_);
			_g_free0 (_data_->_tmp7_);
			_g_free0 (_data_->details);
		} else {
			_data_->_tmp12_ = _data_->self->priv->_actions;
			_data_->_tmp13_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_CLOSE_TAB, _data_->_tmp12_);
			_data_->close_tab_action = _data_->_tmp13_;
			_data_->_tmp14_ = _data_->close_tab_action;
			g_simple_action_set_enabled (_data_->_tmp14_, TRUE);
			_data_->self->saved = TRUE;
			_data_->_tmp15_ = _data_->close_tab_action;
			_data_->_tmp16_ = scratch_services_document_get_file (_data_->self);
			_data_->_tmp17_ = _data_->_tmp16_;
			_data_->_tmp18_ = g_file_get_path (_data_->_tmp17_);
			_data_->_tmp19_ = _data_->_tmp18_;
			_data_->_tmp20_ = g_variant_new ("s", _data_->_tmp19_, NULL);
			g_variant_ref_sink (_data_->_tmp20_);
			_data_->_tmp21_ = _data_->_tmp20_;
			g_signal_emit_by_name (_data_->_tmp15_, "activate", _data_->_tmp21_);
			_g_variant_unref0 (_data_->_tmp21_);
			_g_free0 (_data_->_tmp19_);
			_g_object_unref0 (_data_->close_tab_action);
		}
	} else {
		if (_data_->self->priv->loaded) {
			_data_->_tmp22_ = !_data_->self->priv->is_saving;
		} else {
			_data_->_tmp22_ = FALSE;
		}
		if (_data_->_tmp22_) {
			_data_->_tmp25_ = scratch_services_document_get_locked (_data_->self);
			_data_->_tmp26_ = _data_->_tmp25_;
			if (!_data_->_tmp26_) {
				_data_->_tmp24_ = !scratch_services_document_can_write (_data_->self);
			} else {
				_data_->_tmp24_ = FALSE;
			}
			if (_data_->_tmp24_) {
				_data_->_tmp27_ = _data_->self->priv->_source_view;
				_data_->_tmp28_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp27_);
				_data_->_tmp29_ = _data_->_tmp28_;
				_data_->_tmp23_ = gtk_text_buffer_get_modified (_data_->_tmp29_);
			} else {
				_data_->_tmp23_ = FALSE;
			}
			if (_data_->_tmp23_) {
				scratch_services_document_set_locked (_data_->self, TRUE);
				_data_->_tmp30_ = g_strdup (_ ("File “%s” does not have write permission."));
				_data_->_vala1_details = _data_->_tmp30_;
				_data_->_tmp31_ = _data_->_vala1_details;
				_data_->_tmp32_ = scratch_services_document_get_basename (_data_->self);
				_data_->_tmp33_ = _data_->_tmp32_;
				_data_->_tmp34_ = g_strdup_printf ("<b>%s</b>", _data_->_tmp33_);
				_data_->_tmp35_ = _data_->_tmp34_;
				_data_->_tmp36_ = g_strdup_printf (_data_->_tmp31_, _data_->_tmp35_);
				_data_->_tmp37_ = _data_->_tmp36_;
				scratch_services_document_ask_save_location (_data_->self, _data_->_tmp37_, "");
				_g_free0 (_data_->_tmp37_);
				_g_free0 (_data_->_tmp35_);
				_g_free0 (_data_->_tmp33_);
				_g_free0 (_data_->_vala1_details);
			} else {
				_data_->_tmp38_ = gtk_source_buffer_new (NULL);
				_data_->new_buffer = _data_->_tmp38_;
				_data_->_tmp39_ = _data_->new_buffer;
				_data_->_tmp40_ = _data_->self->priv->source_file;
				_data_->_tmp41_ = gtk_source_file_loader_new (_data_->_tmp39_, _data_->_tmp40_);
				_data_->source_file_loader = _data_->_tmp41_;
				{
					_data_->_tmp42_ = _data_->source_file_loader;
					_data_->_state_ = 1;
					gtk_source_file_loader_load_async (_data_->_tmp42_, G_PRIORITY_DEFAULT, NULL, NULL, NULL, NULL, scratch_services_document_check_file_status_ready, _data_);
					return FALSE;
					_state_1:
					gtk_source_file_loader_load_finish (_data_->_tmp42_, _data_->_res_, &_data_->_inner_error0_);
					if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
						goto __catch0_g_error;
					}
				}
				goto __finally0;
				__catch0_g_error:
				{
					_data_->e = _data_->_inner_error0_;
					_data_->_inner_error0_ = NULL;
					_data_->_tmp43_ = _data_->e;
					_data_->_tmp44_ = _data_->_tmp43_->message;
					g_critical ("Document.vala:969: %s", _data_->_tmp44_);
					scratch_services_document_show_default_load_error_view (_data_->self, "");
					_g_error_free0 (_data_->e);
					_g_object_unref0 (_data_->source_file_loader);
					_g_object_unref0 (_data_->new_buffer);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				__finally0:
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					_g_object_unref0 (_data_->source_file_loader);
					_g_object_unref0 (_data_->new_buffer);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
					g_clear_error (&_data_->_inner_error0_);
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp45_ = _data_->self->priv->last_save_content;
				_data_->_tmp46_ = _data_->new_buffer;
				g_object_get ((GtkTextBuffer*) _data_->_tmp46_, "text", &_data_->_tmp47_, NULL);
				_data_->_tmp48_ = _data_->_tmp47_;
				_data_->_tmp49_ = _data_->_tmp48_;
				_data_->_tmp50_ = g_strcmp0 (_data_->_tmp45_, _data_->_tmp49_) == 0;
				_g_free0 (_data_->_tmp49_);
				if (_data_->_tmp50_) {
					_g_object_unref0 (_data_->source_file_loader);
					_g_object_unref0 (_data_->new_buffer);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp51_ = _data_->self->priv->last_save_content;
				_data_->_tmp52_ = _data_->self->priv->_source_view;
				_data_->_tmp53_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp52_);
				_data_->_tmp54_ = _data_->_tmp53_;
				g_object_get (_data_->_tmp54_, "text", &_data_->_tmp55_, NULL);
				_data_->_tmp56_ = _data_->_tmp55_;
				_data_->_tmp57_ = _data_->_tmp56_;
				_data_->_tmp58_ = g_strcmp0 (_data_->_tmp51_, _data_->_tmp57_) == 0;
				_g_free0 (_data_->_tmp57_);
				if (_data_->_tmp58_) {
					_data_->self->priv->loaded = FALSE;
					_data_->_tmp59_ = _data_->self->priv->_source_view;
					_data_->_tmp60_ = _data_->new_buffer;
					g_object_get ((GtkTextBuffer*) _data_->_tmp60_, "text", &_data_->_tmp61_, NULL);
					_data_->_tmp62_ = _data_->_tmp61_;
					_data_->_tmp63_ = _data_->_tmp62_;
					scratch_widgets_source_view_set_text (_data_->_tmp59_, _data_->_tmp63_, TRUE);
					_g_free0 (_data_->_tmp63_);
					_data_->_tmp64_ = _data_->new_buffer;
					g_object_get ((GtkTextBuffer*) _data_->_tmp64_, "text", &_data_->_tmp65_, NULL);
					_data_->_tmp66_ = _data_->_tmp65_;
					_g_free0 (_data_->self->priv->last_save_content);
					_data_->self->priv->last_save_content = _data_->_tmp66_;
					scratch_services_document_set_saved_status (_data_->self, TRUE);
					_data_->_tmp67_ = _data_->self->priv->_source_view;
					_data_->_tmp68_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp67_);
					_data_->_tmp69_ = _data_->_tmp68_;
					gtk_text_buffer_set_modified (_data_->_tmp69_, FALSE);
					_data_->self->priv->loaded = TRUE;
					_data_->_tmp70_ = _data_->self->priv->outline;
					if (_data_->_tmp70_ != NULL) {
						_data_->_tmp71_ = _data_->self->priv->outline;
						scratch_services_symbol_outline_parse_symbols (_data_->_tmp71_);
					}
					_g_object_unref0 (_data_->source_file_loader);
					_g_object_unref0 (_data_->new_buffer);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp72_ = scratch_services_document_get_file (_data_->self);
				_data_->_tmp73_ = _data_->_tmp72_;
				_data_->_tmp74_ = g_file_get_uri (_data_->_tmp73_);
				_data_->_tmp75_ = _data_->_tmp74_;
				_data_->_tmp76_ = g_strdup_printf (_ ("File “%s” was modified by an external application"), _data_->_tmp75_);
				_data_->_tmp77_ = _data_->_tmp76_;
				_g_free0 (_data_->_tmp75_);
				_data_->primary_text = _data_->_tmp77_;
				_data_->_tmp78_ = _data_->self->priv->_source_view;
				_data_->_tmp79_ = gtk_text_view_get_buffer ((GtkTextView*) _data_->_tmp78_);
				_data_->_tmp80_ = _data_->_tmp79_;
				if (gtk_text_buffer_get_modified (_data_->_tmp80_)) {
					_data_->_tmp81_ = g_strdup (_ ("There are also unsaved changes. Reloading the document will overwrite " \
"the unsaved changes."));
					_g_free0 (_data_->secondary_text);
					_data_->secondary_text = _data_->_tmp81_;
				} else {
					_data_->_tmp82_ = g_strdup (_ ("The document changed externally since you last saved it."));
					_g_free0 (_data_->secondary_text);
					_data_->secondary_text = _data_->_tmp82_;
				}
				_data_->_tmp83_ = _data_->primary_text;
				_data_->_tmp84_ = _data_->secondary_text;
				_data_->_tmp85_ = _data_->new_buffer;
				g_object_get ((GtkTextBuffer*) _data_->_tmp85_, "text", &_data_->_tmp86_, NULL);
				_data_->_tmp87_ = _data_->_tmp86_;
				_data_->_tmp88_ = _data_->_tmp87_;
				scratch_services_document_ask_external_changes (_data_->self, _data_->_tmp83_, _data_->_tmp84_, _data_->_tmp88_);
				_g_free0 (_data_->_tmp88_);
				_g_free0 (_data_->secondary_text);
				_g_free0 (_data_->primary_text);
				_g_object_unref0 (_data_->source_file_loader);
				_g_object_unref0 (_data_->new_buffer);
			}
		}
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static Block38Data*
block38_data_ref (Block38Data* _data38_)
{
	g_atomic_int_inc (&_data38_->_ref_count_);
	return _data38_;
}

static void
block38_data_unref (void * _userdata_)
{
	Block38Data* _data38_;
	_data38_ = (Block38Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data38_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data38_->self;
		_g_object_unref0 (_data38_->dialog);
		_g_object_unref0 (self);
		g_slice_free (Block38Data, _data38_);
	}
}

static Block39Data*
block39_data_ref (Block39Data* _data39_)
{
	g_atomic_int_inc (&_data39_->_ref_count_);
	return _data39_;
}

static void
block39_data_unref (void * _userdata_)
{
	Block39Data* _data39_;
	_data39_ = (Block39Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data39_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data39_->_data38_->self;
		block38_data_unref (_data39_->_data38_);
		_data39_->_data38_ = NULL;
		g_slice_free (Block39Data, _data39_);
	}
}

static void
___lambda26_ (ScratchServicesDocument* self,
              GObject* obj,
              GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	if (scratch_services_document_save_as_with_hold_finish (self, res)) {
		scratch_services_document_set_locked (self, FALSE);
	}
}

static void
____lambda26__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda26_ ((ScratchServicesDocument*) self, source_object, res);
	g_object_unref (self);
}

static gboolean
__lambda25_ (Block39Data* _data39_)
{
	Block38Data* _data38_;
	ScratchServicesDocument* self;
	gboolean result;
	_data38_ = _data39_->_data38_;
	self = _data38_->self;
	switch (_data39_->id) {
		case GTK_RESPONSE_ACCEPT:
		{
			scratch_services_document_save_as_with_hold (self, ____lambda26__gasync_ready_callback, g_object_ref (self));
			break;
		}
		case GTK_RESPONSE_REJECT:
		{
			break;
		}
		default:
		{
			break;
		}
	}
	result = FALSE;
	return result;
}

static gboolean
___lambda25__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda25_ (self);
	return result;
}

static void
__lambda24_ (Block38Data* _data38_,
             gint id)
{
	ScratchServicesDocument* self;
	Block39Data* _data39_;
	GraniteMessageDialog* _tmp0_;
	self = _data38_->self;
	_data39_ = g_slice_new0 (Block39Data);
	_data39_->_ref_count_ = 1;
	_data39_->_data38_ = block38_data_ref (_data38_);
	_data39_->id = id;
	_tmp0_ = _data38_->dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp0_);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda25__gsource_func, block39_data_ref (_data39_), block39_data_unref);
	block39_data_unref (_data39_);
	_data39_ = NULL;
}

static void
___lambda24__gtk_dialog_response (GtkDialog* _sender,
                                  gint response_id,
                                  gpointer self)
{
	__lambda24_ (self, response_id);
}

static void
scratch_services_document_ask_save_location (ScratchServicesDocument* self,
                                             const gchar* details,
                                             const gchar* error_text)
{
	Block38Data* _data38_;
	GtkApplication* app_instance = NULL;
	GApplication* _tmp0_;
	GtkApplication* _tmp1_;
	GFile* _tmp2_;
	GFile* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GThemedIcon* _tmp8_;
	GtkApplication* _tmp9_;
	GtkWindow* _tmp10_;
	GtkWindow* _tmp11_;
	GtkWindow* _tmp12_;
	GraniteMessageDialog* _tmp13_ = NULL;
	GraniteMessageDialog* _tmp14_;
	GraniteMessageDialog* _tmp15_;
	GtkButton* saveas_button = NULL;
	GraniteMessageDialog* _tmp16_;
	GtkWidget* _tmp17_;
	GtkButton* _tmp18_;
	GtkButton* _tmp19_;
	GtkStyleContext* _tmp20_;
	GraniteMessageDialog* _tmp22_;
	GraniteMessageDialog* _tmp23_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (details != NULL);
	g_return_if_fail (error_text != NULL);
	_data38_ = g_slice_new0 (Block38Data);
	_data38_->_ref_count_ = 1;
	_data38_->self = g_object_ref (self);
	scratch_services_document_set_locked (self, TRUE);
	_tmp0_ = g_application_get_default ();
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_application_get_type (), GtkApplication));
	app_instance = _tmp1_;
	_tmp2_ = scratch_services_document_get_file (self);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_file_get_basename (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strdup_printf (_ ("“%s” can't be saved here. Save a duplicate somewhere else?"), _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = (GThemedIcon*) g_themed_icon_new ("dialog-question");
	_tmp9_ = app_instance;
	_tmp10_ = gtk_application_get_active_window (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = _g_object_ref0 (_tmp11_);
	_tmp13_ = granite_message_dialog_new_with_image_from_icon_name (_tmp7_, details, "document-save", GTK_BUTTONS_NONE);
	granite_message_dialog_set_badge_icon (_tmp13_, (GIcon*) _tmp8_);
	_g_object_unref0 (_tmp8_);
	gtk_window_set_transient_for ((GtkWindow*) _tmp13_, _tmp12_);
	_g_object_unref0 (_tmp12_);
	g_object_ref_sink (_tmp13_);
	_tmp14_ = _tmp13_;
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_data38_->dialog = _tmp14_;
	_tmp15_ = _data38_->dialog;
	gtk_dialog_add_button ((GtkDialog*) _tmp15_, _ ("Ignore"), (gint) GTK_RESPONSE_REJECT);
	_tmp16_ = _data38_->dialog;
	_tmp17_ = gtk_dialog_add_button ((GtkDialog*) _tmp16_, _ ("Save Duplicate…"), (gint) GTK_RESPONSE_ACCEPT);
	_tmp18_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, gtk_button_get_type (), GtkButton));
	saveas_button = _tmp18_;
	_tmp19_ = saveas_button;
	_tmp20_ = gtk_widget_get_style_context ((GtkWidget*) _tmp19_);
	gtk_style_context_add_class (_tmp20_, GTK_STYLE_CLASS_SUGGESTED_ACTION);
	if (g_strcmp0 (error_text, "") != 0) {
		GraniteMessageDialog* _tmp21_;
		_tmp21_ = _data38_->dialog;
		granite_message_dialog_show_error_details (_tmp21_, error_text);
	}
	_tmp22_ = _data38_->dialog;
	g_signal_connect_data ((GtkDialog*) _tmp22_, "response", (GCallback) ___lambda24__gtk_dialog_response, block38_data_ref (_data38_), (GClosureNotify) block38_data_unref, 0);
	_tmp23_ = _data38_->dialog;
	gtk_window_present ((GtkWindow*) _tmp23_);
	_g_object_unref0 (saveas_button);
	_g_object_unref0 (app_instance);
	block38_data_unref (_data38_);
	_data38_ = NULL;
}

static Block40Data*
block40_data_ref (Block40Data* _data40_)
{
	g_atomic_int_inc (&_data40_->_ref_count_);
	return _data40_;
}

static void
block40_data_unref (void * _userdata_)
{
	Block40Data* _data40_;
	_data40_ = (Block40Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data40_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data40_->self;
		_g_object_unref0 (_data40_->dialog);
		_g_free0 (_data40_->external_content);
		_g_object_unref0 (self);
		g_slice_free (Block40Data, _data40_);
	}
}

static Block41Data*
block41_data_ref (Block41Data* _data41_)
{
	g_atomic_int_inc (&_data41_->_ref_count_);
	return _data41_;
}

static void
block41_data_unref (void * _userdata_)
{
	Block41Data* _data41_;
	_data41_ = (Block41Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data41_->_ref_count_)) {
		ScratchServicesDocument* self;
		self = _data41_->_data40_->self;
		block40_data_unref (_data41_->_data40_);
		_data41_->_data40_ = NULL;
		g_slice_free (Block41Data, _data41_);
	}
}

static void
___lambda35_ (ScratchServicesDocument* self,
              GObject* obj,
              GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	if (scratch_services_document_save_as_with_hold_finish (self, res)) {
		scratch_services_document_set_locked (self, FALSE);
	}
}

static void
____lambda35__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda35_ ((ScratchServicesDocument*) self, source_object, res);
	g_object_unref (self);
}

static void
___lambda36_ (ScratchServicesDocument* self,
              GObject* obj,
              GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	if (!scratch_services_document_save_with_hold_finish (self, res)) {
		scratch_services_document_set_locked (self, TRUE);
	}
}

static void
____lambda36__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda36_ ((ScratchServicesDocument*) self, source_object, res);
	g_object_unref (self);
}

static gboolean
__lambda34_ (Block41Data* _data41_)
{
	Block40Data* _data40_;
	ScratchServicesDocument* self;
	gboolean result;
	_data40_ = _data41_->_data40_;
	self = _data40_->self;
	switch (_data41_->id) {
		case GTK_RESPONSE_ACCEPT:
		{
			scratch_services_document_save_as_with_hold (self, ____lambda35__gasync_ready_callback, g_object_ref (self));
			break;
		}
		case GTK_RESPONSE_REJECT:
		{
			break;
		}
		case 0:
		{
			ScratchWidgetsSourceView* _tmp0_;
			GtkTextBuffer* _tmp1_;
			GtkTextBuffer* _tmp2_;
			ScratchWidgetsSourceView* _tmp3_;
			GtkTextBuffer* _tmp4_;
			GtkTextBuffer* _tmp5_;
			ScratchWidgetsSourceView* _tmp6_;
			GtkTextBuffer* _tmp7_;
			GtkTextBuffer* _tmp8_;
			gchar* _tmp9_;
			gchar* _tmp10_;
			ScratchServicesSymbolOutline* _tmp11_;
			_tmp0_ = self->priv->_source_view;
			_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp0_);
			_tmp2_ = _tmp1_;
			g_object_set (_tmp2_, "text", _data40_->external_content, NULL);
			_tmp3_ = self->priv->_source_view;
			_tmp4_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp3_);
			_tmp5_ = _tmp4_;
			gtk_text_buffer_set_modified (_tmp5_, FALSE);
			_tmp6_ = self->priv->_source_view;
			_tmp7_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp6_);
			_tmp8_ = _tmp7_;
			g_object_get (_tmp8_, "text", &_tmp9_, NULL);
			_tmp10_ = _tmp9_;
			_g_free0 (self->priv->last_save_content);
			self->priv->last_save_content = _tmp10_;
			scratch_services_document_set_saved_status (self, TRUE);
			scratch_services_document_set_locked (self, FALSE);
			_tmp11_ = self->priv->outline;
			if (_tmp11_ != NULL) {
				ScratchServicesSymbolOutline* _tmp12_;
				_tmp12_ = self->priv->outline;
				scratch_services_symbol_outline_parse_symbols (_tmp12_);
			}
			break;
		}
		case 1:
		{
			scratch_services_document_set_locked (self, FALSE);
			scratch_services_document_save_with_hold (self, TRUE, FALSE, ____lambda36__gasync_ready_callback, g_object_ref (self));
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda34__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda34_ (self);
	return result;
}

static void
__lambda33_ (Block40Data* _data40_,
             gint id)
{
	ScratchServicesDocument* self;
	Block41Data* _data41_;
	self = _data40_->self;
	_data41_ = g_slice_new0 (Block41Data);
	_data41_->_ref_count_ = 1;
	_data41_->_data40_ = block40_data_ref (_data40_);
	_data41_->id = id;
	gtk_widget_destroy ((GtkWidget*) _data40_->dialog);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda34__gsource_func, block41_data_ref (_data41_), block41_data_unref);
	block41_data_unref (_data41_);
	_data41_ = NULL;
}

static void
___lambda33__gtk_dialog_response (GtkDialog* _sender,
                                  gint response_id,
                                  gpointer self)
{
	__lambda33_ (self, response_id);
}

static void
scratch_services_document_ask_external_changes (ScratchServicesDocument* self,
                                                const gchar* primary_text,
                                                const gchar* secondary_text,
                                                const gchar* external_content)
{
	Block40Data* _data40_;
	gchar* _tmp0_;
	GtkApplication* app_instance = NULL;
	GApplication* _tmp1_;
	GtkApplication* _tmp2_;
	GThemedIcon* _tmp3_;
	GThemedIcon* _tmp4_;
	GtkWindow* _tmp5_;
	GtkWindow* _tmp6_;
	GtkWindow* _tmp7_;
	GraniteMessageDialog* _tmp8_ = NULL;
	GraniteMessageDialog* _tmp9_;
	GtkButton* reload_button = NULL;
	GtkWidget* _tmp10_;
	GtkButton* _tmp11_;
	GtkStyleContext* _tmp12_;
	GtkButton* overwrite_button = NULL;
	GtkWidget* _tmp13_;
	GtkButton* _tmp14_;
	GtkStyleContext* _tmp15_;
	GtkButton* saveas_button = NULL;
	GtkWidget* _tmp16_;
	GtkButton* _tmp17_;
	GtkStyleContext* _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (primary_text != NULL);
	g_return_if_fail (secondary_text != NULL);
	g_return_if_fail (external_content != NULL);
	_data40_ = g_slice_new0 (Block40Data);
	_data40_->_ref_count_ = 1;
	_data40_->self = g_object_ref (self);
	_tmp0_ = g_strdup (external_content);
	_g_free0 (_data40_->external_content);
	_data40_->external_content = _tmp0_;
	scratch_services_document_set_locked (self, TRUE);
	_tmp1_ = g_application_get_default ();
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_application_get_type (), GtkApplication));
	app_instance = _tmp2_;
	_tmp3_ = (GThemedIcon*) g_themed_icon_new ("dialog-warning");
	_tmp4_ = _tmp3_;
	_tmp5_ = gtk_application_get_active_window (app_instance);
	_tmp6_ = _tmp5_;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	_tmp8_ = granite_message_dialog_new (primary_text, secondary_text, (GIcon*) _tmp4_, GTK_BUTTONS_NONE);
	gtk_window_set_transient_for ((GtkWindow*) _tmp8_, _tmp7_);
	_g_object_unref0 (_tmp7_);
	g_object_ref_sink (_tmp8_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp4_);
	_data40_->dialog = _tmp9_;
	gtk_dialog_add_button ((GtkDialog*) _data40_->dialog, _ ("Continue"), (gint) GTK_RESPONSE_REJECT);
	_tmp10_ = gtk_dialog_add_button ((GtkDialog*) _data40_->dialog, _ ("Reload"), 0);
	_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, gtk_button_get_type (), GtkButton));
	reload_button = _tmp11_;
	_tmp12_ = gtk_widget_get_style_context ((GtkWidget*) reload_button);
	gtk_style_context_add_class (_tmp12_, GTK_STYLE_CLASS_DESTRUCTIVE_ACTION);
	_tmp13_ = gtk_dialog_add_button ((GtkDialog*) _data40_->dialog, _ ("Overwrite"), 1);
	_tmp14_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, gtk_button_get_type (), GtkButton));
	overwrite_button = _tmp14_;
	_tmp15_ = gtk_widget_get_style_context ((GtkWidget*) overwrite_button);
	gtk_style_context_add_class (_tmp15_, GTK_STYLE_CLASS_DESTRUCTIVE_ACTION);
	_tmp16_ = gtk_dialog_add_button ((GtkDialog*) _data40_->dialog, _ ("Save Document elsewhere"), (gint) GTK_RESPONSE_ACCEPT);
	_tmp17_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, gtk_button_get_type (), GtkButton));
	saveas_button = _tmp17_;
	_tmp18_ = gtk_widget_get_style_context ((GtkWidget*) saveas_button);
	gtk_style_context_add_class (_tmp18_, GTK_STYLE_CLASS_SUGGESTED_ACTION);
	g_signal_connect_data ((GtkDialog*) _data40_->dialog, "response", (GCallback) ___lambda33__gtk_dialog_response, block40_data_ref (_data40_), (GClosureNotify) block40_data_unref, 0);
	gtk_window_present ((GtkWindow*) _data40_->dialog);
	_g_object_unref0 (saveas_button);
	_g_object_unref0 (overwrite_button);
	_g_object_unref0 (reload_button);
	_g_object_unref0 (app_instance);
	block40_data_unref (_data40_);
	_data40_ = NULL;
}

void
scratch_services_document_check_undoable_actions (ScratchServicesDocument* self)
{
	GtkSourceBuffer* source_buffer = NULL;
	ScratchWidgetsSourceView* _tmp0_;
	GtkTextBuffer* _tmp1_;
	GtkTextBuffer* _tmp2_;
	GtkSourceBuffer* _tmp3_;
	GSimpleActionGroup* _tmp4_;
	GSimpleAction* _tmp5_;
	GSimpleAction* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	GSimpleActionGroup* _tmp9_;
	GSimpleAction* _tmp10_;
	GSimpleAction* _tmp11_;
	gboolean _tmp12_;
	gboolean _tmp13_;
	GSimpleActionGroup* _tmp14_;
	GSimpleAction* _tmp15_;
	GSimpleAction* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gtk_source_buffer_get_type (), GtkSourceBuffer));
	source_buffer = _tmp3_;
	_tmp4_ = self->priv->_actions;
	_tmp5_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_UNDO, _tmp4_);
	_tmp6_ = _tmp5_;
	g_object_get (source_buffer, "can-undo", &_tmp7_, NULL);
	_tmp8_ = _tmp7_;
	g_simple_action_set_enabled (_tmp6_, _tmp8_);
	_g_object_unref0 (_tmp6_);
	_tmp9_ = self->priv->_actions;
	_tmp10_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_REDO, _tmp9_);
	_tmp11_ = _tmp10_;
	g_object_get (source_buffer, "can-redo", &_tmp12_, NULL);
	_tmp13_ = _tmp12_;
	g_simple_action_set_enabled (_tmp11_, _tmp13_);
	_g_object_unref0 (_tmp11_);
	_tmp14_ = self->priv->_actions;
	_tmp15_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_REVERT, _tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = self->original_content;
	g_object_get ((GtkTextBuffer*) source_buffer, "text", &_tmp18_, NULL);
	_tmp19_ = _tmp18_;
	_tmp20_ = _tmp19_;
	g_simple_action_set_enabled (_tmp16_, g_strcmp0 (_tmp17_, _tmp20_) != 0);
	_g_free0 (_tmp20_);
	_g_object_unref0 (_tmp16_);
	_g_object_unref0 (source_buffer);
}

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

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

void
scratch_services_document_set_saved_status (ScratchServicesDocument* self,
                                            gboolean val)
{
	gchar* unsaved_identifier = NULL;
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	self->saved = val;
	_tmp0_ = g_strdup ("* ");
	unsaved_identifier = _tmp0_;
	if (!val) {
		const gchar* _tmp1_;
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		_tmp1_ = scratch_services_document_get_title (self);
		_tmp2_ = _tmp1_;
		_tmp3_ = unsaved_identifier;
		if (!string_contains (_tmp2_, _tmp3_)) {
			const gchar* _tmp4_;
			const gchar* _tmp5_;
			const gchar* _tmp6_;
			gchar* _tmp7_;
			gchar* _tmp8_;
			_tmp4_ = unsaved_identifier;
			_tmp5_ = scratch_services_document_get_title (self);
			_tmp6_ = _tmp5_;
			_tmp7_ = g_strconcat (_tmp4_, _tmp6_, NULL);
			_tmp8_ = _tmp7_;
			scratch_services_document_set_title (self, _tmp8_);
			_g_free0 (_tmp8_);
		}
	} else {
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp9_ = scratch_services_document_get_title (self);
		_tmp10_ = _tmp9_;
		_tmp11_ = unsaved_identifier;
		_tmp12_ = string_replace (_tmp10_, _tmp11_, "");
		_tmp13_ = _tmp12_;
		scratch_services_document_set_title (self, _tmp13_);
		_g_free0 (_tmp13_);
	}
	_g_free0 (unsaved_identifier);
}

static void
scratch_services_document_create_backup (ScratchServicesDocument* self)
{
	gboolean _tmp0_ = FALSE;
	GFile* backup = NULL;
	GFile* _tmp2_;
	GFile* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GFile* _tmp8_;
	GFile* _tmp9_;
	GFile* _tmp10_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	if (!scratch_services_document_can_write (self)) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp1_;
		_tmp1_ = self->priv->_closing;
		_tmp0_ = _tmp1_;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = scratch_services_document_get_file (self);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_file_get_path (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp5_, "~", NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_file_new_for_path (_tmp7_);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	backup = _tmp9_;
	_tmp10_ = backup;
	if (!g_file_query_exists (_tmp10_, NULL)) {
		{
			GFile* _tmp11_;
			GFile* _tmp12_;
			GFile* _tmp13_;
			_tmp11_ = scratch_services_document_get_file (self);
			_tmp12_ = _tmp11_;
			_tmp13_ = backup;
			g_file_copy (_tmp12_, _tmp13_, G_FILE_COPY_NONE, NULL, NULL, NULL, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			gchar* _tmp14_;
			gchar* _tmp15_;
			GError* _tmp16_;
			const gchar* _tmp17_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp14_ = scratch_services_document_get_uri (self);
			_tmp15_ = _tmp14_;
			_tmp16_ = e;
			_tmp17_ = _tmp16_->message;
			g_warning ("Document.vala:1173: Cannot create backup copy for file “%s”: %s", _tmp15_, _tmp17_);
			_g_free0 (_tmp15_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (backup);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	_g_object_unref0 (backup);
}

static void
scratch_services_document_delete_backup (ScratchServicesDocument* self,
                                         const gchar* backup_path)
{
	gchar* backup_file = NULL;
	const gchar* _tmp6_;
	GFile* backup = NULL;
	const gchar* _tmp7_;
	GFile* _tmp8_;
	gboolean _tmp9_ = FALSE;
	GFile* _tmp10_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	if (backup_path == NULL) {
		GFile* _tmp0_;
		GFile* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp0_ = scratch_services_document_get_file (self);
		_tmp1_ = _tmp0_;
		_tmp2_ = g_file_get_path (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_strconcat (_tmp3_, "~", NULL);
		_g_free0 (backup_file);
		backup_file = _tmp4_;
		_g_free0 (_tmp3_);
	} else {
		gchar* _tmp5_;
		_tmp5_ = g_strdup (backup_path);
		_g_free0 (backup_file);
		backup_file = _tmp5_;
	}
	_tmp6_ = backup_file;
	g_debug ("Document.vala:1187: Backup file deleting: %s", _tmp6_);
	_tmp7_ = backup_file;
	_tmp8_ = g_file_new_for_path (_tmp7_);
	backup = _tmp8_;
	_tmp10_ = backup;
	if (_tmp10_ == NULL) {
		_tmp9_ = TRUE;
	} else {
		GFile* _tmp11_;
		_tmp11_ = backup;
		_tmp9_ = !g_file_query_exists (_tmp11_, NULL);
	}
	if (_tmp9_) {
		GFile* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		_tmp12_ = backup;
		_tmp13_ = g_file_get_path (_tmp12_);
		_tmp14_ = _tmp13_;
		g_debug ("Document.vala:1190: Backup file doesn't exists: %s", _tmp14_);
		_g_free0 (_tmp14_);
		_g_object_unref0 (backup);
		_g_free0 (backup_file);
		return;
	}
	{
		GFile* _tmp15_;
		const gchar* _tmp16_;
		_tmp15_ = backup;
		g_file_delete (_tmp15_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp16_ = backup_file;
		g_debug ("Document.vala:1196: Backup file deleted: %s", _tmp16_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		gchar* _tmp17_;
		gchar* _tmp18_;
		GError* _tmp19_;
		const gchar* _tmp20_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp17_ = scratch_services_document_get_basename (self);
		_tmp18_ = _tmp17_;
		_tmp19_ = e;
		_tmp20_ = _tmp19_->message;
		g_warning ("Document.vala:1198: Cannot delete backup for file “%s”: %s", _tmp18_, _tmp20_);
		_g_free0 (_tmp18_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (backup);
		_g_free0 (backup_file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_object_unref0 (backup);
	_g_free0 (backup_file);
}

static gboolean
scratch_services_document_delete_temporary_file (ScratchServicesDocument* self,
                                                 gboolean force)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp2_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = scratch_services_document_get_is_file_temporary (self);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp3_ = FALSE;
		gchar* _tmp4_;
		gchar* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gboolean _tmp8_;
		_tmp4_ = scratch_services_document_get_text (self);
		_tmp5_ = _tmp4_;
		_tmp6_ = strlen (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_ > 0;
		_g_free0 (_tmp5_);
		if (_tmp8_) {
			_tmp3_ = !force;
		} else {
			_tmp3_ = FALSE;
		}
		_tmp0_ = _tmp3_;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	{
		GFile* _tmp9_;
		GFile* _tmp10_;
		_tmp9_ = scratch_services_document_get_file (self);
		_tmp10_ = _tmp9_;
		g_file_delete (_tmp10_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		result = TRUE;
		return result;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp11_;
		GFile* _tmp12_;
		GFile* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		GError* _tmp16_;
		const gchar* _tmp17_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp11_ = e;
		if (g_error_matches (_tmp11_, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
			result = TRUE;
			_g_error_free0 (e);
			return result;
		}
		_tmp12_ = scratch_services_document_get_file (self);
		_tmp13_ = _tmp12_;
		_tmp14_ = g_file_get_uri (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = e;
		_tmp17_ = _tmp16_->message;
		g_warning ("Document.vala:1214: Cannot delete temporary file “%s”: %s", _tmp15_, _tmp17_);
		_g_free0 (_tmp15_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp18_ = FALSE;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp18_;
	}
	result = FALSE;
	return result;
}

gboolean
scratch_services_document_can_write (ScratchServicesDocument* self)
{
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		GFileInfo* info = NULL;
		GFile* _tmp0_;
		GFile* _tmp1_;
		GFileInfo* _tmp2_;
		GFileInfo* _tmp3_;
		_tmp0_ = scratch_services_document_get_file (self);
		_tmp1_ = _tmp0_;
		_tmp2_ = g_file_query_info (_tmp1_, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
		info = _tmp2_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp3_ = info;
		if (g_file_info_has_attribute (_tmp3_, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
			GFileInfo* _tmp4_;
			_tmp4_ = info;
			result = g_file_info_get_attribute_boolean (_tmp4_, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
			_g_object_unref0 (info);
			return result;
		}
		_g_object_unref0 (info);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		g_debug ("Document.vala:1228: query_info ACCESS_CAN_WRITE failed");
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp5_ = FALSE;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp5_;
	}
	result = TRUE;
	return result;
}

gboolean
scratch_services_document_exists (ScratchServicesDocument* self,
                                  GCancellable* cancellable)
{
	GFile* _tmp0_;
	GFile* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = scratch_services_document_get_file (self);
	_tmp1_ = _tmp0_;
	result = g_file_query_exists (_tmp1_, cancellable);
	return result;
}

static void
_scratch_services_document_unmounted_cb_g_mount_unmounted (GMount* _sender,
                                                           gpointer self)
{
	scratch_services_document_unmounted_cb ((ScratchServicesDocument*) self);
}

static void
scratch_services_document_file_changed (ScratchServicesDocument* self)
{
	GMount* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->mount;
	if (_tmp0_ != NULL) {
		GMount* _tmp1_;
		guint _tmp2_;
		_tmp1_ = self->priv->mount;
		g_signal_parse_name ("unmounted", g_mount_get_type (), &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _scratch_services_document_unmounted_cb_g_mount_unmounted, self);
		_g_object_unref0 (self->priv->mount);
		self->priv->mount = NULL;
	}
	{
		GMount* _tmp3_ = NULL;
		GFile* _tmp4_;
		GFile* _tmp5_;
		GMount* _tmp6_;
		GMount* _tmp7_;
		GMount* _tmp8_;
		_tmp4_ = scratch_services_document_get_file (self);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_file_find_enclosing_mount (_tmp5_, NULL, &_inner_error0_);
		_tmp3_ = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp7_ = _tmp3_;
		_tmp3_ = NULL;
		_g_object_unref0 (self->priv->mount);
		self->priv->mount = _tmp7_;
		_tmp8_ = self->priv->mount;
		g_signal_connect_object (_tmp8_, "unmounted", (GCallback) _scratch_services_document_unmounted_cb_g_mount_unmounted, self, 0);
		_g_object_unref0 (_tmp3_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		g_debug ("Document.vala:1249: Could not find mount location");
		return;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	self->priv->mounted = TRUE;
}

static void
_scratch_services_document_sync_outline_width_g_object_notify (GObject* _sender,
                                                               GParamSpec* pspec,
                                                               gpointer self)
{
	scratch_services_document_sync_outline_width ((ScratchServicesDocument*) self);
}

static gboolean
____lambda50_ (ScratchServicesDocument* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	ScratchWidgetsDocumentView* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	GtkPaned* _tmp4_;
	HdyTabPage* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	gboolean result;
	_tmp0_ = scratch_services_document_get_doc_view (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = scratch_widgets_document_view_get_outline_width (_tmp1_);
	_tmp3_ = _tmp2_;
	scratch_services_document_set_outline_width (self, _tmp3_);
	_tmp4_ = self->priv->outline_widget_pane;
	g_signal_connect_object ((GObject*) _tmp4_, "notify::position", (GCallback) _scratch_services_document_sync_outline_width_g_object_notify, self, 0);
	_tmp5_ = self->priv->_tab;
	_tmp6_ = hdy_tab_page_get_loading (_tmp5_);
	_tmp7_ = _tmp6_;
	if (!_tmp7_) {
		ScratchServicesSymbolOutline* _tmp8_;
		_tmp8_ = self->priv->outline;
		scratch_services_symbol_outline_parse_symbols (_tmp8_);
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
_____lambda50__gsource_func (gpointer self)
{
	gboolean result;
	result = ____lambda50_ ((ScratchServicesDocument*) self);
	return result;
}

void
scratch_services_document_show_outline (ScratchServicesDocument* self,
                                        gboolean show)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (show) {
		ScratchServicesSymbolOutline* _tmp1_;
		_tmp1_ = self->priv->outline;
		_tmp0_ = _tmp1_ == NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		GQuark _tmp6_ = 0U;
		static GQuark _tmp5_label0 = 0;
		static GQuark _tmp5_label1 = 0;
		static GQuark _tmp5_label2 = 0;
		static GQuark _tmp5_label3 = 0;
		static GQuark _tmp5_label4 = 0;
		ScratchServicesSymbolOutline* _tmp9_;
		_tmp2_ = scratch_services_document_get_mime_type (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		_tmp6_ = (NULL == _tmp4_) ? 0 : g_quark_from_string (_tmp4_);
		if (_tmp6_ == ((0 != _tmp5_label0) ? _tmp5_label0 : (_tmp5_label0 = g_quark_from_static_string ("text/x-vala")))) {
			switch (0) {
				default:
				{
					ScratchServicesValaSymbolOutline* _tmp7_;
					_tmp7_ = scratch_services_vala_symbol_outline_new (self);
					g_object_ref_sink (_tmp7_);
					_g_object_unref0 (self->priv->outline);
					self->priv->outline = (ScratchServicesSymbolOutline*) _tmp7_;
					break;
				}
			}
		} else if ((((_tmp6_ == ((0 != _tmp5_label1) ? _tmp5_label1 : (_tmp5_label1 = g_quark_from_static_string ("text/x-csrc")))) || (_tmp6_ == ((0 != _tmp5_label2) ? _tmp5_label2 : (_tmp5_label2 = g_quark_from_static_string ("text/x-chdr"))))) || (_tmp6_ == ((0 != _tmp5_label3) ? _tmp5_label3 : (_tmp5_label3 = g_quark_from_static_string ("text/x-c++src"))))) || (_tmp6_ == ((0 != _tmp5_label4) ? _tmp5_label4 : (_tmp5_label4 = g_quark_from_static_string ("text/x-c++hdr"))))) {
			switch (0) {
				default:
				{
					ScratchServicesCtagsSymbolOutline* _tmp8_;
					_tmp8_ = scratch_services_ctags_symbol_outline_new (self);
					g_object_ref_sink (_tmp8_);
					_g_object_unref0 (self->priv->outline);
					self->priv->outline = (ScratchServicesSymbolOutline*) _tmp8_;
					break;
				}
			}
		}
		_tmp9_ = self->priv->outline;
		if (_tmp9_ != NULL) {
			GtkPaned* _tmp10_;
			ScratchServicesSymbolOutline* _tmp11_;
			GtkWidget* _tmp12_;
			GtkWidget* _tmp13_;
			_tmp10_ = self->priv->outline_widget_pane;
			_tmp11_ = self->priv->outline;
			_tmp12_ = scratch_services_symbol_outline_get_widget (_tmp11_);
			_tmp13_ = _tmp12_;
			gtk_paned_pack2 (_tmp10_, _tmp13_, FALSE, FALSE);
			_g_object_unref0 (_tmp13_);
			g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _____lambda50__gsource_func, g_object_ref (self), g_object_unref);
		}
	} else {
		gboolean _tmp14_ = FALSE;
		if (!show) {
			ScratchServicesSymbolOutline* _tmp15_;
			_tmp15_ = self->priv->outline;
			_tmp14_ = _tmp15_ != NULL;
		} else {
			_tmp14_ = FALSE;
		}
		if (_tmp14_) {
			GtkPaned* _tmp16_;
			guint _tmp17_;
			GQuark _tmp18_;
			GtkPaned* _tmp19_;
			GtkWidget* _tmp20_;
			_tmp16_ = self->priv->outline_widget_pane;
			g_signal_parse_name ("notify::position", G_TYPE_OBJECT, &_tmp17_, &_tmp18_, TRUE);
			g_signal_handlers_disconnect_matched ((GObject*) _tmp16_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp17_, _tmp18_, NULL, (GCallback) _scratch_services_document_sync_outline_width_g_object_notify, self);
			_tmp19_ = self->priv->outline_widget_pane;
			_tmp20_ = gtk_paned_get_child2 (_tmp19_);
			gtk_widget_destroy (_tmp20_);
			_g_object_unref0 (self->priv->outline);
			self->priv->outline = NULL;
		}
	}
}

static void
scratch_services_document_sync_outline_width (ScratchServicesDocument* self)
{
	gint width = 0;
	GtkPaned* _tmp0_;
	GtkPaned* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	ScratchWidgetsDocumentView* _tmp4_;
	ScratchWidgetsDocumentView* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->outline_widget_pane;
	_tmp1_ = self->priv->outline_widget_pane;
	_tmp2_ = gtk_paned_get_position (_tmp1_);
	_tmp3_ = _tmp2_;
	width = gtk_widget_get_allocated_width ((GtkWidget*) _tmp0_) - _tmp3_;
	_tmp4_ = scratch_services_document_get_doc_view (self);
	_tmp5_ = _tmp4_;
	_tmp6_ = scratch_widgets_document_view_get_outline_width (_tmp5_);
	_tmp7_ = _tmp6_;
	if (width != _tmp7_) {
		ScratchWidgetsDocumentView* _tmp8_;
		ScratchWidgetsDocumentView* _tmp9_;
		_tmp8_ = scratch_services_document_get_doc_view (self);
		_tmp9_ = _tmp8_;
		scratch_widgets_document_view_set_outline_width (_tmp9_, width);
	}
}

void
scratch_services_document_set_outline_width (ScratchServicesDocument* self,
                                             gint width)
{
	ScratchServicesSymbolOutline* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->outline;
	if (_tmp0_ != NULL) {
		gint aw = 0;
		GtkPaned* _tmp1_;
		GtkPaned* _tmp2_;
		_tmp1_ = self->priv->outline_widget_pane;
		aw = gtk_widget_get_allocated_width ((GtkWidget*) _tmp1_);
		_tmp2_ = self->priv->outline_widget_pane;
		gtk_paned_set_position (_tmp2_, aw - width);
	}
}

static void
scratch_services_document_unmounted_cb (ScratchServicesDocument* self)
{
	g_return_if_fail (self != NULL);
	g_warning ("Document.vala:1303: Folder containing the file was unmounted");
	self->priv->mounted = FALSE;
}

void
scratch_services_document_goto (ScratchServicesDocument* self,
                                gint line)
{
	ScratchWidgetsSourceView* text = NULL;
	ScratchWidgetsSourceView* _tmp0_;
	ScratchWidgetsSourceView* _tmp1_;
	GtkTextIter iter = {0};
	GtkTextBuffer* _tmp2_;
	GtkTextBuffer* _tmp3_;
	GtkTextIter _tmp4_ = {0};
	GtkTextBuffer* _tmp5_;
	GtkTextBuffer* _tmp6_;
	GtkTextIter _tmp7_;
	GtkTextIter _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	text = _tmp1_;
	_tmp2_ = gtk_text_view_get_buffer ((GtkTextView*) text);
	_tmp3_ = _tmp2_;
	gtk_text_buffer_get_iter_at_line (_tmp3_, &_tmp4_, line - 1);
	iter = _tmp4_;
	_tmp5_ = gtk_text_view_get_buffer ((GtkTextView*) text);
	_tmp6_ = _tmp5_;
	_tmp7_ = iter;
	gtk_text_buffer_place_cursor (_tmp6_, &_tmp7_);
	_tmp8_ = iter;
	gtk_text_view_scroll_to_iter ((GtkTextView*) text, &_tmp8_, 0.0, TRUE, 0.5, 0.5);
	_g_object_unref0 (text);
}

static void
scratch_services_document_strip_trailing_spaces (ScratchServicesDocument* self)
{
	gboolean _tmp0_ = FALSE;
	gchar* lang_id = NULL;
	ScratchWidgetsSourceView* _tmp4_;
	GtkSourceLanguage* _tmp5_;
	GtkSourceLanguage* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gboolean _tmp10_ = FALSE;
	const gchar* _tmp11_;
	GtkSourceBuffer* source_buffer = NULL;
	ScratchWidgetsSourceView* _tmp13_;
	GtkTextBuffer* _tmp14_;
	GtkTextBuffer* _tmp15_;
	GtkSourceBuffer* _tmp16_;
	GtkTextIter iter = {0};
	gint cursor_pos = 0;
	GtkSourceBuffer* _tmp17_;
	gint _tmp18_;
	gint _tmp19_;
	GtkSourceBuffer* _tmp20_;
	GtkTextIter _tmp21_ = {0};
	gint orig_line = 0;
	gint orig_offset = 0;
	gchar* text = NULL;
	GtkSourceBuffer* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar** lines = NULL;
	const gchar* _tmp25_;
	gchar** _tmp26_;
	gchar** _tmp27_;
	gint lines_length1;
	gint _lines_size_;
	gchar** _tmp28_;
	gint _tmp28__length1;
	gchar** _tmp29_;
	gint _tmp29__length1;
	GtkSourceBuffer* _tmp30_;
	GMatchInfo* info = NULL;
	GtkTextIter start_delete = {0};
	GtkTextIter end_delete = {0};
	GRegex* whitespace = NULL;
	GtkSourceBuffer* _tmp60_;
	GtkTextIter _tmp61_ = {0};
	GtkSourceBuffer* _tmp62_;
	GtkTextIter _tmp63_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	if (!self->priv->loaded) {
		_tmp0_ = TRUE;
	} else {
		ScratchWidgetsSourceView* _tmp1_;
		GtkSourceLanguage* _tmp2_;
		GtkSourceLanguage* _tmp3_;
		_tmp1_ = self->priv->_source_view;
		_tmp2_ = scratch_widgets_source_view_get_language (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp0_ = _tmp3_ == NULL;
	}
	if (_tmp0_) {
		return;
	}
	_tmp4_ = self->priv->_source_view;
	_tmp5_ = scratch_widgets_source_view_get_language (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = gtk_source_language_get_id (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_strdup (_tmp8_);
	lang_id = _tmp9_;
	_tmp11_ = lang_id;
	if (g_strcmp0 (_tmp11_, "markdown") == 0) {
		_tmp10_ = TRUE;
	} else {
		const gchar* _tmp12_;
		_tmp12_ = lang_id;
		_tmp10_ = g_strcmp0 (_tmp12_, "yaml") == 0;
	}
	if (_tmp10_) {
		_g_free0 (lang_id);
		return;
	}
	_tmp13_ = self->priv->_source_view;
	_tmp14_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, gtk_source_buffer_get_type (), GtkSourceBuffer));
	source_buffer = _tmp16_;
	_tmp17_ = source_buffer;
	g_object_get ((GtkTextBuffer*) _tmp17_, "cursor-position", &_tmp18_, NULL);
	_tmp19_ = _tmp18_;
	cursor_pos = _tmp19_;
	_tmp20_ = source_buffer;
	gtk_text_buffer_get_iter_at_offset ((GtkTextBuffer*) _tmp20_, &_tmp21_, cursor_pos);
	iter = _tmp21_;
	orig_line = gtk_text_iter_get_line (&iter);
	orig_offset = gtk_text_iter_get_line_offset (&iter);
	_tmp22_ = source_buffer;
	g_object_get ((GtkTextBuffer*) _tmp22_, "text", &_tmp23_, NULL);
	_tmp24_ = _tmp23_;
	text = _tmp24_;
	_tmp25_ = text;
	_tmp27_ = _tmp26_ = g_regex_split_simple ("[\\r\\n]", _tmp25_, 0, 0);
	lines = _tmp27_;
	lines_length1 = _vala_array_length (_tmp26_);
	_lines_size_ = lines_length1;
	_tmp28_ = lines;
	_tmp28__length1 = lines_length1;
	if (_tmp28__length1 == 0) {
		lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (text);
		_g_object_unref0 (source_buffer);
		_g_free0 (lang_id);
		return;
	}
	_tmp29_ = lines;
	_tmp29__length1 = lines_length1;
	_tmp30_ = source_buffer;
	if (_tmp29__length1 != gtk_text_buffer_get_line_count ((GtkTextBuffer*) _tmp30_)) {
		gchar** _tmp31_;
		gint _tmp31__length1;
		GtkSourceBuffer* _tmp32_;
		const gchar* _tmp33_;
		g_critical ("Document.vala:1343: Mismatch between line counts when stripping traili" \
"ng spaces, not continuing");
		_tmp31_ = lines;
		_tmp31__length1 = lines_length1;
		_tmp32_ = source_buffer;
		_tmp33_ = text;
		g_debug ("Document.vala:1344: lines.length %u, buffer lines %u \n %s", (guint) _tmp31__length1, (guint) gtk_text_buffer_get_line_count ((GtkTextBuffer*) _tmp32_), _tmp33_);
		lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (text);
		_g_object_unref0 (source_buffer);
		_g_free0 (lang_id);
		return;
	}
	{
		GRegex* _tmp34_ = NULL;
		GRegex* _tmp35_;
		GRegex* _tmp36_;
		_tmp35_ = g_regex_new ("[ \t]+$", 0, 0, &_inner_error0_);
		_tmp34_ = _tmp35_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			_g_regex_unref0 (whitespace);
			_g_match_info_unref0 (info);
			lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (text);
			_g_object_unref0 (source_buffer);
			_g_free0 (lang_id);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
		_tmp36_ = _tmp34_;
		_tmp34_ = NULL;
		_g_regex_unref0 (whitespace);
		whitespace = _tmp36_;
		_g_regex_unref0 (_tmp34_);
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		GError* e = NULL;
		GError* _tmp37_;
		const gchar* _tmp38_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp37_ = e;
		_tmp38_ = _tmp37_->message;
		g_critical ("Document.vala:1355: Error while building regex to replace trailing whi" \
"tespace: %s", _tmp38_);
		_g_error_free0 (e);
		_g_regex_unref0 (whitespace);
		_g_match_info_unref0 (info);
		lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (text);
		_g_object_unref0 (source_buffer);
		_g_free0 (lang_id);
		return;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_regex_unref0 (whitespace);
		_g_match_info_unref0 (info);
		lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (text);
		_g_object_unref0 (source_buffer);
		_g_free0 (lang_id);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	{
		gint line_no = 0;
		line_no = 0;
		{
			gboolean _tmp39_ = FALSE;
			_tmp39_ = TRUE;
			while (TRUE) {
				gchar** _tmp41_;
				gint _tmp41__length1;
				GRegex* _tmp42_;
				gchar** _tmp43_;
				gint _tmp43__length1;
				const gchar* _tmp44_;
				GMatchInfo* _tmp45_ = NULL;
				gboolean _tmp46_;
				if (!_tmp39_) {
					gint _tmp40_;
					_tmp40_ = line_no;
					line_no = _tmp40_ + 1;
				}
				_tmp39_ = FALSE;
				_tmp41_ = lines;
				_tmp41__length1 = lines_length1;
				if (!(line_no < _tmp41__length1)) {
					break;
				}
				_tmp42_ = whitespace;
				_tmp43_ = lines;
				_tmp43__length1 = lines_length1;
				_tmp44_ = _tmp43_[line_no];
				_tmp46_ = g_regex_match (_tmp42_, _tmp44_, 0, &_tmp45_);
				_g_match_info_unref0 (info);
				info = _tmp45_;
				if (_tmp46_) {
					GtkSourceBuffer* _tmp47_;
					GtkTextIter _tmp48_ = {0};
					GtkTextIter _tmp49_;
					GMatchInfo* _tmp50_;
					gchar* _tmp51_;
					gchar* _tmp52_;
					gint _tmp53_;
					gint _tmp54_;
					GtkSourceBuffer* _tmp55_;
					GtkTextIter _tmp56_;
					GtkSourceBuffer* _tmp57_;
					GtkSourceBuffer* _tmp58_;
					GtkSourceBuffer* _tmp59_;
					_tmp47_ = source_buffer;
					gtk_text_buffer_get_iter_at_line ((GtkTextBuffer*) _tmp47_, &_tmp48_, line_no);
					start_delete = _tmp48_;
					gtk_text_iter_forward_to_line_end (&start_delete);
					_tmp49_ = start_delete;
					end_delete = _tmp49_;
					_tmp50_ = info;
					_tmp51_ = g_match_info_fetch (_tmp50_, 0);
					_tmp52_ = _tmp51_;
					_tmp53_ = strlen (_tmp52_);
					_tmp54_ = _tmp53_;
					gtk_text_iter_backward_chars (&end_delete, _tmp54_);
					_g_free0 (_tmp52_);
					_tmp55_ = source_buffer;
					_tmp56_ = start_delete;
					if (gtk_source_buffer_iter_has_context_class (_tmp55_, &_tmp56_, "string")) {
						continue;
					}
					_tmp57_ = source_buffer;
					gtk_source_buffer_begin_not_undoable_action (_tmp57_);
					_tmp58_ = source_buffer;
					gtk_text_buffer_delete ((GtkTextBuffer*) _tmp58_, &start_delete, &end_delete);
					_tmp59_ = source_buffer;
					gtk_source_buffer_end_not_undoable_action (_tmp59_);
				}
			}
		}
	}
	_tmp60_ = source_buffer;
	gtk_text_buffer_get_iter_at_line_offset ((GtkTextBuffer*) _tmp60_, &_tmp61_, orig_line, orig_offset);
	iter = _tmp61_;
	_tmp62_ = source_buffer;
	_tmp63_ = iter;
	gtk_text_buffer_place_cursor ((GtkTextBuffer*) _tmp62_, &_tmp63_);
	_g_regex_unref0 (whitespace);
	_g_match_info_unref0 (info);
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (text);
	_g_object_unref0 (source_buffer);
	_g_free0 (lang_id);
}

static void
scratch_services_document_on_tab_loading_change (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	HdyTabPage* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_ = FALSE;
	HdyTabPage* _tmp5_;
	gboolean _tmp6_;
	gboolean _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = self->priv->_tab;
	_tmp2_ = hdy_tab_page_get_loading (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, !_tmp3_);
	_tmp5_ = self->priv->_tab;
	_tmp6_ = hdy_tab_page_get_loading (_tmp5_);
	_tmp7_ = _tmp6_;
	if (!_tmp7_) {
		ScratchServicesSymbolOutline* _tmp8_;
		_tmp8_ = self->priv->outline;
		_tmp4_ = _tmp8_ != NULL;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		ScratchServicesSymbolOutline* _tmp9_;
		_tmp9_ = self->priv->outline;
		scratch_services_symbol_outline_parse_symbols (_tmp9_);
	}
}

GSimpleActionGroup*
scratch_services_document_get_actions (ScratchServicesDocument* self)
{
	GSimpleActionGroup* result;
	GSimpleActionGroup* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_actions;
	result = _tmp0_;
	return result;
}

void
scratch_services_document_set_actions (ScratchServicesDocument* self,
                                       GSimpleActionGroup* value)
{
	GSimpleActionGroup* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_services_document_get_actions (self);
	if (old_value != value) {
		self->priv->_actions = value;
		g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_ACTIONS_PROPERTY]);
	}
}

HdyTabPage*
scratch_services_document_get_tab (ScratchServicesDocument* self)
{
	HdyTabPage* result;
	HdyTabPage* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_tab;
	result = _tmp0_;
	return result;
}

static void
scratch_services_document_set_tab (ScratchServicesDocument* self,
                                   HdyTabPage* value)
{
	HdyTabPage* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_services_document_get_tab (self);
	if (old_value != value) {
		self->priv->_tab = value;
		g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_TAB_PROPERTY]);
	}
}

gboolean
scratch_services_document_get_is_file_temporary (ScratchServicesDocument* self)
{
	gboolean result;
	GFile* _tmp0_;
	GFile* _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = scratch_services_document_get_file (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		GFile* _tmp2_;
		GFile* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		GApplication* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		gboolean _tmp9_;
		_tmp2_ = scratch_services_document_get_file (self);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_file_get_path (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_application_get_default ();
		_tmp7_ = scratch_application_get_data_home_folder_unsaved (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, SCRATCH_TYPE_APPLICATION, ScratchApplication));
		_tmp8_ = _tmp7_;
		_tmp9_ = g_str_has_prefix (_tmp5_, _tmp8_);
		_g_free0 (_tmp5_);
		result = _tmp9_;
		return result;
	} else {
		result = FALSE;
		return result;
	}
}

GFile*
scratch_services_document_get_file (ScratchServicesDocument* self)
{
	GFile* result;
	GtkSourceFile* _tmp0_;
	GFile* _tmp1_;
	GFile* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->source_file;
	_tmp1_ = gtk_source_file_get_location (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
scratch_services_document_set_file (ScratchServicesDocument* self,
                                    GFile* value)
{
	GtkSourceFile* _tmp0_;
	ScratchWidgetsSourceView* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->source_file;
	gtk_source_file_set_location (_tmp0_, value);
	_tmp1_ = self->priv->_source_view;
	scratch_widgets_source_view_set_location (_tmp1_, value);
	scratch_services_document_file_changed (self);
	_tmp2_ = scratch_services_document_get_basename (self);
	_tmp3_ = _tmp2_;
	scratch_services_document_set_title (self, _tmp3_);
	_g_free0 (_tmp3_);
	g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_FILE_PROPERTY]);
}

gchar*
scratch_services_document_get_project_path (ScratchServicesDocument* self)
{
	gchar* result;
	ScratchWidgetsSourceView* _tmp0_;
	ScratchFolderManagerProjectFolderItem* _tmp1_;
	ScratchFolderManagerProjectFolderItem* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = scratch_widgets_source_view_get_project (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != NULL) {
		ScratchWidgetsSourceView* _tmp3_;
		ScratchFolderManagerProjectFolderItem* _tmp4_;
		ScratchFolderManagerProjectFolderItem* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp3_ = self->priv->_source_view;
		_tmp4_ = scratch_widgets_source_view_get_project (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = scratch_folder_manager_item_get_path ((ScratchFolderManagerItem*) _tmp5_);
		_tmp7_ = _tmp6_;
		result = _tmp7_;
		return result;
	} else {
		gchar* _tmp8_;
		_tmp8_ = g_strdup ("");
		result = _tmp8_;
		return result;
	}
}

const gchar*
scratch_services_document_get_title (ScratchServicesDocument* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_title;
	result = _tmp0_;
	return result;
}

void
scratch_services_document_set_title (ScratchServicesDocument* self,
                                     const gchar* value)
{
	gchar* _tmp0_;
	HdyTabPage* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_title);
	self->priv->_title = _tmp0_;
	_tmp1_ = self->priv->_tab;
	if (_tmp1_ != NULL) {
		HdyTabPage* _tmp2_;
		HdyTabPage* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp2_ = self->priv->_tab;
		hdy_tab_page_set_title (_tmp2_, value);
		_tmp3_ = self->priv->_tab;
		_tmp4_ = scratch_services_document_get_tab_tooltip (self);
		_tmp5_ = _tmp4_;
		hdy_tab_page_set_tooltip (_tmp3_, _tmp5_);
		_g_free0 (_tmp5_);
	}
	g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_TITLE_PROPERTY]);
}

const gchar*
scratch_services_document_get_mime_type (ScratchServicesDocument* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	const gchar* _tmp11_;
	const gchar* _tmp13_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_mime_type;
	if (_tmp0_ == NULL) {
		{
			GFileInfo* info = NULL;
			GFile* _tmp1_;
			GFile* _tmp2_;
			GFileInfo* _tmp3_;
			gchar* content_type = NULL;
			GFileInfo* _tmp4_;
			gchar* _tmp5_;
			const gchar* _tmp6_;
			gchar* _tmp7_;
			const gchar* _tmp8_;
			_tmp1_ = scratch_services_document_get_file (self);
			_tmp2_ = _tmp1_;
			_tmp3_ = g_file_query_info (_tmp2_, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
			info = _tmp3_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp4_ = info;
			_tmp5_ = g_file_info_get_attribute_as_string (_tmp4_, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
			content_type = _tmp5_;
			_tmp6_ = content_type;
			_tmp7_ = g_content_type_get_mime_type (_tmp6_);
			_g_free0 (self->priv->_mime_type);
			self->priv->_mime_type = _tmp7_;
			_tmp8_ = self->priv->_mime_type;
			result = _tmp8_;
			_g_free0 (content_type);
			_g_object_unref0 (info);
			return result;
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp9_;
			const gchar* _tmp10_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp9_ = e;
			_tmp10_ = _tmp9_->message;
			g_debug ("Document.vala:100: %s", _tmp10_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	_tmp11_ = self->priv->_mime_type;
	if (_tmp11_ == NULL) {
		gchar* _tmp12_;
		_tmp12_ = g_strdup ("undefined");
		_g_free0 (self->priv->_mime_type);
		self->priv->_mime_type = _tmp12_;
	}
	_tmp13_ = self->priv->_mime_type;
	result = _tmp13_;
	return result;
}

GIcon*
scratch_services_document_get_icon (ScratchServicesDocument* self)
{
	GIcon* result;
	GIcon* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_icon;
	result = _tmp0_;
	return result;
}

void
scratch_services_document_set_icon (ScratchServicesDocument* self,
                                    GIcon* value)
{
	GIcon* _tmp0_;
	HdyTabPage* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_icon);
	self->priv->_icon = _tmp0_;
	_tmp1_ = self->priv->_tab;
	if (_tmp1_ != NULL) {
		HdyTabPage* _tmp2_;
		GIcon* _tmp3_;
		_tmp2_ = self->priv->_tab;
		_tmp3_ = self->priv->_icon;
		hdy_tab_page_set_icon (_tmp2_, _tmp3_);
	}
	g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_ICON_PROPERTY]);
}

gboolean
scratch_services_document_get_locked (ScratchServicesDocument* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_locked;
	return result;
}

void
scratch_services_document_set_locked (ScratchServicesDocument* self,
                                      gboolean value)
{
	GSimpleActionGroup* _tmp0_;
	GSimpleAction* _tmp1_;
	GSimpleAction* _tmp2_;
	gboolean _tmp3_;
	gboolean _tmp4_;
	ScratchWidgetsSourceView* _tmp6_;
	GtkTextBuffer* _tmp7_;
	GtkTextBuffer* _tmp8_;
	g_return_if_fail (self != NULL);
	self->priv->_locked = value;
	_tmp0_ = self->priv->_actions;
	_tmp1_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_SAVE, _tmp0_);
	_tmp2_ = _tmp1_;
	g_simple_action_set_enabled (_tmp2_, !value);
	_g_object_unref0 (_tmp2_);
	scratch_services_document_toggle_changed_handlers (self, !value);
	_tmp3_ = scratch_services_document_get_locked (self);
	_tmp4_ = _tmp3_;
	if (_tmp4_) {
		GIcon* _tmp5_;
		_tmp5_ = self->priv->locked_icon;
		scratch_services_document_set_icon (self, _tmp5_);
	} else {
		scratch_services_document_set_icon (self, NULL);
	}
	_tmp6_ = self->priv->_source_view;
	_tmp7_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp6_);
	_tmp8_ = _tmp7_;
	scratch_services_document_set_saved_status (self, !gtk_text_buffer_get_modified (_tmp8_));
	g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_LOCKED_PROPERTY]);
}

gboolean
scratch_services_document_get_loading (ScratchServicesDocument* self)
{
	gboolean result;
	gboolean _tmp0_ = FALSE;
	HdyTabPage* _tmp1_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->_tab;
	if (_tmp1_ == NULL) {
		_tmp0_ = FALSE;
	} else {
		HdyTabPage* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = self->priv->_tab;
		_tmp3_ = hdy_tab_page_get_loading (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	}
	result = _tmp0_;
	return result;
}

void
scratch_services_document_set_loading (ScratchServicesDocument* self,
                                       gboolean value)
{
	HdyTabPage* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_tab;
	if (_tmp0_ != NULL) {
		HdyTabPage* _tmp1_;
		_tmp1_ = self->priv->_tab;
		hdy_tab_page_set_loading (_tmp1_, value);
	}
	g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_LOADING_PROPERTY]);
}

gboolean
scratch_services_document_get_closing (ScratchServicesDocument* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_closing;
	return result;
}

static void
scratch_services_document_set_closing (ScratchServicesDocument* self,
                                       gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_services_document_get_closing (self);
	if (old_value != value) {
		self->priv->_closing = value;
		g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_CLOSING_PROPERTY]);
	}
}

ScratchWidgetsSourceView*
scratch_services_document_get_source_view (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* result;
	ScratchWidgetsSourceView* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_source_view;
	result = _tmp0_;
	return result;
}

static void
scratch_services_document_set_source_view (ScratchServicesDocument* self,
                                           ScratchWidgetsSourceView* value)
{
	ScratchWidgetsSourceView* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_services_document_get_source_view (self);
	if (old_value != value) {
		ScratchWidgetsSourceView* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_source_view);
		self->priv->_source_view = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_SOURCE_VIEW_PROPERTY]);
	}
}

static ScratchWidgetsDocumentView*
scratch_services_document_get_doc_view (ScratchServicesDocument* self)
{
	ScratchWidgetsDocumentView* result;
	GtkWidget* _tmp0_;
	ScratchWidgetsDocumentView* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp1_ = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, SCRATCH_TYPE_MAIN_WINDOW, ScratchMainWindow)->document_view;
	result = _tmp1_;
	return result;
}

static void
_scratch_services_document_set_minimap_g_settings_changed (GSettings* _sender,
                                                           const gchar* key,
                                                           gpointer self)
{
	scratch_services_document_set_minimap ((ScratchServicesDocument*) self);
}

static void
_scratch_services_document_set_strip_trailing_whitespace_g_settings_changed (GSettings* _sender,
                                                                             const gchar* key,
                                                                             gpointer self)
{
	scratch_services_document_set_strip_trailing_whitespace ((ScratchServicesDocument*) self);
}

static gboolean
_scratch_services_document___lambda131_ (ScratchServicesDocument* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	_tmp1_ = scratch_services_document_get_locked (self);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp3_ = scratch_services_document_get_is_file_temporary (self);
		_tmp4_ = _tmp3_;
		_tmp0_ = !_tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		scratch_services_document_check_undoable_actions (self);
		scratch_services_document_check_file_status (self, NULL, NULL);
	}
	result = FALSE;
	return result;
}

static gboolean
__scratch_services_document___lambda131__gtk_widget_focus_in_event (GtkWidget* _sender,
                                                                    GdkEventFocus* event,
                                                                    gpointer self)
{
	gboolean result;
	result = _scratch_services_document___lambda131_ ((ScratchServicesDocument*) self);
	return result;
}

static gboolean
_scratch_services_document___lambda132_ (ScratchServicesDocument* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	_tmp1_ = scratch_services_document_get_locked (self);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		GSettings* _tmp3_;
		_tmp3_ = scratch_settings;
		_tmp0_ = g_settings_get_boolean (_tmp3_, "autosave");
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		scratch_services_document_save_with_hold (self, FALSE, FALSE, NULL, NULL);
	}
	result = FALSE;
	return result;
}

static gboolean
__scratch_services_document___lambda132__gtk_widget_focus_out_event (GtkWidget* _sender,
                                                                     GdkEventFocus* event,
                                                                     gpointer self)
{
	gboolean result;
	result = _scratch_services_document___lambda132_ ((ScratchServicesDocument*) self);
	return result;
}

static void
_scratch_services_document___lambda133_ (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	GtkTextBuffer* _tmp1_;
	GtkTextBuffer* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	gboolean _tmp7_;
	if (!self->priv->loaded) {
		return;
	}
	_tmp0_ = self->priv->_source_view;
	_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp0_);
	_tmp2_ = _tmp1_;
	g_object_get (_tmp2_, "text", &_tmp3_, NULL);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	_tmp6_ = self->priv->last_save_content;
	_tmp7_ = g_strcmp0 (_tmp5_, _tmp6_) != 0;
	_g_free0 (_tmp5_);
	if (_tmp7_) {
		gboolean _tmp8_ = FALSE;
		gboolean _tmp9_;
		gboolean _tmp10_;
		self->saved = FALSE;
		_tmp9_ = scratch_services_document_get_locked (self);
		_tmp10_ = _tmp9_;
		if (_tmp10_) {
			_tmp8_ = TRUE;
		} else {
			GSettings* _tmp11_;
			_tmp11_ = scratch_settings;
			_tmp8_ = !g_settings_get_boolean (_tmp11_, "autosave");
		}
		if (_tmp8_) {
			scratch_services_document_set_saved_status (self, FALSE);
		}
	} else {
		scratch_services_document_set_saved_status (self, TRUE);
	}
}

static void
__scratch_services_document___lambda133__gtk_text_buffer_changed (GtkTextBuffer* _sender,
                                                                  gpointer self)
{
	_scratch_services_document___lambda133_ ((ScratchServicesDocument*) self);
}

static void
_scratch_services_document___lambda134_ (ScratchServicesDocument* self)
{
	self->priv->completion_shown = TRUE;
}

static void
__scratch_services_document___lambda134__gtk_source_completion_show (GtkSourceCompletion* _sender,
                                                                     gpointer self)
{
	_scratch_services_document___lambda134_ ((ScratchServicesDocument*) self);
}

static void
_scratch_services_document___lambda135_ (ScratchServicesDocument* self)
{
	self->priv->completion_shown = FALSE;
}

static void
__scratch_services_document___lambda135__gtk_source_completion_hide (GtkSourceCompletion* _sender,
                                                                     gpointer self)
{
	_scratch_services_document___lambda135_ ((ScratchServicesDocument*) self);
}

static gboolean
_scratch_services_document___lambda136_ (ScratchServicesDocument* self)
{
	ScratchWidgetsSourceView* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	_tmp0_ = self->priv->_source_view;
	g_object_get ((GtkWidget*) _tmp0_, "has-focus", &_tmp1_, NULL);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		ScratchWidgetsSourceView* _tmp3_;
		_tmp3_ = self->priv->_source_view;
		gtk_widget_grab_focus ((GtkWidget*) _tmp3_);
	}
}

static gboolean
__scratch_services_document___lambda136__gtk_widget_enter_notify_event (GtkWidget* _sender,
                                                                        GdkEventCrossing* event,
                                                                        gpointer self)
{
	gboolean result;
	result = _scratch_services_document___lambda136_ ((ScratchServicesDocument*) self);
	return result;
}

static gboolean
_scratch_services_document___lambda137_ (ScratchServicesDocument* self)
{
	GSettings* _tmp0_;
	_tmp0_ = scratch_settings;
	if (g_settings_get_boolean (_tmp0_, "strip-trailing-on-save")) {
		scratch_services_document_strip_trailing_spaces (self);
	}
}

static gboolean
__scratch_services_document___lambda137__gtk_widget_focus_out_event (GtkWidget* _sender,
                                                                     GdkEventFocus* event,
                                                                     gpointer self)
{
	gboolean result;
	result = _scratch_services_document___lambda137_ ((ScratchServicesDocument*) self);
	return result;
}

static GObject *
scratch_services_document_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ScratchServicesDocument * self;
	GThemedIcon* _tmp0_;
	GtkStack* _tmp1_;
	ScratchWidgetsSourceView* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	GtkScrolledWindow* _tmp4_ = NULL;
	GtkScrolledWindow* _tmp5_;
	ScratchWidgetsSourceView* _tmp6_;
	GtkSourceFile* _tmp7_;
	GtkSourceMap* _tmp8_;
	GtkPaned* _tmp9_;
	gboolean _tmp10_ = FALSE;
	PangoFontDescription* _tmp11_;
	GtkSourceMap* _tmp17_;
	ScratchWidgetsSourceView* _tmp18_;
	GSettings* _tmp19_;
	GSettings* _tmp20_;
	GtkGrid* source_grid = NULL;
	GtkGrid* _tmp21_ = NULL;
	GtkGrid* _tmp22_;
	GtkScrolledWindow* _tmp23_;
	GtkGrid* _tmp24_;
	GtkSourceMap* _tmp25_;
	GtkPaned* _tmp26_;
	GtkGrid* _tmp27_;
	GtkGrid* doc_grid = NULL;
	GtkGrid* _tmp28_;
	GtkGrid* _tmp29_;
	GtkGrid* _tmp30_;
	GtkPaned* _tmp31_;
	GtkGrid* _tmp32_;
	GtkStack* _tmp33_;
	GtkGrid* _tmp34_;
	ScratchWidgetsSourceView* _tmp35_;
	GtkTextBuffer* _tmp36_;
	GtkTextBuffer* _tmp37_;
	ScratchWidgetsSourceView* _tmp38_;
	ScratchWidgetsSourceView* _tmp39_;
	ScratchWidgetsSourceView* _tmp40_;
	GtkTextBuffer* _tmp41_;
	GtkTextBuffer* _tmp42_;
	ScratchWidgetsSourceView* _tmp43_;
	GtkSourceCompletion* _tmp44_;
	GtkSourceCompletion* _tmp45_;
	ScratchWidgetsSourceView* _tmp46_;
	GtkSourceCompletion* _tmp47_;
	GtkSourceCompletion* _tmp48_;
	ScratchWidgetsSourceView* _tmp49_;
	ScratchWidgetsSourceView* _tmp50_;
	GFile* _tmp51_;
	GFile* _tmp52_;
	GtkStack* _tmp53_;
	parent_class = G_OBJECT_CLASS (scratch_services_document_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_SERVICES_TYPE_DOCUMENT, ScratchServicesDocument);
	_tmp0_ = (GThemedIcon*) g_themed_icon_new ("emblem-readonly-symbolic");
	_g_object_unref0 (self->priv->locked_icon);
	self->priv->locked_icon = (GIcon*) _tmp0_;
	_tmp1_ = (GtkStack*) gtk_stack_new ();
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->main_stack);
	self->main_stack = _tmp1_;
	_tmp2_ = scratch_widgets_source_view_new ();
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	scratch_services_document_set_source_view (self, _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_set ((GtkWidget*) _tmp4_, "expand", TRUE, NULL);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->scroll);
	self->priv->scroll = _tmp4_;
	_tmp5_ = self->priv->scroll;
	_tmp6_ = self->priv->_source_view;
	gtk_container_add ((GtkContainer*) _tmp5_, (GtkWidget*) _tmp6_);
	_tmp7_ = gtk_source_file_new ();
	_g_object_unref0 (self->priv->source_file);
	self->priv->source_file = _tmp7_;
	_tmp8_ = (GtkSourceMap*) gtk_source_map_new ();
	g_object_ref_sink (_tmp8_);
	_g_object_unref0 (self->priv->source_map);
	self->priv->source_map = _tmp8_;
	_tmp9_ = (GtkPaned*) gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp9_);
	_g_object_unref0 (self->priv->outline_widget_pane);
	self->priv->outline_widget_pane = _tmp9_;
	_tmp11_ = scratch_services_document_builder_blocks_font;
	if (_tmp11_ != NULL) {
		PangoFontMap* _tmp12_;
		_tmp12_ = scratch_services_document_builder_font_map;
		_tmp10_ = _tmp12_ != NULL;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		GtkSourceMap* _tmp13_;
		PangoFontMap* _tmp14_;
		GtkSourceMap* _tmp15_;
		PangoFontDescription* _tmp16_;
		_tmp13_ = self->priv->source_map;
		_tmp14_ = scratch_services_document_builder_font_map;
		gtk_widget_set_font_map ((GtkWidget*) _tmp13_, _tmp14_);
		_tmp15_ = self->priv->source_map;
		_tmp16_ = scratch_services_document_builder_blocks_font;
		g_object_set (_tmp15_, "font-desc", _tmp16_, NULL);
	}
	_tmp17_ = self->priv->source_map;
	_tmp18_ = self->priv->_source_view;
	gtk_source_map_set_view (_tmp17_, (GtkSourceView*) _tmp18_);
	scratch_services_document_set_minimap (self);
	scratch_services_document_set_strip_trailing_whitespace (self);
	_tmp19_ = scratch_settings;
	g_signal_connect_object (_tmp19_, "changed::show-mini-map", (GCallback) _scratch_services_document_set_minimap_g_settings_changed, self, 0);
	_tmp20_ = scratch_settings;
	g_signal_connect_object (_tmp20_, "changed::strip-trailing-on-save", (GCallback) _scratch_services_document_set_strip_trailing_whitespace_g_settings_changed, self, 0);
	_tmp21_ = (GtkGrid*) gtk_grid_new ();
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp21_, GTK_ORIENTATION_HORIZONTAL);
	gtk_grid_set_column_homogeneous (_tmp21_, FALSE);
	g_object_ref_sink (_tmp21_);
	source_grid = _tmp21_;
	_tmp22_ = source_grid;
	_tmp23_ = self->priv->scroll;
	gtk_container_add ((GtkContainer*) _tmp22_, (GtkWidget*) _tmp23_);
	_tmp24_ = source_grid;
	_tmp25_ = self->priv->source_map;
	gtk_container_add ((GtkContainer*) _tmp24_, (GtkWidget*) _tmp25_);
	_tmp26_ = self->priv->outline_widget_pane;
	_tmp27_ = source_grid;
	gtk_paned_pack1 (_tmp26_, (GtkWidget*) _tmp27_, TRUE, FALSE);
	_tmp28_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp28_);
	doc_grid = _tmp28_;
	_tmp29_ = doc_grid;
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp29_, GTK_ORIENTATION_VERTICAL);
	_tmp30_ = doc_grid;
	_tmp31_ = self->priv->outline_widget_pane;
	gtk_container_add ((GtkContainer*) _tmp30_, (GtkWidget*) _tmp31_);
	_tmp32_ = doc_grid;
	gtk_widget_show_all ((GtkWidget*) _tmp32_);
	_tmp33_ = self->main_stack;
	_tmp34_ = doc_grid;
	gtk_stack_add_named (_tmp33_, (GtkWidget*) _tmp34_, "content");
	_tmp35_ = self->priv->_source_view;
	_tmp36_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp35_);
	_tmp37_ = _tmp36_;
	gtk_text_buffer_create_tag (_tmp37_, "highlight_search_all", "background", "yellow", NULL, NULL);
	_tmp38_ = self->priv->_source_view;
	g_signal_connect_object ((GtkWidget*) _tmp38_, "focus-in-event", (GCallback) __scratch_services_document___lambda131__gtk_widget_focus_in_event, self, 0);
	_tmp39_ = self->priv->_source_view;
	g_signal_connect_object ((GtkWidget*) _tmp39_, "focus-out-event", (GCallback) __scratch_services_document___lambda132__gtk_widget_focus_out_event, self, 0);
	_tmp40_ = self->priv->_source_view;
	_tmp41_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp40_);
	_tmp42_ = _tmp41_;
	g_signal_connect_object (_tmp42_, "changed", (GCallback) __scratch_services_document___lambda133__gtk_text_buffer_changed, self, 0);
	_tmp43_ = self->priv->_source_view;
	_tmp44_ = gtk_source_view_get_completion ((GtkSourceView*) _tmp43_);
	_tmp45_ = _tmp44_;
	g_signal_connect_object (_tmp45_, "show", (GCallback) __scratch_services_document___lambda134__gtk_source_completion_show, self, 0);
	_tmp46_ = self->priv->_source_view;
	_tmp47_ = gtk_source_view_get_completion ((GtkSourceView*) _tmp46_);
	_tmp48_ = _tmp47_;
	g_signal_connect_object (_tmp48_, "hide", (GCallback) __scratch_services_document___lambda135__gtk_source_completion_hide, self, 0);
	_tmp49_ = self->priv->_source_view;
	g_signal_connect_object ((GtkWidget*) _tmp49_, "enter-notify-event", (GCallback) __scratch_services_document___lambda136__gtk_widget_enter_notify_event, self, 0);
	_tmp50_ = self->priv->_source_view;
	g_signal_connect_object ((GtkWidget*) _tmp50_, "focus-out-event", (GCallback) __scratch_services_document___lambda137__gtk_widget_focus_out_event, self, 0);
	_tmp51_ = scratch_services_document_get_file (self);
	_tmp52_ = _tmp51_;
	self->priv->loaded = _tmp52_ == NULL;
	_tmp53_ = self->main_stack;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp53_);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (doc_grid);
	_g_object_unref0 (source_grid);
	return obj;
}

static void
_vala_PangoFontDescription_free (PangoFontDescription* self)
{
	g_boxed_free (pango_font_description_get_type (), self);
}

static void
scratch_services_document_class_init (ScratchServicesDocumentClass * klass,
                                      gpointer klass_data)
{
	gchar* fontpath = NULL;
	gchar* _tmp0_;
	FcConfig* config = NULL;
	FcConfig* _tmp1_;
	FcConfig* _tmp2_;
	const gchar* _tmp3_;
	scratch_services_document_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ScratchServicesDocument_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_scratch_services_document_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_scratch_services_document_set_property;
	G_OBJECT_CLASS (klass)->constructor = scratch_services_document_constructor;
	G_OBJECT_CLASS (klass)->finalize = scratch_services_document_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_ACTIONS_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_ACTIONS_PROPERTY] = g_param_spec_object ("actions", "actions", "actions", g_simple_action_group_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_TAB_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_TAB_PROPERTY] = g_param_spec_object ("tab", "tab", "tab", hdy_tab_page_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_IS_FILE_TEMPORARY_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_IS_FILE_TEMPORARY_PROPERTY] = g_param_spec_boolean ("is-file-temporary", "is-file-temporary", "is-file-temporary", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_FILE_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_FILE_PROPERTY] = g_param_spec_object ("file", "file", "file", g_file_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_PROJECT_PATH_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_PROJECT_PATH_PROPERTY] = g_param_spec_string ("project-path", "project-path", "project-path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_TITLE_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_TITLE_PROPERTY] = g_param_spec_string ("title", "title", "title", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_MIME_TYPE_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_MIME_TYPE_PROPERTY] = g_param_spec_string ("mime-type", "mime-type", "mime-type", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_ICON_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_ICON_PROPERTY] = g_param_spec_object ("icon", "icon", "icon", g_icon_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_LOCKED_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_LOCKED_PROPERTY] = g_param_spec_boolean ("locked", "locked", "locked", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_LOADING_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_LOADING_PROPERTY] = g_param_spec_boolean ("loading", "loading", "loading", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_CLOSING_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_CLOSING_PROPERTY] = g_param_spec_boolean ("closing", "closing", "closing", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_SERVICES_DOCUMENT_SOURCE_VIEW_PROPERTY, scratch_services_document_properties[SCRATCH_SERVICES_DOCUMENT_SOURCE_VIEW_PROPERTY] = g_param_spec_object ("source-view", "source-view", "source-view", SCRATCH_WIDGETS_TYPE_SOURCE_VIEW, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	scratch_services_document_signals[SCRATCH_SERVICES_DOCUMENT_DOC_OPENED_SIGNAL] = g_signal_new ("doc-opened", SCRATCH_SERVICES_TYPE_DOCUMENT, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	scratch_services_document_signals[SCRATCH_SERVICES_DOCUMENT_DOC_CLOSED_SIGNAL] = g_signal_new ("doc-closed", SCRATCH_SERVICES_TYPE_DOCUMENT, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	_tmp0_ = g_build_filename (CONSTANTS_DATADIR, CONSTANTS_PROJECT_NAME, "fonts", "BuilderBlocks.ttf", NULL);
	fontpath = _tmp0_;
	_tmp1_ = FcInitLoadConfigAndFonts ();
	config = _tmp1_;
	_tmp2_ = config;
	_tmp3_ = fontpath;
	if (!FcConfigAppFontAddFile (_tmp2_, _tmp3_)) {
		g_warning ("Document.vala:209: Unable to load Builder Blocks font, SourceView map " \
"might not be pretty");
	} else {
		PangoFontMap* _tmp4_;
		PangoFontMap* _tmp5_;
		FcConfig* _tmp6_;
		PangoFontDescription* _tmp7_;
		_tmp4_ = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
		_g_object_unref0 (scratch_services_document_builder_font_map);
		scratch_services_document_builder_font_map = _tmp4_;
		_tmp5_ = scratch_services_document_builder_font_map;
		_tmp6_ = config;
		pango_fc_font_map_set_config (_tmp5_, _tmp6_);
		_tmp7_ = pango_font_description_from_string ("Builder Blocks 1");
		__vala_PangoFontDescription_free0 (scratch_services_document_builder_blocks_font);
		scratch_services_document_builder_blocks_font = _tmp7_;
	}
	_g_free0 (fontpath);
}

static void
scratch_services_document_instance_init (ScratchServicesDocument * self,
                                         gpointer klass)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	self->priv = scratch_services_document_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->_title = _tmp0_;
	self->priv->_mime_type = NULL;
	self->priv->_icon = NULL;
	self->priv->_locked = TRUE;
	self->priv->_closing = FALSE;
	self->priv->outline = NULL;
	_tmp1_ = g_strdup ("");
	self->original_content = _tmp1_;
	_tmp2_ = g_strdup ("");
	self->priv->last_save_content = _tmp2_;
	self->saved = TRUE;
	self->priv->completion_shown = FALSE;
	self->priv->onchange_handler_id = (gulong) 0;
	self->priv->loaded = FALSE;
	self->priv->mounted = TRUE;
	self->priv->load_timout_id = (guint) 0;
	g_rec_mutex_init (&self->priv->__lock_is_saving);
	self->priv->is_saving = FALSE;
	g_rec_mutex_init (&self->priv->__lock_source_view);
}

static void
scratch_services_document_finalize (GObject * obj)
{
	ScratchServicesDocument * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_SERVICES_TYPE_DOCUMENT, ScratchServicesDocument);
	_g_object_unref0 (self->priv->source_file);
	_g_free0 (self->priv->_title);
	_g_free0 (self->priv->_mime_type);
	_g_object_unref0 (self->priv->_icon);
	_g_object_unref0 (self->main_stack);
	_g_object_unref0 (self->priv->_source_view);
	_g_object_unref0 (self->priv->outline);
	_g_free0 (self->original_content);
	_g_free0 (self->priv->last_save_content);
	_g_object_unref0 (self->priv->scroll);
	_g_object_unref0 (self->priv->source_map);
	_g_object_unref0 (self->priv->outline_widget_pane);
	_g_object_unref0 (self->priv->save_cancellable);
	_g_object_unref0 (self->priv->load_cancellable);
	_g_object_unref0 (self->priv->mount);
	_g_object_unref0 (self->priv->locked_icon);
	g_rec_mutex_clear (&self->priv->__lock_is_saving);
	g_rec_mutex_clear (&self->priv->__lock_source_view);
	G_OBJECT_CLASS (scratch_services_document_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
scratch_services_document_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchServicesDocumentClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_services_document_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchServicesDocument), 0, (GInstanceInitFunc) scratch_services_document_instance_init, NULL };
	GType scratch_services_document_type_id;
	scratch_services_document_type_id = g_type_register_static (gtk_box_get_type (), "ScratchServicesDocument", &g_define_type_info, G_TYPE_FLAG_NONE);
	ScratchServicesDocument_private_offset = g_type_add_instance_private (scratch_services_document_type_id, sizeof (ScratchServicesDocumentPrivate));
	return scratch_services_document_type_id;
}

GType
scratch_services_document_get_type (void)
{
	static gsize scratch_services_document_type_id__once = 0;
	if (g_once_init_enter (&scratch_services_document_type_id__once)) {
		GType scratch_services_document_type_id;
		scratch_services_document_type_id = scratch_services_document_get_type_once ();
		g_once_init_leave (&scratch_services_document_type_id__once, scratch_services_document_type_id);
	}
	return scratch_services_document_type_id__once;
}

static void
_vala_scratch_services_document_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	ScratchServicesDocument * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_SERVICES_TYPE_DOCUMENT, ScratchServicesDocument);
	switch (property_id) {
		case SCRATCH_SERVICES_DOCUMENT_ACTIONS_PROPERTY:
		g_value_set_object (value, scratch_services_document_get_actions (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_TAB_PROPERTY:
		g_value_set_object (value, scratch_services_document_get_tab (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_IS_FILE_TEMPORARY_PROPERTY:
		g_value_set_boolean (value, scratch_services_document_get_is_file_temporary (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_FILE_PROPERTY:
		g_value_set_object (value, scratch_services_document_get_file (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_PROJECT_PATH_PROPERTY:
		g_value_take_string (value, scratch_services_document_get_project_path (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_TITLE_PROPERTY:
		g_value_set_string (value, scratch_services_document_get_title (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_MIME_TYPE_PROPERTY:
		g_value_set_string (value, scratch_services_document_get_mime_type (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_ICON_PROPERTY:
		g_value_set_object (value, scratch_services_document_get_icon (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_LOCKED_PROPERTY:
		g_value_set_boolean (value, scratch_services_document_get_locked (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_LOADING_PROPERTY:
		g_value_set_boolean (value, scratch_services_document_get_loading (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_CLOSING_PROPERTY:
		g_value_set_boolean (value, scratch_services_document_get_closing (self));
		break;
		case SCRATCH_SERVICES_DOCUMENT_SOURCE_VIEW_PROPERTY:
		g_value_set_object (value, scratch_services_document_get_source_view (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_scratch_services_document_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	ScratchServicesDocument * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_SERVICES_TYPE_DOCUMENT, ScratchServicesDocument);
	switch (property_id) {
		case SCRATCH_SERVICES_DOCUMENT_ACTIONS_PROPERTY:
		scratch_services_document_set_actions (self, g_value_get_object (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_TAB_PROPERTY:
		scratch_services_document_set_tab (self, g_value_get_object (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_FILE_PROPERTY:
		scratch_services_document_set_file (self, g_value_get_object (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_TITLE_PROPERTY:
		scratch_services_document_set_title (self, g_value_get_string (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_ICON_PROPERTY:
		scratch_services_document_set_icon (self, g_value_get_object (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_LOCKED_PROPERTY:
		scratch_services_document_set_locked (self, g_value_get_boolean (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_LOADING_PROPERTY:
		scratch_services_document_set_loading (self, g_value_get_boolean (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_CLOSING_PROPERTY:
		scratch_services_document_set_closing (self, g_value_get_boolean (value));
		break;
		case SCRATCH_SERVICES_DOCUMENT_SOURCE_VIEW_PROPERTY:
		scratch_services_document_set_source_view (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

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

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

