コード例 #1
0
ファイル: testgmenu.c プロジェクト: 3v1n0/gtk
static void
enabled_cell_toggled (GtkCellRendererToggle *cell,
                      const gchar           *path_str,
                      GtkTreeModel          *model)
{
  GActionGroup *group;
  GAction *action;
  gchar *name;
  GtkTreePath *path;
  GtkTreeIter iter;
  gboolean enabled;

  group = g_object_get_data (G_OBJECT (model), "group");
  path = gtk_tree_path_new_from_string (path_str);
  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, 0, &name, -1);

  enabled = g_action_group_get_action_enabled (group, name);
  action = g_action_map_lookup_action (G_ACTION_MAP (group), name);
  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !enabled);

  gtk_tree_model_row_changed (model, path, &iter);

  g_free (name);
  gtk_tree_path_free (path);
}
コード例 #2
0
void
nautilus_toolbar_reset_menus (NautilusToolbar *self)
{
	NautilusWindowSlot *slot;
	NautilusView *view;
	GActionGroup *view_action_group;
	GVariant *variant;
	GVariantIter iter;
	gboolean show_sort_trash, show_sort_search, show_sort_access, show_sort_modification, enable_sort;
	const gchar *hint;

	/* Allow actions from the current view to be activated through
	 * the view menu and action menu of the toolbar */
	slot = nautilus_window_get_active_slot (self->priv->window);
	view = nautilus_window_slot_get_current_view (slot);
	view_action_group = nautilus_view_get_action_group (view);
	gtk_widget_insert_action_group (GTK_WIDGET (self),
					"view",
					G_ACTION_GROUP (view_action_group));

	gtk_widget_set_visible (self->priv->visible_columns,
				g_action_group_has_action (view_action_group, "visible-columns"));

	enable_sort = g_action_group_get_action_enabled (view_action_group, "sort");
	show_sort_trash = show_sort_search = show_sort_modification = show_sort_access = FALSE;
	gtk_widget_set_visible (self->priv->sort_menu, enable_sort);

	if (enable_sort) {
		variant = g_action_group_get_action_state_hint (view_action_group, "sort");
		g_variant_iter_init (&iter, variant);

		while (g_variant_iter_next (&iter, "&s", &hint)) {
			if (g_strcmp0 (hint, "trash-time") == 0)
				show_sort_trash = TRUE;
			if (g_strcmp0 (hint, "search-relevance") == 0)
				show_sort_search = TRUE;
		}

		g_variant_unref (variant);
	}

	gtk_widget_set_visible (self->priv->sort_trash_time, show_sort_trash);
	gtk_widget_set_visible (self->priv->sort_search_relevance, show_sort_search);

	variant = g_action_group_get_action_state (view_action_group, "zoom-to-level");
	gtk_adjustment_set_value (self->priv->zoom_adjustment,
				  g_variant_get_int32 (variant));
	g_variant_unref (variant);
}
コード例 #3
0
ファイル: testgmenu.c プロジェクト: 3v1n0/gtk
static void
enabled_cell_func (GtkTreeViewColumn *column,
                   GtkCellRenderer   *cell,
                   GtkTreeModel      *model,
                   GtkTreeIter       *iter,
                   gpointer           data)
{
  GActionGroup *group = data;
  gchar *name;
  gboolean enabled;

  gtk_tree_model_get (model, iter, 0, &name, -1);
  enabled = g_action_group_get_action_enabled (group, name);
  g_free (name);

  gtk_cell_renderer_toggle_set_active (GTK_CELL_RENDERER_TOGGLE (cell), enabled);
}
コード例 #4
0
ファイル: gtkapplicationwindow.c プロジェクト: jdapena/gtk
static void
accel_activate (GClosure     *closure,
                GValue       *return_value,
                guint         n_param_values,
                const GValue *param_values,
                gpointer      invocation_hint,
                gpointer      marshal_data)
{
  AccelClosure *aclosure = (AccelClosure*)closure;
  GActionGroup *actions;

  actions = G_ACTION_GROUP (closure->data);
  if (g_action_group_get_action_enabled (actions, aclosure->action_name))
    {
       g_action_group_activate_action (actions, aclosure->action_name, aclosure->parameter);

      /* we handled the accelerator */
      g_value_set_boolean (return_value, TRUE);
    }
}
コード例 #5
0
ファイル: testgmenu.c プロジェクト: 3v1n0/gtk
static GtkWidget *
create_menuitem_from_model (GMenuModel   *model,
                            gint          item,
                            GActionGroup *group)
{
  GtkWidget *w;
  gchar *label;
  gchar *action;
  gchar *target;
  gchar *s;
  ActionData *a;
  const GVariantType *type;
  GVariant *v;

  label = NULL;
  g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_LABEL, "s", &label);

  action = NULL;
  g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_ACTION, "s", &action);

  if (action != NULL)
    type = g_action_group_get_action_state_type (group, action);
  else
    type = NULL;

  if (type == NULL)
    w = gtk_menu_item_new_with_mnemonic (label);
  else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
    w = gtk_check_menu_item_new_with_label (label);
  else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
    {
      w = gtk_check_menu_item_new_with_label (label);
      gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (w), TRUE);
    }
  else
    g_assert_not_reached ();

  if (action != NULL)
    {
      a = g_new0 (ActionData, 1);
      a->group = g_object_ref (group);
      a->name = g_strdup (action);
      g_object_set_data_full (G_OBJECT (w), "action", a, action_data_free);

      if (!g_action_group_get_action_enabled (group, action))
        gtk_widget_set_sensitive (w, FALSE);

      s = g_strconcat ("action-enabled-changed::", action, NULL);
      a->enabled_changed_id = g_signal_connect (group, s,
                                                G_CALLBACK (enabled_changed), w);
      g_free (s);

      a->activate_handler = g_signal_connect (w, "activate", G_CALLBACK (item_activated), NULL);

      if (type == NULL)
        {
          /* all set */
        }
      else if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN))
        {
          s = g_strconcat ("action-state-changed::", action, NULL);
          a->state_changed_id = g_signal_connect (group, s,
                                                  G_CALLBACK (toggle_state_changed), w);
          g_free (s);
          v = g_action_group_get_action_state (group, action);
          gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w),
                                          g_variant_get_boolean (v));
          g_variant_unref (v);
        }
      else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING))
        {
          s = g_strconcat ("action-state-changed::", action, NULL);
          a->state_changed_id = g_signal_connect (group, s,
                                                  G_CALLBACK (radio_state_changed), w);
          g_free (s);
          g_menu_model_get_item_attribute (model, item, G_MENU_ATTRIBUTE_TARGET, "s", &target);
          a->target = g_strdup (target);
          v = g_action_group_get_action_state (group, action);
          gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (w),
                                          g_strcmp0 (g_variant_get_string (v, NULL), target) == 0);
          g_variant_unref (v);
          g_free (target);
        }
      else
        g_assert_not_reached ();
    }

  g_free (label);
  g_free (action);

  return w;
}