コード例 #1
0
ファイル: toggleaction.c プロジェクト: RainMark/gtk3-tutorial
int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);
    
    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
    g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
    
    GtkWidget *menubar = gtk_menu_bar_new();
    gtk_container_add(GTK_CONTAINER(window), menubar);

    GtkActionGroup *actiongroup = gtk_action_group_new("ActionGroup");
    
    GtkAction *action = gtk_action_new("actionFile", "_File", NULL, NULL);
    gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), action);
    GtkWidget *menuitemFile = gtk_action_create_menu_item(GTK_ACTION(action));
    gtk_menu_bar_append(GTK_MENU_BAR(menubar), menuitemFile);
    
    GtkWidget *menu = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitemFile), menu);
    
    GtkToggleAction *toggleaction;
    
    toggleaction = gtk_toggle_action_new("actionNew", "_New", "Create a new document", GTK_STOCK_NEW);
    gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(toggleaction), TRUE);
    gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), GTK_ACTION(toggleaction));
    GtkWidget *menuitemNew = gtk_action_create_menu_item(GTK_ACTION(toggleaction));
    gtk_menu_append(GTK_MENU(menu), menuitemNew);
    toggleaction = gtk_toggle_action_new("actionOpen", "_Open", "Open a file", GTK_STOCK_OPEN);
    gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), GTK_ACTION(toggleaction));
    GtkWidget *menuitemOpen = gtk_action_create_menu_item(GTK_ACTION(toggleaction));
    gtk_menu_append(GTK_MENU(menu), menuitemOpen);
    toggleaction = gtk_toggle_action_new("actionSave", "_Save", "Save a file", GTK_STOCK_SAVE);
    gtk_action_group_add_action(GTK_ACTION_GROUP(actiongroup), GTK_ACTION(toggleaction));
    GtkWidget *menuitemSave = gtk_action_create_menu_item(GTK_ACTION(toggleaction));
    gtk_menu_append(GTK_MENU(menu), menuitemSave);

    gtk_widget_show_all(window);
    
    gtk_main();
    
    return 0;
}
コード例 #2
0
GtkAction *
nautilus_action_from_menu_item (NautilusMenuItem *item)
{
	char *name, *label, *tip, *icon_name;
	gboolean sensitive, priority;
	GtkAction *action;
	GdkPixbuf *pixbuf;

	g_object_get (G_OBJECT (item),
		      "name", &name, "label", &label,
		      "tip", &tip, "icon", &icon_name,
		      "sensitive", &sensitive,
		      "priority", &priority,
		      NULL);

	action = gtk_action_new (name,
				 label,
				 tip,
				 NULL);

	if (icon_name != NULL) {
		pixbuf = nautilus_ui_get_menu_icon (icon_name);
		if (pixbuf != NULL) {
			gtk_action_set_gicon (action, G_ICON (pixbuf));
			g_object_unref (pixbuf);
		}
	}

	gtk_action_set_sensitive (action, sensitive);
	g_object_set (action, "is-important", priority, NULL);

	g_signal_connect_data (action, "activate",
			       G_CALLBACK (extension_action_callback),
			       g_object_ref (item),
			       (GClosureNotify)g_object_unref, 0);

	g_free (name);
	g_free (label);
	g_free (tip);
	g_free (icon_name);

	return action;
}
コード例 #3
0
ファイル: rbgtkaction.c プロジェクト: Mazwak/ruby-gnome2
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE name, label, tooltip, stock_id;
    const gchar *stock = NULL;

    rb_scan_args(argc, argv, "22", &name, &label, &tooltip, &stock_id);

    if (TYPE(stock_id) == T_SYMBOL) {
        stock = rb_id2name(SYM2ID(stock_id));
    } else if (TYPE(stock_id) == T_STRING){
        stock = RVAL2CSTR(stock_id);
    }

    G_INITIALIZE(self, gtk_action_new(RVAL2CSTR(name), RVAL2CSTR(label),
                                      NIL_P(tooltip) ? NULL : RVAL2CSTR(tooltip),
                                      stock));
    return Qnil;
}
コード例 #4
0
ファイル: rbgtk-action.c プロジェクト: Mazwak/ruby-gnome2
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE name, options, label, tooltip, stock_id, buffer;

    rb_scan_args(argc, argv, "11", &name, &options);
    rbg_scan_options(options,
                     "label", &label,
                     "tooltip", &tooltip,
                     "stock_id", &stock_id,
                     NULL);

    G_INITIALIZE(self, gtk_action_new(RVAL2CSTR(name),
                                      RVAL2CSTR_ACCEPT_NIL(label),
                                      RVAL2CSTR_ACCEPT_NIL(tooltip),
                                      RVAL2GLIBID_ACCEPT_NIL(stock_id, buffer)));

    return Qnil;
}
コード例 #5
0
ファイル: main.c プロジェクト: mcmihail/cinnamon-bluetooth
static GtkAction *
add_menu_item (const char *address,
	       const char *suffix,
	       const char *label,
	       GtkUIManager *uimanager,
	       guint merge_id,
	       GCallback callback)
{
	GtkAction *action;
	char *action_path, *action_name;

	g_return_val_if_fail (address != NULL, NULL);
	g_return_val_if_fail (suffix != NULL, NULL);
	g_return_val_if_fail (label != NULL, NULL);

	action_name = g_strdup_printf ("%s-%s", address, suffix);
	action = gtk_action_new (action_name, label, NULL, NULL);

	gtk_action_group_add_action (devices_action_group, action);
	g_object_unref (action);

	action_path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s", address);
	gtk_ui_manager_add_ui (uimanager, merge_id,
			       action_path, action_name, action_name,
			       GTK_UI_MANAGER_MENUITEM, FALSE);
	g_free (action_path);

	g_free (action_name);

	if (callback != NULL)
		g_signal_connect (G_OBJECT (action), "activate", callback, NULL);

	g_object_set_data_full (G_OBJECT (action),
				"address", g_strdup (address), g_free);

	return action;
}
コード例 #6
0
ファイル: menus.c プロジェクト: GNOME/dia
static guint
ensure_menu_path (GtkUIManager *ui_manager, GtkActionGroup *actions, const gchar *path, gboolean end)
{
  guint id = gtk_ui_manager_new_merge_id (ui_manager);

  if (!gtk_ui_manager_get_widget (ui_manager, path)) {
    gchar *subpath = g_strdup (path);

    if (strrchr (subpath, '/')) {
      const gchar *action_name;
      gchar *sep;

      GtkAction *action;

      sep = strrchr (subpath, '/');
      *sep = '\0'; /* cut subpath */
      action_name = sep + 1;

      ensure_menu_path (ui_manager, actions, subpath, FALSE);

      action = gtk_action_new (action_name, sep + 1, NULL, NULL);
      if (!gtk_action_group_get_action (actions, action_name))
        gtk_action_group_add_action (actions, action);
      g_object_unref (G_OBJECT (action));

      gtk_ui_manager_add_ui (ui_manager, id, subpath,
	                     action_name, action_name,
			     end ? GTK_UI_MANAGER_SEPARATOR : GTK_UI_MANAGER_MENU,
			     FALSE); /* FALSE=add-to-end */
    } else {
      g_warning ("ensure_menu_path() invalid menu path: %s.", subpath ? subpath : "NULL");
    }
    g_free (subpath);
  }
  return id;
}
コード例 #7
0
ファイル: actions1.c プロジェクト: laubstein/pw3270
 void init_actions(void)
 {
	static const gchar	*group_name[]	= { "default", "online", "offline", "selection", "clipboard", "paste", "filetransfer" };
 	GtkAction				*dunno			= gtk_action_new("Dunno",NULL,NULL,NULL);
	int						f;

	#ifdef DEBUG
		if(ACTION_GROUP_MAX != G_N_ELEMENTS(group_name))
		{
			Trace("Unexpected action_group size, found %d, expecting %d",(int) G_N_ELEMENTS(group_name),(int) ACTION_GROUP_MAX);
			exit(-1);
		}
	#endif

	for(f=0;f<ACTION_GROUP_MAX;f++)
	{
		action_group[f] = gtk_action_group_new(group_name[f]);

		Trace("action(%d): %p %s",f,action_group[f],group_name[f]);
		gtk_action_group_set_translation_domain(action_group[f], PACKAGE_NAME);
	}

	action_group[f] = 0;
	g_object_set_data(G_OBJECT(topwindow),"ActionGroups",action_group);

	for(f=0;f<G_N_ELEMENTS(action_by_id);f++)
		action_by_id[f] = dunno;

#ifdef 	X3270_FT
	set_ft_action_state(hSession,0,NULL);
	register_schange(ST_3270_MODE, set_ft_action_state);
#else
	gtk_action_group_set_sensitive(ft_actions,FALSE);
#endif

 }
