@GFdevelop thanks for the info. For me, when there's no selection and I right-click on an item, it first selects the item and the menu pops up as expected. Perhaps it's a difference in GTK+ versions (GTK 2.24.32 here and it looks like you might have GTK+3).
Anyway, if the crux of this PR fixes some GTK+ versions without affecting others, which it seems to do, then it looks OK to me at a glance.