/* vtgsourceoutliner.c generated by valac 0.12.1.1-323029-dirty, the Vala compiler
 * generated from vtgsourceoutliner.vala, do not modify */

/*
 *  vtgsourceoutliner.vala - Vala developer toys for GEdit
 *  
 *  Copyright (C) 2009 - Andrea Del Signore <sejerpz@tin.it>
 *  
 *  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.
 */

#include <glib.h>
#include <glib-object.h>
#include <gedit/gedit-view.h>
#include <gedit/gedit-document.h>
#include <gtk/gtk.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <afrodite.h>
#include <stdlib.h>


#define VTG_TYPE_SOURCE_OUTLINER (vtg_source_outliner_get_type ())
#define VTG_SOURCE_OUTLINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_TYPE_SOURCE_OUTLINER, VtgSourceOutliner))
#define VTG_SOURCE_OUTLINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_TYPE_SOURCE_OUTLINER, VtgSourceOutlinerClass))
#define VTG_IS_SOURCE_OUTLINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_TYPE_SOURCE_OUTLINER))
#define VTG_IS_SOURCE_OUTLINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_TYPE_SOURCE_OUTLINER))
#define VTG_SOURCE_OUTLINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_TYPE_SOURCE_OUTLINER, VtgSourceOutlinerClass))

typedef struct _VtgSourceOutliner VtgSourceOutliner;
typedef struct _VtgSourceOutlinerClass VtgSourceOutlinerClass;
typedef struct _VtgSourceOutlinerPrivate VtgSourceOutlinerPrivate;

#define VTG_TYPE_PLUGIN_INSTANCE (vtg_plugin_instance_get_type ())
#define VTG_PLUGIN_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_TYPE_PLUGIN_INSTANCE, VtgPluginInstance))
#define VTG_PLUGIN_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_TYPE_PLUGIN_INSTANCE, VtgPluginInstanceClass))
#define VTG_IS_PLUGIN_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_TYPE_PLUGIN_INSTANCE))
#define VTG_IS_PLUGIN_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_TYPE_PLUGIN_INSTANCE))
#define VTG_PLUGIN_INSTANCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_TYPE_PLUGIN_INSTANCE, VtgPluginInstanceClass))

typedef struct _VtgPluginInstance VtgPluginInstance;
typedef struct _VtgPluginInstanceClass VtgPluginInstanceClass;

#define VTG_TYPE_SOURCE_OUTLINER_VIEW (vtg_source_outliner_view_get_type ())
#define VTG_SOURCE_OUTLINER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_TYPE_SOURCE_OUTLINER_VIEW, VtgSourceOutlinerView))
#define VTG_SOURCE_OUTLINER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_TYPE_SOURCE_OUTLINER_VIEW, VtgSourceOutlinerViewClass))
#define VTG_IS_SOURCE_OUTLINER_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_TYPE_SOURCE_OUTLINER_VIEW))
#define VTG_IS_SOURCE_OUTLINER_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_TYPE_SOURCE_OUTLINER_VIEW))
#define VTG_SOURCE_OUTLINER_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_TYPE_SOURCE_OUTLINER_VIEW, VtgSourceOutlinerViewClass))

typedef struct _VtgSourceOutlinerView VtgSourceOutlinerView;
typedef struct _VtgSourceOutlinerViewClass VtgSourceOutlinerViewClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))

#define VTG_TYPE_SYMBOL_COMPLETION (vtg_symbol_completion_get_type ())
#define VTG_SYMBOL_COMPLETION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_TYPE_SYMBOL_COMPLETION, VtgSymbolCompletion))
#define VTG_SYMBOL_COMPLETION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_TYPE_SYMBOL_COMPLETION, VtgSymbolCompletionClass))
#define VTG_IS_SYMBOL_COMPLETION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_TYPE_SYMBOL_COMPLETION))
#define VTG_IS_SYMBOL_COMPLETION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_TYPE_SYMBOL_COMPLETION))
#define VTG_SYMBOL_COMPLETION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_TYPE_SYMBOL_COMPLETION, VtgSymbolCompletionClass))

