Пример #1
0
static void
disable_plugin (const gchar *name)
{
  GMenuModel *plugin_menu;

  g_print ("Disabling '%s' plugin\n", name);

  plugin_menu = find_plugin_menu ();
  if (plugin_menu)
    {
      const gchar *id;
      gint i;

      for (i = 0; i < g_menu_model_get_n_items (plugin_menu); i++)
        {
           if (g_menu_model_get_item_attribute (plugin_menu, i, "id", "s", &id) &&
               g_strcmp0 (id, name) == 0)
             {
               g_menu_remove (G_MENU (plugin_menu), i);
               g_print ("Menus of '%s' plugin removed\n", name);
             }
        }
    }
  else
    g_warning ("Plugin menu not found\n");

  g_action_map_remove_action (G_ACTION_MAP (g_application_get_default ()), name);
  g_print ("Actions of '%s' plugin removed\n", name);

  if (g_strcmp0 (name, "red") == 0)
    is_red_plugin_enabled = FALSE;
  else
    is_black_plugin_enabled = FALSE;
}
Пример #2
0
static void
impl_deactivate	(EogWindowActivatable *activatable)
{
	EogPostrPlugin *plugin = EOG_POSTR_PLUGIN (activatable);
	GMenu *menu;
	GMenuModel *model;
	gint i;

	eog_debug (DEBUG_PLUGINS);

	menu = eog_window_get_gear_menu_section (plugin->window,
						 "plugins-section");

	g_return_if_fail (G_IS_MENU (menu));

	/* Remove menu entry */
	model = G_MENU_MODEL (menu);
	for (i = 0; i < g_menu_model_get_n_items (model); i++) {
		gchar *id;
		if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)) {
			const gboolean found =
				(g_strcmp0 (id, EOG_POSTR_PLUGIN_MENU_ID) == 0);
			g_free (id);

			if (found) {
				g_menu_remove (menu, i);
				break;
			}
		}
	}

	/* Finally remove action */
	g_action_map_remove_action (G_ACTION_MAP (plugin->window),
				    EOG_POSTR_PLUGIN_ACTION);
}
Пример #3
0
void
gw_application_remove_accelerators (GwApplication *application, GMenuModel *menumodel)
{
    //Sanity checks
    g_return_if_fail (application != NULL);
    g_return_if_fail (menumodel != NULL);

    //Declarations
    gint total_items;
    gint index;
    gchar *accel = NULL;
    gchar *action = NULL;
    gchar *detail = NULL;
    GMenuModel *sublink = NULL;

    //Initializations
    total_items = g_menu_model_get_n_items (menumodel);

    for (index = 0; index < total_items; index++)
    {
      g_menu_model_get_item_attribute (menumodel, index, "accel", "s", &accel, NULL);
      g_menu_model_get_item_attribute (menumodel, index, G_MENU_ATTRIBUTE_ACTION, "s", &action, NULL);
      g_menu_model_get_item_attribute (menumodel, index, G_MENU_ATTRIBUTE_TARGET, "s", &detail, NULL);
      if (accel != NULL && action != NULL)
      {
        if (detail != NULL)
          gtk_application_remove_accelerator (GTK_APPLICATION (application), action, g_variant_new_string (detail));
        else
          gtk_application_remove_accelerator (GTK_APPLICATION (application), action, NULL);
      }

      if (accel != NULL) g_free (accel); accel = NULL;
      if (action != NULL) g_free (action); action = NULL;
      if (detail != NULL) g_free (detail); detail = NULL;

      //Recursive work
      sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SUBMENU);
      if (sublink != NULL) gw_application_remove_accelerators (application, sublink);
      sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SECTION);
      if (sublink != NULL) gw_application_remove_accelerators (application, sublink);
    }
}
static GMenuModel *
find_gmenu_model (GMenuModel  *model,
		  const gchar *model_id)
{
	gint i, n_items;
	GMenuModel *insertion_model = NULL;

	n_items = g_menu_model_get_n_items (model);

	for (i = 0; i < n_items && !insertion_model; i++) {
		gchar *id = NULL;
		if (g_menu_model_get_item_attribute (model, i, "id", "s", &id) &&
		    g_strcmp0 (id, model_id) == 0) {
			insertion_model = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
			if (!insertion_model)
				insertion_model = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU);
		} else {
			GMenuModel *submodel;
			GMenuModel *submenu;
			gint j, j_items;

			submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);

			if (!submodel)
			        submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU);

			if (!submodel)
				continue;

			j_items = g_menu_model_get_n_items (submodel);
			for (j = 0; j < j_items; j++) {
				submenu = g_menu_model_get_item_link (submodel, j, G_MENU_LINK_SUBMENU);
				if (submenu) {
					insertion_model = find_gmenu_model (submenu, model_id);
					g_object_unref (submenu);
				}

				if (insertion_model)
					break;
			}

			g_object_unref (submodel);
		}

		g_free (id);
	}

	return insertion_model;
}
Пример #5
0
static void
eog_reload_plugin_deactivate (EogWindowActivatable *activatable)
{
	const gchar * const empty_accels[1] = { NULL };
	EogReloadPlugin *plugin = EOG_RELOAD_PLUGIN (activatable);
	GMenu *menu;
	GMenuModel *model;
	gint i;

	eog_debug (DEBUG_PLUGINS);

	menu = eog_window_get_gear_menu_section (plugin->window,
						 "plugins-section");

	g_return_if_fail (G_IS_MENU (menu));

	/* Remove menu entry */
	model = G_MENU_MODEL (menu);
	for (i = 0; i < g_menu_model_get_n_items (model); i++) {
		gchar *id;
		if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)) {
			const gboolean found =
				(g_strcmp0 (id, EOG_RELOAD_PLUGIN_MENU_ID) == 0);
			g_free (id);

			if (found) {
				g_menu_remove (menu, i);
				break;
			}
		}
	}

	/* Unset accelerator */
	gtk_application_set_accels_for_action(GTK_APPLICATION (EOG_APP),
					      "win." EOG_RELOAD_PLUGIN_ACTION,
					      empty_accels);

	/* Disconnect selection-changed handler as the thumbview would
	 * otherwise still cause callbacks during its own disposal */
	g_signal_handlers_disconnect_by_func (eog_window_get_thumb_view (plugin->window),
					      _selection_changed_cb, plugin);

	/* Finally remove action */
	g_action_map_remove_action (G_ACTION_MAP (plugin->window),
				    EOG_RELOAD_PLUGIN_ACTION);
}
Пример #6
0
static GMenuModel *
find_extension_point_section (GMenuModel  *model,
                              const gchar *extension_point)
{
	gint i, n_items;
	GMenuModel *section = NULL;

	n_items = g_menu_model_get_n_items (model);

	for (i = 0; i < n_items && !section; i++)
	{
		gchar *id = NULL;

		if (g_menu_model_get_item_attribute (model, i, "id", "s", &id) &&
		    strcmp (id, extension_point) == 0)
		{
			section = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
		}
		else
		{
			GMenuModel *subsection;
			GMenuModel *submenu;
			gint j, j_items;

			subsection = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);

			j_items = g_menu_model_get_n_items (subsection);

			for (j = 0; j < j_items && !section; j++)
			{
				submenu = g_menu_model_get_item_link (subsection, j, G_MENU_LINK_SUBMENU);
				if (submenu)
				{
					section = find_extension_point_section (submenu, extension_point);
				}
			}
		}

		g_free (id);
	}

	return section;
}
Пример #7
0
void
gw_menumodel_set_links (GMenuModel *menumodel, const gchar *LABEL, const gchar *NEW_LABEL, const gchar *LINK_TYPE, GMenuModel *link)
{
    //Sanity checks
    g_return_if_fail (menumodel != NULL);
    g_return_if_fail (LABEL != NULL);
    g_return_if_fail (LINK_TYPE != NULL);

    //Declarations
    gint total_items;
    gint index;
    gchar *label;
    gboolean valid;
    GMenuItem *menuitem;
    GMenuModel *sublink;

    //Initializations
    total_items = g_menu_model_get_n_items (menumodel);

    for (index = 0; index < total_items; index++)
    {
      valid = g_menu_model_get_item_attribute (menumodel, index, G_MENU_ATTRIBUTE_LABEL, "s", &label, NULL);
      if (valid == TRUE && label != NULL)
      {
        if (label != NULL && strcmp (label, LABEL) == 0)
        {
          menuitem = g_menu_item_new (NEW_LABEL, NULL);
          g_menu_item_set_link (menuitem, LINK_TYPE, link);
          g_menu_remove (G_MENU (menumodel), index);
          g_menu_insert_item (G_MENU (menumodel), index, menuitem);
          g_object_unref (menuitem); menuitem = NULL;
        }
        g_free (label); label = NULL;
      }

      //Recursive work
      sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SUBMENU);
      if (sublink != NULL) gw_menumodel_set_links (sublink, LABEL, NEW_LABEL, LINK_TYPE, link);
      sublink = g_menu_model_get_item_link (menumodel, index, G_MENU_LINK_SECTION);
      if (sublink != NULL) gw_menumodel_set_links (sublink, LABEL, NEW_LABEL, LINK_TYPE, link);
    }
}
Пример #8
0
static void
impl_deactivate	(EogWindowActivatable *activatable)
{
	const gchar * const empty_accels[1] = { NULL };
	EogFitToWidthPlugin *plugin = EOG_FIT_TO_WIDTH_PLUGIN (activatable);
	GMenu *menu;
	GMenuModel *model;
	gint i;

	menu = eog_window_get_gear_menu_section (plugin->window,
						 "plugins-section");

	g_return_if_fail (G_IS_MENU (menu));

	/* Remove menu entry */
	model = G_MENU_MODEL (menu);
	for (i = 0; i < g_menu_model_get_n_items (model); i++) {
		gchar *id;
		if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)) {
			const gboolean found =
				(g_strcmp0 (id, EOG_FIT_TO_WIDTH_PLUGIN_MENU_ID) == 0);
			g_free (id);

			if (found) {
				g_menu_remove (menu, i);
				break;
			}
		}
	}

	/* Unset accelerator */
	gtk_application_set_accels_for_action(GTK_APPLICATION (EOG_APP),
					      "win." EOG_FIT_TO_WIDTH_PLUGIN_ACTION,
					      empty_accels);

	/* Finally remove action */
	g_action_map_remove_action (G_ACTION_MAP (plugin->window),
				    EOG_FIT_TO_WIDTH_PLUGIN_ACTION);
}
Пример #9
0
static void
gtk_model_menu_binding_append_item (GtkModelMenuBinding  *binding,
                                    GMenuModel           *model,
                                    gint                  item_index,
                                    gchar               **heading)
{
  GMenuModel *section;

  if ((section = g_menu_model_get_item_link (model, item_index, "section")))
    {
      g_menu_model_get_item_attribute (model, item_index, "label", "s", heading);
      gtk_model_menu_binding_append_model (binding, section, FALSE);
    }
  else
    {
      GtkMenuItem *item;

      item = gtk_model_menu_item_new (model, item_index, binding->actions, binding->accels);
      gtk_menu_shell_append (binding->shell, GTK_WIDGET (item));
      gtk_widget_show (GTK_WIDGET (item));
      binding->n_items++;
    }
}
Пример #10
0
GeditMenuExtension *
gedit_window_activatable_extend_gear_menu (GeditWindowActivatable *activatable,
                                           const gchar            *extension_point)
{
	GeditMenuExtension *menu = NULL;
	GeditWindow *window;
	GMenuModel *model;
	gint i, n_items;

	g_return_val_if_fail (GEDIT_IS_WINDOW_ACTIVATABLE (activatable), NULL);
	g_return_val_if_fail (extension_point != NULL, NULL);

	g_object_get (G_OBJECT (activatable), "window", &window, NULL);
	model = _gedit_window_get_gear_menu (window);
	g_object_unref (window);

	n_items = g_menu_model_get_n_items (model);

	for (i = 0; i < n_items; i++)
	{
		gchar *id = NULL;

		if (g_menu_model_get_item_attribute (model, i, "id", "s", &id) &&
		    strcmp (id, extension_point) == 0)
		{
			GMenuModel *section;

			section = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
			menu = _gedit_menu_extension_new (G_MENU (section));
		}

		g_free (id);
	}

	return menu;
}
Пример #11
0
static gboolean
append_menu (RBButtonBar *bar, GMenuModel *menu, gboolean need_separator)
{
	int i;
	gulong id;

	id = g_signal_connect (menu, "items-changed", G_CALLBACK (items_changed_cb), bar);
	g_hash_table_insert (bar->priv->handlers, (gpointer)id, g_object_ref (menu));

	for (i = 0; i < g_menu_model_get_n_items (menu); i++) {
		char *label_text;
		char *accel;
		GtkWidget *button;
		GtkWidget *label;
		GMenuModel *submenu;

		/* recurse into sections */
		submenu = g_menu_model_get_item_link (menu, i, G_MENU_LINK_SECTION);
		if (submenu != NULL) {
			need_separator = append_menu (bar, submenu, TRUE);
			continue;
		}

		/* if this item and the previous item are in different sections, add
		 * a separator between them.  this may not be a good idea.
		 */
		if (need_separator) {
			GtkWidget *sep;

			if (bar->priv->position > 0) {
				sep = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
				gtk_widget_show (sep);
				g_object_set (sep, "margin-start", 6, "margin-end", 6, NULL);
				gtk_grid_attach (GTK_GRID (bar), sep, bar->priv->position++, 0, 1, 1);
			}

			need_separator = FALSE;
		}

		button = NULL;

		/* submenus become menu buttons, normal items become buttons */
		submenu = g_menu_model_get_item_link (menu, i, G_MENU_LINK_SUBMENU);

		if (submenu != NULL) {
			button = gtk_menu_button_new ();
			gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), submenu);

			g_object_set_data_full (G_OBJECT (button), "rb-menu-model", g_object_ref (submenu), (GDestroyNotify)g_object_unref);
		} else {
			GMenuAttributeIter *iter;
			const char *name;
			GVariant *value;
			char *str;
			guint signal_id;
		
			/* we can't do more than one of action and rb-property-bind
			 * and rb-signal-bind, so just do whichever turns up first
			 * in the iterator
			 */
			iter = g_menu_model_iterate_item_attributes (menu, i);
			while (g_menu_attribute_iter_get_next (iter, &name, &value)) {
				if (g_str_equal (name, "action")) {
					button = gtk_button_new ();
					g_variant_get (value, "s", &str, NULL);
					gtk_actionable_set_action_name (GTK_ACTIONABLE (button), str);
					/* action target too somehow? */
					g_free (str);
					break;
				} else if (g_str_equal (name, "rb-property-bind")) {
					/* property has to be a boolean, can't do inverts, etc. etc. */
					button = gtk_toggle_button_new ();
					g_variant_get (value, "s", &str, NULL);
					g_object_bind_property (bar->priv->target, str,
								button, "active",
								G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
					g_free (str);
					break;
				} else if (g_str_equal (name, "rb-signal-bind")) {
					button = gtk_button_new ();
					g_variant_get (value, "s", &str, NULL);
					signal_id = g_signal_lookup (str, G_OBJECT_TYPE (bar->priv->target));
					if (signal_id != 0) {
						g_object_set_data (G_OBJECT (button), "rb-signal-bind-id", GUINT_TO_POINTER (signal_id));
						g_signal_connect (button, "clicked", G_CALLBACK (signal_button_clicked_cb), bar);
					}
					g_free (str);
					break;
				}
			}

			g_object_unref (iter);
		}

		if (button == NULL) {
			g_warning ("no idea what's going on here");
			continue;
		}

		gtk_widget_set_hexpand (button, FALSE);
		gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

		label_text = NULL;
		g_menu_model_get_item_attribute (menu, i, "label", "s", &label_text);
		label = gtk_label_new (g_dgettext (NULL, label_text));
		g_object_set (label, "margin-left", 6, "margin-right", 6, NULL);
		gtk_container_add (GTK_CONTAINER (button), label);

		if (g_menu_model_get_item_attribute (menu, i, "accel", "s", &accel)) {
			g_object_set_data_full (G_OBJECT (button), "rb-accel", accel, (GDestroyNotify) g_free);
		}

		gtk_widget_show_all (button);
		gtk_size_group_add_widget (bar->priv->size_group, button);
		gtk_grid_attach (GTK_GRID (bar), button, bar->priv->position++, 0, 1, 1);

		g_free (label_text);
	}

	return need_separator;
}
Пример #12
0
static void
append_items_from_model (GtkWidget    *menu,
                         GMenuModel   *model,
                         GActionGroup *group,
                         gboolean     *need_separator,
                         const gchar  *heading)
{
  gint n;
  gint i;
  GtkWidget *w;
  GtkWidget *menuitem;
  GtkWidget *submenu;
  GMenuModel *m;
  gchar *label;

  n = g_menu_model_get_n_items (model);

  if (*need_separator && n > 0)
    {
      w = gtk_separator_menu_item_new ();
      gtk_widget_show (w);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
      *need_separator = FALSE;
    }

  if (heading != NULL)
    {
      w = gtk_menu_item_new_with_label (heading);
      gtk_widget_show (w);
      gtk_widget_set_sensitive (w, FALSE);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
    }

  for (i = 0; i < n; i++)
    {
      if ((m = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION)))
        {
          label = NULL;
          g_menu_model_get_item_attribute (model, i, G_MENU_ATTRIBUTE_LABEL, "s", &label);
          append_items_from_model (menu, m, group, need_separator, label);
          g_object_unref (m);
          g_free (label);

          if (*need_separator)
            {
              w = gtk_separator_menu_item_new ();
              gtk_widget_show (w);
              gtk_menu_shell_append (GTK_MENU_SHELL (menu), w);
              *need_separator = FALSE;
            }

          continue;
        }

      menuitem = create_menuitem_from_model (model, i, group);

      if ((m = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU)))
        {
          submenu = create_menu_from_model (m, group);
          gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
          g_object_unref (m);
        }

      gtk_widget_show (menuitem);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);

      *need_separator = TRUE;
    }
}
Пример #13
0
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;
}