~simon-kersey/bzr-explorer/add-tool-exec

« back to all changes in this revision

Viewing changes to lib/explorer.py

  • Committer: Simon Kersey
  • Date: 2010-01-20 23:22:10 UTC
  • mfrom: (360.1.1 update-tool-defs)
  • Revision ID: simon.kersey@ipl.com-20100120232210-1ug3fm3uhh2w112d
Enable new tools.xml features:
- Linking visibility of Toolset to visibility of Working Tree
- Controlling what a tool is added to: tools menu or toolbox or both
- Tool type 'bzrexec' causes qrun to be called with --execute option
- If tool is in toolset that is linked to working tree and tool action contains %(selected)s selected items in working tree are passed as arguments to command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
        self.dry_run = dry_run
143
143
        self._app_runner = app_runner.ApplicationRunner(self.show_error)
144
144
        self._custom_modeless_dialogs = {}
 
145
        self._tools_linked_to_wt = False
145
146
        # permitted values are None, local, remote
146
147
        self.location_category = None
147
148
        self.location_views = None
825
826
            for prof in self._profiles:
826
827
                for entry in prof.tools().root():
827
828
                    self._add_tool_entry_to_menu(entry, menu)
828
 
 
 
829
        #
 
830
        # Disable refresh on working tree visibility
 
831
        if self._tools_linked_to_wt:
 
832
            self._tools_linked_to_wt = False
 
833
            trace.mutter("Disabling refresh on working tree visibility")
 
834
            QtCore.QObject.disconnect(self._wt_browser,
 
835
                                      QtCore.SIGNAL("visibilityChanged(bool)"),
 
836
                                      self._refresh_tools_menu)
 
837
        #
829
838
        # TODO: Add Tools/Options if on Windows
830
839
        if self.desktop_env.name() == 'windows':
831
840
            footer_actions = [("action", self.ui.action_Preferences)]
833
842
            footer_actions = None
834
843
        self._refresh_dynamic_menu(self.ui.menu_Tools,
835
844
            self._std_tool_menu_items, tool_appender, footer_actions)
836
 
        self._toolbox.refresh()
837
 
 
 
845
        self._toolbox.refresh(self._wt_browser.isVisible())
 
846
        #
 
847
        # Enable refresh on working tree visibility if tools linked to it
 
848
        if self._toolbox.linked_to_wt and not self._tools_linked_to_wt:
 
849
            trace.mutter("Enabling refresh on wt visibility - toolbox")
 
850
            self._tools_linked_to_wt = True
 
851
            QtCore.QObject.connect(self._wt_browser,
 
852
                                   QtCore.SIGNAL("visibilityChanged(bool)"),
 
853
                                   self._refresh_tools_menu)
 
854
        
838
855
    def _add_tool_entry_to_menu(self, entry, menu):
839
856
        if isinstance(entry, tools.Tool):
840
 
            def open_callback():
841
 
                self._do_open_tool(entry)
842
 
            label = entry.title
843
 
            action = menu.addAction(entry.title, open_callback)
844
 
            tip = "(%s) %s" % (entry.type, entry.action)
845
 
            action.setStatusTip(tip)
846
 
            if entry.icon:
847
 
                icon = kinds.icon_by_resource_path(entry.icon)
848
 
            else:
849
 
                icon = kinds.icon_for_kind(entry.type)
850
 
            action.setIcon(icon)
 
857
            if entry.applies_to_menu():
 
858
                def open_callback():
 
859
                    self._do_open_tool(entry)
 
860
                label = entry.title
 
861
                action = menu.addAction(entry.title, open_callback)
 
862
                tip = "(%s) %s" % (entry.type, entry.action)
 
863
                action.setStatusTip(tip)
 
864
                if entry.icon:
 
865
                    icon = kinds.icon_by_resource_path(entry.icon)
 
866
                else:
 
867
                    icon = kinds.icon_for_kind(entry.type)
 
868
                action.setIcon(icon)
851
869
        elif isinstance(entry, tools.ToolFolder):
852
 
            submenu = QtGui.QMenu(entry.title, menu)
853
 
            for child in entry:
854
 
                self._add_tool_entry_to_menu(child, submenu)
855
 
            menu.addMenu(submenu)
 
870
            if entry.in_menu():
 
871
                #
 
872
                # if toolset depends on working tree then rebuild tools menu
 
873
                # based on visibility of working tree browser
 
874
                if entry.linked_to_wt() and not self._tools_linked_to_wt:
 
875
                    trace.mutter("Enabling refresh on wt visibility - menu")
 
876
                    self._tools_linked_to_wt = True
 
877
                    QtCore.QObject.connect(self._wt_browser,
 
878
                                           QtCore.SIGNAL("visibilityChanged(bool)"),
 
879
                                           self._refresh_tools_menu)
 
880
                #
 
881
                # build toolset based menu
 
882
                if (not entry.linked_to_wt() or 
 
883
                    (entry.linked_to_wt() and self._wt_browser.isVisible())) :
 
884
                    submenu = QtGui.QMenu(entry.title, menu)
 
885
                    for child in entry:
 
886
                        self._add_tool_entry_to_menu(child, submenu)
 
887
                    menu.addMenu(submenu)
856
888
        elif isinstance(entry, tools.ToolSeparator):
857
889
            menu.addSeparator()
858
890
 
862
894
                self.location_context)
863
895
            self.open_web_browser(link)
864
896
        else:
 
897
            #
 
898
            # for wt linked items get items selected in working tree
 
899
            if tool.linked_to_wt() and tool.uses_selected:
 
900
                selected_items = \
 
901
                    self._wt_browser._browser._tree_viewer.get_selection_items()
 
902
                if len(selected_items) > 0:
 
903
                    paths = [item.path for item in selected_items]
 
904
                    self.location_context['selected'] = " ".join(paths) 
865
905
            args = mod_app_suite.command_to_args(tool.action,
866
906
                self.location_context)
867
 
            if tool.type == 'bzr':
 
907
            if (tool.type == 'bzr') or (tool.type == 'bzrexec'):
868
908
                # If the command looks like it's a GUI one,
869
909
                # run it directly. Otherwise, run it via qrun
870
910
                # making sure that we're passing --ui-mode.
871
911
                if args[0][0] in ['q', 'g']:
872
912
                    args = self._get_bzr_executable() + args
 
913
                elif tool.type == 'bzrexec':
 
914
                    args = self._get_bzr_executable() + \
 
915
                           ['qrun', '--ui-mode', '--execute', '--'] + args
873
916
                else:
874
 
                    args = self._get_bzr_executable() + ['qrun', '--ui-mode', '--'] + args
 
917
                    args = self._get_bzr_executable() + \
 
918
                           ['qrun', '--ui-mode', '--'] + args
875
919
            self.run_app(args)
876
920
 
877
921
    ## Show message helpers ##