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

/*
* Copyright (c) 2011-2016 Felipe Escoto (https://github.com/Philip-Scott/Notes-up)
*
* 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 2 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authored by: Felipe Escoto <felescoto95@hotmail.com>
*/

#include <glib-object.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
#include <granite.h>
#include <stdlib.h>
#include <string.h>

#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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

typedef enum  {
	ENOTES_MODE_NONE = -1,
	ENOTES_MODE_VIEW = 0,
	ENOTES_MODE_EDIT = 1,
	ENOTES_MODE_BOTH = 2
} ENotesMode;

#define ENOTES_TYPE_MODE (enotes_mode_get_type ())

#define ENOTES_TYPE_VIEW_EDIT_STACK (enotes_view_edit_stack_get_type ())
#define ENOTES_VIEW_EDIT_STACK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_VIEW_EDIT_STACK, ENotesViewEditStack))
#define ENOTES_VIEW_EDIT_STACK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_VIEW_EDIT_STACK, ENotesViewEditStackClass))
#define ENOTES_IS_VIEW_EDIT_STACK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_VIEW_EDIT_STACK))
#define ENOTES_IS_VIEW_EDIT_STACK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_VIEW_EDIT_STACK))
#define ENOTES_VIEW_EDIT_STACK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_VIEW_EDIT_STACK, ENotesViewEditStackClass))

typedef struct _ENotesViewEditStack ENotesViewEditStack;
typedef struct _ENotesViewEditStackClass ENotesViewEditStackClass;
typedef struct _ENotesViewEditStackPrivate ENotesViewEditStackPrivate;

#define ENOTES_TYPE_VIEWER (enotes_viewer_get_type ())
#define ENOTES_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_VIEWER, ENotesViewer))
#define ENOTES_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_VIEWER, ENotesViewerClass))
#define ENOTES_IS_VIEWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_VIEWER))
#define ENOTES_IS_VIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_VIEWER))
#define ENOTES_VIEWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_VIEWER, ENotesViewerClass))

typedef struct _ENotesViewer ENotesViewer;
typedef struct _ENotesViewerClass ENotesViewerClass;

#define ENOTES_TYPE_EDITOR (enotes_editor_get_type ())
#define ENOTES_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_EDITOR, ENotesEditor))
#define ENOTES_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_EDITOR, ENotesEditorClass))
#define ENOTES_IS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_EDITOR))
#define ENOTES_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_EDITOR))
#define ENOTES_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_EDITOR, ENotesEditorClass))

typedef struct _ENotesEditor ENotesEditor;
typedef struct _ENotesEditorClass ENotesEditorClass;
enum  {
	ENOTES_VIEW_EDIT_STACK_0_PROPERTY,
	ENOTES_VIEW_EDIT_STACK_VIEWER_PROPERTY,
	ENOTES_VIEW_EDIT_STACK_EDITOR_PROPERTY,
	ENOTES_VIEW_EDIT_STACK_NUM_PROPERTIES
};
static GParamSpec* enotes_view_edit_stack_properties[ENOTES_VIEW_EDIT_STACK_NUM_PROPERTIES];
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define ENOTES_TYPE_APPLICATION (enotes_application_get_type ())
#define ENOTES_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_APPLICATION, ENotesApplication))
#define ENOTES_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_APPLICATION, ENotesApplicationClass))
#define ENOTES_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_APPLICATION))
#define ENOTES_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_APPLICATION))
#define ENOTES_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_APPLICATION, ENotesApplicationClass))

typedef struct _ENotesApplication ENotesApplication;
typedef struct _ENotesApplicationClass ENotesApplicationClass;
typedef struct _ENotesApplicationPrivate ENotesApplicationPrivate;

#define ENOTES_APPLICATION_TYPE_STATE (enotes_application_state_get_type ())
#define ENOTES_APPLICATION_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_APPLICATION_TYPE_STATE, ENotesApplicationState))
#define ENOTES_APPLICATION_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_APPLICATION_TYPE_STATE, ENotesApplicationStateClass))
#define ENOTES_APPLICATION_IS_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_APPLICATION_TYPE_STATE))
#define ENOTES_APPLICATION_IS_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_APPLICATION_TYPE_STATE))
#define ENOTES_APPLICATION_STATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_APPLICATION_TYPE_STATE, ENotesApplicationStateClass))