typedef struct _VtgSymbolCompletion VtgSymbolCompletion;
typedef struct _VtgSymbolCompletionClass VtgSymbolCompletionClass;
#define _afrodite_source_file_unref0(var) ((var == NULL) ? NULL : (var = (afrodite_source_file_unref (var), NULL)))

struct _VtgSourceOutliner {
	GObject parent_instance;
	VtgSourceOutlinerPrivate * priv;
};

struct _VtgSourceOutlinerClass {
	GObjectClass parent_class;
};

struct _VtgSourceOutlinerPrivate {
	VtgPluginInstance* _plugin_instance;
	GeditView* _active_view;
	GeditDocument* _active_doc;
	VtgSourceOutlinerView* _outliner_view;
	gboolean completion_setup;
};


static gpointer vtg_source_outliner_parent_class = NULL;
static GType vtg_source_outliner_type_id = 0;

GType vtg_source_outliner_get_type (void) G_GNUC_CONST;
GType vtg_source_outliner_register_type (GTypeModule * module);
GType vtg_plugin_instance_get_type (void) G_GNUC_CONST;
GType vtg_plugin_instance_register_type (GTypeModule * module);
GType vtg_source_outliner_view_get_type (void) G_GNUC_CONST;
GType vtg_source_outliner_view_register_type (GTypeModule * module);
#define VTG_SOURCE_OUTLINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VTG_TYPE_SOURCE_OUTLINER, VtgSourceOutlinerPrivate))
enum  {
	VTG_SOURCE_OUTLINER_DUMMY_PROPERTY,
	VTG_SOURCE_OUTLINER_ACTIVE_VIEW
};
static void vtg_source_outliner_on_goto_source (VtgSourceOutliner* self, VtgSourceOutlinerView* sender, gint line, gint start_column, gint end_column);
static void _vtg_source_outliner_on_goto_source_vtg_source_outliner_view_goto_source (VtgSourceOutlinerView* _sender, gint line, gint start_column, gint end_column, gpointer self);
void vtg_source_outliner_view_clear_view (VtgSourceOutlinerView* self);
void vtg_source_outliner_view_deactivate (VtgSourceOutlinerView* self);
void vtg_source_outliner_cleanup_document (VtgSourceOutliner* self);
static void vtg_source_outliner_cleanup_completion_with_view (VtgSourceOutliner* self, GeditView* view);
VtgSourceOutliner* vtg_source_outliner_new (VtgPluginInstance* plugin_instance);
VtgSourceOutliner* vtg_source_outliner_construct (GType object_type, VtgPluginInstance* plugin_instance);
VtgSourceOutlinerView* vtg_source_outliner_view_new (VtgPluginInstance* plugin_instance);
VtgSourceOutlinerView* vtg_source_outliner_view_construct (GType object_type, VtgPluginInstance* plugin_instance);
static void vtg_source_outliner_on_filter_changed (VtgSourceOutliner* self, VtgSourceOutlinerView* sender);
static void _vtg_source_outliner_on_filter_changed_vtg_source_outliner_view_filter_changed (VtgSourceOutlinerView* _sender, gpointer self);
static gboolean vtg_source_outliner_update_source_outliner_view (VtgSourceOutliner* self);
static GtkTextIter* _gtk_text_iter_dup (GtkTextIter* self);
static void vtg_source_outliner_setup_document (VtgSourceOutliner* self, GeditDocument* doc);
static void vtg_source_outliner_on_notify_language (VtgSourceOutliner* self, GObject* sender, GParamSpec* pspec);
static void _vtg_source_outliner_on_notify_language_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void vtg_source_outliner_on_notify_cursor_position (VtgSourceOutliner* self, GObject* sender, GParamSpec* pspec);
static void _vtg_source_outliner_on_notify_cursor_position_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void vtg_source_outliner_setup_completion_with_view (VtgSourceOutliner* self, GeditView* view);
GType vtg_symbol_completion_get_type (void) G_GNUC_CONST;
GType vtg_symbol_completion_register_type (GTypeModule * module);
VtgSymbolCompletion* vtg_plugin_instance_scs_find_from_view (VtgPluginInstance* self, GeditView* view);
AfroditeCompletionEngine* vtg_symbol_completion_get_completion_engine (VtgSymbolCompletion* self);
void vtg_source_outliner_setup_completion_engine (VtgSourceOutliner* self, AfroditeCompletionEngine* engine);
static void vtg_source_outliner_on_file_parsed (VtgSourceOutliner* self, AfroditeCompletionEngine* sender, const gchar* filename, AfroditeParseResult* parse_result);
static void _vtg_source_outliner_on_file_parsed_afrodite_completion_engine_file_parsed (AfroditeCompletionEngine* _sender, AfroditeCompletionEngine* sender, const gchar* filename, AfroditeParseResult* parse_result, gpointer self);
static void vtg_source_outliner_on_file_removed (VtgSourceOutliner* self, AfroditeCompletionEngine* sender, const gchar* filename);
static void _vtg_source_outliner_on_file_removed_afrodite_completion_engine_file_removed (AfroditeCompletionEngine* _sender, AfroditeCompletionEngine* sender, const gchar* filename, gpointer self);
void vtg_source_outliner_cleanup_completion_engine (VtgSourceOutliner* self, AfroditeCompletionEngine* engine);
gboolean vtg_utils_is_vala_doc (GeditDocument* doc);
static void vtg_source_outliner_update_cursor_position (VtgSourceOutliner* self, GeditDocument* doc);
void vtg_source_outliner_view_set_current_position (VtgSourceOutlinerView* self, gint line, gint column);
gchar* vtg_utils_get_document_name (GeditDocument* doc);
void vtg_utils_trace (const gchar* format, ...);
void vtg_source_outliner_view_update_view (VtgSourceOutlinerView* self, AfroditeSourceFile* source);
GeditView* vtg_source_outliner_get_active_view (VtgSourceOutliner* self);
void vtg_source_outliner_set_active_view (VtgSourceOutliner* self, GeditView* value);
void vtg_source_outliner_view_set_active_view (VtgSourceOutlinerView* self, GeditView* value);
static void vtg_source_outliner_finalize (GObject* obj);
static void _vala_vtg_source_outliner_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_vtg_source_outliner_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


