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

/*
* Copyright 2017–2020 elementary, Inc. <https://elementary.io>
*           2011–2013 Mario Guerriero <mefrio.g@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#include "codecore.h"
#include <glib.h>
#include <gtk/gtk.h>
#include <granite.h>
#include <gio/gio.h>
#include <gdk/gdk.h>
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <handy.h>
#include <libpeas.h>
#include <float.h>
#include <math.h>
#include <gtksourceview/gtksource.h>
#include <vte/vte.h>
#include <cairo-gobject.h>
#include <glib-unix.h>
#include <signal.h>

#define SCRATCH_MAIN_WINDOW_MAX_SEARCH_TEXT_LENGTH ((guint) 255)
#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_MAIN_WINDOW_0_PROPERTY,
	SCRATCH_MAIN_WINDOW_APP_PROPERTY,
	SCRATCH_MAIN_WINDOW_RESTORE_DOCS_PROPERTY,
	SCRATCH_MAIN_WINDOW_RESTORE_OVERRIDE_PROPERTY,
	SCRATCH_MAIN_WINDOW_DEFAULT_GLOBALSEARCH_PATH_PROPERTY,
	SCRATCH_MAIN_WINDOW_ACTIONS_PROPERTY,
	SCRATCH_MAIN_WINDOW_NUM_PROPERTIES
};
static GParamSpec* scratch_main_window_properties[SCRATCH_MAIN_WINDOW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block2Data Block2Data;
typedef void (*ScratchMainWindowHookFunc) (gpointer user_data);
typedef struct _Block3Data Block3Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_variant_iter_free0(var) ((var == NULL) ? NULL : (var = (g_variant_iter_free (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
typedef struct _ScratchMainWindowRestoreOpenedDocumentsData ScratchMainWindowRestoreOpenedDocumentsData;
typedef struct _ScratchMainWindowOpenDocumentData ScratchMainWindowOpenDocumentData;
typedef struct _ScratchMainWindowOpenDocumentAtSelectedRangeData ScratchMainWindowOpenDocumentAtSelectedRangeData;
typedef struct _ScratchMainWindowCheckUnsavedChangesData ScratchMainWindowCheckUnsavedChangesData;
typedef struct _Block4Data Block4Data;
typedef struct _Block5Data Block5Data;
typedef struct _Block6Data Block6Data;
typedef struct _Block7Data Block7Data;
typedef struct _Block8Data Block8Data;

struct _ScratchMainWindowPrivate {
	ScratchApplication* _app;
	gboolean _restore_docs;
	RestoreOverride* _restore_override;
	CodeWelcomeView* welcome_view;
	CodeTerminal* terminal;
	ScratchFolderManagerFileView* folder_manager_view;
	ScratchServicesDocumentManager* document_manager;
	GtkEventControllerKey* key_controller;
	ScratchServicesPluginsManager* plugins;
	GraniteDialog* preferences_dialog;
	GtkPaned* hp1;
	GtkPaned* vp;
	GtkStack* content_stack;
	GSimpleActionGroup* _actions;
	gulong color_scheme_listener_handler_id;
	ScratchServicesGitManager* git_manager;
};

struct _Block1Data {
	int _ref_count_;
	ScratchMainWindow* self;
	GtkSettings* gtk_settings;
	GraniteSettings* granite_settings;
};

struct _Block2Data {
	int _ref_count_;
	ScratchMainWindow* self;
	GtkGrid* view_grid;
};

struct _Block3Data {
	int _ref_count_;
	ScratchMainWindow* self;
	ScratchMainWindowHookFunc hook_func;
	gpointer hook_func_target;
	GDestroyNotify hook_func_target_destroy_notify;
};

struct _ScratchMainWindowRestoreOpenedDocumentsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchMainWindow* self;
	GFile* focused_file;
	GSettings* _tmp0_;
	GVariant* doc_infos;
	GSettings* _tmp1_;
	GVariant* _tmp2_;
	GVariantIter* doc_info_iter;
	GVariant* _tmp3_;
	GVariantIter* _tmp4_;
	gchar* focused_uri;
	GSettings* _tmp5_;
	gchar* _tmp6_;
	gchar* uri;
	gint pos;
	gboolean was_restore_overriden;
	GVariantIter* _tmp7_;
	gchar* _tmp8_;
	gint _tmp9_;
	gboolean _tmp10_;
	const gchar* _tmp11_;
	GFile* file;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gboolean _tmp15_;
	const gchar* _tmp16_;
	GFile* _tmp17_;
	const gchar* _tmp18_;
	GFile* _tmp19_;
	GFile* _tmp20_;
	gboolean is_focused;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	GFile* _tmp23_;
	GFile* _tmp24_;
	ScratchServicesDocument* doc;
	GSimpleActionGroup* _tmp25_;
	GFile* _tmp26_;
	ScratchServicesDocument* _tmp27_;
	gboolean _tmp28_;
	ScratchServicesDocument* _tmp29_;
	ScratchServicesDocument* _tmp30_;
	gboolean _tmp31_;
	gboolean _tmp32_;
	gboolean _tmp33_;
	RestoreOverride* _tmp34_;
	GFile* _tmp35_;
	gchar* _tmp36_;
	gchar* _tmp37_;
	RestoreOverride* _tmp38_;
	GFile* _tmp39_;
	GFile* _tmp40_;
	gchar* _tmp41_;
	gchar* _tmp42_;
	ScratchServicesDocument* _tmp43_;
	RestoreOverride* _tmp44_;
	SelectionRange _tmp45_;
	SelectionRange _tmp46_;
	gboolean _tmp47_;
	ScratchServicesDocument* _tmp48_;
	ScratchWidgetsDocumentView* _tmp49_;
	ScratchWidgetsDocumentView* _tmp50_;
	GFile* _tmp51_;
	ScratchFolderManagerFileView* _tmp52_;
	GFile* _tmp53_;
	gchar* _tmp54_;
	gchar* _tmp55_;
};

struct _ScratchMainWindowOpenDocumentData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchMainWindow* self;
	ScratchServicesDocument* doc;
	gboolean focus;
	gint cursor_position;
	ScratchFolderManagerProjectFolderItem* project;
	ScratchFolderManagerFileView* _tmp0_;
	GFile* _tmp1_;
	GFile* _tmp2_;
	ScratchFolderManagerProjectFolderItem* _tmp3_;
	ScratchWidgetsSourceView* _tmp4_;
	ScratchWidgetsSourceView* _tmp5_;
	ScratchWidgetsDocumentView* _tmp6_;
};

struct _ScratchMainWindowOpenDocumentAtSelectedRangeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchMainWindow* self;
	ScratchServicesDocument* doc;
	gboolean focus;
	SelectionRange range;
	gboolean is_override;
	gboolean _tmp0_;
	RestoreOverride* _tmp1_;
	ScratchWidgetsSourceView* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	ScratchFolderManagerFileView* _tmp4_;
	GFile* _tmp5_;
	GFile* _tmp6_;
	ScratchFolderManagerProjectFolderItem* _tmp7_;
	ScratchFolderManagerProjectFolderItem* _tmp8_;
	ScratchWidgetsDocumentView* _tmp9_;
	SelectionRange _tmp10_;
};

struct _ScratchMainWindowCheckUnsavedChangesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	ScratchMainWindow* self;
	gboolean app_closing;
	gboolean result;
	ScratchWidgetsDocumentView* _tmp0_;
	ScratchWidgetsDocumentView* _tmp1_;
	GList* _tmp2_;
	GList* doc_collection;
	GList* doc_it;
	ScratchServicesDocument* _tmp3_;
	ScratchServicesDocument* doc;
	ScratchServicesDocument* _tmp4_;
	ScratchWidgetsDocumentView* _tmp5_;
	ScratchServicesDocument* _tmp6_;
};

struct _Block4Data {
	int _ref_count_;
	ScratchMainWindow* self;
	ScratchDialogsCloneRepositoryDialog* clone_dialog;
};

struct _Block5Data {
	int _ref_count_;
	Block4Data * _data4_;
	gchar* uri;
	gchar* target;
};

struct _Block6Data {
	int _ref_count_;
	Block5Data * _data5_;
	GraniteMessageDialog* message_dialog;
};

struct _Block7Data {
	int _ref_count_;
	ScratchMainWindow* self;
	gchar* close_path;
};

struct _Block8Data {
	int _ref_count_;
	ScratchMainWindow* self;
	gchar* project_path;
	gboolean make_restorable;
};

static gint ScratchMainWindow_private_offset;
static gpointer scratch_main_window_parent_class = NULL;
GeeMultiMap* scratch_main_window_action_accelerators = NULL;
static gchar* scratch_main_window_base_title;
static gchar* scratch_main_window_base_title = NULL;

static void scratch_main_window_action_clone_repo (ScratchMainWindow* self,
                                            GSimpleAction* action,
                                            GVariant* param);
static void _scratch_main_window_action_clone_repo_gsimple_action_activate_callback (GSimpleAction* action,
                                                                              GVariant* parameter,
                                                                              gpointer self);
static void scratch_main_window_action_find (ScratchMainWindow* self,
                                      GSimpleAction* action,
                                      GVariant* param);
static void _scratch_main_window_action_find_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self);
static void scratch_main_window_action_find_next (ScratchMainWindow* self);
static void _scratch_main_window_action_find_next_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self);
static void scratch_main_window_action_find_previous (ScratchMainWindow* self);
static void _scratch_main_window_action_find_previous_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self);
static void scratch_main_window_action_find_global (ScratchMainWindow* self,
                                             GSimpleAction* action,
                                             GVariant* param);
static void _scratch_main_window_action_find_global_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self);
static void scratch_main_window_action_open (ScratchMainWindow* self);
static void _scratch_main_window_action_open_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self);
static void scratch_main_window_action_open_folder (ScratchMainWindow* self,
                                             GSimpleAction* action,
                                             GVariant* param);
static void _scratch_main_window_action_open_folder_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self);
static void scratch_main_window_action_open_project (ScratchMainWindow* self,
                                              GSimpleAction* action);
static void _scratch_main_window_action_open_project_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                GVariant* parameter,
                                                                                gpointer self);
static void scratch_main_window_action_collapse_all_folders (ScratchMainWindow* self);
static void _scratch_main_window_action_collapse_all_folders_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                        GVariant* parameter,
                                                                                        gpointer self);
static void scratch_main_window_action_preferences (ScratchMainWindow* self);
static void _scratch_main_window_action_preferences_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self);
static void scratch_main_window_action_revert (ScratchMainWindow* self);
static void _scratch_main_window_action_revert_gsimple_action_activate_callback (GSimpleAction* action,
                                                                          GVariant* parameter,
                                                                          gpointer self);
static void scratch_main_window_action_save (ScratchMainWindow* self);
static void _scratch_main_window_action_save_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self);
static void scratch_main_window_action_save_as (ScratchMainWindow* self);
static void _scratch_main_window_action_save_as_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self);
static void scratch_main_window_action_toggle_show_find (ScratchMainWindow* self);
static void _scratch_main_window_action_toggle_show_find_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                    GVariant* parameter,
                                                                                    gpointer self);
static void scratch_main_window_action_templates (ScratchMainWindow* self);
static void _scratch_main_window_action_templates_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self);
static void scratch_main_window_action_go_to (ScratchMainWindow* self);
static void _scratch_main_window_action_go_to_gsimple_action_activate_callback (GSimpleAction* action,
                                                                         GVariant* parameter,
                                                                         gpointer self);
static void scratch_main_window_action_sort_lines (ScratchMainWindow* self);
static void _scratch_main_window_action_sort_lines_gsimple_action_activate_callback (GSimpleAction* action,
                                                                              GVariant* parameter,
                                                                              gpointer self);
static void scratch_main_window_action_new_tab (ScratchMainWindow* self);
static void _scratch_main_window_action_new_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self);
static void scratch_main_window_action_new_tab_from_clipboard (ScratchMainWindow* self);
static void _scratch_main_window_action_new_tab_from_clipboard_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                          GVariant* parameter,
                                                                                          gpointer self);
static void scratch_main_window_action_duplicate_tab (ScratchMainWindow* self);
static void _scratch_main_window_action_duplicate_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self);
static void scratch_main_window_action_undo (ScratchMainWindow* self);
static void _scratch_main_window_action_undo_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self);
static void scratch_main_window_action_redo (ScratchMainWindow* self);
static void _scratch_main_window_action_redo_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self);
static void scratch_main_window_action_show_replace (ScratchMainWindow* self,
                                              GSimpleAction* action);
static void _scratch_main_window_action_show_replace_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                GVariant* parameter,
                                                                                gpointer self);
static void scratch_main_window_action_to_lower_case (ScratchMainWindow* self);
static void _scratch_main_window_action_to_lower_case_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self);
static void scratch_main_window_action_to_upper_case (ScratchMainWindow* self);
static void _scratch_main_window_action_to_upper_case_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self);
static void scratch_main_window_action_duplicate (ScratchMainWindow* self);
static void _scratch_main_window_action_duplicate_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self);
static void scratch_main_window_action_fullscreen (ScratchMainWindow* self);
static void _scratch_main_window_action_fullscreen_gsimple_action_activate_callback (GSimpleAction* action,
                                                                              GVariant* parameter,
                                                                              gpointer self);
static void scratch_main_window_action_quit_app (ScratchMainWindow* self);
static void _scratch_main_window_action_quit_app_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self);
static void scratch_main_window_action_close_window (ScratchMainWindow* self);
static void _scratch_main_window_action_close_window_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                GVariant* parameter,
                                                                                gpointer self);
static void scratch_main_window_action_set_default_zoom (ScratchMainWindow* self);
static void _scratch_main_window_action_set_default_zoom_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                    GVariant* parameter,
                                                                                    gpointer self);
static void _scratch_main_window_action_zoom_in_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self);
static void _scratch_main_window_action_zoom_out_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self);
static void scratch_main_window_action_toggle_comment (ScratchMainWindow* self);
static void _scratch_main_window_action_toggle_comment_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                  GVariant* parameter,
                                                                                  gpointer self);
static void scratch_main_window_action_toggle_sidebar (ScratchMainWindow* self,
                                                GSimpleAction* action);
static void _scratch_main_window_action_toggle_sidebar_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                  GVariant* parameter,
                                                                                  gpointer self);
static void scratch_main_window_action_focus_sidebar (ScratchMainWindow* self);
static void _scratch_main_window_action_focus_sidebar_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self);
static void scratch_main_window_action_focus_document (ScratchMainWindow* self);
static void _scratch_main_window_action_focus_document_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                  GVariant* parameter,
                                                                                  gpointer self);
static void scratch_main_window_action_toggle_terminal (ScratchMainWindow* self);
static void _scratch_main_window_action_toggle_terminal_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                   GVariant* parameter,
                                                                                   gpointer self);
static void scratch_main_window_action_open_in_terminal (ScratchMainWindow* self,
                                                  GSimpleAction* action,
                                                  GVariant* param);
static void _scratch_main_window_action_open_in_terminal_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                    GVariant* parameter,
                                                                                    gpointer self);
static void scratch_main_window_action_set_active_project (ScratchMainWindow* self,
                                                    GSimpleAction* action,
                                                    GVariant* param);
static void _scratch_main_window_action_set_active_project_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                      GVariant* parameter,
                                                                                      gpointer self);
static void scratch_main_window_action_toggle_outline (ScratchMainWindow* self,
                                                GSimpleAction* action);
static void _scratch_main_window_action_toggle_outline_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                  GVariant* parameter,
                                                                                  gpointer self);
static void scratch_main_window_action_next_tab (ScratchMainWindow* self);
static void _scratch_main_window_action_next_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self);
static void scratch_main_window_action_previous_tab (ScratchMainWindow* self);
static void _scratch_main_window_action_previous_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                GVariant* parameter,
                                                                                gpointer self);
static void scratch_main_window_action_clear_lines (ScratchMainWindow* self);
static void _scratch_main_window_action_clear_lines_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self);
static void scratch_main_window_action_branch_actions (ScratchMainWindow* self,
                                                GSimpleAction* action,
                                                GVariant* param);
static void _scratch_main_window_action_branch_actions_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                  GVariant* parameter,
                                                                                  gpointer self);
static void scratch_main_window_action_add_mark (ScratchMainWindow* self);
static void _scratch_main_window_action_add_mark_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self);
static void scratch_main_window_action_previous_mark (ScratchMainWindow* self);
static void _scratch_main_window_action_previous_mark_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self);
static void scratch_main_window_action_next_mark (ScratchMainWindow* self);
static void _scratch_main_window_action_next_mark_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self);
static void scratch_main_window_action_close_tab (ScratchMainWindow* self,
                                           GSimpleAction* action,
                                           GVariant* param);
static void _scratch_main_window_action_close_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self);
static void scratch_main_window_action_close_tabs_to_right (ScratchMainWindow* self);
static void _scratch_main_window_action_close_tabs_to_right_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                       GVariant* parameter,
                                                                                       gpointer self);
static void scratch_main_window_action_close_other_tabs (ScratchMainWindow* self);
static void _scratch_main_window_action_close_other_tabs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                    GVariant* parameter,
                                                                                    gpointer self);
static void scratch_main_window_action_hide_project_docs (ScratchMainWindow* self,
                                                   GSimpleAction* action,
                                                   GVariant* param);
static void _scratch_main_window_action_hide_project_docs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                     GVariant* parameter,
                                                                                     gpointer self);
static void scratch_main_window_action_close_project_docs (ScratchMainWindow* self,
                                                    GSimpleAction* action,
                                                    GVariant* param);
static void _scratch_main_window_action_close_project_docs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                      GVariant* parameter,
                                                                                      gpointer self);
static void scratch_main_window_action_restore_project_docs (ScratchMainWindow* self,
                                                      GSimpleAction* action,
                                                      GVariant* param);
static void _scratch_main_window_action_restore_project_docs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                        GVariant* parameter,
                                                                                        gpointer self);
static void scratch_main_window_action_move_tab_to_new_window (ScratchMainWindow* self);
static void _scratch_main_window_action_move_tab_to_new_window_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                          GVariant* parameter,
                                                                                          gpointer self);
static void scratch_main_window_action_restore_closed_tab (ScratchMainWindow* self,
                                                    GSimpleAction* action,
                                                    GVariant* param);
static void _scratch_main_window_action_restore_closed_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                      GVariant* parameter,
                                                                                      gpointer self);
static void scratch_main_window_action_open_in_new_window (ScratchMainWindow* self,
                                                    GSimpleAction* action,
                                                    GVariant* param);
static void _scratch_main_window_action_open_in_new_window_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                      GVariant* parameter,
                                                                                      gpointer self);
static void scratch_main_window_update_style (ScratchMainWindow* self);
static void scratch_main_window_connect_color_scheme_preference_listener (ScratchMainWindow* self);
static void scratch_main_window_disconnect_color_scheme_preference_listener (ScratchMainWindow* self);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda183_ (Block1Data* _data1_);
static void ___lambda183__g_object_notify (GObject* _sender,
                                    GParamSpec* pspec,
                                    gpointer self);
static void scratch_main_window_update_toolbar_button (ScratchMainWindow* self,
                                                const gchar* name,
                                                gboolean new_state);
static void scratch_main_window_init_layout (ScratchMainWindow* self);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void __lambda184_ (ScratchMainWindow* self,
                   GdkDragContext* ctx,
                   gint x,
                   gint y,
                   GtkSelectionData* sel,
                   guint info,
                   guint time);
static void ___lambda184__gtk_widget_drag_data_received (GtkWidget* _sender,
                                                  GdkDragContext* context,
                                                  gint x,
                                                  gint y,
                                                  GtkSelectionData* selection_data,
                                                  guint info,
                                                  guint time_,
                                                  gpointer self);
static void __lambda185_ (ScratchMainWindow* self,
                   const gchar* a);
static void scratch_main_window_open_binary (ScratchMainWindow* self,
                                      GFile* file);
static void ___lambda185__scratch_folder_manager_file_view_activate (ScratchFolderManagerFileView* _sender,
                                                              const gchar* file,
                                                              gpointer self);
static gboolean __lambda186_ (ScratchMainWindow* self,
                       ScratchFolderManagerFile* file);
static gboolean ___lambda186__scratch_folder_manager_file_view_rename_request (ScratchFolderManagerFileView* _sender,
                                                                        ScratchFolderManagerFile* file,
                                                                        gpointer self);
static void __lambda187_ (ScratchMainWindow* self);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda188_ (ScratchMainWindow* self);
static void ___lambda188__scratch_main_window_hook_func (gpointer self);
static void __lambda189_ (Block3Data* _data3_);
static void ___lambda189__scratch_services_plugins_manager_extension_added (ScratchServicesPluginsManager* _sender,
                                                                     PeasPluginInfo* info,
                                                                     gpointer self);
static void scratch_main_window_restore (ScratchMainWindow* self);
static void ___lambda187__gtk_widget_realize (GtkWidget* _sender,
                                       gpointer self);
static void __lambda191_ (ScratchMainWindow* self);
static void scratch_main_window_update_find_actions (ScratchMainWindow* self);
static void ___lambda191__gtk_widget_realize (GtkWidget* _sender,
                                       gpointer self);
static void __lambda193_ (ScratchMainWindow* self);
static void scratch_main_window_set_widgets_sensitive (ScratchMainWindow* self,
                                                gboolean val);
static void ___lambda193__scratch_widgets_document_view_request_placeholder (ScratchWidgetsDocumentView* _sender,
                                                                      gpointer self);
static void __lambda194_ (Block2Data* _data2_);
static void ___lambda194__scratch_widgets_document_view_tab_added (ScratchWidgetsDocumentView* _sender,
                                                            ScratchServicesDocument* document,
                                                            gpointer self);
static void __lambda195_ (ScratchMainWindow* self,
                   ScratchServicesDocument* doc);
static void ___lambda195__scratch_widgets_document_view_tab_removed (ScratchWidgetsDocumentView* _sender,
                                                              ScratchServicesDocument* document,
                                                              gpointer self);
static void __lambda196_ (ScratchMainWindow* self,
                   ScratchServicesDocument* doc);
static void ___lambda196__scratch_widgets_document_view_document_change (ScratchWidgetsDocumentView* _sender,
                                                                  ScratchServicesDocument* document,
                                                                  ScratchWidgetsDocumentView* parent,
                                                                  gpointer self);
static void scratch_main_window_restore_opened_documents_data_free (gpointer _data);
static void scratch_main_window_restore_opened_documents (ScratchMainWindow* self,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
static void scratch_main_window_restore_opened_documents_finish (ScratchMainWindow* self,
                                                          GAsyncResult* _res_);
static gboolean scratch_main_window_restore_opened_documents_co (ScratchMainWindowRestoreOpenedDocumentsData* _data_);
static void scratch_main_window_restore_opened_documents_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static gboolean scratch_main_window_on_key_pressed (ScratchMainWindow* self,
                                             guint keyval,
                                             guint keycode,
                                             GdkModifierType state);
static GVariant* _variant_new1 (gboolean value);
static gboolean scratch_main_window_real_delete_event (GtkWidget* base,
                                                GdkEventAny* event);
static void scratch_main_window_open_document_data_free (gpointer _data);
static gboolean scratch_main_window_open_document_co (ScratchMainWindowOpenDocumentData* _data_);
static void scratch_main_window_open_document_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void scratch_main_window_open_document_at_selected_range_data_free (gpointer _data);
static gboolean scratch_main_window_open_document_at_selected_range_co (ScratchMainWindowOpenDocumentAtSelectedRangeData* _data_);
static void scratch_main_window_open_document_at_selected_range_ready (GObject* source_object,
                                                                GAsyncResult* _res_,
                                                                gpointer _user_data_);
static void scratch_main_window_check_unsaved_changes_data_free (gpointer _data);
static gboolean scratch_main_window_check_unsaved_changes_co (ScratchMainWindowCheckUnsavedChangesData* _data_);
static void scratch_main_window_check_unsaved_changes_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_);
static void __lambda190_ (ScratchMainWindow* self,
                   GObject* obj,
                   GAsyncResult* res);
static void ___lambda190__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void scratch_main_window_create_unsaved_documents_directory (ScratchMainWindow* self);
static void scratch_main_window_update_window_state_setting (ScratchMainWindow* self);
static void scratch_main_window_zooming (ScratchMainWindow* self,
                                  GdkScrollDirection direction);
static void ___lambda178_ (ScratchMainWindow* self);
static void ____lambda178__gtk_widget_destroy (GtkWidget* _sender,
                                        gpointer self);
static void _g_free0_ (gpointer var);
static inline void _g_slist_free__g_free0_ (GSList* self);
static void scratch_main_window_choose_folder (ScratchMainWindow* self);
static void ___lambda177_ (ScratchMainWindow* self,
                    GFile* glib_file);
static void ____lambda177__gfunc (gconstpointer data,
                           gpointer self);
static void _g_object_unref0_ (gpointer var);
static inline void _g_slist_free__g_object_unref0_ (GSList* self);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static void __lambda174_ (Block4Data* _data4_,
                   gint res);
static Block5Data* block5_data_ref (Block5Data* _data5_);
static void block5_data_unref (void * _userdata_);
static void ___lambda175_ (Block5Data* _data5_,
                    GObject* obj,
                    GAsyncResult* res);
static Block6Data* block6_data_ref (Block6Data* _data6_);
static void block6_data_unref (void * _userdata_);
static void ___lambda176_ (Block6Data* _data6_,
                    gint res);
static void ____lambda176__gtk_dialog_response (GtkDialog* _sender,
                                         gint response_id,
                                         gpointer self);
static void ____lambda175__gasync_ready_callback (GObject* source_object,
                                           GAsyncResult* res,
                                           gpointer self);
static void ___lambda174__gtk_dialog_response (GtkDialog* _sender,
                                        gint response_id,
                                        gpointer self);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static void __lambda180_ (Block7Data* _data7_,
                   ScratchServicesDocument* doc);
static void ___lambda180__gfunc (gconstpointer data,
                          gpointer self);
static void scratch_main_window_close_project_docs (ScratchMainWindow* self,
                                             const gchar* project_path,
                                             gboolean make_restorable);
static gchar* scratch_main_window_get_target_path_for_actions (ScratchMainWindow* self,
                                                        GVariant* path_variant,
                                                        gboolean use_build_dir);
static void scratch_main_window_restore_project_docs (ScratchMainWindow* self,
                                               const gchar* project_path);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
static void __lambda181_ (Block8Data* _data8_,
                   ScratchServicesDocument* doc);
static void ___lambda181__gfunc (gconstpointer data,
                          gpointer self);
static gboolean __lambda182_ (ScratchMainWindow* self,
                       gchar* doc_path);
static gboolean ___lambda182__gee_forall_func (gpointer g,
                                        gpointer self);
static void scratch_main_window_find (ScratchMainWindow* self,
                               const gchar* search_term);
static gboolean ___lambda179_ (ScratchMainWindow* self);
static gboolean ____lambda179__gsource_func (gpointer self);
static gboolean __lambda192_ (ScratchMainWindow* self);
static gboolean ___lambda192__gsource_func (gpointer self);
static GVariant* _variant_new2 (gboolean value);
static GVariant* _variant_new3 (gboolean value);
static GVariant* _variant_new4 (gboolean value);
static GVariant* _variant_new5 (gboolean value);
static void scratch_main_window_set_app (ScratchMainWindow* self,
                                  ScratchApplication* value);
static GObject * scratch_main_window_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static void _vala_array_add2 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _scratch_main_window___lambda197_ (ScratchMainWindow* self);
static void __scratch_main_window___lambda197__g_settings_changed (GSettings* _sender,
                                                            const gchar* key,
                                                            gpointer self);
static gboolean _scratch_main_window_on_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                                   guint keyval,
                                                                                   guint keycode,
                                                                                   GdkModifierType state,
                                                                                   gpointer self);
static void _scratch_main_window___lambda198_ (ScratchMainWindow* self);
static void __scratch_main_window___lambda198__g_object_notify (GObject* _sender,
                                                         GParamSpec* pspec,
                                                         gpointer self);
static void _scratch_main_window___lambda199_ (ScratchMainWindow* self,
                                        const gchar* name,
                                        GVariant* new_state);
static void __scratch_main_window___lambda199__g_action_group_action_state_changed (GActionGroup* _sender,
                                                                             const gchar* action_name,
                                                                             GVariant* state,
                                                                             gpointer self);
static GVariant* _variant_new6 (gboolean value);
static GVariant* _variant_new7 (gboolean value);
static GVariant* _variant_new8 (gboolean value);
static gboolean _scratch_main_window_quit_source_func_gsource_func (gpointer self);
static void scratch_main_window_finalize (GObject * obj);
static GType scratch_main_window_get_type_once (void);
static void _vala_scratch_main_window_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_scratch_main_window_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);

static const GActionEntry SCRATCH_MAIN_WINDOW_ACTION_ENTRIES[57] = {{SCRATCH_MAIN_WINDOW_ACTION_CLONE_REPO, _scratch_main_window_action_clone_repo_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_FIND, _scratch_main_window_action_find_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_FIND_NEXT, _scratch_main_window_action_find_next_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_FIND_PREVIOUS, _scratch_main_window_action_find_previous_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_FIND_GLOBAL, _scratch_main_window_action_find_global_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_OPEN, _scratch_main_window_action_open_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_OPEN_FOLDER, _scratch_main_window_action_open_folder_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_OPEN_PROJECT, _scratch_main_window_action_open_project_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_COLLAPSE_ALL_FOLDERS, _scratch_main_window_action_collapse_all_folders_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_PREFERENCES, _scratch_main_window_action_preferences_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_REVERT, _scratch_main_window_action_revert_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_SAVE, _scratch_main_window_action_save_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_SAVE_AS, _scratch_main_window_action_save_as_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SHOW_FIND, _scratch_main_window_action_toggle_show_find_gsimple_action_activate_callback, NULL, "false"}, {SCRATCH_MAIN_WINDOW_ACTION_TEMPLATES, _scratch_main_window_action_templates_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_GO_TO, _scratch_main_window_action_go_to_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_SORT_LINES, _scratch_main_window_action_sort_lines_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_NEW_TAB, _scratch_main_window_action_new_tab_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_NEW_FROM_CLIPBOARD, _scratch_main_window_action_new_tab_from_clipboard_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_DUPLICATE_TAB, _scratch_main_window_action_duplicate_tab_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_PREFERENCES, _scratch_main_window_action_preferences_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_UNDO, _scratch_main_window_action_undo_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_REDO, _scratch_main_window_action_redo_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_SHOW_REPLACE, _scratch_main_window_action_show_replace_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_TO_LOWER_CASE, _scratch_main_window_action_to_lower_case_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_TO_UPPER_CASE, _scratch_main_window_action_to_upper_case_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_DUPLICATE, _scratch_main_window_action_duplicate_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_FULLSCREEN, _scratch_main_window_action_fullscreen_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_QUIT, _scratch_main_window_action_quit_app_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_CLOSE_WINDOW, _scratch_main_window_action_close_window_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_ZOOM_DEFAULT, _scratch_main_window_action_set_default_zoom_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_ZOOM_IN, _scratch_main_window_action_zoom_in_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_ZOOM_OUT, _scratch_main_window_action_zoom_out_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_COMMENT, _scratch_main_window_action_toggle_comment_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SIDEBAR, _scratch_main_window_action_toggle_sidebar_gsimple_action_activate_callback, NULL, "true"}, {SCRATCH_MAIN_WINDOW_ACTION_FOCUS_SIDEBAR, _scratch_main_window_action_focus_sidebar_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_FOCUS_DOCUMENT, _scratch_main_window_action_focus_document_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_TERMINAL, _scratch_main_window_action_toggle_terminal_gsimple_action_activate_callback, NULL, "false"}, {SCRATCH_MAIN_WINDOW_ACTION_OPEN_IN_TERMINAL, _scratch_main_window_action_open_in_terminal_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_SET_ACTIVE_PROJECT, _scratch_main_window_action_set_active_project_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_OUTLINE, _scratch_main_window_action_toggle_outline_gsimple_action_activate_callback, NULL, "false"}, {SCRATCH_MAIN_WINDOW_ACTION_NEXT_TAB, _scratch_main_window_action_next_tab_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_PREVIOUS_TAB, _scratch_main_window_action_previous_tab_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_CLEAR_LINES, _scratch_main_window_action_clear_lines_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_BRANCH_ACTIONS, _scratch_main_window_action_branch_actions_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_ADD_MARK, _scratch_main_window_action_add_mark_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_PREVIOUS_MARK, _scratch_main_window_action_previous_mark_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_NEXT_MARK, _scratch_main_window_action_next_mark_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_CLOSE_TAB, _scratch_main_window_action_close_tab_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_CLOSE_TABS_TO_RIGHT, _scratch_main_window_action_close_tabs_to_right_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_CLOSE_OTHER_TABS, _scratch_main_window_action_close_other_tabs_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_HIDE_PROJECT_DOCS, _scratch_main_window_action_hide_project_docs_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_CLOSE_PROJECT_DOCS, _scratch_main_window_action_close_project_docs_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_RESTORE_PROJECT_DOCS, _scratch_main_window_action_restore_project_docs_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_MOVE_TAB_TO_NEW_WINDOW, _scratch_main_window_action_move_tab_to_new_window_gsimple_action_activate_callback}, {SCRATCH_MAIN_WINDOW_ACTION_RESTORE_CLOSED_TAB, _scratch_main_window_action_restore_closed_tab_gsimple_action_activate_callback, "s"}, {SCRATCH_MAIN_WINDOW_ACTION_OPEN_IN_NEW_WINDOW, _scratch_main_window_action_open_in_new_window_gsimple_action_activate_callback, "s"}};
VALA_EXTERN const SelectionRange SELECTION_RANGE_EMPTY;

static inline gpointer
scratch_main_window_get_instance_private (ScratchMainWindow* self)
{
	return G_STRUCT_MEMBER_P (self, ScratchMainWindow_private_offset);
}

static void
_scratch_main_window_action_clone_repo_gsimple_action_activate_callback (GSimpleAction* action,
                                                                         GVariant* parameter,
                                                                         gpointer self)
{
	scratch_main_window_action_clone_repo ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_find_gsimple_action_activate_callback (GSimpleAction* action,
                                                                   GVariant* parameter,
                                                                   gpointer self)
{
	scratch_main_window_action_find ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_find_next_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self)
{
	scratch_main_window_action_find_next ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_find_previous_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self)
{
	scratch_main_window_action_find_previous ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_find_global_gsimple_action_activate_callback (GSimpleAction* action,
                                                                          GVariant* parameter,
                                                                          gpointer self)
{
	scratch_main_window_action_find_global ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_open_gsimple_action_activate_callback (GSimpleAction* action,
                                                                   GVariant* parameter,
                                                                   gpointer self)
{
	scratch_main_window_action_open ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_open_folder_gsimple_action_activate_callback (GSimpleAction* action,
                                                                          GVariant* parameter,
                                                                          gpointer self)
{
	scratch_main_window_action_open_folder ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_open_project_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self)
{
	scratch_main_window_action_open_project ((ScratchMainWindow*) self, action);
}

static void
_scratch_main_window_action_collapse_all_folders_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                   GVariant* parameter,
                                                                                   gpointer self)
{
	scratch_main_window_action_collapse_all_folders ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_preferences_gsimple_action_activate_callback (GSimpleAction* action,
                                                                          GVariant* parameter,
                                                                          gpointer self)
{
	scratch_main_window_action_preferences ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_revert_gsimple_action_activate_callback (GSimpleAction* action,
                                                                     GVariant* parameter,
                                                                     gpointer self)
{
	scratch_main_window_action_revert ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_save_gsimple_action_activate_callback (GSimpleAction* action,
                                                                   GVariant* parameter,
                                                                   gpointer self)
{
	scratch_main_window_action_save ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_save_as_gsimple_action_activate_callback (GSimpleAction* action,
                                                                      GVariant* parameter,
                                                                      gpointer self)
{
	scratch_main_window_action_save_as ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_toggle_show_find_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self)
{
	scratch_main_window_action_toggle_show_find ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_templates_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self)
{
	scratch_main_window_action_templates ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_go_to_gsimple_action_activate_callback (GSimpleAction* action,
                                                                    GVariant* parameter,
                                                                    gpointer self)
{
	scratch_main_window_action_go_to ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_sort_lines_gsimple_action_activate_callback (GSimpleAction* action,
                                                                         GVariant* parameter,
                                                                         gpointer self)
{
	scratch_main_window_action_sort_lines ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_new_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                      GVariant* parameter,
                                                                      gpointer self)
{
	scratch_main_window_action_new_tab ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_new_tab_from_clipboard_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                     GVariant* parameter,
                                                                                     gpointer self)
{
	scratch_main_window_action_new_tab_from_clipboard ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_duplicate_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self)
{
	scratch_main_window_action_duplicate_tab ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_undo_gsimple_action_activate_callback (GSimpleAction* action,
                                                                   GVariant* parameter,
                                                                   gpointer self)
{
	scratch_main_window_action_undo ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_redo_gsimple_action_activate_callback (GSimpleAction* action,
                                                                   GVariant* parameter,
                                                                   gpointer self)
{
	scratch_main_window_action_redo ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_show_replace_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self)
{
	scratch_main_window_action_show_replace ((ScratchMainWindow*) self, action);
}

static void
_scratch_main_window_action_to_lower_case_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self)
{
	scratch_main_window_action_to_lower_case ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_to_upper_case_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self)
{
	scratch_main_window_action_to_upper_case ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_duplicate_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self)
{
	scratch_main_window_action_duplicate ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_fullscreen_gsimple_action_activate_callback (GSimpleAction* action,
                                                                         GVariant* parameter,
                                                                         gpointer self)
{
	scratch_main_window_action_fullscreen ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_quit_app_gsimple_action_activate_callback (GSimpleAction* action,
                                                                       GVariant* parameter,
                                                                       gpointer self)
{
	scratch_main_window_action_quit_app ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_close_window_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self)
{
	scratch_main_window_action_close_window ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_set_default_zoom_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self)
{
	scratch_main_window_action_set_default_zoom ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_zoom_in_gsimple_action_activate_callback (GSimpleAction* action,
                                                                      GVariant* parameter,
                                                                      gpointer self)
{
	scratch_main_window_action_zoom_in ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_zoom_out_gsimple_action_activate_callback (GSimpleAction* action,
                                                                       GVariant* parameter,
                                                                       gpointer self)
{
	scratch_main_window_action_zoom_out ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_toggle_comment_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self)
{
	scratch_main_window_action_toggle_comment ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_toggle_sidebar_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self)
{
	scratch_main_window_action_toggle_sidebar ((ScratchMainWindow*) self, action);
}

static void
_scratch_main_window_action_focus_sidebar_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self)
{
	scratch_main_window_action_focus_sidebar ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_focus_document_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self)
{
	scratch_main_window_action_focus_document ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_toggle_terminal_gsimple_action_activate_callback (GSimpleAction* action,
                                                                              GVariant* parameter,
                                                                              gpointer self)
{
	scratch_main_window_action_toggle_terminal ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_open_in_terminal_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self)
{
	scratch_main_window_action_open_in_terminal ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_set_active_project_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self)
{
	scratch_main_window_action_set_active_project ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_toggle_outline_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self)
{
	scratch_main_window_action_toggle_outline ((ScratchMainWindow*) self, action);
}

static void
_scratch_main_window_action_next_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                       GVariant* parameter,
                                                                       gpointer self)
{
	scratch_main_window_action_next_tab ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_previous_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                           GVariant* parameter,
                                                                           gpointer self)
{
	scratch_main_window_action_previous_tab ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_clear_lines_gsimple_action_activate_callback (GSimpleAction* action,
                                                                          GVariant* parameter,
                                                                          gpointer self)
{
	scratch_main_window_action_clear_lines ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_branch_actions_gsimple_action_activate_callback (GSimpleAction* action,
                                                                             GVariant* parameter,
                                                                             gpointer self)
{
	scratch_main_window_action_branch_actions ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_add_mark_gsimple_action_activate_callback (GSimpleAction* action,
                                                                       GVariant* parameter,
                                                                       gpointer self)
{
	scratch_main_window_action_add_mark ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_previous_mark_gsimple_action_activate_callback (GSimpleAction* action,
                                                                            GVariant* parameter,
                                                                            gpointer self)
{
	scratch_main_window_action_previous_mark ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_next_mark_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self)
{
	scratch_main_window_action_next_mark ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_close_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                        GVariant* parameter,
                                                                        gpointer self)
{
	scratch_main_window_action_close_tab ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_close_tabs_to_right_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                  GVariant* parameter,
                                                                                  gpointer self)
{
	scratch_main_window_action_close_tabs_to_right ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_close_other_tabs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                               GVariant* parameter,
                                                                               gpointer self)
{
	scratch_main_window_action_close_other_tabs ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_hide_project_docs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                GVariant* parameter,
                                                                                gpointer self)
{
	scratch_main_window_action_hide_project_docs ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_close_project_docs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self)
{
	scratch_main_window_action_close_project_docs ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_restore_project_docs_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                   GVariant* parameter,
                                                                                   gpointer self)
{
	scratch_main_window_action_restore_project_docs ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_move_tab_to_new_window_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                     GVariant* parameter,
                                                                                     gpointer self)
{
	scratch_main_window_action_move_tab_to_new_window ((ScratchMainWindow*) self);
}

static void
_scratch_main_window_action_restore_closed_tab_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self)
{
	scratch_main_window_action_restore_closed_tab ((ScratchMainWindow*) self, action, parameter);
}

static void
_scratch_main_window_action_open_in_new_window_gsimple_action_activate_callback (GSimpleAction* action,
                                                                                 GVariant* parameter,
                                                                                 gpointer self)
{
	scratch_main_window_action_open_in_new_window ((ScratchMainWindow*) self, action, parameter);
}

ScratchMainWindow*
scratch_main_window_construct (GType object_type,
                               gboolean restore_docs)
{
	ScratchMainWindow * self = NULL;
	self = (ScratchMainWindow*) g_object_new (object_type, "icon-name", CONSTANTS_PROJECT_NAME, "restore-docs", restore_docs, NULL);
	return self;
}

ScratchMainWindow*
scratch_main_window_new (gboolean restore_docs)
{
	return scratch_main_window_construct (SCRATCH_TYPE_MAIN_WINDOW, restore_docs);
}

ScratchMainWindow*
scratch_main_window_construct_with_restore_override (GType object_type,
                                                     gboolean restore_docs,
                                                     RestoreOverride* restore_override)
{
	ScratchMainWindow * self = NULL;
	g_return_val_if_fail (restore_override != NULL, NULL);
	self = (ScratchMainWindow*) g_object_new (object_type, "icon-name", CONSTANTS_PROJECT_NAME, "restore-docs", restore_docs, "restore-override", restore_override, NULL);
	return self;
}

ScratchMainWindow*
scratch_main_window_new_with_restore_override (gboolean restore_docs,
                                               RestoreOverride* restore_override)
{
	return scratch_main_window_construct_with_restore_override (SCRATCH_TYPE_MAIN_WINDOW, restore_docs, restore_override);
}

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

static void
scratch_main_window_update_style (ScratchMainWindow* self)
{
	GtkSettings* gtk_settings = NULL;
	GtkSettings* _tmp0_;
	GtkSettings* _tmp1_;
	GSettings* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_settings_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	gtk_settings = _tmp1_;
	_tmp2_ = scratch_settings;
	if (g_settings_get_boolean (_tmp2_, "follow-system-style")) {
		gboolean system_prefers_dark = FALSE;
		GraniteSettings* _tmp3_;
		GraniteSettingsColorScheme _tmp4_;
		GraniteSettingsColorScheme _tmp5_;
		GtkSettings* _tmp6_;
		_tmp3_ = granite_settings_get_default ();
		_tmp4_ = granite_settings_get_prefers_color_scheme (_tmp3_);
		_tmp5_ = _tmp4_;
		system_prefers_dark = _tmp5_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK;
		_tmp6_ = gtk_settings;
		g_object_set (_tmp6_, "gtk-application-prefer-dark-theme", system_prefers_dark, NULL);
		scratch_main_window_connect_color_scheme_preference_listener (self);
	} else {
		GtkSettings* _tmp7_;
		GSettings* _tmp8_;
		scratch_main_window_disconnect_color_scheme_preference_listener (self);
		_tmp7_ = gtk_settings;
		_tmp8_ = scratch_settings;
		g_object_set (_tmp7_, "gtk-application-prefer-dark-theme", g_settings_get_boolean (_tmp8_, "prefer-dark-style"), NULL);
	}
	_g_object_unref0 (gtk_settings);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->granite_settings);
		_g_object_unref0 (_data1_->gtk_settings);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
__lambda183_ (Block1Data* _data1_)
{
	ScratchMainWindow* self;
	GraniteSettingsColorScheme _tmp0_;
	GraniteSettingsColorScheme _tmp1_;
	self = _data1_->self;
	_tmp0_ = granite_settings_get_prefers_color_scheme (_data1_->granite_settings);
	_tmp1_ = _tmp0_;
	g_object_set (_data1_->gtk_settings, "gtk-application-prefer-dark-theme", _tmp1_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK, NULL);
}

static void
___lambda183__g_object_notify (GObject* _sender,
                               GParamSpec* pspec,
                               gpointer self)
{
	__lambda183_ (self);
}

static void
scratch_main_window_connect_color_scheme_preference_listener (ScratchMainWindow* self)
{
	Block1Data* _data1_;
	GtkSettings* _tmp0_;
	GtkSettings* _tmp1_;
	GraniteSettings* _tmp2_;
	GraniteSettings* _tmp3_;
	gulong _tmp4_;
	g_return_if_fail (self != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = gtk_settings_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data1_->gtk_settings = _tmp1_;
	_tmp2_ = granite_settings_get_default ();
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_data1_->granite_settings = _tmp3_;
	_tmp4_ = g_signal_connect_data ((GObject*) _data1_->granite_settings, "notify::prefers-color-scheme", (GCallback) ___lambda183__g_object_notify, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	self->priv->color_scheme_listener_handler_id = _tmp4_;
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

static void
scratch_main_window_disconnect_color_scheme_preference_listener (ScratchMainWindow* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->color_scheme_listener_handler_id != ((gulong) 0)) {
		GraniteSettings* granite_settings = NULL;
		GraniteSettings* _tmp0_;
		GraniteSettings* _tmp1_;
		GraniteSettings* _tmp2_;
		_tmp0_ = granite_settings_get_default ();
		_tmp1_ = _g_object_ref0 (_tmp0_);
		granite_settings = _tmp1_;
		_tmp2_ = granite_settings;
		g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->color_scheme_listener_handler_id);
		self->priv->color_scheme_listener_handler_id = (gulong) 0;
		_g_object_unref0 (granite_settings);
	}
}

static void
scratch_main_window_update_toolbar_button (ScratchMainWindow* self,
                                           const gchar* name,
                                           gboolean new_state)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = name;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SHOW_FIND)))) {
		switch (0) {
			default:
			{
				ScratchWidgetsSearchBar* _tmp22_;
				if (new_state) {
					ScratchHeaderBar* _tmp3_;
					GtkToggleButton* _tmp4_;
					GtkToggleButton* _tmp5_;
					gchar* _tmp6_;
					gchar** _tmp7_;
					gchar** _tmp8_;
					gint _tmp8__length1;
					gchar* _tmp9_;
					gchar* _tmp10_;
					_tmp3_ = self->toolbar;
					_tmp4_ = scratch_header_bar_get_find_button (_tmp3_);
					_tmp5_ = _tmp4_;
					_tmp6_ = g_strdup ("Escape");
					_tmp7_ = g_new0 (gchar*, 1 + 1);
					_tmp7_[0] = _tmp6_;
					_tmp8_ = _tmp7_;
					_tmp8__length1 = 1;
					_tmp9_ = granite_markup_accel_tooltip (_tmp8_, (gint) 1, _ ("Hide search bar"));
					_tmp10_ = _tmp9_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp5_, _tmp10_);
					_g_free0 (_tmp10_);
					_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
				} else {
					ScratchHeaderBar* _tmp11_;
					GtkToggleButton* _tmp12_;
					GtkToggleButton* _tmp13_;
					ScratchApplication* _tmp14_;
					gchar* _tmp15_;
					gchar* _tmp16_;
					gchar** _tmp17_;
					gchar** _tmp18_;
					gchar** _tmp19_;
					gint _tmp19__length1;
					gchar* _tmp20_;
					gchar* _tmp21_;
					_tmp11_ = self->toolbar;
					_tmp12_ = scratch_header_bar_get_find_button (_tmp11_);
					_tmp13_ = _tmp12_;
					_tmp14_ = self->priv->_app;
					_tmp15_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, name, NULL);
					_tmp16_ = _tmp15_;
					_tmp18_ = _tmp17_ = gtk_application_get_accels_for_action ((GtkApplication*) _tmp14_, _tmp16_);
					_tmp19_ = _tmp18_;
					_tmp19__length1 = _vala_array_length (_tmp17_);
					_tmp20_ = granite_markup_accel_tooltip (_tmp19_, (gint) _vala_array_length (_tmp17_), _ ("Find on Page…"));
					_tmp21_ = _tmp20_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp13_, _tmp21_);
					_g_free0 (_tmp21_);
					_tmp19_ = (_vala_array_free (_tmp19_, _tmp19__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_tmp16_);
				}
				_tmp22_ = self->search_bar;
				scratch_widgets_search_bar_reveal (_tmp22_, new_state);
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SIDEBAR)))) {
		switch (0) {
			default:
			{
				if (new_state) {
					ScratchHeaderBar* _tmp23_;
					GtkToggleButton* _tmp24_;
					GtkToggleButton* _tmp25_;
					ScratchApplication* _tmp26_;
					gchar* _tmp27_;
					gchar* _tmp28_;
					gchar** _tmp29_;
					gchar** _tmp30_;
					gchar** _tmp31_;
					gint _tmp31__length1;
					gchar* _tmp32_;
					gchar* _tmp33_;
					_tmp23_ = self->toolbar;
					_tmp24_ = scratch_header_bar_get_sidebar_button (_tmp23_);
					_tmp25_ = _tmp24_;
					_tmp26_ = self->priv->_app;
					_tmp27_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, name, NULL);
					_tmp28_ = _tmp27_;
					_tmp30_ = _tmp29_ = gtk_application_get_accels_for_action ((GtkApplication*) _tmp26_, _tmp28_);
					_tmp31_ = _tmp30_;
					_tmp31__length1 = _vala_array_length (_tmp29_);
					_tmp32_ = granite_markup_accel_tooltip (_tmp31_, (gint) _vala_array_length (_tmp29_), _ ("Hide Projects Sidebar"));
					_tmp33_ = _tmp32_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp25_, _tmp33_);
					_g_free0 (_tmp33_);
					_tmp31_ = (_vala_array_free (_tmp31_, _tmp31__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_tmp28_);
				} else {
					ScratchHeaderBar* _tmp34_;
					GtkToggleButton* _tmp35_;
					GtkToggleButton* _tmp36_;
					ScratchApplication* _tmp37_;
					gchar* _tmp38_;
					gchar* _tmp39_;
					gchar** _tmp40_;
					gchar** _tmp41_;
					gchar** _tmp42_;
					gint _tmp42__length1;
					gchar* _tmp43_;
					gchar* _tmp44_;
					_tmp34_ = self->toolbar;
					_tmp35_ = scratch_header_bar_get_sidebar_button (_tmp34_);
					_tmp36_ = _tmp35_;
					_tmp37_ = self->priv->_app;
					_tmp38_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, name, NULL);
					_tmp39_ = _tmp38_;
					_tmp41_ = _tmp40_ = gtk_application_get_accels_for_action ((GtkApplication*) _tmp37_, _tmp39_);
					_tmp42_ = _tmp41_;
					_tmp42__length1 = _vala_array_length (_tmp40_);
					_tmp43_ = granite_markup_accel_tooltip (_tmp42_, (gint) _vala_array_length (_tmp40_), _ ("Show Projects Sidebar"));
					_tmp44_ = _tmp43_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp36_, _tmp44_);
					_g_free0 (_tmp44_);
					_tmp42_ = (_vala_array_free (_tmp42_, _tmp42__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_tmp39_);
				}
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_OUTLINE)))) {
		switch (0) {
			default:
			{
				if (new_state) {
					ScratchHeaderBar* _tmp45_;
					GtkToggleButton* _tmp46_;
					GtkToggleButton* _tmp47_;
					ScratchApplication* _tmp48_;
					gchar* _tmp49_;
					gchar* _tmp50_;
					gchar** _tmp51_;
					gchar** _tmp52_;
					gchar** _tmp53_;
					gint _tmp53__length1;
					gchar* _tmp54_;
					gchar* _tmp55_;
					_tmp45_ = self->toolbar;
					_tmp46_ = scratch_header_bar_get_outline_button (_tmp45_);
					_tmp47_ = _tmp46_;
					_tmp48_ = self->priv->_app;
					_tmp49_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, name, NULL);
					_tmp50_ = _tmp49_;
					_tmp52_ = _tmp51_ = gtk_application_get_accels_for_action ((GtkApplication*) _tmp48_, _tmp50_);
					_tmp53_ = _tmp52_;
					_tmp53__length1 = _vala_array_length (_tmp51_);
					_tmp54_ = granite_markup_accel_tooltip (_tmp53_, (gint) _vala_array_length (_tmp51_), _ ("Hide Symbol Outline"));
					_tmp55_ = _tmp54_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp47_, _tmp55_);
					_g_free0 (_tmp55_);
					_tmp53_ = (_vala_array_free (_tmp53_, _tmp53__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_tmp50_);
				} else {
					ScratchHeaderBar* _tmp56_;
					GtkToggleButton* _tmp57_;
					GtkToggleButton* _tmp58_;
					ScratchApplication* _tmp59_;
					gchar* _tmp60_;
					gchar* _tmp61_;
					gchar** _tmp62_;
					gchar** _tmp63_;
					gchar** _tmp64_;
					gint _tmp64__length1;
					gchar* _tmp65_;
					gchar* _tmp66_;
					_tmp56_ = self->toolbar;
					_tmp57_ = scratch_header_bar_get_outline_button (_tmp56_);
					_tmp58_ = _tmp57_;
					_tmp59_ = self->priv->_app;
					_tmp60_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, name, NULL);
					_tmp61_ = _tmp60_;
					_tmp63_ = _tmp62_ = gtk_application_get_accels_for_action ((GtkApplication*) _tmp59_, _tmp61_);
					_tmp64_ = _tmp63_;
					_tmp64__length1 = _vala_array_length (_tmp62_);
					_tmp65_ = granite_markup_accel_tooltip (_tmp64_, (gint) _vala_array_length (_tmp62_), _ ("Show Symbol Outline"));
					_tmp66_ = _tmp65_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp58_, _tmp66_);
					_g_free0 (_tmp66_);
					_tmp64_ = (_vala_array_free (_tmp64_, _tmp64__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_tmp61_);
				}
				break;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_TERMINAL)))) {
		switch (0) {
			default:
			{
				if (new_state) {
					ScratchHeaderBar* _tmp67_;
					GtkToggleButton* _tmp68_;
					GtkToggleButton* _tmp69_;
					ScratchApplication* _tmp70_;
					gchar* _tmp71_;
					gchar* _tmp72_;
					gchar** _tmp73_;
					gchar** _tmp74_;
					gchar** _tmp75_;
					gint _tmp75__length1;
					gchar* _tmp76_;
					gchar* _tmp77_;
					_tmp67_ = self->toolbar;
					_tmp68_ = scratch_header_bar_get_terminal_button (_tmp67_);
					_tmp69_ = _tmp68_;
					_tmp70_ = self->priv->_app;
					_tmp71_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, name, NULL);
					_tmp72_ = _tmp71_;
					_tmp74_ = _tmp73_ = gtk_application_get_accels_for_action ((GtkApplication*) _tmp70_, _tmp72_);
					_tmp75_ = _tmp74_;
					_tmp75__length1 = _vala_array_length (_tmp73_);
					_tmp76_ = granite_markup_accel_tooltip (_tmp75_, (gint) _vala_array_length (_tmp73_), _ ("Hide Terminal"));
					_tmp77_ = _tmp76_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp69_, _tmp77_);
					_g_free0 (_tmp77_);
					_tmp75_ = (_vala_array_free (_tmp75_, _tmp75__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_tmp72_);
				} else {
					ScratchHeaderBar* _tmp78_;
					GtkToggleButton* _tmp79_;
					GtkToggleButton* _tmp80_;
					ScratchApplication* _tmp81_;
					gchar* _tmp82_;
					gchar* _tmp83_;
					gchar** _tmp84_;
					gchar** _tmp85_;
					gchar** _tmp86_;
					gint _tmp86__length1;
					gchar* _tmp87_;
					gchar* _tmp88_;
					_tmp78_ = self->toolbar;
					_tmp79_ = scratch_header_bar_get_terminal_button (_tmp78_);
					_tmp80_ = _tmp79_;
					_tmp81_ = self->priv->_app;
					_tmp82_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, name, NULL);
					_tmp83_ = _tmp82_;
					_tmp85_ = _tmp84_ = gtk_application_get_accels_for_action ((GtkApplication*) _tmp81_, _tmp83_);
					_tmp86_ = _tmp85_;
					_tmp86__length1 = _vala_array_length (_tmp84_);
					_tmp87_ = granite_markup_accel_tooltip (_tmp86_, (gint) _vala_array_length (_tmp84_), _ ("Show Terminal"));
					_tmp88_ = _tmp87_;
					gtk_widget_set_tooltip_markup ((GtkWidget*) _tmp80_, _tmp88_);
					_g_free0 (_tmp88_);
					_tmp86_ = (_vala_array_free (_tmp86_, _tmp86__length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (_tmp83_);
				}
				break;
			}
		}
	}
}

static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}

static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data2_->self;
		_g_object_unref0 (_data2_->view_grid);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

static void
__lambda184_ (ScratchMainWindow* self,
              GdkDragContext* ctx,
              gint x,
              gint y,
              GtkSelectionData* sel,
              guint info,
              guint time)
{
	gchar** uris = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_;
	gint uris_length1;
	gint _uris_size_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	g_return_if_fail (ctx != NULL);
	g_return_if_fail (sel != NULL);
	_tmp1_ = _tmp0_ = gtk_selection_data_get_uris (sel);
	uris = _tmp1_;
	uris_length1 = _vala_array_length (_tmp0_);
	_uris_size_ = uris_length1;
	_tmp2_ = uris;
	_tmp2__length1 = uris_length1;
	if (_tmp2__length1 > 0) {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp3_ = FALSE;
				_tmp3_ = TRUE;
				while (TRUE) {
					gchar** _tmp5_;
					gint _tmp5__length1;
					gchar* filename = NULL;
					gchar** _tmp6_;
					gint _tmp6__length1;
					const gchar* _tmp7_;
					gchar* _tmp8_;
					GFile* file = NULL;
					const gchar* _tmp9_;
					GFile* _tmp10_;
					gboolean is_folder = FALSE;
					gboolean _tmp11_ = FALSE;
					GFile* _tmp12_;
					gboolean _tmp13_ = FALSE;
					gboolean _tmp14_;
					if (!_tmp3_) {
						gint _tmp4_;
						_tmp4_ = i;
						i = _tmp4_ + 1;
					}
					_tmp3_ = FALSE;
					_tmp5_ = uris;
					_tmp5__length1 = uris_length1;
					if (!(i < _tmp5__length1)) {
						break;
					}
					_tmp6_ = uris;
					_tmp6__length1 = uris_length1;
					_tmp7_ = _tmp6_[i];
					_tmp8_ = g_strdup (_tmp7_);
					filename = _tmp8_;
					_tmp9_ = filename;
					_tmp10_ = g_file_new_for_uri (_tmp9_);
					file = _tmp10_;
					_tmp12_ = file;
					_tmp14_ = scratch_services_file_handler_can_open_file (_tmp12_, &_tmp13_);
					is_folder = _tmp13_;
					if (_tmp14_) {
						_tmp11_ = !is_folder;
					} else {
						_tmp11_ = FALSE;
					}
					if (_tmp11_) {
						ScratchServicesDocument* doc = NULL;
						GSimpleActionGroup* _tmp15_;
						GFile* _tmp16_;
						ScratchServicesDocument* _tmp17_;
						ScratchWidgetsDocumentView* _tmp18_;
						ScratchServicesDocument* _tmp19_;
						_tmp15_ = self->priv->_actions;
						_tmp16_ = file;
						_tmp17_ = scratch_services_document_new (_tmp15_, _tmp16_);
						g_object_ref_sink (_tmp17_);
						doc = _tmp17_;
						_tmp18_ = self->document_view;
						_tmp19_ = doc;
						scratch_widgets_document_view_open_document (_tmp18_, _tmp19_, TRUE, 0, &SELECTION_RANGE_EMPTY, NULL, NULL);
						_g_object_unref0 (doc);
					}
					_g_object_unref0 (file);
					_g_free0 (filename);
				}
			}
		}
		gtk_drag_finish (ctx, TRUE, FALSE, (guint32) time);
	}
	uris = (_vala_array_free (uris, uris_length1, (GDestroyNotify) g_free), NULL);
}

static void
___lambda184__gtk_widget_drag_data_received (GtkWidget* _sender,
                                             GdkDragContext* context,
                                             gint x,
                                             gint y,
                                             GtkSelectionData* selection_data,
                                             guint info,
                                             guint time_,
                                             gpointer self)
{
	__lambda184_ ((ScratchMainWindow*) self, context, x, y, selection_data, info, time_);
}

static void
__lambda185_ (ScratchMainWindow* self,
              const gchar* a)
{
	ScratchFolderManagerFile* file = NULL;
	ScratchFolderManagerFile* _tmp0_;
	ScratchServicesDocument* doc = NULL;
	GSimpleActionGroup* _tmp1_;
	ScratchFolderManagerFile* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	ScratchServicesDocument* _tmp5_;
	ScratchFolderManagerFile* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	g_return_if_fail (a != NULL);
	_tmp0_ = scratch_folder_manager_file_new (a);
	file = _tmp0_;
	_tmp1_ = self->priv->_actions;
	_tmp2_ = file;
	_tmp3_ = scratch_folder_manager_file_get_file (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = scratch_services_document_new (_tmp1_, _tmp4_);
	g_object_ref_sink (_tmp5_);
	doc = _tmp5_;
	_tmp6_ = file;
	_tmp7_ = scratch_folder_manager_file_get_is_valid_textfile (_tmp6_);
	_tmp8_ = _tmp7_;
	if (_tmp8_) {
		ScratchServicesDocument* _tmp9_;
		_tmp9_ = doc;
		scratch_main_window_open_document (self, _tmp9_, TRUE, 0, NULL, NULL);
	} else {
		ScratchFolderManagerFile* _tmp10_;
		GFile* _tmp11_;
		GFile* _tmp12_;
		_tmp10_ = file;
		_tmp11_ = scratch_folder_manager_file_get_file (_tmp10_);
		_tmp12_ = _tmp11_;
		scratch_main_window_open_binary (self, _tmp12_);
	}
	_g_object_unref0 (doc);
	_g_object_unref0 (file);
}

static void
___lambda185__scratch_folder_manager_file_view_activate (ScratchFolderManagerFileView* _sender,
                                                         const gchar* file,
                                                         gpointer self)
{
	__lambda185_ ((ScratchMainWindow*) self, file);
}

static gboolean
__lambda186_ (ScratchMainWindow* self,
              ScratchFolderManagerFile* file)
{
	gboolean allow = FALSE;
	ScratchApplication* _tmp0_;
	GList* _tmp1_;
	gboolean result;
	g_return_val_if_fail (file != NULL, FALSE);
	allow = TRUE;
	_tmp0_ = self->priv->_app;
	_tmp1_ = gtk_application_get_windows ((GtkApplication*) _tmp0_);
	{
		GList* window_collection = NULL;
		GList* window_it = NULL;
		window_collection = _tmp1_;
		for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
			GtkWindow* _tmp2_;
			GtkWindow* window = NULL;
			_tmp2_ = _g_object_ref0 ((GtkWindow*) window_it->data);
			window = _tmp2_;
			{
				ScratchMainWindow* win = NULL;
				GtkWindow* _tmp3_;
				ScratchMainWindow* _tmp4_;
				ScratchMainWindow* _tmp5_;
				ScratchWidgetsDocumentView* _tmp6_;
				GList* _tmp7_;
				_tmp3_ = window;
				_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, SCRATCH_TYPE_MAIN_WINDOW, ScratchMainWindow));
				win = _tmp4_;
				_tmp5_ = win;
				_tmp6_ = _tmp5_->document_view;
				_tmp7_ = _tmp6_->docs;
				{
					GList* doc_collection = NULL;
					GList* doc_it = NULL;
					doc_collection = _tmp7_;
					for (doc_it = doc_collection; doc_it != NULL; doc_it = doc_it->next) {
						ScratchServicesDocument* _tmp8_;
						ScratchServicesDocument* doc = NULL;
						_tmp8_ = _g_object_ref0 ((ScratchServicesDocument*) doc_it->data);
						doc = _tmp8_;
						{
							ScratchServicesDocument* _tmp9_;
							GFile* _tmp10_;
							GFile* _tmp11_;
							GFile* _tmp12_;
							GFile* _tmp13_;
							_tmp9_ = doc;
							_tmp10_ = scratch_services_document_get_file (_tmp9_);
							_tmp11_ = _tmp10_;
							_tmp12_ = scratch_folder_manager_file_get_file (file);
							_tmp13_ = _tmp12_;
							if (g_file_equal (_tmp11_, _tmp13_)) {
								gboolean _tmp14_ = FALSE;
								gboolean _tmp15_ = FALSE;
								if (allow) {
									ScratchServicesDocument* _tmp16_;
									gboolean _tmp17_;
									gboolean _tmp18_;
									_tmp16_ = doc;
									_tmp17_ = scratch_services_document_get_locked (_tmp16_);
									_tmp18_ = _tmp17_;
									_tmp15_ = !_tmp18_;
								} else {
									_tmp15_ = FALSE;
								}
								if (_tmp15_) {
									ScratchServicesDocument* _tmp19_;
									_tmp19_ = doc;
									_tmp14_ = _tmp19_->saved;
								} else {
									_tmp14_ = FALSE;
								}
								allow = _tmp14_;
							}
							_g_object_unref0 (doc);
						}
					}
				}
				_g_object_unref0 (win);
				_g_object_unref0 (window);
			}
		}
	}
	result = allow;
	return result;
}

static gboolean
___lambda186__scratch_folder_manager_file_view_rename_request (ScratchFolderManagerFileView* _sender,
                                                               ScratchFolderManagerFile* file,
                                                               gpointer self)
{
	gboolean result;
	result = __lambda186_ ((ScratchMainWindow*) self, file);
	return result;
}

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data3_->self;
		(_data3_->hook_func_target_destroy_notify == NULL) ? NULL : (_data3_->hook_func_target_destroy_notify (_data3_->hook_func_target), NULL);
		_data3_->hook_func = NULL;
		_data3_->hook_func_target = NULL;
		_data3_->hook_func_target_destroy_notify = NULL;
		_g_object_unref0 (self);
		g_slice_free (Block3Data, _data3_);
	}
}

static void
__lambda188_ (ScratchMainWindow* self)
{
	ScratchServicesPluginsManager* _tmp0_;
	ScratchServicesPluginsManager* _tmp1_;
	ScratchHeaderBar* _tmp2_;
	ScratchServicesPluginsManager* _tmp3_;
	ScratchHeaderBar* _tmp4_;
	GMenu* _tmp5_;
	_tmp0_ = self->priv->plugins;
	g_signal_emit_by_name (_tmp0_, "hook-window", self);
	_tmp1_ = self->priv->plugins;
	_tmp2_ = self->toolbar;
	g_signal_emit_by_name (_tmp1_, "hook-toolbar", _tmp2_);
	_tmp3_ = self->priv->plugins;
	_tmp4_ = self->toolbar;
	_tmp5_ = _tmp4_->share_menu;
	g_signal_emit_by_name (_tmp3_, "hook-share-menu", (GMenuModel*) _tmp5_);
}

static void
___lambda188__scratch_main_window_hook_func (gpointer self)
{
	__lambda188_ ((ScratchMainWindow*) self);
}

static void
__lambda189_ (Block3Data* _data3_)
{
	ScratchMainWindow* self;
	self = _data3_->self;
	_data3_->hook_func (_data3_->hook_func_target);
}

static void
___lambda189__scratch_services_plugins_manager_extension_added (ScratchServicesPluginsManager* _sender,
                                                                PeasPluginInfo* info,
                                                                gpointer self)
{
	__lambda189_ (self);
}

static void
__lambda187_ (ScratchMainWindow* self)
{
	Block3Data* _data3_;
	GSettings* _tmp0_;
	CodeSidebar* _tmp1_;
	GSettings* _tmp2_;
	ScratchWidgetsDocumentView* _tmp3_;
	GSettings* _tmp4_;
	CodeTerminal* _tmp5_;
	ScratchServicesPluginsManager* _tmp6_;
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_data3_->self = g_object_ref (self);
	_tmp0_ = scratch_saved_state;
	_tmp1_ = self->sidebar;
	g_settings_bind (_tmp0_, "sidebar-visible", (GObject*) _tmp1_, "visible", G_SETTINGS_BIND_DEFAULT);
	_tmp2_ = scratch_saved_state;
	_tmp3_ = self->document_view;
	g_settings_bind (_tmp2_, "outline-visible", (GObject*) _tmp3_, "outline_visible", G_SETTINGS_BIND_DEFAULT);
	_tmp4_ = scratch_saved_state;
	_tmp5_ = self->priv->terminal;
	g_settings_bind (_tmp4_, "terminal-visible", (GObject*) _tmp5_, "visible", G_SETTINGS_BIND_DEFAULT);
	_data3_->hook_func = ___lambda188__scratch_main_window_hook_func;
	_data3_->hook_func_target = g_object_ref (self);
	_data3_->hook_func_target_destroy_notify = g_object_unref;
	_tmp6_ = self->priv->plugins;
	g_signal_connect_data (_tmp6_, "extension-added", (GCallback) ___lambda189__scratch_services_plugins_manager_extension_added, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
	_data3_->hook_func (_data3_->hook_func_target);
	scratch_main_window_restore (self);
	block3_data_unref (_data3_);
	_data3_ = NULL;
}

static void
___lambda187__gtk_widget_realize (GtkWidget* _sender,
                                  gpointer self)
{
	__lambda187_ ((ScratchMainWindow*) self);
}

static void
__lambda191_ (ScratchMainWindow* self)
{
	scratch_main_window_update_find_actions (self);
}

static void
___lambda191__gtk_widget_realize (GtkWidget* _sender,
                                  gpointer self)
{
	__lambda191_ ((ScratchMainWindow*) self);
}

static void
__lambda193_ (ScratchMainWindow* self)
{
	GtkStack* _tmp0_;
	CodeWelcomeView* _tmp1_;
	const gchar* _tmp2_;
	ScratchHeaderBar* _tmp3_;
	_tmp0_ = self->priv->content_stack;
	_tmp1_ = self->priv->welcome_view;
	gtk_stack_set_visible_child (_tmp0_, (GtkWidget*) _tmp1_);
	_tmp2_ = scratch_main_window_base_title;
	gtk_window_set_title ((GtkWindow*) self, _tmp2_);
	_tmp3_ = self->toolbar;
	scratch_header_bar_document_available (_tmp3_, FALSE);
	scratch_main_window_set_widgets_sensitive (self, FALSE);
}

static void
___lambda193__scratch_widgets_document_view_request_placeholder (ScratchWidgetsDocumentView* _sender,
                                                                 gpointer self)
{
	__lambda193_ ((ScratchMainWindow*) self);
}

static void
__lambda194_ (Block2Data* _data2_)
{
	ScratchMainWindow* self;
	GtkStack* _tmp0_;
	ScratchHeaderBar* _tmp1_;
	self = _data2_->self;
	_tmp0_ = self->priv->content_stack;
	gtk_stack_set_visible_child (_tmp0_, (GtkWidget*) _data2_->view_grid);
	_tmp1_ = self->toolbar;
	scratch_header_bar_document_available (_tmp1_, TRUE);
	scratch_main_window_set_widgets_sensitive (self, TRUE);
	scratch_main_window_update_find_actions (self);
}

static void
___lambda194__scratch_widgets_document_view_tab_added (ScratchWidgetsDocumentView* _sender,
                                                       ScratchServicesDocument* document,
                                                       gpointer self)
{
	__lambda194_ (self);
}

static void
__lambda195_ (ScratchMainWindow* self,
              ScratchServicesDocument* doc)
{
	ScratchFolderManagerItem* selected_item = NULL;
	ScratchFolderManagerFileView* _tmp0_;
	CodeWidgetsSourceListItem* _tmp1_;
	CodeWidgetsSourceListItem* _tmp2_;
	ScratchFolderManagerItem* _tmp3_;
	gboolean _tmp4_ = FALSE;
	ScratchFolderManagerItem* _tmp5_;
	g_return_if_fail (doc != NULL);
	scratch_main_window_update_find_actions (self);
	_tmp0_ = self->priv->folder_manager_view;
	_tmp1_ = code_widgets_source_list_get_selected ((CodeWidgetsSourceList*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, SCRATCH_FOLDER_MANAGER_TYPE_ITEM, ScratchFolderManagerItem));
	selected_item = _tmp3_;
	_tmp5_ = selected_item;
	if (_tmp5_ != NULL) {
		ScratchFolderManagerItem* _tmp6_;
		ScratchFolderManagerFile* _tmp7_;
		ScratchFolderManagerFile* _tmp8_;
		GFile* _tmp9_;
		GFile* _tmp10_;
		GFile* _tmp11_;
		GFile* _tmp12_;
		_tmp6_ = selected_item;
		_tmp7_ = scratch_folder_manager_item_get_file (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = scratch_folder_manager_file_get_file (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = scratch_services_document_get_file (doc);
		_tmp12_ = _tmp11_;
		_tmp4_ = g_file_equal (_tmp10_, _tmp12_);
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		ScratchFolderManagerFileView* _tmp13_;
		_tmp13_ = self->priv->folder_manager_view;
		code_widgets_source_list_set_selected ((CodeWidgetsSourceList*) _tmp13_, NULL);
	}
	_g_object_unref0 (selected_item);
}

static void
___lambda195__scratch_widgets_document_view_tab_removed (ScratchWidgetsDocumentView* _sender,
                                                         ScratchServicesDocument* document,
                                                         gpointer self)
{
	__lambda195_ ((ScratchMainWindow*) self, document);
}

static void
__lambda196_ (ScratchMainWindow* self,
              ScratchServicesDocument* doc)
{
	if (doc != NULL) {
		ScratchWidgetsSearchBar* _tmp0_;
		ScratchWidgetsSourceView* _tmp1_;
		ScratchWidgetsSourceView* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		ScratchHeaderBar* _tmp8_;
		ScratchFolderManagerFileView* _tmp9_;
		GFile* _tmp10_;
		GFile* _tmp11_;
		gchar* _tmp12_;
		gchar* _tmp13_;
		ScratchServicesPluginsManager* _tmp14_;
		GSimpleActionGroup* _tmp15_;
		GSimpleAction* _tmp16_;
		GSimpleAction* _tmp17_;
		GFile* _tmp18_;
		GFile* _tmp19_;
		_tmp0_ = self->search_bar;
		_tmp1_ = scratch_services_document_get_source_view (doc);
		_tmp2_ = _tmp1_;
		scratch_widgets_search_bar_set_text_view (_tmp0_, _tmp2_);
		_tmp3_ = scratch_services_document_get_basename (doc);
		_tmp4_ = _tmp3_;
		_tmp5_ = scratch_main_window_base_title;
		_tmp6_ = g_strdup_printf (_ ("%s - %s"), _tmp4_, _tmp5_);
		_tmp7_ = _tmp6_;
		gtk_window_set_title ((GtkWindow*) self, _tmp7_);
		_g_free0 (_tmp7_);
		_g_free0 (_tmp4_);
		_tmp8_ = self->toolbar;
		scratch_header_bar_set_document_focus (_tmp8_, doc);
		_tmp9_ = self->priv->folder_manager_view;
		_tmp10_ = scratch_services_document_get_file (doc);
		_tmp11_ = _tmp10_;
		_tmp12_ = g_file_get_path (_tmp11_);
		_tmp13_ = _tmp12_;
		scratch_folder_manager_file_view_select_path (_tmp9_, _tmp13_);
		_g_free0 (_tmp13_);
		_tmp14_ = self->priv->plugins;
		g_signal_emit_by_name (_tmp14_, "hook-document", doc);
		_tmp15_ = self->priv->_actions;
		_tmp16_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_SAVE_AS, _tmp15_);
		_tmp17_ = _tmp16_;
		_tmp18_ = scratch_services_document_get_file (doc);
		_tmp19_ = _tmp18_;
		g_simple_action_set_enabled (_tmp17_, _tmp19_ != NULL);
		_g_object_unref0 (_tmp17_);
		scratch_services_document_check_undoable_actions (doc);
	} else {
		const gchar* _tmp20_;
		GSimpleActionGroup* _tmp21_;
		GSimpleAction* _tmp22_;
		GSimpleAction* _tmp23_;
		_tmp20_ = scratch_main_window_base_title;
		gtk_window_set_title ((GtkWindow*) self, _tmp20_);
		_tmp21_ = self->priv->_actions;
		_tmp22_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_SAVE_AS, _tmp21_);
		_tmp23_ = _tmp22_;
		g_simple_action_set_enabled (_tmp23_, FALSE);
		_g_object_unref0 (_tmp23_);
	}
}

static void
___lambda196__scratch_widgets_document_view_document_change (ScratchWidgetsDocumentView* _sender,
                                                             ScratchServicesDocument* document,
                                                             ScratchWidgetsDocumentView* parent,
                                                             gpointer self)
{
	__lambda196_ ((ScratchMainWindow*) self, document);
}

static void
scratch_main_window_init_layout (ScratchMainWindow* self)
{
	Block2Data* _data2_;
	ScratchHeaderBar* _tmp0_;
	ScratchHeaderBar* _tmp1_;
	const gchar* _tmp2_;
	ScratchWidgetsSearchBar* _tmp3_;
	CodeWelcomeView* _tmp4_;
	ScratchWidgetsDocumentView* _tmp5_;
	GtkTargetEntry target = {0};
	GtkTargetEntry _tmp6_ = {0};
	CodeWelcomeView* _tmp7_;
	GtkTargetEntry _tmp8_;
	GtkTargetEntry* _tmp9_;
	GtkTargetEntry* _tmp10_;
	gint _tmp10__length1;
	CodeWelcomeView* _tmp11_;
	CodeSidebar* _tmp12_;
	ScratchServicesPluginsManager* _tmp13_;
	ScratchFolderManagerFileView* _tmp14_;
	CodeSidebar* _tmp15_;
	ScratchFolderManagerFileView* _tmp16_;
	ScratchFolderManagerFileView* _tmp17_;
	ScratchFolderManagerFileView* _tmp18_;
	ScratchFolderManagerFileView* _tmp19_;
	CodeTerminal* _tmp20_ = NULL;
	GtkGrid* _tmp21_ = NULL;
	ScratchWidgetsSearchBar* _tmp22_;
	ScratchWidgetsDocumentView* _tmp23_;
	GtkStack* _tmp24_ = NULL;
	GtkStack* _tmp25_;
	GtkStack* _tmp26_;
	CodeWelcomeView* _tmp27_;
	GtkStack* _tmp28_;
	gint width = 0;
	gint height = 0;
	gint _tmp29_ = 0;
	gint _tmp30_ = 0;
	GtkPaned* _tmp31_;
	GtkPaned* _tmp32_;
	GtkPaned* _tmp33_;
	GtkStack* _tmp34_;
	GtkPaned* _tmp35_;
	CodeTerminal* _tmp36_;
	GtkBox* box = NULL;
	GtkBox* _tmp37_;
	ScratchHeaderBar* _tmp38_;
	GtkPaned* _tmp39_;
	GtkPaned* _tmp40_;
	GtkPaned* _tmp41_;
	CodeSidebar* _tmp42_;
	GtkPaned* _tmp43_;
	GtkPaned* _tmp44_;
	HdyHeaderGroup* header_group = NULL;
	HdyHeaderGroup* _tmp45_;
	CodeSidebar* _tmp46_;
	HdyHeaderBar* _tmp47_;
	HdyHeaderBar* _tmp48_;
	ScratchHeaderBar* _tmp49_;
	GtkSizeGroup* size_group = NULL;
	GtkSizeGroup* _tmp50_;
	CodeSidebar* _tmp51_;
	HdyHeaderBar* _tmp52_;
	HdyHeaderBar* _tmp53_;
	ScratchHeaderBar* _tmp54_;
	ScratchWidgetsDocumentView* _tmp55_;
	ScratchWidgetsDocumentView* _tmp56_;
	ScratchWidgetsDocumentView* _tmp57_;
	ScratchWidgetsDocumentView* _tmp58_;
	ScratchWidgetsDocumentView* _tmp59_;
	g_return_if_fail (self != NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = scratch_header_bar_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->toolbar);
	self->toolbar = _tmp0_;
	_tmp1_ = self->toolbar;
	_tmp2_ = scratch_main_window_base_title;
	hdy_header_bar_set_title ((HdyHeaderBar*) _tmp1_, _tmp2_);
	_tmp3_ = scratch_widgets_search_bar_new (self);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->search_bar);
	self->search_bar = _tmp3_;
	_tmp4_ = code_welcome_view_new (self);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->welcome_view);
	self->priv->welcome_view = _tmp4_;
	_tmp5_ = scratch_widgets_document_view_new (self);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->document_view);
	self->document_view = _tmp5_;
	_tmp6_.target = "text/uri-list";
	_tmp6_.flags = (guint) 0;
	_tmp6_.info = (guint) 0;
	target = _tmp6_;
	_tmp7_ = self->priv->welcome_view;
	_tmp8_ = target;
	_tmp9_ = g_new0 (GtkTargetEntry, 1);
	_tmp9_[0] = _tmp8_;
	_tmp10_ = _tmp9_;
	_tmp10__length1 = 1;
	gtk_drag_dest_set ((GtkWidget*) _tmp7_, GTK_DEST_DEFAULT_ALL, _tmp10_, (gint) 1, GDK_ACTION_COPY);
	_tmp10_ = (g_free (_tmp10_), NULL);
	_tmp11_ = self->priv->welcome_view;
	g_signal_connect_object ((GtkWidget*) _tmp11_, "drag-data-received", (GCallback) ___lambda184__gtk_widget_drag_data_received, self, 0);
	_tmp12_ = code_sidebar_new ();
	g_object_ref_sink (_tmp12_);
	_g_object_unref0 (self->sidebar);
	self->sidebar = _tmp12_;
	_tmp13_ = self->priv->plugins;
	_tmp14_ = scratch_folder_manager_file_view_new (_tmp13_);
	g_object_ref_sink (_tmp14_);
	_g_object_unref0 (self->priv->folder_manager_view);
	self->priv->folder_manager_view = _tmp14_;
	_tmp15_ = self->sidebar;
	_tmp16_ = self->priv->folder_manager_view;
	code_sidebar_add_tab (_tmp15_, (CodePaneSwitcher*) _tmp16_);
	_tmp17_ = self->priv->folder_manager_view;
	gtk_widget_show_all ((GtkWidget*) _tmp17_);
	_tmp18_ = self->priv->folder_manager_view;
	g_signal_connect_object (_tmp18_, "activate", (GCallback) ___lambda185__scratch_folder_manager_file_view_activate, self, 0);
	_tmp19_ = self->priv->folder_manager_view;
	g_signal_connect_object (_tmp19_, "rename-request", (GCallback) ___lambda186__scratch_folder_manager_file_view_rename_request, self, 0);
	_tmp20_ = code_terminal_new ();
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp20_, TRUE);
	gtk_widget_set_visible ((GtkWidget*) _tmp20_, FALSE);
	g_object_ref_sink (_tmp20_);
	_g_object_unref0 (self->priv->terminal);
	self->priv->terminal = _tmp20_;
	_tmp21_ = (GtkGrid*) gtk_grid_new ();
	gtk_orientable_set_orientation ((GtkOrientable*) _tmp21_, GTK_ORIENTATION_VERTICAL);
	g_object_ref_sink (_tmp21_);
	_data2_->view_grid = _tmp21_;
	_tmp22_ = self->search_bar;
	gtk_container_add ((GtkContainer*) _data2_->view_grid, (GtkWidget*) _tmp22_);
	_tmp23_ = self->document_view;
	gtk_container_add ((GtkContainer*) _data2_->view_grid, (GtkWidget*) _tmp23_);
	_tmp24_ = (GtkStack*) gtk_stack_new ();
	g_object_set ((GtkWidget*) _tmp24_, "expand", TRUE, NULL);
	g_object_set ((GtkWidget*) _tmp24_, "width-request", 200, NULL);
	g_object_ref_sink (_tmp24_);
	_g_object_unref0 (self->priv->content_stack);
	self->priv->content_stack = _tmp24_;
	_tmp25_ = self->priv->content_stack;
	gtk_container_add ((GtkContainer*) _tmp25_, (GtkWidget*) _data2_->view_grid);
	_tmp26_ = self->priv->content_stack;
	_tmp27_ = self->priv->welcome_view;
	gtk_container_add ((GtkContainer*) _tmp26_, (GtkWidget*) _tmp27_);
	_tmp28_ = self->priv->content_stack;
	gtk_stack_set_visible_child (_tmp28_, (GtkWidget*) _data2_->view_grid);
	gtk_window_get_size ((GtkWindow*) self, &_tmp29_, &_tmp30_);
	width = _tmp29_;
	height = _tmp30_;
	_tmp31_ = (GtkPaned*) gtk_paned_new (GTK_ORIENTATION_VERTICAL);
	g_object_ref_sink (_tmp31_);
	_g_object_unref0 (self->priv->vp);
	self->priv->vp = _tmp31_;
	_tmp32_ = self->priv->vp;
	gtk_paned_set_position (_tmp32_, height - 150);
	_tmp33_ = self->priv->vp;
	_tmp34_ = self->priv->content_stack;
	gtk_paned_pack1 (_tmp33_, (GtkWidget*) _tmp34_, TRUE, FALSE);
	_tmp35_ = self->priv->vp;
	_tmp36_ = self->priv->terminal;
	gtk_paned_pack2 (_tmp35_, (GtkWidget*) _tmp36_, FALSE, FALSE);
	_tmp37_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp37_);
	box = _tmp37_;
	_tmp38_ = self->toolbar;
	gtk_container_add ((GtkContainer*) box, (GtkWidget*) _tmp38_);
	_tmp39_ = self->priv->vp;
	gtk_container_add ((GtkContainer*) box, (GtkWidget*) _tmp39_);
	_tmp40_ = (GtkPaned*) gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp40_);
	_g_object_unref0 (self->priv->hp1);
	self->priv->hp1 = _tmp40_;
	_tmp41_ = self->priv->hp1;
	_tmp42_ = self->sidebar;
	gtk_paned_pack1 (_tmp41_, (GtkWidget*) _tmp42_, FALSE, FALSE);
	_tmp43_ = self->priv->hp1;
	gtk_paned_pack2 (_tmp43_, (GtkWidget*) box, TRUE, FALSE);
	_tmp44_ = self->priv->hp1;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp44_);
	_tmp45_ = hdy_header_group_new ();
	header_group = _tmp45_;
	_tmp46_ = self->sidebar;
	_tmp47_ = code_sidebar_get_headerbar (_tmp46_);
	_tmp48_ = _tmp47_;
	hdy_header_group_add_header_bar (header_group, _tmp48_);
	_tmp49_ = self->toolbar;
	hdy_header_group_add_header_bar (header_group, (HdyHeaderBar*) _tmp49_);
	_tmp50_ = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
	size_group = _tmp50_;
	_tmp51_ = self->sidebar;
	_tmp52_ = code_sidebar_get_headerbar (_tmp51_);
	_tmp53_ = _tmp52_;
	gtk_size_group_add_widget (size_group, (GtkWidget*) _tmp53_);
	_tmp54_ = self->toolbar;
	gtk_size_group_add_widget (size_group, (GtkWidget*) _tmp54_);
	g_signal_connect_object ((GtkWidget*) self, "realize", (GCallback) ___lambda187__gtk_widget_realize, self, 0);
	_tmp55_ = self->document_view;
	g_signal_connect_object ((GtkWidget*) _tmp55_, "realize", (GCallback) ___lambda191__gtk_widget_realize, self, 0);
	_tmp56_ = self->document_view;
	g_signal_connect_object (_tmp56_, "request-placeholder", (GCallback) ___lambda193__scratch_widgets_document_view_request_placeholder, self, 0);
	_tmp57_ = self->document_view;
	g_signal_connect_data (_tmp57_, "tab-added", (GCallback) ___lambda194__scratch_widgets_document_view_tab_added, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	_tmp58_ = self->document_view;
	g_signal_connect_object (_tmp58_, "tab-removed", (GCallback) ___lambda195__scratch_widgets_document_view_tab_removed, self, 0);
	_tmp59_ = self->document_view;
	g_signal_connect_object (_tmp59_, "document-change", (GCallback) ___lambda196__scratch_widgets_document_view_document_change, self, 0);
	scratch_main_window_set_widgets_sensitive (self, FALSE);
	_g_object_unref0 (size_group);
	_g_object_unref0 (header_group);
	_g_object_unref0 (box);
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

static void
scratch_main_window_open_binary (ScratchMainWindow* self,
                                 GFile* file)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file != NULL);
	if (!g_file_query_exists (file, NULL)) {
		return;
	}
	{
		gchar* _tmp0_;
		gchar* _tmp1_;
		_tmp0_ = g_file_get_uri (file);
		_tmp1_ = _tmp0_;
		g_app_info_launch_default_for_uri (_tmp1_, NULL, &_inner_error0_);
		_g_free0 (_tmp1_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = e;
		_tmp3_ = _tmp2_->message;
		g_critical ("MainWindow.vala:659: %s", _tmp3_);
		_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;
	}
}

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

static void
scratch_main_window_restore_opened_documents (ScratchMainWindow* self,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	ScratchMainWindowRestoreOpenedDocumentsData* _data_;
	ScratchMainWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchMainWindowRestoreOpenedDocumentsData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_main_window_restore_opened_documents_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	scratch_main_window_restore_opened_documents_co (_data_);
}

static void
scratch_main_window_restore_opened_documents_finish (ScratchMainWindow* self,
                                                     GAsyncResult* _res_)
{
	ScratchMainWindowRestoreOpenedDocumentsData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
scratch_main_window_restore_opened_documents_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	ScratchMainWindowRestoreOpenedDocumentsData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_main_window_restore_opened_documents_co (_data_);
}

static gboolean
scratch_main_window_restore_opened_documents_co (ScratchMainWindowRestoreOpenedDocumentsData* _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_->focused_file = NULL;
	_data_->_tmp0_ = scratch_privacy_settings;
	if (g_settings_get_boolean (_data_->_tmp0_, "remember-recent-files")) {
		_data_->_tmp1_ = scratch_settings;
		_data_->_tmp2_ = g_settings_get_value (_data_->_tmp1_, "opened-files");
		_data_->doc_infos = _data_->_tmp2_;
		_data_->_tmp3_ = _data_->doc_infos;
		_data_->_tmp4_ = g_variant_iter_new (_data_->_tmp3_);
		_data_->doc_info_iter = _data_->_tmp4_;
		_data_->_tmp5_ = scratch_settings;
		_data_->_tmp6_ = g_settings_get_string (_data_->_tmp5_, "focused-document");
		_data_->focused_uri = _data_->_tmp6_;
		_data_->was_restore_overriden = FALSE;
		while (TRUE) {
			_data_->_tmp7_ = _data_->doc_info_iter;
			_data_->_tmp8_ = NULL;
			_data_->_tmp9_ = 0;
			_data_->_tmp10_ = g_variant_iter_next (_data_->_tmp7_, "(si)", &_data_->_tmp8_, &_data_->_tmp9_, NULL);
			_g_free0 (_data_->uri);
			_data_->uri = _data_->_tmp8_;
			_data_->pos = _data_->_tmp9_;
			if (!_data_->_tmp10_) {
				break;
			}
			_data_->_tmp11_ = _data_->uri;
			if (g_strcmp0 (_data_->_tmp11_, "") != 0) {
				_data_->_tmp12_ = _data_->uri;
				_data_->_tmp13_ = g_uri_parse_scheme (_data_->_tmp12_);
				_data_->_tmp14_ = _data_->_tmp13_;
				_data_->_tmp15_ = _data_->_tmp14_ != NULL;
				_g_free0 (_data_->_tmp14_);
				if (_data_->_tmp15_) {
					_data_->_tmp16_ = _data_->uri;
					_data_->_tmp17_ = g_file_new_for_uri (_data_->_tmp16_);
					_g_object_unref0 (_data_->file);
					_data_->file = _data_->_tmp17_;
				} else {
					_data_->_tmp18_ = _data_->uri;
					_data_->_tmp19_ = g_file_new_for_commandline_arg (_data_->_tmp18_);
					_g_object_unref0 (_data_->file);
					_data_->file = _data_->_tmp19_;
				}
				_data_->_tmp20_ = _data_->file;
				if (g_file_query_exists (_data_->_tmp20_, NULL)) {
					_data_->_tmp21_ = _data_->uri;
					_data_->_tmp22_ = _data_->focused_uri;
					_data_->is_focused = g_strcmp0 (_data_->_tmp21_, _data_->_tmp22_) == 0;
					if (_data_->is_focused) {
						_data_->_tmp23_ = _data_->file;
						_data_->_tmp24_ = _g_object_ref0 (_data_->_tmp23_);
						_g_object_unref0 (_data_->focused_file);
						_data_->focused_file = _data_->_tmp24_;
					}
					_data_->_tmp25_ = _data_->self->priv->_actions;
					_data_->_tmp26_ = _data_->file;
					_data_->_tmp27_ = scratch_services_document_new (_data_->_tmp25_, _data_->_tmp26_);
					g_object_ref_sink (_data_->_tmp27_);
					_data_->doc = _data_->_tmp27_;
					_data_->_tmp29_ = _data_->doc;
					if (scratch_services_document_exists (_data_->_tmp29_, NULL)) {
						_data_->_tmp28_ = TRUE;
					} else {
						_data_->_tmp30_ = _data_->doc;
						_data_->_tmp31_ = scratch_services_document_get_is_file_temporary (_data_->_tmp30_);
						_data_->_tmp32_ = _data_->_tmp31_;
						_data_->_tmp28_ = !_data_->_tmp32_;
					}
					if (_data_->_tmp28_) {
						_data_->_tmp34_ = _data_->self->priv->_restore_override;
						if (_data_->_tmp34_ != NULL) {
							_data_->_tmp35_ = _data_->file;
							_data_->_tmp36_ = g_file_get_path (_data_->_tmp35_);
							_data_->_tmp37_ = _data_->_tmp36_;
							_data_->_tmp38_ = _data_->self->priv->_restore_override;
							_data_->_tmp39_ = restore_override_get_file (_data_->_tmp38_);
							_data_->_tmp40_ = _data_->_tmp39_;
							_data_->_tmp41_ = g_file_get_path (_data_->_tmp40_);
							_data_->_tmp42_ = _data_->_tmp41_;
							_data_->_tmp33_ = g_strcmp0 (_data_->_tmp37_, _data_->_tmp42_) == 0;
							_g_free0 (_data_->_tmp42_);
							_g_free0 (_data_->_tmp37_);
						} else {
							_data_->_tmp33_ = FALSE;
						}
						if (_data_->_tmp33_) {
							_data_->_tmp43_ = _data_->doc;
							_data_->_tmp44_ = _data_->self->priv->_restore_override;
							memset (&_data_->_tmp45_, 0, sizeof (SelectionRange));
							restore_override_get_range (_data_->_tmp44_, &_data_->_tmp45_);
							_data_->_tmp46_ = _data_->_tmp45_;
							_data_->_state_ = 1;
							scratch_main_window_open_document_at_selected_range (_data_->self, _data_->_tmp43_, TRUE, &_data_->_tmp46_, TRUE, scratch_main_window_restore_opened_documents_ready, _data_);
							return FALSE;
							_state_1:
							scratch_main_window_open_document_at_selected_range_finish (_data_->self, _data_->_res_);
							_data_->was_restore_overriden = TRUE;
						} else {
							if (_data_->was_restore_overriden) {
								_data_->_tmp47_ = FALSE;
							} else {
								_data_->_tmp47_ = _data_->is_focused;
							}
							_data_->_tmp48_ = _data_->doc;
							_data_->_state_ = 2;
							scratch_main_window_open_document (_data_->self, _data_->_tmp48_, _data_->_tmp47_, _data_->pos, scratch_main_window_restore_opened_documents_ready, _data_);
							return FALSE;
							_state_2:
							scratch_main_window_open_document_finish (_data_->self, _data_->_res_);
						}
					}
					_g_object_unref0 (_data_->doc);
				}
				_g_object_unref0 (_data_->file);
			}
		}
		_g_free0 (_data_->uri);
		_g_free0 (_data_->focused_uri);
		_g_variant_iter_free0 (_data_->doc_info_iter);
		_g_variant_unref0 (_data_->doc_infos);
	}
	_data_->_tmp49_ = _data_->self->document_view;
	scratch_widgets_document_view_request_placeholder_if_empty (_data_->_tmp49_);
	_data_->_tmp50_ = _data_->self->document_view;
	scratch_widgets_document_view_update_outline_visible (_data_->_tmp50_);
	scratch_main_window_set_restore_override (_data_->self, NULL);
	_data_->_tmp51_ = _data_->focused_file;
	if (_data_->_tmp51_ != NULL) {
		_data_->_tmp52_ = _data_->self->priv->folder_manager_view;
		_data_->_tmp53_ = _data_->focused_file;
		_data_->_tmp54_ = g_file_get_path (_data_->_tmp53_);
		_data_->_tmp55_ = _data_->_tmp54_;
		scratch_folder_manager_file_view_expand_to_path (_data_->_tmp52_, _data_->_tmp55_);
		_g_free0 (_data_->_tmp55_);
	}
	_g_object_unref0 (_data_->focused_file);
	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 GVariant*
_variant_new1 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static gboolean
scratch_main_window_on_key_pressed (ScratchMainWindow* self,
                                    guint keyval,
                                    guint keycode,
                                    GdkModifierType state)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GQuark _tmp3_ = 0U;
	static GQuark _tmp2_label0 = 0;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = gdk_keyval_name (keyval);
	_tmp1_ = _tmp0_;
	_tmp3_ = (NULL == _tmp1_) ? 0 : g_quark_from_string (_tmp1_);
	if (_tmp3_ == ((0 != _tmp2_label0) ? _tmp2_label0 : (_tmp2_label0 = g_quark_from_static_string ("Escape")))) {
		switch (0) {
			default:
			{
				ScratchWidgetsSearchBar* _tmp4_;
				gboolean _tmp5_;
				gboolean _tmp6_;
				_tmp4_ = self->search_bar;
				_tmp5_ = scratch_widgets_search_bar_get_is_revealed (_tmp4_);
				_tmp6_ = _tmp5_;
				if (_tmp6_) {
					GSimpleAction* action = NULL;
					GSimpleActionGroup* _tmp7_;
					GSimpleAction* _tmp8_;
					GSimpleAction* _tmp9_;
					GVariant* _tmp10_;
					ScratchWidgetsDocumentView* _tmp11_;
					ScratchServicesDocument* _tmp12_;
					ScratchServicesDocument* _tmp13_;
					ScratchWidgetsSourceView* _tmp14_;
					ScratchWidgetsSourceView* _tmp15_;
					_tmp7_ = self->priv->_actions;
					_tmp8_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SHOW_FIND, _tmp7_);
					action = _tmp8_;
					_tmp9_ = action;
					_tmp10_ = _variant_new1 (FALSE);
					g_simple_action_set_state (_tmp9_, _tmp10_);
					_g_variant_unref0 (_tmp10_);
					_tmp11_ = self->document_view;
					_tmp12_ = scratch_widgets_document_view_get_current_document (_tmp11_);
					_tmp13_ = _tmp12_;
					_tmp14_ = scratch_services_document_get_source_view (_tmp13_);
					_tmp15_ = _tmp14_;
					gtk_widget_grab_focus ((GtkWidget*) _tmp15_);
					_g_object_unref0 (action);
				}
				break;
			}
		}
	}
	result = FALSE;
	return result;
}

static gboolean
scratch_main_window_real_delete_event (GtkWidget* base,
                                       GdkEventAny* event)
{
	ScratchMainWindow * self;
	gboolean result;
	self = (ScratchMainWindow*) base;
	g_return_val_if_fail (event != NULL, FALSE);
	scratch_main_window_action_close_window (self);
	result = TRUE;
	return result;
}

static void
scratch_main_window_set_widgets_sensitive (ScratchMainWindow* self,
                                           gboolean val)
{
	GSimpleActionGroup* _tmp0_;
	GSimpleAction* _tmp1_;
	GSimpleAction* _tmp2_;
	GSimpleActionGroup* _tmp3_;
	GSimpleAction* _tmp4_;
	GSimpleAction* _tmp5_;
	GSimpleActionGroup* _tmp6_;
	GSimpleAction* _tmp7_;
	GSimpleAction* _tmp8_;
	GSimpleActionGroup* _tmp9_;
	GSimpleAction* _tmp10_;
	GSimpleAction* _tmp11_;
	GSimpleActionGroup* _tmp12_;
	GSimpleAction* _tmp13_;
	GSimpleAction* _tmp14_;
	GSimpleActionGroup* _tmp15_;
	GSimpleAction* _tmp16_;
	GSimpleAction* _tmp17_;
	GSimpleActionGroup* _tmp18_;
	GSimpleAction* _tmp19_;
	GSimpleAction* _tmp20_;
	GSimpleActionGroup* _tmp21_;
	GSimpleAction* _tmp22_;
	GSimpleAction* _tmp23_;
	ScratchWidgetsSearchBar* _tmp24_;
	ScratchHeaderBar* _tmp25_;
	GtkMenuButton* _tmp26_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_actions;
	_tmp1_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SHOW_FIND, _tmp0_);
	_tmp2_ = _tmp1_;
	g_simple_action_set_enabled (_tmp2_, val);
	_g_object_unref0 (_tmp2_);
	_tmp3_ = self->priv->_actions;
	_tmp4_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_GO_TO, _tmp3_);
	_tmp5_ = _tmp4_;
	g_simple_action_set_enabled (_tmp5_, val);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = self->priv->_actions;
	_tmp7_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_SHOW_REPLACE, _tmp6_);
	_tmp8_ = _tmp7_;
	g_simple_action_set_enabled (_tmp8_, val);
	_g_object_unref0 (_tmp8_);
	_tmp9_ = self->priv->_actions;
	_tmp10_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_SAVE, _tmp9_);
	_tmp11_ = _tmp10_;
	g_simple_action_set_enabled (_tmp11_, val);
	_g_object_unref0 (_tmp11_);
	_tmp12_ = self->priv->_actions;
	_tmp13_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_SAVE_AS, _tmp12_);
	_tmp14_ = _tmp13_;
	g_simple_action_set_enabled (_tmp14_, val);
	_g_object_unref0 (_tmp14_);
	_tmp15_ = self->priv->_actions;
	_tmp16_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_UNDO, _tmp15_);
	_tmp17_ = _tmp16_;
	g_simple_action_set_enabled (_tmp17_, val);
	_g_object_unref0 (_tmp17_);
	_tmp18_ = self->priv->_actions;
	_tmp19_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_REDO, _tmp18_);
	_tmp20_ = _tmp19_;
	g_simple_action_set_enabled (_tmp20_, val);
	_g_object_unref0 (_tmp20_);
	_tmp21_ = self->priv->_actions;
	_tmp22_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_REVERT, _tmp21_);
	_tmp23_ = _tmp22_;
	g_simple_action_set_enabled (_tmp23_, val);
	_g_object_unref0 (_tmp23_);
	_tmp24_ = self->search_bar;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp24_, val);
	_tmp25_ = self->toolbar;
	_tmp26_ = _tmp25_->share_menu_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp26_, val);
}

ScratchServicesDocument*
scratch_main_window_get_current_document (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchServicesDocument* _tmp3_;
	ScratchServicesDocument* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->document_view;
	_tmp1_ = scratch_widgets_document_view_get_current_document (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

ScratchServicesDocument*
scratch_main_window_get_focused_document (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchServicesDocument* _tmp3_;
	ScratchServicesDocument* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->document_view;
	_tmp1_ = scratch_widgets_document_view_get_current_document (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

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

void
scratch_main_window_set_selected_text_for_search (ScratchMainWindow* self)
{
	ScratchWidgetsSearchBar* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp3_;
	gchar* _tmp4_ = NULL;
	ScratchServicesDocument* _tmp5_;
	gchar* selected_text = NULL;
	gchar* _tmp9_;
	gchar* search_term = NULL;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp20_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->search_bar;
	_tmp1_ = scratch_widgets_search_bar_get_is_focused (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		return;
	}
	_tmp3_ = scratch_main_window_get_current_document (self);
	doc = _tmp3_;
	_tmp5_ = doc;
	if (_tmp5_ != NULL) {
		ScratchServicesDocument* _tmp6_;
		gchar* _tmp7_;
		_tmp6_ = doc;
		_tmp7_ = scratch_services_document_get_selected_text (_tmp6_, FALSE);
		_g_free0 (_tmp4_);
		_tmp4_ = _tmp7_;
	} else {
		gchar* _tmp8_;
		_tmp8_ = g_strdup ("");
		_g_free0 (_tmp4_);
		_tmp4_ = _tmp8_;
	}
	_tmp9_ = _tmp4_;
	_tmp4_ = NULL;
	selected_text = _tmp9_;
	_tmp10_ = g_strdup ("");
	search_term = _tmp10_;
	_tmp11_ = selected_text;
	if (string_contains (_tmp11_, "\n")) {
		const gchar* _tmp12_;
		gchar** _tmp13_;
		gchar** _tmp14_;
		gchar** _tmp15_;
		gint _tmp15__length1;
		const gchar* _tmp16_;
		gchar* _tmp17_;
		_tmp12_ = selected_text;
		_tmp14_ = _tmp13_ = g_strsplit (_tmp12_, "\n", 2);
		_tmp15_ = _tmp14_;
		_tmp15__length1 = _vala_array_length (_tmp13_);
		_tmp16_ = _tmp15_[0];
		_tmp17_ = g_strdup (_tmp16_);
		_g_free0 (search_term);
		search_term = _tmp17_;
		_tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL);
	} else {
		const gchar* _tmp18_;
		gchar* _tmp19_;
		_tmp18_ = selected_text;
		_tmp19_ = g_strdup (_tmp18_);
		_g_free0 (search_term);
		search_term = _tmp19_;
	}
	_tmp20_ = search_term;
	if (g_strcmp0 (_tmp20_, "") != 0) {
		ScratchWidgetsSearchBar* _tmp21_;
		const gchar* _tmp22_;
		_tmp21_ = self->search_bar;
		_tmp22_ = search_term;
		scratch_widgets_search_bar_set_search_entry_text (_tmp21_, _tmp22_);
	}
	_g_free0 (search_term);
	_g_free0 (selected_text);
	_g_free0 (_tmp4_);
	_g_object_unref0 (doc);
}

gboolean
scratch_main_window_has_successful_search (ScratchMainWindow* self)
{
	ScratchWidgetsSearchBar* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->search_bar;
	_tmp1_ = scratch_widgets_search_bar_get_search_occurrences (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_ > ((guint) 0);
	return result;
}

void
scratch_main_window_open_folder (ScratchMainWindow* self,
                                 GFile* folder)
{
	ScratchFolderManagerFile* foldermanager_file = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	ScratchFolderManagerFile* _tmp2_;
	ScratchFolderManagerFile* _tmp3_;
	ScratchFolderManagerFileView* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (folder != NULL);
	_tmp0_ = g_file_get_path (folder);
	_tmp1_ = _tmp0_;
	_tmp2_ = scratch_folder_manager_file_new (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	foldermanager_file = _tmp3_;
	_tmp4_ = self->priv->folder_manager_view;
	scratch_folder_manager_file_view_open_folder (_tmp4_, foldermanager_file);
	_g_object_unref0 (foldermanager_file);
}

static void
scratch_main_window_open_document_data_free (gpointer _data)
{
	ScratchMainWindowOpenDocumentData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->doc);
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchMainWindowOpenDocumentData, _data_);
}

void
scratch_main_window_open_document (ScratchMainWindow* self,
                                   ScratchServicesDocument* doc,
                                   gboolean focus,
                                   gint cursor_position,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	ScratchMainWindowOpenDocumentData* _data_;
	ScratchMainWindow* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (doc != NULL);
	_data_ = g_slice_new0 (ScratchMainWindowOpenDocumentData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_main_window_open_document_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (doc);
	_g_object_unref0 (_data_->doc);
	_data_->doc = _tmp1_;
	_data_->focus = focus;
	_data_->cursor_position = cursor_position;
	scratch_main_window_open_document_co (_data_);
}

void
scratch_main_window_open_document_finish (ScratchMainWindow* self,
                                          GAsyncResult* _res_)
{
	ScratchMainWindowOpenDocumentData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
scratch_main_window_open_document_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	ScratchMainWindowOpenDocumentData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_main_window_open_document_co (_data_);
}

static gboolean
scratch_main_window_open_document_co (ScratchMainWindowOpenDocumentData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->folder_manager_view;
	_data_->_tmp1_ = scratch_services_document_get_file (_data_->doc);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = scratch_folder_manager_file_view_get_project_for_file (_data_->_tmp0_, _data_->_tmp2_);
	_data_->project = _data_->_tmp3_;
	_data_->_tmp4_ = scratch_services_document_get_source_view (_data_->doc);
	_data_->_tmp5_ = _data_->_tmp4_;
	scratch_widgets_source_view_set_project (_data_->_tmp5_, _data_->project);
	_data_->_tmp6_ = _data_->self->document_view;
	_data_->_state_ = 1;
	scratch_widgets_document_view_open_document (_data_->_tmp6_, _data_->doc, _data_->focus, _data_->cursor_position, &SELECTION_RANGE_EMPTY, scratch_main_window_open_document_ready, _data_);
	return FALSE;
	_state_1:
	scratch_widgets_document_view_open_document_finish (_data_->_tmp6_, _data_->_res_);
	_g_object_unref0 (_data_->project);
	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_main_window_open_document_at_selected_range_data_free (gpointer _data)
{
	ScratchMainWindowOpenDocumentAtSelectedRangeData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->doc);
	_g_object_unref0 (_data_->self);
	g_slice_free (ScratchMainWindowOpenDocumentAtSelectedRangeData, _data_);
}

void
scratch_main_window_open_document_at_selected_range (ScratchMainWindow* self,
                                                     ScratchServicesDocument* doc,
                                                     gboolean focus,
                                                     SelectionRange* range,
                                                     gboolean is_override,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	ScratchMainWindowOpenDocumentAtSelectedRangeData* _data_;
	ScratchMainWindow* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	SelectionRange _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (doc != NULL);
	g_return_if_fail (range != NULL);
	_data_ = g_slice_new0 (ScratchMainWindowOpenDocumentAtSelectedRangeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_main_window_open_document_at_selected_range_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (doc);
	_g_object_unref0 (_data_->doc);
	_data_->doc = _tmp1_;
	_data_->focus = focus;
	_tmp2_ = *range;
	_data_->range = _tmp2_;
	_data_->is_override = is_override;
	scratch_main_window_open_document_at_selected_range_co (_data_);
}

void
scratch_main_window_open_document_at_selected_range_finish (ScratchMainWindow* self,
                                                            GAsyncResult* _res_)
{
	ScratchMainWindowOpenDocumentAtSelectedRangeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
scratch_main_window_open_document_at_selected_range_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_)
{
	ScratchMainWindowOpenDocumentAtSelectedRangeData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_main_window_open_document_at_selected_range_co (_data_);
}

static gboolean
scratch_main_window_open_document_at_selected_range_co (ScratchMainWindowOpenDocumentAtSelectedRangeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = _data_->self->priv->_restore_override;
	if (_data_->_tmp1_ != NULL) {
		_data_->_tmp0_ = _data_->is_override == FALSE;
	} else {
		_data_->_tmp0_ = FALSE;
	}
	if (_data_->_tmp0_) {
		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_ = scratch_services_document_get_source_view (_data_->doc);
	_data_->_tmp3_ = _data_->_tmp2_;
	_data_->_tmp4_ = _data_->self->priv->folder_manager_view;
	_data_->_tmp5_ = scratch_services_document_get_file (_data_->doc);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = scratch_folder_manager_file_view_get_project_for_file (_data_->_tmp4_, _data_->_tmp6_);
	_data_->_tmp8_ = _data_->_tmp7_;
	scratch_widgets_source_view_set_project (_data_->_tmp3_, _data_->_tmp8_);
	_g_object_unref0 (_data_->_tmp8_);
	_data_->_tmp9_ = _data_->self->document_view;
	_data_->_tmp10_ = _data_->range;
	_data_->_state_ = 1;
	scratch_widgets_document_view_open_document (_data_->_tmp9_, _data_->doc, _data_->focus, 0, &_data_->_tmp10_, scratch_main_window_open_document_at_selected_range_ready, _data_);
	return FALSE;
	_state_1:
	scratch_widgets_document_view_open_document_finish (_data_->_tmp9_, _data_->_res_);
	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_main_window_close_document (ScratchMainWindow* self,
                                    ScratchServicesDocument* doc)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (doc != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_close_document (_tmp0_, doc);
}

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

void
scratch_main_window_check_unsaved_changes (ScratchMainWindow* self,
                                           gboolean app_closing,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	ScratchMainWindowCheckUnsavedChangesData* _data_;
	ScratchMainWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (ScratchMainWindowCheckUnsavedChangesData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, scratch_main_window_check_unsaved_changes_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->app_closing = app_closing;
	scratch_main_window_check_unsaved_changes_co (_data_);
}

gboolean
scratch_main_window_check_unsaved_changes_finish (ScratchMainWindow* self,
                                                  GAsyncResult* _res_)
{
	gboolean result;
	ScratchMainWindowCheckUnsavedChangesData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
scratch_main_window_check_unsaved_changes_ready (GObject* source_object,
                                                 GAsyncResult* _res_,
                                                 gpointer _user_data_)
{
	ScratchMainWindowCheckUnsavedChangesData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	scratch_main_window_check_unsaved_changes_co (_data_);
}

static gboolean
scratch_main_window_check_unsaved_changes_co (ScratchMainWindowCheckUnsavedChangesData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->document_view;
	_data_->_tmp0_->is_closing = TRUE;
	_data_->_tmp1_ = _data_->self->document_view;
	_data_->_tmp2_ = _data_->_tmp1_->docs;
	{
		_data_->doc_collection = _data_->_tmp2_;
		for (_data_->doc_it = _data_->doc_collection; _data_->doc_it != NULL; _data_->doc_it = _data_->doc_it->next) {
			_data_->_tmp3_ = _g_object_ref0 ((ScratchServicesDocument*) _data_->doc_it->data);
			_data_->doc = _data_->_tmp3_;
			{
				_data_->_tmp4_ = _data_->doc;
				_data_->_state_ = 1;
				scratch_services_document_do_close (_data_->_tmp4_, _data_->app_closing, scratch_main_window_check_unsaved_changes_ready, _data_);
				return FALSE;
				_state_1:
				if (!scratch_services_document_do_close_finish (_data_->_tmp4_, _data_->_res_)) {
					_data_->_tmp5_ = _data_->self->document_view;
					_data_->_tmp6_ = _data_->doc;
					scratch_widgets_document_view_set_current_document (_data_->_tmp5_, _data_->_tmp6_);
					_data_->result = FALSE;
					_g_object_unref0 (_data_->doc);
					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_object_unref0 (_data_->doc);
			}
		}
	}
	_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;
}

static void
__lambda190_ (ScratchMainWindow* self,
              GObject* obj,
              GAsyncResult* res)
{
	ScratchFolderManagerFileView* _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (res != NULL);
	_tmp0_ = self->priv->folder_manager_view;
	scratch_folder_manager_file_view_restore_saved_state_finish (_tmp0_, res);
	_tmp1_ = self->priv->_restore_docs;
	if (_tmp1_) {
		scratch_main_window_restore_opened_documents (self, NULL, NULL);
	}
}

static void
___lambda190__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	__lambda190_ ((ScratchMainWindow*) self, source_object, res);
	g_object_unref (self);
}

static void
scratch_main_window_restore (ScratchMainWindow* self)
{
	GtkPaned* _tmp0_;
	GSettings* _tmp1_;
	GtkPaned* _tmp2_;
	GSettings* _tmp3_;
	ScratchFolderManagerFileView* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->hp1;
	_tmp1_ = scratch_saved_state;
	gtk_paned_set_position (_tmp0_, g_settings_get_int (_tmp1_, "hp1-size"));
	_tmp2_ = self->priv->vp;
	_tmp3_ = scratch_saved_state;
	gtk_paned_set_position (_tmp2_, g_settings_get_int (_tmp3_, "vp-size"));
	_tmp4_ = self->priv->folder_manager_view;
	scratch_folder_manager_file_view_restore_saved_state (_tmp4_, ___lambda190__gasync_ready_callback, g_object_ref (self));
}

static void
scratch_main_window_create_unsaved_documents_directory (ScratchMainWindow* self)
{
	GFile* directory = NULL;
	ScratchApplication* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_app;
	_tmp1_ = scratch_application_get_data_home_folder_unsaved (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_file_new_for_path (_tmp2_);
	directory = _tmp3_;
	_tmp4_ = directory;
	if (!g_file_query_exists (_tmp4_, NULL)) {
		{
			GFile* _tmp5_;
			GFile* _tmp6_;
			gchar* _tmp7_;
			gchar* _tmp8_;
			_tmp5_ = directory;
			g_file_make_directory_with_parents (_tmp5_, NULL, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp6_ = directory;
			_tmp7_ = g_file_get_path (_tmp6_);
			_tmp8_ = _tmp7_;
			g_debug ("MainWindow.vala:846: created 'unsaved' directory: %s", _tmp8_);
			_g_free0 (_tmp8_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GFile* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			GError* _tmp12_;
			const gchar* _tmp13_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp9_ = directory;
			_tmp10_ = g_file_get_path (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = e;
			_tmp13_ = _tmp12_->message;
			g_critical ("MainWindow.vala:848: Unable to create the 'unsaved' directory: '%s': %" \
"s", _tmp11_, _tmp13_);
			_g_free0 (_tmp11_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (directory);
			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 (directory);
}

static void
scratch_main_window_update_window_state_setting (ScratchMainWindow* self)
{
	GdkWindowState state = 0U;
	GdkWindow* _tmp0_;
	GSettings* _tmp7_;
	GtkPaned* _tmp8_;
	GSettings* _tmp9_;
	GtkPaned* _tmp10_;
	CodeTerminal* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_window ((GtkWidget*) self);
	state = gdk_window_get_state (_tmp0_);
	if ((state & GDK_WINDOW_STATE_MAXIMIZED) == GDK_WINDOW_STATE_MAXIMIZED) {
		GSettings* _tmp1_;
		_tmp1_ = scratch_saved_state;
		g_settings_set_enum (_tmp1_, "window-state", (gint) SCRATCH_SCRATCH_WINDOW_STATE_MAXIMIZED);
	} else {
		if ((state & GDK_WINDOW_STATE_FULLSCREEN) == GDK_WINDOW_STATE_FULLSCREEN) {
			GSettings* _tmp2_;
			_tmp2_ = scratch_saved_state;
			g_settings_set_enum (_tmp2_, "window-state", (gint) SCRATCH_SCRATCH_WINDOW_STATE_FULLSCREEN);
		} else {
			GSettings* _tmp3_;
			gint width = 0;
			gint height = 0;
			gint _tmp4_ = 0;
			gint _tmp5_ = 0;
			GSettings* _tmp6_;
			_tmp3_ = scratch_saved_state;
			g_settings_set_enum (_tmp3_, "window-state", (gint) SCRATCH_SCRATCH_WINDOW_STATE_NORMAL);
			gtk_window_get_size ((GtkWindow*) self, &_tmp4_, &_tmp5_);
			width = _tmp4_;
			height = _tmp5_;
			_tmp6_ = scratch_saved_state;
			g_settings_set (_tmp6_, "window-size", "(ii)", width, height);
		}
	}
	_tmp7_ = scratch_saved_state;
	_tmp8_ = self->priv->hp1;
	g_settings_set_int (_tmp7_, "hp1-size", gtk_paned_get_position (_tmp8_));
	_tmp9_ = scratch_saved_state;
	_tmp10_ = self->priv->vp;
	g_settings_set_int (_tmp9_, "vp-size", gtk_paned_get_position (_tmp10_));
	_tmp11_ = self->priv->terminal;
	code_terminal_save_settings (_tmp11_);
}

gboolean
scratch_main_window_quit_source_func (ScratchMainWindow* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	scratch_main_window_action_quit_app (self);
	result = FALSE;
	return result;
}

void
scratch_main_window_before_quit (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_update_opened_files_setting (_tmp0_);
	scratch_main_window_update_window_state_setting (self);
}

static gchar*
double_to_string (gdouble self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp1__length1;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = G_ASCII_DTOSTR_BUF_SIZE;
	_tmp2_ = g_ascii_dtostr (_tmp1_, (gint) G_ASCII_DTOSTR_BUF_SIZE, self);
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	result = _tmp4_;
	return result;
}

void
scratch_main_window_set_default_zoom (ScratchMainWindow* self)
{
	CodeTerminal* _tmp0_;
	GSettings* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->terminal;
	code_terminal_set_default_font_size (_tmp0_);
	_tmp1_ = scratch_settings;
	_tmp2_ = scratch_main_window_get_current_font (self);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, " ", NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = double_to_string (scratch_main_window_get_default_font_size (self));
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strconcat (_tmp5_, _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	g_settings_set_string (_tmp1_, "font", _tmp9_);
	_g_free0 (_tmp9_);
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
}

void
scratch_main_window_action_zoom_in (ScratchMainWindow* self)
{
	CodeTerminal* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->terminal;
	code_terminal_increment_size (_tmp0_);
	scratch_main_window_zooming (self, GDK_SCROLL_UP);
}

void
scratch_main_window_action_zoom_out (ScratchMainWindow* self)
{
	CodeTerminal* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->terminal;
	code_terminal_decrement_size (_tmp0_);
	scratch_main_window_zooming (self, GDK_SCROLL_DOWN);
}

static void
scratch_main_window_zooming (ScratchMainWindow* self,
                             GdkScrollDirection direction)
{
	gchar* font = NULL;
	gchar* _tmp0_;
	gint font_size = 0;
	GSettings* _tmp1_;
	gchar* new_font = NULL;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GSettings* _tmp13_;
	const gchar* _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_current_font (self);
	font = _tmp0_;
	font_size = (gint) scratch_main_window_get_current_font_size (self);
	_tmp1_ = scratch_settings;
	if (g_settings_get_boolean (_tmp1_, "use-system-font")) {
		GSettings* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = scratch_settings;
		g_settings_set_boolean (_tmp2_, "use-system-font", FALSE);
		_tmp3_ = scratch_main_window_get_default_font (self);
		_g_free0 (font);
		font = _tmp3_;
		font_size = (gint) scratch_main_window_get_default_font_size (self);
	}
	if (direction == GDK_SCROLL_DOWN) {
		gint _tmp4_;
		_tmp4_ = font_size;
		font_size = _tmp4_ - 1;
		if (font_size < SCRATCH_MAIN_WINDOW_FONT_SIZE_MIN) {
			_g_free0 (font);
			return;
		}
	} else {
		if (direction == GDK_SCROLL_UP) {
			gint _tmp5_;
			_tmp5_ = font_size;
			font_size = _tmp5_ + 1;
			if (font_size > SCRATCH_MAIN_WINDOW_FONT_SIZE_MAX) {
				_g_free0 (font);
				return;
			}
		}
	}
	_tmp6_ = font;
	_tmp7_ = g_strconcat (_tmp6_, " ", NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_strdup_printf ("%i", font_size);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_strconcat (_tmp8_, _tmp10_, NULL);
	_tmp12_ = _tmp11_;
	_g_free0 (_tmp10_);
	_g_free0 (_tmp8_);
	new_font = _tmp12_;
	_tmp13_ = scratch_settings;
	_tmp14_ = new_font;
	g_settings_set_string (_tmp13_, "font", _tmp14_);
	_g_free0 (new_font);
	_g_free0 (font);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

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

static gint
string_last_index_of (const gchar* self,
                      const gchar* needle,
                      gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = g_strrstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

gchar*
scratch_main_window_get_current_font (ScratchMainWindow* self)
{
	gchar* font = NULL;
	GSettings* _tmp0_;
	gchar* _tmp1_;
	gchar* font_family = NULL;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = scratch_settings;
	_tmp1_ = g_settings_get_string (_tmp0_, "font");
	font = _tmp1_;
	_tmp2_ = string_substring (font, (glong) 0, (glong) string_last_index_of (font, " ", 0));
	font_family = _tmp2_;
	result = font_family;
	_g_free0 (font);
	return result;
}

static gdouble
double_parse (const gchar* str)
{
	gdouble result;
	g_return_val_if_fail (str != NULL, -1.0);
	result = g_ascii_strtod (str, NULL);
	return result;
}

gdouble
scratch_main_window_get_current_font_size (ScratchMainWindow* self)
{
	gchar* font = NULL;
	GSettings* _tmp0_;
	gchar* _tmp1_;
	gchar* font_size = NULL;
	gchar* _tmp2_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = scratch_settings;
	_tmp1_ = g_settings_get_string (_tmp0_, "font");
	font = _tmp1_;
	_tmp2_ = string_substring (font, (glong) (string_last_index_of (font, " ", 0) + 1), (glong) -1);
	font_size = _tmp2_;
	result = double_parse (font_size);
	_g_free0 (font_size);
	_g_free0 (font);
	return result;
}

gchar*
scratch_main_window_get_default_font (ScratchMainWindow* self)
{
	gchar* font = NULL;
	ScratchApplication* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* font_family = NULL;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_app;
	_tmp1_ = scratch_application_get_system_document_font (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	font = _tmp3_;
	_tmp4_ = string_substring (font, (glong) 0, (glong) string_last_index_of (font, " ", 0));
	font_family = _tmp4_;
	result = font_family;
	_g_free0 (font);
	return result;
}

gdouble
scratch_main_window_get_default_font_size (ScratchMainWindow* self)
{
	gchar* font = NULL;
	ScratchApplication* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* font_size = NULL;
	gchar* _tmp4_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->_app;
	_tmp1_ = scratch_application_get_system_document_font (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	font = _tmp3_;
	_tmp4_ = string_substring (font, (glong) (string_last_index_of (font, " ", 0) + 1), (glong) -1);
	font_size = _tmp4_;
	result = double_parse (font_size);
	_g_free0 (font_size);
	_g_free0 (font);
	return result;
}

static void
scratch_main_window_action_set_default_zoom (ScratchMainWindow* self)
{
	g_return_if_fail (self != NULL);
	scratch_main_window_set_default_zoom (self);
}

static void
___lambda178_ (ScratchMainWindow* self)
{
	_g_object_unref0 (self->priv->preferences_dialog);
	self->priv->preferences_dialog = NULL;
}

static void
____lambda178__gtk_widget_destroy (GtkWidget* _sender,
                                   gpointer self)
{
	___lambda178_ ((ScratchMainWindow*) self);
}

static void
scratch_main_window_action_preferences (ScratchMainWindow* self)
{
	GraniteDialog* _tmp0_;
	GraniteDialog* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->preferences_dialog;
	if (_tmp0_ == NULL) {
		ScratchServicesPluginsManager* _tmp1_;
		ScratchDialogsPreferences* _tmp2_;
		GraniteDialog* _tmp3_;
		GraniteDialog* _tmp4_;
		_tmp1_ = self->priv->plugins;
		_tmp2_ = scratch_dialogs_preferences_new ((GtkWindow*) self, _tmp1_);
		g_object_ref_sink (_tmp2_);
		_g_object_unref0 (self->priv->preferences_dialog);
		self->priv->preferences_dialog = (GraniteDialog*) _tmp2_;
		_tmp3_ = self->priv->preferences_dialog;
		gtk_widget_show_all ((GtkWidget*) _tmp3_);
		_tmp4_ = self->priv->preferences_dialog;
		g_signal_connect_object ((GtkWidget*) _tmp4_, "destroy", (GCallback) ____lambda178__gtk_widget_destroy, self, 0);
	}
	_tmp5_ = self->priv->preferences_dialog;
	gtk_window_present ((GtkWindow*) _tmp5_);
}

static void
scratch_main_window_action_close_window (ScratchMainWindow* self)
{
	ScratchApplication* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_app;
	scratch_application_handle_quit_window (_tmp0_, self, NULL, NULL);
}

static void
scratch_main_window_action_quit_app (ScratchMainWindow* self)
{
	ScratchApplication* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_app;
	scratch_application_handle_quit_app (_tmp0_, NULL, NULL);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static inline void
_g_slist_free__g_free0_ (GSList* self)
{
	g_slist_free_full (self, (GDestroyNotify) _g_free0_);
}

static void
scratch_main_window_action_open (ScratchMainWindow* self)
{
	GtkFileFilter* all_files_filter = NULL;
	GtkFileFilter* _tmp0_;
	GtkFileFilter* _tmp1_;
	GtkFileFilter* _tmp2_;
	GtkFileFilter* text_files_filter = NULL;
	GtkFileFilter* _tmp3_;
	GtkFileFilter* _tmp4_;
	GtkFileFilter* _tmp5_;
	GtkFileChooserNative* file_chooser = NULL;
	GtkFileChooserNative* _tmp6_;
	GtkFileChooserNative* _tmp7_;
	GtkFileFilter* _tmp8_;
	GtkFileFilter* _tmp9_;
	GtkFileChooserNative* _tmp10_;
	GtkFileFilter* _tmp11_;
	GtkFileFilter* _tmp12_;
	GtkFileChooserNative* _tmp13_;
	const gchar* _tmp14_ = NULL;
	const gchar* _tmp15_;
	GtkFileChooserNative* _tmp17_;
	gint response = 0;
	GtkFileChooserNative* _tmp18_;
	GtkFileChooserNative* _tmp19_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_file_filter_new ();
	g_object_ref_sink (_tmp0_);
	all_files_filter = _tmp0_;
	_tmp1_ = all_files_filter;
	gtk_file_filter_set_name (_tmp1_, _ ("All files"));
	_tmp2_ = all_files_filter;
	gtk_file_filter_add_pattern (_tmp2_, "*");
	_tmp3_ = gtk_file_filter_new ();
	g_object_ref_sink (_tmp3_);
	text_files_filter = _tmp3_;
	_tmp4_ = text_files_filter;
	gtk_file_filter_set_name (_tmp4_, _ ("Text files"));
	_tmp5_ = text_files_filter;
	gtk_file_filter_add_mime_type (_tmp5_, "text/*");
	_tmp6_ = gtk_file_chooser_native_new (_ ("Open some files"), (GtkWindow*) self, GTK_FILE_CHOOSER_ACTION_OPEN, _ ("Open"), _ ("Cancel"));
	file_chooser = _tmp6_;
	_tmp7_ = file_chooser;
	_tmp8_ = text_files_filter;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	gtk_file_chooser_add_filter ((GtkFileChooser*) _tmp7_, _tmp9_);
	_tmp10_ = file_chooser;
	_tmp11_ = all_files_filter;
	_tmp12_ = _g_object_ref0 (_tmp11_);
	gtk_file_chooser_add_filter ((GtkFileChooser*) _tmp10_, _tmp12_);
	_tmp13_ = file_chooser;
	gtk_file_chooser_set_select_multiple ((GtkFileChooser*) _tmp13_, TRUE);
	_tmp15_ = scratch_utils_last_path;
	_tmp14_ = _tmp15_;
	if (_tmp14_ == NULL) {
		const gchar* _tmp16_;
		_tmp16_ = g_get_home_dir ();
		_tmp14_ = _tmp16_;
	}
	_tmp17_ = file_chooser;
	gtk_file_chooser_set_current_folder_uri ((GtkFileChooser*) _tmp17_, _tmp14_);
	_tmp18_ = file_chooser;
	response = gtk_native_dialog_run ((GtkNativeDialog*) _tmp18_);
	_tmp19_ = file_chooser;
	gtk_native_dialog_destroy ((GtkNativeDialog*) _tmp19_);
	if (response == ((gint) GTK_RESPONSE_ACCEPT)) {
		GtkFileChooserNative* _tmp20_;
		GSList* _tmp21_;
		_tmp20_ = file_chooser;
		_tmp21_ = gtk_file_chooser_get_uris ((GtkFileChooser*) _tmp20_);
		{
			GSList* uri_collection = NULL;
			GSList* uri_it = NULL;
			uri_collection = _tmp21_;
			for (uri_it = uri_collection; uri_it != NULL; uri_it = uri_it->next) {
				gchar* _tmp22_;
				gchar* uri = NULL;
				_tmp22_ = g_strdup ((const gchar*) uri_it->data);
				uri = _tmp22_;
				{
					const gchar* _tmp23_;
					gchar* _tmp24_;
					GFile* file = NULL;
					const gchar* _tmp25_;
					GFile* _tmp26_;
					ScratchServicesDocument* doc = NULL;
					GSimpleActionGroup* _tmp27_;
					GFile* _tmp28_;
					ScratchServicesDocument* _tmp29_;
					ScratchServicesDocument* _tmp30_;
					_tmp23_ = uri;
					_tmp24_ = g_path_get_dirname (_tmp23_);
					_g_free0 (scratch_utils_last_path);
					scratch_utils_last_path = _tmp24_;
					_tmp25_ = uri;
					_tmp26_ = g_file_new_for_uri (_tmp25_);
					file = _tmp26_;
					_tmp27_ = self->priv->_actions;
					_tmp28_ = file;
					_tmp29_ = scratch_services_document_new (_tmp27_, _tmp28_);
					g_object_ref_sink (_tmp29_);
					doc = _tmp29_;
					_tmp30_ = doc;
					scratch_main_window_open_document (self, _tmp30_, TRUE, 0, NULL, NULL);
					_g_object_unref0 (doc);
					_g_object_unref0 (file);
					_g_free0 (uri);
				}
			}
			(uri_collection == NULL) ? NULL : (uri_collection = (_g_slist_free__g_free0_ (uri_collection), NULL));
		}
	}
	_g_object_unref0 (file_chooser);
	_g_object_unref0 (text_files_filter);
	_g_object_unref0 (all_files_filter);
}

static void
scratch_main_window_action_open_in_new_window (ScratchMainWindow* self,
                                               GSimpleAction* action,
                                               GVariant* param)
{
	gchar* path = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	ScratchMainWindow* new_window = NULL;
	ScratchMainWindow* _tmp3_;
	GFile* file = NULL;
	const gchar* _tmp4_;
	GFile* _tmp5_;
	ScratchServicesDocument* doc = NULL;
	ScratchMainWindow* _tmp6_;
	GSimpleActionGroup* _tmp7_;
	GFile* _tmp8_;
	ScratchServicesDocument* _tmp9_;
	ScratchMainWindow* _tmp10_;
	ScratchServicesDocument* _tmp11_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = g_variant_get_string (param, NULL);
	_tmp1_ = g_strdup (_tmp0_);
	path = _tmp1_;
	_tmp2_ = path;
	if (g_strcmp0 (_tmp2_, "") == 0) {
		_g_free0 (path);
		return;
	}
	_tmp3_ = scratch_main_window_new (FALSE);
	g_object_ref_sink (_tmp3_);
	new_window = _tmp3_;
	_tmp4_ = path;
	_tmp5_ = g_file_new_for_path (_tmp4_);
	file = _tmp5_;
	_tmp6_ = new_window;
	_tmp7_ = _tmp6_->priv->_actions;
	_tmp8_ = file;
	_tmp9_ = scratch_services_document_new (_tmp7_, _tmp8_);
	g_object_ref_sink (_tmp9_);
	doc = _tmp9_;
	_tmp10_ = new_window;
	_tmp11_ = doc;
	scratch_main_window_open_document (_tmp10_, _tmp11_, TRUE, 0, NULL, NULL);
	_g_object_unref0 (doc);
	_g_object_unref0 (file);
	_g_object_unref0 (new_window);
	_g_free0 (path);
}

static void
scratch_main_window_action_open_project (ScratchMainWindow* self,
                                         GSimpleAction* action)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	scratch_main_window_choose_folder (self);
}

static void
___lambda177_ (ScratchMainWindow* self,
               GFile* glib_file)
{
	ScratchFolderManagerFile* foldermanager_file = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	ScratchFolderManagerFile* _tmp2_;
	ScratchFolderManagerFile* _tmp3_;
	ScratchFolderManagerFileView* _tmp4_;
	g_return_if_fail (glib_file != NULL);
	_tmp0_ = g_file_get_path (glib_file);
	_tmp1_ = _tmp0_;
	_tmp2_ = scratch_folder_manager_file_new (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	foldermanager_file = _tmp3_;
	_tmp4_ = self->priv->folder_manager_view;
	scratch_folder_manager_file_view_open_folder (_tmp4_, foldermanager_file);
	_g_object_unref0 (foldermanager_file);
}

static void
____lambda177__gfunc (gconstpointer data,
                      gpointer self)
{
	___lambda177_ ((ScratchMainWindow*) self, (GFile*) data);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_slist_free__g_object_unref0_ (GSList* self)
{
	g_slist_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static void
scratch_main_window_choose_folder (ScratchMainWindow* self)
{
	GtkFileChooserNative* chooser = NULL;
	GtkFileChooserNative* _tmp0_;
	GtkFileChooserNative* _tmp1_;
	GtkFileChooserNative* _tmp2_;
	GtkFileChooserNative* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_file_chooser_native_new ("Select a folder.", (GtkWindow*) self, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, _ ("_Open"), _ ("_Cancel"));
	chooser = _tmp0_;
	_tmp1_ = chooser;
	gtk_file_chooser_set_select_multiple ((GtkFileChooser*) _tmp1_, TRUE);
	_tmp2_ = chooser;
	if (gtk_native_dialog_run ((GtkNativeDialog*) _tmp2_) == ((gint) GTK_RESPONSE_ACCEPT)) {
		GtkFileChooserNative* _tmp3_;
		GSList* _tmp4_;
		GSList* _tmp5_;
		_tmp3_ = chooser;
		_tmp4_ = gtk_file_chooser_get_files ((GtkFileChooser*) _tmp3_);
		_tmp5_ = _tmp4_;
		g_slist_foreach (_tmp5_, ____lambda177__gfunc, self);
		(_tmp5_ == NULL) ? NULL : (_tmp5_ = (_g_slist_free__g_object_unref0_ (_tmp5_), NULL));
	}
	_tmp6_ = chooser;
	gtk_native_dialog_destroy ((GtkNativeDialog*) _tmp6_);
	_g_object_unref0 (chooser);
}

static void
scratch_main_window_action_open_folder (ScratchMainWindow* self,
                                        GSimpleAction* action,
                                        GVariant* param)
{
	gchar* path = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = g_variant_get_string (param, NULL);
	_tmp1_ = g_strdup (_tmp0_);
	path = _tmp1_;
	_tmp2_ = path;
	if (g_strcmp0 (_tmp2_, "") == 0) {
		scratch_main_window_choose_folder (self);
	} else {
		ScratchFolderManagerFileView* _tmp3_;
		const gchar* _tmp4_;
		ScratchFolderManagerFile* _tmp5_;
		ScratchFolderManagerFile* _tmp6_;
		_tmp3_ = self->priv->folder_manager_view;
		_tmp4_ = path;
		_tmp5_ = scratch_folder_manager_file_new (_tmp4_);
		_tmp6_ = _tmp5_;
		scratch_folder_manager_file_view_open_folder (_tmp3_, _tmp6_);
		_g_object_unref0 (_tmp6_);
	}
	_g_free0 (path);
}

static Block4Data*
block4_data_ref (Block4Data* _data4_)
{
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}

static void
block4_data_unref (void * _userdata_)
{
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data4_->self;
		_g_object_unref0 (_data4_->clone_dialog);
		_g_object_unref0 (self);
		g_slice_free (Block4Data, _data4_);
	}
}

static Block5Data*
block5_data_ref (Block5Data* _data5_)
{
	g_atomic_int_inc (&_data5_->_ref_count_);
	return _data5_;
}

static void
block5_data_unref (void * _userdata_)
{
	Block5Data* _data5_;
	_data5_ = (Block5Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data5_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data5_->_data4_->self;
		_g_free0 (_data5_->target);
		_g_free0 (_data5_->uri);
		block4_data_unref (_data5_->_data4_);
		_data5_->_data4_ = NULL;
		g_slice_free (Block5Data, _data5_);
	}
}

static Block6Data*
block6_data_ref (Block6Data* _data6_)
{
	g_atomic_int_inc (&_data6_->_ref_count_);
	return _data6_;
}

static void
block6_data_unref (void * _userdata_)
{
	Block6Data* _data6_;
	_data6_ = (Block6Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data6_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data6_->_data5_->_data4_->self;
		_g_object_unref0 (_data6_->message_dialog);
		block5_data_unref (_data6_->_data5_);
		_data6_->_data5_ = NULL;
		g_slice_free (Block6Data, _data6_);
	}
}

static void
___lambda176_ (Block6Data* _data6_,
               gint res)
{
	Block5Data* _data5_;
	Block4Data* _data4_;
	ScratchMainWindow* self;
	GraniteMessageDialog* _tmp0_;
	_data5_ = _data6_->_data5_;
	_data4_ = _data5_->_data4_;
	self = _data4_->self;
	if (res == 1) {
		gtk_widget_show ((GtkWidget*) _data4_->clone_dialog);
	} else {
		gtk_widget_destroy ((GtkWidget*) _data4_->clone_dialog);
	}
	_tmp0_ = _data6_->message_dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp0_);
}

static void
____lambda176__gtk_dialog_response (GtkDialog* _sender,
                                    gint response_id,
                                    gpointer self)
{
	___lambda176_ (self, response_id);
}

static void
___lambda175_ (Block5Data* _data5_,
               GObject* obj,
               GAsyncResult* res)
{
	Block4Data* _data4_;
	ScratchMainWindow* self;
	CodeSidebar* _tmp0_;
	GFile* workdir = NULL;
	gchar* _error_ = NULL;
	ScratchServicesGitManager* _tmp1_;
	GFile* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gboolean _tmp4_;
	_data4_ = _data5_->_data4_;
	self = _data4_->self;
	g_return_if_fail (res != NULL);
	_tmp0_ = self->sidebar;
	code_sidebar_set_cloning_in_progress (_tmp0_, FALSE);
	workdir = NULL;
	_error_ = NULL;
	_tmp1_ = self->priv->git_manager;
	_tmp4_ = scratch_services_git_manager_clone_repository_finish (_tmp1_, res, &_tmp2_, &_tmp3_);
	_g_object_unref0 (workdir);
	workdir = _tmp2_;
	_g_free0 (_error_);
	_error_ = _tmp3_;
	if (_tmp4_) {
		GFile* _tmp5_;
		gboolean _tmp6_;
		gboolean _tmp7_;
		_tmp5_ = workdir;
		scratch_main_window_open_folder (self, _tmp5_);
		gtk_widget_destroy ((GtkWidget*) _data4_->clone_dialog);
		g_object_get ((GtkWindow*) self, "is-active", &_tmp6_, NULL);
		_tmp7_ = _tmp6_;
		if (_tmp7_) {
			CodeSidebar* _tmp8_;
			_tmp8_ = self->sidebar;
			code_sidebar_notify_cloning_success (_tmp8_);
		} else {
			GNotification* notification = NULL;
			GNotification* _tmp9_;
			GNotification* _tmp10_;
			const gchar* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			GNotification* _tmp14_;
			GThemedIcon* _tmp15_;
			GThemedIcon* _tmp16_;
			ScratchApplication* _tmp17_;
			const gchar* _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			GNotification* _tmp21_;
			_tmp9_ = g_notification_new (_ ("Cloning completed"));
			notification = _tmp9_;
			_tmp10_ = notification;
			_tmp11_ = _data5_->target;
			_tmp12_ = g_strdup_printf (_ ("Clone successfully created in %s"), _tmp11_);
			_tmp13_ = _tmp12_;
			g_notification_set_body (_tmp10_, _tmp13_);
			_g_free0 (_tmp13_);
			_tmp14_ = notification;
			_tmp15_ = (GThemedIcon*) g_themed_icon_new ("process-completed-symbolic");
			_tmp16_ = _tmp15_;
			g_notification_set_icon (_tmp14_, (GIcon*) _tmp16_);
			_g_object_unref0 (_tmp16_);
			_tmp17_ = self->priv->_app;
			_tmp18_ = _data5_->target;
			_tmp19_ = g_strdup_printf ("cloning-finished-%s", _tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = notification;
			g_application_send_notification ((GApplication*) _tmp17_, _tmp20_, _tmp21_);
			_g_free0 (_tmp20_);
			_g_object_unref0 (notification);
		}
	} else {
		Block6Data* _data6_;
		const gchar* _tmp22_;
		gchar* _tmp23_;
		gchar* _tmp24_;
		const gchar* _tmp25_;
		GtkWindow* _tmp26_;
		GraniteMessageDialog* _tmp27_ = NULL;
		GraniteMessageDialog* _tmp28_;
		GraniteMessageDialog* _tmp29_;
		GraniteMessageDialog* _tmp30_;
		GraniteMessageDialog* _tmp31_;
		_data6_ = g_slice_new0 (Block6Data);
		_data6_->_ref_count_ = 1;
		_data6_->_data5_ = block5_data_ref (_data5_);
		_tmp22_ = _data5_->uri;
		_tmp23_ = g_strdup_printf (_ ("Unable to clone %s"), _tmp22_);
		_tmp24_ = _tmp23_;
		_tmp25_ = _error_;
		_tmp26_ = _g_object_ref0 ((GtkWindow*) self);
		_tmp27_ = granite_message_dialog_new_with_image_from_icon_name (_tmp24_, _tmp25_, "dialog-error", GTK_BUTTONS_CLOSE);
		gtk_window_set_transient_for ((GtkWindow*) _tmp27_, _tmp26_);
		_g_object_unref0 (_tmp26_);
		g_object_ref_sink (_tmp27_);
		_tmp28_ = _tmp27_;
		_g_free0 (_tmp24_);
		_data6_->message_dialog = _tmp28_;
		_tmp29_ = _data6_->message_dialog;
		gtk_dialog_add_button ((GtkDialog*) _tmp29_, _ ("Retry"), 1);
		_tmp30_ = _data6_->message_dialog;
		g_signal_connect_data ((GtkDialog*) _tmp30_, "response", (GCallback) ____lambda176__gtk_dialog_response, block6_data_ref (_data6_), (GClosureNotify) block6_data_unref, 0);
		_tmp31_ = _data6_->message_dialog;
		gtk_window_present ((GtkWindow*) _tmp31_);
		block6_data_unref (_data6_);
		_data6_ = NULL;
	}
	_g_free0 (_error_);
	_g_object_unref0 (workdir);
}

static void
____lambda175__gasync_ready_callback (GObject* source_object,
                                      GAsyncResult* res,
                                      gpointer self)
{
	___lambda175_ (self, source_object, res);
	block5_data_unref (self);
}

static void
__lambda174_ (Block4Data* _data4_,
              gint res)
{
	ScratchMainWindow* self;
	GSettings* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GSettings* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gboolean _tmp6_ = FALSE;
	self = _data4_->self;
	_tmp0_ = scratch_settings;
	_tmp1_ = scratch_dialogs_clone_repository_dialog_get_remote (_data4_->clone_dialog);
	_tmp2_ = _tmp1_;
	g_settings_set_string (_tmp0_, "default-remote", _tmp2_);
	_g_free0 (_tmp2_);
	_tmp3_ = scratch_settings;
	_tmp4_ = scratch_dialogs_clone_repository_dialog_get_projects_folder (_data4_->clone_dialog);
	_tmp5_ = _tmp4_;
	g_settings_set_string (_tmp3_, "default-projects-folder", _tmp5_);
	_g_free0 (_tmp5_);
	if (res == ((gint) GTK_RESPONSE_APPLY)) {
		gboolean _tmp7_;
		gboolean _tmp8_;
		_tmp7_ = scratch_dialogs_clone_repository_dialog_get_can_clone (_data4_->clone_dialog);
		_tmp8_ = _tmp7_;
		_tmp6_ = _tmp8_;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		Block5Data* _data5_;
		CodeSidebar* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		ScratchServicesGitManager* _tmp12_;
		const gchar* _tmp13_;
		const gchar* _tmp14_;
		_data5_ = g_slice_new0 (Block5Data);
		_data5_->_ref_count_ = 1;
		_data5_->_data4_ = block4_data_ref (_data4_);
		_tmp9_ = self->sidebar;
		code_sidebar_set_cloning_in_progress (_tmp9_, TRUE);
		gtk_widget_hide ((GtkWidget*) _data4_->clone_dialog);
		_tmp10_ = scratch_dialogs_clone_repository_dialog_get_valid_source_repository_uri (_data4_->clone_dialog);
		_data5_->uri = _tmp10_;
		_tmp11_ = scratch_dialogs_clone_repository_dialog_get_valid_target (_data4_->clone_dialog);
		_data5_->target = _tmp11_;
		_tmp12_ = self->priv->git_manager;
		_tmp13_ = _data5_->uri;
		_tmp14_ = _data5_->target;
		scratch_services_git_manager_clone_repository (_tmp12_, _tmp13_, _tmp14_, ____lambda175__gasync_ready_callback, block5_data_ref (_data5_));
		block5_data_unref (_data5_);
		_data5_ = NULL;
	} else {
		gtk_widget_destroy ((GtkWidget*) _data4_->clone_dialog);
	}
}

static void
___lambda174__gtk_dialog_response (GtkDialog* _sender,
                                   gint response_id,
                                   gpointer self)
{
	__lambda174_ (self, response_id);
}

static void
scratch_main_window_action_clone_repo (ScratchMainWindow* self,
                                       GSimpleAction* action,
                                       GVariant* param)
{
	Block4Data* _data4_;
	gchar* default_projects_folder = NULL;
	GSettings* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	gchar* default_remote = NULL;
	GSettings* _tmp11_;
	gchar* _tmp12_;
	const gchar* _tmp13_;
	ScratchDialogsCloneRepositoryDialog* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_data4_ = g_slice_new0 (Block4Data);
	_data4_->_ref_count_ = 1;
	_data4_->self = g_object_ref (self);
	_tmp0_ = scratch_settings;
	_tmp1_ = g_settings_get_string (_tmp0_, "default-projects-folder");
	default_projects_folder = _tmp1_;
	_tmp3_ = default_projects_folder;
	if (g_strcmp0 (_tmp3_, "") == 0) {
		ScratchServicesGitManager* _tmp4_;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		_tmp4_ = self->priv->git_manager;
		_tmp5_ = scratch_services_git_manager_get_active_project_path (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = g_strcmp0 (_tmp6_, "") != 0;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		ScratchServicesGitManager* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp7_ = self->priv->git_manager;
		_tmp8_ = scratch_services_git_manager_get_active_project_path (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = g_path_get_dirname (_tmp9_);
		_g_free0 (default_projects_folder);
		default_projects_folder = _tmp10_;
	}
	_tmp11_ = scratch_settings;
	_tmp12_ = g_settings_get_string (_tmp11_, "default-remote");
	default_remote = _tmp12_;
	_tmp13_ = default_projects_folder;
	_tmp14_ = scratch_dialogs_clone_repository_dialog_new (_tmp13_, default_remote);
	g_object_ref_sink (_tmp14_);
	_data4_->clone_dialog = _tmp14_;
	g_signal_connect_data ((GtkDialog*) _data4_->clone_dialog, "response", (GCallback) ___lambda174__gtk_dialog_response, block4_data_ref (_data4_), (GClosureNotify) block4_data_unref, 0);
	gtk_window_present ((GtkWindow*) _data4_->clone_dialog);
	_g_free0 (default_remote);
	_g_free0 (default_projects_folder);
	block4_data_unref (_data4_);
	_data4_ = NULL;
}

static void
scratch_main_window_action_collapse_all_folders (ScratchMainWindow* self)
{
	ScratchFolderManagerFileView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->folder_manager_view;
	scratch_folder_manager_file_view_collapse_all (_tmp0_);
}

static void
scratch_main_window_action_save (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_current_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ != NULL) {
		ScratchServicesDocument* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = doc;
		_tmp3_ = scratch_services_document_get_is_file_temporary (_tmp2_);
		_tmp4_ = _tmp3_;
		if (_tmp4_ == TRUE) {
			scratch_main_window_action_save_as (self);
		} else {
			ScratchServicesDocument* _tmp5_;
			_tmp5_ = doc;
			scratch_services_document_save_request (_tmp5_);
		}
	}
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_save_as (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_current_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ != NULL) {
		ScratchServicesDocument* _tmp2_;
		_tmp2_ = doc;
		scratch_services_document_save_as_with_hold (_tmp2_, NULL, NULL);
	}
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_undo (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_current_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ != NULL) {
		ScratchServicesDocument* _tmp2_;
		_tmp2_ = doc;
		scratch_services_document_undo (_tmp2_);
	}
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_redo (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_current_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ != NULL) {
		ScratchServicesDocument* _tmp2_;
		_tmp2_ = doc;
		scratch_services_document_redo (_tmp2_);
	}
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_revert (ScratchMainWindow* self)
{
	ScratchDialogsRestoreConfirmationDialog* confirmation_dialog = NULL;
	ScratchDialogsRestoreConfirmationDialog* _tmp0_;
	ScratchDialogsRestoreConfirmationDialog* _tmp1_;
	ScratchDialogsRestoreConfirmationDialog* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_dialogs_restore_confirmation_dialog_new (self);
	g_object_ref_sink (_tmp0_);
	confirmation_dialog = _tmp0_;
	_tmp1_ = confirmation_dialog;
	if (gtk_dialog_run ((GtkDialog*) _tmp1_) == ((gint) GTK_RESPONSE_ACCEPT)) {
		ScratchServicesDocument* doc = NULL;
		ScratchServicesDocument* _tmp2_;
		ScratchServicesDocument* _tmp3_;
		_tmp2_ = scratch_main_window_get_current_document (self);
		doc = _tmp2_;
		_tmp3_ = doc;
		if (_tmp3_ != NULL) {
			ScratchServicesDocument* _tmp4_;
			_tmp4_ = doc;
			scratch_services_document_revert (_tmp4_);
		}
		_g_object_unref0 (doc);
	}
	_tmp5_ = confirmation_dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp5_);
	_g_object_unref0 (confirmation_dialog);
}

static void
scratch_main_window_action_duplicate (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_current_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ != NULL) {
		ScratchServicesDocument* _tmp2_;
		_tmp2_ = doc;
		scratch_services_document_duplicate_selection (_tmp2_);
	}
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_new_tab (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_new_document (_tmp0_);
}

static void
scratch_main_window_action_new_tab_from_clipboard (ScratchMainWindow* self)
{
	gchar* text_from_clipboard = NULL;
	GtkClipboard* _tmp0_;
	gchar* _tmp1_;
	ScratchWidgetsDocumentView* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->clipboard;
	_tmp1_ = gtk_clipboard_wait_for_text (_tmp0_);
	text_from_clipboard = _tmp1_;
	_tmp2_ = self->document_view;
	scratch_widgets_document_view_new_document_from_clipboard (_tmp2_, text_from_clipboard);
	_g_free0 (text_from_clipboard);
}

static void
scratch_main_window_action_fullscreen (ScratchMainWindow* self)
{
	GdkWindow* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_window ((GtkWidget*) self);
	if ((gdk_window_get_state (_tmp0_) & GDK_WINDOW_STATE_FULLSCREEN) == GDK_WINDOW_STATE_FULLSCREEN) {
		gtk_window_unfullscreen ((GtkWindow*) self);
	} else {
		gtk_window_fullscreen ((GtkWindow*) self);
	}
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data7_->self;
		_g_free0 (_data7_->close_path);
		_g_object_unref0 (self);
		g_slice_free (Block7Data, _data7_);
	}
}

static void
__lambda180_ (Block7Data* _data7_,
              ScratchServicesDocument* doc)
{
	ScratchMainWindow* self;
	GFile* _tmp0_;
	GFile* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	gboolean _tmp5_;
	self = _data7_->self;
	g_return_if_fail (doc != NULL);
	_tmp0_ = scratch_services_document_get_file (doc);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_file_get_path (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _data7_->close_path;
	_tmp5_ = g_strcmp0 (_tmp3_, _tmp4_) == 0;
	_g_free0 (_tmp3_);
	if (_tmp5_) {
		ScratchWidgetsDocumentView* _tmp6_;
		_tmp6_ = self->document_view;
		scratch_widgets_document_view_close_document (_tmp6_, doc);
	}
}

static void
___lambda180__gfunc (gconstpointer data,
                     gpointer self)
{
	__lambda180_ (self, (ScratchServicesDocument*) data);
}

static void
scratch_main_window_action_close_tab (ScratchMainWindow* self,
                                      GSimpleAction* action,
                                      GVariant* param)
{
	Block7Data* _data7_;
	gchar* _tmp0_;
	const gchar* _tmp3_;
	GList* docs = NULL;
	ScratchWidgetsDocumentView* _tmp5_;
	GList* _tmp6_;
	GList* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_data7_->self = g_object_ref (self);
	_tmp0_ = g_strdup ("");
	_data7_->close_path = _tmp0_;
	if (param != NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = g_variant_get_string (param, NULL);
		_tmp2_ = g_strdup (_tmp1_);
		_g_free0 (_data7_->close_path);
		_data7_->close_path = _tmp2_;
	}
	_tmp3_ = _data7_->close_path;
	if (g_strcmp0 (_tmp3_, "") == 0) {
		ScratchWidgetsDocumentView* _tmp4_;
		_tmp4_ = self->document_view;
		scratch_widgets_document_view_close_document (_tmp4_, NULL);
		block7_data_unref (_data7_);
		_data7_ = NULL;
		return;
	}
	_tmp5_ = self->document_view;
	_tmp6_ = _tmp5_->docs;
	docs = _tmp6_;
	_tmp7_ = docs;
	g_list_foreach (_tmp7_, ___lambda180__gfunc, _data7_);
	block7_data_unref (_data7_);
	_data7_ = NULL;
}

static void
scratch_main_window_action_duplicate_tab (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_duplicate_tab (_tmp0_);
}

static void
scratch_main_window_action_close_tabs_to_right (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_close_tabs_to_right (_tmp0_);
}

static void
scratch_main_window_action_close_other_tabs (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_close_other_tabs (_tmp0_);
}

static void
scratch_main_window_action_hide_project_docs (ScratchMainWindow* self,
                                              GSimpleAction* action,
                                              GVariant* param)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = scratch_main_window_get_target_path_for_actions (self, param, FALSE);
	_tmp1_ = _tmp0_;
	scratch_main_window_close_project_docs (self, _tmp1_, TRUE);
	_g_free0 (_tmp1_);
}

static void
scratch_main_window_action_close_project_docs (ScratchMainWindow* self,
                                               GSimpleAction* action,
                                               GVariant* param)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = scratch_main_window_get_target_path_for_actions (self, param, FALSE);
	_tmp1_ = _tmp0_;
	scratch_main_window_close_project_docs (self, _tmp1_, FALSE);
	_g_free0 (_tmp1_);
}

static void
scratch_main_window_action_restore_project_docs (ScratchMainWindow* self,
                                                 GSimpleAction* action,
                                                 GVariant* param)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = scratch_main_window_get_target_path_for_actions (self, param, FALSE);
	_tmp1_ = _tmp0_;
	scratch_main_window_restore_project_docs (self, _tmp1_);
	_g_free0 (_tmp1_);
}

static void
scratch_main_window_action_restore_closed_tab (ScratchMainWindow* self,
                                               GSimpleAction* action,
                                               GVariant* param)
{
	ScratchWidgetsDocumentView* _tmp0_;
	const gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->document_view;
	_tmp1_ = g_variant_get_string (param, NULL);
	scratch_widgets_document_view_restore_closed_tab (_tmp0_, _tmp1_);
}

static Block8Data*
block8_data_ref (Block8Data* _data8_)
{
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}

static void
block8_data_unref (void * _userdata_)
{
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		ScratchMainWindow* self;
		self = _data8_->self;
		_g_free0 (_data8_->project_path);
		_g_object_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}

static void
__lambda181_ (Block8Data* _data8_,
              ScratchServicesDocument* doc)
{
	ScratchMainWindow* self;
	GFile* _tmp0_;
	GFile* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gboolean _tmp6_;
	self = _data8_->self;
	g_return_if_fail (doc != NULL);
	_tmp0_ = scratch_services_document_get_file (doc);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_file_get_path (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_data8_->project_path, G_DIR_SEPARATOR_S, NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_str_has_prefix (_tmp3_, _tmp5_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	if (_tmp6_) {
		ScratchWidgetsDocumentView* _tmp7_;
		_tmp7_ = self->document_view;
		scratch_widgets_document_view_close_document (_tmp7_, doc);
		if (_data8_->make_restorable) {
			ScratchServicesDocumentManager* _tmp8_;
			_tmp8_ = self->priv->document_manager;
			scratch_services_document_manager_make_restorable (_tmp8_, doc);
		}
	}
}

static void
___lambda181__gfunc (gconstpointer data,
                     gpointer self)
{
	__lambda181_ (self, (ScratchServicesDocument*) data);
}

static void
scratch_main_window_close_project_docs (ScratchMainWindow* self,
                                        const gchar* project_path,
                                        gboolean make_restorable)
{
	Block8Data* _data8_;
	gchar* _tmp0_;
	GList* docs = NULL;
	ScratchWidgetsDocumentView* _tmp1_;
	GList* _tmp2_;
	GList* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (project_path != NULL);
	_data8_ = g_slice_new0 (Block8Data);
	_data8_->_ref_count_ = 1;
	_data8_->self = g_object_ref (self);
	_tmp0_ = g_strdup (project_path);
	_g_free0 (_data8_->project_path);
	_data8_->project_path = _tmp0_;
	_data8_->make_restorable = make_restorable;
	_tmp1_ = self->document_view;
	_tmp2_ = _tmp1_->docs;
	docs = _tmp2_;
	_tmp3_ = docs;
	g_list_foreach (_tmp3_, ___lambda181__gfunc, _data8_);
	if (!_data8_->make_restorable) {
		ScratchServicesDocumentManager* _tmp4_;
		_tmp4_ = self->priv->document_manager;
		scratch_services_document_manager_remove_project (_tmp4_, _data8_->project_path);
	}
	block8_data_unref (_data8_);
	_data8_ = NULL;
}

static gboolean
__lambda182_ (ScratchMainWindow* self,
              gchar* doc_path)
{
	ScratchServicesDocument* doc = NULL;
	GSimpleActionGroup* _tmp0_;
	GFile* _tmp1_;
	GFile* _tmp2_;
	ScratchServicesDocument* _tmp3_;
	ScratchServicesDocument* _tmp4_;
	gboolean result;
	g_return_val_if_fail (doc_path != NULL, FALSE);
	_tmp0_ = self->priv->_actions;
	_tmp1_ = g_file_new_for_path (doc_path);
	_tmp2_ = _tmp1_;
	_tmp3_ = scratch_services_document_new (_tmp0_, _tmp2_);
	g_object_ref_sink (_tmp3_);
	_tmp4_ = _tmp3_;
	_g_object_unref0 (_tmp2_);
	doc = _tmp4_;
	scratch_main_window_open_document (self, doc, TRUE, 0, NULL, NULL);
	result = TRUE;
	_g_object_unref0 (doc);
	_g_free0 (doc_path);
	return result;
}

static gboolean
___lambda182__gee_forall_func (gpointer g,
                               gpointer self)
{
	gboolean result;
	result = __lambda182_ ((ScratchMainWindow*) self, (gchar*) g);
	return result;
}

static void
scratch_main_window_restore_project_docs (ScratchMainWindow* self,
                                          const gchar* project_path)
{
	ScratchServicesDocumentManager* _tmp0_;
	GeeCollection* _tmp1_;
	GeeCollection* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (project_path != NULL);
	_tmp0_ = self->priv->document_manager;
	_tmp1_ = scratch_services_document_manager_take_restorable_paths (_tmp0_, project_path);
	_tmp2_ = _tmp1_;
	gee_traversable_foreach ((GeeTraversable*) _tmp2_, ___lambda182__gee_forall_func, self);
	_g_object_unref0 (_tmp2_);
}

/** Not a toggle action - linked to keyboard short cut (Ctrl-f). **/
static void
scratch_main_window_action_find (ScratchMainWindow* self,
                                 GSimpleAction* action,
                                 GVariant* param)
{
	const gchar* _tmp0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	if (param != NULL) {
		const gchar* _tmp1_;
		_tmp1_ = g_variant_get_string (param, NULL);
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = "";
	}
	scratch_main_window_find (self, _tmp0_);
}

