/* gitg-entry-history.c generated by valac 0.56.19, the Vala compiler
 * generated from gitg-entry-history.vala, do not modify */

/*
 * This file is part of gitg
 *
 * Copyright (C) 2026 - Alberto Fanjul
 *
 * gitg 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.
 *
 * gitg 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 gitg. If not, see <http://www.gnu.org/licenses/>.
 */

#include "libgitg.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
#include <stdio.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

enum  {
	GITG_ENTRY_HISTORY_0_PROPERTY,
	GITG_ENTRY_HISTORY_NUM_PROPERTIES
};
static GParamSpec* gitg_entry_history_properties[GITG_ENTRY_HISTORY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
enum  {
	GITG_ENTRY_HISTORY_ACTIVATED_WITH_TEXT_SIGNAL,
	GITG_ENTRY_HISTORY_NUM_SIGNALS
};
static guint gitg_entry_history_signals[GITG_ENTRY_HISTORY_NUM_SIGNALS] = {0};

struct _GitgEntryHistoryPrivate {
	GeeArrayList* history;
	gint history_position;
	gchar* current_text;
	gchar* history_file;
	GtkListStore* completion_store;
};

static gint GitgEntryHistory_private_offset;
static gpointer gitg_entry_history_parent_class = NULL;

static void gitg_entry_history_load_history (GitgEntryHistory* self);
static void gitg_entry_history_setup_completion (GitgEntryHistory* self);
static void gitg_entry_history_on_activate (GitgEntryHistory* self);
static void _gitg_entry_history_on_activate_gtk_entry_activate (GtkEntry* _sender,
                                                         gpointer self);
static gboolean gitg_entry_history_on_key_press (GitgEntryHistory* self,
                                          GdkEventKey* event);
static gboolean _gitg_entry_history_on_key_press_gtk_widget_key_press_event (GtkWidget* _sender,
                                                                      GdkEventKey* event,
                                                                      gpointer self);
static void gitg_entry_history_update_completion (GitgEntryHistory* self);
static void gitg_entry_history_save_history (GitgEntryHistory* self);
static void gitg_entry_history_navigate_history_up (GitgEntryHistory* self);
static void gitg_entry_history_navigate_history_down (GitgEntryHistory* self);
static void gitg_entry_history_finalize (GObject * obj);
static GType gitg_entry_history_get_type_once (void);

static inline gpointer
gitg_entry_history_get_instance_private (GitgEntryHistory* self)
{
	return G_STRUCT_MEMBER_P (self, GitgEntryHistory_private_offset);
}

static void
_gitg_entry_history_on_activate_gtk_entry_activate (GtkEntry* _sender,
                                                    gpointer self)
{
	gitg_entry_history_on_activate ((GitgEntryHistory*) self);
}

static gboolean
_gitg_entry_history_on_key_press_gtk_widget_key_press_event (GtkWidget* _sender,
                                                             GdkEventKey* event,
                                                             gpointer self)
{
	gboolean result;
	result = gitg_entry_history_on_key_press ((GitgEntryHistory*) self, event);
	return result;
}

GitgEntryHistory*
gitg_entry_history_construct (GType object_type,
                              const gchar* history_file_path)
{
	GitgEntryHistory * self = NULL;
	GeeArrayList* _tmp0_;
	gchar* _tmp1_;
	self = (GitgEntryHistory*) g_object_new (object_type, NULL);
	_tmp0_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->history);
	self->priv->history = _tmp0_;
	self->priv->history_position = -1;
	_tmp1_ = g_strdup ("");
	_g_free0 (self->priv->current_text);
	self->priv->current_text = _tmp1_;
	if (history_file_path != NULL) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (history_file_path);
		_g_free0 (self->priv->history_file);
		self->priv->history_file = _tmp2_;
	} else {
		const gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = g_get_user_cache_dir ();
		_tmp4_ = g_build_filename (_tmp3_, "gtk_entry_history.txt", NULL);
		_g_free0 (self->priv->history_file);
		self->priv->history_file = _tmp4_;
	}
	gitg_entry_history_load_history (self);
	gitg_entry_history_setup_completion (self);
	g_signal_connect_object ((GtkEntry*) self, "activate", (GCallback) _gitg_entry_history_on_activate_gtk_entry_activate, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "key-press-event", (GCallback) _gitg_entry_history_on_key_press_gtk_widget_key_press_event, self, 0);
	return self;
}