コード例 #8
0
ファイル: main.c プロジェクト: gergelypolonkai/magus-kargen
int
main(int argc, char **argv)
{
	GtkWidget *menubar,
			  *pri_vbox,
			  *tabla,
			  *scroll;
	GtkAccelGroup *accel_group;
	GtkUIManager *ui_manager;
	GtkAction *action;

	LIBXML_TEST_VERSION

	karakter_betoltes("ruin.xml");
	//return 0;

	gtk_init(&argc, &argv);

	action_group = gtk_action_group_new("main_menu");

	action = gtk_action_new("uj-karakter", "Új karakter", "Új karakter létrehozása", GTK_STOCK_NEW);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>N");

	action = gtk_action_new("karakter-megnyitas", "Karakter megnyitása", "Elmentett karakter megnyitása", GTK_STOCK_OPEN);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>O");

	action = gtk_action_new("karakter-mentes", "Karakter mentése", "Karakter adatainak mentése", GTK_STOCK_SAVE);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>S");

	action = gtk_action_new("kilepes", "Kilépés", "Kilépés a programból", GTK_STOCK_QUIT);
	gtk_action_group_add_action_with_accel(action_group, action, "<Control>Q");
	g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(kilepes_func), NULL);

	action = gtk_action_new("karakter-menu", "Karakter", "Karakter", NULL);
	gtk_action_group_add_action(action_group, action);

	gtk_action_group_add_radio_actions(action_group, menu_items, nezet_menu_szama, 0, G_CALLBACK(nezet_menu), NULL);
	action = gtk_action_new("nezet-menu", "Nézet", "Nézet", NULL);
	gtk_action_group_add_action(action_group, action);

	ui_manager = gtk_ui_manager_new();
	gtk_ui_manager_set_add_tearoffs(ui_manager, FALSE);
	gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
	gtk_ui_manager_add_ui_from_file(ui_manager, "magus_kargen_res.ui", NULL);

	accel_group = gtk_accel_group_new();

	main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(main_window), "destroy", G_SIGNAL_FUNC(main_window_destroy), NULL);
	gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group);
	gtk_window_set_title(GTK_WINDOW(main_window), "M.A.G.U.S. - Reneszánsz karakternyilvántartó");

	menubar = gtk_ui_manager_get_widget(ui_manager, "/menu");

	book = gtk_notebook_new();
	gtk_notebook_set_scrollable(GTK_NOTEBOOK(book), TRUE);
	gtk_notebook_popup_enable(GTK_NOTEBOOK(book));
	g_signal_connect(GTK_OBJECT(book), "change-current-page", G_SIGNAL_FUNC(lapvaltas), NULL);

	/* Azonnal látható és hallható dolgok */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(18, 2, FALSE);
	azonnal_lathato_dolgok_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(EGYBOL_LATHATO_HALLHATO_DOLGOK));

	/* A játékos és a karakter adatai */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(4, 2, FALSE);
	jatekos_es_karakter_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(A_JATEKOS_ES_A_KARAKTER_ADATAI));

	/* Képességek */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(10, 2, FALSE);
	kepessegek_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(KEPESSEGEK));

	/* Főbb adatok */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(26, 4, FALSE);
	fobb_adatok_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(A_KARAKTER_FOBB_ADATAI));

	/* Megjelenés */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(10, 4, FALSE);
	megjelenes_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(MEGJELENES));

	/* Állandó érzelmek */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(15, 2, FALSE);
	erzelmek_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(ALLANDO_ERZELMEK));

	/* Szimpatikus viszonyok. Ide majd egy TableView kene */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(SZIMPATIKUS_VISZONYOK));

	/* Kapcsolatok, ismertseg. Ide majd egy TableView kene */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ISMERTSEG));

	/* Kulonleges kepessegek, hatranyok. Ide is TableView kene */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KULONLEGES_KEPESSEGEK));

	/* Tapasztalati pontok, átváltás */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(3, 2, FALSE);
	tapasztalat_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(TAPASZTALATI_PONTOK));

	/* Képzettségek. Ide majd egy TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KEPZETTSEGEK));

	/* Nyelvek. Ide is TableView */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(NYELVEK));

	/* Harcértékek */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(5, 4, FALSE);
	harcertekek_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(HARCERTEKEK));

	/* Életerő */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(3, 4, FALSE);
	eletero_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(ELETERO));

	/* Pszi */
	scroll = gtk_scrolled_window_new(NULL, NULL);
	tabla = gtk_table_new(5, 2, FALSE);
	pszi_lap(GTK_TABLE(tabla));
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), tabla);
	gtk_notebook_append_page(GTK_NOTEBOOK(book), scroll, gtk_label_new(PSZI));

	/* Mágia */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MAGIA));

	/* Fegyverek és pajzsok. Ide két TableView kell. */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(FEGYVEREK_PAJZS));

	/* Állatok, csatlósok, szolgák. Ide sok TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ALLATOK_CSATLOSOK));

	/* Mesterek és tanítók. Ide két TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MESTEREK));

	/* Földbirtokok. Ide is TableView kell */
	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(BIRTOKOK_BEFEKTETESEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ALAKULATOK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ISKOLAK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MUVEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(ERTEKEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(RUHAK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSTARGYAK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(FELSZERELES));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSLATOK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(TANULAS));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(SEBESULESEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(BETEGSEGEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(VARAZSLAT_KUTATAS));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KULONLEGES_DOLGOK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(MEGJEGYZESEK));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(TORTENET));

	gtk_notebook_append_page(GTK_NOTEBOOK(book), gtk_table_new(1, 1, FALSE), gtk_label_new(KEPEK));

	pri_vbox = gtk_vbox_new(FALSE, 0);

	gtk_box_pack_start(GTK_BOX(pri_vbox), menubar, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(pri_vbox), book, TRUE, TRUE, 0);

	gtk_container_add(GTK_CONTAINER(main_window), pri_vbox);

	gtk_widget_show_all(main_window);
	gtk_window_maximize(GTK_WINDOW(main_window));

	gtk_main();

	xmlCleanupParser();

	return 0;
}
コード例 #9
0
ファイル: ghid-main-menu.c プロジェクト: rlutz/pcb
/*! \brief Translate a resource tree into a menu structure
 *
 *  \param [in] menu    The GHidMainMenu widget to be acted on
 *  \param [in] shall   The base menu shell (a menu bar or popup menu)
 *  \param [in] res     The base of the resource tree
 * */
void
ghid_main_menu_real_add_resource (GHidMainMenu *menu, GtkMenuShell *shell,
                                  const Resource *res)
{
    int i, j;
    const Resource *tmp_res;
    gchar mnemonic = 0;

    for (i = 0; i < res->c; ++i)
    {
        const gchar *accel = NULL;
        char *menu_label;
        const char *res_val;
        const Resource *sub_res = res->v[i].subres;
        GtkAction *action = NULL;

        switch (resource_type (res->v[i]))
        {
        case 101:   /* name, subres: passthrough */
            ghid_main_menu_real_add_resource (menu, shell, sub_res);
            break;
        case   1:   /* no name, subres */
            tmp_res = resource_subres (sub_res, "a");  /* accelerator */
            res_val = resource_value (sub_res, "m");   /* mnemonic */
            if (res_val)
                mnemonic = res_val[0];
            /* The accelerator resource will have two values, like
             *   a={"Ctrl-Q" "Ctrl<Key>q"}
             * The first Gtk ignores. The second needs to be translated. */
            if (tmp_res)
                accel = check_unique_accel
                        (translate_accelerator (tmp_res->v[1].value));

            /* Now look for the first unnamed value (not a subresource) to
             * figure out the name of the menu or the menuitem. */
            res_val = "button";
            for (j = 0; j < sub_res->c; ++j)
                if (resource_type (sub_res->v[j]) == 10)
                {
                    res_val = _(sub_res->v[j].value);
                    break;
                }
            /* Hack '_' in based on mnemonic value */
            if (!mnemonic)
                menu_label = g_strdup (res_val);
            else
            {
                char *post_ = strchr (res_val, mnemonic);
                if (post_ == NULL)
                    menu_label = g_strdup (res_val);
                else
                {
                    GString *tmp = g_string_new ("");
                    g_string_append_len (tmp, res_val, post_ - res_val);
                    g_string_append_c (tmp, '_');
                    g_string_append (tmp, post_);
                    menu_label = g_string_free (tmp, FALSE);
                }
            }
            /* If the subresource we're processing also has unnamed
             * subresources, it's a submenu, not a regular menuitem. */
            if (sub_res->flags & FLAG_S)
            {
                /* SUBMENU */
                GtkWidget *submenu = gtk_menu_new ();
                GtkWidget *item = gtk_menu_item_new_with_mnemonic (menu_label);
                GtkWidget *tearoff = gtk_tearoff_menu_item_new ();

                gtk_menu_shell_append (shell, item);
                gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);

                /* add tearoff to menu */
                gtk_menu_shell_append (GTK_MENU_SHELL (submenu), tearoff);
                /* recurse on the newly-added submenu */
                ghid_main_menu_real_add_resource (menu,
                                                  GTK_MENU_SHELL (submenu),
                                                  sub_res);
            }
            else
            {
                /* NON-SUBMENU: MENU ITEM */
                const char *checked = resource_value (sub_res, "checked");
                const char *label = resource_value (sub_res, "sensitive");
                const char *tip = resource_value (sub_res, "tip");
                if (checked)
                {
                    /* TOGGLE ITEM */
                    gchar *name = g_strdup_printf ("MainMenuAction%d",
                                                   action_counter++);

                    action = GTK_ACTION (gtk_toggle_action_new (name, menu_label,
                                         tip, NULL));
                    /* checked=foo       is a binary flag (checkbox)
                     * checked=foo,bar   is a flag compared to a value (radio) */
                    gtk_toggle_action_set_draw_as_radio
                    (GTK_TOGGLE_ACTION (action), !!strchr (checked, ','));
                }
                else if (label && strcmp (label, "false") == 0)
                {
                    /* INSENSITIVE ITEM */
                    GtkWidget *item = gtk_menu_item_new_with_label (menu_label);
                    gtk_widget_set_sensitive (item, FALSE);
                    gtk_menu_shell_append (shell, item);
                }
                else
                {
                    /* NORMAL ITEM */
                    gchar *name = g_strdup_printf ("MainMenuAction%d", action_counter++);
                    action = gtk_action_new (name, menu_label, tip, NULL);
                }
            }
            /* Connect accelerator, if there is one */
            if (action)
            {
                GtkWidget *item;
                gtk_action_set_accel_group (action, menu->accel_group);
                gtk_action_group_add_action_with_accel (menu->action_group,
                                                        action, accel);
                gtk_action_connect_accelerator (action);
                g_signal_connect (G_OBJECT (action), "activate", menu->action_cb,
                                  (gpointer) sub_res);
                g_object_set_data (G_OBJECT (action), "resource",
                                   (gpointer) sub_res);
                item = gtk_action_create_menu_item (action);
                gtk_menu_shell_append (shell, item);
                menu->actions = g_list_append (menu->actions, action);
                menu->special_key_cb (accel, action, sub_res);
            }
            /* Scan rest of resource in case there is more work */
            for (j = 0; j < sub_res->c; j++)
            {
                const char *res_name;
                /* named value = X resource */
                if (resource_type (sub_res->v[j]) == 110)
                {
                    res_name = sub_res->v[j].name;

                    /* translate bg, fg to background, foreground */
                    if (strcmp (res_name, "fg") == 0)   res_name = "foreground";
                    if (strcmp (res_name, "bg") == 0)   res_name = "background";

                    /* ignore special named values (m, a, sensitive) */
                    if (strcmp (res_name, "m") == 0
                            || strcmp (res_name, "a") == 0
                            || strcmp (res_name, "sensitive") == 0
                            || strcmp (res_name, "tip") == 0)
                        break;

                    /* log checked and active special values */
                    if (action && strcmp (res_name, "checked") == 0)
                        g_object_set_data (G_OBJECT (action), "checked-flag",
                                           sub_res->v[j].value);
                    else if (action && strcmp (res_name, "active") == 0)
                        g_object_set_data (G_OBJECT (action), "active-flag",
                                           sub_res->v[j].value);
                    else
                        /* if we got this far it is supposed to be an X
                         * resource.  For now ignore it and warn the user */
                        Message (_("The gtk gui currently ignores \"%s\""
                                   "as part of a menuitem resource.\n"
                                   "Feel free to provide patches\n"),
                                 sub_res->v[j].value);
                }
            }
            break;
        case  10:   /* no name, value */
            /* If we get here, the resource is "-" or "@foo" for some foo */
            if (res->v[i].value[0] == '@')
            {
                GList *children;
                int pos;

                children = gtk_container_get_children (GTK_CONTAINER (shell));
                pos = g_list_length (children);
                g_list_free (children);

                if (strcmp (res->v[i].value, "@layerview") == 0)
                {
                    menu->layer_view_shell = shell;
                    menu->layer_view_pos = pos;
                }
                else if (strcmp (res->v[i].value, "@layerpick") == 0)
                {
                    menu->layer_pick_shell = shell;
                    menu->layer_pick_pos = pos;
                }
                else if (strcmp (res->v[i].value, "@routestyles") == 0)
                {
                    menu->route_style_shell = shell;
                    menu->route_style_pos = pos;
                }
                else
                    Message (_("GTK GUI currently ignores \"%s\" in the menu\n"
                               "resource file.\n"), res->v[i].value);
            }
            else if (strcmp (res->v[i].value, "-") == 0)
            {
                GtkWidget *item = gtk_separator_menu_item_new ();
                gtk_menu_shell_append (shell, item);
            }
            else if (i > 0)
            {
                /* This is an action-less menuitem. It is really only useful
                 * when you're starting to build a new menu and you're looking
                 * to get the layout right. */
                GtkWidget *item
                    = gtk_menu_item_new_with_label (_(res->v[i].value));
                gtk_menu_shell_append (shell, item);
            }
            break;
        }
    }
}
コード例 #10
0
/**
 * nautilus_window_initialize_menus
 *
 * Create and install the set of menus for this window.
 * @window: A recently-created NautilusWindow.
 */