typedef struct _ENotesApplicationState ENotesApplicationState;
typedef struct _ENotesApplicationStateClass ENotesApplicationStateClass;

#define ENOTES_TYPE_PAGE (enotes_page_get_type ())
#define ENOTES_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_PAGE, ENotesPage))
#define ENOTES_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_PAGE, ENotesPageClass))
#define ENOTES_IS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_PAGE))
#define ENOTES_IS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_PAGE))
#define ENOTES_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_PAGE, ENotesPageClass))

typedef struct _ENotesPage ENotesPage;
typedef struct _ENotesPageClass ENotesPageClass;
typedef struct _ENotesPagePrivate ENotesPagePrivate;

#define ENOTES_TYPE_PAGES_LIST (enotes_pages_list_get_type ())
#define ENOTES_PAGES_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ENOTES_TYPE_PAGES_LIST, ENotesPagesList))
#define ENOTES_PAGES_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ENOTES_TYPE_PAGES_LIST, ENotesPagesListClass))
#define ENOTES_IS_PAGES_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ENOTES_TYPE_PAGES_LIST))
#define ENOTES_IS_PAGES_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ENOTES_TYPE_PAGES_LIST))
#define ENOTES_PAGES_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ENOTES_TYPE_PAGES_LIST, ENotesPagesListClass))

typedef struct _ENotesPagesList ENotesPagesList;
typedef struct _ENotesPagesListClass ENotesPagesListClass;

struct _ENotesViewEditStack {
	GtkGrid parent_instance;
	ENotesViewEditStackPrivate * priv;
	GtkPaned* view_edit_pane;
};

struct _ENotesViewEditStackClass {
	GtkGridClass parent_class;
};

struct _ENotesViewEditStackPrivate {
	ENotesMode* current_mode;
	ENotesViewer* _viewer;
	ENotesEditor* _editor;
	GtkStack* stack;
};

struct _ENotesApplication {
	GraniteApplication parent_instance;
	ENotesApplicationPrivate * priv;
	gboolean running;
	ENotesApplicationState* state;
};

struct _ENotesApplicationClass {
	GraniteApplicationClass parent_class;
};

struct _ENotesPage {
	GObject parent_instance;
	ENotesPagePrivate * priv;
	gint64 id;
	gint64 notebook_id;
	gchar* name;
	gchar* data;
	gchar* subtitle;
	gchar* html_cache;
	gint64 creation_date;
	gint64 modification_date;
	gboolean new_page;
	gboolean cache_changed;
	gchar* full_path;
};

struct _ENotesPageClass {
	GObjectClass parent_class;
};

static gint ENotesViewEditStack_private_offset;
static gpointer enotes_view_edit_stack_parent_class = NULL;
static ENotesViewEditStack* enotes_view_edit_stack_instance;
static ENotesViewEditStack* enotes_view_edit_stack_instance = NULL;
VALA_EXTERN ENotesApplication* enotes_app;

VALA_EXTERN GType enotes_mode_get_type (void) G_GNUC_CONST ;
VALA_EXTERN ENotesMode enotes_mode_get_mode (gint value);
VALA_EXTERN gint enotes_mode_get_value (ENotesMode value);
VALA_EXTERN GType enotes_view_edit_stack_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesViewEditStack, g_object_unref)
VALA_EXTERN GType enotes_viewer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesViewer, g_object_unref)
VALA_EXTERN GType enotes_editor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesEditor, g_object_unref)
VALA_EXTERN ENotesViewEditStack* enotes_view_edit_stack_get_instance (void);
static ENotesViewEditStack* enotes_view_edit_stack_new (void);
static ENotesViewEditStack* enotes_view_edit_stack_construct (GType object_type);
VALA_EXTERN ENotesEditor* enotes_editor_new (void);
VALA_EXTERN ENotesEditor* enotes_editor_construct (GType object_type);
static void enotes_view_edit_stack_set_editor (ENotesViewEditStack* self,
                                        ENotesEditor* value);
