1163 """ |
1163 """ |
1164 Private method to stage the selected lines or hunk. |
1164 Private method to stage the selected lines or hunk. |
1165 """ |
1165 """ |
1166 cursor = self.lDiffEdit.textCursor() |
1166 cursor = self.lDiffEdit.textCursor() |
1167 startIndex, endIndex = self.__selectedLinesIndexes(self.lDiffEdit) |
1167 startIndex, endIndex = self.__selectedLinesIndexes(self.lDiffEdit) |
1168 if cursor.hasSelection(): |
1168 patch = ( |
1169 patch = self.lDiffParser.createLinesPatch(startIndex, endIndex) |
1169 self.lDiffParser.createLinesPatch(startIndex, endIndex) |
1170 else: |
1170 if cursor.hasSelection() else |
1171 patch = self.lDiffParser.createHunkPatch(startIndex) |
1171 self.lDiffParser.createHunkPatch(startIndex) |
|
1172 ) |
1172 if patch: |
1173 if patch: |
1173 patchFile = self.__tmpPatchFileName() |
1174 patchFile = self.__tmpPatchFileName() |
1174 try: |
1175 try: |
1175 with open(patchFile, "w") as f: |
1176 with open(patchFile, "w") as f: |
1176 f.write(patch) |
1177 f.write(patch) |
1184 """ |
1185 """ |
1185 Private method to unstage the selected lines or hunk. |
1186 Private method to unstage the selected lines or hunk. |
1186 """ |
1187 """ |
1187 cursor = self.rDiffEdit.textCursor() |
1188 cursor = self.rDiffEdit.textCursor() |
1188 startIndex, endIndex = self.__selectedLinesIndexes(self.rDiffEdit) |
1189 startIndex, endIndex = self.__selectedLinesIndexes(self.rDiffEdit) |
1189 if cursor.hasSelection(): |
1190 patch = ( |
1190 patch = self.rDiffParser.createLinesPatch(startIndex, endIndex, |
1191 self.rDiffParser.createLinesPatch(startIndex, endIndex, |
1191 reverse=True) |
1192 reverse=True) |
1192 else: |
1193 if cursor.hasSelection() else |
1193 patch = self.rDiffParser.createHunkPatch(startIndex) |
1194 self.rDiffParser.createHunkPatch(startIndex) |
|
1195 ) |
1194 if patch: |
1196 if patch: |
1195 patchFile = self.__tmpPatchFileName() |
1197 patchFile = self.__tmpPatchFileName() |
1196 try: |
1198 try: |
1197 with open(patchFile, "w") as f: |
1199 with open(patchFile, "w") as f: |
1198 f.write(patch) |
1200 f.write(patch) |
1206 """ |
1208 """ |
1207 Private method to revert the selected lines or hunk. |
1209 Private method to revert the selected lines or hunk. |
1208 """ |
1210 """ |
1209 cursor = self.lDiffEdit.textCursor() |
1211 cursor = self.lDiffEdit.textCursor() |
1210 startIndex, endIndex = self.__selectedLinesIndexes(self.lDiffEdit) |
1212 startIndex, endIndex = self.__selectedLinesIndexes(self.lDiffEdit) |
1211 if cursor.hasSelection(): |
1213 title = ( |
1212 title = self.tr("Revert selected lines") |
1214 self.tr("Revert selected lines") |
1213 else: |
1215 if cursor.hasSelection() else |
1214 title = self.tr("Revert hunk") |
1216 self.tr("Revert hunk") |
|
1217 ) |
1215 res = E5MessageBox.yesNo( |
1218 res = E5MessageBox.yesNo( |
1216 self, |
1219 self, |
1217 title, |
1220 title, |
1218 self.tr("""Are you sure you want to revert the selected""" |
1221 self.tr("""Are you sure you want to revert the selected""" |
1219 """ changes?""")) |
1222 """ changes?""")) |