void
nautilus_window_initialize_menus (NautilusWindow *window)
{
    GtkActionGroup *action_group;
    GtkUIManager *ui_manager;
    GtkAction *action;
    gint i;

    window->details->ui_manager = gtk_ui_manager_new ();
    ui_manager = window->details->ui_manager;

    /* shell actions */
    action_group = gtk_action_group_new ("ShellActions");
    gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
    window->details->main_action_group = action_group;
    gtk_action_group_add_actions (action_group,
                                  main_entries, G_N_ELEMENTS (main_entries),
                                  window);
    gtk_action_group_add_toggle_actions (action_group,
                                         main_toggle_entries, G_N_ELEMENTS (main_toggle_entries),
                                         window);
    gtk_action_group_add_radio_actions (action_group,
                                        view_radio_entries, G_N_ELEMENTS (view_radio_entries),
                                        -1, G_CALLBACK (action_view_radio_changed),
                                        window);

    action = nautilus_option_menu_action_new ("Zoom Options",
             _("Zoom"), _("Zoom Options"), NULL);
    gtk_action_group_add_action (action_group, action);
    g_object_unref (action);

    nautilus_window_menus_set_visibility_for_app_menu (window);
    window->details->app_menu_visibility_id =
        g_signal_connect_swapped (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
                                  "notify::gtk-shell-shows-app-menu",
                                  G_CALLBACK (nautilus_window_menus_set_visibility_for_app_menu), window);

    action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_UP);
    g_object_set (action, "short_label", _("_Up"), NULL);

    action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_HOME);
    g_object_set (action, "short_label", _("_Home"), NULL);

    /* Alt+N for the first 10 tabs */
    for (i = 0; i < 10; ++i) {
        gchar action_name[80];
        gchar accelerator[80];

        snprintf(action_name, sizeof (action_name), "Tab%d", i);
        action = gtk_action_new (action_name, NULL, NULL, NULL);
        g_object_set_data (G_OBJECT (action), "num", GINT_TO_POINTER (i));
        g_signal_connect (action, "activate",
                          G_CALLBACK (action_tab_change_action_activate_callback), window);
        snprintf(accelerator, sizeof (accelerator), "<alt>%d", (i+1)%10);
        gtk_action_group_add_action_with_accel (action_group, action, accelerator);
        g_object_unref (action);
        gtk_ui_manager_add_ui (ui_manager,
                               gtk_ui_manager_new_merge_id (ui_manager),
                               "/",
                               action_name,
                               action_name,
                               GTK_UI_MANAGER_ACCELERATOR,
                               FALSE);

    }

    gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
    g_object_unref (action_group); /* owned by ui_manager */

    gtk_window_add_accel_group (GTK_WINDOW (window),
                                gtk_ui_manager_get_accel_group (ui_manager));

    g_signal_connect (ui_manager, "connect-proxy",
                      G_CALLBACK (connect_proxy_cb), window);

    /* add the UI */
    gtk_ui_manager_add_ui_from_resource (ui_manager, "/org/gnome/nautilus/nautilus-shell-ui.xml", NULL);

    /* set actions for option menu items */
    populate_option_menu_items (window);
}
コード例 #11
0
ファイル: nemo-window-menus.c プロジェクト: fossamikom/nemo
/**
 * nemo_window_initialize_menus
 * 
 * Create and install the set of menus for this window.
 * @window: A recently-created NemoWindow.
 */
void 
nemo_window_initialize_menus (NemoWindow *window)
{
	GtkActionGroup *action_group;
	GtkUIManager *ui_manager;
	GtkAction *action;
	gint i;

	if (window->details->ui_manager == NULL){
        window->details->ui_manager = gtk_ui_manager_new ();
    }
	ui_manager = window->details->ui_manager;

	/* shell actions */
	action_group = gtk_action_group_new ("ShellActions");
	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
	window->details->main_action_group = action_group;
	gtk_action_group_add_actions (action_group, 
				      main_entries, G_N_ELEMENTS (main_entries),
				      window);
	gtk_action_group_add_toggle_actions (action_group, 
					     main_toggle_entries, G_N_ELEMENTS (main_toggle_entries),
					     window);
	gtk_action_group_add_radio_actions (action_group,
					    main_radio_entries, G_N_ELEMENTS (main_radio_entries),
					    0, G_CALLBACK (sidebar_radio_entry_changed_cb),
					    window);

	action = gtk_action_group_get_action (action_group, NEMO_ACTION_UP);
	g_object_set (action, "short_label", _("_Up"), NULL);

	action = gtk_action_group_get_action (action_group, NEMO_ACTION_HOME);
	g_object_set (action, "short_label", _("_Home"), NULL);

  	action = gtk_action_group_get_action (action_group, NEMO_ACTION_EDIT_LOCATION);
  	g_object_set (action, "short_label", _("_Location"), NULL);

	action = gtk_action_group_get_action (action_group, NEMO_ACTION_SHOW_HIDDEN_FILES);
	g_signal_handlers_block_by_func (action, action_show_hidden_files_callback, window);
	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
				      g_settings_get_boolean (nemo_preferences, NEMO_PREFERENCES_SHOW_HIDDEN_FILES));
	g_signal_handlers_unblock_by_func (action, action_show_hidden_files_callback, window);


	g_signal_connect_swapped (nemo_preferences, "changed::" NEMO_PREFERENCES_SHOW_HIDDEN_FILES,
				  G_CALLBACK(show_hidden_files_preference_callback),
				  window);

	/* Alt+N for the first 10 tabs */
	for (i = 0; i < 10; ++i) {
		gchar action_name[80];
		gchar accelerator[80];

		snprintf(action_name, sizeof (action_name), "Tab%d", i);
		action = gtk_action_new (action_name, NULL, NULL, NULL);
		g_object_set_data (G_OBJECT (action), "num", GINT_TO_POINTER (i));
		g_signal_connect (action, "activate",
				G_CALLBACK (action_tab_change_action_activate_callback), window);
		snprintf(accelerator, sizeof (accelerator), "<alt>%d", (i+1)%10);
		gtk_action_group_add_action_with_accel (action_group, action, accelerator);
		g_object_unref (action);
		gtk_ui_manager_add_ui (ui_manager,
				gtk_ui_manager_new_merge_id (ui_manager),
				"/",
				action_name,
				action_name,
				GTK_UI_MANAGER_ACCELERATOR,
				FALSE);

	}

	gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
	g_object_unref (action_group); /* owned by ui_manager */

	gtk_window_add_accel_group (GTK_WINDOW (window),
				    gtk_ui_manager_get_accel_group (ui_manager));
	
	g_signal_connect (ui_manager, "connect_proxy",
			  G_CALLBACK (connect_proxy_cb), window);
	g_signal_connect (ui_manager, "disconnect_proxy",
			  G_CALLBACK (disconnect_proxy_cb), window);

	/* add the UI */
	gtk_ui_manager_add_ui_from_resource (ui_manager, "/org/nemo/nemo-shell-ui.xml", NULL);

	nemo_window_initialize_trash_icon_monitor (window);
	nemo_window_initialize_go_menu (window);
}
コード例 #12
0
ファイル: actions1.c プロジェクト: laubstein/pw3270
 GtkAction * create_action_by_descriptor(const gchar *name, struct action_descriptor *data)
 {
	int			state		= data->attr.key_state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_ALT_MASK);
	int			f;

//	Trace("%s: %d",name,data->ui_type);

	switch(data->ui_type)
	{
	case UI_CALLBACK_TYPE_TOGGLE:
		data->action = GTK_ACTION(gtk_toggle_action_new(name, gettext(data->attr.label ? data->attr.label : data->name), gettext(data->attr.tooltip), data->attr.stock_id));
		break;

	case UI_CALLBACK_TYPE_DEFAULT:
		data->action = gtk_action_new(name, gettext(data->attr.label ? data->attr.label : data->name), gettext(data->attr.tooltip),data->attr.stock_id);
		break;

	case UI_CALLBACK_TYPE_SCROLL:
		if(data->sub >= 0 && data->sub <= G_N_ELEMENTS(action_scroll))
			action_scroll[data->sub] = data->action = gtk_action_new(name, gettext(data->attr.label ? data->attr.label : data->name), gettext(data->attr.tooltip),data->attr.stock_id);
		break;

	case UI_CALLBACK_TYPE_SCRIPT:

		if(data->script.text)
			g_object_set_data_full(G_OBJECT(data->action),"script_text",g_strdup(data->script.text),g_free);

		if(data->callback)
			g_signal_connect(G_OBJECT(data->action),"activate",G_CALLBACK(data->callback),topwindow);
		else
			g_signal_connect(G_OBJECT(data->action),"activate",G_CALLBACK(action_script_activated),topwindow);

		data->callback = 0;
		break;

	default:
		Trace("Invalid action type %d in %s",data->ui_type,data->name);
		return NULL;
	}