VALA_EXTERN ENotesViewer* enotes_viewer_new (void);
VALA_EXTERN ENotesViewer* enotes_viewer_construct (GType object_type);
static void enotes_view_edit_stack_set_viewer (ENotesViewEditStack* self,
                                        ENotesViewer* value);
VALA_EXTERN ENotesViewer* enotes_view_edit_stack_get_viewer (ENotesViewEditStack* self);
VALA_EXTERN ENotesEditor* enotes_view_edit_stack_get_editor (ENotesViewEditStack* self);
static void enotes_view_edit_stack_show_view (ENotesViewEditStack* self);
VALA_EXTERN GType enotes_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesApplication, g_object_unref)
VALA_EXTERN GType enotes_application_state_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesApplicationState, g_object_unref)
static void __lambda35_ (ENotesViewEditStack* self);
VALA_EXTERN ENotesMode enotes_application_state_get_mode (ENotesApplicationState* self);
static void enotes_view_edit_stack_unset_both (ENotesViewEditStack* self);
static void enotes_view_edit_stack_show_edit (ENotesViewEditStack* self);
static void enotes_view_edit_stack_show_both (ENotesViewEditStack* self);
static void ___lambda35__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static void __lambda36_ (ENotesViewEditStack* self);
VALA_EXTERN GType enotes_page_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPage, g_object_unref)
VALA_EXTERN ENotesPage* enotes_application_state_get_opened_page (ENotesApplicationState* self);
VALA_EXTERN void enotes_viewer_load_page (ENotesViewer* self,
                              ENotesPage* page,
                              gboolean force_load);
VALA_EXTERN void enotes_application_state_set_mode (ENotesApplicationState* self,
                                        ENotesMode value);
static void ___lambda36__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static gboolean _enotes_mode_equal (const ENotesMode * s1,
                             const ENotesMode * s2);
static ENotesMode* _enotes_mode_dup (ENotesMode* self);
VALA_EXTERN void enotes_editor_give_focus (ENotesEditor* self);
VALA_EXTERN GType enotes_pages_list_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ENotesPagesList, g_object_unref)
VALA_EXTERN ENotesPagesList* enotes_pages_list_get_instance (void);
VALA_EXTERN void enotes_pages_list_grab_focus (ENotesPagesList* self);
VALA_EXTERN void enotes_editor_save_file (ENotesEditor* self);
static void enotes_view_edit_stack_finalize (GObject * obj);
static GType enotes_view_edit_stack_get_type_once (void);
static void _vala_enotes_view_edit_stack_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_enotes_view_edit_stack_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

ENotesMode
enotes_mode_get_mode (gint value)
{
	ENotesMode result;
	switch (value) {
		case 0:
		{
			result = ENOTES_MODE_VIEW;
			return result;
		}
		case 1:
		{
			result = ENOTES_MODE_EDIT;
			return result;
		}
		case 2:
		{
			result = ENOTES_MODE_BOTH;
			return result;
		}
		default:
		{
			result = 0;
			return result;
		}
	}
}

gint
enotes_mode_get_value (ENotesMode value)
{
	gint result;
	switch (value) {
		case ENOTES_MODE_VIEW:
		{
			result = 0;
			return result;
		}
		case ENOTES_MODE_EDIT:
		{
			result = 1;
			return result;
		}
		case ENOTES_MODE_BOTH:
		{
			result = 2;
			return result;
		}
		default:
		{
			result = 0;
			return result;
		}
	}
}

static GType
enotes_mode_get_type_once (void)
{
	static const GEnumValue values[] = {{ENOTES_MODE_NONE, "ENOTES_MODE_NONE", "none"}, {ENOTES_MODE_VIEW, "ENOTES_MODE_VIEW", "view"}, {ENOTES_MODE_EDIT, "ENOTES_MODE_EDIT", "edit"}, {ENOTES_MODE_BOTH, "ENOTES_MODE_BOTH", "both"}, {0, NULL, NULL}};
	GType enotes_mode_type_id;
	enotes_mode_type_id = g_enum_register_static ("ENotesMode", values);
	return enotes_mode_type_id;
}

