/* exported interface documented in completion.h */ GtkEntryCompletion *nsgtk_url_entry_completion_new(struct nsgtk_scaffolding *gs) { GtkEntryCompletion *completion; completion = gtk_entry_completion_new(); gtk_entry_completion_set_match_func(completion, nsgtk_completion_match, NULL, NULL); gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(nsgtk_completion_list)); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_minimum_key_length(completion, 1); /* enable popup for completion */ gtk_entry_completion_set_popup_completion(completion, TRUE); /* when selected callback */ g_signal_connect(G_OBJECT(completion), "match-selected", G_CALLBACK(nsgtk_completion_match_select), gs); g_object_set(G_OBJECT(completion), "popup-set-width", TRUE, "popup-single-match", TRUE, NULL); return completion; }
GtkWidget * terminal_search_dialog_new (GtkWindow *parent) { GtkWidget *dialog; TerminalSearchDialogPrivate *priv; GtkListStore *store; GtkEntryCompletion *completion; priv = g_new0 (TerminalSearchDialogPrivate, 1); if (!terminal_util_load_builder_file ("find-dialog.ui", "find-dialog", &dialog, "search-label", &priv->search_label, "search-entry", &priv->search_entry, "match-case-checkbutton", &priv->match_case_checkbutton, "entire-word-checkbutton", &priv->entire_word_checkbutton, "regex-checkbutton", &priv->regex_checkbutton, "search-backwards-checkbutton", &priv->backwards_checkbutton, "wrap-around-checkbutton", &priv->wrap_around_checkbutton, NULL)) { g_free (priv); return NULL; } g_object_set_qdata_full (G_OBJECT (dialog), get_quark (), priv, (GDestroyNotify) terminal_search_dialog_private_destroy); priv->search_text_entry = gtk_bin_get_child (GTK_BIN (priv->search_entry)); gtk_widget_set_size_request (priv->search_entry, 300, -1); priv->store = store = gtk_list_store_new (1, G_TYPE_STRING); g_object_set (G_OBJECT (priv->search_entry), "model", store, "text-column", 0, NULL); priv->completion = completion = gtk_entry_completion_new (); gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store)); gtk_entry_completion_set_text_column (completion, 0); gtk_entry_completion_set_minimum_key_length (completion, HISTORY_MIN_ITEM_LEN); gtk_entry_completion_set_popup_completion (completion, FALSE); gtk_entry_completion_set_inline_completion (completion, TRUE); gtk_entry_set_completion (GTK_ENTRY (priv->search_text_entry), completion); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE); gtk_entry_set_activates_default (GTK_ENTRY (priv->search_text_entry), TRUE); g_signal_connect (priv->search_text_entry, "changed", G_CALLBACK (update_sensitivity), dialog); g_signal_connect (priv->regex_checkbutton, "toggled", G_CALLBACK (update_sensitivity), dialog); g_signal_connect (dialog, "response", G_CALLBACK (response_handler), NULL); if (parent) gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); return GTK_WIDGET (dialog); }
static gboolean on_focus_in( GtkWidget *entry, GdkEventFocus* evt, gpointer user_data ) { GtkEntryCompletion* completion = gtk_entry_completion_new(); GtkListStore* list = gtk_list_store_new( COUNT_COLS, G_TYPE_STRING, G_TYPE_STRING ); GtkCellRenderer* render; gtk_entry_completion_set_minimum_key_length( completion, 1 ); gtk_entry_completion_set_model( completion, GTK_TREE_MODEL(list) ); g_object_unref( list ); // gtk_entry_completion_set_text_column( completion, COL_PATH ); // g_object_set( completion, "text-column", COL_PATH, NULL );VV g_object_set( completion, "text-column", COL_NAME, NULL ); render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( (GtkCellLayout*)completion, render, TRUE ); gtk_cell_layout_add_attribute( (GtkCellLayout*)completion, render, "text", COL_NAME ); gtk_entry_completion_set_inline_completion( completion, TRUE ); #if GTK_CHECK_VERSION( 2, 8, 0) // gtk+ prior to 2.8.0 doesn't have this API gtk_entry_completion_set_popup_set_width( completion, TRUE ); #endif gtk_entry_set_completion( GTK_ENTRY(entry), completion ); g_signal_connect( G_OBJECT(entry), "changed", G_CALLBACK(on_changed), NULL ); g_object_unref( completion ); return FALSE; }
static gboolean on_focus_in( GtkWidget *entry, GdkEventFocus* evt, gpointer user_data ) { GtkEntryCompletion* completion = gtk_entry_completion_new(); GtkListStore* list = gtk_list_store_new( N_COLS, G_TYPE_STRING, G_TYPE_STRING ); GtkCellRenderer* render; gtk_entry_completion_set_minimum_key_length( completion, 1 ); gtk_entry_completion_set_model( completion, GTK_TREE_MODEL(list) ); g_object_unref( list ); /* gtk_entry_completion_set_text_column( completion, COL_PATH ); */ // Following line causes GTK3 to show both columns, so skip this and use // custom match-selected handler to insert COL_PATH //g_object_set( completion, "text-column", COL_PATH, NULL ); render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( (GtkCellLayout*)completion, render, TRUE ); gtk_cell_layout_add_attribute( (GtkCellLayout*)completion, render, "text", COL_NAME ); //gtk_entry_completion_set_inline_completion( completion, TRUE ); gtk_entry_completion_set_popup_set_width( completion, TRUE ); gtk_entry_set_completion( GTK_ENTRY(entry), completion ); g_signal_connect( G_OBJECT(entry), "changed", G_CALLBACK(on_changed), NULL ); g_signal_connect( G_OBJECT( completion ), "match-selected", G_CALLBACK( on_match_selected ), entry ); g_signal_connect( G_OBJECT( completion ), "insert-prefix", G_CALLBACK( on_insert_prefix ), entry ); g_object_unref( completion ); return FALSE; }
/* * Create completion in entry */ static void dialog_entry_completion_new(const GtkWidget *container, GtkEntryCompletionMatchFunc completion_func, gpointer completion_data) { GtkListStore *list_store = NULL; GtkEntryCompletion *completion = NULL; /* Create a tree model and use it as the completion model */ list_store = gtk_list_store_new(1, G_TYPE_STRING); /* Create the completion object */ completion = gtk_entry_completion_new(); gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(list_store)); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_minimum_key_length(completion, AV_WIDGET_ENTRY_COMPLETION_KEY_LEN_MIN); gtk_entry_completion_set_popup_completion(completion, FALSE); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_match_func(completion, completion_func, completion_data, NULL); /* Assign the completion to the entry */ gtk_entry_set_completion(GTK_ENTRY(container), completion); g_object_unref (completion); }
static void setup_auto_complete_with_data(ThreadData* data) { GtkListStore* store; GSList *l; GtkEntryCompletion* comp = gtk_entry_completion_new(); gtk_entry_completion_set_minimum_key_length( comp, 2 ); gtk_entry_completion_set_inline_completion( comp, TRUE ); #if GTK_CHECK_VERSION( 2, 8, 0 ) gtk_entry_completion_set_popup_set_width( comp, TRUE ); gtk_entry_completion_set_popup_single_match( comp, FALSE ); #endif store = gtk_list_store_new( 1, G_TYPE_STRING ); for( l = data->files; l; l = l->next ) { const char *name = (const char*)l->data; GtkTreeIter it; gtk_list_store_append( store, &it ); gtk_list_store_set( store, &it, 0, name, -1 ); } gtk_entry_completion_set_model( comp, (GtkTreeModel*)store ); g_object_unref( store ); gtk_entry_completion_set_text_column( comp, 0 ); gtk_entry_set_completion( (GtkEntry*)data->entry, comp ); /* trigger entry completion */ gtk_entry_completion_complete(comp); g_object_unref( comp ); }
static void ag_chart_edit_init(AgChartEdit *chart_edit) { GET_PRIV(chart_edit); gtk_widget_init_template(GTK_WIDGET(chart_edit)); g_object_set( priv->year_adjust, "lower", (gdouble)G_MININT, "upper", (gdouble)G_MAXINT, NULL ); gtk_entry_completion_set_model(priv->country_comp, country_list); gtk_entry_completion_set_text_column(priv->country_comp, AG_COUNTRY_NAME); gtk_entry_set_completion(GTK_ENTRY(priv->country), priv->country_comp); gtk_entry_completion_set_model(priv->city_comp, city_list); gtk_entry_completion_set_text_column(priv->city_comp, AG_CITY_NAME); gtk_entry_completion_set_minimum_key_length(priv->city_comp, 3); gtk_entry_set_completion(GTK_ENTRY(priv->city), priv->city_comp); gtk_entry_completion_set_match_func( priv->city_comp, (GtkEntryCompletionMatchFunc)ag_chart_edit_city_matches, chart_edit, NULL ); }
static void fm_path_entry_init(FmPathEntry *entry) { FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(entry); GtkEntryCompletion* completion = gtk_entry_completion_new(); GtkCellRenderer* render; priv->model = NULL; priv->completion_model = NULL; priv->completion_len = 0; priv->in_change = FALSE; priv->completion = completion; priv->highlight_completion_match = TRUE; priv->common_suffix_append_idle_id = -1; priv->common_suffix[0] = 0; gtk_entry_completion_set_minimum_key_length(completion, 1); gtk_entry_completion_set_match_func(completion, fm_path_entry_match_func, NULL, NULL); g_signal_connect(G_OBJECT(completion), "match-selected", G_CALLBACK(fm_path_entry_match_selected), (gpointer)NULL); g_object_set(completion, "text-column", COL_FILE_NAME, NULL); render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( (GtkCellLayout*)completion, render, TRUE ); gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion), render, fm_path_entry_completion_render_func, entry, NULL); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_popup_set_width(completion, TRUE); g_signal_connect(G_OBJECT(entry), "key-press-event", G_CALLBACK(fm_path_entry_key_press), NULL); gtk_entry_set_completion(GTK_ENTRY(entry), completion); }
int clip_GTK_ENTRYCOMPLETIONSETMINIMUMKEYLENGTH(ClipMachine * ClipMachineMemory) { C_object *ccompletion = _fetch_co_arg(ClipMachineMemory); gint length = _clip_parni(ClipMachineMemory, 2); CHECKCOBJ(ccompletion, GTK_IS_ENTRY_COMPLETION(ccompletion->object)); CHECKARG(2, NUMERIC_type_of_ClipVarType); gtk_entry_completion_set_minimum_key_length(GTK_ENTRY_COMPLETION(ccompletion->object), length); return 0; err: return 1; }
void completion_add(struct tab *t) { /* enable completion for tab */ t->completion = gtk_entry_completion_new(); gtk_entry_completion_set_text_column(t->completion, 0); gtk_entry_set_completion(GTK_ENTRY(t->uri_entry), t->completion); gtk_entry_completion_set_model(t->completion, GTK_TREE_MODEL(completion_model)); gtk_entry_completion_set_match_func(t->completion, completion_match, NULL, NULL); gtk_entry_completion_set_minimum_key_length(t->completion, 1); gtk_entry_completion_set_inline_selection(t->completion, TRUE); g_signal_connect(G_OBJECT (t->completion), "match-selected", G_CALLBACK(completion_select_cb), t); g_signal_connect(G_OBJECT (t->completion), "cursor-on-match", G_CALLBACK(completion_hover_cb), t); }
static void fm_path_entry_init(FmPathEntry *entry) { FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(entry); GtkEntryCompletion* completion = gtk_entry_completion_new(); GtkCellRenderer* render; priv->model = fm_path_entry_model_new(entry); priv->completion = completion; priv->cancellable = g_cancellable_new(); priv->highlight_completion_match = TRUE; gtk_entry_completion_set_minimum_key_length(completion, 1); gtk_entry_completion_set_match_func(completion, fm_path_entry_match_func, NULL, NULL); g_object_set(completion, "text_column", COL_FULL_PATH, NULL); gtk_entry_completion_set_model(completion, priv->model); render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( (GtkCellLayout*)completion, render, TRUE ); gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion), render, fm_path_entry_completion_render_func, entry, NULL); /* NOTE: this is to avoid a bug of gtk+. * The inline selection provided by GtkEntry is buggy. * If we change the content of the entry, it still stores * the old prefix sometimes so things don't work as expected. * So, unfortunately, we're not able to use this nice feature. * * Please see gtk_entry_completion_key_press() of gtk/gtkentry.c * and look for completion->priv->completion_prefix. */ gtk_entry_completion_set_inline_selection(completion, FALSE); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_popup_set_width(completion, TRUE); /* gtk_entry_completion_set_popup_single_match(completion, FALSE); */ /* connect to these signals rather than overriding default handlers since * we want to invoke our handlers before the default ones provided by Gtk. */ g_signal_connect(entry, "key-press-event", G_CALLBACK(fm_path_entry_key_press), NULL); g_signal_connect(entry, "activate", G_CALLBACK(fm_path_entry_on_activate), NULL); g_signal_connect(entry, "populate-popup", G_CALLBACK(fm_path_entry_populate_popup), NULL); }
/** * gva_main_init_search_completion: * @error: return location for a #GError, or %NULL * * Initializes autocompletion in the search entry. This must be done * <emphasis>after</emphasis> the game database is built and ROMs are * analyzed. If an error occurs, the function returns %FALSE and sets * @error. * * Returns: %TRUE if autocompletion was initialized successfully, * %FALSE if an error occurred **/ gboolean gva_main_init_search_completion (GError **error) { GtkEntryCompletion *completion; GtkCellRenderer *renderer; GtkListStore *store; GtkTreeIter iter; GtkEntry *entry; sqlite3_stmt *stmt; gint errcode; GList *list; if (!gva_db_prepare (SQL_COMPLETION_LIST, &stmt, error)) return FALSE; store = gtk_list_store_new ( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); while ((errcode = sqlite3_step (stmt)) == SQLITE_ROW) { GvaGameStoreColumn column_id; const gchar *column_name; const gchar *column_title; const gchar *search_text; gchar *collation_key; search_text = (const gchar *) sqlite3_column_text (stmt, 0); column_name = (const gchar *) sqlite3_column_text (stmt, 1); gva_columns_lookup_id (column_name, &column_id); column_title = gva_columns_lookup_title (column_id); if (search_text == NULL || *search_text == '\0') continue; gtk_list_store_append (store, &iter); collation_key = gva_search_collate_key (search_text); gtk_list_store_set ( store, &iter, COLUMN_NAME, column_name, COLUMN_TEXT, search_text, COLUMN_TYPE, column_title, COLUMN_CKEY, collation_key, -1); g_free (collation_key); } sqlite3_finalize (stmt); if (errcode != SQLITE_DONE) { gva_db_set_error (error, 0, NULL); g_object_unref (store); return FALSE; } completion = gtk_entry_completion_new (); gtk_entry_completion_set_match_func ( completion, (GtkEntryCompletionMatchFunc) main_entry_completion_match, NULL, NULL); gtk_entry_completion_set_minimum_key_length (completion, 3); gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store)); gtk_entry_completion_set_text_column (completion, COLUMN_TEXT); g_signal_connect ( completion, "match-selected", G_CALLBACK (main_entry_completion_match_selected_cb), NULL); list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (completion)); g_object_set (list->data, "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_list_free (list); renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "sensitive", FALSE, "xalign", 1.0, NULL); gtk_cell_layout_pack_start ( GTK_CELL_LAYOUT (completion), renderer, FALSE); gtk_cell_layout_add_attribute ( GTK_CELL_LAYOUT (completion), renderer, "text", COLUMN_TYPE); entry = GTK_ENTRY (GVA_WIDGET_MAIN_SEARCH_ENTRY); gtk_entry_set_completion (entry, completion); return TRUE; }
int main (int argc, char *argv[]) { GtkWidget *vbox; GtkWidget *label; GtkWidget *entry; GtkEntryCompletion *completion; GtkTreeModel *completion_model; GtkCellRenderer *cell; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); g_signal_connect (window, "delete_event", gtk_main_quit, NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example."); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); /* Create our first entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); gtk_entry_completion_set_inline_completion (completion, TRUE); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = create_simple_completion_model (); gtk_entry_completion_set_model (completion, completion_model); g_object_unref (completion_model); /* Use model column 0 as the text column */ gtk_entry_completion_set_text_column (completion, 0); /* Create our second entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = create_completion_model (); gtk_entry_completion_set_model (completion, completion_model); gtk_entry_completion_set_minimum_key_length (completion, 2); g_object_unref (completion_model); /* Use model column 1 as the text column */ cell = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell, "pixbuf", 0, NULL); cell = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell, "text", 1, NULL); gtk_entry_completion_set_match_func (completion, match_func, NULL, NULL); g_signal_connect (completion, "match-selected", G_CALLBACK (match_selected_cb), NULL); gtk_entry_completion_insert_action_text (completion, 100, "action!"); gtk_entry_completion_insert_action_text (completion, 101, "'nother action!"); g_signal_connect (completion, "action_activated", G_CALLBACK (activated_cb), NULL); /* Create our third entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); gtk_entry_completion_set_model (completion, completion_model); g_object_unref (completion_model); /* Use model column 0 as the text column */ gtk_entry_completion_set_text_column (completion, 0); /* Fill the completion dynamically */ gdk_threads_add_timeout (1000, (GSourceFunc) animation_timer, completion); /* Fourth entry */ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Model-less entry completion"), FALSE, FALSE, 0); entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); gtk_widget_show_all (window); gtk_main (); return 0; }