gtk_menu_popup() removing treeview selection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello There!

I'm trying to display a context menu when an item of a GtkTreeView
receives a right click. When I right click the item the menu is shown
but the selection in my GtkTreeView disapears and I want the item I
right click selected when the GtkMenu is shown.

The menu is GtkBuilt:

...
<object class="GtkMenu" id="menu_nf">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
  <object class="GtkMenuItem" id="abrir_nfe">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="label" translatable="yes">Abrir</property>
    <property name="use_underline">True</property>
  </object>
</child>
<child>
  <object class="GtkMenuItem" id="emitir_nfe">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="label" translatable="yes">Emitir</property>
    <property name="use_underline">True</property>
  </object>
</child>
</object>
...

And these are the relevant functions that I'm using to display the menu:

static gint popup_menu_nfe(GtkTreeView *t, GdkEventButton *e, gpointer *win){
    gtk_menu_popup((LIVRENFE_WINDOW(win))->menu_nf, NULL,
        NULL, NULL, NULL, e->button, e->time);
}

static gint nfe_context_menu_show(GtkTreeView *t, GdkEventButton *e,
        gpointer win){
    if(e->type == GDK_BUTTON_PRESS){
        if(e->button == GDK_BUTTON_SECONDARY){
            GtkTreeSelection *s;
            GtkTreePath *p;
            s = gtk_tree_view_get_selection(t);
            if(gtk_tree_view_get_path_at_pos(t, e->x, e->y, &p,
                    NULL, NULL, NULL)){
                gtk_tree_selection_unselect_all(s);
                gtk_tree_selection_select_path(s, p);
                gtk_tree_path_free(p);
            }
            popup_menu_nfe(t, e, win);
            return TRUE;
        }
    }
    return FALSE;
}

static gint nfe_on_popup(GtkTreeView *t, gpointer win){
    popup_menu_nfe(t, NULL, win);
    return TRUE;
}

static void livrenfe_window_init(LivrenfeWindow *win){
    gtk_widget_init_template(GTK_WIDGET(win));
    ...
    g_signal_connect((LIVRENFE_WINDOW(win))->treeview, "button-press-event",
        G_CALLBACK(nfe_context_menu_show), win);
    g_signal_connect((LIVRENFE_WINDOW(win))->treeview, "popup-menu",
        G_CALLBACK(nfe_on_popup), win);
    ...
}

Full code is here:
https://github.com/pablogallardo/livrenfe/blob/master/src/lnfe_window.c

I've followed the example in here
https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Events#Context_Menus_on_Right_Click

If I comment out the gtk_menu_popup() call, items get selected when I
right click them but it seems that I'm doing something wrong when I
call gtk_menu_popup(). I've also tried to call gtk_menu_popup() before
I do the GtkTreeSelection part and it doesn't work.

Could someone please help me?

Thanks!


Pablo G. Gallardo
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list



[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux