27 from eric7.EricWidgets.EricApplication import ericApp |
27 from eric7.EricWidgets.EricApplication import ericApp |
28 from eric7.EricWidgets.EricFileSaveConfirmDialog import confirmOverwrite |
28 from eric7.EricWidgets.EricFileSaveConfirmDialog import confirmOverwrite |
29 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
29 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
30 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
30 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
31 |
31 |
32 from .MicroPythonFileManager import MicroPythonFileManager |
|
33 from .MicroPythonFileSystemUtilities import ( |
32 from .MicroPythonFileSystemUtilities import ( |
34 decoratedName, |
33 decoratedName, |
35 listdirStat, |
34 listdirStat, |
36 mode2string, |
35 mode2string, |
37 mtime2string, |
36 mtime2string, |
42 class MicroPythonFileManagerWidget(QWidget, Ui_MicroPythonFileManagerWidget): |
41 class MicroPythonFileManagerWidget(QWidget, Ui_MicroPythonFileManagerWidget): |
43 """ |
42 """ |
44 Class implementing a file manager for MicroPython devices. |
43 Class implementing a file manager for MicroPython devices. |
45 """ |
44 """ |
46 |
45 |
47 def __init__(self, device, parent=None): |
46 def __init__(self, fileManager, parent=None): |
48 """ |
47 """ |
49 Constructor |
48 Constructor |
50 |
49 |
51 @param device MicroPython device object |
50 @param fileManager reference to the device file manager interface |
52 @type BaseDevice |
51 @type MicroPythonFileManager |
53 @param parent reference to the parent widget |
52 @param parent reference to the parent widget |
54 @type QWidget |
53 @type QWidget |
55 """ |
54 """ |
56 super().__init__(parent) |
55 super().__init__(parent) |
57 self.setupUi(self) |
56 self.setupUi(self) |
92 self.deviceFileTreeWidget.header().setSortIndicator( |
91 self.deviceFileTreeWidget.header().setSortIndicator( |
93 0, Qt.SortOrder.AscendingOrder |
92 0, Qt.SortOrder.AscendingOrder |
94 ) |
93 ) |
95 |
94 |
96 self.__progressInfoDialog = None |
95 self.__progressInfoDialog = None |
97 self.__fileManager = MicroPythonFileManager(device, self) |
96 self.__fileManager = fileManager |
98 |
97 |
99 self.__fileManager.longListFiles.connect(self.__handleLongListFiles) |
98 self.__fileManager.longListFiles.connect(self.__handleLongListFiles) |
100 self.__fileManager.currentDir.connect(self.__handleCurrentDir) |
99 self.__fileManager.currentDir.connect(self.__handleCurrentDir) |
101 self.__fileManager.currentDirChanged.connect(self.__handleCurrentDir) |
100 self.__fileManager.currentDirChanged.connect(self.__handleCurrentDir) |
102 self.__fileManager.putFileDone.connect(self.__newDeviceList) |
101 self.__fileManager.putFileDone.connect(self.__newDeviceList) |
739 |
738 |
740 if saveAs: |
739 if saveAs: |
741 filename, ok = QInputDialog.getText( |
740 filename, ok = QInputDialog.getText( |
742 self, |
741 self, |
743 self.tr("Save File As"), |
742 self.tr("Save File As"), |
744 self.tr("Enter a new name for the file"), |
743 self.tr("Enter a new name for the file:"), |
745 QLineEdit.EchoMode.Normal, |
744 QLineEdit.EchoMode.Normal, |
746 filename, |
745 filename, |
747 ) |
746 ) |
748 if not ok or not filename: |
747 if not ok or not filename: |
749 return |
748 return |
768 elif action == "rename": |
767 elif action == "rename": |
769 filename = os.path.basename(resultFilename) |
768 filename = os.path.basename(resultFilename) |
770 |
769 |
771 text = aw.text() |
770 text = aw.text() |
772 if self.__repl.deviceSupportsLocalFileAccess(): |
771 if self.__repl.deviceSupportsLocalFileAccess(): |
773 with open(os.path.join(self.deviceCwd.text(), filename), "w") as f: |
772 filename = os.path.join(self.deviceCwd.text(), filename) |
|
773 os.makedirs(os.path.dirname(filename), exist_ok=True) |
|
774 with open(filename, "w") as f: |
774 f.write(text) |
775 f.write(text) |
775 else: |
776 self.__newDeviceList() |
776 deviceCwd = self.deviceCwd.text() |
777 aw.setFileName(filename) |
777 if deviceCwd: |
778 else: |
778 filename = ( |
779 if not filename.startswith("/"): |
779 deviceCwd + "/" + filename if deviceCwd != "/" else "/" + filename |
780 deviceCwd = self.deviceCwd.text() |
780 ) |
781 if deviceCwd: |
|
782 filename = ( |
|
783 deviceCwd + "/" + filename |
|
784 if deviceCwd != "/" |
|
785 else "/" + filename |
|
786 ) |
|
787 dirname = filename.rsplit("/", 1)[0] |
|
788 self.__fileManager.makedirs(dirname) |
781 self.__fileManager.putData(filename, text.encode("utf-8")) |
789 self.__fileManager.putData(filename, text.encode("utf-8")) |
|
790 aw.setFileName("device:" + filename) |
782 |
791 |
783 aw.setModified(False) |
792 aw.setModified(False) |
784 aw.resetOnlineChangeTraceInfo() |
793 aw.resetOnlineChangeTraceInfo() |
785 |
794 |
786 @pyqtSlot() |
795 @pyqtSlot() |