1# -*- coding: utf-8 -*-
2
3# Copyright (c) 2003 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4#
5
6"""
7Module implementing a dialog to enter the data for a tagging operation.
8"""
9
10from PyQt5.QtWidgets import QDialog, QDialogButtonBox
11
12from .Ui_SvnTagDialog import Ui_SvnTagDialog
13
14
15class SvnTagDialog(QDialog, Ui_SvnTagDialog):
16    """
17    Class implementing a dialog to enter the data for a tagging operation.
18    """
19    def __init__(self, taglist, reposURL, standardLayout, parent=None):
20        """
21        Constructor
22
23        @param taglist list of previously entered tags (list of strings)
24        @param reposURL repository path (string) or None
25        @param standardLayout flag indicating the layout of the
26            repository (boolean)
27        @param parent parent widget (QWidget)
28        """
29        super().__init__(parent)
30        self.setupUi(self)
31
32        self.okButton = self.buttonBox.button(
33            QDialogButtonBox.StandardButton.Ok)
34        self.okButton.setEnabled(False)
35
36        self.tagCombo.clear()
37        self.tagCombo.addItems(sorted(taglist, reverse=True))
38
39        if reposURL is not None and reposURL != "":
40            self.tagCombo.setEditText(reposURL)
41
42        if not standardLayout:
43            self.TagActionGroup.setEnabled(False)
44
45        msh = self.minimumSizeHint()
46        self.resize(max(self.width(), msh.width()), msh.height())
47
48    def on_tagCombo_editTextChanged(self, text):
49        """
50        Private method used to enable/disable the OK-button.
51
52        @param text text of the tag combobox (string)
53        """
54        self.okButton.setDisabled(text == "")
55
56    def getParameters(self):
57        """
58        Public method to retrieve the tag data.
59
60        @return tuple of string and int (tag, tag operation)
61        """
62        tag = self.tagCombo.currentText()
63        tagOp = 0
64        if self.createRegularButton.isChecked():
65            tagOp = 1
66        elif self.createBranchButton.isChecked():
67            tagOp = 2
68        elif self.deleteRegularButton.isChecked():
69            tagOp = 4
70        elif self.deleteBranchButton.isChecked():
71            tagOp = 8
72        return (tag, tagOp)
73