28 class SvnDiffDialog(QWidget, Ui_SvnDiffDialog): |
28 class SvnDiffDialog(QWidget, Ui_SvnDiffDialog): |
29 """ |
29 """ |
30 Class implementing a dialog to show the output of the svn diff command |
30 Class implementing a dialog to show the output of the svn diff command |
31 process. |
31 process. |
32 """ |
32 """ |
|
33 |
33 def __init__(self, vcs, parent=None): |
34 def __init__(self, vcs, parent=None): |
34 """ |
35 """ |
35 Constructor |
36 Constructor |
36 |
37 |
37 @param vcs reference to the vcs object |
38 @param vcs reference to the vcs object |
38 @param parent parent widget (QWidget) |
39 @param parent parent widget (QWidget) |
39 """ |
40 """ |
40 super().__init__(parent) |
41 super().__init__(parent) |
41 self.setupUi(self) |
42 self.setupUi(self) |
42 |
43 |
43 self.refreshButton = self.buttonBox.addButton( |
44 self.refreshButton = self.buttonBox.addButton( |
44 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) |
45 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole |
45 self.refreshButton.setToolTip( |
46 ) |
46 self.tr("Press to refresh the display")) |
47 self.refreshButton.setToolTip(self.tr("Press to refresh the display")) |
47 self.refreshButton.setEnabled(False) |
48 self.refreshButton.setEnabled(False) |
48 self.buttonBox.button( |
49 self.buttonBox.button(QDialogButtonBox.StandardButton.Save).setEnabled(False) |
49 QDialogButtonBox.StandardButton.Save).setEnabled(False) |
50 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
50 self.buttonBox.button( |
51 |
51 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
52 |
|
53 self.searchWidget.attachTextEdit(self.contents) |
52 self.searchWidget.attachTextEdit(self.contents) |
54 |
53 |
55 self.process = QProcess() |
54 self.process = QProcess() |
56 self.vcs = vcs |
55 self.vcs = vcs |
57 |
56 |
58 font = Preferences.getEditorOtherFonts("MonospacedFont") |
57 font = Preferences.getEditorOtherFonts("MonospacedFont") |
59 self.contents.document().setDefaultFont(font) |
58 self.contents.document().setDefaultFont(font) |
60 |
59 |
61 self.highlighter = SvnDiffHighlighter(self.contents.document()) |
60 self.highlighter = SvnDiffHighlighter(self.contents.document()) |
62 |
61 |
63 self.process.finished.connect(self.__procFinished) |
62 self.process.finished.connect(self.__procFinished) |
64 self.process.readyReadStandardOutput.connect(self.__readStdout) |
63 self.process.readyReadStandardOutput.connect(self.__readStdout) |
65 self.process.readyReadStandardError.connect(self.__readStderr) |
64 self.process.readyReadStandardError.connect(self.__readStderr) |
66 |
65 |
67 def closeEvent(self, e): |
66 def closeEvent(self, e): |
68 """ |
67 """ |
69 Protected slot implementing a close event handler. |
68 Protected slot implementing a close event handler. |
70 |
69 |
71 @param e close event (QCloseEvent) |
70 @param e close event (QCloseEvent) |
72 """ |
71 """ |
73 if ( |
72 if ( |
74 self.process is not None and |
73 self.process is not None |
75 self.process.state() != QProcess.ProcessState.NotRunning |
74 and self.process.state() != QProcess.ProcessState.NotRunning |
76 ): |
75 ): |
77 self.process.terminate() |
76 self.process.terminate() |
78 QTimer.singleShot(2000, self.process.kill) |
77 QTimer.singleShot(2000, self.process.kill) |
79 self.process.waitForFinished(3000) |
78 self.process.waitForFinished(3000) |
80 |
79 |
81 e.accept() |
80 e.accept() |
82 |
81 |
83 def __getVersionArg(self, version): |
82 def __getVersionArg(self, version): |
84 """ |
83 """ |
85 Private method to get a svn revision argument for the given revision. |
84 Private method to get a svn revision argument for the given revision. |
86 |
85 |
87 @param version revision (integer or string) |
86 @param version revision (integer or string) |
88 @return version argument (string) |
87 @return version argument (string) |
89 """ |
88 """ |
90 if version == "WORKING": |
89 if version == "WORKING": |
91 return None |
90 return None |
92 else: |
91 else: |
93 return str(version) |
92 return str(version) |
94 |
93 |
95 def start(self, fn, versions=None, urls=None, summary=False, |
94 def start(self, fn, versions=None, urls=None, summary=False, refreshable=False): |
96 refreshable=False): |
|
97 """ |
95 """ |
98 Public slot to start the svn diff command. |
96 Public slot to start the svn diff command. |
99 |
97 |
100 @param fn filename to be diffed (string) |
98 @param fn filename to be diffed (string) |
101 @param versions list of versions to be diffed (list of up to 2 strings |
99 @param versions list of versions to be diffed (list of up to 2 strings |
102 or None) |
100 or None) |
103 @param urls list of repository URLs (list of 2 strings) |
101 @param urls list of repository URLs (list of 2 strings) |
104 @param summary flag indicating a summarizing diff |
102 @param summary flag indicating a summarizing diff |
105 (only valid for URL diffs) (boolean) |
103 (only valid for URL diffs) (boolean) |
106 @param refreshable flag indicating a refreshable diff (boolean) |
104 @param refreshable flag indicating a refreshable diff (boolean) |
107 """ |
105 """ |
108 self.refreshButton.setVisible(refreshable) |
106 self.refreshButton.setVisible(refreshable) |
109 |
107 |
110 self.errorGroup.hide() |
108 self.errorGroup.hide() |
111 self.inputGroup.show() |
109 self.inputGroup.show() |
112 self.inputGroup.setEnabled(True) |
110 self.inputGroup.setEnabled(True) |
113 self.intercept = False |
111 self.intercept = False |
114 self.filename = fn |
112 self.filename = fn |
115 |
113 |
116 self.process.kill() |
114 self.process.kill() |
117 |
115 |
118 self.contents.clear() |
116 self.contents.clear() |
119 self.highlighter.regenerateRules() |
117 self.highlighter.regenerateRules() |
120 self.paras = 0 |
118 self.paras = 0 |
121 |
119 |
122 self.filesCombo.clear() |
120 self.filesCombo.clear() |
123 |
121 |
124 self.__oldFile = "" |
122 self.__oldFile = "" |
125 self.__oldFileLine = -1 |
123 self.__oldFileLine = -1 |
126 self.__fileSeparators = [] |
124 self.__fileSeparators = [] |
127 |
125 |
128 args = [] |
126 args = [] |
129 args.append('diff') |
127 args.append("diff") |
130 self.vcs.addArguments(args, self.vcs.options['global']) |
128 self.vcs.addArguments(args, self.vcs.options["global"]) |
131 self.vcs.addArguments(args, self.vcs.options['diff']) |
129 self.vcs.addArguments(args, self.vcs.options["diff"]) |
132 if '--diff-cmd' in self.vcs.options['diff']: |
130 if "--diff-cmd" in self.vcs.options["diff"]: |
133 self.buttonBox.button(QDialogButtonBox.StandardButton.Save).hide() |
131 self.buttonBox.button(QDialogButtonBox.StandardButton.Save).hide() |
134 |
132 |
135 if versions is not None: |
133 if versions is not None: |
136 self.raise_() |
134 self.raise_() |
137 self.activateWindow() |
135 self.activateWindow() |
138 |
136 |
139 rev1 = self.__getVersionArg(versions[0]) |
137 rev1 = self.__getVersionArg(versions[0]) |
140 rev2 = None |
138 rev2 = None |
141 if len(versions) == 2: |
139 if len(versions) == 2: |
142 rev2 = self.__getVersionArg(versions[1]) |
140 rev2 = self.__getVersionArg(versions[1]) |
143 |
141 |
144 if rev1 is not None or rev2 is not None: |
142 if rev1 is not None or rev2 is not None: |
145 args.append('-r') |
143 args.append("-r") |
146 if rev1 is not None and rev2 is not None: |
144 if rev1 is not None and rev2 is not None: |
147 args.append('{0}:{1}'.format(rev1, rev2)) |
145 args.append("{0}:{1}".format(rev1, rev2)) |
148 elif rev2 is None: |
146 elif rev2 is None: |
149 args.append(rev1) |
147 args.append(rev1) |
150 elif rev1 is None: |
148 elif rev1 is None: |
151 args.append(rev2) |
149 args.append(rev2) |
152 |
150 |
153 self.summaryPath = None |
151 self.summaryPath = None |
154 if urls is not None: |
152 if urls is not None: |
155 if summary: |
153 if summary: |
156 args.append("--summarize") |
154 args.append("--summarize") |
157 self.summaryPath = urls[0] |
155 self.summaryPath = urls[0] |
176 dname, fnames = self.vcs.splitPathList(fn) |
174 dname, fnames = self.vcs.splitPathList(fn) |
177 self.vcs.addArguments(args, fnames) |
175 self.vcs.addArguments(args, fnames) |
178 else: |
176 else: |
179 dname, fname = self.vcs.splitPath(fn) |
177 dname, fname = self.vcs.splitPath(fn) |
180 args.append(fname) |
178 args.append(fname) |
181 |
179 |
182 self.process.setWorkingDirectory(dname) |
180 self.process.setWorkingDirectory(dname) |
183 |
181 |
184 self.process.start('svn', args) |
182 self.process.start("svn", args) |
185 procStarted = self.process.waitForStarted(5000) |
183 procStarted = self.process.waitForStarted(5000) |
186 if not procStarted: |
184 if not procStarted: |
187 self.inputGroup.setEnabled(False) |
185 self.inputGroup.setEnabled(False) |
188 self.inputGroup.hide() |
186 self.inputGroup.hide() |
189 EricMessageBox.critical( |
187 EricMessageBox.critical( |
190 self, |
188 self, |
191 self.tr('Process Generation Error'), |
189 self.tr("Process Generation Error"), |
192 self.tr( |
190 self.tr( |
193 'The process {0} could not be started. ' |
191 "The process {0} could not be started. " |
194 'Ensure, that it is in the search path.' |
192 "Ensure, that it is in the search path." |
195 ).format('svn')) |
193 ).format("svn"), |
196 |
194 ) |
|
195 |
197 def __procFinished(self, exitCode, exitStatus): |
196 def __procFinished(self, exitCode, exitStatus): |
198 """ |
197 """ |
199 Private slot connected to the finished signal. |
198 Private slot connected to the finished signal. |
200 |
199 |
201 @param exitCode exit code of the process (integer) |
200 @param exitCode exit code of the process (integer) |
202 @param exitStatus exit status of the process (QProcess.ExitStatus) |
201 @param exitStatus exit status of the process (QProcess.ExitStatus) |
203 """ |
202 """ |
204 self.inputGroup.setEnabled(False) |
203 self.inputGroup.setEnabled(False) |
205 self.inputGroup.hide() |
204 self.inputGroup.hide() |
206 self.refreshButton.setEnabled(True) |
205 self.refreshButton.setEnabled(True) |
207 |
206 |
208 if self.paras == 0: |
207 if self.paras == 0: |
209 self.contents.setPlainText(self.tr('There is no difference.')) |
208 self.contents.setPlainText(self.tr("There is no difference.")) |
210 |
209 |
211 self.buttonBox.button( |
210 self.buttonBox.button(QDialogButtonBox.StandardButton.Save).setEnabled( |
212 QDialogButtonBox.StandardButton.Save).setEnabled(self.paras > 0) |
211 self.paras > 0 |
213 self.buttonBox.button( |
212 ) |
214 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
213 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) |
215 self.buttonBox.button( |
214 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
216 QDialogButtonBox.StandardButton.Close).setDefault(True) |
215 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus( |
217 self.buttonBox.button( |
216 Qt.FocusReason.OtherFocusReason |
218 QDialogButtonBox.StandardButton.Close).setFocus( |
217 ) |
219 Qt.FocusReason.OtherFocusReason) |
218 |
220 |
|
221 tc = self.contents.textCursor() |
219 tc = self.contents.textCursor() |
222 tc.movePosition(QTextCursor.MoveOperation.Start) |
220 tc.movePosition(QTextCursor.MoveOperation.Start) |
223 self.contents.setTextCursor(tc) |
221 self.contents.setTextCursor(tc) |
224 self.contents.ensureCursorVisible() |
222 self.contents.ensureCursorVisible() |
225 |
223 |
226 self.filesCombo.addItem(self.tr("<Start>"), 0) |
224 self.filesCombo.addItem(self.tr("<Start>"), 0) |
227 self.filesCombo.addItem(self.tr("<End>"), -1) |
225 self.filesCombo.addItem(self.tr("<End>"), -1) |
228 for oldFile, newFile, pos in sorted(self.__fileSeparators): |
226 for oldFile, newFile, pos in sorted(self.__fileSeparators): |
229 if oldFile != newFile: |
227 if oldFile != newFile: |
230 self.filesCombo.addItem( |
228 self.filesCombo.addItem("{0}\n{1}".format(oldFile, newFile), pos) |
231 "{0}\n{1}".format(oldFile, newFile), pos) |
|
232 else: |
229 else: |
233 self.filesCombo.addItem(oldFile, pos) |
230 self.filesCombo.addItem(oldFile, pos) |
234 |
231 |
235 def __appendText(self, txt): |
232 def __appendText(self, txt): |
236 """ |
233 """ |
237 Private method to append text to the end of the contents pane. |
234 Private method to append text to the end of the contents pane. |
238 |
235 |
239 @param txt text to insert (string) |
236 @param txt text to insert (string) |
240 """ |
237 """ |
241 tc = self.contents.textCursor() |
238 tc = self.contents.textCursor() |
242 tc.movePosition(QTextCursor.MoveOperation.End) |
239 tc.movePosition(QTextCursor.MoveOperation.End) |
243 self.contents.setTextCursor(tc) |
240 self.contents.setTextCursor(tc) |
244 self.contents.insertPlainText(txt) |
241 self.contents.insertPlainText(txt) |
245 |
242 |
246 def __extractFileName(self, line): |
243 def __extractFileName(self, line): |
247 """ |
244 """ |
248 Private method to extract the file name out of a file separator line. |
245 Private method to extract the file name out of a file separator line. |
249 |
246 |
250 @param line line to be processed (string) |
247 @param line line to be processed (string) |
251 @return extracted file name (string) |
248 @return extracted file name (string) |
252 """ |
249 """ |
253 f = line.split(None, 1)[1] |
250 f = line.split(None, 1)[1] |
254 f = f.rsplit(None, 2)[0] |
251 f = f.rsplit(None, 2)[0] |
255 return f |
252 return f |
256 |
253 |
257 def __processFileLine(self, line): |
254 def __processFileLine(self, line): |
258 """ |
255 """ |
259 Private slot to process a line giving the old/new file. |
256 Private slot to process a line giving the old/new file. |
260 |
257 |
261 @param line line to be processed (string) |
258 @param line line to be processed (string) |
262 """ |
259 """ |
263 if line.startswith('---'): |
260 if line.startswith("---"): |
264 self.__oldFileLine = self.paras |
261 self.__oldFileLine = self.paras |
265 self.__oldFile = self.__extractFileName(line) |
262 self.__oldFile = self.__extractFileName(line) |
266 else: |
263 else: |
267 self.__fileSeparators.append( |
264 self.__fileSeparators.append( |
268 (self.__oldFile, self.__extractFileName(line), |
265 (self.__oldFile, self.__extractFileName(line), self.__oldFileLine) |
269 self.__oldFileLine)) |
266 ) |
270 |
267 |
271 def __readStdout(self): |
268 def __readStdout(self): |
272 """ |
269 """ |
273 Private slot to handle the readyReadStandardOutput signal. |
270 Private slot to handle the readyReadStandardOutput signal. |
274 |
271 |
275 It reads the output of the process, formats it and inserts it into |
272 It reads the output of the process, formats it and inserts it into |
276 the contents pane. |
273 the contents pane. |
277 """ |
274 """ |
278 self.process.setReadChannel(QProcess.ProcessChannel.StandardOutput) |
275 self.process.setReadChannel(QProcess.ProcessChannel.StandardOutput) |
279 |
276 |
280 while self.process.canReadLine(): |
277 while self.process.canReadLine(): |
281 line = str(self.process.readLine(), |
278 line = str( |
282 Preferences.getSystem("IOEncoding"), |
279 self.process.readLine(), Preferences.getSystem("IOEncoding"), "replace" |
283 'replace') |
280 ) |
284 if self.summaryPath: |
281 if self.summaryPath: |
285 line = line.replace(self.summaryPath + '/', '') |
282 line = line.replace(self.summaryPath + "/", "") |
286 line = " ".join(line.split()) |
283 line = " ".join(line.split()) |
287 if line.startswith("--- ") or line.startswith("+++ "): |
284 if line.startswith("--- ") or line.startswith("+++ "): |
288 self.__processFileLine(line) |
285 self.__processFileLine(line) |
289 |
286 |
290 self.__appendText(line) |
287 self.__appendText(line) |
291 self.paras += 1 |
288 self.paras += 1 |
292 |
289 |
293 def __readStderr(self): |
290 def __readStderr(self): |
294 """ |
291 """ |
295 Private slot to handle the readyReadStandardError signal. |
292 Private slot to handle the readyReadStandardError signal. |
296 |
293 |
297 It reads the error output of the process and inserts it into the |
294 It reads the error output of the process and inserts it into the |
298 error pane. |
295 error pane. |
299 """ |
296 """ |
300 if self.process is not None: |
297 if self.process is not None: |
301 self.errorGroup.show() |
298 self.errorGroup.show() |
302 s = str(self.process.readAllStandardError(), |
299 s = str( |
303 Preferences.getSystem("IOEncoding"), |
300 self.process.readAllStandardError(), |
304 'replace') |
301 Preferences.getSystem("IOEncoding"), |
|
302 "replace", |
|
303 ) |
305 self.errors.insertPlainText(s) |
304 self.errors.insertPlainText(s) |
306 self.errors.ensureCursorVisible() |
305 self.errors.ensureCursorVisible() |
307 |
306 |
308 def on_buttonBox_clicked(self, button): |
307 def on_buttonBox_clicked(self, button): |
309 """ |
308 """ |
310 Private slot called by a button of the button box clicked. |
309 Private slot called by a button of the button box clicked. |
311 |
310 |
312 @param button button that was clicked (QAbstractButton) |
311 @param button button that was clicked (QAbstractButton) |
313 """ |
312 """ |
314 if button == self.buttonBox.button( |
313 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Save): |
315 QDialogButtonBox.StandardButton.Save |
|
316 ): |
|
317 self.on_saveButton_clicked() |
314 self.on_saveButton_clicked() |
318 elif button == self.refreshButton: |
315 elif button == self.refreshButton: |
319 self.on_refreshButton_clicked() |
316 self.on_refreshButton_clicked() |
320 |
317 |
321 @pyqtSlot(int) |
318 @pyqtSlot(int) |
322 def on_filesCombo_activated(self, index): |
319 def on_filesCombo_activated(self, index): |
323 """ |
320 """ |
324 Private slot to handle the selection of a file. |
321 Private slot to handle the selection of a file. |
325 |
322 |
326 @param index activated row (integer) |
323 @param index activated row (integer) |
327 """ |
324 """ |
328 para = self.filesCombo.itemData(index) |
325 para = self.filesCombo.itemData(index) |
329 |
326 |
330 if para == 0: |
327 if para == 0: |
331 tc = self.contents.textCursor() |
328 tc = self.contents.textCursor() |
332 tc.movePosition(QTextCursor.MoveOperation.Start) |
329 tc.movePosition(QTextCursor.MoveOperation.Start) |
333 self.contents.setTextCursor(tc) |
330 self.contents.setTextCursor(tc) |
334 self.contents.ensureCursorVisible() |
331 self.contents.ensureCursorVisible() |
341 # step 1: move cursor to end |
338 # step 1: move cursor to end |
342 tc = self.contents.textCursor() |
339 tc = self.contents.textCursor() |
343 tc.movePosition(QTextCursor.MoveOperation.End) |
340 tc.movePosition(QTextCursor.MoveOperation.End) |
344 self.contents.setTextCursor(tc) |
341 self.contents.setTextCursor(tc) |
345 self.contents.ensureCursorVisible() |
342 self.contents.ensureCursorVisible() |
346 |
343 |
347 # step 2: move cursor to desired line |
344 # step 2: move cursor to desired line |
348 tc = self.contents.textCursor() |
345 tc = self.contents.textCursor() |
349 delta = tc.blockNumber() - para |
346 delta = tc.blockNumber() - para |
350 tc.movePosition( |
347 tc.movePosition( |
351 QTextCursor.MoveOperation.PreviousBlock, |
348 QTextCursor.MoveOperation.PreviousBlock, |
352 QTextCursor.MoveMode.MoveAnchor, |
349 QTextCursor.MoveMode.MoveAnchor, |
353 delta) |
350 delta, |
|
351 ) |
354 self.contents.setTextCursor(tc) |
352 self.contents.setTextCursor(tc) |
355 self.contents.ensureCursorVisible() |
353 self.contents.ensureCursorVisible() |
356 |
354 |
357 @pyqtSlot() |
355 @pyqtSlot() |
358 def on_saveButton_clicked(self): |
356 def on_saveButton_clicked(self): |
359 """ |
357 """ |
360 Private slot to handle the Save button press. |
358 Private slot to handle the Save button press. |
361 |
359 |
362 It saves the diff shown in the dialog to a file in the local |
360 It saves the diff shown in the dialog to a file in the local |
363 filesystem. |
361 filesystem. |
364 """ |
362 """ |
365 if isinstance(self.filename, list): |
363 if isinstance(self.filename, list): |
366 if len(self.filename) > 1: |
364 if len(self.filename) > 1: |
367 fname = self.vcs.splitPathList(self.filename)[0] |
365 fname = self.vcs.splitPathList(self.filename)[0] |
368 else: |
366 else: |
369 dname, fname = self.vcs.splitPath(self.filename[0]) |
367 dname, fname = self.vcs.splitPath(self.filename[0]) |
370 if fname != '.': |
368 if fname != ".": |
371 fname = "{0}.diff".format(self.filename[0]) |
369 fname = "{0}.diff".format(self.filename[0]) |
372 else: |
370 else: |
373 fname = dname |
371 fname = dname |
374 else: |
372 else: |
375 fname = self.vcs.splitPath(self.filename)[0] |
373 fname = self.vcs.splitPath(self.filename)[0] |
376 |
374 |
377 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
375 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
378 self, |
376 self, |
379 self.tr("Save Diff"), |
377 self.tr("Save Diff"), |
380 fname, |
378 fname, |
381 self.tr("Patch Files (*.diff)"), |
379 self.tr("Patch Files (*.diff)"), |
382 None, |
380 None, |
383 EricFileDialog.DontConfirmOverwrite) |
381 EricFileDialog.DontConfirmOverwrite, |
384 |
382 ) |
|
383 |
385 if not fname: |
384 if not fname: |
386 return # user aborted |
385 return # user aborted |
387 |
386 |
388 fpath = pathlib.Path(fname) |
387 fpath = pathlib.Path(fname) |
389 if not fpath.suffix: |
388 if not fpath.suffix: |
390 ex = selectedFilter.split("(*")[1].split(")")[0] |
389 ex = selectedFilter.split("(*")[1].split(")")[0] |
391 if ex: |
390 if ex: |
392 fpath = fpath.with_suffix(ex) |
391 fpath = fpath.with_suffix(ex) |
393 if fpath.exists(): |
392 if fpath.exists(): |
394 res = EricMessageBox.yesNo( |
393 res = EricMessageBox.yesNo( |
395 self, |
394 self, |
396 self.tr("Save Diff"), |
395 self.tr("Save Diff"), |
397 self.tr("<p>The patch file <b>{0}</b> already exists." |
396 self.tr( |
398 " Overwrite it?</p>").format(fpath), |
397 "<p>The patch file <b>{0}</b> already exists." " Overwrite it?</p>" |
399 icon=EricMessageBox.Warning) |
398 ).format(fpath), |
|
399 icon=EricMessageBox.Warning, |
|
400 ) |
400 if not res: |
401 if not res: |
401 return |
402 return |
402 |
403 |
403 eol = ericApp().getObject("Project").getEolString() |
404 eol = ericApp().getObject("Project").getEolString() |
404 try: |
405 try: |
405 with fpath.open("w", encoding="utf-8", newline="") as f: |
406 with fpath.open("w", encoding="utf-8", newline="") as f: |
406 f.write(eol.join(self.contents.toPlainText().splitlines())) |
407 f.write(eol.join(self.contents.toPlainText().splitlines())) |
407 except OSError as why: |
408 except OSError as why: |
408 EricMessageBox.critical( |
409 EricMessageBox.critical( |
409 self, self.tr('Save Diff'), |
410 self, |
|
411 self.tr("Save Diff"), |
410 self.tr( |
412 self.tr( |
411 '<p>The patch file <b>{0}</b> could not be saved.' |
413 "<p>The patch file <b>{0}</b> could not be saved." |
412 '<br>Reason: {1}</p>') |
414 "<br>Reason: {1}</p>" |
413 .format(fpath, str(why))) |
415 ).format(fpath, str(why)), |
414 |
416 ) |
|
417 |
415 @pyqtSlot() |
418 @pyqtSlot() |
416 def on_refreshButton_clicked(self): |
419 def on_refreshButton_clicked(self): |
417 """ |
420 """ |
418 Private slot to refresh the display. |
421 Private slot to refresh the display. |
419 """ |
422 """ |
420 self.buttonBox.button( |
423 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
421 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
424 |
422 |
425 self.buttonBox.button(QDialogButtonBox.StandardButton.Save).setEnabled(False) |
423 self.buttonBox.button( |
|
424 QDialogButtonBox.StandardButton.Save).setEnabled(False) |
|
425 self.refreshButton.setEnabled(False) |
426 self.refreshButton.setEnabled(False) |
426 |
427 |
427 self.start(self.filename, refreshable=True) |
428 self.start(self.filename, refreshable=True) |
428 |
429 |
429 def on_passwordCheckBox_toggled(self, isOn): |
430 def on_passwordCheckBox_toggled(self, isOn): |
430 """ |
431 """ |
431 Private slot to handle the password checkbox toggled. |
432 Private slot to handle the password checkbox toggled. |
432 |
433 |
433 @param isOn flag indicating the status of the check box (boolean) |
434 @param isOn flag indicating the status of the check box (boolean) |
434 """ |
435 """ |
435 if isOn: |
436 if isOn: |
436 self.input.setEchoMode(QLineEdit.EchoMode.Password) |
437 self.input.setEchoMode(QLineEdit.EchoMode.Password) |
437 else: |
438 else: |
438 self.input.setEchoMode(QLineEdit.EchoMode.Normal) |
439 self.input.setEchoMode(QLineEdit.EchoMode.Normal) |
439 |
440 |
440 @pyqtSlot() |
441 @pyqtSlot() |
441 def on_sendButton_clicked(self): |
442 def on_sendButton_clicked(self): |
442 """ |
443 """ |
443 Private slot to send the input to the subversion process. |
444 Private slot to send the input to the subversion process. |
444 """ |
445 """ |
445 inputTxt = self.input.text() |
446 inputTxt = self.input.text() |
446 inputTxt += os.linesep |
447 inputTxt += os.linesep |
447 |
448 |
448 if self.passwordCheckBox.isChecked(): |
449 if self.passwordCheckBox.isChecked(): |
449 self.errors.insertPlainText(os.linesep) |
450 self.errors.insertPlainText(os.linesep) |
450 self.errors.ensureCursorVisible() |
451 self.errors.ensureCursorVisible() |
451 else: |
452 else: |
452 self.errors.insertPlainText(inputTxt) |
453 self.errors.insertPlainText(inputTxt) |
453 self.errors.ensureCursorVisible() |
454 self.errors.ensureCursorVisible() |
454 |
455 |
455 self.process.write(strToQByteArray(inputTxt)) |
456 self.process.write(strToQByteArray(inputTxt)) |
456 |
457 |
457 self.passwordCheckBox.setChecked(False) |
458 self.passwordCheckBox.setChecked(False) |
458 self.input.clear() |
459 self.input.clear() |
459 |
460 |
460 def on_input_returnPressed(self): |
461 def on_input_returnPressed(self): |
461 """ |
462 """ |
462 Private slot to handle the press of the return key in the input field. |
463 Private slot to handle the press of the return key in the input field. |
463 """ |
464 """ |
464 self.intercept = True |
465 self.intercept = True |
465 self.on_sendButton_clicked() |
466 self.on_sendButton_clicked() |
466 |
467 |
467 def keyPressEvent(self, evt): |
468 def keyPressEvent(self, evt): |
468 """ |
469 """ |
469 Protected slot to handle a key press event. |
470 Protected slot to handle a key press event. |
470 |
471 |
471 @param evt the key press event (QKeyEvent) |
472 @param evt the key press event (QKeyEvent) |
472 """ |
473 """ |
473 if self.intercept: |
474 if self.intercept: |
474 self.intercept = False |
475 self.intercept = False |
475 evt.accept() |
476 evt.accept() |