~mvo/software-center/treeview-keep-state-on-db-cache-change

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/panes/installedpane.py

  • Committer: Michael Vogt
  • Date: 2012-03-29 13:30:51 UTC
  • Revision ID: michael.vogt@ubuntu.com-20120329133051-kk94te44s2lbce3j
softwarecenter/ui/gtk3/panes/installedpane.py: keep the state of the treeview on refresh, note that this depends on the fixes in the previous branch merges to work correctly

Show diffs side-by-side

added added

removed removed

Lines of Context:
325
325
        self.nonapps_visible = NonAppVisibility.NEVER_VISIBLE
326
326
        self.refresh_apps()
327
327
 
 
328
    def _save_treeview_state(self):
 
329
        # store the state
 
330
        expanded_rows = []
 
331
        self.app_view.tree_view.map_expanded_rows(
 
332
            lambda view,path,data: expanded_rows.append(path.to_string()), None)
 
333
        vadj = self.app_view.tree_view_scroll.get_vadjustment().get_value()
 
334
        return expanded_rows, vadj
 
335
 
 
336
    def _restore_treeview_state(self, state):
 
337
        expanded_rows, vadj = state
 
338
        for ind in expanded_rows:
 
339
            path = Gtk.TreePath.new_from_string(ind)
 
340
            self.app_view.tree_view.expand_row(path, False)
 
341
        self.app_view.tree_view_scroll.get_vadjustment().set_lower(vadj)
 
342
        self.app_view.tree_view_scroll.get_vadjustment().set_value(vadj)
 
343
 
328
344
    #~ @interrupt_build_and_wait
329
345
    def _build_categorised_installedview(self):
330
346
        LOG.debug('Rebuilding categorised installedview...')
334
350
        if window:
335
351
            window.set_cursor(self.busy_cursor)
336
352
        self.show_installed_view_spinner()
 
353
        treeview_state = self._save_treeview_state()
337
354
 
338
355
        # disconnect the model to avoid e.g. updates of "cursor-changed"
339
356
        #  AppTreeView.expand_path while the model is in rebuild-flux
415
432
                mode=AppView.INSTALLED_MODE)
416
433
 
417
434
            self.app_view.set_model(self.treefilter)
 
435
            self._restore_treeview_state(treeview_state)
418
436
 
419
437
            # hide the local spinner
420
438
            self.hide_installed_view_spinner()