GType
enotes_mode_get_type (void)
{
	static volatile gsize enotes_mode_type_id__once = 0;
	if (g_once_init_enter (&enotes_mode_type_id__once)) {
		GType enotes_mode_type_id;
		enotes_mode_type_id = enotes_mode_get_type_once ();
		g_once_init_leave (&enotes_mode_type_id__once, enotes_mode_type_id);
	}
	return enotes_mode_type_id__once;
}

static inline gpointer
enotes_view_edit_stack_get_instance_private (ENotesViewEditStack* self)
{
	return G_STRUCT_MEMBER_P (self, ENotesViewEditStack_private_offset);
}

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

ENotesViewEditStack*
enotes_view_edit_stack_get_instance (void)
{
	ENotesViewEditStack* _tmp0_;
	ENotesViewEditStack* _tmp2_;
	ENotesViewEditStack* _tmp3_;
	ENotesViewEditStack* result;
	_tmp0_ = enotes_view_edit_stack_instance;
	if (_tmp0_ == NULL) {
		ENotesViewEditStack* _tmp1_;
		_tmp1_ = enotes_view_edit_stack_new ();
		g_object_ref_sink (_tmp1_);
		_g_object_unref0 (enotes_view_edit_stack_instance);
		enotes_view_edit_stack_instance = _tmp1_;
	}
	_tmp2_ = enotes_view_edit_stack_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

static void
__lambda35_ (ENotesViewEditStack* self)
{
	ENotesApplication* _tmp0_;
	ENotesApplicationState* _tmp1_;
	ENotesMode _tmp2_;
	ENotesMode _tmp3_;
	_tmp0_ = enotes_app;
	_tmp1_ = _tmp0_->state;
	_tmp2_ = enotes_application_state_get_mode (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == ENOTES_MODE_EDIT) {
		enotes_view_edit_stack_unset_both (self);
		enotes_view_edit_stack_show_edit (self);
	} else {
		ENotesApplication* _tmp4_;
		ENotesApplicationState* _tmp5_;
		ENotesMode _tmp6_;
		ENotesMode _tmp7_;
		_tmp4_ = enotes_app;
		_tmp5_ = _tmp4_->state;
		_tmp6_ = enotes_application_state_get_mode (_tmp5_);
		_tmp7_ = _tmp6_;
		if (_tmp7_ == ENOTES_MODE_VIEW) {
			enotes_view_edit_stack_unset_both (self);
			enotes_view_edit_stack_show_view (self);
		} else {
			enotes_view_edit_stack_show_both (self);
		}
	}
}

static void
___lambda35__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda35_ ((ENotesViewEditStack*) self);
}

static void
__lambda36_ (ENotesViewEditStack* self)
{
	ENotesPage* opened_page = NULL;
	ENotesApplication* _tmp0_;
	ENotesApplicationState* _tmp1_;
	ENotesPage* _tmp2_;
	ENotesPage* _tmp3_;
	ENotesPage* _tmp4_;
	ENotesViewer* _tmp5_;
	ENotesPage* _tmp6_;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp8_ = FALSE;
	ENotesApplication* _tmp9_;
	ENotesApplicationState* _tmp10_;
	ENotesMode _tmp11_;
	ENotesMode _tmp12_;
	_tmp0_ = enotes_app;
	_tmp1_ = _tmp0_->state;
	_tmp2_ = enotes_application_state_get_opened_page (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	opened_page = _tmp4_;
	_tmp5_ = self->priv->_viewer;
	_tmp6_ = opened_page;
	enotes_viewer_load_page (_tmp5_, _tmp6_, FALSE);
	_tmp9_ = enotes_app;
	_tmp10_ = _tmp9_->state;
	_tmp11_ = enotes_application_state_get_mode (_tmp10_);
	_tmp12_ = _tmp11_;
	if (_tmp12_ == ENOTES_MODE_VIEW) {
		ENotesPage* _tmp13_;
		_tmp13_ = opened_page;
		_tmp8_ = _tmp13_ != NULL;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		ENotesPage* _tmp14_;
		const gchar* _tmp15_;
		_tmp14_ = opened_page;
		_tmp15_ = _tmp14_->data;
		_tmp7_ = g_strcmp0 (_tmp15_, "") == 0;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		ENotesApplication* _tmp16_;
		ENotesApplicationState* _tmp17_;
		_tmp16_ = enotes_app;
		_tmp17_ = _tmp16_->state;
		enotes_application_state_set_mode (_tmp17_, ENOTES_MODE_EDIT);
	}
	_g_object_unref0 (opened_page);
}

static void
___lambda36__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda36_ ((ENotesViewEditStack*) self);
}

