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

/*
 *  vtgprojectsearchresultsview.vala - Vala developer toys for GEdit
 *  
 *  Copyright (C) 2008 - 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 <gtk/gtk.h>
#include <gedit/gedit-window.h>
#include <gedit/gedit-panel.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gedit/gedit-view.h>
#include <vbf.h>
#include <gedit/gedit-tab.h>
#include <float.h>
#include <math.h>
#include <pango/pango.h>


#define VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW (vtg_project_search_results_view_get_type ())
#define VTG_PROJECT_SEARCH_RESULTS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW, VtgProjectSearchResultsView))
#define VTG_PROJECT_SEARCH_RESULTS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW, VtgProjectSearchResultsViewClass))
#define VTG_IS_PROJECT_SEARCH_RESULTS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW))
#define VTG_IS_PROJECT_SEARCH_RESULTS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW))
#define VTG_PROJECT_SEARCH_RESULTS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW, VtgProjectSearchResultsViewClass))

typedef struct _VtgProjectSearchResultsView VtgProjectSearchResultsView;
typedef struct _VtgProjectSearchResultsViewClass VtgProjectSearchResultsViewClass;
typedef struct _VtgProjectSearchResultsViewPrivate VtgProjectSearchResultsViewPrivate;

#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_PROJECT_MANAGER (vtg_project_manager_get_type ())
#define VTG_PROJECT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_TYPE_PROJECT_MANAGER, VtgProjectManager))
#define VTG_PROJECT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_TYPE_PROJECT_MANAGER, VtgProjectManagerClass))
#define VTG_IS_PROJECT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_TYPE_PROJECT_MANAGER))
#define VTG_IS_PROJECT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_TYPE_PROJECT_MANAGER))
#define VTG_PROJECT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_TYPE_PROJECT_MANAGER, VtgProjectManagerClass))

typedef struct _VtgProjectManager VtgProjectManager;
typedef struct _VtgProjectManagerClass VtgProjectManagerClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _gtk_tree_path_free0(var) ((var == NULL) ? NULL : (var = (gtk_tree_path_free (var), NULL)))

#define VTG_TYPE_OUTPUT_VIEW (vtg_output_view_get_type ())
#define VTG_OUTPUT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_TYPE_OUTPUT_VIEW, VtgOutputView))
#define VTG_OUTPUT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_TYPE_OUTPUT_VIEW, VtgOutputViewClass))
#define VTG_IS_OUTPUT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_TYPE_OUTPUT_VIEW))
#define VTG_IS_OUTPUT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_TYPE_OUTPUT_VIEW))
#define VTG_OUTPUT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_TYPE_OUTPUT_VIEW, VtgOutputViewClass))

typedef struct _VtgOutputView VtgOutputView;
typedef struct _VtgOutputViewClass VtgOutputViewClass;

#define VTG_TYPE_OUTPUT_TYPES (vtg_output_types_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _VtgProjectSearchResultsView {
	GObject parent_instance;
	VtgProjectSearchResultsViewPrivate * priv;
};

struct _VtgProjectSearchResultsViewClass {
	GObjectClass parent_class;
};

struct _VtgProjectSearchResultsViewPrivate {
	GtkVBox* _ui;
	GtkListStore* _model;
	GtkTreeView* _results_view;
	GtkTreePath* _current;
	gint _match_count;
	VtgPluginInstance* _plugin_instance;
	VtgProjectManager* _project;
};

typedef enum  {
	VTG_OUTPUT_TYPES_MESSAGE,
	VTG_OUTPUT_TYPES_ERROR,
	VTG_OUTPUT_TYPES_CHILD_PROCESS,
	VTG_OUTPUT_TYPES_BUILD,
	VTG_OUTPUT_TYPES_AUTO_BUILD,
	VTG_OUTPUT_TYPES_SEARCH
} VtgOutputTypes;


static gpointer vtg_project_search_results_view_parent_class = NULL;
static GType vtg_project_search_results_view_type_id = 0;

GType vtg_project_search_results_view_get_type (void) G_GNUC_CONST;
GType vtg_project_search_results_view_register_type (GTypeModule * module);
GType vtg_plugin_instance_get_type (void) G_GNUC_CONST;
GType vtg_plugin_instance_register_type (GTypeModule * module);
GType vtg_project_manager_get_type (void) G_GNUC_CONST;
GType vtg_project_manager_register_type (GTypeModule * module);
#define VTG_PROJECT_SEARCH_RESULTS_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW, VtgProjectSearchResultsViewPrivate))
enum  {
	VTG_PROJECT_SEARCH_RESULTS_VIEW_DUMMY_PROPERTY
};
GeditWindow* vtg_plugin_instance_get_window (VtgPluginInstance* self);
VtgProjectSearchResultsView* vtg_project_search_results_view_new (VtgPluginInstance* plugin_instance);
VtgProjectSearchResultsView* vtg_project_search_results_view_construct (GType object_type, VtgPluginInstance* plugin_instance);
void vtg_project_search_results_view_on_results_view_row_activated (VtgProjectSearchResultsView* self, GtkWidget* sender, GtkTreePath* path, GtkTreeViewColumn* column);
static void _vtg_project_search_results_view_on_results_view_row_activated_gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self);
GType vtg_output_view_get_type (void) G_GNUC_CONST;
GType vtg_output_view_register_type (GTypeModule * module);
VtgOutputView* vtg_plugin_instance_get_output_view (VtgPluginInstance* self);
GType vtg_output_types_get_type (void) G_GNUC_CONST;
void vtg_project_search_results_view_on_message_added (VtgProjectSearchResultsView* self, VtgOutputView* sender, VtgOutputTypes output_type, const gchar* message);
static void _vtg_project_search_results_view_on_message_added_vtg_output_view_message_added (VtgOutputView* _sender, VtgOutputTypes output_type, const gchar* message, gpointer self);
void vtg_project_search_results_view_initialize (VtgProjectSearchResultsView* self, VtgProjectManager* project);
void vtg_project_search_results_view_activate (VtgProjectSearchResultsView* self);
VbfProject* vtg_project_manager_get_project (VtgProjectManager* self);
static void vtg_project_search_results_view_add_message (VtgProjectSearchResultsView* self, const gchar* file, const gchar* message);
static void vtg_project_search_results_view_activate_path (VtgProjectSearchResultsView* self, GtkTreePath* path);
gchar* vtg_project_manager_source_uri_for_name (VtgProjectManager* self, const gchar* name);
GeditTab* vtg_plugin_instance_activate_uri (VtgPluginInstance* self, const gchar* uri, gint line, gint col);
void vtg_plugin_instance_activate_display_name (VtgPluginInstance* self, const gchar* display_name, gint line, gint col);
void vtg_project_search_results_view_next_match (VtgProjectSearchResultsView* self);
void vtg_project_search_results_view_previous_match (VtgProjectSearchResultsView* self);
gboolean vtg_string_utils_is_null_or_empty (const gchar* data);
static void vtg_project_search_results_view_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);


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


static void _vtg_project_search_results_view_on_results_view_row_activated_gtk_tree_view_row_activated (GtkTreeView* _sender, GtkTreePath* path, GtkTreeViewColumn* column, gpointer self) {
	vtg_project_search_results_view_on_results_view_row_activated (self, _sender, path, column);
}


static void _vtg_project_search_results_view_on_message_added_vtg_output_view_message_added (VtgOutputView* _sender, VtgOutputTypes output_type, const gchar* message, gpointer self) {
	vtg_project_search_results_view_on_message_added (self, _sender, output_type, message);
}


VtgProjectSearchResultsView* vtg_project_search_results_view_construct (GType object_type, VtgPluginInstance* plugin_instance) {
	VtgProjectSearchResultsView * self = NULL;
	GeditWindow* _tmp0_ = NULL;
	GeditPanel* _tmp1_ = NULL;
	GeditPanel* _tmp2_;
	GeditPanel* panel;
	GtkVBox* _tmp3_ = NULL;
	GtkListStore* _tmp4_ = NULL;
	GtkTreeView* _tmp5_ = NULL;
	GtkCellRendererPixbuf* _tmp6_ = NULL;
	GtkCellRenderer* renderer;
	GtkCellRendererText* _tmp7_ = NULL;
	GtkTreeViewColumn* _tmp8_ = NULL;
	GtkTreeViewColumn* column;
	const gchar* _tmp9_ = NULL;
	GtkCellRendererText* _tmp10_ = NULL;
	GtkTreeViewColumn* _tmp11_ = NULL;
	const gchar* _tmp12_ = NULL;
	GtkCellRendererText* _tmp13_ = NULL;
	GtkTreeViewColumn* _tmp14_ = NULL;
	const gchar* _tmp15_ = NULL;
	GtkScrolledWindow* _tmp16_ = NULL;
	GtkScrolledWindow* scroll;
	const gchar* _tmp17_ = NULL;
	VtgOutputView* _tmp18_ = NULL;
	g_return_val_if_fail (plugin_instance != NULL, NULL);
	self = (VtgProjectSearchResultsView*) g_object_new (object_type, NULL);
	self->priv->_plugin_instance = plugin_instance;
	_tmp0_ = vtg_plugin_instance_get_window (self->priv->_plugin_instance);
	_tmp1_ = gedit_window_get_bottom_panel (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	panel = _tmp2_;
	_tmp3_ = (GtkVBox*) gtk_vbox_new (FALSE, 8);
	_g_object_unref0 (self->priv->_ui);
	self->priv->_ui = g_object_ref_sink (_tmp3_);
	_tmp4_ = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_OBJECT);
	_g_object_unref0 (self->priv->_model);
	self->priv->_model = _tmp4_;
	_tmp5_ = (GtkTreeView*) gtk_tree_view_new_with_model ((GtkTreeModel*) self->priv->_model);
	_g_object_unref0 (self->priv->_results_view);
	self->priv->_results_view = g_object_ref_sink (_tmp5_);
	_tmp6_ = (GtkCellRendererPixbuf*) gtk_cell_renderer_pixbuf_new ();
	renderer = (GtkCellRenderer*) g_object_ref_sink (_tmp6_);
	_tmp7_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	_g_object_unref0 (renderer);
	renderer = (GtkCellRenderer*) g_object_ref_sink (_tmp7_);
	_tmp8_ = gtk_tree_view_column_new ();
	column = g_object_ref_sink (_tmp8_);
	_tmp9_ = _ ("File");
	gtk_tree_view_column_set_title (column, _tmp9_);
	gtk_cell_layout_pack_start ((GtkCellLayout*) column, renderer, FALSE);
	gtk_cell_layout_add_attribute ((GtkCellLayout*) column, renderer, "text", 0);
	gtk_tree_view_append_column (self->priv->_results_view, column);
	_tmp10_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	_g_object_unref0 (renderer);
	renderer = (GtkCellRenderer*) g_object_ref_sink (_tmp10_);
	_tmp11_ = gtk_tree_view_column_new ();
	_g_object_unref0 (column);
	column = g_object_ref_sink (_tmp11_);
	_tmp12_ = _ ("Line");
	gtk_tree_view_column_set_title (column, _tmp12_);
	gtk_cell_layout_pack_start ((GtkCellLayout*) column, renderer, FALSE);
	gtk_cell_layout_add_attribute ((GtkCellLayout*) column, renderer, "text", 1);
	gtk_tree_view_append_column (self->priv->_results_view, column);
	_tmp13_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	_g_object_unref0 (renderer);
	renderer = (GtkCellRenderer*) g_object_ref_sink (_tmp13_);
	_tmp14_ = gtk_tree_view_column_new ();
	_g_object_unref0 (column);
	column = g_object_ref_sink (_tmp14_);
	_tmp15_ = _ ("Text");
	gtk_tree_view_column_set_title (column, _tmp15_);
	gtk_cell_layout_pack_start ((GtkCellLayout*) column, renderer, FALSE);
	gtk_cell_layout_add_attribute ((GtkCellLayout*) column, renderer, "text", 2);
	gtk_tree_view_append_column (self->priv->_results_view, column);
	g_signal_connect_object (self->priv->_results_view, "row-activated", (GCallback) _vtg_project_search_results_view_on_results_view_row_activated_gtk_tree_view_row_activated, self, 0);
	gtk_tree_view_set_rules_hint (self->priv->_results_view, TRUE);
	_tmp16_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	scroll = g_object_ref_sink (_tmp16_);
	gtk_container_add ((GtkContainer*) scroll, (GtkWidget*) self->priv->_results_view);
	gtk_box_pack_start ((GtkBox*) self->priv->_ui, (GtkWidget*) scroll, TRUE, TRUE, (guint) 0);
	gtk_widget_show_all ((GtkWidget*) self->priv->_ui);
	_tmp17_ = _ ("Search results");
	gedit_panel_add_item_with_stock_icon (panel, (GtkWidget*) self->priv->_ui, "Search results", _tmp17_, GTK_STOCK_FIND);
	_tmp18_ = vtg_plugin_instance_get_output_view (self->priv->_plugin_instance);
	g_signal_connect_object (_tmp18_, "message-added", (GCallback) _vtg_project_search_results_view_on_message_added_vtg_output_view_message_added, self, 0);
	gtk_tree_sortable_set_sort_column_id ((GtkTreeSortable*) self->priv->_model, 0, GTK_SORT_ASCENDING);
	_g_object_unref0 (scroll);
	_g_object_unref0 (column);
	_g_object_unref0 (renderer);
	_g_object_unref0 (panel);
	return self;
}


VtgProjectSearchResultsView* vtg_project_search_results_view_new (VtgPluginInstance* plugin_instance) {
	return vtg_project_search_results_view_construct (VTG_TYPE_PROJECT_SEARCH_RESULTS_VIEW, plugin_instance);
}


void vtg_project_search_results_view_initialize (VtgProjectSearchResultsView* self, VtgProjectManager* project) {
	g_return_if_fail (self != NULL);
	self->priv->_project = project;
	_gtk_tree_path_free0 (self->priv->_current);
	self->priv->_current = NULL;
	self->priv->_match_count = 0;
	gtk_list_store_clear (self->priv->_model);
}


void vtg_project_search_results_view_activate (VtgProjectSearchResultsView* self) {
	GeditWindow* _tmp0_ = NULL;
	GeditPanel* _tmp1_ = NULL;
	GeditPanel* _tmp2_;
	GeditPanel* panel;
	GeditWindow* _tmp3_ = NULL;
	GeditView* _tmp4_ = NULL;
	GeditView* _tmp5_;
	GeditView* view;
	gboolean _tmp6_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = vtg_plugin_instance_get_window (self->priv->_plugin_instance);
	_tmp1_ = gedit_window_get_bottom_panel (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	panel = _tmp2_;
	gedit_panel_activate_item (panel, (GtkWidget*) self->priv->_ui);
	_tmp3_ = vtg_plugin_instance_get_window (self->priv->_plugin_instance);
	_tmp4_ = gedit_window_get_active_view (_tmp3_);
	_tmp5_ = _g_object_ref0 (_tmp4_);
	view = _tmp5_;
	if (view != NULL) {
		gboolean _tmp7_;
		g_object_get ((GtkWidget*) view, "is-focus", &_tmp7_, NULL);
		_tmp6_ = !_tmp7_;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		gtk_widget_grab_focus ((GtkWidget*) view);
	}
	_g_object_unref0 (view);
	_g_object_unref0 (panel);
}


static gchar* string_replace (const gchar* self, const gchar* old, const gchar* replacement) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_;
	GRegex* _tmp2_ = NULL;
	GRegex* _tmp3_;
	GRegex* regex;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	_tmp0_ = g_regex_escape_string (old, -1);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_regex_new (_tmp1_, 0, 0, &_inner_error_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	regex = _tmp3_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == G_REGEX_ERROR) {
			goto __catch30_g_regex_error;
		}
		g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp4_ = g_regex_replace_literal (regex, self, (gssize) (-1), 0, replacement, 0, &_inner_error_);
	_tmp5_ = _tmp4_;
	if (_inner_error_ != NULL) {
		_g_regex_unref0 (regex);
		if (_inner_error_->domain == G_REGEX_ERROR) {
			goto __catch30_g_regex_error;
		}
		_g_regex_unref0 (regex);
		g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	result = _tmp5_;
	_g_regex_unref0 (regex);
	return result;
	_g_regex_unref0 (regex);
	goto __finally30;
	__catch30_g_regex_error:
	{
		GError * e;
		e = _inner_error_;
		_inner_error_ = NULL;
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally30:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
}


void vtg_project_search_results_view_on_message_added (VtgProjectSearchResultsView* self, VtgOutputView* sender, VtgOutputTypes output_type, const gchar* message) {
	gchar** _tmp0_;
	gchar** _tmp1_ = NULL;
	gchar** lines;
	gint lines_length1;
	gint _lines_size_;
	gint idx;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (message != NULL);
	if (output_type != VTG_OUTPUT_TYPES_SEARCH) {
		return;
	}
	_tmp1_ = _tmp0_ = g_strsplit (message, "\n", 0);
	lines = _tmp1_;
	lines_length1 = _vala_array_length (_tmp0_);
	_lines_size_ = _vala_array_length (_tmp0_);
	idx = 0;
	while (TRUE) {
		gchar** _tmp2_;
		gchar** _tmp3_ = NULL;
		gchar** tmp;
		gint tmp_length1;
		gint _tmp_size_;
		gboolean _tmp4_ = FALSE;
		if (!(lines[idx] != NULL)) {
			break;
		}
		_tmp3_ = _tmp2_ = g_strsplit (lines[idx], ":", 2);
		tmp = _tmp3_;
		tmp_length1 = _vala_array_length (_tmp2_);
		_tmp_size_ = _vala_array_length (_tmp2_);
		if (tmp[0] != NULL) {
			gboolean _tmp5_ = FALSE;
			gboolean _tmp6_;
			_tmp6_ = g_str_has_suffix (tmp[0], ".vala");
			if (_tmp6_) {
				_tmp5_ = TRUE;
			} else {
				gboolean _tmp7_;
				_tmp7_ = g_str_has_suffix (tmp[0], ".vapi");
				_tmp5_ = _tmp7_;
			}
			_tmp4_ = _tmp5_;
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			VbfProject* _tmp8_ = NULL;
			gchar* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_ = NULL;
			gchar* _tmp12_;
			gchar* file;
			_tmp8_ = vtg_project_manager_get_project (self->priv->_project);
			_tmp9_ = g_strconcat (_tmp8_->id, "/", NULL);
			_tmp10_ = _tmp9_;
			_tmp11_ = string_replace (tmp[0], _tmp10_, "");
			_tmp12_ = _tmp11_;
			_g_free0 (_tmp10_);
			file = _tmp12_;
			vtg_project_search_results_view_add_message (self, file, tmp[1]);
			_g_free0 (file);
		}
		idx++;
		tmp = (_vala_array_free (tmp, tmp_length1, (GDestroyNotify) g_free), NULL);
	}
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
}


void vtg_project_search_results_view_on_results_view_row_activated (VtgProjectSearchResultsView* self, GtkWidget* sender, GtkTreePath* path, GtkTreeViewColumn* column) {
	GtkTreePath* _tmp0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sender != NULL);
	g_return_if_fail (path != NULL);
	g_return_if_fail (column != NULL);
	_tmp0_ = gtk_tree_path_copy (path);
	_gtk_tree_path_free0 (self->priv->_current);
	self->priv->_current = _tmp0_;
	vtg_project_search_results_view_activate_path (self, self->priv->_current);
}


static void vtg_project_search_results_view_activate_path (VtgProjectSearchResultsView* self, GtkTreePath* path) {
	GtkTreeIter iter = {0};
	GtkTreeIter _tmp0_ = {0};
	gboolean _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	_tmp1_ = gtk_tree_model_get_iter ((GtkTreeModel*) self->priv->_model, &_tmp0_, path);
	iter = _tmp0_;
	if (_tmp1_) {
		gchar* name = NULL;
		gint line = 0;
		VtgProjectManager* proj = NULL;
		gtk_tree_model_get ((GtkTreeModel*) self->priv->_model, &iter, 0, &name, 1, &line, 3, &proj, -1);
		if (proj != NULL) {
			VbfProject* _tmp2_ = NULL;
			gchar* _tmp3_ = NULL;
			gchar* _tmp4_;
			gchar* _tmp5_ = NULL;
			gchar* _tmp6_;
			gchar* uri;
			_tmp2_ = vtg_project_manager_get_project (self->priv->_project);
			_tmp3_ = g_build_filename (_tmp2_->id, name, NULL);
			_tmp4_ = _tmp3_;
			_tmp5_ = vtg_project_manager_source_uri_for_name (proj, _tmp4_);
			_tmp6_ = _tmp5_;
			_g_free0 (_tmp4_);
			uri = _tmp6_;
			if (uri != NULL) {
				GeditTab* _tmp7_ = NULL;
				GeditTab* _tmp8_;
				_tmp7_ = vtg_plugin_instance_activate_uri (self->priv->_plugin_instance, uri, line, 0);
				_tmp8_ = _tmp7_;
				_g_object_unref0 (_tmp8_);
			} else {
				g_warning ("vtgprojectsearchresultsview.vala:140: Couldn't find uri for source: %s", name);
			}
			_g_free0 (uri);
		} else {
			vtg_plugin_instance_activate_display_name (self->priv->_plugin_instance, name, line, 0);
		}
		_g_object_unref0 (proj);
		_g_free0 (name);
	}
}


void vtg_project_search_results_view_next_match (VtgProjectSearchResultsView* self) {
	gboolean _tmp0_ = FALSE;
	GtkTreeSelection* _tmp4_ = NULL;
	g_return_if_fail (self != NULL);
	if (self->priv->_match_count == 0) {
		return;
	}
	if (self->priv->_current == NULL) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp1_ = NULL;
		gint _tmp2_;
		_tmp1_ = gtk_tree_path_to_string (self->priv->_current);
		_tmp2_ = atoi (_tmp1_);
		_tmp0_ = _tmp2_ == (self->priv->_match_count - 1);
	}
	if (_tmp0_) {
		GtkTreePath* _tmp3_ = NULL;
		_tmp3_ = gtk_tree_path_new_first ();
		_gtk_tree_path_free0 (self->priv->_current);
		self->priv->_current = _tmp3_;
	} else {
		gtk_tree_path_next (self->priv->_current);
	}
	vtg_project_search_results_view_activate_path (self, self->priv->_current);
	gtk_tree_view_scroll_to_cell (self->priv->_results_view, self->priv->_current, NULL, FALSE, (gfloat) 0, (gfloat) 0);
	_tmp4_ = gtk_tree_view_get_selection (self->priv->_results_view);
	gtk_tree_selection_select_path (_tmp4_, self->priv->_current);
}


void vtg_project_search_results_view_previous_match (VtgProjectSearchResultsView* self) {
	gboolean _tmp0_ = FALSE;
	GtkTreeSelection* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	if (self->priv->_match_count == 0) {
		return;
	}
	if (self->priv->_current == NULL) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp1_;
		_tmp1_ = gtk_tree_path_prev (self->priv->_current);
		_tmp0_ = !_tmp1_;
	}
	if (_tmp0_) {
		GtkTreePath* _tmp2_ = NULL;
		_tmp2_ = gtk_tree_path_new_from_indices (self->priv->_match_count - 1, -1);
		_gtk_tree_path_free0 (self->priv->_current);
		self->priv->_current = _tmp2_;
	}
	vtg_project_search_results_view_activate_path (self, self->priv->_current);
	gtk_tree_view_scroll_to_cell (self->priv->_results_view, self->priv->_current, NULL, FALSE, (gfloat) 0, (gfloat) 0);
	_tmp3_ = gtk_tree_view_get_selection (self->priv->_results_view);
	gtk_tree_selection_select_path (_tmp3_, self->priv->_current);
}


static void vtg_project_search_results_view_add_message (VtgProjectSearchResultsView* self, const gchar* file, const gchar* message) {
	gchar** _tmp0_;
	gchar** _tmp1_ = NULL;
	gchar** lines;
	gint lines_length1;
	gint _lines_size_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file != NULL);
	g_return_if_fail (message != NULL);
	_tmp1_ = _tmp0_ = g_strsplit (message, "\n", 0);
	lines = _tmp1_;
	lines_length1 = _vala_array_length (_tmp0_);
	_lines_size_ = _vala_array_length (_tmp0_);
	{
		gchar** line_collection;
		int line_collection_length1;
		int line_it;
		line_collection = lines;
		line_collection_length1 = lines_length1;
		for (line_it = 0; line_it < lines_length1; line_it = line_it + 1) {
			gchar* _tmp2_;
			gchar* line;
			_tmp2_ = g_strdup (line_collection[line_it]);
			line = _tmp2_;
			{
				gboolean _tmp3_;
				gchar** _tmp4_;
				gchar** _tmp5_ = NULL;
				gchar** parts;
				gint parts_length1;
				gint _parts_size_;
				gboolean _tmp6_ = FALSE;
				_tmp3_ = vtg_string_utils_is_null_or_empty (line);
				if (_tmp3_) {
					_g_free0 (line);
					continue;
				}
				_tmp5_ = _tmp4_ = g_strsplit (line, ":", 2);
				parts = _tmp5_;
				parts_length1 = _vala_array_length (_tmp4_);
				_parts_size_ = _vala_array_length (_tmp4_);
				if (parts[0] != NULL) {
					_tmp6_ = parts_length1 > 1;
				} else {
					_tmp6_ = FALSE;
				}
				if (_tmp6_) {
					gint _tmp7_;
					gint line_number;
					const gchar* _tmp8_ = NULL;
					gchar* _tmp9_;
					gchar* text;
					GtkTreeIter iter = {0};
					GtkTreeIter _tmp10_ = {0};
					_tmp7_ = atoi (parts[0]);
					line_number = _tmp7_;
					_tmp8_ = pango_trim_string (parts[1]);
					_tmp9_ = g_strdup (_tmp8_);
					text = _tmp9_;
					gtk_list_store_append (self->priv->_model, &_tmp10_);
					iter = _tmp10_;
					gtk_list_store_set (self->priv->_model, &iter, 0, file, 1, line_number, 2, text, 3, self->priv->_project, -1);
					self->priv->_match_count++;
					_g_free0 (text);
				}
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (line);
			}
		}
	}
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
}


static void vtg_project_search_results_view_class_init (VtgProjectSearchResultsViewClass * klass) {
	vtg_project_search_results_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (VtgProjectSearchResultsViewPrivate));
	G_OBJECT_CLASS (klass)->finalize = vtg_project_search_results_view_finalize;
}


static void vtg_project_search_results_view_instance_init (VtgProjectSearchResultsView * self) {
	self->priv = VTG_PROJECT_SEARCH_RESULTS_VIEW_GET_PRIVATE (self);
	self->priv->_model = NULL;
	self->priv->_results_view = NULL;
	self->priv->_current = NULL;
	self->priv->_match_count = 0;
	self->priv->_plugin_instance = NULL;
}


static void vtg_project_search_results_view_finalize (GObject* obj) {
	VtgProjectSearchResultsView * self;
	GeditWindow* _tmp0_ = NULL;
	GeditPanel* _tmp1_ = NULL;
	GeditPanel* _tmp2_;
	GeditPanel* panel;
	self = VTG_PROJECT_SEARCH_RESULTS_VIEW (obj);
	_tmp0_ = vtg_plugin_instance_get_window (self->priv->_plugin_instance);
	_tmp1_ = gedit_window_get_bottom_panel (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	panel = _tmp2_;
	gedit_panel_remove_item (panel, (GtkWidget*) self->priv->_ui);
	_g_object_unref0 (panel);
	_g_object_unref0 (self->priv->_ui);
	_g_object_unref0 (self->priv->_model);
	_g_object_unref0 (self->priv->_results_view);
	_gtk_tree_path_free0 (self->priv->_current);
	G_OBJECT_CLASS (vtg_project_search_results_view_parent_class)->finalize (obj);
}


GType vtg_project_search_results_view_get_type (void) {
	return vtg_project_search_results_view_type_id;
}


GType vtg_project_search_results_view_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (VtgProjectSearchResultsViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vtg_project_search_results_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (VtgProjectSearchResultsView), 0, (GInstanceInitFunc) vtg_project_search_results_view_instance_init, NULL };
	vtg_project_search_results_view_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "VtgProjectSearchResultsView", &g_define_type_info, 0);
	return vtg_project_search_results_view_type_id;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


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