GitgEntryHistory*
gitg_entry_history_new (const gchar* history_file_path)
{
	return gitg_entry_history_construct (GITG_TYPE_ENTRY_HISTORY, history_file_path);
}

static void
gitg_entry_history_setup_completion (GitgEntryHistory* self)
{
	GtkEntryCompletion* completion = NULL;
	GtkEntryCompletion* _tmp0_;
	GtkListStore* _tmp1_;
	GtkListStore* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_entry_completion_new ();
	completion = _tmp0_;
	_tmp1_ = gtk_list_store_new (1, G_TYPE_STRING, -1);
	_g_object_unref0 (self->priv->completion_store);
	self->priv->completion_store = _tmp1_;
	_tmp2_ = self->priv->completion_store;
	gtk_entry_completion_set_model (completion, (GtkTreeModel*) _tmp2_);
	gtk_entry_completion_set_text_column (completion, 0);
	gtk_entry_completion_set_inline_completion (completion, TRUE);
	gtk_entry_completion_set_inline_selection (completion, TRUE);
	gtk_entry_completion_set_popup_completion (completion, TRUE);
	gtk_entry_completion_set_popup_single_match (completion, FALSE);
	gtk_entry_set_completion ((GtkEntry*) self, completion);
	gitg_entry_history_update_completion (self);
	_g_object_unref0 (completion);
}