//	Trace("%s(%s), callback: %p action: %p",__FUNCTION__,name,data->callback,data->action);

	if(data->callback)
		g_signal_connect(G_OBJECT(data->action),data->ui_type == UI_CALLBACK_TYPE_TOGGLE ? "toggled" : "activate",G_CALLBACK(data->callback),data->user_data);

	// Check for special keyboard action
	for(f=0;f<G_N_ELEMENTS(keyboard_action);f++)
	{
		if(data->attr.key_value == keyboard_action[f].keyval && (state == keyboard_action[f].state))
		{
			keyboard_action[f].action = data->action;
			gtk_action_group_add_action(action_group[data->group],data->action);
			return data->action;
		}
	}

	// Check for PF actions
	if(data->attr.key_value >= GDK_F1 && data->attr.key_value <= GDK_F12 && !(state & (GDK_CONTROL_MASK|GDK_ALT_MASK)))
	{
		f = data->attr.key_value - GDK_F1;

		if(state&GDK_SHIFT_MASK)
			pf_action[f].shift = data->action;
		else
			pf_action[f].normal = data->action;
		gtk_action_group_add_action(action_group[data->group],data->action);
		return data->action;
	}

	// Register action
	if(data->attr.accel)
		gtk_action_group_add_action_with_accel(action_group[data->group],data->action,data->attr.accel);
	else
		gtk_action_group_add_action(action_group[data->group],data->action);

	return data->action;
 }
コード例 #13
0
ファイル: anjuta-command-bar.c プロジェクト: kyoushuu/anjuta
/**
 * anjuta_command_bar_add_action_group:
 * @self: An AnjutaCommandBar
 * @group_name: A unique name for this group of entries
 * @entries: (array length=num_entries): A list of entries to add
 * @num_entries: The number of items pointed to by entries
 * @user_data: User data to pass to the entry callback
 * 
 * Adds a group of entries to an AnjutaCommandBar.
 */
