~exaile-devel/exaile/exaile-0.3.x

« back to all changes in this revision

Viewing changes to xlgui/widgets/playlist.py

  • Committer: Mathias Brodala
  • Date: 2012-08-22 21:22:13 UTC
  • Revision ID: info@noctus.net-20120822212213-5on0c31n83krjtvu
* Keep selection of multiple rows upon button press in playlist views (required for DnD)

(Fixes: bug #1039353)

Show diffs side-by-side

added added

removed removed

Lines of Context:
797
797
 
798
798
            Also sets the internal state for button pressed
799
799
 
800
 
            (Taken from thunar_details_view_button_press_event() of thunar-details-view.c)
 
800
            Taken from the following sources:
 
801
            
 
802
            * thunar_details_view_button_press_event() of thunar-details-view.c
 
803
            * MultiDragTreeView.__button_press/__button.release of quodlibet/qltk/views.py
801
804
        """
802
805
        self.button_pressed = True
803
806
        selection = self.get_selection()
810
813
        if e.state & gtk.accelerator_get_default_mod_mask() == 0 and not path:
811
814
            selection.unselect_all()
812
815
 
813
 
        # Open the context menu on right clicks
814
 
        if e.type == gtk.gdk.BUTTON_PRESS and e.button == 3:
815
 
            if path:
816
 
                # Select the path on which the user clicked if not selected yet
817
 
                if not selection.path_is_selected(path):
818
 
                    # We don't unselect all other items if Control is active
819
 
                    if e.state & gtk.gdk.CONTROL_MASK == 0:
820
 
                        selection.unselect_all()
821
 
 
822
 
                    selection.select_path(path)
823
 
 
824
 
                self.menu.popup(None, None, None, e.button, e.time)
825
 
 
826
 
            return True
 
816
        if path and e.type == gtk.gdk.BUTTON_PRESS:
 
817
            # Prevent unselection of all except the clicked item on left
 
818
            # clicks, required to preserve the selection for DnD
 
819
            if e.button == 1 and e.state & gtk.accelerator_get_default_mod_mask() == 0 and \
 
820
               selection.path_is_selected(path):
 
821
                selection.set_select_function(lambda *args: False)
 
822
 
 
823
            # Open the context menu on right clicks
 
824
            if e.button == 3:
 
825
                if path:
 
826
                    # Select the path on which the user clicked if not selected yet
 
827
                    if not selection.path_is_selected(path):
 
828
                        # We don't unselect all other items if Control is active
 
829
                        if e.state & gtk.gdk.CONTROL_MASK == 0:
 
830
                            selection.unselect_all()
 
831
 
 
832
                        selection.select_path(path)
 
833
 
 
834
                    self.menu.popup(None, None, None, e.button, e.time)
 
835
 
 
836
                return True
827
837
 
828
838
        return gtk.TreeView.do_button_press_event(self, e)
829
839
 
832
842
            Unsets the internal state for button press
833
843
        """
834
844
        self.button_pressed = False
 
845
        # Restore regular selection behavior in any case
 
846
        self.get_selection().set_select_function(lambda *args: True)
835
847
 
836
848
        return gtk.TreeView.do_button_release_event(self, e)
837
849