static void
gitg_entry_history_update_completion (GitgEntryHistory* self)
{
	GtkListStore* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->completion_store;
	gtk_list_store_clear (_tmp0_);
	{
		GeeArrayList* _item_list = NULL;
		GeeArrayList* _tmp1_;
		gint _item_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _item_index = 0;
		_tmp1_ = self->priv->history;
		_item_list = _tmp1_;
		_tmp2_ = _item_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_item_size = _tmp4_;
		_item_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			gchar* item = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			GtkTreeIter iter = {0};
			GtkListStore* _tmp9_;
			GtkTreeIter _tmp10_ = {0};
			GtkListStore* _tmp11_;
			GtkTreeIter _tmp12_;
			const gchar* _tmp13_;
			_item_index = _item_index + 1;
			_tmp5_ = _item_index;
			_tmp6_ = _item_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _item_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _item_index);
			item = (gchar*) _tmp8_;
			_tmp9_ = self->priv->completion_store;
			gtk_list_store_append (_tmp9_, &_tmp10_);
			iter = _tmp10_;
			_tmp11_ = self->priv->completion_store;
			_tmp12_ = iter;
			_tmp13_ = item;
			gtk_list_store_set (_tmp11_, &_tmp12_, 0, _tmp13_, -1);
			_g_free0 (item);
		}
	}
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static void
gitg_entry_history_load_history (GitgEntryHistory* self)
{
	GeeArrayList* _tmp0_;
	GFile* file = NULL;
	const gchar* _tmp1_;
	GFile* _tmp2_;
	GFile* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->history;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
	_tmp1_ = self->priv->history_file;
	_tmp2_ = g_file_new_for_path (_tmp1_);
	file = _tmp2_;
	_tmp3_ = file;
	if (!g_file_query_exists (_tmp3_, NULL)) {
		_g_object_unref0 (file);
		return;
	}
	{
		GFileInputStream* _tmp4_ = NULL;
		GFile* _tmp5_;
		GFileInputStream* _tmp6_;
		GDataInputStream* dis = NULL;
		GDataInputStream* _tmp7_;
		gchar* line = NULL;
		_tmp5_ = file;
		_tmp6_ = g_file_read (_tmp5_, NULL, &_inner_error0_);
		_tmp4_ = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp7_ = g_data_input_stream_new ((GInputStream*) _tmp4_);
		dis = _tmp7_;
		while (TRUE) {
			gchar* _tmp8_ = NULL;
			GDataInputStream* _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			const gchar* _tmp12_;
			const gchar* _tmp13_;
			gchar* _tmp14_;
			const gchar* _tmp15_;
			gint _tmp16_;
			gint _tmp17_;
			_tmp9_ = dis;
			_tmp10_ = g_data_input_stream_read_line (_tmp9_, NULL, NULL, &_inner_error0_);
			_tmp8_ = _tmp10_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_free0 (line);
				_g_object_unref0 (dis);
				_g_object_unref0 (_tmp4_);
				goto __catch0_g_error;
			}
			_tmp11_ = _tmp8_;
			_tmp8_ = NULL;
			_g_free0 (line);
			line = _tmp11_;
			_tmp12_ = line;
			if (!(_tmp12_ != NULL)) {
				_g_free0 (_tmp8_);
				break;
			}
			_tmp13_ = line;
			_tmp14_ = string_strip (_tmp13_);
			_g_free0 (line);
			line = _tmp14_;
			_tmp15_ = line;
			_tmp16_ = strlen (_tmp15_);
			_tmp17_ = _tmp16_;
			if (_tmp17_ > 0) {
				GeeArrayList* _tmp18_;
				const gchar* _tmp19_;
				_tmp18_ = self->priv->history;
				_tmp19_ = line;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp18_, _tmp19_);
			}
			_g_free0 (_tmp8_);
		}
		_g_free0 (line);
		_g_object_unref0 (dis);
		_g_object_unref0 (_tmp4_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		FILE* _tmp20_;
		GError* _tmp21_;
		const gchar* _tmp22_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp20_ = stderr;
		_tmp21_ = e;
		_tmp22_ = _tmp21_->message;
		fprintf (_tmp20_, "Error loading history: %s\n", _tmp22_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_object_unref0 (file);
}

static void
gitg_entry_history_save_history (GitgEntryHistory* self)
{
	GFile* file = NULL;
	const gchar* _tmp0_;
	GFile* _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->history_file;
	_tmp1_ = g_file_new_for_path (_tmp0_);
	file = _tmp1_;
	{
		GFile* parent = NULL;
		GFile* _tmp2_;
		GFile* _tmp3_;
		gboolean _tmp4_ = FALSE;
		GFile* _tmp5_;
		GFileOutputStream* _tmp8_ = NULL;
		GFile* _tmp9_;
		GFileOutputStream* _tmp10_;
		GDataOutputStream* dos = NULL;
		GDataOutputStream* _tmp11_;
		_tmp2_ = file;
		_tmp3_ = g_file_get_parent (_tmp2_);
		parent = _tmp3_;
		_tmp5_ = parent;
		if (_tmp5_ != NULL) {
			GFile* _tmp6_;
			_tmp6_ = parent;
			_tmp4_ = !g_file_query_exists (_tmp6_, NULL);
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			GFile* _tmp7_;
			_tmp7_ = parent;
			g_file_make_directory_with_parents (_tmp7_, NULL, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (parent);
				goto __catch0_g_error;
			}
		}
		_tmp9_ = file;
		_tmp10_ = g_file_replace (_tmp9_, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &_inner_error0_);
		_tmp8_ = _tmp10_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (parent);
			goto __catch0_g_error;
		}
		_tmp11_ = g_data_output_stream_new ((GOutputStream*) _tmp8_);
		dos = _tmp11_;
		{
			GeeArrayList* _item_list = NULL;
			GeeArrayList* _tmp12_;
			gint _item_size = 0;
			GeeArrayList* _tmp13_;
			gint _tmp14_;
			gint _tmp15_;
			gint _item_index = 0;
			_tmp12_ = self->priv->history;
			_item_list = _tmp12_;
			_tmp13_ = _item_list;
			_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
			_tmp15_ = _tmp14_;
			_item_size = _tmp15_;
			_item_index = -1;
			while (TRUE) {
				gint _tmp16_;
				gint _tmp17_;
				gchar* item = NULL;
				GeeArrayList* _tmp18_;
				gpointer _tmp19_;
				GDataOutputStream* _tmp20_;
				const gchar* _tmp21_;
				gchar* _tmp22_;
				gchar* _tmp23_;
				_item_index = _item_index + 1;
				_tmp16_ = _item_index;
				_tmp17_ = _item_size;
				if (!(_tmp16_ < _tmp17_)) {
					break;
				}
				_tmp18_ = _item_list;
				_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _item_index);
				item = (gchar*) _tmp19_;
				_tmp20_ = dos;
				_tmp21_ = item;
				_tmp22_ = g_strconcat (_tmp21_, "\n", NULL);
				_tmp23_ = _tmp22_;
				g_data_output_stream_put_string (_tmp20_, _tmp23_, NULL, &_inner_error0_);
				_g_free0 (_tmp23_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_free0 (item);
					_g_object_unref0 (dos);
					_g_object_unref0 (_tmp8_);
					_g_object_unref0 (parent);
					goto __catch0_g_error;
				}
				_g_free0 (item);
			}
		}
		_g_object_unref0 (dos);
		_g_object_unref0 (_tmp8_);
		_g_object_unref0 (parent);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		FILE* _tmp24_;
		GError* _tmp25_;
		const gchar* _tmp26_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp24_ = stderr;
		_tmp25_ = e;
		_tmp26_ = _tmp25_->message;
		fprintf (_tmp24_, "Error saving history: %s\n", _tmp26_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_g_object_unref0 (file);
}

static void
gitg_entry_history_on_activate (GitgEntryHistory* self)
{
	gchar* text = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	gboolean _tmp6_ = FALSE;
	GeeArrayList* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	gchar* _tmp27_;
	const gchar* _tmp28_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_entry_get_text ((GtkEntry*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = string_strip (_tmp1_);
	text = _tmp2_;
	_tmp3_ = text;
	_tmp4_ = strlen (_tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == 0) {
		_g_free0 (text);
		return;
	}
	_tmp7_ = self->priv->history;
	_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_ == 0) {
		_tmp6_ = TRUE;
	} else {
		GeeArrayList* _tmp10_;
		GeeArrayList* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gpointer _tmp14_;
		gchar* _tmp15_;
		const gchar* _tmp16_;
		_tmp10_ = self->priv->history;
		_tmp11_ = self->priv->history;
		_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _tmp13_ - 1);
		_tmp15_ = (gchar*) _tmp14_;
		_tmp16_ = text;
		_tmp6_ = g_strcmp0 (_tmp15_, _tmp16_) != 0;
		_g_free0 (_tmp15_);
	}
	if (_tmp6_) {
		GeeArrayList* _tmp17_;
		const gchar* _tmp18_;
		GeeArrayList* _tmp19_;
		const gchar* _tmp20_;
		_tmp17_ = self->priv->history;
		_tmp18_ = text;
		gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp17_, _tmp18_);
		_tmp19_ = self->priv->history;
		_tmp20_ = text;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp19_, _tmp20_);
		while (TRUE) {
			GeeArrayList* _tmp21_;
			gint _tmp22_;
			gint _tmp23_;
			GeeArrayList* _tmp24_;
			gpointer _tmp25_;
			gchar* _tmp26_;
			_tmp21_ = self->priv->history;
			_tmp22_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp21_);
			_tmp23_ = _tmp22_;
			if (!(_tmp23_ > 1000)) {
				break;
			}
			_tmp24_ = self->priv->history;
			_tmp25_ = gee_abstract_list_remove_at ((GeeAbstractList*) _tmp24_, 0);
			_tmp26_ = (gchar*) _tmp25_;
			_g_free0 (_tmp26_);
		}
		gitg_entry_history_save_history (self);
		gitg_entry_history_update_completion (self);
	}
	self->priv->history_position = -1;
	_tmp27_ = g_strdup ("");
	_g_free0 (self->priv->current_text);
	self->priv->current_text = _tmp27_;
	_tmp28_ = text;
	g_signal_emit (self, gitg_entry_history_signals[GITG_ENTRY_HISTORY_ACTIVATED_WITH_TEXT_SIGNAL], 0, _tmp28_);
	_g_free0 (text);
}