static void
scratch_main_window_find (ScratchMainWindow* self,
                          const gchar* search_term)
{
	ScratchWidgetsSearchBar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	ScratchWidgetsSearchBar* _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (search_term != NULL);
	if (g_strcmp0 (search_term, "") != 0) {
		ScratchWidgetsSearchBar* _tmp0_;
		_tmp0_ = self->search_bar;
		scratch_widgets_search_bar_set_search_entry_text (_tmp0_, search_term);
	} else {
		scratch_main_window_set_selected_text_for_search (self);
	}
	_tmp1_ = self->search_bar;
	_tmp2_ = scratch_widgets_search_bar_get_is_revealed (_tmp1_);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		GSimpleAction* show_find_action = NULL;
		GSimpleActionGroup* _tmp4_;
		GSimpleAction* _tmp5_;
		GSimpleAction* _tmp6_;
		gboolean _tmp7_;
		gboolean _tmp8_;
		_tmp4_ = self->priv->_actions;
		_tmp5_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SHOW_FIND, _tmp4_);
		show_find_action = _tmp5_;
		_tmp6_ = show_find_action;
		_tmp7_ = g_action_get_enabled ((GAction*) _tmp6_);
		_tmp8_ = _tmp7_;
		if (_tmp8_) {
			GSimpleAction* _tmp9_;
			GVariant* _tmp10_;
			GVariant* _tmp11_;
			_tmp9_ = show_find_action;
			_tmp10_ = g_variant_new ("b", TRUE, NULL);
			g_variant_ref_sink (_tmp10_);
			_tmp11_ = _tmp10_;
			g_signal_emit_by_name (_tmp9_, "activate", _tmp11_);
			_g_variant_unref0 (_tmp11_);
		}
		_g_object_unref0 (show_find_action);
	}
	_tmp12_ = self->search_bar;
	scratch_widgets_search_bar_search (_tmp12_);
}