static ENotesViewEditStack*
enotes_view_edit_stack_construct (GType object_type)
{
	ENotesViewEditStack * self = NULL;
	GtkStack* _tmp0_;
	GtkPaned* _tmp1_;
	GtkPaned* _tmp2_;
	GtkPaned* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	ENotesEditor* _tmp6_;
	ENotesEditor* _tmp7_;
	ENotesViewer* _tmp8_;
	ENotesViewer* _tmp9_;
	GtkStack* _tmp10_;
	ENotesViewer* _tmp11_;
	GtkStack* _tmp12_;
	ENotesEditor* _tmp13_;
	GtkStack* _tmp14_;
	GtkPaned* _tmp15_;
	GtkStack* _tmp16_;
	GtkStack* _tmp17_;
	ENotesApplication* _tmp18_;
	ENotesApplicationState* _tmp19_;
	ENotesApplication* _tmp20_;
	ENotesApplicationState* _tmp21_;
	self = (ENotesViewEditStack*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkStack*) gtk_stack_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->stack);
	self->priv->stack = _tmp0_;
	_tmp1_ = (GtkPaned*) gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->view_edit_pane);
	self->view_edit_pane = _tmp1_;
	_tmp2_ = self->view_edit_pane;
	_tmp3_ = self->view_edit_pane;
	g_object_get (_tmp3_, "max-position", &_tmp4_, NULL);
	_tmp5_ = _tmp4_;
	gtk_paned_set_position (_tmp2_, _tmp5_ / 2);
	_tmp6_ = enotes_editor_new ();
	g_object_ref_sink (_tmp6_);
	_tmp7_ = _tmp6_;
	enotes_view_edit_stack_set_editor (self, _tmp7_);
	_g_object_unref0 (_tmp7_);
	_tmp8_ = enotes_viewer_new ();
	g_object_ref_sink (_tmp8_);
	_tmp9_ = _tmp8_;
	enotes_view_edit_stack_set_viewer (self, _tmp9_);
	_g_object_unref0 (_tmp9_);
	_tmp10_ = self->priv->stack;
	_tmp11_ = self->priv->_viewer;
	gtk_stack_add_named (_tmp10_, (GtkWidget*) _tmp11_, "viewer");
	_tmp12_ = self->priv->stack;
	_tmp13_ = self->priv->_editor;
	gtk_stack_add_named (_tmp12_, (GtkWidget*) _tmp13_, "editor");
	_tmp14_ = self->priv->stack;
	_tmp15_ = self->view_edit_pane;
	gtk_stack_add_named (_tmp14_, (GtkWidget*) _tmp15_, "both");
	_tmp16_ = self->priv->stack;
	gtk_stack_set_transition_type (_tmp16_, GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT);
	_tmp17_ = self->priv->stack;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp17_);
	gtk_widget_show_all ((GtkWidget*) self);
	enotes_view_edit_stack_show_view (self);
	_tmp18_ = enotes_app;
	_tmp19_ = _tmp18_->state;
	g_signal_connect_object ((GObject*) _tmp19_, "notify::mode", (GCallback) ___lambda35__g_object_notify, self, 0);
	_tmp20_ = enotes_app;
	_tmp21_ = _tmp20_->state;
	g_signal_connect_object ((GObject*) _tmp21_, "notify::opened-page", (GCallback) ___lambda36__g_object_notify, self, 0);
	return self;
}

static ENotesViewEditStack*
enotes_view_edit_stack_new (void)
{
	return enotes_view_edit_stack_construct (ENOTES_TYPE_VIEW_EDIT_STACK);
}

static gboolean
_enotes_mode_equal (const ENotesMode * s1,
                    const ENotesMode * s2)
{
	if (s1 == s2) {
		return TRUE;
	}
	if (s1 == NULL) {
		return FALSE;
	}
	if (s2 == NULL) {
		return FALSE;
	}
	return (*s1) == (*s2);
}