void 
anjuta_command_bar_add_action_group (AnjutaCommandBar *self, 
                                     const gchar *group_name, 
                                     const AnjutaCommandBarEntry *entries,
                                     int num_entries, gpointer user_data)
{
	GtkWidget *vbox;
	GtkWidget *scrolled_window;
	GtkWidget *current_vbox;
	GtkActionGroup *action_group;
	int i;
	
	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
	                                GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
	                                     GTK_SHADOW_IN);

	g_hash_table_insert (self->priv->widgets, (gchar *) group_name, 
	                     scrolled_window);

	action_group = gtk_action_group_new (group_name);

	g_hash_table_insert (self->priv->action_groups, (gchar *) group_name,
	                     action_group);

	/* The current_vbox is the vbox we're currently adding buttons to. As 
	 * frame entries are encountered, the current box changes to the newly 
	 * created frame vbox. But start by adding any other buttons to the top
	 * level vbox. */
	current_vbox = vbox;

	for (i = 0; i < num_entries; i++)
	{
		if (entries[i].type == ANJUTA_COMMAND_BAR_ENTRY_BUTTON)
		{
			GtkAction *action;
			GtkWidget *button;
			GtkWidget *button_box;
			GtkWidget *button_label;
			

			action = gtk_action_new (entries[i].action_name, _(entries[i].label), 
			                         _(entries[i].tooltip), entries[i].stock_icon);
			button = gtk_button_new();
			button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
			gtk_container_add (GTK_CONTAINER (button), button_box);

			gtk_action_group_add_action (action_group, action);
			
			gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

			if (entries[i].stock_icon)
			{
				GtkWidget* image;
				image = gtk_action_create_icon (action, 
				                                GTK_ICON_SIZE_BUTTON);
				gtk_box_pack_start (GTK_BOX (button_box), image, FALSE, FALSE, 5);
			}

			gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), 
			                                    action);
			button_label = gtk_label_new (gettext(entries[i].label));
			gtk_label_set_width_chars (GTK_LABEL (button_label), self->priv->max_text_width);
			gtk_label_set_line_wrap (GTK_LABEL (button_label), TRUE);
			gtk_misc_set_alignment (GTK_MISC (button_label), 0, 0.5);
			gtk_box_pack_start (GTK_BOX (button_box), button_label,
			                    FALSE, FALSE, 5);
			gtk_widget_show_all (button);
			

			g_signal_connect (G_OBJECT (action), "activate",
			                  entries[i].callback,
			                  user_data);

			/* Left-align button contents */
			g_object_set (G_OBJECT (button), "xalign", 0.0, NULL);

			gtk_box_pack_start (GTK_BOX (current_vbox), button, FALSE, FALSE, 
			                    2);
		}
		else
		{
			gchar *frame_label_text;
			GtkWidget *frame_label;
			GtkWidget *frame;
			GtkWidget *frame_vbox;
			
			frame_label_text = g_strdup_printf ("<b>%s</b>", _(entries[i].label));
			frame_label = gtk_label_new (NULL);
			frame = gtk_frame_new (NULL);
			
			gtk_label_set_markup(GTK_LABEL (frame_label), frame_label_text);
			gtk_frame_set_label_widget (GTK_FRAME (frame), frame_label);

			g_free (frame_label_text);
			
			frame_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);

			g_object_set (G_OBJECT (frame), "shadow-type", GTK_SHADOW_NONE, 
			              NULL);

			gtk_container_add (GTK_CONTAINER (frame), frame_vbox);
			gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 2);

			current_vbox = frame_vbox;
		}
	}

	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
	                                       vbox);
	gtk_widget_show_all (scrolled_window);
	gtk_notebook_append_page (GTK_NOTEBOOK (self), scrolled_window, NULL);
}
コード例 #14
0
ファイル: tilda_terminal.c プロジェクト: JaewookYim/tilda
static void popup_menu (tilda_window *tw, tilda_term *tt)
{
    DEBUG_FUNCTION ("popup_menu");
    DEBUG_ASSERT (tw != NULL);
    DEBUG_ASSERT (tt != NULL);

    GtkAction *action;
    GtkActionGroup *action_group;
    GtkUIManager *ui_manager;
    GError *error = NULL;
    GtkWidget *menu;

    /* Just use a static string here to initialize the GtkUIManager,
     * rather than installing and reading from a file all the time. */
    static const gchar menu_str[] =
        "<ui>"
            "<popup name=\"popup-menu\">"
                "<menuitem action=\"new-tab\" />"
                "<menuitem action=\"close-tab\" />"
                "<separator />"
                "<menuitem action=\"copy\" />"
                "<menuitem action=\"paste\" />"
                "<separator />"
                "<menuitem action=\"fullscreen\" />"
                "<separator />"
                "<menuitem action=\"preferences\" />"
                "<separator />"
                "<menuitem action=\"quit\" />"
            "</popup>"
        "</ui>";

    /* Create the action group */
    action_group = gtk_action_group_new ("popup-menu-action-group");

    /* Add Actions and connect callbacks */
    action = gtk_action_new ("new-tab", _("_New Tab"), NULL, GTK_STOCK_ADD);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("addtab_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_add_tab_cb), tw);

    action = gtk_action_new ("close-tab", _("_Close Tab"), NULL, GTK_STOCK_CLOSE);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("closetab_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_close_tab_cb), tw);

    action = gtk_action_new ("copy", NULL, NULL, GTK_STOCK_COPY);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("copy_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_copy_cb), tt);

    action = gtk_action_new ("paste", NULL, NULL, GTK_STOCK_PASTE);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("paste_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_paste_cb), tt);

    action = gtk_action_new ("fullscreen", _("Toggle fullscreen"), NULL, NULL);
    gtk_action_group_add_action (action_group, action);
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_fullscreen_cb), tw);

    action = gtk_action_new ("preferences", NULL, NULL, GTK_STOCK_PREFERENCES);
    gtk_action_group_add_action (action_group, action);
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_preferences_cb), tw);

    action = gtk_action_new ("quit", NULL, NULL, GTK_STOCK_QUIT);
    gtk_action_group_add_action_with_accel (action_group, action, config_getstr("quit_key"));
    g_signal_connect (G_OBJECT(action), "activate", G_CALLBACK(menu_quit_cb), tw);

    /* Create and add actions to the GtkUIManager */
    ui_manager = gtk_ui_manager_new ();
    gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
    gtk_ui_manager_add_ui_from_string (ui_manager, menu_str, -1, &error);

    /* Check for an error (REALLY REALLY unlikely, unless the developers screwed up */
    if (error)
    {
        DEBUG_ERROR ("GtkUIManager problem\n");
        g_printerr ("Error message: %s\n", error->message);
        g_error_free (error);
    }

    /* Get the popup menu out of the GtkUIManager */
    menu = gtk_ui_manager_get_widget (ui_manager, "/ui/popup-menu");

    /* Disable auto hide */
    tw->disable_auto_hide = TRUE;
    g_signal_connect (G_OBJECT(menu), "unmap", G_CALLBACK(on_popup_hide), tw);

    /* Display the menu */
    gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, gtk_get_current_event_time());
    gtk_widget_show_all(menu);
}
コード例 #15
0
ファイル: gtkhtml-editor-private.c プロジェクト: 0lvin/ghtml
static void
editor_inline_spelling_suggestions (GtkhtmlEditor *editor,
                                    GtkhtmlSpellChecker *checker)
{
	GtkActionGroup *action_group;
	GtkUIManager *manager;
	GtkHTML *html;
	GList *list;
	const gchar *path;
	gchar *word;
	guint count = 0;
	guint length;
	guint merge_id;
	guint threshold;

	html = gtkhtml_editor_get_html (editor);
	word = html_engine_get_spell_word (html->engine);
	list = gtkhtml_spell_checker_get_suggestions (checker, word, -1);

	path = "/context-menu/context-spell-suggest/";
	manager = gtkhtml_editor_get_ui_manager (editor);
	action_group = editor->priv->suggestion_actions;
	merge_id = editor->priv->spell_suggestions_merge_id;

	/* Calculate how many suggestions to put directly in the
	 * context menu.  The rest will go in a secondary menu. */
	length = g_list_length (list);
	if (length <= MAX_LEVEL1_SUGGESTIONS)
		threshold = length;
	else if (length - MAX_LEVEL1_SUGGESTIONS < MIN_LEVEL2_SUGGESTIONS)
		threshold = length;
	else
		threshold = MAX_LEVEL1_SUGGESTIONS;

	while (list != NULL) {
		gchar *suggestion = list->data;
		gchar *action_name;
		gchar *action_label;
		GtkAction *action;
		GtkWidget *child;
		GSList *proxies;

		/* Once we reach the threshold, put all subsequent
		 * spelling suggestions in a secondary menu. */
		if (count == threshold)
			path = "/context-menu/context-more-suggestions-menu/";

		/* Action name just needs to be unique. */
		action_name = g_strdup_printf ("suggest-%d", count++);

		action_label = g_markup_printf_escaped (
			"<b>%s</b>", suggestion);

		action = gtk_action_new (
			action_name, action_label, NULL, NULL);

		g_object_set_data_full (
			G_OBJECT (action), "word",
			g_strdup (suggestion), g_free);

		g_signal_connect (
			action, "activate", G_CALLBACK (
			action_context_spell_suggest_cb), editor);

		gtk_action_group_add_action (action_group, action);

		gtk_ui_manager_add_ui (
			manager, merge_id, path,
			action_name, action_name,
			GTK_UI_MANAGER_AUTO, FALSE);

		/* XXX GtkAction offers no support for Pango markup,
		 *     so we have to manually set "use-markup" on the
		 *     child of the proxy widget. */
		gtk_ui_manager_ensure_update (manager);
		proxies = gtk_action_get_proxies (action);
		child = gtk_bin_get_child (proxies->data);
		g_object_set (child, "use-markup", TRUE, NULL);

		g_free (suggestion);
		g_free (action_name);
		g_free (action_label);

		list = g_list_delete_link (list, list);
	}

	g_free (word);
}
コード例 #16
0
ファイル: gtkhtml-editor-private.c プロジェクト: 0lvin/ghtml
/* Helper for gtkhtml_editor_update_context() */
static void
editor_spell_checkers_foreach (GtkhtmlSpellChecker *checker,
                               GtkhtmlEditor *editor)
{
	const GtkhtmlSpellLanguage *language;
	const gchar *language_code;
	GtkActionGroup *action_group;
	GtkUIManager *manager;
	GtkHTML *html;
	GList *list;
	gchar *path;
	gchar *word;
	gint count = 0;
	guint merge_id;

	language = gtkhtml_spell_checker_get_language (checker);
	language_code = gtkhtml_spell_language_get_code (language);

	html = gtkhtml_editor_get_html (editor);
	word = html_engine_get_spell_word (html->engine);
	list = gtkhtml_spell_checker_get_suggestions (checker, word, -1);

	manager = gtkhtml_editor_get_ui_manager (editor);
	action_group = editor->priv->suggestion_actions;
	merge_id = editor->priv->spell_suggestions_merge_id;

	path = g_strdup_printf (
		"/context-menu/context-spell-suggest/"
		"context-spell-suggest-%s-menu", language_code);

	while (list != NULL) {
		gchar *suggestion = list->data;
		gchar *action_name;
		gchar *action_label;
		GtkAction *action;
		GtkWidget *child;
		GSList *proxies;

		/* Action name just needs to be unique. */
		action_name = g_strdup_printf (
			"suggest-%s-%d", language_code, count++);

		action_label = g_markup_printf_escaped (
			"<b>%s</b>", suggestion);

		action = gtk_action_new (
			action_name, action_label, NULL, NULL);

		g_object_set_data_full (
			G_OBJECT (action), "word",
			g_strdup (suggestion), g_free);

		g_signal_connect (
			action, "activate", G_CALLBACK (
			action_context_spell_suggest_cb), editor);

		gtk_action_group_add_action (action_group, action);

		gtk_ui_manager_add_ui (
			manager, merge_id, path,
			action_name, action_name,
			GTK_UI_MANAGER_AUTO, FALSE);

		/* XXX GtkAction offers no supports for Pango markup,
		 *     so we have to manually set "use-markup" on the
		 *     child of the proxy widget. */
		gtk_ui_manager_ensure_update (manager);
		proxies = gtk_action_get_proxies (action);
		child = gtk_bin_get_child (proxies->data);
		g_object_set (child, "use-markup", TRUE, NULL);

		g_free (suggestion);
		g_free (action_name);
		g_free (action_label);

		list = g_list_delete_link (list, list);
	}

	g_free (path);
	g_free (word);
}
コード例 #17
0
ファイル: totem-youtube.c プロジェクト: fatman2021/Mate-Extra
static void
set_up_tree_view (TotemYouTubePlugin *self, GtkBuilder *builder, guint key)
{
	GtkUIManager *ui_manager;
	GtkActionGroup *action_group;
	GtkAction *action, *menu_item;
	GtkWidget *vscroll, *tree_view;
	GtkTreeViewColumn *column;
	GtkCellRenderer *renderer;

	/* Add the cell renderer. This can't be done with GtkBuilder, because it unavoidably sets the expand parameter to FALSE */
	/* TODO: Depends on bug #453692 */
	renderer = GTK_CELL_RENDERER (totem_cell_renderer_video_new (TRUE));
	column = GTK_TREE_VIEW_COLUMN (gtk_builder_get_object (builder,
							       (key == SEARCH_TREE_VIEW) ? "yt_treeview_search_column" : "yt_treeview_related_column"));
	gtk_tree_view_column_pack_start (column, renderer, TRUE);
	gtk_tree_view_column_set_attributes (column, renderer, "thumbnail", 0, "title", 1, NULL);

	/* Give the video lists a handle to Totem and connect their scrollbar signals */
	if (key == SEARCH_TREE_VIEW) {
		tree_view = GTK_WIDGET (gtk_builder_get_object (builder, "yt_treeview_search"));
		vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (gtk_builder_get_object (builder, "yt_scrolled_window_search")));
		self->list_store[key] = GTK_LIST_STORE (gtk_builder_get_object (builder, "yt_list_store_search"));
		self->tree_view[key] = GTK_TREE_VIEW (tree_view);
		self->progress_bar[key] = GTK_PROGRESS_BAR (gtk_builder_get_object (builder, "yt_progress_bar_search"));
	} else {
		tree_view = GTK_WIDGET (gtk_builder_get_object (builder, "yt_treeview_related"));
		vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (gtk_builder_get_object (builder, "yt_scrolled_window_related")));
		self->list_store[key] = GTK_LIST_STORE (gtk_builder_get_object (builder, "yt_list_store_related"));
		self->tree_view[key] = GTK_TREE_VIEW (tree_view);
		self->progress_bar[key] = GTK_PROGRESS_BAR (gtk_builder_get_object (builder, "yt_progress_bar_related"));
	}
	g_object_set (tree_view, "totem", self->totem, NULL);
	g_signal_connect (vscroll, "button-press-event", G_CALLBACK (button_press_event_cb), self);
	g_signal_connect (vscroll, "button-release-event", G_CALLBACK (button_release_event_cb), self);

	/* Add the extra popup menu options. This is done here rather than in the UI file, because it's done for multiple treeviews;
	 * if it were done in the UI file, the same action group would be used multiple times, which GTK+ doesn't like. */
	ui_manager = totem_video_list_get_ui_manager (TOTEM_VIDEO_LIST (tree_view));
	action_group = gtk_action_group_new ("youtube-action-group");
	action = gtk_action_new ("open-in-web-browser", _("_Open in Web Browser"), _("Open the video in your web browser"), "gtk-jump-to");
	gtk_action_group_add_action_with_accel (action_group, action, NULL);

	gtk_ui_manager_insert_action_group (ui_manager, action_group, 1);
	gtk_ui_manager_add_ui (ui_manager, gtk_ui_manager_new_merge_id (ui_manager),
			       "/ui/totem-video-list-popup/",
			       "open-in-web-browser",
			       "open-in-web-browser",
			       GTK_UI_MANAGER_MENUITEM,
			       FALSE);

	menu_item = gtk_ui_manager_get_action (ui_manager, "/ui/totem-video-list-popup/open-in-web-browser");
	g_signal_connect (menu_item, "activate", G_CALLBACK (open_in_web_browser_activate_cb), self);

	/* Connect to more scroll events */
	#if GTK_CHECK_VERSION(3, 0, 0)
		self->vadjust[key] = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(tree_view));
	#else
		self->vadjust[key] = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(tree_view));
	#endif

	g_signal_connect (self->vadjust[key], "value-changed", G_CALLBACK (value_changed_cb), self);

	self->cancel_button = GTK_WIDGET (gtk_builder_get_object (builder, "yt_cancel_button"));
}
コード例 #18
0
ファイル: menus.c プロジェクト: GNOME/dia
/* initialize callbacks from plug-ins */
static void
add_plugin_actions (GtkUIManager *ui_manager, const gchar *base_path)
{
  GtkActionGroup    *actions;
  GtkAction         *action;
  GList             *cblist;
  DiaCallbackFilter *cbf = NULL;
  gchar             *name;
  guint              id;
  static guint       cnt = 0;

  name = g_strdup_printf ("plugin-actions-%d", cnt);
  actions = gtk_action_group_new (name);
  gtk_action_group_set_translation_domain (actions, NULL);
  gtk_action_group_set_translate_func (actions, _dia_translate, NULL, NULL);
  g_free (name);
  name = NULL;
  cnt++;

  gtk_ui_manager_insert_action_group (ui_manager, actions, 5 /* "back" */);
  g_object_unref (actions);

  for (cblist = filter_get_callbacks(); cblist; cblist = cblist->next) {
    gchar *menu_path = NULL;

    cbf = cblist->data;

    if (cbf == NULL) {
      g_warning ("missing DiaCallbackFilter instance");
      continue;
    }

    if (cbf->action == NULL) {
      g_warning ("Plugin '%s': doesn't specify action. Loading failed.",
		cbf->description);
      continue;
    }

    if (   base_path != NULL
        && strncmp (cbf->menupath, base_path, strlen (base_path)) != 0) {
      /* hook for wrong base path, skip */
      continue;
    } else if (!base_path) {
      /* only replace what we know */
      if (strncmp (cbf->menupath, DISPLAY_MENU, strlen (DISPLAY_MENU)) == 0)
        menu_path = g_strdup_printf ("%s%s", INTEGRATED_MENU, cbf->menupath + strlen (DISPLAY_MENU));
      else if (strncmp (cbf->menupath, TOOLBOX_MENU, strlen (TOOLBOX_MENU)) == 0)
        menu_path = g_strdup_printf ("%s%s", INTEGRATED_MENU, cbf->menupath + strlen (TOOLBOX_MENU));
    }

    action = gtk_action_new (cbf->action, cbf->description, NULL, NULL);
    g_signal_connect (G_OBJECT (action), "activate",
		      G_CALLBACK (plugin_callback), (gpointer) cbf);

    gtk_action_group_add_action (actions, action);
    g_object_unref (G_OBJECT (action));

    id = ensure_menu_path (ui_manager, actions, menu_path ? menu_path : cbf->menupath, TRUE);
    gtk_ui_manager_add_ui (ui_manager, id,
			   menu_path ? menu_path : cbf->menupath,
			   cbf->description,
			   cbf->action,
			   GTK_UI_MANAGER_AUTO,
			   FALSE);
    g_free (menu_path);
  }
}
コード例 #19
0
ファイル: module.c プロジェクト: chan18/ljedit
PUSS_EXPORT void* puss_plugin_create(Puss* app) {
	GTree* sections;
	GtkSourceLanguageManager* lm;
	const gchar* const* ids;
	const gchar* const* id;
	GtkSourceLanguage* lang;
	const gchar* name;
	gchar* action_name;
	GtkAction* action;
	const gchar* section;
	GList* section_list;
	GtkUIManager* ui_mgr;
	IToolMenuAction* tool_menu_interface;

	GString* gstr;
	gchar* ui_info;
	GError* err;

	tool_menu_interface = app->extend_query("puss_controls", INTERFACE_TOOL_MENU_ACTION);
	if( !tool_menu_interface )
		return 0;

	bindtextdomain(TEXT_DOMAIN, app->get_locale_path());
	bind_textdomain_codeset(TEXT_DOMAIN, "UTF-8");

	g_self = g_new0(LanguageSelector, 1);
	g_self->app = app;
	g_self->action_group = gtk_action_group_new("puss_language_selector_action_group");

	// set select language menu
	sections = g_tree_new_full((GCompareDataFunc)&g_ascii_strcasecmp, 0, 0, (GDestroyNotify)g_list_free);
	lm = gtk_source_language_manager_get_default();
	ids = gtk_source_language_manager_get_language_ids(lm);
	g_self->last_favory_lang = gtk_source_language_manager_get_language(lm, "cpp");
	for( id=ids; *id; ++id ) {
		lang = gtk_source_language_manager_get_language(lm, *id);
		if( lang ) {
			name = gtk_source_language_get_name(lang);
			action_name = g_strdup_printf("pls_lang_%s", name);
			action = gtk_action_new(action_name, name, NULL, NULL);
			g_signal_connect(action, "activate", G_CALLBACK(&pls_lang_active), lang);
			gtk_action_group_add_action(g_self->action_group, action);
			g_object_unref(action);
			g_free(action_name);

			section = gtk_source_language_get_section(lang);

			section_list = (GList*)g_tree_lookup(sections, section);
			if( section_list ) {
				g_tree_steal(sections, section);
			} else {
				action_name = g_strdup_printf("pls_sec_%s", section);
				action = GTK_ACTION(gtk_action_new(action_name, section, NULL, NULL));
				gtk_action_group_add_action(g_self->action_group, action);
				g_object_unref(action);
				g_free(action_name);
			}

			section_list = g_list_insert_sorted(section_list, (gchar*)name, (GCompareFunc)&g_ascii_strcasecmp);
			
			g_tree_insert(sections, (gchar*)section, section_list);
		}
	}

	// insert language selector menu-tool-button
	// 
	action = gtk_action_new("language_selector_open", _("Language"), _("select high-light source language, default use last"), GTK_STOCK_SELECT_COLOR);
	gtk_action_group_add_action(g_self->action_group, action);
	g_object_unref(action);

	action = GTK_ACTION( g_object_new(tool_menu_interface->get_type ()
			, "name", "language_selector_toolmenu_open"
			, "label", _("Language")
			, "tooltip", _("select high-light source language, default use last")
			, "stock-id", GTK_STOCK_SELECT_COLOR
			, NULL) );
	g_signal_connect(action, "activate", G_CALLBACK(&pls_lang_active), 0);
	gtk_action_group_add_action(g_self->action_group, action);
	g_object_unref(action);

	ui_mgr = GTK_UI_MANAGER(gtk_builder_get_object(app->get_ui_builder(), "main_ui_manager"));
	gtk_ui_manager_insert_action_group(ui_mgr, g_self->action_group, 0);

	// main selector menu
	gstr= g_string_new(NULL);
	g_tree_foreach(sections, (GTraverseFunc)&fill_language_section, gstr);
	g_tree_destroy(sections);

	ui_info = g_strdup_printf(
		"<ui>"
		"  <menubar name='main_menubar'>"
		"     <menu action='view_menu'>\n"
		"      <placeholder name='view_menu_extend_place'>"
		"        <menu action='language_selector_open'>"
		"          %s"
		"          <placeholder name='pls_favory_menu_place'>"
		"          </placeholder>"
		"        </menu>"
		"      </placeholder>"
		"    </menu>"
		"  </menubar>"
		""
		"  <toolbar name='main_toolbar'>"
		"    <placeholder name='main_toolbar_view_place'>"
		"      <toolitem action='language_selector_toolmenu_open'>"
		"        <menu action='language_selector_toolmenu_open'>"
		"          %s"
		"          <placeholder name='pls_favory_toolmenu_place'>"
		"          </placeholder>"
		"        </menu>"
		"      </toolitem>"
		"    </placeholder>"
        "  </toolbar>"
		"</ui>"
		, gstr->str
		, gstr->str
	);

	//g_print(ui_info);
	err = 0;
	g_self->merge_id = gtk_ui_manager_add_ui_from_string(ui_mgr, ui_info, -1, &err);
	if( err ) {
		g_printerr("%s", err->message);
		g_error_free(err);
	}
	g_free(ui_info);
	g_string_free(gstr, TRUE);

	gtk_ui_manager_ensure_update(ui_mgr);

	fill_favory_language_menu();

	return g_self;
}
コード例 #20
0
static GList*
thunar_uca_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
                                      GtkWidget           *window,
                                      GList               *files)
{
  GtkTreeRowReference *row;
  ThunarUcaProvider   *uca_provider = THUNAR_UCA_PROVIDER (menu_provider);
  ThunarUcaContext    *uca_context = NULL;
  GtkTreeIter          iter;
  GtkAction           *action;
  GList               *actions = NULL;
  GList               *paths;
  GList               *lp;
  gchar               *stock_id;
  gchar               *tooltip;
  gchar               *label;
  gchar               *name;

  paths = thunar_uca_model_match (uca_provider->model, files);
  for (lp = g_list_last (paths); lp != NULL; lp = lp->prev)
    {
      /* try to lookup the tree iter for the specified tree path */
      if (gtk_tree_model_get_iter (GTK_TREE_MODEL (uca_provider->model), &iter, lp->data))
        {
          /* determine the label, tooltip and stock-id for the item */
          gtk_tree_model_get (GTK_TREE_MODEL (uca_provider->model), &iter,
                              THUNAR_UCA_MODEL_COLUMN_NAME, &label,
                              THUNAR_UCA_MODEL_COLUMN_STOCK_ID, &stock_id,
                              THUNAR_UCA_MODEL_COLUMN_DESCRIPTION, &tooltip,
                              -1);

          /* generate a unique action name */
          name = g_strdup_printf ("ThunarUca::action-%d", ++uca_provider->last_action_id);

          /* create the new action with the given parameters */
          action = gtk_action_new (name, label, tooltip, stock_id);

          /* grab a tree row reference on the given path */
          row = gtk_tree_row_reference_new (GTK_TREE_MODEL (uca_provider->model), lp->data);
          g_object_set_qdata_full (G_OBJECT (action), thunar_uca_row_quark, row,
                                   (GDestroyNotify) gtk_tree_row_reference_free);

          /* allocate a new context on-demand */
          if (G_LIKELY (uca_context == NULL))
            uca_context = thunar_uca_context_new (window, files);
          else
            uca_context = thunar_uca_context_ref (uca_context);
          g_object_set_qdata_full (G_OBJECT (action), thunar_uca_context_quark, uca_context, (GDestroyNotify) thunar_uca_context_unref);

          /* connect the "activate" signal */
          g_signal_connect_data (G_OBJECT (action), "activate", G_CALLBACK (thunar_uca_provider_activated),
                                 g_object_ref (G_OBJECT (uca_provider)), (GClosureNotify) g_object_unref,
                                 G_CONNECT_SWAPPED);

          /* add the action to the return list */
          actions = g_list_prepend (actions, action);

          /* cleanup */
          g_free (stock_id);
          g_free (tooltip);
          g_free (label);
          g_free (name);
        }

      /* release the tree path */
      gtk_tree_path_free (lp->data);
    }
  g_list_free (paths);

  return actions;
}
コード例 #21
0
ファイル: menu.c プロジェクト: wazari972/Grisbi
/**
 * Add menu items to the "Recent files" submenu.
 */
