|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2017 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.E5Completers import E5FileCompleter, E5DirCompleter |
|
18 from E5Gui import E5FileDialog |
|
19 |
|
20 from .Ui_GitCopyDialog import Ui_GitCopyDialog |
|
21 |
|
22 import Utilities |
|
23 import UI.PixmapCache |
|
24 |
|
25 |
|
26 class GitCopyDialog(QDialog, Ui_GitCopyDialog): |
|
27 """ |
|
28 Class implementing a dialog to enter the data for a copy or rename |
|
29 operation. |
|
30 """ |
|
31 def __init__(self, source, parent=None, move=False): |
|
32 """ |
|
33 Constructor |
|
34 |
|
35 @param source name of the source file/directory (string) |
|
36 @param parent parent widget (QWidget) |
|
37 @param move flag indicating a move operation (boolean) |
|
38 """ |
|
39 super(GitCopyDialog, self).__init__(parent) |
|
40 self.setupUi(self) |
|
41 |
|
42 self.dirButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
43 |
|
44 self.source = source |
|
45 if os.path.isdir(self.source): |
|
46 self.targetCompleter = E5DirCompleter(self.targetEdit) |
|
47 else: |
|
48 self.targetCompleter = E5FileCompleter(self.targetEdit) |
|
49 |
|
50 if move: |
|
51 self.setWindowTitle(self.tr('Git Move')) |
|
52 else: |
|
53 self.forceCheckBox.setEnabled(False) |
|
54 |
|
55 self.sourceEdit.setText(source) |
|
56 |
|
57 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
58 |
|
59 msh = self.minimumSizeHint() |
|
60 self.resize(max(self.width(), msh.width()), msh.height()) |
|
61 |
|
62 def getData(self): |
|
63 """ |
|
64 Public method to retrieve the copy data. |
|
65 |
|
66 @return the target name (string) and a flag indicating |
|
67 the operation should be enforced (boolean) |
|
68 """ |
|
69 target = self.targetEdit.text() |
|
70 if not os.path.isabs(target): |
|
71 sourceDir = os.path.dirname(self.sourceEdit.text()) |
|
72 target = os.path.join(sourceDir, target) |
|
73 return Utilities.toNativeSeparators(target), \ |
|
74 self.forceCheckBox.isChecked() |
|
75 |
|
76 @pyqtSlot() |
|
77 def on_dirButton_clicked(self): |
|
78 """ |
|
79 Private slot to handle the button press for selecting the target via a |
|
80 selection dialog. |
|
81 """ |
|
82 if os.path.isdir(self.source): |
|
83 target = E5FileDialog.getExistingDirectory( |
|
84 self, |
|
85 self.tr("Select target"), |
|
86 self.targetEdit.text(), |
|
87 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
88 else: |
|
89 target = E5FileDialog.getSaveFileName( |
|
90 self, |
|
91 self.tr("Select target"), |
|
92 self.targetEdit.text(), |
|
93 "", |
|
94 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) |
|
95 |
|
96 if target: |
|
97 self.targetEdit.setText(Utilities.toNativeSeparators(target)) |
|
98 |
|
99 @pyqtSlot(str) |
|
100 def on_targetEdit_textChanged(self, txt): |
|
101 """ |
|
102 Private slot to handle changes of the target. |
|
103 |
|
104 @param txt contents of the target edit (string) |
|
105 """ |
|
106 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
107 os.path.isabs(txt) or os.path.dirname(txt) == "") |