static void
enotes_view_edit_stack_unset_both (ENotesViewEditStack* self)
{
	ENotesMode* _tmp0_;
	ENotesMode _tmp1_;
	GtkPaned* _tmp2_;
	ENotesViewer* _tmp3_;
	GtkPaned* _tmp4_;
	ENotesEditor* _tmp5_;
	GtkStack* _tmp6_;
	ENotesViewer* _tmp7_;
	GtkStack* _tmp8_;
	ENotesEditor* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->current_mode;
	_tmp1_ = ENOTES_MODE_BOTH;
	if (_enotes_mode_equal (_tmp0_, &_tmp1_) != TRUE) {
		return;
	}
	_tmp2_ = self->view_edit_pane;
	_tmp3_ = self->priv->_viewer;
	gtk_container_remove ((GtkContainer*) _tmp2_, (GtkWidget*) _tmp3_);
	_tmp4_ = self->view_edit_pane;
	_tmp5_ = self->priv->_editor;
	gtk_container_remove ((GtkContainer*) _tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->stack;
	_tmp7_ = self->priv->_viewer;
	gtk_stack_add_named (_tmp6_, (GtkWidget*) _tmp7_, "viewer");
	_tmp8_ = self->priv->stack;
	_tmp9_ = self->priv->_editor;
	gtk_stack_add_named (_tmp8_, (GtkWidget*) _tmp9_, "editor");
	gtk_widget_show_all ((GtkWidget*) self);
}

static ENotesMode*
_enotes_mode_dup (ENotesMode* self)
{
	ENotesMode* dup;
	dup = g_new0 (ENotesMode, 1);
	memcpy (dup, self, sizeof (ENotesMode));
	return dup;
}

static gpointer
__enotes_mode_dup0 (gpointer self)
{
	return self ? _enotes_mode_dup (self) : NULL;
}

static void
enotes_view_edit_stack_show_both (ENotesViewEditStack* self)
{
	ENotesMode* _tmp0_;
	ENotesMode _tmp1_;
	GtkStack* _tmp2_;
	ENotesViewer* _tmp3_;
	GtkStack* _tmp4_;
	ENotesEditor* _tmp5_;
	GtkPaned* _tmp6_;
	ENotesViewer* _tmp7_;
	GtkPaned* _tmp8_;
	ENotesEditor* _tmp9_;
	GtkStack* _tmp10_;
	ENotesMode _tmp11_;
	ENotesMode* _tmp12_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->current_mode;
	_tmp1_ = ENOTES_MODE_BOTH;
	if (_enotes_mode_equal (_tmp0_, &_tmp1_) == TRUE) {
		return;
	}
	_tmp2_ = self->priv->stack;
	_tmp3_ = self->priv->_viewer;
	gtk_container_remove ((GtkContainer*) _tmp2_, (GtkWidget*) _tmp3_);
	_tmp4_ = self->priv->stack;
	_tmp5_ = self->priv->_editor;
	gtk_container_remove ((GtkContainer*) _tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = self->view_edit_pane;
	_tmp7_ = self->priv->_viewer;
	gtk_paned_pack1 (_tmp6_, (GtkWidget*) _tmp7_, TRUE, FALSE);
	_tmp8_ = self->view_edit_pane;
	_tmp9_ = self->priv->_editor;
	gtk_paned_pack2 (_tmp8_, (GtkWidget*) _tmp9_, FALSE, FALSE);
	gtk_widget_show_all ((GtkWidget*) self);
	_tmp10_ = self->priv->stack;
	gtk_stack_set_visible_child_name (_tmp10_, "both");
	_tmp11_ = ENOTES_MODE_BOTH;
	_tmp12_ = __enotes_mode_dup0 (&_tmp11_);
	_g_free0 (self->priv->current_mode);
	self->priv->current_mode = _tmp12_;
}

static void
enotes_view_edit_stack_show_edit (ENotesViewEditStack* self)
{
	ENotesMode* _tmp0_;
	ENotesMode _tmp1_;
	ENotesMode _tmp2_;
	ENotesMode* _tmp3_;
	GtkStack* _tmp4_;
	ENotesEditor* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->current_mode;
	_tmp1_ = ENOTES_MODE_EDIT;
	if (_enotes_mode_equal (_tmp0_, &_tmp1_) == TRUE) {
		return;
	}
	_tmp2_ = ENOTES_MODE_EDIT;
	_tmp3_ = __enotes_mode_dup0 (&_tmp2_);
	_g_free0 (self->priv->current_mode);
	self->priv->current_mode = _tmp3_;
	_tmp4_ = self->priv->stack;
	gtk_stack_set_visible_child_name (_tmp4_, "editor");
	_tmp5_ = self->priv->_editor;
	enotes_editor_give_focus (_tmp5_);
}

static void
enotes_view_edit_stack_show_view (ENotesViewEditStack* self)
{
	ENotesMode* _tmp0_;
	ENotesMode _tmp1_;
	GtkStack* _tmp2_;
	ENotesPagesList* _tmp3_;
	ENotesPagesList* _tmp4_;
	ENotesMode _tmp5_;
	ENotesMode* _tmp6_;
	ENotesApplication* _tmp7_;
	ENotesApplicationState* _tmp8_;
	ENotesPage* _tmp9_;
	ENotesPage* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->current_mode;
	_tmp1_ = ENOTES_MODE_VIEW;
	if (_enotes_mode_equal (_tmp0_, &_tmp1_) == TRUE) {
		return;
	}
	_tmp2_ = self->priv->stack;
	gtk_stack_set_visible_child_name (_tmp2_, "viewer");
	_tmp3_ = enotes_pages_list_get_instance ();
	_tmp4_ = _tmp3_;
	enotes_pages_list_grab_focus (_tmp4_);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = ENOTES_MODE_VIEW;
	_tmp6_ = __enotes_mode_dup0 (&_tmp5_);
	_g_free0 (self->priv->current_mode);
	self->priv->current_mode = _tmp6_;
	_tmp7_ = enotes_app;
	_tmp8_ = _tmp7_->state;
	_tmp9_ = enotes_application_state_get_opened_page (_tmp8_);
	_tmp10_ = _tmp9_;
	if (_tmp10_ != NULL) {
		ENotesEditor* _tmp11_;
		ENotesViewer* _tmp12_;
		ENotesApplication* _tmp13_;
		ENotesApplicationState* _tmp14_;
		ENotesPage* _tmp15_;
		ENotesPage* _tmp16_;
		_tmp11_ = self->priv->_editor;
		enotes_editor_save_file (_tmp11_);
		_tmp12_ = self->priv->_viewer;
		_tmp13_ = enotes_app;
		_tmp14_ = _tmp13_->state;
		_tmp15_ = enotes_application_state_get_opened_page (_tmp14_);
		_tmp16_ = _tmp15_;
		enotes_viewer_load_page (_tmp12_, _tmp16_, TRUE);
	}
}

ENotesViewer*
enotes_view_edit_stack_get_viewer (ENotesViewEditStack* self)
{
	ENotesViewer* result;
	ENotesViewer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_viewer;
	result = _tmp0_;
	return result;
}

static void
enotes_view_edit_stack_set_viewer (ENotesViewEditStack* self,
                                   ENotesViewer* value)
{
	ENotesViewer* old_value;
	g_return_if_fail (self != NULL);
	old_value = enotes_view_edit_stack_get_viewer (self);
	if (old_value != value) {
		ENotesViewer* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_viewer);
		self->priv->_viewer = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, enotes_view_edit_stack_properties[ENOTES_VIEW_EDIT_STACK_VIEWER_PROPERTY]);
	}
}