static gboolean
___lambda179_ (ScratchMainWindow* self)
{
	ScratchWidgetsSearchBar* _tmp0_;
	gboolean result;
	_tmp0_ = self->search_bar;
	scratch_widgets_search_bar_focus_replace_entry (_tmp0_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
____lambda179__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda179_ ((ScratchMainWindow*) self);
	return result;
}

static void
scratch_main_window_action_show_replace (ScratchMainWindow* self,
                                         GSimpleAction* action)
{
	ScratchWidgetsSearchBar* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	scratch_main_window_find (self, "");
	_tmp0_ = self->search_bar;
	_tmp1_ = scratch_widgets_search_bar_get_is_revealed (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		ScratchWidgetsSearchBar* _tmp3_;
		_tmp3_ = self->search_bar;
		scratch_widgets_search_bar_focus_replace_entry (_tmp3_);
	} else {
		ScratchWidgetsSearchBar* _tmp4_;
		_tmp4_ = self->search_bar;
		scratch_widgets_search_bar_reveal (_tmp4_, TRUE);
		g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ____lambda179__gsource_func, g_object_ref (self), g_object_unref);
	}
}

static void
scratch_main_window_action_find_next (ScratchMainWindow* self)
{
	ScratchWidgetsSearchBar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->search_bar;
	scratch_widgets_search_bar_search_next (_tmp0_);
}

