src/eric7/Plugins/VcsPlugins/vcsGit/GitCopyDialog.py

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

eric ide

mercurial