Changeset 80e56e


Ignore:
Timestamp:
01/17/2014 10:51:54 PM (12 years ago)
Author:
Calum Lind <calumlind+deluge@gmail.com>
Branches:
2.0.x, develop, master
Children:
01d2ef8
Parents:
2b64d7
git-author:
bendikro <bendikro@gmail.com> (10/04/2013 09:44:17 AM)
git-committer:
Calum Lind <calumlind+deluge@gmail.com> (01/17/2014 10:51:54 PM)
Message:

Fix #1000 : GTKUI: Select first row in list if no rows are selected

Also do not remove selection when changing filter (as 1.3 works)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • deluge/ui/gtkui/torrentview.py

    r2b64d7 r80e56e  
    4242import gobject
    4343import logging
    44 import warnings
    4544
    4645from twisted.internet import reactor
    4746
    4847import listview
    49 import deluge.common
    5048import deluge.component as component
    5149from deluge.ui.client import client
     
    366364        self.set_columns_to_update()
    367365        self.update_view(load_new_list=True)
     366        self.select_first_row()
    368367
    369368    def stop(self):
     
    398397        see: core.get_torrents_status
    399398        """
    400         self.treeview.get_selection().unselect_all()
    401399        search_filter = self.filter and self.filter.get('name', None) or None
    402400        self.filter = dict(filter_dict)  # Copied version of filter_dict.
    403401        if search_filter and 'name' not in filter_dict:
    404402            self.filter['name'] = search_filter
    405         self.update()
     403        self.update(select_row=True)
    406404
    407405    def set_columns_to_update(self, columns=None):
     
    429427        return status_keys
    430428
    431     def send_status_request(self, columns=None):
     429    def send_status_request(self, columns=None, select_row=False):
    432430        # Store the 'status_fields' we need to send to core
    433431        status_keys = self.set_columns_to_update(columns)
     
    442440        # Request the statuses for all these torrent_ids, this is async so we
    443441        # will deal with the return in a signal callback.
    444         component.get("SessionProxy").get_torrents_status(
     442        d = component.get("SessionProxy").get_torrents_status(
    445443            self.filter, status_keys).addCallback(self._on_get_torrents_status)
    446 
    447     def update(self):
     444        if select_row:
     445            d.addCallback(self.select_first_row)
     446
     447    def select_first_row(self, ignored=None):
     448        """
     449        Set the first row in the list selected if a selection does
     450        not already exist
     451        """
     452        rows = self.treeview.get_selection().get_selected_rows()[1]
     453        # Only select row if noe rows are selected
     454        if not rows:
     455            self.treeview.get_selection().select_path((0,))
     456
     457    def update(self, select_row=False):
     458        """
     459        Sends a status request to core and updates the torrent list with the result.
     460
     461        :param select_row: if the first row in the list should be selected if
     462                           no rows are already selected.
     463        :type select_row: boolean
     464
     465        """
    448466        if self.got_state:
    449467            if self.search_box.search_pending is not None and self.search_box.search_pending.active():
     
    451469                return
    452470            # Send a status request
    453             gobject.idle_add(self.send_status_request)
     471            gobject.idle_add(self.send_status_request, None, select_row)
    454472
    455473    def update_view(self, load_new_list=False):
     
    515533        self.prev_status = status
    516534
    517     def _on_get_torrents_status(self, status):
     535    def _on_get_torrents_status(self, status, select_row=False):
    518536        """Callback function for get_torrents_status().  'status' should be a
    519537        dictionary of {torrent_id: {key, value}}."""
     
    521539        if self.search_box.prefiltered is not None:
    522540            self.search_box.prefiltered = None
     541
    523542        if self.status == self.prev_status and self.prev_status:
    524543            # We do not bother updating since the status hasn't changed
    525544            self.prev_status = self.status
    526545            return
    527         gobject.idle_add(self.update_view)
     546        self.update_view()
    528547
    529548    def add_rows(self, torrent_ids):
Note: See TracChangeset for help on using the changeset viewer.