static void
scratch_main_window_action_find_previous (ScratchMainWindow* self)
{
	ScratchWidgetsSearchBar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->search_bar;
	scratch_widgets_search_bar_search_previous (_tmp0_);
}

static void
scratch_main_window_action_find_global (ScratchMainWindow* self,
                                        GSimpleAction* action,
                                        GVariant* param)
{
	gboolean _tmp0_ = FALSE;
	ScratchWidgetsSearchBar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gchar* search_path = NULL;
	gchar* _tmp7_;
	gboolean _tmp8_ = FALSE;
	const gchar* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp1_ = self->search_bar;
	_tmp2_ = scratch_widgets_search_bar_get_is_focused (_tmp1_);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		_tmp0_ = TRUE;
	} else {
		ScratchWidgetsSearchBar* _tmp4_;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		_tmp4_ = self->search_bar;
		_tmp5_ = scratch_widgets_search_bar_get_entry_text (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = g_strcmp0 (_tmp6_, "") == 0;
	}
	if (_tmp0_) {
		scratch_main_window_set_selected_text_for_search (self);
	}
	_tmp7_ = g_strdup ("");
	search_path = _tmp7_;
	if (param != NULL) {
		const gchar* _tmp9_;
		_tmp9_ = g_variant_get_string (param, NULL);
		_tmp8_ = g_strcmp0 (_tmp9_, "") != 0;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		const gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp10_ = g_variant_get_string (param, NULL);
		_tmp11_ = g_strdup (_tmp10_);
		_g_free0 (search_path);
		search_path = _tmp11_;
	} else {
		gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp12_ = scratch_main_window_get_default_globalsearch_path (self);
		_tmp13_ = _tmp12_;
		_g_free0 (search_path);
		search_path = _tmp13_;
	}
	_tmp14_ = search_path;
	if (g_strcmp0 (_tmp14_, "") != 0) {
		ScratchFolderManagerFileView* _tmp15_;
		const gchar* _tmp16_;
		ScratchWidgetsSearchBar* _tmp17_;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		_tmp15_ = self->priv->folder_manager_view;
		_tmp16_ = search_path;
		_tmp17_ = self->search_bar;
		_tmp18_ = scratch_widgets_search_bar_get_entry_text (_tmp17_);
		_tmp19_ = _tmp18_;
		scratch_folder_manager_file_view_search_global (_tmp15_, _tmp16_, _tmp19_);
	} else {
		g_warning ("MainWindow.vala:1334: Unable to perform global search - search documen" \
"t instead");
		scratch_main_window_find (self, "");
	}
	_g_free0 (search_path);
}