static void _vtg_source_outliner_on_goto_source_vtg_source_outliner_view_goto_source (VtgSourceOutlinerView* _sender, gint line, gint start_column, gint end_column, gpointer self) {
	vtg_source_outliner_on_goto_source (self, _sender, line, start_column, end_column);
}


static void _vtg_source_outliner_on_filter_changed_vtg_source_outliner_view_filter_changed (VtgSourceOutlinerView* _sender, gpointer self) {
	vtg_source_outliner_on_filter_changed (self, _sender);
}


VtgSourceOutliner* vtg_source_outliner_construct (GType object_type, VtgPluginInstance* plugin_instance) {
	VtgSourceOutliner * self = NULL;
	VtgSourceOutlinerView* _tmp0_ = NULL;
	g_return_val_if_fail (plugin_instance != NULL, NULL);
	self = (VtgSourceOutliner*) g_object_new (object_type, NULL);
	self->priv->_plugin_instance = plugin_instance;
	_tmp0_ = vtg_source_outliner_view_new (plugin_instance);
	_g_object_unref0 (self->priv->_outliner_view);
	self->priv->_outliner_view = _tmp0_;
	g_signal_connect_object (self->priv->_outliner_view, "goto-source", (GCallback) _vtg_source_outliner_on_goto_source_vtg_source_outliner_view_goto_source, self, 0);
	g_signal_connect_object (self->priv->_outliner_view, "filter-changed", (GCallback) _vtg_source_outliner_on_filter_changed_vtg_source_outliner_view_filter_changed, self, 0);
	return self;
}


