Пример #1
0
/**
 * gva_main_clear_search:
 *
 * Clears the search entry and, if the Search Results view is active,
 * any results from the previous search.
 **/
void
gva_main_clear_search (void)
{
        GtkWidget *widget;

        widget = GVA_WIDGET_MAIN_SEARCH_ENTRY;
        gtk_entry_set_text (GTK_ENTRY (widget), "");
        gva_main_set_last_selected_match (NULL, NULL);

        if (gva_tree_view_get_selected_view () == 2)
                gva_main_execute_search ();
}
Пример #2
0
/**
 * gva_main_execute_search:
 *
 * Executes a game database search and configures the main window to
 * display the results.  More precisely, the function saves the search
 * entry contents to GConf, switches to the Search Results view, forces
 * an update, ensures a row in the resulting game list is selected, and
 * gives focus to the main tree view.
 *
 * The SQL expression used in the database search is retrieved from
 * gva_main_get_search_expression().  It is applied while updating the
 * Search Results view.
 **/
void
gva_main_execute_search (void)
{
        GtkTreeSelection *selection;
        GtkTreeModel *model;
        GtkTreeView *view;
        GtkTreeIter iter;
        GtkEntry *entry;
        gchar *text;

        entry = GTK_ENTRY (GVA_WIDGET_MAIN_SEARCH_ENTRY);
        view = GTK_TREE_VIEW (GVA_WIDGET_MAIN_TREE_VIEW);
        selection = gtk_tree_view_get_selection (view);

        /* Save the search entry text. */
        text = g_strdup (gtk_entry_get_text (entry));
        gtk_entry_set_text (entry, g_strstrip (text));
        gva_main_set_last_search_text (text);
        g_free (text);

        /* Force a tree view update. */
        if (gva_tree_view_get_selected_view () != 2)
                gva_tree_view_set_selected_view (2);
        else
        {
                GError *error = NULL;

                gva_tree_view_update (&error);
                gva_error_handle (&error);
        }

        /* Select something in the tree view.  Parts of this are
         * copied from gva_tree_view_set_selected_game(). */
        if (!gtk_tree_selection_get_selected (selection, &model, &iter))
        {
                if (gtk_tree_model_get_iter_first (model, &iter))
                {
                        GtkTreePath *path;

                        path = gtk_tree_model_get_path (model, &iter);
                        gtk_tree_view_set_cursor (view, path, NULL, FALSE);
                        gtk_tree_view_scroll_to_cell (
                                view, path, NULL, TRUE, 0.5, 0.0);
                        gtk_tree_path_free (path);
                }
        }

        gtk_widget_grab_focus (GTK_WIDGET (view));
}