static gboolean
__lambda192_ (ScratchMainWindow* self)
{
	gboolean is_current_doc = FALSE;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	gboolean _tmp2_;
	GSimpleActionGroup* _tmp3_;
	GSimpleAction* _tmp4_;
	GSimpleAction* _tmp5_;
	GSimpleActionGroup* _tmp6_;
	GSimpleAction* _tmp7_;
	GSimpleAction* _tmp8_;
	GSimpleActionGroup* _tmp9_;
	GSimpleAction* _tmp10_;
	GSimpleAction* _tmp11_;
	GSimpleActionGroup* _tmp12_;
	GSimpleAction* _tmp13_;
	GSimpleAction* _tmp14_;
	gboolean _tmp15_ = FALSE;
	gboolean can_global_search = FALSE;
	GSimpleActionGroup* _tmp19_;
	GSimpleAction* _tmp20_;
	GSimpleAction* _tmp21_;
	gboolean result;
	_tmp0_ = scratch_main_window_get_current_document (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_object_unref0 (_tmp1_);
	is_current_doc = _tmp2_;
	_tmp3_ = self->priv->_actions;
	_tmp4_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_FIND, _tmp3_);
	_tmp5_ = _tmp4_;
	g_simple_action_set_enabled (_tmp5_, is_current_doc);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = self->priv->_actions;
	_tmp7_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SHOW_FIND, _tmp6_);
	_tmp8_ = _tmp7_;
	g_simple_action_set_enabled (_tmp8_, is_current_doc);
	_g_object_unref0 (_tmp8_);
	_tmp9_ = self->priv->_actions;
	_tmp10_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_FIND_NEXT, _tmp9_);
	_tmp11_ = _tmp10_;
	g_simple_action_set_enabled (_tmp11_, is_current_doc);
	_g_object_unref0 (_tmp11_);
	_tmp12_ = self->priv->_actions;
	_tmp13_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_FIND_PREVIOUS, _tmp12_);
	_tmp14_ = _tmp13_;
	g_simple_action_set_enabled (_tmp14_, is_current_doc);
	_g_object_unref0 (_tmp14_);
	if (is_current_doc) {
		_tmp15_ = TRUE;
	} else {
		ScratchServicesGitManager* _tmp16_;
		const gchar* _tmp17_;
		const gchar* _tmp18_;
		_tmp16_ = self->priv->git_manager;
		_tmp17_ = scratch_services_git_manager_get_active_project_path (_tmp16_);
		_tmp18_ = _tmp17_;
		_tmp15_ = _tmp18_ != NULL;
	}
	can_global_search = _tmp15_;
	_tmp19_ = self->priv->_actions;
	_tmp20_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_FIND_GLOBAL, _tmp19_);
	_tmp21_ = _tmp20_;
	g_simple_action_set_enabled (_tmp21_, can_global_search);
	_g_object_unref0 (_tmp21_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda192__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda192_ ((ScratchMainWindow*) self);
	return result;
}

