71 self.localHomeButton.setIcon(EricPixmapCache.getIcon("home")) |
71 self.localHomeButton.setIcon(EricPixmapCache.getIcon("home")) |
72 self.localReloadButton.setIcon(EricPixmapCache.getIcon("reload")) |
72 self.localReloadButton.setIcon(EricPixmapCache.getIcon("reload")) |
73 self.deviceUpButton.setIcon(EricPixmapCache.getIcon("1uparrow")) |
73 self.deviceUpButton.setIcon(EricPixmapCache.getIcon("1uparrow")) |
74 self.deviceHomeButton.setIcon(EricPixmapCache.getIcon("home")) |
74 self.deviceHomeButton.setIcon(EricPixmapCache.getIcon("home")) |
75 self.deviceReloadButton.setIcon(EricPixmapCache.getIcon("reload")) |
75 self.deviceReloadButton.setIcon(EricPixmapCache.getIcon("reload")) |
|
76 self.openButton.setIcon(EricPixmapCache.getIcon("open")) |
|
77 self.saveButton.setIcon(EricPixmapCache.getIcon("fileSave")) |
|
78 self.saveAsButton.setIcon(EricPixmapCache.getIcon("fileSaveAs")) |
76 |
79 |
77 self.deviceUpButton.setEnabled(not self.__repl.isMicrobit()) |
80 self.deviceUpButton.setEnabled(not self.__repl.isMicrobit()) |
78 self.deviceHomeButton.setEnabled(not self.__repl.isMicrobit()) |
81 self.deviceHomeButton.setEnabled(not self.__repl.isMicrobit()) |
79 |
82 |
80 self.putButton.setEnabled(False) |
83 self.putButton.setEnabled(False) |
81 self.putAsButton.setEnabled(False) |
84 self.putAsButton.setEnabled(False) |
82 self.getButton.setEnabled(False) |
85 self.getButton.setEnabled(False) |
83 self.getAsButton.setEnabled(False) |
86 self.getAsButton.setEnabled(False) |
|
87 |
|
88 self.openButton.setEnabled(False) |
|
89 self.saveButton.setEnabled(False) |
84 |
90 |
85 self.localFileTreeWidget.header().setSortIndicator( |
91 self.localFileTreeWidget.header().setSortIndicator( |
86 0, Qt.SortOrder.AscendingOrder |
92 0, Qt.SortOrder.AscendingOrder |
87 ) |
93 ) |
88 self.deviceFileTreeWidget.header().setSortIndicator( |
94 self.deviceFileTreeWidget.header().setSortIndicator( |
103 ) |
109 ) |
104 self.__fileManager.removeDirectoryDone.connect(self.__newDeviceList) |
110 self.__fileManager.removeDirectoryDone.connect(self.__newDeviceList) |
105 self.__fileManager.createDirectoryDone.connect(self.__newDeviceList) |
111 self.__fileManager.createDirectoryDone.connect(self.__newDeviceList) |
106 self.__fileManager.deleteFileDone.connect(self.__newDeviceList) |
112 self.__fileManager.deleteFileDone.connect(self.__newDeviceList) |
107 self.__fileManager.fsinfoDone.connect(self.__fsInfoResultReceived) |
113 self.__fileManager.fsinfoDone.connect(self.__fsInfoResultReceived) |
|
114 self.__fileManager.putDataDone.connect(self.__newDeviceList) |
108 |
115 |
109 self.__fileManager.error.connect(self.__handleError) |
116 self.__fileManager.error.connect(self.__handleError) |
110 |
117 |
111 self.localFileTreeWidget.customContextMenuRequested.connect( |
118 self.localFileTreeWidget.customContextMenuRequested.connect( |
112 self.__showLocalContextMenu |
119 self.__showLocalContextMenu |
170 Public method to start the widget. |
177 Public method to start the widget. |
171 """ |
178 """ |
172 dirname = "" |
179 dirname = "" |
173 vm = ericApp().getObject("ViewManager") |
180 vm = ericApp().getObject("ViewManager") |
174 aw = vm.activeWindow() |
181 aw = vm.activeWindow() |
175 if aw: |
182 if aw and aw.isLocalFile(): |
176 dirname = os.path.dirname(aw.getFileName()) |
183 dirname = os.path.dirname(aw.getFileName()) |
177 if not dirname: |
184 if not dirname: |
178 dirname = ( |
185 dirname = ( |
179 Preferences.getMicroPython("MpyWorkspace") |
186 Preferences.getMicroPython("MpyWorkspace") |
180 or Preferences.getMultiProject("Workspace") |
187 or Preferences.getMultiProject("Workspace") |
369 self.__listLocalFiles(name[:-1], True) |
376 self.__listLocalFiles(name[:-1], True) |
370 elif Utilities.MimeTypes.isTextFile(name): |
377 elif Utilities.MimeTypes.isTextFile(name): |
371 ericApp().getObject("ViewManager").getEditor(name) |
378 ericApp().getObject("ViewManager").getEditor(name) |
372 else: |
379 else: |
373 cwd = self.deviceCwd.text() |
380 cwd = self.deviceCwd.text() |
374 if cwd.endswith("/"): |
381 if cwd: |
375 name = cwd + item.text(0) |
382 name = ( |
|
383 cwd + item.text(0) |
|
384 if cwd.endswith("/") |
|
385 else"{0}/{1}".format(cwd, item.text(0)) |
|
386 ) |
376 else: |
387 else: |
377 name = "{0}/{1}".format(cwd, item.text(0)) |
388 name = item.text(0) |
378 if name.endswith("/"): |
389 if name.endswith("/"): |
379 # directory names end with a '/' |
390 # directory names end with a '/' |
380 self.__fileManager.cd(name[:-1]) |
391 self.__fileManager.cd(name[:-1]) |
|
392 else: |
|
393 data = self.__fileManager.getData(name) |
|
394 text = data.decode(encoding = "utf-8") |
|
395 ericApp().getObject("ViewManager").newEditorWithText( |
|
396 text, "Python3", "device:{0}".format(name) |
|
397 ) |
381 |
398 |
382 @pyqtSlot() |
399 @pyqtSlot() |
383 def on_deviceFileTreeWidget_itemSelectionChanged(self): |
400 def on_deviceFileTreeWidget_itemSelectionChanged(self): |
384 """ |
401 """ |
385 Private slot handling a change of selection in the local pane. |
402 Private slot handling a change of selection in the local pane. |
647 """ |
667 """ |
648 self.__fileManager.lls( |
668 self.__fileManager.lls( |
649 self.deviceCwd.text(), |
669 self.deviceCwd.text(), |
650 showHidden=Preferences.getMicroPython("ShowHiddenDevice"), |
670 showHidden=Preferences.getMicroPython("ShowHiddenDevice"), |
651 ) |
671 ) |
|
672 |
|
673 @pyqtSlot() |
|
674 def on_openButton_clicked(self): |
|
675 """ |
|
676 Private slot to open the selected file in a new editor. |
|
677 """ |
|
678 selectedItems = self.deviceFileTreeWidget.selectedItems() |
|
679 if selectedItems: |
|
680 filename = selectedItems[0].text(0).strip() |
|
681 if self.__deviceWithLocalAccess: |
|
682 name = os.path.join(self.deviceCwd.text(), filename) |
|
683 if not name.endswith("/") and Utilities.MimeTypes.isTextFile(name): |
|
684 ericApp().getObject("ViewManager").getEditor(name) |
|
685 else: |
|
686 cwd = self.deviceCwd.text() |
|
687 if cwd: |
|
688 name = ( |
|
689 cwd + filename |
|
690 if cwd.endswith("/") |
|
691 else"{0}/{1}".format(cwd, filename) |
|
692 ) |
|
693 else: |
|
694 name = filename |
|
695 if not name.endswith("/"): |
|
696 data = self.__fileManager.getData(name) |
|
697 text = data.decode(encoding = "utf-8") |
|
698 ericApp().getObject("ViewManager").newEditorWithText( |
|
699 text, "Python3", "device:{0}".format(name) |
|
700 ) |
|
701 |
|
702 @pyqtSlot() |
|
703 def on_saveButton_clicked(self, saveAs=False): |
|
704 """ |
|
705 Private slot to save the text of the current editor to a file on the device. |
|
706 """ |
|
707 aw = ericApp().getObject("ViewManager").activeWindow() |
|
708 if not aw: |
|
709 return |
|
710 |
|
711 selectedItems = self.deviceFileTreeWidget.selectedItems() |
|
712 if selectedItems: |
|
713 filename = selectedItems[0].text(0).strip() |
|
714 if filename.endswith("/"): |
|
715 saveAs = True |
|
716 else: |
|
717 saveAs = True |
|
718 |
|
719 if saveAs: |
|
720 filename, ok = QInputDialog.getText( |
|
721 self, |
|
722 self.tr("Save File As"), |
|
723 self.tr("Enter a new name for the file"), |
|
724 QLineEdit.EchoMode.Normal, |
|
725 filename, |
|
726 ) |
|
727 if not ok or not filename: |
|
728 return |
|
729 |
|
730 if saveAs and self.__isFileInList(filename, self.deviceFileTreeWidget): |
|
731 # ask for overwrite permission |
|
732 action, resultFilename = confirmOverwrite( |
|
733 filename, |
|
734 self.tr("Save File As"), |
|
735 self.tr( |
|
736 "The given file exists already (Enter file name only)." |
|
737 ), |
|
738 False, |
|
739 self, |
|
740 ) |
|
741 if action == "cancel": |
|
742 return |
|
743 elif action == "rename": |
|
744 filename = os.path.basename(resultFilename) |
|
745 |
|
746 text = aw.text() |
|
747 if self.__deviceWithLocalAccess: |
|
748 with open(os.path.join(self.deviceCwd.text(), filename), "w") as f: |
|
749 f.write(text) |
|
750 else: |
|
751 deviceCwd = self.deviceCwd.text() |
|
752 if deviceCwd: |
|
753 filename = ( |
|
754 deviceCwd + "/" + filename |
|
755 if deviceCwd != "/" |
|
756 else "/" + filename |
|
757 ) |
|
758 self.__fileManager.putData(filename, text.encode("utf-8")) |
|
759 |
|
760 aw.setModified(False) |
|
761 |
|
762 @pyqtSlot() |
|
763 def on_saveAsButton_clicked(self): |
|
764 """ |
|
765 Private slot to save the current editor in a new file on the connected device. |
|
766 """ |
|
767 self.on_saveButton_clicked(saveAs=True) |
652 |
768 |
653 ################################################################## |
769 ################################################################## |
654 ## Context menu methods for the local files below |
770 ## Context menu methods for the local files below |
655 ################################################################## |
771 ################################################################## |
656 |
772 |