static gboolean
gitg_entry_history_on_key_press (GitgEntryHistory* self,
                                 GdkEventKey* event)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (event != NULL, FALSE);
	if (event->keyval == GDK_KEY_Up) {
		gitg_entry_history_navigate_history_up (self);
		result = TRUE;
		return result;
	}
	if (event->keyval == GDK_KEY_Down) {
		gitg_entry_history_navigate_history_down (self);
		result = TRUE;
		return result;
	}
	if (event->keyval != GDK_KEY_Up) {
		_tmp1_ = event->keyval != GDK_KEY_Down;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_tmp0_ = event->keyval != GDK_KEY_Return;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		self->priv->history_position = -1;
	}
	result = FALSE;
	return result;
}

static void
gitg_entry_history_navigate_history_up (GitgEntryHistory* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->history;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		return;
	}
	if (self->priv->history_position == -1) {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		GeeArrayList* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		_tmp3_ = gtk_entry_get_text ((GtkEntry*) self);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_strdup (_tmp4_);
		_g_free0 (self->priv->current_text);
		self->priv->current_text = _tmp5_;
		_tmp6_ = self->priv->history;
		_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
		_tmp8_ = _tmp7_;
		self->priv->history_position = _tmp8_;
	}
	if (self->priv->history_position > 0) {
		gint _tmp9_;
		GeeArrayList* _tmp10_;
		gpointer _tmp11_;
		gchar* _tmp12_;
		_tmp9_ = self->priv->history_position;
		self->priv->history_position = _tmp9_ - 1;
		_tmp10_ = self->priv->history;
		_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, self->priv->history_position);
		_tmp12_ = (gchar*) _tmp11_;
		gtk_entry_set_text ((GtkEntry*) self, _tmp12_);
		_g_free0 (_tmp12_);
		gtk_editable_set_position ((GtkEditable*) self, -1);
	}
}

