@@ -220,6 +220,59 @@ def unsafe_set(self, treeiter, pane, keys_values):
220220 self .set (treeiter , safe_keys_values )
221221
222222
223+ class TreeviewCommon :
224+
225+ def on_treeview_popup_menu (self , treeview ):
226+ cursor_path , cursor_col = treeview .get_cursor ()
227+ if not cursor_path :
228+ self .popup_menu .popup_at_pointer (None )
229+ return True
230+
231+ # We always want to pop up to the right of the first column,
232+ # ignoring the actual cursor column location.
233+ rect = treeview .get_background_area (
234+ cursor_path , treeview .get_column (0 ))
235+
236+ self .popup_menu .popup_at_rect (
237+ treeview .get_bin_window (),
238+ rect ,
239+ Gdk .Gravity .SOUTH_EAST ,
240+ Gdk .Gravity .NORTH_WEST ,
241+ None ,
242+ )
243+ return True
244+
245+ def on_treeview_button_press_event (self , treeview , event ):
246+
247+ # If we have multiple treeviews, unselect clear other tree selections
248+ num_panes = getattr (self , 'num_panes' , 1 )
249+ if num_panes > 1 :
250+ for t in self .treeview [:self .num_panes ]:
251+ if t != treeview :
252+ t .get_selection ().unselect_all ()
253+
254+ if (event .triggers_context_menu () and
255+ event .type == Gdk .EventType .BUTTON_PRESS ):
256+
257+ treeview .grab_focus ()
258+
259+ path = treeview .get_path_at_pos (int (event .x ), int (event .y ))
260+ if path is None :
261+ return False
262+
263+ selection = treeview .get_selection ()
264+ model , rows = selection .get_selected_rows ()
265+
266+ if path [0 ] not in rows :
267+ selection .unselect_all ()
268+ selection .select_path (path [0 ])
269+ treeview .set_cursor (path [0 ])
270+
271+ self .popup_menu .popup_at_pointer (event )
272+ return True
273+ return False
274+
275+
223276def treeview_search_cb (model , column , key , it , data ):
224277 # If the key contains a path separator, search the whole path,
225278 # otherwise just use the filename. If the key is all lower-case, do a
0 commit comments