glade-adaptor-chooser-widget.c 22.1 KB
Newer Older
1
/*
2
 * glade-adaptor-chooser-widget.c
3
 *
4
 * Copyright (C) 2014-2017 Juan Pablo Ugarte
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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.
 *
 * Authors:
 *   Juan Pablo Ugarte <juanpablougarte@gmail.com>
 */

#include "glade-app.h"
#include "gladeui-enum-types.h"
26
#include "glade-adaptor-chooser-widget.h"
27
#include "glade-dnd.h"
28 29 30 31 32 33

#include <string.h>

enum
{
  COLUMN_ADAPTOR = 0,
34
  COLUMN_GROUP,
35 36 37 38 39
  COLUMN_NORMALIZED_NAME,
  COLUMN_NORMALIZED_NAME_LEN,
  N_COLUMN
};

40
struct _GladeAdaptorChooserWidgetPrivate
41
{
42
  GtkTreeView        *treeview;
43 44 45 46
  GtkListStore       *store;
  GtkTreeModelFilter *treemodelfilter;
  GtkSearchEntry     *searchentry;
  GtkEntryCompletion *entrycompletion;
47
  GtkScrolledWindow  *scrolledwindow;
48 49 50 51 52 53 54 55

  /* Needed for gtk_tree_view_column_set_cell_data_func() */
  GtkTreeViewColumn *column_icon;
  GtkCellRenderer   *icon_cell;
  GtkTreeViewColumn *column_adaptor;
  GtkCellRenderer   *adaptor_cell;

  /* Properties */
56
  _GladeAdaptorChooserWidgetFlags flags;
57
  GladeProject *project;
58 59
  gboolean show_group_title;
  gchar *search_text;
60 61 62 63 64 65 66
};

enum
{
  PROP_0,

  PROP_SHOW_FLAGS,
67 68
  PROP_PROJECT,
  PROP_SHOW_GROUP_TITLE
69 70 71 72 73 74 75 76 77 78 79
};

enum
{
  ADAPTOR_SELECTED,

  LAST_SIGNAL
};

static guint adaptor_chooser_signals[LAST_SIGNAL] = { 0 };

80
G_DEFINE_TYPE_WITH_PRIVATE (_GladeAdaptorChooserWidget, _glade_adaptor_chooser_widget, GTK_TYPE_BOX);
81

82
#define GET_PRIVATE(d) ((_GladeAdaptorChooserWidgetPrivate *) _glade_adaptor_chooser_widget_get_instance_private((_GladeAdaptorChooserWidget*)d))
83

84
static void
85
_glade_adaptor_chooser_widget_init (_GladeAdaptorChooserWidget *chooser)
86 87 88 89 90
{
  gtk_widget_init_template (GTK_WIDGET (chooser));
}

static void
91
_glade_adaptor_chooser_widget_finalize (GObject *object)
92
{
93 94 95 96 97
  _GladeAdaptorChooserWidgetPrivate *priv = GET_PRIVATE (object);

  g_clear_pointer (&priv->search_text, g_free);
  g_clear_object (&priv->project);

98
  G_OBJECT_CLASS (_glade_adaptor_chooser_widget_parent_class)->finalize (object);
99 100 101
}

static void
102 103 104 105
_glade_adaptor_chooser_widget_set_property (GObject      *object, 
                                            guint         prop_id,
                                            const GValue *value,
                                            GParamSpec   *pspec)