VtgSourceOutliner* vtg_source_outliner_new (VtgPluginInstance* plugin_instance) {
	return vtg_source_outliner_construct (VTG_TYPE_SOURCE_OUTLINER, plugin_instance);
}


static void vtg_source_outliner_on_filter_changed (VtgSourceOutliner* self, VtgSourceOutlinerView* sender) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	vtg_source_outliner_update_source_outliner_view (self);
}


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


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


static gpointer __gtk_text_iter_dup0 (gpointer self) {
	return self ? _gtk_text_iter_dup (self) : NULL;
}


static void vtg_source_outliner_on_goto_source (VtgSourceOutliner* self, VtgSourceOutlinerView* sender, gint line, gint start_column, gint end_column) {
	GtkTextBuffer* _tmp0_ = NULL;
	GeditDocument* _tmp1_;
	GeditDocument* doc;
	GtkTextIter* iter = NULL;
	GtkTextIter _tmp2_ = {0};
	GtkTextIter* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	_tmp0_ = gtk_text_view_get_buffer ((GtkTextView*) self->priv->_active_view);
	_tmp1_ = _g_object_ref0 (GEDIT_DOCUMENT (_tmp0_));
	doc = _tmp1_;
	gtk_text_buffer_get_iter_at_line_offset ((GtkTextBuffer*) doc, &_tmp2_, line - 1, 0);
	_g_free0 (iter);
	_tmp3_ = __gtk_text_iter_dup0 (&_tmp2_);
	iter = _tmp3_;
	if (iter != NULL) {
		gtk_text_buffer_place_cursor ((GtkTextBuffer*) doc, iter);
		gtk_text_view_scroll_to_iter ((GtkTextView*) self->priv->_active_view, iter, (gdouble) 0, TRUE, (gdouble) 0, 0.5);
		gtk_widget_grab_focus ((GtkWidget*) self->priv->_active_view);
	}
	_g_free0 (iter);
	_g_object_unref0 (doc);
}


static void _vtg_source_outliner_on_notify_language_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	vtg_source_outliner_on_notify_language (self, _sender, pspec);
}


static void _vtg_source_outliner_on_notify_cursor_position_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	vtg_source_outliner_on_notify_cursor_position (self, _sender, pspec);
}


static void vtg_source_outliner_setup_document (VtgSourceOutliner* self, GeditDocument* doc) {
	GeditDocument* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (doc != NULL);
	_tmp0_ = _g_object_ref0 (doc);
	_g_object_unref0 (self->priv->_active_doc);
	self->priv->_active_doc = _tmp0_;
	g_signal_connect_object ((GObject*) doc, "notify::language", (GCallback) _vtg_source_outliner_on_notify_language_g_object_notify, self, 0);
	g_signal_connect_object ((GObject*) doc, "notify::cursor-position", (GCallback) _vtg_source_outliner_on_notify_cursor_position_g_object_notify, self, 0);
}


void vtg_source_outliner_cleanup_document (VtgSourceOutliner* self) {
	g_return_if_fail (self != NULL);
	if (self->priv->_active_doc != NULL) {
		guint _tmp0_;
		GQuark _tmp1_;
		guint _tmp2_;
		GQuark _tmp3_;
		g_signal_parse_name ("notify::language", G_TYPE_OBJECT, &_tmp0_, &_tmp1_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) self->priv->_active_doc, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, _tmp1_, NULL, (GCallback) _vtg_source_outliner_on_notify_language_g_object_notify, self);
		g_signal_parse_name ("notify::cursor-position", G_TYPE_OBJECT, &_tmp2_, &_tmp3_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) self->priv->_active_doc, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, _tmp3_, NULL, (GCallback) _vtg_source_outliner_on_notify_cursor_position_g_object_notify, self);
		_g_object_unref0 (self->priv->_active_doc);
		self->priv->_active_doc = NULL;
	}
}