static void
scratch_main_window_update_find_actions (ScratchMainWindow* self)
{
	g_return_if_fail (self != NULL);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda192__gsource_func, g_object_ref (self), g_object_unref);
}

/** Toggle action - linked to toolbar togglebutton. **/
static GVariant*
_variant_new2 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static void
scratch_main_window_action_toggle_show_find (ScratchMainWindow* self)
{
	GSimpleAction* action = NULL;
	GSimpleActionGroup* _tmp0_;
	GSimpleAction* _tmp1_;
	gboolean to_show = FALSE;
	GSimpleAction* _tmp2_;
	GVariant* _tmp3_;
	GVariant* _tmp4_;
	gboolean _tmp5_;
	GSimpleAction* _tmp6_;
	GVariant* _tmp7_;
	ScratchWidgetsSearchBar* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_actions;
	_tmp1_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SHOW_FIND, _tmp0_);
	action = _tmp1_;
	_tmp2_ = action;
	_tmp3_ = g_action_get_state ((GAction*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = !g_variant_get_boolean (_tmp4_);
	_g_variant_unref0 (_tmp4_);
	to_show = _tmp5_;
	_tmp6_ = action;
	_tmp7_ = _variant_new2 (to_show);
	g_simple_action_set_state (_tmp6_, _tmp7_);
	_g_variant_unref0 (_tmp7_);
	_tmp8_ = self->search_bar;
	scratch_widgets_search_bar_reveal (_tmp8_, to_show);
	if (to_show) {
		ScratchWidgetsSearchBar* _tmp9_;
		ScratchWidgetsSearchBar* _tmp10_;
		const gchar* _tmp11_;
		const gchar* _tmp12_;
		_tmp9_ = self->search_bar;
		scratch_widgets_search_bar_focus_search_entry (_tmp9_);
		_tmp10_ = self->search_bar;
		_tmp11_ = scratch_widgets_search_bar_get_entry_text (_tmp10_);
		_tmp12_ = _tmp11_;
		if (g_strcmp0 (_tmp12_, "") == 0) {
			scratch_main_window_set_selected_text_for_search (self);
		}
	}
	_g_object_unref0 (action);
}

static void
scratch_main_window_action_go_to (ScratchMainWindow* self)
{
	ScratchHeaderBar* _tmp0_;
	CodeFormatBar* _tmp1_;
	CodeFormatBarFormatButton* _tmp2_;
	CodeFormatBarFormatButton* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->toolbar;
	_tmp1_ = _tmp0_->format_bar;
	_tmp2_ = code_format_bar_get_line_menubutton (_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_toggle_button_set_active ((GtkToggleButton*) _tmp3_, TRUE);
}

static void
scratch_main_window_action_templates (ScratchMainWindow* self)
{
	ScratchServicesPluginsManager* _tmp0_;
	ScratchServicesInterface* _tmp1_;
	ScratchServicesInterface* _tmp2_;
	ScratchTemplateManager* _tmp3_;
	ScratchTemplateManager* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->plugins;
	_tmp1_ = scratch_services_plugins_manager_get_plugin_iface (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = scratch_services_interface_get_template_manager (_tmp2_);
	_tmp4_ = _tmp3_;
	scratch_template_manager_show_window (_tmp4_, (GtkWidget*) self);
}

static void
scratch_main_window_action_to_lower_case (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchWidgetsDocumentView* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchServicesDocument* _tmp3_;
	ScratchServicesDocument* _tmp4_;
	GtkTextBuffer* buffer = NULL;
	ScratchServicesDocument* _tmp5_;
	ScratchWidgetsSourceView* _tmp6_;
	ScratchWidgetsSourceView* _tmp7_;
	GtkTextBuffer* _tmp8_;
	GtkTextBuffer* _tmp9_;
	GtkTextBuffer* _tmp10_;
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkTextBuffer* _tmp11_;
	GtkTextIter _tmp12_ = {0};
	GtkTextIter _tmp13_ = {0};
	gchar* selected = NULL;
	GtkTextBuffer* _tmp14_;
	GtkTextIter _tmp15_;
	GtkTextIter _tmp16_;
	gchar* _tmp17_;
	GtkTextBuffer* _tmp18_;
	GtkTextBuffer* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	_tmp1_ = scratch_widgets_document_view_get_current_document (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	doc = _tmp3_;
	_tmp4_ = doc;
	if (_tmp4_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp5_ = doc;
	_tmp6_ = scratch_services_document_get_source_view (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = _g_object_ref0 (_tmp9_);
	buffer = _tmp10_;
	_tmp11_ = buffer;
	gtk_text_buffer_get_selection_bounds (_tmp11_, &_tmp12_, &_tmp13_);
	start = _tmp12_;
	end = _tmp13_;
	_tmp14_ = buffer;
	_tmp15_ = start;
	_tmp16_ = end;
	_tmp17_ = gtk_text_buffer_get_text (_tmp14_, &_tmp15_, &_tmp16_, TRUE);
	selected = _tmp17_;
	_tmp18_ = buffer;
	gtk_text_buffer_delete (_tmp18_, &start, &end);
	_tmp19_ = buffer;
	_tmp20_ = selected;
	_tmp21_ = g_utf8_strdown (_tmp20_, (gssize) -1);
	_tmp22_ = _tmp21_;
	gtk_text_buffer_insert (_tmp19_, &start, _tmp22_, -1);
	_g_free0 (_tmp22_);
	_g_free0 (selected);
	_g_object_unref0 (buffer);
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_to_upper_case (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchWidgetsDocumentView* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchServicesDocument* _tmp3_;
	ScratchServicesDocument* _tmp4_;
	GtkTextBuffer* buffer = NULL;
	ScratchServicesDocument* _tmp5_;
	ScratchWidgetsSourceView* _tmp6_;
	ScratchWidgetsSourceView* _tmp7_;
	GtkTextBuffer* _tmp8_;
	GtkTextBuffer* _tmp9_;
	GtkTextBuffer* _tmp10_;
	GtkTextIter start = {0};
	GtkTextIter end = {0};
	GtkTextBuffer* _tmp11_;
	GtkTextIter _tmp12_ = {0};
	GtkTextIter _tmp13_ = {0};
	gchar* selected = NULL;
	GtkTextBuffer* _tmp14_;
	GtkTextIter _tmp15_;
	GtkTextIter _tmp16_;
	gchar* _tmp17_;
	GtkTextBuffer* _tmp18_;
	GtkTextBuffer* _tmp19_;
	const gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	_tmp1_ = scratch_widgets_document_view_get_current_document (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	doc = _tmp3_;
	_tmp4_ = doc;
	if (_tmp4_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp5_ = doc;
	_tmp6_ = scratch_services_document_get_source_view (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = _g_object_ref0 (_tmp9_);
	buffer = _tmp10_;
	_tmp11_ = buffer;
	gtk_text_buffer_get_selection_bounds (_tmp11_, &_tmp12_, &_tmp13_);
	start = _tmp12_;
	end = _tmp13_;
	_tmp14_ = buffer;
	_tmp15_ = start;
	_tmp16_ = end;
	_tmp17_ = gtk_text_buffer_get_text (_tmp14_, &_tmp15_, &_tmp16_, TRUE);
	selected = _tmp17_;
	_tmp18_ = buffer;
	gtk_text_buffer_delete (_tmp18_, &start, &end);
	_tmp19_ = buffer;
	_tmp20_ = selected;
	_tmp21_ = g_utf8_strup (_tmp20_, (gssize) -1);
	_tmp22_ = _tmp21_;
	gtk_text_buffer_insert (_tmp19_, &start, _tmp22_, -1);
	_g_free0 (_tmp22_);
	_g_free0 (selected);
	_g_object_unref0 (buffer);
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_toggle_comment (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	GtkTextBuffer* buffer = NULL;
	ScratchServicesDocument* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	ScratchWidgetsSourceView* _tmp4_;
	GtkTextBuffer* _tmp5_;
	GtkTextBuffer* _tmp6_;
	GtkTextBuffer* _tmp7_;
	GtkTextBuffer* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_focused_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp2_ = doc;
	_tmp3_ = scratch_services_document_get_source_view (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	buffer = _tmp7_;
	_tmp8_ = buffer;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp8_, gtk_source_buffer_get_type ())) {
		GtkTextBuffer* _tmp9_;
		_tmp9_ = buffer;
		scratch_comment_toggler_toggle_comment (G_TYPE_CHECK_INSTANCE_TYPE (_tmp9_, gtk_source_buffer_get_type ()) ? ((GtkSourceBuffer*) _tmp9_) : NULL);
	}
	_g_object_unref0 (buffer);
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_sort_lines (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	ScratchWidgetsSourceView* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_focused_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp2_ = doc;
	_tmp3_ = scratch_services_document_get_source_view (_tmp2_);
	_tmp4_ = _tmp3_;
	scratch_widgets_source_view_sort_selected_lines (_tmp4_);
	_g_object_unref0 (doc);
}

static GVariant*
_variant_new3 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static void
scratch_main_window_action_toggle_sidebar (ScratchMainWindow* self,
                                           GSimpleAction* action)
{
	CodeSidebar* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	GVariant* _tmp3_;
	CodeSidebar* _tmp4_;
	GVariant* _tmp5_;
	GVariant* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->sidebar;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = g_action_get_state ((GAction*) action);
	_tmp2_ = _tmp1_;
	_tmp3_ = _variant_new3 (!g_variant_get_boolean (_tmp2_));
	g_simple_action_set_state (action, _tmp3_);
	_g_variant_unref0 (_tmp3_);
	_g_variant_unref0 (_tmp2_);
	_tmp4_ = self->sidebar;
	_tmp5_ = g_action_get_state ((GAction*) action);
	_tmp6_ = _tmp5_;
	gtk_widget_set_visible ((GtkWidget*) _tmp4_, g_variant_get_boolean (_tmp6_));
	_g_variant_unref0 (_tmp6_);
}

static void
scratch_main_window_action_focus_sidebar (ScratchMainWindow* self)
{
	CodeSidebar* _tmp0_;
	CodeSidebar* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	CodeSidebar* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->sidebar;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->sidebar;
	_tmp2_ = gtk_widget_get_visible ((GtkWidget*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		GSimpleAction* toggle_sidebar_action = NULL;
		GSimpleActionGroup* _tmp4_;
		GSimpleAction* _tmp5_;
		GSimpleAction* _tmp6_;
		_tmp4_ = self->priv->_actions;
		_tmp5_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SIDEBAR, _tmp4_);
		toggle_sidebar_action = _tmp5_;
		_tmp6_ = toggle_sidebar_action;
		g_signal_emit_by_name (_tmp6_, "activate", NULL);
		_g_object_unref0 (toggle_sidebar_action);
	}
	_tmp7_ = self->sidebar;
	code_sidebar_focus_sidebar (_tmp7_);
}

static void
scratch_main_window_action_focus_document (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_current_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ != NULL) {
		ScratchServicesDocument* _tmp2_;
		_tmp2_ = doc;
		scratch_services_document_focus (_tmp2_);
	}
	_g_object_unref0 (doc);
}

static GVariant*
_variant_new4 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static void
scratch_main_window_action_toggle_terminal (ScratchMainWindow* self)
{
	GSimpleAction* toggle_terminal_action = NULL;
	GSimpleActionGroup* _tmp0_;
	GSimpleAction* _tmp1_;
	GSimpleAction* _tmp2_;
	GSimpleAction* _tmp3_;
	GVariant* _tmp4_;
	GVariant* _tmp5_;
	GVariant* _tmp6_;
	CodeTerminal* _tmp7_;
	GSimpleAction* _tmp8_;
	GVariant* _tmp9_;
	GVariant* _tmp10_;
	GSimpleAction* _tmp11_;
	GVariant* _tmp12_;
	GVariant* _tmp13_;
	gboolean _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_actions;
	_tmp1_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_TERMINAL, _tmp0_);
	toggle_terminal_action = _tmp1_;
	_tmp2_ = toggle_terminal_action;
	_tmp3_ = toggle_terminal_action;
	_tmp4_ = g_action_get_state ((GAction*) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _variant_new4 (!g_variant_get_boolean (_tmp5_));
	g_simple_action_set_state (_tmp2_, _tmp6_);
	_g_variant_unref0 (_tmp6_);
	_g_variant_unref0 (_tmp5_);
	_tmp7_ = self->priv->terminal;
	_tmp8_ = toggle_terminal_action;
	_tmp9_ = g_action_get_state ((GAction*) _tmp8_);
	_tmp10_ = _tmp9_;
	gtk_widget_set_visible ((GtkWidget*) _tmp7_, g_variant_get_boolean (_tmp10_));
	_g_variant_unref0 (_tmp10_);
	_tmp11_ = toggle_terminal_action;
	_tmp12_ = g_action_get_state ((GAction*) _tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_variant_get_boolean (_tmp13_);
	_g_variant_unref0 (_tmp13_);
	if (_tmp14_) {
		CodeTerminal* _tmp15_;
		_tmp15_ = self->priv->terminal;
		gtk_widget_grab_focus ((GtkWidget*) _tmp15_);
	} else {
		ScratchServicesDocument* _tmp16_;
		ScratchServicesDocument* _tmp17_;
		gboolean _tmp18_;
		_tmp16_ = scratch_main_window_get_current_document (self);
		_tmp17_ = _tmp16_;
		_tmp18_ = _tmp17_ != NULL;
		_g_object_unref0 (_tmp17_);
		if (_tmp18_) {
			ScratchServicesDocument* _tmp19_;
			ScratchServicesDocument* _tmp20_;
			_tmp19_ = scratch_main_window_get_current_document (self);
			_tmp20_ = _tmp19_;
			scratch_services_document_focus (_tmp20_);
			_g_object_unref0 (_tmp20_);
		}
	}
	_g_object_unref0 (toggle_terminal_action);
}

static void
scratch_main_window_action_open_in_terminal (ScratchMainWindow* self,
                                             GSimpleAction* action,
                                             GVariant* param)
{
	CodeTerminal* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	gchar* target_path = NULL;
	gchar* _tmp6_;
	CodeTerminal* _tmp7_;
	CodeTerminal* _tmp8_;
	VteTerminal* _tmp9_;
	VteTerminal* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->terminal;
	_tmp1_ = gtk_widget_get_visible ((GtkWidget*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (!_tmp2_) {
		GSimpleAction* toggle_terminal_action = NULL;
		GSimpleActionGroup* _tmp3_;
		GSimpleAction* _tmp4_;
		GSimpleAction* _tmp5_;
		_tmp3_ = self->priv->_actions;
		_tmp4_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_TERMINAL, _tmp3_);
		toggle_terminal_action = _tmp4_;
		_tmp5_ = toggle_terminal_action;
		g_signal_emit_by_name (_tmp5_, "activate", NULL);
		_g_object_unref0 (toggle_terminal_action);
	}
	_tmp6_ = scratch_main_window_get_target_path_for_actions (self, param, TRUE);
	target_path = _tmp6_;
	_tmp7_ = self->priv->terminal;
	code_terminal_change_location (_tmp7_, target_path);
	_tmp8_ = self->priv->terminal;
	_tmp9_ = code_terminal_get_terminal (_tmp8_);
	_tmp10_ = _tmp9_;
	gtk_widget_grab_focus ((GtkWidget*) _tmp10_);
	_g_free0 (target_path);
}

static void
scratch_main_window_action_set_active_project (ScratchMainWindow* self,
                                               GSimpleAction* action,
                                               GVariant* param)
{
	gchar* project_path = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	ScratchFolderManagerFileView* _tmp2_;
	const gchar* _tmp3_;
	gchar* new_build_dir = NULL;
	ScratchServicesGitManager* _tmp8_;
	ScratchServicesGitManager* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	CodeTerminal* _tmp12_;
	const gchar* _tmp13_;
	CodeTerminal* _tmp14_;
	gboolean _tmp15_;
	gboolean _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = g_variant_get_string (param, NULL);
	_tmp1_ = g_strdup (_tmp0_);
	project_path = _tmp1_;
	_tmp2_ = self->priv->folder_manager_view;
	_tmp3_ = project_path;
	if (scratch_folder_manager_file_view_project_is_open (_tmp2_, _tmp3_)) {
		ScratchServicesGitManager* _tmp4_;
		const gchar* _tmp5_;
		ScratchFolderManagerFileView* _tmp6_;
		_tmp4_ = self->priv->git_manager;
		_tmp5_ = project_path;
		scratch_services_git_manager_set_active_project_path (_tmp4_, _tmp5_);
		_tmp6_ = self->priv->folder_manager_view;
		scratch_folder_manager_file_view_collapse_other_projects (_tmp6_);
	} else {
		const gchar* _tmp7_;
		_tmp7_ = project_path;
		g_warning ("MainWindow.vala:1492: Attempt to set folder path %s which is not opene" \
"d as active project ignored", _tmp7_);
	}
	_tmp8_ = scratch_services_git_manager_get_instance ();
	_tmp9_ = _tmp8_;
	_tmp10_ = scratch_services_git_manager_get_default_build_dir (_tmp9_, NULL);
	_tmp11_ = _tmp10_;
	_g_object_unref0 (_tmp9_);
	new_build_dir = _tmp11_;
	_tmp12_ = self->priv->terminal;
	_tmp13_ = new_build_dir;
	code_terminal_change_location (_tmp12_, _tmp13_);
	_tmp14_ = self->priv->terminal;
	_tmp15_ = gtk_widget_get_visible ((GtkWidget*) _tmp14_);
	_tmp16_ = _tmp15_;
	if (_tmp16_) {
		CodeTerminal* _tmp17_;
		VteTerminal* _tmp18_;
		VteTerminal* _tmp19_;
		_tmp17_ = self->priv->terminal;
		_tmp18_ = code_terminal_get_terminal (_tmp17_);
		_tmp19_ = _tmp18_;
		gtk_widget_grab_focus ((GtkWidget*) _tmp19_);
	}
	_g_free0 (new_build_dir);
	_g_free0 (project_path);
}

static GVariant*
_variant_new5 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static void
scratch_main_window_action_toggle_outline (ScratchMainWindow* self,
                                           GSimpleAction* action)
{
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	ScratchWidgetsDocumentView* _tmp3_;
	GVariant* _tmp4_;
	GVariant* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = g_action_get_state ((GAction*) action);
	_tmp1_ = _tmp0_;
	_tmp2_ = _variant_new5 (!g_variant_get_boolean (_tmp1_));
	g_simple_action_set_state (action, _tmp2_);
	_g_variant_unref0 (_tmp2_);
	_g_variant_unref0 (_tmp1_);
	_tmp3_ = self->document_view;
	_tmp4_ = g_action_get_state ((GAction*) action);
	_tmp5_ = _tmp4_;
	scratch_widgets_document_view_set_outline_visible (_tmp3_, g_variant_get_boolean (_tmp5_));
	_g_variant_unref0 (_tmp5_);
}

static void
scratch_main_window_action_next_tab (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_next_document (_tmp0_);
}

static void
scratch_main_window_action_previous_tab (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_previous_document (_tmp0_);
}

static void
scratch_main_window_action_clear_lines (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	ScratchWidgetsSourceView* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_focused_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp2_ = doc;
	_tmp3_ = scratch_services_document_get_source_view (_tmp2_);
	_tmp4_ = _tmp3_;
	scratch_widgets_source_view_clear_selected_lines (_tmp4_);
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_branch_actions (ScratchMainWindow* self,
                                           GSimpleAction* action,
                                           GVariant* param)
{
	ScratchFolderManagerFileView* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->folder_manager_view;
	_tmp1_ = scratch_main_window_get_target_path_for_actions (self, param, FALSE);
	_tmp2_ = _tmp1_;
	scratch_folder_manager_file_view_branch_actions (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
}

static void
scratch_main_window_action_previous_mark (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	ScratchWidgetsSourceView* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_focused_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp2_ = doc;
	_tmp3_ = scratch_services_document_get_source_view (_tmp2_);
	_tmp4_ = _tmp3_;
	scratch_widgets_source_view_goto_previous_mark (_tmp4_);
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_next_mark (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	ScratchWidgetsSourceView* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_focused_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp2_ = doc;
	_tmp3_ = scratch_services_document_get_source_view (_tmp2_);
	_tmp4_ = _tmp3_;
	scratch_widgets_source_view_goto_next_mark (_tmp4_);
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_add_mark (ScratchMainWindow* self)
{
	ScratchServicesDocument* doc = NULL;
	ScratchServicesDocument* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchWidgetsSourceView* _tmp3_;
	ScratchWidgetsSourceView* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = scratch_main_window_get_focused_document (self);
	doc = _tmp0_;
	_tmp1_ = doc;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (doc);
		return;
	}
	_tmp2_ = doc;
	_tmp3_ = scratch_services_document_get_source_view (_tmp2_);
	_tmp4_ = _tmp3_;
	scratch_widgets_source_view_add_mark_at_cursor (_tmp4_);
	_g_object_unref0 (doc);
}

static void
scratch_main_window_action_move_tab_to_new_window (ScratchMainWindow* self)
{
	ScratchWidgetsDocumentView* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->document_view;
	scratch_widgets_document_view_transfer_tab_to_new_window (_tmp0_);
}

static gchar*
scratch_main_window_get_target_path_for_actions (ScratchMainWindow* self,
                                                 GVariant* path_variant,
                                                 gboolean use_build_dir)
{
	gchar* path = NULL;
	gchar* _tmp0_;
	const gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup ("");
	path = _tmp0_;
	if (path_variant != NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = g_variant_get_string (path_variant, NULL);
		_tmp2_ = g_strdup (_tmp1_);
		_g_free0 (path);
		path = _tmp2_;
	}
	_tmp3_ = path;
	if (g_strcmp0 (_tmp3_, "") == 0) {
		ScratchServicesGitManager* _tmp4_;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		const gchar* _tmp11_;
		_tmp4_ = self->priv->git_manager;
		_tmp5_ = scratch_services_git_manager_get_active_project_path (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strdup (_tmp6_);
		_g_free0 (path);
		path = _tmp7_;
		if (use_build_dir) {
			ScratchServicesGitManager* _tmp8_;
			const gchar* _tmp9_;
			gchar* _tmp10_;
			_tmp8_ = self->priv->git_manager;
			_tmp9_ = path;
			_tmp10_ = scratch_services_git_manager_get_default_build_dir (_tmp8_, _tmp9_);
			_g_free0 (path);
			path = _tmp10_;
		}
		_tmp11_ = path;
		if (_tmp11_ == NULL) {
			ScratchServicesDocument* current_doc = NULL;
			ScratchServicesDocument* _tmp12_;
			ScratchServicesDocument* _tmp13_;
			_tmp12_ = scratch_main_window_get_current_document (self);
			current_doc = _tmp12_;
			_tmp13_ = current_doc;
			if (_tmp13_ != NULL) {
				ScratchServicesDocument* _tmp14_;
				GFile* _tmp15_;
				GFile* _tmp16_;
				gchar* _tmp17_;
				_tmp14_ = current_doc;
				_tmp15_ = scratch_services_document_get_file (_tmp14_);
				_tmp16_ = _tmp15_;
				_tmp17_ = g_file_get_path (_tmp16_);
				_g_free0 (path);
				path = _tmp17_;
			} else {
				result = NULL;
				_g_object_unref0 (current_doc);
				_g_free0 (path);
				return result;
			}
			_g_object_unref0 (current_doc);
		}
	}
	result = path;
	return result;
}

ScratchApplication*
scratch_main_window_get_app (ScratchMainWindow* self)
{
	ScratchApplication* result;
	ScratchApplication* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_app;
	result = _tmp0_;
	return result;
}

static void
scratch_main_window_set_app (ScratchMainWindow* self,
                             ScratchApplication* value)
{
	ScratchApplication* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_main_window_get_app (self);
	if (old_value != value) {
		ScratchApplication* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_app);
		self->priv->_app = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_APP_PROPERTY]);
	}
}

gboolean
scratch_main_window_get_restore_docs (ScratchMainWindow* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_restore_docs;
	return result;
}

static void
scratch_main_window_set_restore_docs (ScratchMainWindow* self,
                                      gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_main_window_get_restore_docs (self);
	if (old_value != value) {
		self->priv->_restore_docs = value;
		g_object_notify_by_pspec ((GObject *) self, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_RESTORE_DOCS_PROPERTY]);
	}
}

RestoreOverride*
scratch_main_window_get_restore_override (ScratchMainWindow* self)
{
	RestoreOverride* result;
	RestoreOverride* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_restore_override;
	result = _tmp0_;
	return result;
}

void
scratch_main_window_set_restore_override (ScratchMainWindow* self,
                                          RestoreOverride* value)
{
	RestoreOverride* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_main_window_get_restore_override (self);
	if (old_value != value) {
		RestoreOverride* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_restore_override);
		self->priv->_restore_override = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_RESTORE_OVERRIDE_PROPERTY]);
	}
}

gchar*
scratch_main_window_get_default_globalsearch_path (ScratchMainWindow* self)
{
	gchar* result;
	ScratchWidgetsDocumentView* _tmp0_;
	ScratchServicesDocument* _tmp1_;
	ScratchServicesDocument* _tmp2_;
	ScratchServicesGitManager* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->document_view;
	_tmp1_ = scratch_widgets_document_view_get_current_document (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != NULL) {
		ScratchWidgetsDocumentView* _tmp3_;
		ScratchServicesDocument* _tmp4_;
		ScratchServicesDocument* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gboolean _tmp9_;
		_tmp3_ = self->document_view;
		_tmp4_ = scratch_widgets_document_view_get_current_document (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = scratch_services_document_get_project_path (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_;
		_tmp9_ = g_strcmp0 (_tmp8_, "") != 0;
		_g_free0 (_tmp8_);
		if (_tmp9_) {
			ScratchWidgetsDocumentView* _tmp10_;
			ScratchServicesDocument* _tmp11_;
			ScratchServicesDocument* _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			_tmp10_ = self->document_view;
			_tmp11_ = scratch_widgets_document_view_get_current_document (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = scratch_services_document_get_project_path (_tmp12_);
			_tmp14_ = _tmp13_;
			result = _tmp14_;
			return result;
		}
	}
	_tmp15_ = self->priv->git_manager;
	_tmp16_ = scratch_services_git_manager_get_active_project_path (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = g_strdup (_tmp17_);
	result = _tmp18_;
	return result;
}

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

static void
scratch_main_window_set_actions (ScratchMainWindow* self,
                                 GSimpleActionGroup* value)
{
	GSimpleActionGroup* old_value;
	g_return_if_fail (self != NULL);
	old_value = scratch_main_window_get_actions (self);
	if (old_value != value) {
		GSimpleActionGroup* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_actions);
		self->priv->_actions = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_ACTIONS_PROPERTY]);
	}
}

static void
_vala_array_add2 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_scratch_main_window___lambda197_ (ScratchMainWindow* self)
{
	scratch_main_window_update_style (self);
}

static void
__scratch_main_window___lambda197__g_settings_changed (GSettings* _sender,
                                                       const gchar* key,
                                                       gpointer self)
{
	_scratch_main_window___lambda197_ ((ScratchMainWindow*) self);
}

static gboolean
_scratch_main_window_on_key_pressed_gtk_event_controller_key_key_pressed (GtkEventControllerKey* _sender,
                                                                          guint keyval,
                                                                          guint keycode,
                                                                          GdkModifierType state,
                                                                          gpointer self)
{
	gboolean result;
	result = scratch_main_window_on_key_pressed ((ScratchMainWindow*) self, keyval, keycode, state);
	return result;
}

static void
_scratch_main_window___lambda198_ (ScratchMainWindow* self)
{
	ScratchHeaderBar* _tmp0_;
	GtkButton* _tmp1_;
	GtkButton* _tmp2_;
	ScratchServicesPluginsManager* _tmp3_;
	ScratchServicesInterface* _tmp4_;
	ScratchServicesInterface* _tmp5_;
	ScratchTemplateManager* _tmp6_;
	ScratchTemplateManager* _tmp7_;
	_tmp0_ = self->toolbar;
	_tmp1_ = scratch_header_bar_get_templates_button (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->plugins;
	_tmp4_ = scratch_services_plugins_manager_get_plugin_iface (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = scratch_services_interface_get_template_manager (_tmp5_);
	_tmp7_ = _tmp6_;
	gtk_widget_set_visible ((GtkWidget*) _tmp2_, _tmp7_->template_available);
}

static void
__scratch_main_window___lambda198__g_object_notify (GObject* _sender,
                                                    GParamSpec* pspec,
                                                    gpointer self)
{
	_scratch_main_window___lambda198_ ((ScratchMainWindow*) self);
}

static void
_scratch_main_window___lambda199_ (ScratchMainWindow* self,
                                   const gchar* name,
                                   GVariant* new_state)
{
	g_return_if_fail (name != NULL);
	g_return_if_fail (new_state != NULL);
	scratch_main_window_update_toolbar_button (self, name, g_variant_get_boolean (new_state));
}

static void
__scratch_main_window___lambda199__g_action_group_action_state_changed (GActionGroup* _sender,
                                                                        const gchar* action_name,
                                                                        GVariant* state,
                                                                        gpointer self)
{
	_scratch_main_window___lambda199_ ((ScratchMainWindow*) self, action_name, state);
}

static GVariant*
_variant_new6 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static GVariant*
_variant_new7 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static GVariant*
_variant_new8 (gboolean value)
{
	return g_variant_ref_sink (g_variant_new_boolean (value));
}

static gboolean
_scratch_main_window_quit_source_func_gsource_func (gpointer self)
{
	gboolean result;
	result = scratch_main_window_quit_source_func ((ScratchMainWindow*) self);
	return result;
}

static GObject *
scratch_main_window_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ScratchMainWindow * self;
	GApplication* _tmp0_;
	GtkApplication* _tmp1_;
	GtkApplication* _tmp2_;
	const gchar* _tmp3_;
	GtkIconTheme* default_theme = NULL;
	GtkIconTheme* _tmp4_;
	GtkIconTheme* _tmp5_;
	ScratchServicesDocumentManager* _tmp6_;
	ScratchServicesGitManager* _tmp7_;
	GSimpleActionGroup* _tmp8_;
	GSimpleActionGroup* _tmp9_;
	GSimpleActionGroup* _tmp10_;
	GSimpleActionGroup* _tmp11_;
	GdkRectangle rect = {0};
	GSettings* _tmp32_;
	gint _tmp33_ = 0;
	gint _tmp34_ = 0;
	GdkRectangle _tmp35_;
	GdkRectangle _tmp36_;
	GSettings* _tmp37_;
	GdkDisplay* _tmp38_;
	GtkClipboard* _tmp39_;
	GtkClipboard* _tmp40_;
	ScratchServicesPluginsManager* _tmp41_;
	GtkEventControllerKey* _tmp42_ = NULL;
	GtkEventControllerKey* _tmp43_;
	gint window_state = 0;
	GSettings* _tmp44_;
	ScratchHeaderBar* _tmp45_;
	GtkButton* _tmp46_;
	GtkButton* _tmp47_;
	ScratchServicesPluginsManager* _tmp48_;
	ScratchServicesInterface* _tmp49_;
	ScratchServicesInterface* _tmp50_;
	ScratchTemplateManager* _tmp51_;
	ScratchTemplateManager* _tmp52_;
	ScratchServicesPluginsManager* _tmp53_;
	ScratchServicesInterface* _tmp54_;
	ScratchServicesInterface* _tmp55_;
	ScratchTemplateManager* _tmp56_;
	ScratchTemplateManager* _tmp57_;
	GSimpleActionGroup* _tmp58_;
	GSimpleAction* sidebar_action = NULL;
	GSimpleActionGroup* _tmp59_;
	GSimpleAction* _tmp60_;
	GSimpleAction* _tmp61_;
	GSettings* _tmp62_;
	GVariant* _tmp63_;
	GSettings* _tmp64_;
	GSimpleAction* outline_action = NULL;
	GSimpleActionGroup* _tmp65_;
	GSimpleAction* _tmp66_;
	GSimpleAction* _tmp67_;
	GSettings* _tmp68_;
	GVariant* _tmp69_;
	GSettings* _tmp70_;
	GSimpleAction* terminal_action = NULL;
	GSimpleActionGroup* _tmp71_;
	GSimpleAction* _tmp72_;
	GSimpleAction* _tmp73_;
	GSettings* _tmp74_;
	GVariant* _tmp75_;
	GSettings* _tmp76_;
	parent_class = G_OBJECT_CLASS (scratch_main_window_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_TYPE_MAIN_WINDOW, ScratchMainWindow);
	_tmp0_ = g_application_get_default ();
	gtk_window_set_application ((GtkWindow*) self, G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, gtk_application_get_type (), GtkApplication));
	_tmp1_ = gtk_window_get_application ((GtkWindow*) self);
	_tmp2_ = _tmp1_;
	scratch_main_window_set_app (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, SCRATCH_TYPE_APPLICATION, ScratchApplication));
	_tmp3_ = scratch_main_window_base_title;
	gtk_window_set_title ((GtkWindow*) self, _tmp3_);
	_tmp4_ = gtk_icon_theme_get_default ();
	default_theme = _tmp4_;
	_tmp5_ = default_theme;
	gtk_icon_theme_add_resource_path (_tmp5_, "/io/elementary/code");
	_tmp6_ = scratch_services_document_manager_get_instance ();
	_g_object_unref0 (self->priv->document_manager);
	self->priv->document_manager = _tmp6_;
	_tmp7_ = scratch_services_git_manager_get_instance ();
	_g_object_unref0 (self->priv->git_manager);
	self->priv->git_manager = _tmp7_;
	_tmp8_ = g_simple_action_group_new ();
	_tmp9_ = _tmp8_;
	scratch_main_window_set_actions (self, _tmp9_);
	_g_object_unref0 (_tmp9_);
	_tmp10_ = self->priv->_actions;
	g_action_map_add_action_entries ((GActionMap*) _tmp10_, SCRATCH_MAIN_WINDOW_ACTION_ENTRIES, (gint) G_N_ELEMENTS (SCRATCH_MAIN_WINDOW_ACTION_ENTRIES), self);
	_tmp11_ = self->priv->_actions;
	gtk_widget_insert_action_group ((GtkWidget*) self, SCRATCH_MAIN_WINDOW_ACTION_GROUP, (GActionGroup*) _tmp11_);
	{
		GeeIterator* _action_it = NULL;
		GeeMultiMap* _tmp12_;
		GeeSet* _tmp13_;
		GeeSet* _tmp14_;
		GeeIterator* _tmp15_;
		GeeIterator* _tmp16_;
		_tmp12_ = scratch_main_window_action_accelerators;
		_tmp13_ = gee_multi_map_get_keys (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp15_ = gee_iterable_iterator ((GeeIterable*) _tmp14_);
		_tmp16_ = _tmp15_;
		_g_object_unref0 (_tmp14_);
		_action_it = _tmp16_;
		while (TRUE) {
			GeeIterator* _tmp17_;
			gchar* action = NULL;
			GeeIterator* _tmp18_;
			gpointer _tmp19_;
			gchar** accels_array = NULL;
			GeeMultiMap* _tmp20_;
			const gchar* _tmp21_;
			GeeCollection* _tmp22_;
			GeeCollection* _tmp23_;
			gint _tmp24_ = 0;
			gpointer* _tmp25_;
			gchar** _tmp26_;
			gint _tmp26__length1;
			gint accels_array_length1;
			gint _accels_array_size_;
			ScratchApplication* _tmp27_;
			const gchar* _tmp28_;
			gchar* _tmp29_;
			gchar* _tmp30_;
			gchar** _tmp31_;
			gint _tmp31__length1;
			_tmp17_ = _action_it;
			if (!gee_iterator_next (_tmp17_)) {
				break;
			}
			_tmp18_ = _action_it;
			_tmp19_ = gee_iterator_get (_tmp18_);
			action = (gchar*) _tmp19_;
			_tmp20_ = scratch_main_window_action_accelerators;
			_tmp21_ = action;
			_tmp22_ = gee_multi_map_get (_tmp20_, _tmp21_);
			_tmp23_ = _tmp22_;
			_tmp25_ = gee_collection_to_array (_tmp23_, &_tmp24_);
			_tmp26_ = _tmp25_;
			_tmp26__length1 = _tmp24_;
			_g_object_unref0 (_tmp23_);
			accels_array = _tmp26_;
			accels_array_length1 = _tmp26__length1;
			_accels_array_size_ = accels_array_length1;
			_vala_array_add2 (&accels_array, &accels_array_length1, &_accels_array_size_, NULL);
			_tmp27_ = self->priv->_app;
			_tmp28_ = action;
			_tmp29_ = g_strconcat (SCRATCH_MAIN_WINDOW_ACTION_PREFIX, _tmp28_, NULL);
			_tmp30_ = _tmp29_;
			_tmp31_ = accels_array;
			_tmp31__length1 = accels_array_length1;
			gtk_application_set_accels_for_action ((GtkApplication*) _tmp27_, _tmp30_, _tmp31_);
			_g_free0 (_tmp30_);
			accels_array = (_vala_array_free (accels_array, accels_array_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (action);
		}
		_g_object_unref0 (_action_it);
	}
	gtk_widget_set_size_request ((GtkWidget*) self, 450, 400);
	gtk_window_set_hide_titlebar_when_maximized ((GtkWindow*) self, FALSE);
	memset (&rect, 0, sizeof (GdkRectangle));
	_tmp32_ = scratch_saved_state;
	g_settings_get (_tmp32_, "window-size", "(ii)", &_tmp33_, &_tmp34_);
	rect.width = _tmp33_;
	rect.height = _tmp34_;
	_tmp35_ = rect;
	g_object_set ((GtkWindow*) self, "default-width", _tmp35_.width, NULL);
	_tmp36_ = rect;
	g_object_set ((GtkWindow*) self, "default-height", _tmp36_.height, NULL);
	scratch_main_window_update_style (self);
	_tmp37_ = scratch_settings;
	g_signal_connect_object (_tmp37_, "changed::follow-system-style", (GCallback) __scratch_main_window___lambda197__g_settings_changed, self, 0);
	_tmp38_ = gtk_widget_get_display ((GtkWidget*) self);
	_tmp39_ = gtk_clipboard_get_for_display (_tmp38_, GDK_SELECTION_CLIPBOARD);
	_tmp40_ = _g_object_ref0 (_tmp39_);
	_g_object_unref0 (self->clipboard);
	self->clipboard = _tmp40_;
	_tmp41_ = scratch_services_plugins_manager_new (self);
	_g_object_unref0 (self->priv->plugins);
	self->priv->plugins = _tmp41_;
	_tmp42_ = (GtkEventControllerKey*) gtk_event_controller_key_new ((GtkWidget*) self);
	gtk_event_controller_set_propagation_phase ((GtkEventController*) _tmp42_, GTK_PHASE_TARGET);
	_g_object_unref0 (self->priv->key_controller);
	self->priv->key_controller = _tmp42_;
	_tmp43_ = self->priv->key_controller;
	g_signal_connect_object (_tmp43_, "key-pressed", (GCallback) _scratch_main_window_on_key_pressed_gtk_event_controller_key_key_pressed, self, 0);
	scratch_main_window_init_layout (self);
	_tmp44_ = scratch_saved_state;
	window_state = g_settings_get_enum (_tmp44_, "window-state");
	switch (window_state) {
		case SCRATCH_SCRATCH_WINDOW_STATE_MAXIMIZED:
		{
			gtk_window_maximize ((GtkWindow*) self);
			break;
		}
		case SCRATCH_SCRATCH_WINDOW_STATE_FULLSCREEN:
		{
			gtk_window_fullscreen ((GtkWindow*) self);
			break;
		}
		default:
		{
			gtk_window_unfullscreen ((GtkWindow*) self);
			break;
		}
	}
	gtk_widget_show_all ((GtkWidget*) self);
	_tmp45_ = self->toolbar;
	_tmp46_ = scratch_header_bar_get_templates_button (_tmp45_);
	_tmp47_ = _tmp46_;
	_tmp48_ = self->priv->plugins;
	_tmp49_ = scratch_services_plugins_manager_get_plugin_iface (_tmp48_);
	_tmp50_ = _tmp49_;
	_tmp51_ = scratch_services_interface_get_template_manager (_tmp50_);
	_tmp52_ = _tmp51_;
	gtk_widget_set_visible ((GtkWidget*) _tmp47_, _tmp52_->template_available);
	_tmp53_ = self->priv->plugins;
	_tmp54_ = scratch_services_plugins_manager_get_plugin_iface (_tmp53_);
	_tmp55_ = _tmp54_;
	_tmp56_ = scratch_services_interface_get_template_manager (_tmp55_);
	_tmp57_ = _tmp56_;
	g_signal_connect_object ((GObject*) _tmp57_, "notify::template_available", (GCallback) __scratch_main_window___lambda198__g_object_notify, self, 0);
	scratch_main_window_create_unsaved_documents_directory (self);
	_tmp58_ = self->priv->_actions;
	g_signal_connect_object ((GActionGroup*) _tmp58_, "action-state-changed", (GCallback) __scratch_main_window___lambda199__g_action_group_action_state_changed, self, 0);
	_tmp59_ = self->priv->_actions;
	_tmp60_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SIDEBAR, _tmp59_);
	sidebar_action = _tmp60_;
	_tmp61_ = sidebar_action;
	_tmp62_ = scratch_saved_state;
	_tmp63_ = _variant_new6 (g_settings_get_boolean (_tmp62_, "sidebar-visible"));
	g_simple_action_set_state (_tmp61_, _tmp63_);
	_g_variant_unref0 (_tmp63_);
	_tmp64_ = scratch_saved_state;
	scratch_main_window_update_toolbar_button (self, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SIDEBAR, g_settings_get_boolean (_tmp64_, "sidebar-visible"));
	_tmp65_ = self->priv->_actions;
	_tmp66_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_OUTLINE, _tmp65_);
	outline_action = _tmp66_;
	_tmp67_ = outline_action;
	_tmp68_ = scratch_saved_state;
	_tmp69_ = _variant_new7 (g_settings_get_boolean (_tmp68_, "outline-visible"));
	g_simple_action_set_state (_tmp67_, _tmp69_);
	_g_variant_unref0 (_tmp69_);
	_tmp70_ = scratch_saved_state;
	scratch_main_window_update_toolbar_button (self, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_OUTLINE, g_settings_get_boolean (_tmp70_, "outline-visible"));
	_tmp71_ = self->priv->_actions;
	_tmp72_ = scratch_utils_action_from_group (SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_TERMINAL, _tmp71_);
	terminal_action = _tmp72_;
	_tmp73_ = terminal_action;
	_tmp74_ = scratch_saved_state;
	_tmp75_ = _variant_new8 (g_settings_get_boolean (_tmp74_, "terminal-visible"));
	g_simple_action_set_state (_tmp73_, _tmp75_);
	_g_variant_unref0 (_tmp75_);
	_tmp76_ = scratch_saved_state;
	scratch_main_window_update_toolbar_button (self, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_TERMINAL, g_settings_get_boolean (_tmp76_, "terminal-visible"));
	g_unix_signal_add_full (G_PRIORITY_HIGH, (gint) SIGINT, _scratch_main_window_quit_source_func_gsource_func, g_object_ref (self), g_object_unref);
	g_unix_signal_add_full (G_PRIORITY_HIGH, (gint) SIGTERM, _scratch_main_window_quit_source_func_gsource_func, g_object_ref (self), g_object_unref);
	_g_object_unref0 (terminal_action);
	_g_object_unref0 (outline_action);
	_g_object_unref0 (sidebar_action);
	return obj;
}

static void
scratch_main_window_class_init (ScratchMainWindowClass * klass,
                                gpointer klass_data)
{
	GeeHashMultiMap* _tmp0_;
	GeeMultiMap* _tmp1_;
	GeeMultiMap* _tmp2_;
	GeeMultiMap* _tmp3_;
	GeeMultiMap* _tmp4_;
	GeeMultiMap* _tmp5_;
	GeeMultiMap* _tmp6_;
	GeeMultiMap* _tmp7_;
	GeeMultiMap* _tmp8_;
	GeeMultiMap* _tmp9_;
	GeeMultiMap* _tmp10_;
	GeeMultiMap* _tmp11_;
	GeeMultiMap* _tmp12_;
	GeeMultiMap* _tmp13_;
	GeeMultiMap* _tmp14_;
	GeeMultiMap* _tmp15_;
	GeeMultiMap* _tmp16_;
	GeeMultiMap* _tmp17_;
	GeeMultiMap* _tmp18_;
	GeeMultiMap* _tmp19_;
	GeeMultiMap* _tmp20_;
	GeeMultiMap* _tmp21_;
	GeeMultiMap* _tmp22_;
	GeeMultiMap* _tmp23_;
	GeeMultiMap* _tmp24_;
	GeeMultiMap* _tmp25_;
	GeeMultiMap* _tmp26_;
	GeeMultiMap* _tmp27_;
	GeeMultiMap* _tmp28_;
	GeeMultiMap* _tmp29_;
	GeeMultiMap* _tmp30_;
	GeeMultiMap* _tmp31_;
	GeeMultiMap* _tmp32_;
	GeeMultiMap* _tmp33_;
	GeeMultiMap* _tmp34_;
	GeeMultiMap* _tmp35_;
	GeeMultiMap* _tmp36_;
	GeeMultiMap* _tmp37_;
	GeeMultiMap* _tmp38_;
	GeeMultiMap* _tmp39_;
	GeeMultiMap* _tmp40_;
	GeeMultiMap* _tmp41_;
	GeeMultiMap* _tmp42_;
	GeeMultiMap* _tmp43_;
	GeeMultiMap* _tmp44_;
	GeeMultiMap* _tmp45_;
	GeeMultiMap* _tmp46_;
	GeeMultiMap* _tmp47_;
	GeeMultiMap* _tmp48_;
	GeeMultiMap* _tmp49_;
	GeeMultiMap* _tmp50_;
	GeeMultiMap* _tmp51_;
	GtkCssProvider* provider = NULL;
	GtkCssProvider* _tmp52_;
	GtkCssProvider* _tmp53_;
	GdkScreen* _tmp54_;
	GtkCssProvider* _tmp55_;
	scratch_main_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ScratchMainWindow_private_offset);
	((GtkWidgetClass *) klass)->delete_event = (gboolean (*) (GtkWidget*, GdkEventAny*)) scratch_main_window_real_delete_event;
	G_OBJECT_CLASS (klass)->get_property = _vala_scratch_main_window_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_scratch_main_window_set_property;
	G_OBJECT_CLASS (klass)->constructor = scratch_main_window_constructor;
	G_OBJECT_CLASS (klass)->finalize = scratch_main_window_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_MAIN_WINDOW_APP_PROPERTY, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_APP_PROPERTY] = g_param_spec_object ("app", "app", "app", SCRATCH_TYPE_APPLICATION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_MAIN_WINDOW_RESTORE_DOCS_PROPERTY, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_RESTORE_DOCS_PROPERTY] = g_param_spec_boolean ("restore-docs", "restore-docs", "restore-docs", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_MAIN_WINDOW_RESTORE_OVERRIDE_PROPERTY, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_RESTORE_OVERRIDE_PROPERTY] = g_param_spec_object ("restore-override", "restore-override", "restore-override", TYPE_RESTORE_OVERRIDE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_MAIN_WINDOW_DEFAULT_GLOBALSEARCH_PATH_PROPERTY, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_DEFAULT_GLOBALSEARCH_PATH_PROPERTY] = g_param_spec_string ("default-globalsearch-path", "default-globalsearch-path", "default-globalsearch-path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), SCRATCH_MAIN_WINDOW_ACTIONS_PROPERTY, scratch_main_window_properties[SCRATCH_MAIN_WINDOW_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_ONLY));
	_tmp0_ = gee_hash_multi_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	scratch_main_window_action_accelerators = (GeeMultiMap*) _tmp0_;
	_tmp1_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp1_, SCRATCH_MAIN_WINDOW_ACTION_FIND "::", "<Control>f");
	_tmp2_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp2_, SCRATCH_MAIN_WINDOW_ACTION_FIND_NEXT, "<Control>g");
	_tmp3_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp3_, SCRATCH_MAIN_WINDOW_ACTION_FIND_PREVIOUS, "<Control><shift>g");
	_tmp4_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp4_, SCRATCH_MAIN_WINDOW_ACTION_FIND_GLOBAL "::", "<Control><shift>f");
	_tmp5_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp5_, SCRATCH_MAIN_WINDOW_ACTION_OPEN, "<Control>o");
	_tmp6_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp6_, SCRATCH_MAIN_WINDOW_ACTION_OPEN_PROJECT, "<Control><Shift>o");
	_tmp7_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp7_, SCRATCH_MAIN_WINDOW_ACTION_REVERT, "<Control><shift>r");
	_tmp8_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp8_, SCRATCH_MAIN_WINDOW_ACTION_SAVE, "<Control>s");
	_tmp9_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp9_, SCRATCH_MAIN_WINDOW_ACTION_SAVE_AS, "<Control><shift>s");
	_tmp10_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp10_, SCRATCH_MAIN_WINDOW_ACTION_GO_TO, "<Control>i");
	_tmp11_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp11_, SCRATCH_MAIN_WINDOW_ACTION_SORT_LINES, "F5");
	_tmp12_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp12_, SCRATCH_MAIN_WINDOW_ACTION_NEW_TAB, "<Control>n");
	_tmp13_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp13_, SCRATCH_MAIN_WINDOW_ACTION_DUPLICATE_TAB, "<Control><Shift>k");
	_tmp14_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp14_, SCRATCH_MAIN_WINDOW_ACTION_UNDO, "<Control>z");
	_tmp15_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp15_, SCRATCH_MAIN_WINDOW_ACTION_REDO, "<Control><shift>z");
	_tmp16_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp16_, SCRATCH_MAIN_WINDOW_ACTION_SHOW_REPLACE, "<Control>r");
	_tmp17_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp17_, SCRATCH_MAIN_WINDOW_ACTION_TO_LOWER_CASE, "<Control>l");
	_tmp18_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp18_, SCRATCH_MAIN_WINDOW_ACTION_TO_UPPER_CASE, "<Control>u");
	_tmp19_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp19_, SCRATCH_MAIN_WINDOW_ACTION_DUPLICATE, "<Control>d");
	_tmp20_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp20_, SCRATCH_MAIN_WINDOW_ACTION_FULLSCREEN, "F11");
	_tmp21_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp21_, SCRATCH_MAIN_WINDOW_ACTION_QUIT, "<Control>q");
	_tmp22_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp22_, SCRATCH_MAIN_WINDOW_ACTION_CLOSE_WINDOW, "<Control>F4");
	_tmp23_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp23_, SCRATCH_MAIN_WINDOW_ACTION_ZOOM_DEFAULT, "<Control>0");
	_tmp24_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp24_, SCRATCH_MAIN_WINDOW_ACTION_ZOOM_DEFAULT, "<Control>KP_0");
	_tmp25_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp25_, SCRATCH_MAIN_WINDOW_ACTION_ZOOM_IN, "<Control>plus");
	_tmp26_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp26_, SCRATCH_MAIN_WINDOW_ACTION_ZOOM_IN, "<Control>equal");
	_tmp27_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp27_, SCRATCH_MAIN_WINDOW_ACTION_ZOOM_IN, "<Control>KP_Add");
	_tmp28_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp28_, SCRATCH_MAIN_WINDOW_ACTION_ZOOM_OUT, "<Control>minus");
	_tmp29_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp29_, SCRATCH_MAIN_WINDOW_ACTION_ZOOM_OUT, "<Control>KP_Subtract");
	_tmp30_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp30_, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_COMMENT, "<Control>m");
	_tmp31_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp31_, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_COMMENT, "<Control>slash");
	_tmp32_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp32_, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SIDEBAR, "F9");
	_tmp33_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp33_, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_SIDEBAR, "<Control>backslash");
	_tmp34_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp34_, SCRATCH_MAIN_WINDOW_ACTION_FOCUS_SIDEBAR, "<Control><Alt>Left");
	_tmp35_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp35_, SCRATCH_MAIN_WINDOW_ACTION_FOCUS_DOCUMENT, "<Control><Alt>Right");
	_tmp36_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp36_, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_TERMINAL, "<Control><Alt>t");
	_tmp37_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp37_, SCRATCH_MAIN_WINDOW_ACTION_OPEN_IN_TERMINAL "::", "<Control><Alt><Shift>t");
	_tmp38_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp38_, SCRATCH_MAIN_WINDOW_ACTION_TOGGLE_OUTLINE, "<Alt>backslash");
	_tmp39_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp39_, SCRATCH_MAIN_WINDOW_ACTION_NEXT_TAB, "<Control>Tab");
	_tmp40_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp40_, SCRATCH_MAIN_WINDOW_ACTION_NEXT_TAB, "<Control>Page_Down");
	_tmp41_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp41_, SCRATCH_MAIN_WINDOW_ACTION_CLOSE_TAB "::", "<Control>w");
	_tmp42_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp42_, SCRATCH_MAIN_WINDOW_ACTION_PREVIOUS_TAB, "<Control><Shift>Tab");
	_tmp43_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp43_, SCRATCH_MAIN_WINDOW_ACTION_PREVIOUS_TAB, "<Control>Page_Up");
	_tmp44_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp44_, SCRATCH_MAIN_WINDOW_ACTION_CLEAR_LINES, "<Control>K");
	_tmp45_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp45_, SCRATCH_MAIN_WINDOW_ACTION_BRANCH_ACTIONS "::", "<Control>B");
	_tmp46_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp46_, SCRATCH_MAIN_WINDOW_ACTION_ADD_MARK, "<Alt>equal");
	_tmp47_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp47_, SCRATCH_MAIN_WINDOW_ACTION_PREVIOUS_MARK, "<Alt>Left");
	_tmp48_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp48_, SCRATCH_MAIN_WINDOW_ACTION_NEXT_MARK, "<Alt>Right");
	_tmp49_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp49_, SCRATCH_MAIN_WINDOW_ACTION_HIDE_PROJECT_DOCS "::", "<Control><Shift>h");
	_tmp50_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp50_, SCRATCH_MAIN_WINDOW_ACTION_MOVE_TAB_TO_NEW_WINDOW, "<Control><Alt>n");
	_tmp51_ = scratch_main_window_action_accelerators;
	gee_multi_map_set (_tmp51_, SCRATCH_MAIN_WINDOW_ACTION_RESTORE_PROJECT_DOCS "::", "<Control><Shift>r");
	_tmp52_ = gtk_css_provider_new ();
	provider = _tmp52_;
	_tmp53_ = provider;
	gtk_css_provider_load_from_resource (_tmp53_, "io/elementary/code/Application.css");
	_tmp54_ = gdk_screen_get_default ();
	_tmp55_ = provider;
	gtk_style_context_add_provider_for_screen (_tmp54_, (GtkStyleProvider*) _tmp55_, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	if (g_strcmp0 (CONSTANTS_BRANCH, "") != 0) {
		gchar* _tmp56_;
		_tmp56_ = g_strdup_printf (_ ("Code (%s)"), CONSTANTS_BRANCH);
		_g_free0 (scratch_main_window_base_title);
		scratch_main_window_base_title = _tmp56_;
	} else {
		gchar* _tmp57_;
		_tmp57_ = g_strdup (_ ("Code"));
		_g_free0 (scratch_main_window_base_title);
		scratch_main_window_base_title = _tmp57_;
	}
	hdy_init ();
	_g_object_unref0 (provider);
}