gboolean affiche_derniers_fichiers_ouverts ( void )
{
    gint i;
    GtkActionGroup * action_group;

    efface_derniers_fichiers_ouverts ();

    if ( conf.nb_derniers_fichiers_ouverts > conf.nb_max_derniers_fichiers_ouverts )
    {
        conf.nb_derniers_fichiers_ouverts = conf.nb_max_derniers_fichiers_ouverts;
    }

    if ( ! conf.nb_derniers_fichiers_ouverts || ! conf.nb_max_derniers_fichiers_ouverts )
    {
        return FALSE;
    }

    action_group = gtk_action_group_new ( "Group2" );

    for ( i = 0 ; i < conf.nb_derniers_fichiers_ouverts ; i++ )
    {
        gchar *tmp_name;
        GtkAction *action;

        tmp_name = g_strdup_printf ( "LastFile%d", i );

        action = gtk_action_new ( tmp_name,
                        tab_noms_derniers_fichiers_ouverts[i],
                        "",
                        "" );
        g_free ( tmp_name );
        g_signal_connect ( action,
                        "activate",
                        G_CALLBACK ( gsb_file_open_direct_menu ),
                        GINT_TO_POINTER ( i ) );
        gtk_action_group_add_action ( action_group, action );
    }

    gtk_ui_manager_insert_action_group ( ui_manager, action_group, 1 );

    recent_files_merge_id = gtk_ui_manager_new_merge_id ( ui_manager );

    for ( i=0 ; i < conf.nb_derniers_fichiers_ouverts ; i++ )
    {
        gchar *tmp_name;
        gchar *tmp_label;

        tmp_name = g_strdup_printf ( "LastFile%d", i );
        tmp_label = g_strdup_printf ( "_%d LastFile%d", i, i );

        gtk_ui_manager_add_ui ( ui_manager,
                    recent_files_merge_id,
                    "/menubar/FileMenu/RecentFiles/",
                    tmp_label,
                    tmp_name,
                    GTK_UI_MANAGER_MENUITEM,
                    FALSE );

        g_free ( tmp_name );
        g_free ( tmp_label );
    }

    /* add a separator */
    gtk_ui_manager_add_ui ( ui_manager,
                    merge_id,
                    "/menubar/FileMenu/Open/",
                    NULL,
                    NULL,
                    GTK_UI_MANAGER_SEPARATOR,
                    FALSE );

    gtk_ui_manager_ensure_update ( ui_manager );

#ifdef GTKOSXAPPLICATION
    grisbi_osx_app_update_menus_cb ( );
#endif /* GTKOSXAPPLICATION */
    return FALSE;
}
コード例 #22
0
ファイル: caja-window-menus.c プロジェクト: fatman2021/caja
void
caja_menus_append_bookmark_to_menu (CajaWindow *window,
                                    CajaBookmark *bookmark,
                                    const char *parent_path,
                                    const char *parent_id,
                                    guint index_in_parent,
                                    GtkActionGroup *action_group,
                                    guint merge_id,
                                    GCallback refresh_callback,
                                    CajaBookmarkFailedCallback failed_callback)
{
    BookmarkHolder *bookmark_holder;
    char action_name[128];
    char *name;
    char *path;
    GdkPixbuf *pixbuf;
    GtkAction *action;
    GtkWidget *menuitem;

    g_assert (CAJA_IS_WINDOW (window));
    g_assert (CAJA_IS_BOOKMARK (bookmark));

    bookmark_holder = bookmark_holder_new (bookmark, window, refresh_callback, failed_callback);
    name = caja_bookmark_get_name (bookmark);

    /* Create menu item with pixbuf */
    pixbuf = caja_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU);

    g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent);

    action = gtk_action_new (action_name,
                             name,
                             _("Go to the location specified by this bookmark"),
                             NULL);

    g_object_set_data_full (G_OBJECT (action), "menu-icon",
                            g_object_ref (pixbuf),
                            g_object_unref);

    g_signal_connect_data (action, "activate",
                           G_CALLBACK (activate_bookmark_in_menu_item),
                           bookmark_holder,
                           bookmark_holder_free_cover, 0);

    gtk_action_group_add_action (action_group,
                                 GTK_ACTION (action));

    g_object_unref (action);

    gtk_ui_manager_add_ui (window->details->ui_manager,
                           merge_id,
                           parent_path,
                           action_name,
                           action_name,
                           GTK_UI_MANAGER_MENUITEM,
                           FALSE);

    path = g_strdup_printf ("%s/%s", parent_path, action_name);
    menuitem = gtk_ui_manager_get_widget (window->details->ui_manager,
                                          path);
    gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem),
            TRUE);

    g_object_unref (pixbuf);
    g_free (path);
    g_free (name);
}
コード例 #23
0
ファイル: main.c プロジェクト: jmenashe/diff-ext
static GList*
get_file_actions(ThunarxMenuProvider* provider, GtkWidget* window, GList* files) {
  GList* actions = 0;
  
  if(files != 0) {
    GtkIconTheme* theme = gtk_icon_theme_get_default();
    guint n = g_list_length(files);
    gchar* three_way_compare_command;
    xdiff_ext_preferences* p = xdiff_ext_preferences_instance();

    g_object_get(G_OBJECT(p), "three-way-compare-command", &three_way_compare_command, NULL);

    g_object_unref(p);
     
    GList* scan = files;
    gboolean go = TRUE;
    
    while(scan && go) {
      gchar* scheme;

      scheme = thunarx_file_info_get_uri_scheme((ThunarxFileInfo*)(scan->data));
      go = strncmp(scheme, "file", 4) == 0;
      g_free(scheme);
      
      scan = g_list_next(scan);
    }
    
    if(go) {
      GtkAction* action = gtk_action_new("xdiff-ext::save", _("Compare later"), _("Select file for comparison"), DIFF_EXT_DATA_DIR"/icons/hicolor/16x16/actions/diff_later.png");
      g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_later), window);
      g_object_set_data_full(G_OBJECT(action), "xdiff-ext::save", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
      actions = g_list_append(actions, action);
      
      if(n == 1) {
        if(!g_queue_is_empty(_saved)) {
          GString* caption = g_string_new("");
          GString* hint = g_string_new("");
          GList* head = g_queue_peek_head_link(_saved);
          gchar* head_file = (gchar*)head->data;
          ThunarVfsInfo* vfs_info = NULL;
          ThunarVfsPath* vfs_path = NULL;
          const gchar* icon_name;
          
          gchar* uri;
          gchar* path;

          uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
          path = g_filename_from_uri(uri, NULL, NULL);
          g_free(uri);
          
          g_string_printf(caption,_("Compare to '%s'"), head_file);
          g_string_printf(hint, _("Compare '%s' and '%s'"), path, head_file);
          
          vfs_path = thunar_vfs_path_new(head_file, NULL);
          vfs_info = thunar_vfs_info_new_for_path(vfs_path, NULL);
          icon_name = thunar_vfs_info_get_custom_icon(vfs_info);
          if(icon_name == NULL) {
            icon_name = thunar_vfs_mime_info_lookup_icon_name(vfs_info->mime_info, theme);
          }
          
          g_message("icon name: '%s'", icon_name);
          thunar_vfs_path_unref(vfs_path);
          thunar_vfs_info_unref(vfs_info);
          
          action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "gaim.png");
          g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_to), window);
          g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
          g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
          actions = g_list_append(actions, action);
          
          if(_saved->length > 1) {
            add_compare_to_menu(actions, window, files, _("Compare to"), make_hint, G_CALLBACK(compare_to), path);
          }
          
          g_string_free(caption, TRUE);
          g_string_free(hint, TRUE);
        }
      } else if(n == 2) {
        GtkAction* action = gtk_action_new("xdiff-ext::compare", _("Compare"), _("Compare selected files"), "diff");
        g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare), window);
        g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
        actions = g_list_append(actions, action);

        if(strcmp("", three_way_compare_command) != 0) {
          if(!g_queue_is_empty(_saved)) {
            GString* caption = g_string_new("");
            GString* hint = g_string_new("");
            GList* head = g_queue_peek_head_link(_saved);
            gchar* head_file = (gchar*)head->data;
            gchar* uri;
            gchar* path1;
            gchar* path2;

            uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
            path1 = g_filename_from_uri(uri, NULL, NULL);
            g_free(uri);
            files = g_list_next(files);
            uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
            path2 = g_filename_from_uri(uri, NULL, NULL);
            g_free(uri);
            
            g_string_printf(caption, _("3-way compare to '%s'"), head_file);
            g_string_printf(hint, _("3-way compare '%s', '%s' and '%s'"), path1, path2, head_file);
            
            action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "diff3_with");
            g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3_to), window);
            g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
            g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
            actions = g_list_append(actions, action);

            if(_saved->length > 1) {
              add_compare_to_menu(actions, window, files, _("3-way compare to"), make_hint3, G_CALLBACK(compare3_to), path1, path2);
            }
            
            g_string_free(caption, TRUE);
            g_string_free(hint, TRUE);
          }
        }
      } else if(n == 3) {
        if(strcmp("", three_way_compare_command) != 0) {
          GtkAction* action = gtk_action_new("xdiff-ext::compare3", _("3-way Compare"), _("Compare selected files"), "diff3");
          g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3), window);
          g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare3", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
          actions = g_list_append(actions, action);
        }
      }
    }
    
    g_free(three_way_compare_command);
  }
          
  return actions;
}
コード例 #24
0
ファイル: main.c プロジェクト: mcmihail/cinnamon-bluetooth
static void
update_device_list (BluetoothApplet *applet,
					gpointer user_data)
{
	GtkUIManager *uimanager;
	GList *actions, *devices, *l;
	gboolean has_devices = FALSE;

	uimanager = GTK_UI_MANAGER (gtk_builder_get_object (xml, "bluetooth-applet-ui-manager"));

	devices = bluetooth_applet_get_devices (applet);

	if (devices == NULL) {
		/* No devices? Remove everything */
		actions = gtk_action_group_list_actions (devices_action_group);
		g_list_foreach (actions, (GFunc) remove_action_item, uimanager);
		g_list_free (actions);
		goto done;
	}

	/* Get a list of actions, and we'll remove the ones with a
	 * device in the list. We remove the submenu items first */
	actions = gtk_action_group_list_actions (devices_action_group);
	for (l = actions; l != NULL; l = l->next) {
		if (bluetooth_verify_address (gtk_action_get_name (l->data)) == FALSE)
			l->data = NULL;
	}
	actions = g_list_remove_all (actions, NULL);

	for (l = devices; l != NULL; l = g_list_next (l)) {
		BluetoothSimpleDevice *device = l->data;
		GtkAction *action, *status, *oper;
		char *name;

		if (device_has_submenu (device) == FALSE) {
			g_boxed_free (BLUETOOTH_TYPE_SIMPLE_DEVICE, device);
			continue;
		}

		has_devices = TRUE;

		action = gtk_action_group_get_action (devices_action_group, device->bdaddr);
		oper = NULL;
		status = NULL;
		if (action) {
			char *action_name;

			actions = g_list_remove (actions, action);

			action_name = g_strdup_printf ("%s-status", device->bdaddr);
			status = gtk_action_group_get_action (devices_action_group, action_name);
			g_free (action_name);

			action_name = g_strdup_printf ("%s-action", device->bdaddr);
			oper = gtk_action_group_get_action (devices_action_group, action_name);
			g_free (action_name);
		}

		name = escape_label_for_action (device->alias);

		if (action == NULL) {
			guint menu_merge_id;
			char *action_path;

			/* The menu item with descendants */
			action = gtk_action_new (device->bdaddr, name, NULL, NULL);

			gtk_action_group_add_action (devices_action_group, action);
			g_object_unref (action);
			menu_merge_id = gtk_ui_manager_new_merge_id (uimanager);
			gtk_ui_manager_add_ui (uimanager, menu_merge_id,
					       "/bluetooth-applet-popup/devices-placeholder", device->bdaddr, device->bdaddr,
					       GTK_UI_MANAGER_MENU, FALSE);
			g_object_set_data_full (G_OBJECT (action),
						"merge-id", GUINT_TO_POINTER (menu_merge_id), NULL);

			/* The status menu item */
			status = add_menu_item (device->bdaddr,
						"status",
						device->connected ? _("Connected") : _("Disconnected"),
						uimanager,
						menu_merge_id,
						NULL);
			gtk_action_set_sensitive (status, FALSE);

			if (device->can_connect) {
				action_path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s/%s-status",
							       device->bdaddr, device->bdaddr);
				action_set_bold (uimanager, status, action_path);
				g_free (action_path);
			} else {
				gtk_action_set_visible (status, FALSE);
			}

			/* The connect button */
			oper = add_menu_item (device->bdaddr,
					      "action",
					      device->connected ? _("Disconnect") : _("Connect"),
					      uimanager,
					      menu_merge_id,
					      G_CALLBACK (on_connect_activate));
			if (!device->can_connect)
				gtk_action_set_visible (oper, FALSE);

			add_separator_item (device->bdaddr, "connect-sep", uimanager, menu_merge_id);

			/* The Send to... button */
			if (device->capabilities & BLUETOOTH_CAPABILITIES_OBEX_PUSH) {
				add_menu_item (device->bdaddr,
					       "sendto",
					       _("Send files..."),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (sendto_callback));
				g_object_set_data_full (G_OBJECT (action),
							"alias", g_strdup (device->alias), g_free);
			}
			if (device->capabilities & BLUETOOTH_CAPABILITIES_OBEX_FILE_TRANSFER) {
				add_menu_item (device->bdaddr,
					       "browse",
					       _("Browse files..."),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (browse_callback));
			}

			add_separator_item (device->bdaddr, "files-sep", uimanager, menu_merge_id);

			if (device->type == BLUETOOTH_TYPE_KEYBOARD && program_available (GNOMECC)) {
				add_menu_item (device->bdaddr,
					       "keyboard",
					       _("Keyboard Settings"),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (keyboard_callback));
			}
			if (device->type == BLUETOOTH_TYPE_MOUSE && program_available (GNOMECC)) {
				add_menu_item (device->bdaddr,
					       "mouse",
					       _("Mouse and Touchpad Settings"),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (mouse_callback));
			}
			if ((device->type == BLUETOOTH_TYPE_HEADSET ||
			     device->type == BLUETOOTH_TYPE_HEADPHONES ||
			     device->type == BLUETOOTH_TYPE_OTHER_AUDIO) && program_available (GNOMECC)) {
				add_menu_item (device->bdaddr,
					       "sound",
					       _("Sound Settings"),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (sound_callback));
			}
		} else {
			gtk_action_set_label (action, name);

			if (device->can_connect) {
				gtk_action_set_visible (status, TRUE);
				gtk_action_set_visible (oper, TRUE);
				set_device_status_label (device->bdaddr, device->connected ? CONNECTED : DISCONNECTED);
				gtk_action_set_label (oper, device->connected ? _("Disconnect") : _("Connect"));
			} else {
				gtk_action_set_visible (status, FALSE);
				gtk_action_set_visible (oper, FALSE);
			}
		}
		g_free (name);

		if (oper != NULL) {
			g_object_set_data_full (G_OBJECT (oper),
						"connected", GINT_TO_POINTER (device->connected ? CONNECTED : DISCONNECTED), NULL);
			g_object_set_data_full (G_OBJECT (oper),
						"device-path", g_strdup (device->device_path), g_free);
		}

		/* And now for the trick of the day */
		if (device->connected != FALSE) {
			char *path;

			path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s", device->bdaddr);
			action_set_bold (uimanager, action, path);
			g_free (path);
		}

		g_boxed_free (BLUETOOTH_TYPE_SIMPLE_DEVICE, device);
	}

	/* Remove the left-over devices */
	g_list_foreach (actions, (GFunc) remove_action_item, uimanager);
	g_list_free (actions);

	/* Cleanup */
	g_list_free (devices);
