mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-20 11:12:46 +03:00
fix url enttry completion
This commit is contained in:
parent
869c16dae6
commit
8b5100a97e
@ -37,6 +37,18 @@
|
|||||||
|
|
||||||
GtkListStore *nsgtk_completion_list;
|
GtkListStore *nsgtk_completion_list;
|
||||||
|
|
||||||
|
struct nsgtk_completion_ctx {
|
||||||
|
/**
|
||||||
|
* callback to obtain a browser window for navigation
|
||||||
|
*/
|
||||||
|
struct browser_window *(*get_bw)(void *ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* context passed to get_bw function
|
||||||
|
*/
|
||||||
|
void *get_bw_ctx;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* completion row matcher
|
* completion row matcher
|
||||||
*/
|
*/
|
||||||
@ -50,7 +62,6 @@ static gboolean nsgtk_completion_match(GtkEntryCompletion *completion,
|
|||||||
* are in the list should be shown.
|
* are in the list should be shown.
|
||||||
*/
|
*/
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -77,14 +88,17 @@ static gboolean
|
|||||||
nsgtk_completion_match_select(GtkEntryCompletion *widget,
|
nsgtk_completion_match_select(GtkEntryCompletion *widget,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gpointer user_data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
|
struct nsgtk_completion_ctx *cb_ctx;
|
||||||
GValue value = G_VALUE_INIT;
|
GValue value = G_VALUE_INIT;
|
||||||
struct nsgtk_scaffolding *g = user_data;
|
struct browser_window *bw;
|
||||||
struct browser_window *bw = nsgtk_get_browser_window(nsgtk_scaffolding_top_level(g));
|
|
||||||
nserror ret;
|
nserror ret;
|
||||||
nsurl *url;
|
nsurl *url;
|
||||||
|
|
||||||
|
cb_ctx = data;
|
||||||
|
bw = cb_ctx->get_bw(cb_ctx->get_bw_ctx);
|
||||||
|
|
||||||
gtk_tree_model_get_value(model, iter, 0, &value);
|
gtk_tree_model_get_value(model, iter, 0, &value);
|
||||||
|
|
||||||
ret = search_web_omni(g_value_get_string(&value),
|
ret = search_web_omni(g_value_get_string(&value),
|
||||||
@ -127,11 +141,20 @@ gboolean nsgtk_completion_update(GtkEntry *entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* exported interface documented in completion.h */
|
/* exported interface documented in completion.h */
|
||||||
GtkEntryCompletion *nsgtk_url_entry_completion_new(struct nsgtk_scaffolding *gs)
|
nserror
|
||||||
|
nsgtk_completion_connect_signals(GtkEntry *entry,
|
||||||
|
struct browser_window *(*get_bw)(void *ctx),
|
||||||
|
void *get_bw_ctx)
|
||||||
{
|
{
|
||||||
GtkEntryCompletion *completion;
|
GtkEntryCompletion *completion;
|
||||||
|
struct nsgtk_completion_ctx *cb_ctx;
|
||||||
|
|
||||||
|
cb_ctx = calloc(1, sizeof(struct nsgtk_completion_ctx));
|
||||||
|
cb_ctx->get_bw = get_bw;
|
||||||
|
cb_ctx->get_bw_ctx = get_bw_ctx;
|
||||||
|
|
||||||
|
completion = gtk_entry_get_completion(entry);
|
||||||
|
|
||||||
completion = gtk_entry_completion_new();
|
|
||||||
gtk_entry_completion_set_match_func(completion,
|
gtk_entry_completion_set_match_func(completion,
|
||||||
nsgtk_completion_match, NULL, NULL);
|
nsgtk_completion_match, NULL, NULL);
|
||||||
|
|
||||||
@ -146,13 +169,15 @@ GtkEntryCompletion *nsgtk_url_entry_completion_new(struct nsgtk_scaffolding *gs)
|
|||||||
gtk_entry_completion_set_popup_completion(completion, TRUE);
|
gtk_entry_completion_set_popup_completion(completion, TRUE);
|
||||||
|
|
||||||
/* when selected callback */
|
/* when selected callback */
|
||||||
g_signal_connect(G_OBJECT(completion), "match-selected",
|
g_signal_connect(G_OBJECT(completion),
|
||||||
G_CALLBACK(nsgtk_completion_match_select), gs);
|
"match-selected",
|
||||||
|
G_CALLBACK(nsgtk_completion_match_select),
|
||||||
|
cb_ctx);
|
||||||
|
|
||||||
g_object_set(G_OBJECT(completion),
|
g_object_set(G_OBJECT(completion),
|
||||||
"popup-set-width", TRUE,
|
"popup-set-width", TRUE,
|
||||||
"popup-single-match", TRUE,
|
"popup-single-match", TRUE,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return completion;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,11 @@ void nsgtk_completion_init(void);
|
|||||||
gboolean nsgtk_completion_update(GtkEntry *entry);
|
gboolean nsgtk_completion_update(GtkEntry *entry);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a new entry completion on a scaffold.
|
* connect signals on entry completion
|
||||||
*
|
|
||||||
* \param gs The scaffoliding which the url entry is in.
|
|
||||||
*/
|
*/
|
||||||
GtkEntryCompletion *nsgtk_url_entry_completion_new(struct nsgtk_scaffolding *gs);
|
nserror
|
||||||
|
nsgtk_completion_connect_signals(GtkEntry *entry,
|
||||||
|
struct browser_window *(*get_bw)(void *ctx),
|
||||||
|
void *get_bw_ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,6 +105,10 @@ struct nsgtk_toolbar {
|
|||||||
* callback to obtain a browser window for navigation
|
* callback to obtain a browser window for navigation
|
||||||
*/
|
*/
|
||||||
struct browser_window *(*get_bw)(void *ctx);
|
struct browser_window *(*get_bw)(void *ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* context passed to get_bw function
|
||||||
|
*/
|
||||||
void *get_bw_ctx;
|
void *get_bw_ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -577,14 +581,20 @@ make_toolbar_item(nsgtk_toolbar_button i, struct nsgtk_theme *theme)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case URL_BAR_ITEM: {
|
case URL_BAR_ITEM: {
|
||||||
GtkWidget *entry = nsgtk_entry_new();
|
/* create a gtk entry widget with a completion attached */
|
||||||
w = GTK_WIDGET(gtk_tool_item_new());
|
GtkWidget *entry;
|
||||||
|
GtkEntryCompletion *completion;
|
||||||
|
|
||||||
if ((entry == NULL) || (w == NULL)) {
|
w = GTK_WIDGET(gtk_tool_item_new());
|
||||||
|
entry = nsgtk_entry_new();
|
||||||
|
completion = gtk_entry_completion_new();
|
||||||
|
|
||||||
|
if ((entry == NULL) || (completion == NULL) || (w == NULL)) {
|
||||||
nsgtk_warning(messages_get("NoMemory"), 0);
|
nsgtk_warning(messages_get("NoMemory"), 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_entry_set_completion(entry, completion);
|
||||||
gtk_container_add(GTK_CONTAINER(w), entry);
|
gtk_container_add(GTK_CONTAINER(w), entry);
|
||||||
gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE);
|
gtk_tool_item_set_expand(GTK_TOOL_ITEM(w), TRUE);
|
||||||
break;
|
break;
|
||||||
@ -1906,9 +1916,13 @@ toolbar_connect_signal(struct nsgtk_toolbar *tb, nsgtk_toolbar_button itemid)
|
|||||||
"changed",
|
"changed",
|
||||||
G_CALLBACK(url_entry_changed_cb),
|
G_CALLBACK(url_entry_changed_cb),
|
||||||
tb);
|
tb);
|
||||||
}
|
|
||||||
|
nsgtk_completion_connect_signals(url_entry,
|
||||||
|
tb->get_bw,
|
||||||
|
tb->get_bw_ctx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NSERROR_OK;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
@ -1996,10 +2010,6 @@ nsgtk_toolbar_create(GtkBuilder *builder,
|
|||||||
/* set the throbber start frame. */
|
/* set the throbber start frame. */
|
||||||
tb->throb_frame = 0;
|
tb->throb_frame = 0;
|
||||||
|
|
||||||
/* set up URL bar completion */
|
|
||||||
/** \todo sort out completion */
|
|
||||||
//tb->url_bar_completion = nsgtk_url_entry_completion_new(gs);
|
|
||||||
|
|
||||||
res = toolbar_connect_signals(tb);
|
res = toolbar_connect_signals(tb);
|
||||||
if (res != NSERROR_OK) {
|
if (res != NSERROR_OK) {
|
||||||
free(tb);
|
free(tb);
|
||||||
|
Loading…
Reference in New Issue
Block a user