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