9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo, Qt |
12 from PyQt4.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo, Qt |
13 from PyQt4.QtGui import QWidget, QDialogButtonBox, QBrush, QColor, \ |
13 from PyQt4.QtGui import QWidget, QDialogButtonBox, QBrush, QColor, \ |
14 QTextCursor, QLineEdit |
14 QTextCursor, QLineEdit, QApplication, QCursor |
15 |
15 |
16 from E5Gui import E5MessageBox, E5FileDialog |
16 from E5Gui import E5MessageBox, E5FileDialog |
17 from E5Gui.E5Application import e5App |
17 from E5Gui.E5Application import e5App |
18 |
18 |
19 from .Ui_HgDiffDialog import Ui_HgDiffDialog |
19 from .Ui_HgDiffDialog import Ui_HgDiffDialog |
146 self.vcs.addArguments(args, fn) |
148 self.vcs.addArguments(args, fn) |
147 else: |
149 else: |
148 dname, fname = self.vcs.splitPath(fn) |
150 dname, fname = self.vcs.splitPath(fn) |
149 args.append(fn) |
151 args.append(fn) |
150 |
152 |
|
153 self.__oldFile = "" |
|
154 self.__oldFileLine = -1 |
|
155 self.__fileSeparators = [] |
|
156 |
|
157 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
151 if self.__hgClient: |
158 if self.__hgClient: |
152 self.inputGroup.setEnabled(False) |
159 self.inputGroup.setEnabled(False) |
153 self.inputGroup.hide() |
160 self.inputGroup.hide() |
154 |
161 |
155 out, err = self.__hgClient.runcommand(args) |
162 out, err = self.__hgClient.runcommand(args) |
176 self.process.setWorkingDirectory(repodir) |
183 self.process.setWorkingDirectory(repodir) |
177 |
184 |
178 self.process.start('hg', args) |
185 self.process.start('hg', args) |
179 procStarted = self.process.waitForStarted() |
186 procStarted = self.process.waitForStarted() |
180 if not procStarted: |
187 if not procStarted: |
|
188 QApplication.restoreOverrideCursor() |
181 self.inputGroup.setEnabled(False) |
189 self.inputGroup.setEnabled(False) |
182 E5MessageBox.critical(self, |
190 E5MessageBox.critical(self, |
183 self.trUtf8('Process Generation Error'), |
191 self.trUtf8('Process Generation Error'), |
184 self.trUtf8( |
192 self.trUtf8( |
185 'The process {0} could not be started. ' |
193 'The process {0} could not be started. ' |
213 |
222 |
214 tc = self.contents.textCursor() |
223 tc = self.contents.textCursor() |
215 tc.movePosition(QTextCursor.Start) |
224 tc.movePosition(QTextCursor.Start) |
216 self.contents.setTextCursor(tc) |
225 self.contents.setTextCursor(tc) |
217 self.contents.ensureCursorVisible() |
226 self.contents.ensureCursorVisible() |
|
227 |
|
228 self.filesCombo.addItem(self.trUtf8("<Start>"), 0) |
|
229 self.filesCombo.addItem(self.trUtf8("<End>"), -1) |
|
230 for oldFile, newFile, pos in sorted(self.__fileSeparators): |
|
231 if oldFile != newFile: |
|
232 self.filesCombo.addItem("{0}\n{1}".format(oldFile, newFile), pos) |
|
233 else: |
|
234 self.filesCombo.addItem(oldFile, pos) |
218 |
235 |
219 def __appendText(self, txt, format): |
236 def __appendText(self, txt, format): |
220 """ |
237 """ |
221 Private method to append text to the end of the contents pane. |
238 Private method to append text to the end of the contents pane. |
222 |
239 |
227 tc.movePosition(QTextCursor.End) |
244 tc.movePosition(QTextCursor.End) |
228 self.contents.setTextCursor(tc) |
245 self.contents.setTextCursor(tc) |
229 self.contents.setCurrentCharFormat(format) |
246 self.contents.setCurrentCharFormat(format) |
230 self.contents.insertPlainText(txt) |
247 self.contents.insertPlainText(txt) |
231 |
248 |
|
249 def __extractFileName(self, line): |
|
250 """ |
|
251 Private method to extract the file name out of a file separator line. |
|
252 |
|
253 @param line line to be processed (string) |
|
254 @return extracted file name (string) |
|
255 """ |
|
256 f = line.split(None, 1)[1] |
|
257 f = f.rsplit(None, 6)[0] |
|
258 f = f.split("/", 1)[1] |
|
259 return f |
|
260 |
|
261 def __processFileLine(self, line): |
|
262 """ |
|
263 Private slot to process a line giving the old/new file. |
|
264 |
|
265 @param line line to be processed (string) |
|
266 """ |
|
267 if line.startswith('---'): |
|
268 self.__oldFileLine = self.paras |
|
269 self.__oldFile = self.__extractFileName(line) |
|
270 else: |
|
271 self.__fileSeparators.append( |
|
272 (self.__oldFile, self.__extractFileName(line), self.__oldFileLine)) |
|
273 |
232 def __processOutputLine(self, line): |
274 def __processOutputLine(self, line): |
233 """ |
275 """ |
234 Private method to process the lines of output. |
276 Private method to process the lines of output. |
235 |
277 |
236 @param line output line to be processed (string) |
278 @param line output line to be processed (string) |
237 """ |
279 """ |
|
280 if line.startswith("---") or \ |
|
281 line.startswith("+++"): |
|
282 self.__processFileLine(line) |
|
283 |
238 if line.startswith('+'): |
284 if line.startswith('+'): |
239 format = self.cAddedFormat |
285 format = self.cAddedFormat |
240 elif line.startswith('-'): |
286 elif line.startswith('-'): |
241 format = self.cRemovedFormat |
287 format = self.cRemovedFormat |
242 elif line.startswith('@@'): |
288 elif line.startswith('@@'): |
290 |
336 |
291 @param button button that was clicked (QAbstractButton) |
337 @param button button that was clicked (QAbstractButton) |
292 """ |
338 """ |
293 if button == self.buttonBox.button(QDialogButtonBox.Save): |
339 if button == self.buttonBox.button(QDialogButtonBox.Save): |
294 self.on_saveButton_clicked() |
340 self.on_saveButton_clicked() |
|
341 |
|
342 @pyqtSlot(int) |
|
343 def on_filesCombo_activated(self, index): |
|
344 """ |
|
345 Private slot to handle the selection of a file. |
|
346 |
|
347 @param index activated row (integer) |
|
348 """ |
|
349 para = self.filesCombo.itemData(index) |
|
350 |
|
351 if para == 0: |
|
352 tc = self.contents.textCursor() |
|
353 tc.movePosition(QTextCursor.Start) |
|
354 self.contents.setTextCursor(tc) |
|
355 self.contents.ensureCursorVisible() |
|
356 elif para == -1: |
|
357 tc = self.contents.textCursor() |
|
358 tc.movePosition(QTextCursor.End) |
|
359 self.contents.setTextCursor(tc) |
|
360 self.contents.ensureCursorVisible() |
|
361 else: |
|
362 # step 1: move cursor to end |
|
363 tc = self.contents.textCursor() |
|
364 tc.movePosition(QTextCursor.End) |
|
365 self.contents.setTextCursor(tc) |
|
366 self.contents.ensureCursorVisible() |
|
367 |
|
368 # step 2: move cursor to desired line |
|
369 tc = self.contents.textCursor() |
|
370 delta = tc.blockNumber() - para |
|
371 tc.movePosition(QTextCursor.PreviousBlock, QTextCursor.MoveAnchor, delta) |
|
372 self.contents.setTextCursor(tc) |
|
373 self.contents.ensureCursorVisible() |
295 |
374 |
296 @pyqtSlot() |
375 @pyqtSlot() |
297 def on_saveButton_clicked(self): |
376 def on_saveButton_clicked(self): |
298 """ |
377 """ |
299 Private slot to handle the Save button press. |
378 Private slot to handle the Save button press. |