static void vtg_source_outliner_setup_completion_with_view (VtgSourceOutliner* self, GeditView* view) {
	VtgSymbolCompletion* _tmp0_ = NULL;
	VtgSymbolCompletion* scs;
	gboolean _tmp1_ = FALSE;
	AfroditeCompletionEngine* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (view != NULL);
	_tmp0_ = vtg_plugin_instance_scs_find_from_view (self->priv->_plugin_instance, view);
	scs = _tmp0_;
	if (scs == NULL) {
		_tmp1_ = TRUE;
	} else {
		AfroditeCompletionEngine* _tmp2_ = NULL;
		_tmp2_ = vtg_symbol_completion_get_completion_engine (scs);
		_tmp1_ = _tmp2_ == NULL;
	}
	if (_tmp1_) {
		_g_object_unref0 (scs);
		return;
	}
	_tmp3_ = vtg_symbol_completion_get_completion_engine (scs);
	vtg_source_outliner_setup_completion_engine (self, _tmp3_);
	_g_object_unref0 (scs);
}


static void _vtg_source_outliner_on_file_parsed_afrodite_completion_engine_file_parsed (AfroditeCompletionEngine* _sender, AfroditeCompletionEngine* sender, const gchar* filename, AfroditeParseResult* parse_result, gpointer self) {
	vtg_source_outliner_on_file_parsed (self, sender, filename, parse_result);
}


static void _vtg_source_outliner_on_file_removed_afrodite_completion_engine_file_removed (AfroditeCompletionEngine* _sender, AfroditeCompletionEngine* sender, const gchar* filename, gpointer self) {
	vtg_source_outliner_on_file_removed (self, sender, filename);
}


void vtg_source_outliner_setup_completion_engine (VtgSourceOutliner* self, AfroditeCompletionEngine* engine) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (engine != NULL);
	self->priv->completion_setup = TRUE;
	g_signal_connect_object (engine, "file-parsed", (GCallback) _vtg_source_outliner_on_file_parsed_afrodite_completion_engine_file_parsed, self, 0);
	g_signal_connect_object (engine, "file-removed", (GCallback) _vtg_source_outliner_on_file_removed_afrodite_completion_engine_file_removed, self, 0);
}


static void vtg_source_outliner_cleanup_completion_with_view (VtgSourceOutliner* self, GeditView* view) {
	VtgSymbolCompletion* _tmp0_ = NULL;
	VtgSymbolCompletion* scs;
	gboolean _tmp1_ = FALSE;
	AfroditeCompletionEngine* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (view != NULL);
	_tmp0_ = vtg_plugin_instance_scs_find_from_view (self->priv->_plugin_instance, view);
	scs = _tmp0_;
	if (scs == NULL) {
		_tmp1_ = TRUE;
	} else {
		AfroditeCompletionEngine* _tmp2_ = NULL;
		_tmp2_ = vtg_symbol_completion_get_completion_engine (scs);
		_tmp1_ = _tmp2_ == NULL;
	}
	if (_tmp1_) {
		_g_object_unref0 (scs);
		return;
	}
	_tmp3_ = vtg_symbol_completion_get_completion_engine (scs);
	vtg_source_outliner_cleanup_completion_engine (self, _tmp3_);
	_g_object_unref0 (scs);
}


