From 52fce13cc769559de2f7316511b06edd609ddf1d Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 17 Jul 2020 00:40:18 -0700 Subject: [PATCH] submodules: add a dialog for adding new submodules Implement an AddSubmodule dialog for adding new submodules to a repository. Add an "Add Submodule..." menu entry to the "Actions" menu and add a "+" button to the Submodules widget to start the dialog. Closes #534 Suggested-by: Muhammad Bashir Al-Noimi Signed-off-by: David Aguilar --- CHANGES.rst | 3 ++ cola/widgets/main.py | 6 +++ cola/widgets/submodules.py | 113 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 117 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8f0894b8..0cfb79f0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,9 @@ v3.8 Usability, bells and whistles ----------------------------- +* The submodules widget can now be used to add submodules. + (`#534 `_) + * The image diff viewer can now be toggled between text and image modes. This is helpful when, for example, diffing .svg files where it can be useful to see diffs in both an image and text representation. diff --git a/cola/widgets/main.py b/cola/widgets/main.py index b944309b..58917c2e 100644 --- a/cola/widgets/main.py +++ b/cola/widgets/main.py @@ -307,6 +307,11 @@ class MainView(standard.MainWindow): cmds.run(cmds.SubmodulesUpdate, context), ) + self.add_submodule_action = add_action( + self, N_('Add Submodule...'), + partial(submodules.add_submodule, context, parent=self) + ) + self.fetch_action = add_action( self, N_('Fetch...'), partial(remote.fetch, context), hotkeys.FETCH ) @@ -582,6 +587,7 @@ class MainView(standard.MainWindow): self.actions_menu.addAction(self.merge_abort_action) self.actions_menu.addSeparator() self.actions_menu.addAction(self.update_submodules_action) + self.actions_menu.addAction(self.add_submodule_action) self.actions_menu.addSeparator() self.actions_reset_menu = self.actions_menu.addMenu(N_('Reset')) self.actions_reset_menu.addAction(self.reset_branch_head_action) diff --git a/cola/widgets/submodules.py b/cola/widgets/submodules.py index 0f5a3c34..d5e545c7 100644 --- a/cola/widgets/submodules.py +++ b/cola/widgets/submodules.py @@ -6,17 +6,30 @@ from qtpy.QtCore import Qt from qtpy.QtCore import Signal from .. import cmds +from .. import compat from .. import core from .. import qtutils from .. import icons from ..i18n import N_ from ..widgets import defs from ..widgets import standard +from ..widgets import text + + +def add_submodule(context, parent): + """Add a new submodule""" + dlg = AddSubmodule(parent) + dlg.show() + if dlg.exec_() == standard.Dialog.Accepted: + cmd = dlg.get(context) + cmd.do() class SubmodulesWidget(QtWidgets.QFrame): + def __init__(self, context, parent): - QtWidgets.QFrame.__init__(self, parent) + super(SubmodulesWidget, self).__init__(parent) + self.context = context self.setToolTip(N_('Submodules')) self.tree = SubmodulesTreeWidget(context, parent=self) @@ -26,6 +39,9 @@ class SubmodulesWidget(QtWidgets.QFrame): self.setLayout(self.main_layout) # Titlebar buttons + self.add_button = qtutils.create_action_button( + tooltip=N_('Add Submodule'), icon=icons.add() + ) self.refresh_button = qtutils.create_action_button( tooltip=N_('Refresh'), icon=icons.sync() ) @@ -35,7 +51,11 @@ class SubmodulesWidget(QtWidgets.QFrame): ) self.button_layout = qtutils.hbox( - defs.no_margin, defs.spacing, self.open_parent_button, self.refresh_button + defs.no_margin, + defs.spacing, + self.add_button, + self.open_parent_button, + self.refresh_button ) self.corner_widget = QtWidgets.QWidget(self) self.corner_widget.setLayout(self.button_layout) @@ -43,13 +63,96 @@ class SubmodulesWidget(QtWidgets.QFrame): titlebar.add_corner_widget(self.corner_widget) # Connections - qtutils.connect_button( - self.refresh_button, context.model.update_submodules_list - ) + qtutils.connect_button(self.add_button, self.add_submodule) + qtutils.connect_button(self.refresh_button, self.refresh) qtutils.connect_button( self.open_parent_button, cmds.run(cmds.OpenParentRepo, context) ) + def refresh(self): + self.context.model.update_submodules_list() + + def add_submodule(self): + add_submodule(self.context, self) + + +class AddSubmodule(standard.Dialog): + """Add a new submodule""" + + def __init__(self, parent): + super(AddSubmodule, self).__init__(parent=parent) + + hint = N_('git://git.example.com/repo.git') + tooltip = N_('Submodule URL (can be relative, ex: ../repo.git)') + self.url_text = text.HintedDefaultLineEdit(hint, tooltip=tooltip, parent=self) + + hint = N_('path/to/submodule') + tooltip = N_('Submodule path within the current repository (optional)') + self.path_text = text.HintedDefaultLineEdit(hint, tooltip=tooltip, parent=self) + + hint = N_('Branch name') + tooltip = N_('Submodule branch to track (optional)') + self.branch_text = text.HintedDefaultLineEdit(hint, tooltip=tooltip, parent=self) + + self.depth_spinbox = standard.SpinBox( + mini=0, maxi=compat.maxint, value=0, parent=self) + self.depth_spinbox.setToolTip( + N_('Create a shallow clone with history truncated to the ' + 'specified number of revisions. 0 performs a full clone.') + ) + + hint = N_('Reference URL') + tooltip = N_('Reference repository to use when cloning (optional)') + self.reference_text = text.HintedDefaultLineEdit(hint, tooltip=tooltip, parent=self) + + self.add_button = qtutils.ok_button(N_('Add Submodule'), enabled=False) + self.close_button = qtutils.close_button() + + self.form_layout = qtutils.form( + defs.no_margin, + defs.button_spacing, + (N_('URL'), self.url_text), + (N_('Path'), self.path_text), + (N_('Branch'), self.branch_text), + (N_('Depth'), self.depth_spinbox), + (N_('Reference Repository'), self.reference_text), + ) + self.button_layout = qtutils.hbox( + defs.no_margin, + defs.button_spacing, + qtutils.STRETCH, + self.add_button, + self.close_button + ) + + self.main_layout = qtutils.vbox( + defs.large_margin, + defs.spacing, + self.form_layout, + self.button_layout + ) + self.setLayout(self.main_layout) + self.init_size(parent=qtutils.active_window()) + + self.url_text.textChanged.connect(self._update_widgets) + + qtutils.connect_button(self.add_button, self.accept) + qtutils.connect_button(self.close_button, self.close) + + def _update_widgets(self, text): + value = self.url_text.value() + self.add_button.setEnabled(bool(value)) + + def get(self, context): + return cmds.SubmoduleAdd( + context, + self.url_text.value(), + self.path_text.value(), + self.branch_text.value(), + self.depth_spinbox.value(), + self.reference_text.value() + ) + # pylint: disable=too-many-ancestors class SubmodulesTreeWidget(standard.TreeWidget): -- 2.11.4.GIT