106
{ 
107
  _GladeAdaptorChooserWidgetPrivate *priv;
108
  
109
  g_return_if_fail (GLADE_IS_ADAPTOR_CHOOSER_WIDGET (object));
110

111
  priv = GET_PRIVATE (object);
112 113 114 115 116 117 118

  switch (prop_id)
    {
      case PROP_SHOW_FLAGS:
        priv->flags = g_value_get_flags (value);
      break;
      case PROP_PROJECT:
119 120
        _glade_adaptor_chooser_widget_set_project (GLADE_ADAPTOR_CHOOSER_WIDGET (object),
                                                   g_value_get_object (value));
121
      break;
122 123 124
      case PROP_SHOW_GROUP_TITLE:
        priv->show_group_title = g_value_get_boolean (value);
      break;
125 126 127 128 129 130 131
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static void
132 133 134 135
_glade_adaptor_chooser_widget_get_property (GObject    *object,
                                            guint       prop_id,
                                            GValue     *value,
                                            GParamSpec *pspec)
136
{
137
  _GladeAdaptorChooserWidgetPrivate *priv;
138

139
  g_return_if_fail (GLADE_IS_ADAPTOR_CHOOSER_WIDGET (object));
140

141
  priv = GET_PRIVATE (object);
142 143 144 145 146 147 148 149 150

  switch (prop_id)
    {
      case PROP_SHOW_FLAGS:
        g_value_set_flags (value, priv->flags);
      break;
      case PROP_PROJECT:
        g_value_set_object (value, priv->project);
      break;
151 152 153
      case PROP_SHOW_GROUP_TITLE:
        g_value_set_boolean (value, priv->show_group_title);
      break;
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

static inline gchar *
normalize_name (const gchar *name)
{
  gchar *normalized_name = g_utf8_normalize (name, -1, G_NORMALIZE_DEFAULT);
  gchar *casefold_name = g_utf8_casefold (normalized_name, -1);
  g_free (normalized_name);
  return casefold_name;
}

static inline void
store_append_adaptor (GtkListStore *store, GladeWidgetAdaptor *adaptor)
{
  gchar *normalized_name = normalize_name (glade_widget_adaptor_get_name (adaptor));

  gtk_list_store_insert_with_values (store, NULL, -1,
                                     COLUMN_ADAPTOR, adaptor,
                                     COLUMN_NORMALIZED_NAME, normalized_name,
                                     COLUMN_NORMALIZED_NAME_LEN, strlen (normalized_name),
                                     -1);
  g_free (normalized_name);
}

static void
183 184 185 186
on_treeview_row_activated (GtkTreeView                *tree_view,
                           GtkTreePath                *path,
                           GtkTreeViewColumn          *column,
                           _GladeAdaptorChooserWidget *chooser)
187 188 189 190 191 192 193 194 195 196
{
  GtkTreeModel *model = gtk_tree_view_get_model (tree_view); 
  GtkTreeIter iter;

  if (gtk_tree_model_get_iter (model, &iter, path))
    {
      GladeWidgetAdaptor *adaptor;

      gtk_tree_model_get (model, &iter, COLUMN_ADAPTOR, &adaptor, -1);

197 198 199
      if (!adaptor)
        return;

200 201 202 203 204 205 206
      /* Emit selected signal */
      g_signal_emit (chooser, adaptor_chooser_signals[ADAPTOR_SELECTED], 0, adaptor);

      g_object_unref (adaptor);
    }
}

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
static void
on_searchentry_search_changed (GtkEntry                   *entry,
                               _GladeAdaptorChooserWidget *chooser)
{
  _GladeAdaptorChooserWidgetPrivate *priv = GET_PRIVATE (chooser);
  const gchar *text = gtk_entry_get_text (entry);

  g_clear_pointer (&priv->search_text, g_free);

  if (g_utf8_strlen (text, -1))
    priv->search_text = normalize_name (text);

  gtk_tree_model_filter_refilter (priv->treemodelfilter);
}

222
static void
223
on_searchentry_activate (GtkEntry *entry, _GladeAdaptorChooserWidget *chooser)
224
{
225
  _GladeAdaptorChooserWidgetPrivate *priv = GET_PRIVATE (chooser);
226 227 228 229 230 231
  const gchar *text = gtk_entry_get_text (entry);
  GladeWidgetAdaptor *adaptor;

  /* try to find an adaptor by name */
  if (!(adaptor = glade_widget_adaptor_get_by_name (text)))
    {
232
      GtkTreeModel *model = GTK_TREE_MODEL (priv->treemodelfilter);
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
      gchar *normalized_name = normalize_name (text);
      GtkTreeIter iter;
      gboolean valid;
      gint count = 0;

      valid = gtk_tree_model_get_iter_first (model, &iter);

      /* we could not find it check if we can find it by normalized name */
      while (valid)
        {
          gchar *name;

          gtk_tree_model_get (model, &iter, COLUMN_NORMALIZED_NAME, &name, -1);

          if (g_strcmp0 (name, normalized_name) == 0)
            {
              gtk_tree_model_get (model, &iter, COLUMN_ADAPTOR, &adaptor, -1);
              g_free (name);
              break;
            }

          valid = gtk_tree_model_iter_next (model, &iter);
          g_free (name);
          count++;
        }

      /* if not, and there is only one row, then we select that one */
      if (!adaptor && count == 1 && gtk_tree_model_get_iter_first (model, &iter))
        gtk_tree_model_get (model, &iter, COLUMN_ADAPTOR, &adaptor, -1);

      g_free (normalized_name);
    }

  if (adaptor)
    g_signal_emit (chooser, adaptor_chooser_signals[ADAPTOR_SELECTED], 0, adaptor);
}

static gboolean
271 272 273 274
chooser_match_func (_GladeAdaptorChooserWidget *chooser,
                    GtkTreeModel               *model,
                    const gchar                *key,
                    GtkTreeIter                *iter)
275 276 277 278 279 280 281 282 283 284 285 286
{
  gboolean visible;
  gint name_len;
  gchar *name;

  if (!key || *key == '\0')
    return TRUE;

  gtk_tree_model_get (model, iter,
                      COLUMN_NORMALIZED_NAME, &name,
                      COLUMN_NORMALIZED_NAME_LEN, &name_len,
                      -1);
287 288
  if (!name)
    return FALSE;
289 290 291 292 293 294 295 296 297 298

  visible = (g_strstr_len (name, name_len, key) != NULL);
  g_free (name);

  return visible;
}

static gboolean
treemodelfilter_visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
{
299
  _GladeAdaptorChooserWidgetPrivate *priv = GET_PRIVATE (data);
300 301 302 303 304
  GladeWidgetAdaptor *adaptor = NULL;
  gboolean visible = TRUE;

  gtk_tree_model_get (model, iter, COLUMN_ADAPTOR, &adaptor, -1);

305 306 307
  if (!adaptor)
    return priv->show_group_title && !priv->search_text;

308
  /* Skip classes not available in project target version */
309
  if (priv->project)
310 311 312 313 314 315 316 317 318 319
    {
      const gchar *catalog = NULL;
      gint major, minor;

      catalog = glade_widget_adaptor_get_catalog (adaptor);
      glade_project_get_target_version (priv->project, catalog, &major, &minor);

      visible = GWA_VERSION_CHECK (adaptor, major, minor);
    }

320
  if (visible && priv->flags)
321 322
    {
      GType type = glade_widget_adaptor_get_object_type (adaptor);
323
      _GladeAdaptorChooserWidgetFlags flags = priv->flags;
324 325

       /* Skip adaptors according to flags */
326
       if (flags & GLADE_ADAPTOR_CHOOSER_WIDGET_SKIP_DEPRECATED && GWA_DEPRECATED (adaptor))
327
         visible = FALSE;
328
       else if (flags & GLADE_ADAPTOR_CHOOSER_WIDGET_SKIP_TOPLEVEL && GWA_IS_TOPLEVEL (adaptor))
329
         visible = FALSE;
330
       else if (flags & GLADE_ADAPTOR_CHOOSER_WIDGET_WIDGET && !g_type_is_a (type, GTK_TYPE_WIDGET))
331
         visible = FALSE;
332
       else if (flags & GLADE_ADAPTOR_CHOOSER_WIDGET_TOPLEVEL && !GWA_IS_TOPLEVEL (adaptor))
333 334 335
         visible = FALSE;
    }

336 337
  if (visible && priv->search_text)
    visible = chooser_match_func (data, model, priv->search_text, iter);
338

339
  g_clear_object (&adaptor);
340

341 342 343 344 345 346 347 348 349 350
  return visible;
}

static gboolean
entrycompletion_match_func (GtkEntryCompletion *entry, const gchar *key, GtkTreeIter *iter, gpointer data)
{
  return chooser_match_func (data, gtk_entry_completion_get_model (entry), key, iter);
}

static void
351 352 353 354 355
adaptor_icon_cell_data_func (GtkTreeViewColumn *tree_column,
                             GtkCellRenderer   *cell,
                             GtkTreeModel      *tree_model,
                             GtkTreeIter       *iter,
                             gpointer           data)
356 357 358 359
{
  GladeWidgetAdaptor *adaptor;
  gtk_tree_model_get (tree_model, iter, COLUMN_ADAPTOR, &adaptor, -1);

360 361
  if (adaptor)
    g_object_set (cell, "sensitive", TRUE, "icon-name", glade_widget_adaptor_get_icon_name (adaptor), NULL);
362
  else
363
    g_object_set (cell, "sensitive", FALSE, "icon-name", "go-down-symbolic", NULL);
364

365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
  g_clear_object (&adaptor);
}

static void
adaptor_text_cell_data_func (GtkTreeViewColumn *tree_column,
                             GtkCellRenderer   *cell,
                             GtkTreeModel      *tree_model,
                             GtkTreeIter       *iter,
                             gpointer           data)
{
  GladeWidgetAdaptor *adaptor;
  gchar *group;

  gtk_tree_model_get (tree_model, iter,
                      COLUMN_ADAPTOR, &adaptor,
                      COLUMN_GROUP, &group,
                      -1);
  if (adaptor)
    g_object_set (cell,
                  "sensitive", TRUE,
                  "text", glade_widget_adaptor_get_name (adaptor),
                  "style", PANGO_STYLE_NORMAL,
                  NULL);
  else
    g_object_set (cell,
                  "sensitive", FALSE,
                  "text", group,
                  "style", PANGO_STYLE_ITALIC,
                  NULL);

  g_clear_object (&adaptor);
  g_free (group);
397 398
}

399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
static void
glade_adaptor_chooser_widget_drag_begin (GtkWidget      *widget,
                                         GdkDragContext *context,
                                         gpointer        data)
{
  GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
  GtkTreeModel *model;
  GtkTreeIter iter;

  if (gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      GladeWidgetAdaptor *adaptor;
      gtk_tree_model_get (model, &iter, COLUMN_ADAPTOR, &adaptor, -1);
      _glade_dnd_set_icon_widget (context,
                                  glade_widget_adaptor_get_icon_name (adaptor),
                                  glade_widget_adaptor_get_name (adaptor));
    }
}

static void
glade_adaptor_chooser_widget_drag_data_get (GtkWidget          *widget,
                                            GdkDragContext     *context,
                                            GtkSelectionData   *data,
                                            guint               info,
                                            guint               time,
                                            gpointer            userdata)
{
  GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
  GtkTreeModel *model;
  GtkTreeIter iter;

  if (gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      GladeWidgetAdaptor *adaptor;
      gtk_tree_model_get (model, &iter, COLUMN_ADAPTOR, &adaptor, -1);
      _glade_dnd_set_data (data, G_OBJECT (adaptor));
    }
}

438
static void
439
_glade_adaptor_chooser_widget_constructed (GObject *object)
440
{
441 442
  _GladeAdaptorChooserWidget *chooser = GLADE_ADAPTOR_CHOOSER_WIDGET (object);
  _GladeAdaptorChooserWidgetPrivate *priv = GET_PRIVATE (chooser);
443 444 445 446

  /* Set cell data function: this save us from alocating name and icon name for each adaptor. */
  gtk_tree_view_column_set_cell_data_func (priv->column_icon,
                                           priv->icon_cell,
447 448
                                           adaptor_icon_cell_data_func,
                                           NULL, NULL);
449 450
  gtk_tree_view_column_set_cell_data_func (priv->column_adaptor,
                                           priv->adaptor_cell,
451 452
                                           adaptor_text_cell_data_func,
                                           NULL, NULL);
453 454 455 456 457 458 459 460
  /* Set tree model filter function */
  gtk_tree_model_filter_set_visible_func (priv->treemodelfilter,
                                          treemodelfilter_visible_func,
                                          chooser, NULL);
  /* Set completion match function */
  gtk_entry_completion_set_match_func (priv->entrycompletion,
                                       entrycompletion_match_func,
                                       chooser, NULL);
461 462 463 464 465 466 467 468 469
  /* Enable Drag & Drop */
  gtk_tree_view_enable_model_drag_source (priv->treeview, GDK_BUTTON1_MASK,
                                          _glade_dnd_get_target (), 1, 0);
  g_signal_connect_after (priv->treeview, "drag-begin",
                          G_CALLBACK (glade_adaptor_chooser_widget_drag_begin),
                          NULL);
  g_signal_connect (priv->treeview, "drag-data-get",
                    G_CALLBACK (glade_adaptor_chooser_widget_drag_data_get),
                    NULL);
470 471
}

472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
static void
_glade_adaptor_chooser_widget_map (GtkWidget *widget)
{
  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);

  if (toplevel)
    {
      _GladeAdaptorChooserWidgetPrivate *priv = GET_PRIVATE (widget);
      gint height = gtk_widget_get_allocated_height (toplevel) - 100;

      if (height > 512)
        height = height * 0.75;

      gtk_scrolled_window_set_max_content_height (priv->scrolledwindow, height);
    }

  GTK_WIDGET_CLASS (_glade_adaptor_chooser_widget_parent_class)->map (widget);
}

491
static GType
492
_glade_adaptor_chooser_widget_flags_get_type (void)
493 494 495 496
{
    static GType etype = 0;
    if (G_UNLIKELY(etype == 0)) {
        static const GFlagsValue values[] = {
497 498 499 500
            { GLADE_ADAPTOR_CHOOSER_WIDGET_WIDGET, "GLADE_ADAPTOR_CHOOSER_WIDGET_WIDGET", "widget" },
            { GLADE_ADAPTOR_CHOOSER_WIDGET_TOPLEVEL, "GLADE_ADAPTOR_CHOOSER_WIDGET_TOPLEVEL", "toplevel" },
            { GLADE_ADAPTOR_CHOOSER_WIDGET_SKIP_TOPLEVEL, "GLADE_ADAPTOR_CHOOSER_WIDGET_SKIP_TOPLEVEL", "skip-toplevel" },
            { GLADE_ADAPTOR_CHOOSER_WIDGET_SKIP_DEPRECATED, "GLADE_ADAPTOR_CHOOSER_WIDGET_SKIP_DEPRECATED", "skip-deprecated" },
501 502
            { 0, NULL, NULL }
        };
503
        etype = g_flags_register_static (g_intern_static_string ("_GladeAdaptorChooserWidgetFlag"), values);
504 505 506 507 508
    }
    return etype;
}

static void
509
_glade_adaptor_chooser_widget_class_init (_GladeAdaptorChooserWidgetClass *klass)
510 511 512 513
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

514 515 516 517
  object_class->finalize = _glade_adaptor_chooser_widget_finalize;
  object_class->set_property = _glade_adaptor_chooser_widget_set_property;
  object_class->get_property = _glade_adaptor_chooser_widget_get_property;
  object_class->constructed = _glade_adaptor_chooser_widget_constructed;
518

519 520
  widget_class->map = _glade_adaptor_chooser_widget_map;

521 522 523 524 525
  g_object_class_install_property (object_class,
                                   PROP_SHOW_FLAGS,
                                   g_param_spec_flags ("show-flags",
                                                       "Show flags",
                                                       "Widget adaptors show flags",
526
                                                       _glade_adaptor_chooser_widget_flags_get_type (),
527
                                                       0,
528
                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
529 530 531 532 533 534 535
  g_object_class_install_property (object_class,
                                   PROP_SHOW_GROUP_TITLE,
                                   g_param_spec_boolean ("show-group-title",
                                                         "Show group title",
                                                         "Whether to show the group title",
                                                         FALSE,
                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
536 537 538 539 540 541
  g_object_class_install_property (object_class,
                                   PROP_PROJECT,
                                   g_param_spec_object ("project",
                                                        "Glade Project",
                                                        "If set, use project target version to skip unsupported classes",
                                                        GLADE_TYPE_PROJECT,
542
                                                        G_PARAM_READWRITE));
543 544 545 546 547 548 549

  adaptor_chooser_signals[ADAPTOR_SELECTED] =
    g_signal_new ("adaptor-selected", G_OBJECT_CLASS_TYPE (klass), 0, 0,
                  NULL, NULL, NULL,
                  G_TYPE_NONE, 1,
                  GLADE_TYPE_WIDGET_ADAPTOR);

550
  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/gladeui/glade-adaptor-chooser-widget.ui");
551
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, treeview);
552 553 554 555 556 557 558 559
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, store);
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, treemodelfilter);
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, searchentry);
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, entrycompletion);
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, column_icon);
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, icon_cell);
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, column_adaptor);
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, adaptor_cell);
560
  gtk_widget_class_bind_template_child_private (widget_class, _GladeAdaptorChooserWidget, scrolledwindow);
