Changeset 4270

Show
Ignore:
Timestamp:
03/04/09 22:12:47 (4 years ago)
Author:
gpolo
Message:

Fixed ticket #125: Update the recent scans listing without needing to restart Umit.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/umit/gui/MainWindow.py

    r4269 r4270  
    363363 
    364364        # This is the default, minimal UI 
     365 
    365366        self.default_ui = """<menubar> 
    366367            <menu action='Scan'> 
     
    369370            <menuitem action='Save Scan'/> 
    370371            <menuitem action='Open Scan'/> 
    371             %(recentscans)s 
     372            <placeholder name='RecentScans'> 
     373            </placeholder> 
    372374            <menuitem action='Quit'/> 
    373375            </menu> 
     
    421423            """ 
    422424 
    423         self.get_recent_scans() 
    424  
    425425        self.main_action_group.add_actions(self.main_actions) 
    426426 
     
    431431        self.ui_manager.insert_action_group(self.main_action_group, 0) 
    432432        self.ui_manager.add_ui_from_string(self.default_ui) 
    433   
     433 
     434        self._rscans_actiongroup = gtk.ActionGroup('UIRecentScans') 
     435        self.ui_manager.insert_action_group(self._rscans_actiongroup, 1) 
     436        self._rscans_merge_id = 0 
     437        self.update_recent_scans() 
     438 
    434439        self.schedctrl.ui_action = self.main_action_group.get_action( 
    435440                'Sched Control') 
     
    699704                raise 
    700705 
    701  
    702     def get_recent_scans(self): 
    703         """Shows the most recent saved scans.""" 
     706    def update_recent_scans(self): 
     707        """Shows the most recent saved scans in the 'Scan' menu.""" 
     708        # clean previous recent scans listing, if any 
     709        if self._rscans_merge_id: 
     710            for action in self._rscans_actiongroup.list_actions(): 
     711                self._rscans_actiongroup.remove_action(action) 
     712            self.ui_manager.remove_ui(self._rscans_merge_id) 
     713            # ensure_update is used here so we can be sure that the 
     714            # UIManager updates our UI. Not doing so will cause 
     715            # new items in the recent scans listing to appear at the 
     716            # end of the current listing. 
     717            self.ui_manager.ensure_update() 
     718 
    704719        r_scans = recent_scans.get_recent_scans_list() 
     720        rscans_ui = """ 
     721        <menubar> 
     722            <menu action='Scan'> 
     723                <placeholder name='RecentScans'> 
     724                %s 
     725                </placeholder> 
     726            </menu> 
     727        </menubar>""" 
    705728        new_rscan_xml = '' 
     729 
     730        actions = [] 
    706731 
    707732        # Add the seven most recent saved scans to the menu. 
     
    718743                new_rscan_xml += "<menuitem action='%s'/>\n" % \ 
    719744                              xml.sax.saxutils.escape(scan) 
    720  
    721                 self.main_actions.append(new_rscan) 
    722         else: 
    723             new_rscan_xml += "<separator />\n" 
    724  
    725         self.default_ui %= {'recentscans': new_rscan_xml} 
     745                actions.append(new_rscan) 
     746        new_rscan_xml += "<separator />\n" 
     747 
     748        self._rscans_actiongroup.add_actions(actions) 
     749        self._rscans_merge_id = self.ui_manager.add_ui_from_string( 
     750                rscans_ui % new_rscan_xml) 
    726751 
    727752    def _create_menubar(self): 
     
    10911116                recent_scans.add_recent_scan(saved_filename) 
    10921117                recent_scans.save() 
     1118                self.update_recent_scans() 
    10931119 
    10941120        else: