133 QApplication.processEvents() |
133 QApplication.processEvents() |
134 self.filename = fn |
134 self.filename = fn |
135 |
135 |
136 self.contents.clear() |
136 self.contents.clear() |
137 self.paras = 0 |
137 self.paras = 0 |
|
138 |
|
139 self.filesCombo.clear() |
|
140 |
|
141 self.__oldFile = "" |
|
142 self.__oldFileLine = -1 |
|
143 self.__fileSeparators = [] |
138 |
144 |
139 if Utilities.hasEnvironmentEntry('TEMP'): |
145 if Utilities.hasEnvironmentEntry('TEMP'): |
140 tmpdir = Utilities.getEnvironmentEntry('TEMP') |
146 tmpdir = Utilities.getEnvironmentEntry('TEMP') |
141 elif Utilities.hasEnvironmentEntry('TMPDIR'): |
147 elif Utilities.hasEnvironmentEntry('TMPDIR'): |
142 tmpdir = Utilities.getEnvironmentEntry('TMPDIR') |
148 tmpdir = Utilities.getEnvironmentEntry('TMPDIR') |
219 else: |
225 else: |
220 diffText = self.client.diff(tmpdir, name, |
226 diffText = self.client.diff(tmpdir, name, |
221 revision1=rev1, revision2=rev2, recurse=recurse) |
227 revision1=rev1, revision2=rev2, recurse=recurse) |
222 counter = 0 |
228 counter = 0 |
223 for line in diffText.splitlines(): |
229 for line in diffText.splitlines(): |
|
230 if line.startswith("---") or \ |
|
231 line.startswith("+++"): |
|
232 self.__processFileLine(line) |
|
233 |
224 self.__appendText("{0}{1}".format(line, os.linesep)) |
234 self.__appendText("{0}{1}".format(line, os.linesep)) |
225 counter += 1 |
235 counter += 1 |
226 if counter == 30: |
236 if counter == 30: |
227 # check for cancel every 30 lines |
237 # check for cancel every 30 lines |
228 counter = 0 |
238 counter = 0 |
263 self.contents.setTextCursor(tc) |
273 self.contents.setTextCursor(tc) |
264 self.contents.setCurrentCharFormat(format) |
274 self.contents.setCurrentCharFormat(format) |
265 self.contents.insertPlainText(line) |
275 self.contents.insertPlainText(line) |
266 self.paras += 1 |
276 self.paras += 1 |
267 |
277 |
|
278 def __extractFileName(self, line): |
|
279 """ |
|
280 Private method to extract the file name out of a file separator line. |
|
281 |
|
282 @param line line to be processed (string) |
|
283 @return extracted file name (string) |
|
284 """ |
|
285 f = line.split(None, 1)[1] |
|
286 f = f.rsplit(None, 2)[0] |
|
287 return f |
|
288 |
|
289 def __processFileLine(self, line): |
|
290 """ |
|
291 Private slot to process a line giving the old/new file. |
|
292 |
|
293 @param line line to be processed (string) |
|
294 """ |
|
295 if line.startswith('---'): |
|
296 self.__oldFileLine = self.paras |
|
297 self.__oldFile = self.__extractFileName(line) |
|
298 else: |
|
299 self.__fileSeparators.append( |
|
300 (self.__oldFile, self.__extractFileName(line), self.__oldFileLine)) |
|
301 |
268 def __finish(self): |
302 def __finish(self): |
269 """ |
303 """ |
270 Private slot called when the user pressed the button. |
304 Private slot called when the user pressed the button. |
271 """ |
305 """ |
272 QApplication.restoreOverrideCursor() |
306 QApplication.restoreOverrideCursor() |
277 |
311 |
278 tc = self.contents.textCursor() |
312 tc = self.contents.textCursor() |
279 tc.movePosition(QTextCursor.Start) |
313 tc.movePosition(QTextCursor.Start) |
280 self.contents.setTextCursor(tc) |
314 self.contents.setTextCursor(tc) |
281 self.contents.ensureCursorVisible() |
315 self.contents.ensureCursorVisible() |
|
316 |
|
317 self.filesCombo.addItem(self.trUtf8("<Start>"), 0) |
|
318 self.filesCombo.addItem(self.trUtf8("<End>"), -1) |
|
319 for oldFile, newFile, pos in sorted(self.__fileSeparators): |
|
320 if oldFile != newFile: |
|
321 self.filesCombo.addItem("{0}\n{1}".format(oldFile, newFile), pos) |
|
322 else: |
|
323 self.filesCombo.addItem(oldFile, pos) |
282 |
324 |
283 self._cancel() |
325 self._cancel() |
284 |
326 |
285 def on_buttonBox_clicked(self, button): |
327 def on_buttonBox_clicked(self, button): |
286 """ |
328 """ |
293 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
335 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
294 self.__finish() |
336 self.__finish() |
295 elif button == self.buttonBox.button(QDialogButtonBox.Save): |
337 elif button == self.buttonBox.button(QDialogButtonBox.Save): |
296 self.on_saveButton_clicked() |
338 self.on_saveButton_clicked() |
297 |
339 |
|
340 @pyqtSlot(int) |
|
341 def on_filesCombo_activated(self, index): |
|
342 """ |
|
343 Private slot to handle the selection of a file. |
|
344 |
|
345 @param index activated row (integer) |
|
346 """ |
|
347 para = self.filesCombo.itemData(index) |
|
348 |
|
349 if para == 0: |
|
350 tc = self.contents.textCursor() |
|
351 tc.movePosition(QTextCursor.Start) |
|
352 self.contents.setTextCursor(tc) |
|
353 self.contents.ensureCursorVisible() |
|
354 elif para == -1: |
|
355 tc = self.contents.textCursor() |
|
356 tc.movePosition(QTextCursor.End) |
|
357 self.contents.setTextCursor(tc) |
|
358 self.contents.ensureCursorVisible() |
|
359 else: |
|
360 # step 1: move cursor to end |
|
361 tc = self.contents.textCursor() |
|
362 tc.movePosition(QTextCursor.End) |
|
363 self.contents.setTextCursor(tc) |
|
364 self.contents.ensureCursorVisible() |
|
365 |
|
366 # step 2: move cursor to desired line |
|
367 tc = self.contents.textCursor() |
|
368 delta = tc.blockNumber() - para |
|
369 tc.movePosition(QTextCursor.PreviousBlock, QTextCursor.MoveAnchor, delta) |
|
370 self.contents.setTextCursor(tc) |
|
371 self.contents.ensureCursorVisible() |
|
372 |
298 @pyqtSlot() |
373 @pyqtSlot() |
299 def on_saveButton_clicked(self): |
374 def on_saveButton_clicked(self): |
300 """ |
375 """ |
301 Private slot to handle the Save button press. |
376 Private slot to handle the Save button press. |
302 |
377 |