25
25
History *history_new (gint max)
27
History *history = g_new (History, 1);
32
history->lock = FALSE;
27
History *history = g_new (History, 1);
32
history->lock = FALSE;
38
38
void history_free (History *history)
40
g_return_if_fail (history != NULL);
43
g_list_foreach (history->ents, (GFunc)g_free, NULL);
44
g_list_free (history->ents);
40
g_return_if_fail (history != NULL);
43
g_list_foreach (history->ents, (GFunc)g_free, NULL);
44
g_list_free (history->ents);
51
51
void history_add (History *history, const gchar *text)
55
g_return_if_fail (history != NULL);
57
if (history->lock) return;
59
/* If we are in the middle of the history list, lets kill
60
all items that are in front of us */
62
while (l && l != history->pos) {
64
n = g_list_remove_link (l, l);
69
history->ents = string_history_add (l, text, history->max);
70
history->pos = history->ents;
55
g_return_if_fail (history != NULL);
57
if (history->lock) return;
59
/* If we are in the middle of the history list, lets kill
60
all items that are in front of us */
62
while (l && l != history->pos) {
64
n = g_list_remove_link (l, l);
69
history->ents = string_history_add (l, text, history->max);
70
history->pos = history->ents;
74
74
gboolean history_can_back (History *history)
76
g_return_val_if_fail (history != NULL, FALSE);
77
g_return_val_if_fail (history->pos != NULL, FALSE);
79
return (history->pos->next != NULL);
76
g_return_val_if_fail (history != NULL, FALSE);
77
g_return_val_if_fail (history->pos != NULL, FALSE);
79
return (history->pos->next != NULL);
83
83
gboolean history_can_forward (History *history)
85
g_return_val_if_fail (history != NULL, FALSE);
86
g_return_val_if_fail (history->pos != NULL, FALSE);
88
return (history->pos->prev != NULL);
85
g_return_val_if_fail (history != NULL, FALSE);
86
g_return_val_if_fail (history->pos != NULL, FALSE);
88
return (history->pos->prev != NULL);
92
const gchar *history_first (History *history)
94
g_return_val_if_fail (history != NULL, NULL);
95
g_return_val_if_fail (history->pos != NULL, NULL);
97
if (history->pos->next)
98
history->pos = g_list_last(history->pos);
100
return (const gchar*)history->pos->data;
92
104
const gchar *history_back (History *history)
94
g_return_val_if_fail (history != NULL, NULL);
95
g_return_val_if_fail (history->pos != NULL, NULL);
97
if (history->pos->next)
98
history->pos = history->pos->next;
100
return (const gchar*)history->pos->data;
106
g_return_val_if_fail (history != NULL, NULL);
107
g_return_val_if_fail (history->pos != NULL, NULL);
109
if (history->pos->next)
110
history->pos = history->pos->next;
112
return (const gchar*)history->pos->data;
104
116
const gchar *history_forward (History *history)
106
g_return_val_if_fail (history != NULL, NULL);
107
g_return_val_if_fail (history->pos != NULL, NULL);
109
if (history->pos->prev)
110
history->pos = history->pos->prev;
112
return (const gchar*)history->pos->data;
118
g_return_val_if_fail (history != NULL, NULL);
119
g_return_val_if_fail (history->pos != NULL, NULL);
121
if (history->pos->prev)
122
history->pos = history->pos->prev;
124
return (const gchar*)history->pos->data;
128
const gchar *history_last (History *history)
130
g_return_val_if_fail (history != NULL, NULL);
131
g_return_val_if_fail (history->pos != NULL, NULL);
133
if (history->pos->prev)
134
history->pos = g_list_first(history->pos);
136
return (const gchar*)history->pos->data;