Plugins/VcsPlugins/vcsSubversion/SvnDiffDialog.py

changeset 1503
4e48604157a4
parent 1300
9083f6b7ea3b
child 1509
c0b5e693b0eb
equal deleted inserted replaced
1501:cf7659c7b691 1503:4e48604157a4
100 100
101 self.process.kill() 101 self.process.kill()
102 102
103 self.contents.clear() 103 self.contents.clear()
104 self.paras = 0 104 self.paras = 0
105
106 self.filesCombo.clear()
107
108 self.__oldFile = ""
109 self.__oldFileLine = -1
110 self.__fileSeparators = []
105 111
106 args = [] 112 args = []
107 args.append('diff') 113 args.append('diff')
108 self.vcs.addArguments(args, self.vcs.options['global']) 114 self.vcs.addArguments(args, self.vcs.options['global'])
109 self.vcs.addArguments(args, self.vcs.options['diff']) 115 self.vcs.addArguments(args, self.vcs.options['diff'])
188 tc = self.contents.textCursor() 194 tc = self.contents.textCursor()
189 tc.movePosition(QTextCursor.Start) 195 tc.movePosition(QTextCursor.Start)
190 self.contents.setTextCursor(tc) 196 self.contents.setTextCursor(tc)
191 self.contents.ensureCursorVisible() 197 self.contents.ensureCursorVisible()
192 198
199 self.filesCombo.addItem(self.trUtf8("<Start>"), 0)
200 self.filesCombo.addItem(self.trUtf8("<End>"), -1)
201 for oldFile, newFile, pos in sorted(self.__fileSeparators):
202 if oldFile != newFile:
203 self.filesCombo.addItem("{0}\n{1}".format(oldFile, newFile), pos)
204 else:
205 self.filesCombo.addItem(oldFile, pos)
206
193 def __appendText(self, txt, format): 207 def __appendText(self, txt, format):
194 """ 208 """
195 Private method to append text to the end of the contents pane. 209 Private method to append text to the end of the contents pane.
196 210
197 @param txt text to insert (string) 211 @param txt text to insert (string)
201 tc.movePosition(QTextCursor.End) 215 tc.movePosition(QTextCursor.End)
202 self.contents.setTextCursor(tc) 216 self.contents.setTextCursor(tc)
203 self.contents.setCurrentCharFormat(format) 217 self.contents.setCurrentCharFormat(format)
204 self.contents.insertPlainText(txt) 218 self.contents.insertPlainText(txt)
205 219
220 def __extractFileName(self, line):
221 """
222 Private method to extract the file name out of a file separator line.
223
224 @param line line to be processed (string)
225 @return extracted file name (string)
226 """
227 f = line.split(None, 1)[1]
228 f = f.rsplit(None, 2)[0]
229 return f
230
231 def __processFileLine(self, line):
232 """
233 Private slot to process a line giving the old/new file.
234
235 @param line line to be processed (string)
236 """
237 if line.startswith('---'):
238 self.__oldFileLine = self.paras
239 self.__oldFile = self.__extractFileName(line)
240 else:
241 self.__fileSeparators.append(
242 (self.__oldFile, self.__extractFileName(line), self.__oldFileLine))
243
206 def __readStdout(self): 244 def __readStdout(self):
207 """ 245 """
208 Private slot to handle the readyReadStandardOutput signal. 246 Private slot to handle the readyReadStandardOutput signal.
209 247
210 It reads the output of the process, formats it and inserts it into 248 It reads the output of the process, formats it and inserts it into
217 Preferences.getSystem("IOEncoding"), 255 Preferences.getSystem("IOEncoding"),
218 'replace') 256 'replace')
219 if self.summaryPath: 257 if self.summaryPath:
220 line = line.replace(self.summaryPath + '/', '') 258 line = line.replace(self.summaryPath + '/', '')
221 line = " ".join(line.split()) 259 line = " ".join(line.split())
260 if line.startswith("---") or \
261 line.startswith("+++"):
262 self.__processFileLine(line)
263
222 if line.startswith('+') or line.startswith('>') or line.startswith('A '): 264 if line.startswith('+') or line.startswith('>') or line.startswith('A '):
223 format = self.cAddedFormat 265 format = self.cAddedFormat
224 elif line.startswith('-') or line.startswith('<') or line.startswith('D '): 266 elif line.startswith('-') or line.startswith('<') or line.startswith('D '):
225 format = self.cRemovedFormat 267 format = self.cRemovedFormat
226 elif line.startswith('@@'): 268 elif line.startswith('@@'):
252 @param button button that was clicked (QAbstractButton) 294 @param button button that was clicked (QAbstractButton)
253 """ 295 """
254 if button == self.buttonBox.button(QDialogButtonBox.Save): 296 if button == self.buttonBox.button(QDialogButtonBox.Save):
255 self.on_saveButton_clicked() 297 self.on_saveButton_clicked()
256 298
299 @pyqtSlot(int)
300 def on_filesCombo_activated(self, index):
301 """
302 Private slot to handle the selection of a file.
303
304 @param index activated row (integer)
305 """
306 para = self.filesCombo.itemData(index)
307
308 if para == 0:
309 tc = self.contents.textCursor()
310 tc.movePosition(QTextCursor.Start)
311 self.contents.setTextCursor(tc)
312 self.contents.ensureCursorVisible()
313 elif para == -1:
314 tc = self.contents.textCursor()
315 tc.movePosition(QTextCursor.End)
316 self.contents.setTextCursor(tc)
317 self.contents.ensureCursorVisible()
318 else:
319 # step 1: move cursor to end
320 tc = self.contents.textCursor()
321 tc.movePosition(QTextCursor.End)
322 self.contents.setTextCursor(tc)
323 self.contents.ensureCursorVisible()
324
325 # step 2: move cursor to desired line
326 tc = self.contents.textCursor()
327 delta = tc.blockNumber() - para
328 tc.movePosition(QTextCursor.PreviousBlock, QTextCursor.MoveAnchor, delta)
329 self.contents.setTextCursor(tc)
330 self.contents.ensureCursorVisible()
331
257 @pyqtSlot() 332 @pyqtSlot()
258 def on_saveButton_clicked(self): 333 def on_saveButton_clicked(self):
259 """ 334 """
260 Private slot to handle the Save button press. 335 Private slot to handle the Save button press.
261 336

eric ide

mercurial