static void
scratch_main_window_instance_init (ScratchMainWindow * self,
                                   gpointer klass)
{
	self->priv = scratch_main_window_get_instance_private (self);
	self->priv->preferences_dialog = NULL;
	self->priv->color_scheme_listener_handler_id = (gulong) 0;
}

static void
scratch_main_window_finalize (GObject * obj)
{
	ScratchMainWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SCRATCH_TYPE_MAIN_WINDOW, ScratchMainWindow);
	_g_object_unref0 (self->priv->_app);
	_g_object_unref0 (self->priv->_restore_override);
	_g_object_unref0 (self->document_view);
	_g_object_unref0 (self->toolbar);
	_g_object_unref0 (self->search_bar);
	_g_object_unref0 (self->priv->welcome_view);
	_g_object_unref0 (self->priv->terminal);
	_g_object_unref0 (self->priv->folder_manager_view);
	_g_object_unref0 (self->priv->document_manager);
	_g_object_unref0 (self->priv->key_controller);
	_g_object_unref0 (self->priv->plugins);
	_g_object_unref0 (self->sidebar);
	_g_object_unref0 (self->priv->preferences_dialog);
	_g_object_unref0 (self->priv->hp1);
	_g_object_unref0 (self->priv->vp);
	_g_object_unref0 (self->priv->content_stack);
	_g_object_unref0 (self->clipboard);
	_g_object_unref0 (self->priv->_actions);
	_g_object_unref0 (self->priv->git_manager);
	G_OBJECT_CLASS (scratch_main_window_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
scratch_main_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ScratchMainWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) scratch_main_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ScratchMainWindow), 0, (GInstanceInitFunc) scratch_main_window_instance_init, NULL };
	GType scratch_main_window_type_id;
	scratch_main_window_type_id = g_type_register_static (hdy_window_get_type (), "ScratchMainWindow", &g_define_type_info, G_TYPE_FLAG_NONE);
	ScratchMainWindow_private_offset = g_type_add_instance_private (scratch_main_window_type_id, sizeof (ScratchMainWindowPrivate));
	return scratch_main_window_type_id;
}