done:
	gtk_ui_manager_ensure_update (uimanager);

	gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (xml, "devices-label")),
				has_devices);
}
コード例 #25
0
ファイル: main.c プロジェクト: cummins-cvp/mate-bluetooth
static void
update_device_list (GtkTreeIter *parent)
{
	GtkUIManager *uimanager;
	GtkTreeIter iter;
	gboolean cont;
	guint num_devices;
	GList *actions, *l;

	num_devices = 0;

	uimanager = GTK_UI_MANAGER (gtk_builder_get_object (xml, "bluetooth-applet-ui-manager"));

	if (parent == NULL) {
		/* No default adapter? Remove everything */
		actions = gtk_action_group_list_actions (devices_action_group);
		g_list_foreach (actions, (GFunc) remove_action_item, uimanager);
		g_list_free (actions);
		goto done;
	}

	/* Get a list of actions, and we'll remove the ones with a
	 * device in the list. We remove the submenu items first */
	actions = gtk_action_group_list_actions (devices_action_group);
	for (l = actions; l != NULL; l = l->next) {
		if (bluetooth_verify_address (gtk_action_get_name (l->data)) == FALSE)
			l->data = NULL;
	}
	actions = g_list_remove_all (actions, NULL);

	cont = gtk_tree_model_iter_children (devices_model, &iter, parent);
	while (cont) {
		GHashTable *services;
		DBusGProxy *proxy;
		char *alias, *address, **uuids, *name;
		gboolean is_connected;
		BluetoothType type;
		GtkAction *action, *status, *oper;

		gtk_tree_model_get (devices_model, &iter,
				    BLUETOOTH_COLUMN_PROXY, &proxy,
				    BLUETOOTH_COLUMN_ADDRESS, &address,
				    BLUETOOTH_COLUMN_SERVICES, &services,
				    BLUETOOTH_COLUMN_ALIAS, &alias,
				    BLUETOOTH_COLUMN_UUIDS, &uuids,
				    BLUETOOTH_COLUMN_TYPE, &type,
				    -1);

		if (device_has_submenu ((const char **) uuids, services, type) == FALSE ||
		    address == NULL || proxy == NULL || alias == NULL) {
			if (proxy != NULL)
				g_object_unref (proxy);

			if (services != NULL)
				g_hash_table_unref (services);
			g_strfreev (uuids);
			g_free (alias);
			g_free (address);
			cont = gtk_tree_model_iter_next (devices_model, &iter);
			continue;
		}

		action = gtk_action_group_get_action (devices_action_group, address);
		oper = NULL;
		status = NULL;
		if (action) {
			char *action_name;

			actions = g_list_remove (actions, action);

			action_name = g_strdup_printf ("%s-status", address);
			status = gtk_action_group_get_action (devices_action_group, action_name);
			g_free (action_name);

			action_name = g_strdup_printf ("%s-action", address);
			oper = gtk_action_group_get_action (devices_action_group, action_name);
			g_free (action_name);
		}

		/* If one service is connected, then we're connected */
		is_connected = FALSE;
		if (services != NULL) {
			GList *list, *l;

			list = g_hash_table_get_values (services);
			for (l = list; l != NULL; l = l->next) {
				BluetoothStatus val = GPOINTER_TO_INT (l->data);
				if (val == BLUETOOTH_STATUS_CONNECTED ||
				    val == BLUETOOTH_STATUS_PLAYING) {
					is_connected = TRUE;
					break;
				}
			}
			g_list_free (list);
		}

		name = escape_label_for_action (alias);

		if (action == NULL) {
			guint menu_merge_id;
			char *action_path;

			/* The menu item with descendants */
			action = gtk_action_new (address, name, NULL, NULL);

			gtk_action_group_add_action (devices_action_group, action);
			g_object_unref (action);
			menu_merge_id = gtk_ui_manager_new_merge_id (uimanager);
			gtk_ui_manager_add_ui (uimanager, menu_merge_id,
					       "/bluetooth-applet-popup/devices-placeholder", address, address,
					       GTK_UI_MANAGER_MENU, FALSE);
			g_object_set_data_full (G_OBJECT (action),
						"merge-id", GUINT_TO_POINTER (menu_merge_id), NULL);

			/* The status menu item */
			status = add_menu_item (address,
						"status",
						is_connected ? _("Connected") : _("Disconnected"),
						uimanager,
						menu_merge_id,
						NULL);
			gtk_action_set_sensitive (status, FALSE);

			if (services != NULL) {
				action_path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s/%s-status",
							       address, address);
				action_set_bold (uimanager, status, action_path);
				g_free (action_path);
			} else {
				gtk_action_set_visible (status, FALSE);
			}

			/* The connect button */
			oper = add_menu_item (address,
					      "action",
					      is_connected ? _("Disconnect") : _("Connect"),
					      uimanager,
					      menu_merge_id,
					      G_CALLBACK (on_connect_activate));
			if (services == NULL)
				gtk_action_set_visible (oper, FALSE);

			add_separator_item (address, "connect-sep", uimanager, menu_merge_id);

			/* The Send to... button */
			if (device_has_uuid ((const char **) uuids, "OBEXObjectPush") != FALSE) {
				add_menu_item (address,
					       "sendto",
					       _("Send files..."),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (sendto_callback));
				g_object_set_data_full (G_OBJECT (action),
							"alias", g_strdup (alias), g_free);
			}
			if (device_has_uuid ((const char **) uuids, "OBEXFileTransfer") != FALSE) {
				add_menu_item (address,
					       "browse",
					       _("Browse files..."),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (browse_callback));
			}

			add_separator_item (address, "files-sep", uimanager, menu_merge_id);

			if (type == BLUETOOTH_TYPE_KEYBOARD && program_available (KEYBOARD_PREFS)) {
				add_menu_item (address,
					       "keyboard",
					       _("Open Keyboard Preferences..."),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (keyboard_callback));
			}
			if (type == BLUETOOTH_TYPE_MOUSE && program_available (MOUSE_PREFS)) {
				add_menu_item (address,
					       "mouse",
					       _("Open Mouse Preferences..."),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (mouse_callback));
			}
			if ((type == BLUETOOTH_TYPE_HEADSET ||
			     type == BLUETOOTH_TYPE_HEADPHONES ||
			     type == BLUETOOTH_TYPE_OTHER_AUDIO) && program_available (SOUND_PREFS)) {
				add_menu_item (address,
					       "sound",
					       _("Open Sound Preferences..."),
					       uimanager,
					       menu_merge_id,
					       G_CALLBACK (sound_callback));
			}
		} else {
			gtk_action_set_label (action, name);

			gtk_action_set_visible (status, services != NULL);
			gtk_action_set_visible (oper, services != NULL);
			if (services != NULL) {
				set_device_status_label (address, is_connected ? CONNECTED : DISCONNECTED);
				gtk_action_set_label (oper, is_connected ? _("Disconnect") : _("Connect"));
			}
		}
		g_free (name);

		if (oper != NULL) {
			g_object_set_data_full (G_OBJECT (oper),
						"connected", GINT_TO_POINTER (is_connected ? CONNECTED : DISCONNECTED), NULL);
			g_object_set_data_full (G_OBJECT (oper),
						"device-path", g_strdup (dbus_g_proxy_get_path (proxy)), g_free);
		}

		/* And now for the trick of the day */
		if (is_connected != FALSE) {
			char *path;

			path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s", address);
			action_set_bold (uimanager, action, path);
			g_free (path);
		}

		num_devices++;

		if (proxy != NULL)
			g_object_unref (proxy);

		if (services != NULL)
			g_hash_table_unref (services);
		g_strfreev (uuids);
		g_free (alias);
		g_free (address);
		cont = gtk_tree_model_iter_next (devices_model, &iter);
	}

	/* Remove the left-over devices */
	g_list_foreach (actions, (GFunc) remove_action_item, uimanager);
	g_list_free (actions);

done:
	gtk_ui_manager_ensure_update (uimanager);

	gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (xml, "devices-label")),
				num_devices > 0);
}