561
  gtk_widget_class_bind_template_callback (widget_class, on_treeview_row_activated);
562
  gtk_widget_class_bind_template_callback (widget_class, on_searchentry_search_changed);
563 564 565 566
  gtk_widget_class_bind_template_callback (widget_class, on_searchentry_activate);
}

GtkWidget *
567
_glade_adaptor_chooser_widget_new (_GladeAdaptorChooserWidgetFlags flags, GladeProject *project)
568
{
569
  return GTK_WIDGET (g_object_new (GLADE_TYPE_ADAPTOR_CHOOSER_WIDGET,
570 571 572 573
                                   "show-flags", flags,
                                   "project", project,
                                   NULL));
}
574 575

void
576 577
_glade_adaptor_chooser_widget_set_project (_GladeAdaptorChooserWidget *chooser,
                                           GladeProject               *project)
578
{
579
  _GladeAdaptorChooserWidgetPrivate *priv;
580

581
  g_return_if_fail (GLADE_IS_ADAPTOR_CHOOSER_WIDGET (chooser));
582 583 584 585 586 587 588 589 590 591 592
  priv = GET_PRIVATE (chooser);

  g_clear_object (&priv->project);

  if (project)
    priv->project = g_object_ref (project);

  gtk_tree_model_filter_refilter (priv->treemodelfilter);
}

