src/eric7/UI/Browser.py

branch
server
changeset 10592
2bada76be1a6
parent 10470
cd7bfd539ac9
child 10680
306373ccf8fd
equal deleted inserted replaced
10591:9acd8da2b378 10592:2bada76be1a6
33 from eric7 import Preferences 33 from eric7 import Preferences
34 from eric7.EricGui import EricPixmapCache 34 from eric7.EricGui import EricPixmapCache
35 from eric7.EricWidgets import EricFileDialog, EricMessageBox 35 from eric7.EricWidgets import EricFileDialog, EricMessageBox
36 from eric7.EricWidgets.EricApplication import ericApp 36 from eric7.EricWidgets.EricApplication import ericApp
37 from eric7.Project.ProjectBrowserModel import ProjectBrowserSimpleDirectoryItem 37 from eric7.Project.ProjectBrowserModel import ProjectBrowserSimpleDirectoryItem
38 from eric7.RemoteServerInterface import EricServerFileDialog
38 from eric7.SystemUtilities import FileSystemUtilities 39 from eric7.SystemUtilities import FileSystemUtilities
39 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 40 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
40 from eric7.Utilities import MimeTypes 41 from eric7.Utilities import MimeTypes
41 42
42 from .BrowserModel import ( 43 from .BrowserModel import (
104 umlFile = pyqtSignal(str) 105 umlFile = pyqtSignal(str)
105 binaryFile = pyqtSignal(str) 106 binaryFile = pyqtSignal(str)
106 pdfFile = pyqtSignal(str) 107 pdfFile = pyqtSignal(str)
107 testFile = pyqtSignal(str) 108 testFile = pyqtSignal(str)
108 109
109 def __init__(self, parent=None): 110 def __init__(self, serverInterface, parent=None):
110 """ 111 """
111 Constructor 112 Constructor
112 113
114 @param serverInterface reference to the 'eric-ide' server interface object
115 @type EricServerInterface
113 @param parent parent widget 116 @param parent parent widget
114 @type QWidget 117 @type QWidget
115 """ 118 """
116 super().__init__(parent) 119 super().__init__(parent)
117 120
118 self.setWindowTitle(QCoreApplication.translate("Browser", "File-Browser")) 121 self.setWindowTitle(QCoreApplication.translate("Browser", "File-Browser"))
119 self.setWindowIcon(EricPixmapCache.getIcon("eric")) 122 self.setWindowIcon(EricPixmapCache.getIcon("eric"))
120 123
121 self.__model = BrowserModel() 124 self.__ericServerInterface = serverInterface
125 self.__remotefsInterface = serverInterface.getServiceInterface("FileSystem")
126
127 self.__model = BrowserModel(fsInterface=self.__remotefsInterface)
122 self.__sortModel = BrowserSortFilterProxyModel() 128 self.__sortModel = BrowserSortFilterProxyModel()
123 self.__sortModel.setSourceModel(self.__model) 129 self.__sortModel.setSourceModel(self.__model)
124 self.setModel(self.__sortModel) 130 self.setModel(self.__sortModel)
125 131
126 self.selectedItemsFilter = [BrowserFileItem] 132 self.selectedItemsFilter = [BrowserFileItem]
336 ) 342 )
337 343
338 # create the directory menu 344 # create the directory menu
339 self.dirMenu = QMenu(self) 345 self.dirMenu = QMenu(self)
340 self.dirMenu.addAction( 346 self.dirMenu.addAction(
341 QCoreApplication.translate("Browser", "New toplevel directory..."), 347 QCoreApplication.translate("Browser", "New Top Level Directory..."),
342 self.__newToplevelDir, 348 self.__newTopLevelDir,
349 )
350 self.__dmRemoteTopLevelAct = self.dirMenu.addAction(
351 QCoreApplication.translate("Browser", "New Remote Top Level Directory..."),
352 self.__newRemoteTopLevelDir,
343 ) 353 )
344 self.addAsTopLevelAct = self.dirMenu.addAction( 354 self.addAsTopLevelAct = self.dirMenu.addAction(
345 QCoreApplication.translate("Browser", "Add as toplevel directory"), 355 QCoreApplication.translate("Browser", "Add as top level directory"),
346 self.__addAsToplevelDir, 356 self.__addAsToplevelDir,
347 ) 357 )
348 self.removeFromToplevelAct = self.dirMenu.addAction( 358 self.removeFromToplevelAct = self.dirMenu.addAction(
349 QCoreApplication.translate("Browser", "Remove from toplevel"), 359 QCoreApplication.translate("Browser", "Remove from top level"),
350 self.__removeToplevel, 360 self.__removeToplevel,
351 ) 361 )
352 self.dirMenu.addSeparator() 362 self.dirMenu.addSeparator()
353 self.dirMenu.addAction( 363 self.dirMenu.addAction(
354 QCoreApplication.translate("Browser", "Refresh directory"), 364 QCoreApplication.translate("Browser", "Refresh directory"),
385 self.gotoMenu.aboutToShow.connect(self._showGotoMenu) 395 self.gotoMenu.aboutToShow.connect(self._showGotoMenu)
386 self.gotoMenu.triggered.connect(self._gotoAttribute) 396 self.gotoMenu.triggered.connect(self._gotoAttribute)
387 397
388 self.attributeMenu = QMenu(self) 398 self.attributeMenu = QMenu(self)
389 self.attributeMenu.addAction( 399 self.attributeMenu.addAction(
390 QCoreApplication.translate("Browser", "New toplevel directory..."), 400 QCoreApplication.translate("Browser", "New Top Level Directory..."),
391 self.__newToplevelDir, 401 self.__newTopLevelDir,
402 )
403 self.__amRemoteTopLevelAct = self.attributeMenu.addAction(
404 QCoreApplication.translate("Browser", "New Remote Top Level Directory..."),
405 self.__newRemoteTopLevelDir,
392 ) 406 )
393 self.attributeMenu.addSeparator() 407 self.attributeMenu.addSeparator()
394 self.attributeMenu.addMenu(self.gotoMenu) 408 self.attributeMenu.addMenu(self.gotoMenu)
395 409
396 # create the background menu 410 # create the background menu
397 self.backMenu = QMenu(self) 411 self.backMenu = QMenu(self)
398 self.backMenu.addAction( 412 self.backMenu.addAction(
399 QCoreApplication.translate("Browser", "New toplevel directory..."), 413 QCoreApplication.translate("Browser", "New Top Level Directory..."),
400 self.__newToplevelDir, 414 self.__newTopLevelDir,
415 )
416 self.__bmRemoteTopLevelAct = self.backMenu.addAction(
417 QCoreApplication.translate("Browser", "New Remote Top Level Directory..."),
418 self.__newRemoteTopLevelDir,
401 ) 419 )
402 self.backMenu.addSeparator() 420 self.backMenu.addSeparator()
403 self.backMenu.addAction(self.showHiddenFilesAct) 421 self.backMenu.addAction(self.showHiddenFilesAct)
404 422
405 def mouseDoubleClickEvent(self, mouseEvent): 423 def mouseDoubleClickEvent(self, mouseEvent):
429 else: 447 else:
430 self._openItem() 448 self._openItem()
431 449
432 def _contextMenuRequested(self, coord): 450 def _contextMenuRequested(self, coord):
433 """ 451 """
434 Protected slot to show the context menu of the listview. 452 Protected slot to show the context menu of the list view.
435 453
436 @param coord the position of the mouse pointer 454 @param coord the position of the mouse pointer
437 @type QPoint 455 @type QPoint
438 """ 456 """
439 categories = self.getSelectedItemsCountCategorized( 457 categories = self.getSelectedItemsCountCategorized(
473 ): 491 ):
474 self.editPixmapAct.setVisible(False) 492 self.editPixmapAct.setVisible(False)
475 self.openInPdfViewerAct.setVisible(False) 493 self.openInPdfViewerAct.setVisible(False)
476 self.menu.popup(coord) 494 self.menu.popup(coord)
477 elif isinstance(itm, BrowserClassAttributeItem): 495 elif isinstance(itm, BrowserClassAttributeItem):
496 self.__amRemoteTopLevelAct.setEnabled(
497 self.__ericServerInterface.isServerConnected()
498 )
478 self.attributeMenu.popup(coord) 499 self.attributeMenu.popup(coord)
479 elif isinstance(itm, BrowserDirectoryItem): 500 elif isinstance(itm, BrowserDirectoryItem):
480 if not index.parent().isValid(): 501 if not index.parent().isValid():
481 self.removeFromToplevelAct.setEnabled(True) 502 self.removeFromToplevelAct.setEnabled(True)
482 self.addAsTopLevelAct.setEnabled(False) 503 self.addAsTopLevelAct.setEnabled(False)
483 else: 504 else:
484 self.removeFromToplevelAct.setEnabled(False) 505 self.removeFromToplevelAct.setEnabled(False)
485 self.addAsTopLevelAct.setEnabled(True) 506 self.addAsTopLevelAct.setEnabled(True)
507 self.__dmRemoteTopLevelAct.setEnabled(
508 self.__ericServerInterface.isServerConnected()
509 )
486 self.dirMenu.popup(coord) 510 self.dirMenu.popup(coord)
487 else: 511 else:
512 self.__bmRemoteTopLevelAct.setEnabled(
513 self.__ericServerInterface.isServerConnected()
514 )
488 self.backMenu.popup(coord) 515 self.backMenu.popup(coord)
489 else: 516 else:
517 self.__bmRemoteTopLevelAct.setEnabled(
518 self.__ericServerInterface.isServerConnected()
519 )
490 self.backMenu.popup(self.mapToGlobal(coord)) 520 self.backMenu.popup(self.mapToGlobal(coord))
491 521
492 def _showGotoMenu(self): 522 def _showGotoMenu(self):
493 """ 523 """
494 Protected slot to prepare the goto submenu of the attribute menu. 524 Protected slot to prepare the goto submenu of the attribute menu.
753 """ 783 """
754 self.__sortModel.setShowHiddenFiles(checked) 784 self.__sortModel.setShowHiddenFiles(checked)
755 # remember the current state 785 # remember the current state
756 Preferences.setUI("BrowsersListHiddenFiles", checked) 786 Preferences.setUI("BrowsersListHiddenFiles", checked)
757 787
788 @pyqtSlot()
758 def handleTesting(self): 789 def handleTesting(self):
759 """ 790 """
760 Public slot to handle the testing popup menu entry. 791 Public slot to handle the testing popup menu entry.
761 """ 792 """
762 try: 793 try:
767 pyfn = None 798 pyfn = None
768 799
769 if pyfn is not None: 800 if pyfn is not None:
770 self.testFile.emit(pyfn) 801 self.testFile.emit(pyfn)
771 802
772 def __newToplevelDir(self): 803 @pyqtSlot()
773 """ 804 def __newTopLevelDir(self):
774 Private slot to handle the New toplevel directory popup menu entry. 805 """
806 Private slot to handle the New Top Level Directory popup menu entry.
775 """ 807 """
776 dname = EricFileDialog.getExistingDirectory( 808 dname = EricFileDialog.getExistingDirectory(
777 None, 809 None,
778 QCoreApplication.translate("Browser", "New toplevel directory"), 810 QCoreApplication.translate("Browser", "New Top Level Directory"),
779 "", 811 "",
780 EricFileDialog.ShowDirsOnly, 812 EricFileDialog.ShowDirsOnly,
781 ) 813 )
782 if dname: 814 if dname:
783 dname = os.path.abspath(FileSystemUtilities.toNativeSeparators(dname)) 815 dname = os.path.abspath(FileSystemUtilities.toNativeSeparators(dname))
784 self.__model.addTopLevelDir(dname) 816 self.__model.addTopLevelDir(dname)
785 817
818 @pyqtSlot()
819 def __newRemoteTopLevelDir(self):
820 """
821 Private slot to handle the New Remote Top Level Directory popup menu entry.
822 """
823 dname = EricServerFileDialog.getExistingDirectory(
824 None,
825 QCoreApplication.translate("Browser", "New Remote Top Level Directory"),
826 "",
827 dirsOnly=True,
828 )
829 if dname:
830 self.__model.addTopLevelDir(dname)
831
832 @pyqtSlot()
786 def __removeToplevel(self): 833 def __removeToplevel(self):
787 """ 834 """
788 Private slot to handle the Remove from toplevel popup menu entry. 835 Private slot to handle the Remove from top level popup menu entry.
789 """ 836 """
790 index = self.currentIndex() 837 index = self.currentIndex()
791 sindex = self.model().mapToSource(index) 838 sindex = self.model().mapToSource(index)
792 self.__model.removeToplevelDir(sindex) 839 self.__model.removeToplevelDir(sindex)
793 840
841 @pyqtSlot()
794 def __addAsToplevelDir(self): 842 def __addAsToplevelDir(self):
795 """ 843 """
796 Private slot to handle the Add as toplevel directory popup menu entry. 844 Private slot to handle the Add as top level directory popup menu entry.
797 """ 845 """
798 index = self.currentIndex() 846 index = self.currentIndex()
799 dname = self.model().item(index).dirName() 847 dname = self.model().item(index).dirName()
800 self.__model.addTopLevelDir(dname) 848 self.__model.addTopLevelDir(dname)
801 849
850 @pyqtSlot()
802 def __refreshDirectory(self): 851 def __refreshDirectory(self):
803 """ 852 """
804 Private slot to refresh a directory entry. 853 Private slot to refresh a directory entry.
805 """ 854 """
806 index = self.currentIndex() 855 index = self.currentIndex()
807 refreshDir = self.model().item(index).dirName() 856 refreshDir = self.model().item(index).dirName()
808 self.__model.directoryChanged(refreshDir) 857 self.__model.directoryChanged(refreshDir)
809 858
859 @pyqtSlot()
810 def __findInDirectory(self): 860 def __findInDirectory(self):
811 """ 861 """
812 Private slot to handle the Find in directory popup menu entry. 862 Private slot to handle the Find in directory popup menu entry.
813 """ 863 """
814 index = self.currentIndex() 864 index = self.currentIndex()
815 searchDir = self.model().item(index).dirName() 865 searchDir = self.model().item(index).dirName()
816 866
817 ericApp().getObject("UserInterface").showFindFilesWidget(searchDir=searchDir) 867 ericApp().getObject("UserInterface").showFindFilesWidget(searchDir=searchDir)
818 868
869 @pyqtSlot()
819 def __replaceInDirectory(self): 870 def __replaceInDirectory(self):
820 """ 871 """
821 Private slot to handle the Find&Replace in directory popup menu entry. 872 Private slot to handle the Find&Replace in directory popup menu entry.
822 """ 873 """
823 index = self.currentIndex() 874 index = self.currentIndex()
824 searchDir = self.model().item(index).dirName() 875 searchDir = self.model().item(index).dirName()
825 876
826 ericApp().getObject("UserInterface").showReplaceFilesWidget(searchDir=searchDir) 877 ericApp().getObject("UserInterface").showReplaceFilesWidget(searchDir=searchDir)
827 878
879 @pyqtSlot(str)
828 def handleProgramChange(self, fn): 880 def handleProgramChange(self, fn):
829 """ 881 """
830 Public slot to handle the programChange signal. 882 Public slot to handle the programChange signal.
831 883
832 @param fn file name 884 @param fn file name
833 @type str 885 @type str
834 """ 886 """
835 self.__model.programChange(os.path.dirname(fn)) 887 self.__model.programChange(os.path.dirname(fn))
836 888
889 @pyqtSlot(str)
837 def handleInterpreterChanged(self, interpreter): 890 def handleInterpreterChanged(self, interpreter):
838 """ 891 """
839 Public slot to handle a change of the debug client's interpreter. 892 Public slot to handle a change of the debug client's interpreter.
840 893
841 @param interpreter interpreter of the debug client 894 @param interpreter interpreter of the debug client

eric ide

mercurial