void vtg_source_outliner_cleanup_completion_engine (VtgSourceOutliner* self, AfroditeCompletionEngine* engine) {
	guint _tmp0_;
	guint _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (engine != NULL);
	g_signal_parse_name ("file-parsed", AFRODITE_TYPE_COMPLETION_ENGINE, &_tmp0_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (engine, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, 0, NULL, (GCallback) _vtg_source_outliner_on_file_parsed_afrodite_completion_engine_file_parsed, self);
	g_signal_parse_name ("file-removed", AFRODITE_TYPE_COMPLETION_ENGINE, &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (engine, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _vtg_source_outliner_on_file_removed_afrodite_completion_engine_file_removed, self);
	self->priv->completion_setup = FALSE;
}


static void vtg_source_outliner_on_notify_language (VtgSourceOutliner* self, GObject* sender, GParamSpec* pspec) {
	GeditDocument* _tmp0_;
	GeditDocument* doc;
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = _g_object_ref0 (GEDIT_DOCUMENT (sender));
	doc = _tmp0_;
	_tmp1_ = vtg_utils_is_vala_doc (doc);
	if (_tmp1_) {
		vtg_source_outliner_update_source_outliner_view (self);
		vtg_source_outliner_setup_completion_with_view (self, self->priv->_active_view);
	}
	_g_object_unref0 (doc);
}


static void vtg_source_outliner_on_notify_cursor_position (VtgSourceOutliner* self, GObject* sender, GParamSpec* pspec) {
	GeditDocument* _tmp0_;
	GeditDocument* doc;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = _g_object_ref0 (GEDIT_DOCUMENT (sender));
	doc = _tmp0_;
	vtg_source_outliner_update_cursor_position (self, doc);
	_g_object_unref0 (doc);
}


static void vtg_source_outliner_update_cursor_position (VtgSourceOutliner* self, GeditDocument* doc) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (doc != NULL);
	_tmp0_ = vtg_utils_is_vala_doc (doc);
	if (_tmp0_) {
		GtkTextMark* _tmp1_ = NULL;
		GtkTextMark* mark;
		GtkTextIter start = {0};
		GtkTextIter _tmp2_ = {0};
		gint _tmp3_;
		gint line;
		gint _tmp4_;
		gint column;
		_tmp1_ = gtk_text_buffer_get_insert ((GtkTextBuffer*) doc);
		mark = GTK_TEXT_MARK (_tmp1_);
		gtk_text_buffer_get_iter_at_mark ((GtkTextBuffer*) doc, &_tmp2_, mark);
		start = _tmp2_;
		_tmp3_ = gtk_text_iter_get_line (&start);
		line = _tmp3_;
		_tmp4_ = gtk_text_iter_get_line_index (&start);
		column = _tmp4_;
		vtg_source_outliner_view_set_current_position (self->priv->_outliner_view, line, column);
	}
}


static void vtg_source_outliner_on_file_removed (VtgSourceOutliner* self, AfroditeCompletionEngine* sender, const gchar* filename) {
	GtkTextBuffer* _tmp0_ = NULL;
	GeditDocument* _tmp1_;
	GeditDocument* doc;
	gchar* _tmp2_ = NULL;
	gchar* name;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (filename != NULL);
	_tmp0_ = gtk_text_view_get_buffer ((GtkTextView*) self->priv->_active_view);
	_tmp1_ = _g_object_ref0 (GEDIT_DOCUMENT (_tmp0_));
	doc = _tmp1_;
	_tmp2_ = vtg_utils_get_document_name (doc);
	name = _tmp2_;
	vtg_utils_trace ("vtgsourceoutliner.vala:189: File removed: %s - current file: %s", filename, name);
	if (g_strcmp0 (filename, name) == 0) {
		vtg_source_outliner_view_clear_view (self->priv->_outliner_view);
	}
	_g_free0 (name);
	_g_object_unref0 (doc);
}


static void vtg_source_outliner_on_file_parsed (VtgSourceOutliner* self, AfroditeCompletionEngine* sender, const gchar* filename, AfroditeParseResult* parse_result) {
	GtkTextBuffer* _tmp0_ = NULL;
	GeditDocument* _tmp1_;
	GeditDocument* doc;
	gchar* _tmp2_ = NULL;
	gchar* name;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (filename != NULL);
	g_return_if_fail (parse_result != NULL);
	_tmp0_ = gtk_text_view_get_buffer ((GtkTextView*) self->priv->_active_view);
	_tmp1_ = _g_object_ref0 (GEDIT_DOCUMENT (_tmp0_));
	doc = _tmp1_;
	_tmp2_ = vtg_utils_get_document_name (doc);
	name = _tmp2_;
	vtg_utils_trace ("vtgsourceoutliner.vala:199: File parsed: %s - current file: %s", filename, name);
	if (g_strcmp0 (filename, name) == 0) {
		vtg_source_outliner_update_source_outliner_view (self);
	}
	_g_free0 (name);
	_g_object_unref0 (doc);
}


static gboolean vtg_source_outliner_update_source_outliner_view (VtgSourceOutliner* self) {
	gboolean result = FALSE;
	VtgSymbolCompletion* _tmp0_ = NULL;
	VtgSymbolCompletion* scs;
	gboolean _tmp1_ = FALSE;
	GtkTextBuffer* _tmp3_ = NULL;
	GeditDocument* _tmp4_;
	GeditDocument* doc;
	gchar* _tmp5_ = NULL;
	gchar* name;
	AfroditeCompletionEngine* _tmp6_ = NULL;
	AfroditeCodeDom* _tmp7_ = NULL;
	AfroditeSourceFile* _tmp8_ = NULL;
	AfroditeSourceFile* _result_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = vtg_plugin_instance_scs_find_from_view (self->priv->_plugin_instance, self->priv->_active_view);
	scs = _tmp0_;
	if (scs == NULL) {
		_tmp1_ = TRUE;
	} else {
		AfroditeCompletionEngine* _tmp2_ = NULL;
		_tmp2_ = vtg_symbol_completion_get_completion_engine (scs);
		_tmp1_ = _tmp2_ == NULL;
	}
	if (_tmp1_) {
		vtg_utils_trace ("vtgsourceoutliner.vala:209: symbol completion helper is null for view");
		result = TRUE;
		_g_object_unref0 (scs);
		return result;
	}
	_tmp3_ = gtk_text_view_get_buffer ((GtkTextView*) self->priv->_active_view);
	_tmp4_ = _g_object_ref0 (GEDIT_DOCUMENT (_tmp3_));
	doc = _tmp4_;
	_tmp5_ = vtg_utils_get_document_name (doc);
	name = _tmp5_;
	_tmp6_ = vtg_symbol_completion_get_completion_engine (scs);
	_tmp7_ = afrodite_completion_engine_get_codedom (_tmp6_);
	_tmp8_ = afrodite_code_dom_lookup_source_file (_tmp7_, name);
	_result_ = _tmp8_;
	vtg_source_outliner_update_cursor_position (self, doc);
	vtg_source_outliner_view_update_view (self->priv->_outliner_view, _result_);
	if (_result_ == NULL) {
		vtg_source_outliner_view_clear_view (self->priv->_outliner_view);
	}
	result = TRUE;
	_afrodite_source_file_unref0 (_result_);
	_g_free0 (name);
	_g_object_unref0 (doc);
	_g_object_unref0 (scs);
	return result;
}


GeditView* vtg_source_outliner_get_active_view (VtgSourceOutliner* self) {
	GeditView* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self->priv->_active_view;
	return result;
}


void vtg_source_outliner_set_active_view (VtgSourceOutliner* self, GeditView* value) {
	g_return_if_fail (self != NULL);
	if (self->priv->_active_view != value) {
		GeditView* _tmp0_;
		if (self->priv->_active_view != NULL) {
			vtg_source_outliner_cleanup_document (self);
			if (self->priv->completion_setup) {
				vtg_source_outliner_cleanup_completion_with_view (self, self->priv->_active_view);
			}
			vtg_source_outliner_view_clear_view (self->priv->_outliner_view);
		}
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_active_view);
		self->priv->_active_view = _tmp0_;
		vtg_source_outliner_view_set_active_view (self->priv->_outliner_view, self->priv->_active_view);
		if (self->priv->_active_view != NULL) {
			GtkTextBuffer* _tmp1_ = NULL;
			GeditDocument* _tmp2_;
			GeditDocument* doc;
			gboolean _tmp3_;
			_tmp1_ = gtk_text_view_get_buffer ((GtkTextView*) self->priv->_active_view);
			_tmp2_ = _g_object_ref0 (GEDIT_DOCUMENT (_tmp1_));
			doc = _tmp2_;
			vtg_source_outliner_setup_document (self, doc);
			_tmp3_ = vtg_utils_is_vala_doc (doc);
			if (_tmp3_) {
				vtg_source_outliner_setup_completion_with_view (self, self->priv->_active_view);
				vtg_source_outliner_update_source_outliner_view (self);
			}
			_g_object_unref0 (doc);
		}
	}
	g_object_notify ((GObject *) self, "active-view");
}


