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