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

/*
 * This file is part of LaTeXila.
 *
 * Copyright © 2010-2011 Sébastien Wilmet
 *
 * LaTeXila is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LaTeXila is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <gtksourceview/gtksourceview.h>


#define TYPE_DOCUMENTS_PANEL (documents_panel_get_type ())
#define DOCUMENTS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENTS_PANEL, DocumentsPanel))
#define DOCUMENTS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENTS_PANEL, DocumentsPanelClass))
#define IS_DOCUMENTS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENTS_PANEL))
#define IS_DOCUMENTS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENTS_PANEL))
#define DOCUMENTS_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENTS_PANEL, DocumentsPanelClass))

typedef struct _DocumentsPanel DocumentsPanel;
typedef struct _DocumentsPanelClass DocumentsPanelClass;
typedef struct _DocumentsPanelPrivate DocumentsPanelPrivate;

#define TYPE_DOCUMENT_TAB (document_tab_get_type ())
#define DOCUMENT_TAB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT_TAB, DocumentTab))
#define DOCUMENT_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_TAB, DocumentTabClass))
#define IS_DOCUMENT_TAB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT_TAB))
#define IS_DOCUMENT_TAB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_TAB))
#define DOCUMENT_TAB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_TAB, DocumentTabClass))

typedef struct _DocumentTab DocumentTab;
typedef struct _DocumentTabClass DocumentTabClass;

#define TYPE_MAIN_WINDOW (main_window_get_type ())
#define MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MAIN_WINDOW, MainWindow))
#define MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MAIN_WINDOW, MainWindowClass))
#define IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MAIN_WINDOW))
#define IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MAIN_WINDOW))
#define MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MAIN_WINDOW, MainWindowClass))

typedef struct _MainWindow MainWindow;
typedef struct _MainWindowClass MainWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block7Data Block7Data;

#define TYPE_DOCUMENT (document_get_type ())
#define DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT, Document))
#define DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT, DocumentClass))
#define IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT))
#define IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT))
#define DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT, DocumentClass))

typedef struct _Document Document;
typedef struct _DocumentClass DocumentClass;

#define TYPE_CLEAN_BUILD_FILES (clean_build_files_get_type ())
#define CLEAN_BUILD_FILES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLEAN_BUILD_FILES, CleanBuildFiles))
#define CLEAN_BUILD_FILES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLEAN_BUILD_FILES, CleanBuildFilesClass))
#define IS_CLEAN_BUILD_FILES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLEAN_BUILD_FILES))
#define IS_CLEAN_BUILD_FILES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLEAN_BUILD_FILES))
#define CLEAN_BUILD_FILES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLEAN_BUILD_FILES, CleanBuildFilesClass))

typedef struct _CleanBuildFiles CleanBuildFiles;
typedef struct _CleanBuildFilesClass CleanBuildFilesClass;

struct _DocumentsPanel {
	GtkNotebook parent_instance;
	DocumentsPanelPrivate * priv;
};

struct _DocumentsPanelClass {
	GtkNotebookClass parent_class;
};

struct _DocumentsPanelPrivate {
	DocumentTab* _active_tab;
	MainWindow* main_window;
};

struct _Block7Data {
	int _ref_count_;
	DocumentsPanel * self;
	DocumentTab* tab;
};


static gpointer documents_panel_parent_class = NULL;

GType documents_panel_get_type (void) G_GNUC_CONST;
GType document_tab_get_type (void) G_GNUC_CONST;
GType main_window_get_type (void) G_GNUC_CONST;
#define DOCUMENTS_PANEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_DOCUMENTS_PANEL, DocumentsPanelPrivate))
enum  {
	DOCUMENTS_PANEL_DUMMY_PROPERTY,
	DOCUMENTS_PANEL_ACTIVE_TAB
};
DocumentsPanel* documents_panel_new (MainWindow* main_window);
DocumentsPanel* documents_panel_construct (GType object_type, MainWindow* main_window);
static void _lambda31_ (GtkNotebookPage* page, guint page_num, DocumentsPanel* self);
static void documents_panel_set_active_tab (DocumentsPanel* self, DocumentTab* value);
static void __lambda31__gtk_notebook_switch_page (GtkNotebook* _sender, GtkNotebookPage* page, guint page_num, gpointer self);
void documents_panel_add_tab (DocumentsPanel* self, DocumentTab* tab, gint position, gboolean jump_to);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (Block7Data* _data7_);
GtkHBox* document_tab_get_label (DocumentTab* self);
static gboolean _lambda32_ (GdkEventButton* event, Block7Data* _data7_);
static gboolean __lambda32__gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self);
void documents_panel_remove_tab (DocumentsPanel* self, DocumentTab* tab);
GType document_get_type (void) G_GNUC_CONST;
Document* document_tab_get_document (DocumentTab* self);
CleanBuildFiles* clean_build_files_new (MainWindow* main_window, Document* doc);
CleanBuildFiles* clean_build_files_construct (GType object_type, MainWindow* main_window, Document* doc);
GType clean_build_files_get_type (void) G_GNUC_CONST;
gboolean clean_build_files_clean (CleanBuildFiles* self);
void documents_panel_remove_all_tabs (DocumentsPanel* self);
DocumentTab* documents_panel_get_active_tab (DocumentsPanel* self);
static void documents_panel_finalize (GObject* obj);
static void _vala_documents_panel_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_documents_panel_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


static void _lambda31_ (GtkNotebookPage* page, guint page_num, DocumentsPanel* self) {
	GtkWidget* _tmp0_ = NULL;
	g_return_if_fail (page != NULL);
	_tmp0_ = gtk_notebook_get_nth_page ((GtkNotebook*) self, (gint) page_num);
	documents_panel_set_active_tab (self, DOCUMENT_TAB (_tmp0_));
}


static void __lambda31__gtk_notebook_switch_page (GtkNotebook* _sender, GtkNotebookPage* page, guint page_num, gpointer self) {
	_lambda31_ (page, page_num, self);
}


DocumentsPanel* documents_panel_construct (GType object_type, MainWindow* main_window) {
	DocumentsPanel * self = NULL;
	g_return_val_if_fail (main_window != NULL, NULL);
	self = (DocumentsPanel*) g_object_new (object_type, NULL);
	self->priv->main_window = main_window;
	gtk_notebook_set_scrollable ((GtkNotebook*) self, TRUE);
	g_signal_connect_object ((GtkNotebook*) self, "switch-page", (GCallback) __lambda31__gtk_notebook_switch_page, self, 0);
	return self;
}


DocumentsPanel* documents_panel_new (MainWindow* main_window) {
	return documents_panel_construct (TYPE_DOCUMENTS_PANEL, main_window);
}


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


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


static void block7_data_unref (Block7Data* _data7_) {
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		_g_object_unref0 (_data7_->self);
		_g_object_unref0 (_data7_->tab);
		g_slice_free (Block7Data, _data7_);
	}
}


static gboolean _lambda32_ (GdkEventButton* event, Block7Data* _data7_) {
	DocumentsPanel * self;
	gboolean result = FALSE;
	self = _data7_->self;
	if ((*event).button == 3) {
		gint _tmp0_;
		_tmp0_ = gtk_notebook_page_num ((GtkNotebook*) self, (GtkWidget*) _data7_->tab);
		gtk_notebook_set_current_page ((GtkNotebook*) self, _tmp0_);
		g_signal_emit_by_name (self, "right-click", event);
	}
	result = FALSE;
	return result;
}


static gboolean __lambda32__gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self) {
	gboolean result;
	result = _lambda32_ (event, self);
	return result;
}


void documents_panel_add_tab (DocumentsPanel* self, DocumentTab* tab, gint position, gboolean jump_to) {
	Block7Data* _data7_;
	GtkEventBox* _tmp0_ = NULL;
	GtkEventBox* event_box;
	GtkHBox* _tmp1_ = NULL;
	gint _tmp2_;
	gint page_pos;
	g_return_if_fail (self != NULL);
	g_return_if_fail (tab != NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_data7_->self = g_object_ref (self);
	_data7_->tab = _g_object_ref0 (tab);
	_tmp0_ = (GtkEventBox*) gtk_event_box_new ();
	event_box = g_object_ref_sink (_tmp0_);
	_tmp1_ = document_tab_get_label (_data7_->tab);
	gtk_container_add ((GtkContainer*) event_box, (GtkWidget*) _tmp1_);
	g_signal_connect_data ((GtkWidget*) event_box, "button-press-event", (GCallback) __lambda32__gtk_widget_button_press_event, block7_data_ref (_data7_), (GClosureNotify) block7_data_unref, 0);
	_tmp2_ = gtk_notebook_insert_page ((GtkNotebook*) self, (GtkWidget*) _data7_->tab, (GtkWidget*) event_box, position);
	page_pos = _tmp2_;
	gtk_notebook_set_tab_reorderable ((GtkNotebook*) self, (GtkWidget*) _data7_->tab, TRUE);
	if (jump_to) {
		gtk_notebook_set_current_page ((GtkNotebook*) self, page_pos);
	}
	_g_object_unref0 (event_box);
	block7_data_unref (_data7_);
	_data7_ = NULL;
}


void documents_panel_remove_tab (DocumentsPanel* self, DocumentTab* tab) {
	GSettings* _tmp0_ = NULL;
	GSettings* settings;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_;
	gint _tmp6_;
	gint pos;
	g_return_if_fail (self != NULL);
	g_return_if_fail (tab != NULL);
	_tmp0_ = g_settings_new ("org.gnome.latexila.preferences.latex");
	settings = _tmp0_;
	_tmp2_ = g_settings_get_boolean (settings, "no-confirm-clean");
	if (_tmp2_) {
		gboolean _tmp3_;
		_tmp3_ = g_settings_get_boolean (settings, "automatic-clean");
		_tmp1_ = _tmp3_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		Document* _tmp4_ = NULL;
		CleanBuildFiles* _tmp5_ = NULL;
		CleanBuildFiles* build_files;
		_tmp4_ = document_tab_get_document (tab);
		_tmp5_ = clean_build_files_new (self->priv->main_window, _tmp4_);
		build_files = _tmp5_;
		clean_build_files_clean (build_files);
		_g_object_unref0 (build_files);
	}
	_tmp6_ = gtk_notebook_page_num ((GtkNotebook*) self, (GtkWidget*) tab);
	pos = _tmp6_;
	gtk_notebook_remove_page ((GtkNotebook*) self, pos);
	_g_object_unref0 (settings);
}


void documents_panel_remove_all_tabs (DocumentsPanel* self) {
	g_return_if_fail (self != NULL);
	while (TRUE) {
		gint _tmp0_;
		gint n;
		GtkWidget* _tmp1_ = NULL;
		DocumentTab* _tmp2_;
		DocumentTab* tab;
		_tmp0_ = gtk_notebook_get_current_page ((GtkNotebook*) self);
		n = _tmp0_;
		if (n == (-1)) {
			break;
		}
		_tmp1_ = gtk_notebook_get_nth_page ((GtkNotebook*) self, n);
		_tmp2_ = _g_object_ref0 (DOCUMENT_TAB (_tmp1_));
		tab = _tmp2_;
		documents_panel_remove_tab (self, tab);
		_g_object_unref0 (tab);
	}
}


DocumentTab* documents_panel_get_active_tab (DocumentsPanel* self) {
	DocumentTab* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_active_tab;
	return result;
}


static void documents_panel_set_active_tab (DocumentsPanel* self, DocumentTab* value) {
	DocumentTab* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_active_tab);
	self->priv->_active_tab = _tmp0_;
	g_object_notify ((GObject *) self, "active-tab");
}


static void documents_panel_class_init (DocumentsPanelClass * klass) {
	documents_panel_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (DocumentsPanelPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_documents_panel_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_documents_panel_set_property;
	G_OBJECT_CLASS (klass)->finalize = documents_panel_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DOCUMENTS_PANEL_ACTIVE_TAB, g_param_spec_object ("active-tab", "active-tab", "active-tab", TYPE_DOCUMENT_TAB, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_signal_new ("right_click", TYPE_DOCUMENTS_PANEL, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
}


static void documents_panel_instance_init (DocumentsPanel * self) {
	self->priv = DOCUMENTS_PANEL_GET_PRIVATE (self);
}


static void documents_panel_finalize (GObject* obj) {
	DocumentsPanel * self;
	self = DOCUMENTS_PANEL (obj);
	_g_object_unref0 (self->priv->_active_tab);
	G_OBJECT_CLASS (documents_panel_parent_class)->finalize (obj);
}


GType documents_panel_get_type (void) {
	static volatile gsize documents_panel_type_id__volatile = 0;
	if (g_once_init_enter (&documents_panel_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (DocumentsPanelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) documents_panel_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DocumentsPanel), 0, (GInstanceInitFunc) documents_panel_instance_init, NULL };
		GType documents_panel_type_id;
		documents_panel_type_id = g_type_register_static (GTK_TYPE_NOTEBOOK, "DocumentsPanel", &g_define_type_info, 0);
		g_once_init_leave (&documents_panel_type_id__volatile, documents_panel_type_id);
	}
	return documents_panel_type_id__volatile;
}


static void _vala_documents_panel_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	DocumentsPanel * self;
	self = DOCUMENTS_PANEL (object);
	switch (property_id) {
		case DOCUMENTS_PANEL_ACTIVE_TAB:
		g_value_set_object (value, documents_panel_get_active_tab (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_documents_panel_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	DocumentsPanel * self;
	self = DOCUMENTS_PANEL (object);
	switch (property_id) {
		case DOCUMENTS_PANEL_ACTIVE_TAB:
		documents_panel_set_active_tab (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