ENotesEditor*
enotes_view_edit_stack_get_editor (ENotesViewEditStack* self)
{
	ENotesEditor* result;
	ENotesEditor* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_editor;
	result = _tmp0_;
	return result;
}

static void
enotes_view_edit_stack_set_editor (ENotesViewEditStack* self,
                                   ENotesEditor* value)
{
	ENotesEditor* old_value;
	g_return_if_fail (self != NULL);
	old_value = enotes_view_edit_stack_get_editor (self);
	if (old_value != value) {
		ENotesEditor* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_editor);
		self->priv->_editor = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, enotes_view_edit_stack_properties[ENOTES_VIEW_EDIT_STACK_EDITOR_PROPERTY]);
	}
}

static void
enotes_view_edit_stack_class_init (ENotesViewEditStackClass * klass,
                                   gpointer klass_data)
{
	enotes_view_edit_stack_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ENotesViewEditStack_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_enotes_view_edit_stack_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_enotes_view_edit_stack_set_property;
	G_OBJECT_CLASS (klass)->finalize = enotes_view_edit_stack_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), ENOTES_VIEW_EDIT_STACK_VIEWER_PROPERTY, enotes_view_edit_stack_properties[ENOTES_VIEW_EDIT_STACK_VIEWER_PROPERTY] = g_param_spec_object ("viewer", "viewer", "viewer", ENOTES_TYPE_VIEWER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), ENOTES_VIEW_EDIT_STACK_EDITOR_PROPERTY, enotes_view_edit_stack_properties[ENOTES_VIEW_EDIT_STACK_EDITOR_PROPERTY] = g_param_spec_object ("editor", "editor", "editor", ENOTES_TYPE_EDITOR, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
enotes_view_edit_stack_instance_init (ENotesViewEditStack * self,
                                      gpointer klass)
{
	self->priv = enotes_view_edit_stack_get_instance_private (self);
	self->priv->current_mode = NULL;
}

static void
enotes_view_edit_stack_finalize (GObject * obj)
{
	ENotesViewEditStack * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ENOTES_TYPE_VIEW_EDIT_STACK, ENotesViewEditStack);
	_g_free0 (self->priv->current_mode);
	_g_object_unref0 (self->priv->_viewer);
	_g_object_unref0 (self->priv->_editor);
	_g_object_unref0 (self->view_edit_pane);
	_g_object_unref0 (self->priv->stack);
	G_OBJECT_CLASS (enotes_view_edit_stack_parent_class)->finalize (obj);
}

