1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* Copyright (c) 2010-2013 Stefan Bolte <portix@gmx.net>
*
* 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 3 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <string.h>
#include "dwb.h"
#include "entry.h"
static char *s_store;
static GList *s_filterlist;
/* dwb_entry_history_forward {{{*/
DwbStatus
entry_history_forward(GList **last)
{
if (s_filterlist == NULL)
return STATUS_ERROR;
const char *text = NULL;
GList *prev = NULL;
if (*last != NULL)
{
if ((*last)->prev == NULL)
{
text = s_store;
GLIST_FREE0(s_filterlist);
}
else
{
prev = (*last)->prev;
text = prev->data;
}
}
*last = prev;
if (text != NULL)
entry_set_text(text);
return STATUS_OK;
}/*}}}*/
/* entry_history_back(GList **list, GList **last) {{{ */
DwbStatus
entry_history_back(GList **list, GList **last)
{
char *text = NULL;
if (*list == NULL)
return STATUS_ERROR;
GList *next;
if (*last == NULL)
{
const char *text = GET_TEXT();
if (text && *text) {
for (GList *l = *list; l; l=l->next)
{
if (strstr(l->data, text)) {
s_filterlist = g_list_prepend(s_filterlist, l->data);
}
}
if (s_filterlist)
s_filterlist = g_list_reverse(s_filterlist);
}
else
s_filterlist = g_list_copy(*list);
next = s_filterlist;
s_store = g_strdup(text);
}
else if ((*last)->next != NULL)
next = (*last)->next;
else
return STATUS_OK;
*last = next;
if (next)
text = next->data;
if (text && *text)
{
entry_set_text(text);
}
return STATUS_OK;
} /* }}} */
/* entry_focus() {{{*/
void
entry_focus()
{
if (! (dwb.state.bar_visible & BAR_VIS_STATUS))
gtk_widget_show_all(dwb.gui.bottombox);
gtk_widget_show(dwb.gui.entry);
gtk_widget_grab_focus(dwb.gui.entry);
gtk_widget_set_can_focus(CURRENT_WEBVIEW_WIDGET(), false);
gtk_editable_delete_text(GTK_EDITABLE(dwb.gui.entry), 0, -1);
}/*}}}*/
void
entry_clear_history()
{
dwb.state.last_com_history = NULL;
dwb.state.last_nav_history = NULL;
dwb.state.last_find_history = NULL;
FREE0(s_store);
GLIST_FREE0(s_filterlist);
}
void
entry_hide()
{
gtk_widget_hide(dwb.gui.entry);
entry_clear_history();
}
/* entry_insert_text(const char *) {{{*/
void
entry_insert_text(const char *text)
{
int position = gtk_editable_get_position(GTK_EDITABLE(dwb.gui.entry));
gtk_editable_insert_text(GTK_EDITABLE(dwb.gui.entry), text, -1, &position);
gtk_editable_set_position(GTK_EDITABLE(dwb.gui.entry), position);
}/*}}}*/
/* entry_set_text(const char *) {{{*/
void
entry_set_text(const char *text)
{
gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), text);
gtk_editable_set_position(GTK_EDITABLE(dwb.gui.entry), -1);
}/*}}}*/
/* entry_move_cursor_step(GtkMovementStep, int step, gboolean delete) {{{*/
void
entry_move_cursor_step(GtkMovementStep step, int stepcount, gboolean del)
{
g_signal_emit_by_name(dwb.gui.entry, "move-cursor", step, stepcount, del);
if (del)
gtk_editable_delete_selection(GTK_EDITABLE(dwb.gui.entry));
}/*}}}*/
|