|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data for a copy or rename operation. |
|
8 """ |
|
9 |
|
10 import os.path |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from E5Gui.E5PathPicker import E5PathPickerModes |
|
16 |
|
17 from .Ui_HgCopyDialog import Ui_HgCopyDialog |
|
18 |
|
19 |
|
20 class HgCopyDialog(QDialog, Ui_HgCopyDialog): |
|
21 """ |
|
22 Class implementing a dialog to enter the data for a copy or rename |
|
23 operation. |
|
24 """ |
|
25 def __init__(self, source, parent=None, move=False): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param source name of the source file/directory (string) |
|
30 @param parent parent widget (QWidget) |
|
31 @param move flag indicating a move operation (boolean) |
|
32 """ |
|
33 super().__init__(parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.source = source |
|
37 if os.path.isdir(self.source): |
|
38 self.targetPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
39 else: |
|
40 self.targetPicker.setMode(E5PathPickerModes.SaveFileMode) |
|
41 |
|
42 if move: |
|
43 self.setWindowTitle(self.tr('Mercurial Move')) |
|
44 else: |
|
45 self.forceCheckBox.setEnabled(False) |
|
46 |
|
47 self.sourceEdit.setText(source) |
|
48 |
|
49 self.buttonBox.button( |
|
50 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
51 |
|
52 msh = self.minimumSizeHint() |
|
53 self.resize(max(self.width(), msh.width()), msh.height()) |
|
54 |
|
55 def getData(self): |
|
56 """ |
|
57 Public method to retrieve the copy data. |
|
58 |
|
59 @return the target name (string) and a flag indicating |
|
60 the operation should be enforced (boolean) |
|
61 """ |
|
62 target = self.targetPicker.text() |
|
63 if not os.path.isabs(target): |
|
64 sourceDir = os.path.dirname(self.sourceEdit.text()) |
|
65 target = os.path.join(sourceDir, target) |
|
66 return target, self.forceCheckBox.isChecked() |
|
67 |
|
68 @pyqtSlot(str) |
|
69 def on_targetPicker_textChanged(self, txt): |
|
70 """ |
|
71 Private slot to handle changes of the target. |
|
72 |
|
73 @param txt contents of the target edit (string) |
|
74 """ |
|
75 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
76 os.path.isabs(txt) or os.path.dirname(txt) == "") |