|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to select the data for pushing a branch. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from .Ui_GitBranchPushDialog import Ui_GitBranchPushDialog |
|
16 |
|
17 |
|
18 class GitBranchPushDialog(QDialog, Ui_GitBranchPushDialog): |
|
19 """ |
|
20 Class implementing a dialog to select the data for pushing a branch. |
|
21 """ |
|
22 def __init__(self, branches, remotes, delete=False, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param branches list of branch names (list of string) |
|
27 @param remotes list of remote names (list of string) |
|
28 @param delete flag indicating a delete branch action (boolean) |
|
29 @param parent reference to the parent widget (QWidget) |
|
30 """ |
|
31 super(GitBranchPushDialog, self).__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
35 |
|
36 self.__allBranches = self.tr("<all branches>") |
|
37 |
|
38 if "origin" in remotes: |
|
39 self.remoteComboBox.addItem("origin") |
|
40 remotes.remove("origin") |
|
41 self.remoteComboBox.addItems(sorted(remotes)) |
|
42 |
|
43 if delete: |
|
44 self.branchComboBox.addItem("") |
|
45 else: |
|
46 self.branchComboBox.addItem(self.__allBranches) |
|
47 if "master" in branches: |
|
48 if not delete: |
|
49 self.branchComboBox.addItem("master") |
|
50 branches.remove("master") |
|
51 self.branchComboBox.addItems(sorted(branches)) |
|
52 |
|
53 if delete: |
|
54 self.__okButton.setEnabled(False) |
|
55 self.branchComboBox.setEditable(True) |
|
56 |
|
57 @pyqtSlot(str) |
|
58 def on_branchComboBox_editTextChanged(self, txt): |
|
59 """ |
|
60 Private slot to handle a change of the branch name. |
|
61 |
|
62 @param txt branch name (string) |
|
63 """ |
|
64 self.__okButton.setEnabled(bool(txt)) |
|
65 |
|
66 def getData(self): |
|
67 """ |
|
68 Public method to get the selected data. |
|
69 |
|
70 @return tuple of selected branch name, remote name and a flag |
|
71 indicating all branches (tuple of two strings and a boolean) |
|
72 """ |
|
73 return (self.branchComboBox.currentText(), |
|
74 self.remoteComboBox.currentText(), |
|
75 self.branchComboBox.currentText() == self.__allBranches) |