static void
gitg_entry_history_navigate_history_down (GitgEntryHistory* self)
{
	gboolean _tmp0_ = FALSE;
	GeeArrayList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	GeeArrayList* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->history;
	_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == 0) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->history_position == -1;
	}
	if (_tmp0_) {
		return;
	}
	_tmp4_ = self->priv->history_position;
	self->priv->history_position = _tmp4_ + 1;
	_tmp5_ = self->priv->history;
	_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
	_tmp7_ = _tmp6_;
	if (self->priv->history_position >= _tmp7_) {
		const gchar* _tmp8_;
		_tmp8_ = self->priv->current_text;
		gtk_entry_set_text ((GtkEntry*) self, _tmp8_);
		self->priv->history_position = -1;
	} else {
		GeeArrayList* _tmp9_;
		gpointer _tmp10_;
		gchar* _tmp11_;
		_tmp9_ = self->priv->history;
		_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, self->priv->history_position);
		_tmp11_ = (gchar*) _tmp10_;
		gtk_entry_set_text ((GtkEntry*) self, _tmp11_);
		_g_free0 (_tmp11_);
	}
	gtk_editable_set_position ((GtkEditable*) self, -1);
}

void
gitg_entry_history_clear_history (GitgEntryHistory* self)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->history;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
	gitg_entry_history_save_history (self);
	gitg_entry_history_update_completion (self);
}

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

GeeArrayList*
gitg_entry_history_get_history (GitgEntryHistory* self)
{
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->history;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static void
gitg_entry_history_class_init (GitgEntryHistoryClass * klass,
                               gpointer klass_data)
{
	gitg_entry_history_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GitgEntryHistory_private_offset);
	G_OBJECT_CLASS (klass)->finalize = gitg_entry_history_finalize;
	gitg_entry_history_signals[GITG_ENTRY_HISTORY_ACTIVATED_WITH_TEXT_SIGNAL] = g_signal_new ("activated-with-text", GITG_TYPE_ENTRY_HISTORY, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
gitg_entry_history_instance_init (GitgEntryHistory * self,
                                  gpointer klass)
{
	self->priv = gitg_entry_history_get_instance_private (self);
}

static void
gitg_entry_history_finalize (GObject * obj)
{
	GitgEntryHistory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GITG_TYPE_ENTRY_HISTORY, GitgEntryHistory);
	_g_object_unref0 (self->priv->history);
	_g_free0 (self->priv->current_text);
	_g_free0 (self->priv->history_file);
	_g_object_unref0 (self->priv->completion_store);
	G_OBJECT_CLASS (gitg_entry_history_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gitg_entry_history_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GitgEntryHistoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gitg_entry_history_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GitgEntryHistory), 0, (GInstanceInitFunc) gitg_entry_history_instance_init, NULL };
	GType gitg_entry_history_type_id;
	gitg_entry_history_type_id = g_type_register_static (gtk_entry_get_type (), "GitgEntryHistory", &g_define_type_info, 0);
	GitgEntryHistory_private_offset = g_type_add_instance_private (gitg_entry_history_type_id, sizeof (GitgEntryHistoryPrivate));
	return gitg_entry_history_type_id;
}

GType
gitg_entry_history_get_type (void)
{
	static gsize gitg_entry_history_type_id__once = 0;
	if (g_once_init_enter (&gitg_entry_history_type_id__once)) {
		GType gitg_entry_history_type_id;
		gitg_entry_history_type_id = gitg_entry_history_get_type_once ();
		g_once_init_leave (&gitg_entry_history_type_id__once, gitg_entry_history_type_id);
	}
	return gitg_entry_history_type_id__once;
}