static GType
enotes_view_edit_stack_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ENotesViewEditStackClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) enotes_view_edit_stack_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ENotesViewEditStack), 0, (GInstanceInitFunc) enotes_view_edit_stack_instance_init, NULL };
	GType enotes_view_edit_stack_type_id;
	enotes_view_edit_stack_type_id = g_type_register_static (gtk_grid_get_type (), "ENotesViewEditStack", &g_define_type_info, 0);
	ENotesViewEditStack_private_offset = g_type_add_instance_private (enotes_view_edit_stack_type_id, sizeof (ENotesViewEditStackPrivate));
	return enotes_view_edit_stack_type_id;
}

GType
enotes_view_edit_stack_get_type (void)
{
	static volatile gsize enotes_view_edit_stack_type_id__once = 0;
	if (g_once_init_enter (&enotes_view_edit_stack_type_id__once)) {
		GType enotes_view_edit_stack_type_id;
		enotes_view_edit_stack_type_id = enotes_view_edit_stack_get_type_once ();
		g_once_init_leave (&enotes_view_edit_stack_type_id__once, enotes_view_edit_stack_type_id);
	}
	return enotes_view_edit_stack_type_id__once;
}

static void
_vala_enotes_view_edit_stack_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	ENotesViewEditStack * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, ENOTES_TYPE_VIEW_EDIT_STACK, ENotesViewEditStack);
	switch (property_id) {
		case ENOTES_VIEW_EDIT_STACK_VIEWER_PROPERTY:
		g_value_set_object (value, enotes_view_edit_stack_get_viewer (self));
		break;
		case ENOTES_VIEW_EDIT_STACK_EDITOR_PROPERTY:
		g_value_set_object (value, enotes_view_edit_stack_get_editor (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_enotes_view_edit_stack_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	ENotesViewEditStack * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, ENOTES_TYPE_VIEW_EDIT_STACK, ENotesViewEditStack);
	switch (property_id) {
		case ENOTES_VIEW_EDIT_STACK_VIEWER_PROPERTY:
		enotes_view_edit_stack_set_viewer (self, g_value_get_object (value));
		break;
		case ENOTES_VIEW_EDIT_STACK_EDITOR_PROPERTY:
		enotes_view_edit_stack_set_editor (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