void
593
_glade_adaptor_chooser_widget_populate (_GladeAdaptorChooserWidget *chooser)
594 595 596 597
{
  GList *l;

  for (l = glade_app_get_catalogs (); l; l = g_list_next (l))
598
    _glade_adaptor_chooser_widget_add_catalog (chooser, l->data);
599 600 601
}

void
602
_glade_adaptor_chooser_widget_add_catalog (_GladeAdaptorChooserWidget *chooser,
603
                                           GladeCatalog               *catalog)
604 605 606
{
  GList *groups;

607
  g_return_if_fail (GLADE_IS_ADAPTOR_CHOOSER_WIDGET (chooser));
608 609 610

  for (groups = glade_catalog_get_widget_groups (catalog); groups;
       groups = g_list_next (groups))
611
    _glade_adaptor_chooser_widget_add_group (chooser, groups->data);
612 613 614
}

void
615
_glade_adaptor_chooser_widget_add_group (_GladeAdaptorChooserWidget *chooser,
616
                                         GladeWidgetGroup           *group)
617
{
618
  _GladeAdaptorChooserWidgetPrivate *priv;
619 620
  const GList *adaptors;

621
  g_return_if_fail (GLADE_IS_ADAPTOR_CHOOSER_WIDGET (chooser));
622 623
  priv = GET_PRIVATE (chooser);

624 625 626 627 628
  if (priv->show_group_title)
    gtk_list_store_insert_with_values (priv->store, NULL, -1,
                                       COLUMN_GROUP, glade_widget_group_get_title (group),
                                       -1);

629 630 631 632
  for (adaptors = glade_widget_group_get_adaptors (group); adaptors;
       adaptors = g_list_next (adaptors))
    store_append_adaptor (priv->store, adaptors->data);
}
633