~kiwinote/software-center/lp951557

« back to all changes in this revision

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

  • Committer: Gary Lasker
  • Date: 2012-03-30 07:26:46 UTC
  • mfrom: (2929.4.7 treeview-state)
  • Revision ID: gary.lasker@canonical.com-20120330072646-dk8m2shdry1iktu8
* lp:~mvo/software-center/treeview-keep-state-on-db-cache-change:
 - restore the state of the installed view treeview when the
   the db or cache changes, such as on an app install or remove

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()),
 
333
            None)
 
334
        vadj = self.app_view.tree_view_scroll.get_vadjustment().get_value()
 
335
        return expanded_rows, vadj
 
336
 
 
337
    def _restore_treeview_state(self, state):
 
338
        expanded_rows, vadj = state
 
339
        for ind in expanded_rows:
 
340
            path = Gtk.TreePath.new_from_string(ind)
 
341
            self.app_view.tree_view.expand_row(path, False)
 
342
        self.app_view.tree_view_scroll.get_vadjustment().set_lower(vadj)
 
343
        self.app_view.tree_view_scroll.get_vadjustment().set_value(vadj)
 
344
 
328
345
    #~ @interrupt_build_and_wait
329
 
    def _build_categorised_installedview(self):
 
346
    def _build_categorised_installedview(self, keep_state=False):
330
347
        LOG.debug('Rebuilding categorised installedview...')
331
348
 
332
349
        # display the busy cursor and a local spinner while we build the view
335
352
            window.set_cursor(self.busy_cursor)
336
353
        self.show_installed_view_spinner()
337
354
 
 
355
        if keep_state:
 
356
            treeview_state = self._save_treeview_state()
 
357
 
338
358
        # disconnect the model to avoid e.g. updates of "cursor-changed"
339
359
        #  AppTreeView.expand_path while the model is in rebuild-flux
340
360
        self.app_view.set_model(None)
415
435
                mode=AppView.INSTALLED_MODE)
416
436
 
417
437
            self.app_view.set_model(self.treefilter)
 
438
            if keep_state:
 
439
                self._restore_treeview_state(treeview_state)
418
440
 
419
441
            # hide the local spinner
420
442
            self.hide_installed_view_spinner()
431
453
 
432
454
        GObject.idle_add(profiled_rebuild_categorised_view)
433
455
 
434
 
    def _build_oneconfview(self):
 
456
    def _build_oneconfview(self, keep_state=False):
435
457
        LOG.debug('Rebuilding oneconfview for %s...' % self.current_hostid)
436
458
 
437
459
        # display the busy cursor and the local spinner while we build the view
440
462
            window.set_cursor(self.busy_cursor)
441
463
        self.show_installed_view_spinner()
442
464
 
 
465
        if keep_state:
 
466
            treeview_state = self._save_treeview_state()
 
467
 
443
468
        # disconnect the model to avoid e.g. updates of "cursor-changed"
444
469
        #  AppTreeView.expand_path while the model is in rebuild-flux
445
470
        self.app_view.set_model(None)
529
554
                mode=AppView.DIFF_MODE)
530
555
 
531
556
            self.app_view.set_model(self.treefilter)
 
557
            if keep_state:
 
558
                self._restore_treeview_state(treeview_state)
532
559
 
533
560
            # hide the local spinner
534
561
            self.hide_installed_view_spinner()
611
638
    def refresh_apps(self, *args, **kwargs):
612
639
        """refresh the applist and update the navigation bar """
613
640
        logging.debug("installedpane refresh_apps")
 
641
        keep_state = kwargs.get("keep_state", False)
614
642
        if self.current_hostid:
615
 
            self._build_oneconfview()
 
643
            self._build_oneconfview(keep_state)
616
644
        else:
617
 
            self._build_categorised_installedview()
 
645
            self._build_categorised_installedview(keep_state)
618
646
 
619
647
    def _clear_search(self):
620
648
        # remove the details and clear the search
641
669
        self.app_view._append_appcount(appcount, mode=AppView.DIFF_MODE)
642
670
        return vis_cats
643
671
 
 
672
    def _refresh_on_cache_or_db_change(self):
 
673
        self.refresh_apps(keep_state=True)
 
674
        self.app_details_view.refresh_app()
 
675
 
644
676
    def on_db_reopen(self, db):
645
 
        self.refresh_apps(rebuild=True)
646
 
        self.app_details_view.refresh_app()
 
677
        LOG.debug("on_db_reopen")
 
678
        self._refresh_on_cache_or_db_change()
 
679
 
 
680
    def on_cache_ready(self, cache):
 
681
        LOG.debug("on_cache_ready")
 
682
        self._refresh_on_cache_or_db_change()
647
683
 
648
684
    def on_application_selected(self, appview, app):
649
685
        """callback when an app is selected"""