src/eric7/Plugins/VcsPlugins/vcsGit/GitPatchFilesDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
20 20
21 class GitPatchFilesDialog(QDialog, Ui_GitPatchFilesDialog): 21 class GitPatchFilesDialog(QDialog, Ui_GitPatchFilesDialog):
22 """ 22 """
23 Class implementing a dialog to select a list of patch files. 23 Class implementing a dialog to select a list of patch files.
24 """ 24 """
25
25 def __init__(self, rootDir, patchCheckData, parent=None): 26 def __init__(self, rootDir, patchCheckData, parent=None):
26 """ 27 """
27 Constructor 28 Constructor
28 29
29 @param rootDir root of the directory tree (string) 30 @param rootDir root of the directory tree (string)
30 @param patchCheckData tuple of data as returned by the 31 @param patchCheckData tuple of data as returned by the
31 getData() method 32 getData() method
32 @param parent reference to the parent widget (QWidget) 33 @param parent reference to the parent widget (QWidget)
33 """ 34 """
34 super().__init__(parent) 35 super().__init__(parent)
35 self.setupUi(self) 36 self.setupUi(self)
36 37
37 self.__rootDir = rootDir 38 self.__rootDir = rootDir
38 if patchCheckData is not None: 39 if patchCheckData is not None:
39 self.patchFilesList.addItems(patchCheckData[0]) 40 self.patchFilesList.addItems(patchCheckData[0])
40 self.stripSpinBox.setValue(patchCheckData[1]) 41 self.stripSpinBox.setValue(patchCheckData[1])
41 self.eofCheckBox.setChecked(patchCheckData[2]) 42 self.eofCheckBox.setChecked(patchCheckData[2])
42 self.lineCountsCheckBox.setChecked(patchCheckData[3]) 43 self.lineCountsCheckBox.setChecked(patchCheckData[3])
43 44
44 self.addButton.setIcon(UI.PixmapCache.getIcon("plus")) 45 self.addButton.setIcon(UI.PixmapCache.getIcon("plus"))
45 self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus")) 46 self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus"))
46 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) 47 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow"))
47 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) 48 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow"))
48 49
49 self.__okButton = self.buttonBox.button( 50 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
50 QDialogButtonBox.StandardButton.Ok)
51 self.__okButton.setEnabled(len(self.__getPatchFilesList()) > 0) 51 self.__okButton.setEnabled(len(self.__getPatchFilesList()) > 0)
52 52
53 self.deleteButton.setEnabled(False) 53 self.deleteButton.setEnabled(False)
54 self.upButton.setEnabled(False) 54 self.upButton.setEnabled(False)
55 self.downButton.setEnabled(False) 55 self.downButton.setEnabled(False)
56 56
57 @pyqtSlot() 57 @pyqtSlot()
58 def on_patchFilesList_itemSelectionChanged(self): 58 def on_patchFilesList_itemSelectionChanged(self):
59 """ 59 """
60 Private slot to enable button states depending on selection. 60 Private slot to enable button states depending on selection.
61 """ 61 """
62 selectedItems = self.patchFilesList.selectedItems() 62 selectedItems = self.patchFilesList.selectedItems()
63 count = len(selectedItems) 63 count = len(selectedItems)
64 isFirst = ( 64 isFirst = count == 1 and self.patchFilesList.row(selectedItems[0]) == 0
65 count == 1 and
66 self.patchFilesList.row(selectedItems[0]) == 0
67 )
68 isLast = ( 65 isLast = (
69 count == 1 and 66 count == 1
70 self.patchFilesList.row(selectedItems[0]) == 67 and self.patchFilesList.row(selectedItems[0])
71 self.patchFilesList.count() - 1 68 == self.patchFilesList.count() - 1
72 ) 69 )
73 self.deleteButton.setEnabled(count > 0) 70 self.deleteButton.setEnabled(count > 0)
74 self.upButton.setEnabled(count == 1 and not isFirst) 71 self.upButton.setEnabled(count == 1 and not isFirst)
75 self.downButton.setEnabled(count == 1 and not isLast) 72 self.downButton.setEnabled(count == 1 and not isLast)
76 73
77 @pyqtSlot() 74 @pyqtSlot()
78 def on_addButton_clicked(self): 75 def on_addButton_clicked(self):
79 """ 76 """
80 Private slot to add patch files to the list. 77 Private slot to add patch files to the list.
81 """ 78 """
82 patchFiles = EricFileDialog.getOpenFileNames( 79 patchFiles = EricFileDialog.getOpenFileNames(
83 self, 80 self,
84 self.tr("Patch Files"), 81 self.tr("Patch Files"),
85 self.__rootDir, 82 self.__rootDir,
86 self.tr("Patch Files (*.diff *.patch);;All Files (*)")) 83 self.tr("Patch Files (*.diff *.patch);;All Files (*)"),
84 )
87 if patchFiles: 85 if patchFiles:
88 currentPatchFiles = self.__getPatchFilesList() 86 currentPatchFiles = self.__getPatchFilesList()
89 for patchFile in patchFiles: 87 for patchFile in patchFiles:
90 patchFile = Utilities.toNativeSeparators(patchFile) 88 patchFile = Utilities.toNativeSeparators(patchFile)
91 if patchFile not in currentPatchFiles: 89 if patchFile not in currentPatchFiles:
92 self.patchFilesList.addItem(patchFile) 90 self.patchFilesList.addItem(patchFile)
93 91
94 self.__okButton.setEnabled(len(self.__getPatchFilesList()) > 0) 92 self.__okButton.setEnabled(len(self.__getPatchFilesList()) > 0)
95 self.on_patchFilesList_itemSelectionChanged() 93 self.on_patchFilesList_itemSelectionChanged()
96 94
97 @pyqtSlot() 95 @pyqtSlot()
98 def on_deleteButton_clicked(self): 96 def on_deleteButton_clicked(self):
99 """ 97 """
100 Private slot to delete the selected patch files. 98 Private slot to delete the selected patch files.
101 """ 99 """
102 for itm in self.patchFilesList.selectedItems(): 100 for itm in self.patchFilesList.selectedItems():
103 row = self.patchFilesList.row(itm) 101 row = self.patchFilesList.row(itm)
104 self.patchFilesList.takeItem(row) 102 self.patchFilesList.takeItem(row)
105 del itm 103 del itm
106 104
107 self.__okButton.setEnabled(len(self.__getPatchFilesList()) > 0) 105 self.__okButton.setEnabled(len(self.__getPatchFilesList()) > 0)
108 self.on_patchFilesList_itemSelectionChanged() 106 self.on_patchFilesList_itemSelectionChanged()
109 107
110 @pyqtSlot() 108 @pyqtSlot()
111 def on_upButton_clicked(self): 109 def on_upButton_clicked(self):
112 """ 110 """
113 Private slot to move an entry up in the list. 111 Private slot to move an entry up in the list.
114 """ 112 """
115 row = self.patchFilesList.row(self.patchFilesList.selectedItems()[0]) 113 row = self.patchFilesList.row(self.patchFilesList.selectedItems()[0])
116 itm = self.patchFilesList.takeItem(row) 114 itm = self.patchFilesList.takeItem(row)
117 self.patchFilesList.insertItem(row - 1, itm) 115 self.patchFilesList.insertItem(row - 1, itm)
118 itm.setSelected(True) 116 itm.setSelected(True)
119 117
120 @pyqtSlot() 118 @pyqtSlot()
121 def on_downButton_clicked(self): 119 def on_downButton_clicked(self):
122 """ 120 """
123 Private slot to move an entry down in the list. 121 Private slot to move an entry down in the list.
124 """ 122 """
125 row = self.patchFilesList.row(self.patchFilesList.selectedItems()[0]) 123 row = self.patchFilesList.row(self.patchFilesList.selectedItems()[0])
126 itm = self.patchFilesList.takeItem(row) 124 itm = self.patchFilesList.takeItem(row)
127 self.patchFilesList.insertItem(row + 1, itm) 125 self.patchFilesList.insertItem(row + 1, itm)
128 itm.setSelected(True) 126 itm.setSelected(True)
129 127
130 def __getPatchFilesList(self): 128 def __getPatchFilesList(self):
131 """ 129 """
132 Private method to get the list of patch files. 130 Private method to get the list of patch files.
133 131
134 @return list of patch files (list of string) 132 @return list of patch files (list of string)
135 """ 133 """
136 patchFiles = [] 134 patchFiles = []
137 for row in range(self.patchFilesList.count()): 135 for row in range(self.patchFilesList.count()):
138 itm = self.patchFilesList.item(row) 136 itm = self.patchFilesList.item(row)
139 patchFiles.append(itm.text()) 137 patchFiles.append(itm.text())
140 138
141 return patchFiles 139 return patchFiles
142 140
143 def getData(self): 141 def getData(self):
144 """ 142 """
145 Public slot to get the entered data. 143 Public slot to get the entered data.
146 144
147 @return tuple of list of patch files, strip count, flag indicating 145 @return tuple of list of patch files, strip count, flag indicating
148 that the patch has inaccurate end-of-file marker and a flag 146 that the patch has inaccurate end-of-file marker and a flag
149 indicating to not trust the line count information 147 indicating to not trust the line count information
150 (list of string, integer, boolean, boolean) 148 (list of string, integer, boolean, boolean)
151 """ 149 """
152 return (self.__getPatchFilesList(), self.stripSpinBox.value(), 150 return (
153 self.eofCheckBox.isChecked(), 151 self.__getPatchFilesList(),
154 self.lineCountsCheckBox.isChecked()) 152 self.stripSpinBox.value(),
153 self.eofCheckBox.isChecked(),
154 self.lineCountsCheckBox.isChecked(),
155 )

eric ide

mercurial