static void vtg_source_outliner_class_init (VtgSourceOutlinerClass * klass) {
	vtg_source_outliner_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (VtgSourceOutlinerPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_vtg_source_outliner_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_vtg_source_outliner_set_property;
	G_OBJECT_CLASS (klass)->finalize = vtg_source_outliner_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), VTG_SOURCE_OUTLINER_ACTIVE_VIEW, g_param_spec_object ("active-view", "active-view", "active-view", gedit_view_get_type (), G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void vtg_source_outliner_instance_init (VtgSourceOutliner * self) {
	self->priv = VTG_SOURCE_OUTLINER_GET_PRIVATE (self);
	self->priv->_plugin_instance = NULL;
	self->priv->_active_view = NULL;
	self->priv->_active_doc = NULL;
	self->priv->_outliner_view = NULL;
	self->priv->completion_setup = FALSE;
}


static void vtg_source_outliner_finalize (GObject* obj) {
	VtgSourceOutliner * self;
	self = VTG_SOURCE_OUTLINER (obj);
	if (self->priv->_outliner_view != NULL) {
		guint _tmp0_;
		g_signal_parse_name ("goto-source", VTG_TYPE_SOURCE_OUTLINER_VIEW, &_tmp0_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (self->priv->_outliner_view, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, 0, NULL, (GCallback) _vtg_source_outliner_on_goto_source_vtg_source_outliner_view_goto_source, self);
		vtg_source_outliner_view_clear_view (self->priv->_outliner_view);
		vtg_source_outliner_view_deactivate (self->priv->_outliner_view);
		_g_object_unref0 (self->priv->_outliner_view);
		self->priv->_outliner_view = NULL;
	}
	if (self->priv->_active_view != NULL) {
		vtg_source_outliner_cleanup_document (self);
		if (self->priv->completion_setup) {
			vtg_source_outliner_cleanup_completion_with_view (self, self->priv->_active_view);
		}
		_g_object_unref0 (self->priv->_active_view);
		self->priv->_active_view = NULL;
	}
	_g_object_unref0 (self->priv->_active_doc);
	self->priv->_active_doc = NULL;
	_g_object_unref0 (self->priv->_active_view);
	_g_object_unref0 (self->priv->_active_doc);
	_g_object_unref0 (self->priv->_outliner_view);
	G_OBJECT_CLASS (vtg_source_outliner_parent_class)->finalize (obj);
}


GType vtg_source_outliner_get_type (void) {
	return vtg_source_outliner_type_id;
}


GType vtg_source_outliner_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (VtgSourceOutlinerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vtg_source_outliner_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (VtgSourceOutliner), 0, (GInstanceInitFunc) vtg_source_outliner_instance_init, NULL };
	vtg_source_outliner_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "VtgSourceOutliner", &g_define_type_info, 0);
	return vtg_source_outliner_type_id;
}


static void _vala_vtg_source_outliner_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	VtgSourceOutliner * self;
	self = VTG_SOURCE_OUTLINER (object);
	switch (property_id) {
		case VTG_SOURCE_OUTLINER_ACTIVE_VIEW:
		g_value_set_object (value, vtg_source_outliner_get_active_view (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_vtg_source_outliner_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	VtgSourceOutliner * self;
	self = VTG_SOURCE_OUTLINER (object);
	switch (property_id) {
		case VTG_SOURCE_OUTLINER_ACTIVE_VIEW:
		vtg_source_outliner_set_active_view (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



