static void
ide_workbench_header_bar_init (IdeWorkbenchHeaderBar *self)
{
  IdeWorkbenchHeaderBarPrivate *priv = ide_workbench_header_bar_get_instance_private (self);
  GtkWidget *popover;
  GMenu *model;

  gtk_widget_init_template (GTK_WIDGET (self));

  model = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "gear-menu");
  popover = gtk_popover_new_from_model (NULL, G_MENU_MODEL (model));
  gtk_menu_button_set_popover (priv->menu_button, popover);
}
Exemplo n.º 2
0
/**
 * gtk_menu_button_set_menu_model:
 * @menu_button: a #GtkMenuButton
 * @menu_model: (allow-none): a #GMenuModel
 *
 * Sets the #GMenuModel from which the popup will be constructed,
 * or %NULL to disable the button.
 *
 * Depending on the value of #GtkMenuButton:use-popover, either a
 * #GtkMenu will be created with gtk_menu_new_from_model(), or a
 * #GtkPopover with gtk_popover_new_from_model(). In either case,
 * actions will be connected as documented for these functions.
 *
 * If #GtkMenuButton:popup or #GtkMenuButton:popover are already set,
 * their content will be lost and replaced by the newly created popup.
 *
 * Since: 3.6
 */
void
gtk_menu_button_set_menu_model (GtkMenuButton *menu_button,
                                GMenuModel    *menu_model)
{
  GtkMenuButtonPrivate *priv;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
  g_return_if_fail (G_IS_MENU_MODEL (menu_model) || menu_model == NULL);

  priv = menu_button->priv;

  g_object_freeze_notify (G_OBJECT (menu_button));

  if (menu_model)
    g_object_ref (menu_model);

  if (menu_model)
    {
      if (priv->use_popover)
        {
          GtkWidget *popover;

          popover = gtk_popover_new_from_model (GTK_WIDGET (menu_button), menu_model);
          gtk_menu_button_set_popover (menu_button, popover);
        }
      else
        {
          GtkWidget *menu;

          menu = gtk_menu_new_from_model (menu_model);
          gtk_widget_show_all (menu);
          gtk_menu_button_set_popup (menu_button, menu);
        }
    }
  else
    {
      gtk_menu_button_set_popup (menu_button, NULL);
      gtk_menu_button_set_popover (menu_button, NULL);
    }

  priv->model = menu_model;
  g_object_notify (G_OBJECT (menu_button), "menu-model");

  g_object_thaw_notify (G_OBJECT (menu_button));
}
Exemplo n.º 3
0
static GtkWidget*
get_popup (EogZoomEntry *zoom_entry)
{
	GdkRectangle rect;

	if (zoom_entry->priv->popup)
		return zoom_entry->priv->popup;

	zoom_entry->priv->popup = gtk_popover_new_from_model (GTK_WIDGET (zoom_entry),
	                                                       G_MENU_MODEL (zoom_entry->priv->menu));
	g_signal_connect (zoom_entry->priv->popup, "closed",
	                  G_CALLBACK (popup_menu_closed),
	                  zoom_entry);
	gtk_entry_get_icon_area (GTK_ENTRY (zoom_entry->priv->value_entry),
	                         GTK_ENTRY_ICON_SECONDARY, &rect);
	gtk_popover_set_relative_to (GTK_POPOVER (zoom_entry->priv->popup),
	                             zoom_entry->priv->value_entry);
	gtk_popover_set_pointing_to (GTK_POPOVER (zoom_entry->priv->popup), &rect);
	gtk_popover_set_position (GTK_POPOVER (zoom_entry->priv->popup), GTK_POS_BOTTOM);
	gtk_widget_set_size_request (zoom_entry->priv->popup, 150, -1);

	return zoom_entry->priv->popup;
}