GType
scratch_main_window_get_type (void)
{
	static gsize scratch_main_window_type_id__once = 0;
	if (g_once_init_enter (&scratch_main_window_type_id__once)) {
		GType scratch_main_window_type_id;
		scratch_main_window_type_id = scratch_main_window_get_type_once ();
		g_once_init_leave (&scratch_main_window_type_id__once, scratch_main_window_type_id);
	}
	return scratch_main_window_type_id__once;
}

static void
_vala_scratch_main_window_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	ScratchMainWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_TYPE_MAIN_WINDOW, ScratchMainWindow);
	switch (property_id) {
		case SCRATCH_MAIN_WINDOW_APP_PROPERTY:
		g_value_set_object (value, scratch_main_window_get_app (self));
		break;
		case SCRATCH_MAIN_WINDOW_RESTORE_DOCS_PROPERTY:
		g_value_set_boolean (value, scratch_main_window_get_restore_docs (self));
		break;
		case SCRATCH_MAIN_WINDOW_RESTORE_OVERRIDE_PROPERTY:
		g_value_set_object (value, scratch_main_window_get_restore_override (self));
		break;
		case SCRATCH_MAIN_WINDOW_DEFAULT_GLOBALSEARCH_PATH_PROPERTY:
		g_value_take_string (value, scratch_main_window_get_default_globalsearch_path (self));
		break;
		case SCRATCH_MAIN_WINDOW_ACTIONS_PROPERTY:
		g_value_set_object (value, scratch_main_window_get_actions (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_scratch_main_window_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	ScratchMainWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SCRATCH_TYPE_MAIN_WINDOW, ScratchMainWindow);
	switch (property_id) {
		case SCRATCH_MAIN_WINDOW_APP_PROPERTY:
		scratch_main_window_set_app (self, g_value_get_object (value));
		break;
		case SCRATCH_MAIN_WINDOW_RESTORE_DOCS_PROPERTY:
		scratch_main_window_set_restore_docs (self, g_value_get_boolean (value));
		break;
		case SCRATCH_MAIN_WINDOW_RESTORE_OVERRIDE_PROPERTY:
		scratch_main_window_set_restore_override (self, g_value_get_object (value));
		break;
		case SCRATCH_MAIN_WINDOW_ACTIONS_PROPERTY:
		scratch_main_window_set_actions (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;
}

