37 from eric7.QScintilla.EditorAssembly import EditorAssembly |
37 from eric7.QScintilla.EditorAssembly import EditorAssembly |
38 from eric7.QScintilla.Shell import Shell |
38 from eric7.QScintilla.Shell import Shell |
39 from eric7.QScintilla.SpellChecker import SpellChecker |
39 from eric7.QScintilla.SpellChecker import SpellChecker |
40 from eric7.QScintilla.SpellingDictionaryEditDialog import SpellingDictionaryEditDialog |
40 from eric7.QScintilla.SpellingDictionaryEditDialog import SpellingDictionaryEditDialog |
41 from eric7.QScintilla.ZoomDialog import ZoomDialog |
41 from eric7.QScintilla.ZoomDialog import ZoomDialog |
|
42 from eric7.RemoteServerInterface import EricServerFileDialog |
42 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities |
43 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities |
43 |
44 |
44 |
45 |
45 class ViewManager(QWidget): |
46 class ViewManager(QWidget): |
46 """ |
47 """ |
648 ) |
649 ) |
649 ) |
650 ) |
650 self.openAct.triggered.connect(self.__openFiles) |
651 self.openAct.triggered.connect(self.__openFiles) |
651 self.fileActions.append(self.openAct) |
652 self.fileActions.append(self.openAct) |
652 |
653 |
|
654 self.openRemoteAct = EricAction( |
|
655 QCoreApplication.translate("ViewManager", "Open Remote"), |
|
656 EricPixmapCache.getIcon("open-remote"), |
|
657 QCoreApplication.translate("ViewManager", "Open Remote..."), |
|
658 0, |
|
659 0, |
|
660 self, |
|
661 "vm_file_open_remote", |
|
662 ) |
|
663 self.openRemoteAct.setStatusTip( |
|
664 QCoreApplication.translate("ViewManager", "Open a remote file") |
|
665 ) |
|
666 self.openRemoteAct.setWhatsThis( |
|
667 QCoreApplication.translate( |
|
668 "ViewManager", |
|
669 """<b>Open a remote file</b>""" |
|
670 """<p>You will be asked for the name of a remote file to be opened""" |
|
671 """ in an editor window.</p>""", |
|
672 ) |
|
673 ) |
|
674 self.openRemoteAct.triggered.connect(self.__openRemoteFiles) |
|
675 self.openRemoteAct.setEnabled(False) |
|
676 self.fileActions.append(self.openRemoteAct) |
|
677 |
653 self.closeActGrp = createActionGroup(self) |
678 self.closeActGrp = createActionGroup(self) |
654 |
679 |
655 self.closeAct = EricAction( |
680 self.closeAct = EricAction( |
656 QCoreApplication.translate("ViewManager", "Close"), |
681 QCoreApplication.translate("ViewManager", "Close"), |
657 EricPixmapCache.getIcon("closeEditor"), |
682 EricPixmapCache.getIcon("closeEditor"), |
894 self.exportersMenu = self.__initContextMenuExporters() |
919 self.exportersMenu = self.__initContextMenuExporters() |
895 menu.setTearOffEnabled(True) |
920 menu.setTearOffEnabled(True) |
896 |
921 |
897 menu.addAction(self.newAct) |
922 menu.addAction(self.newAct) |
898 menu.addAction(self.openAct) |
923 menu.addAction(self.openAct) |
|
924 menu.addAction(self.openRemoteAct) |
899 self.menuRecentAct = menu.addMenu(self.recentMenu) |
925 self.menuRecentAct = menu.addMenu(self.recentMenu) |
900 menu.addMenu(self.bookmarkedMenu) |
926 menu.addMenu(self.bookmarkedMenu) |
901 menu.addSeparator() |
927 menu.addSeparator() |
902 menu.addAction(self.closeAct) |
928 menu.addAction(self.closeAct) |
903 menu.addAction(self.closeAllAct) |
929 menu.addAction(self.closeAllAct) |
936 tb.setObjectName("FileToolbar") |
962 tb.setObjectName("FileToolbar") |
937 tb.setToolTip(QCoreApplication.translate("ViewManager", "File")) |
963 tb.setToolTip(QCoreApplication.translate("ViewManager", "File")) |
938 |
964 |
939 tb.addAction(self.newAct) |
965 tb.addAction(self.newAct) |
940 tb.addAction(self.openAct) |
966 tb.addAction(self.openAct) |
|
967 tb.addAction(self.openRemoteAct) |
941 tb.addAction(self.closeAct) |
968 tb.addAction(self.closeAct) |
942 tb.addSeparator() |
969 tb.addSeparator() |
943 tb.addAction(self.saveAct) |
970 tb.addAction(self.saveAct) |
944 tb.addAction(self.saveAsAct) |
971 tb.addAction(self.saveAsAct) |
945 tb.addAction(self.saveCopyAct) |
972 tb.addAction(self.saveCopyAct) |
5387 |
5414 |
5388 ################################################################## |
5415 ################################################################## |
5389 ## Methods and slots that deal with file and window handling |
5416 ## Methods and slots that deal with file and window handling |
5390 ################################################################## |
5417 ################################################################## |
5391 |
5418 |
|
5419 @pyqtSlot() |
5392 def __openFiles(self): |
5420 def __openFiles(self): |
5393 """ |
5421 """ |
5394 Private slot to open some files. |
5422 Private slot to open some files. |
5395 """ |
5423 """ |
5396 # set the cwd of the dialog based on the following search criteria: |
|
5397 # 1: Directory of currently active editor |
|
5398 # 2: Directory of currently active project |
|
5399 # 3: CWD |
|
5400 from eric7.QScintilla import Lexers |
5424 from eric7.QScintilla import Lexers |
5401 |
5425 |
5402 fileFilter = self._getOpenFileFilter() |
5426 fileFilter = self._getOpenFileFilter() |
5403 progs = EricFileDialog.getOpenFileNamesAndFilter( |
5427 progs = EricFileDialog.getOpenFileNamesAndFilter( |
5404 self.ui, |
5428 self.ui, |
5405 QCoreApplication.translate("ViewManager", "Open files"), |
5429 QCoreApplication.translate("ViewManager", "Open Files"), |
5406 self._getOpenStartDir(), |
5430 self._getOpenStartDir(), |
5407 Lexers.getOpenFileFiltersList(True, True), |
5431 Lexers.getOpenFileFiltersList(True, True), |
5408 fileFilter, |
5432 fileFilter, |
5409 )[0] |
5433 )[0] |
5410 for prog in progs: |
5434 for prog in progs: |
5411 self.openFiles(prog) |
5435 self.openFiles(prog) |
5412 |
5436 |
|
5437 @pyqtSlot() |
|
5438 def __openRemoteFiles(self): |
|
5439 """ |
|
5440 Private slot to open some files. |
|
5441 """ |
|
5442 from eric7.QScintilla import Lexers |
|
5443 |
|
5444 if ericApp().getObject("EricServer").isServerConnected(): |
|
5445 fileFilter = self._getOpenFileFilter() |
|
5446 progs = EricServerFileDialog.getOpenFileNames( |
|
5447 self.ui, |
|
5448 QCoreApplication.translate("ViewManager", "Open Remote Files"), |
|
5449 self._getOpenStartDir(forRemote=True), |
|
5450 Lexers.getOpenFileFiltersList(True, True), |
|
5451 fileFilter, |
|
5452 ) |
|
5453 for prog in progs: |
|
5454 self.openFiles(prog) |
|
5455 else: |
|
5456 EricMessageBox.critical( |
|
5457 self.ui, |
|
5458 self.tr("Open Remote Files"), |
|
5459 self.tr( |
|
5460 "You must be connected to a remote eric-ide server. Aborting..." |
|
5461 ), |
|
5462 ) |
|
5463 |
|
5464 |
5413 def openFiles(self, prog): |
5465 def openFiles(self, prog): |
5414 """ |
5466 """ |
5415 Public slot to open some files. |
5467 Public slot to open some files. |
5416 |
5468 |
5417 @param prog name of file to be opened |
5469 @param prog name of file to be opened |
5418 @type str |
5470 @type str |
5419 """ |
5471 """ |
5420 prog = os.path.abspath(prog) |
5472 if FileSystemUtilities.isPlainFileName(prog): |
|
5473 prog = os.path.abspath(prog) |
5421 # Open up the new files. |
5474 # Open up the new files. |
5422 self.openSourceFile(prog) |
5475 self.openSourceFile(prog) |
5423 |
5476 |
5424 def checkDirty(self, editor, autosave=False, closeIt=False): |
5477 def checkDirty(self, editor, autosave=False, closeIt=False): |
5425 """ |
5478 """ |
5615 Public slot to close all editors related to a MicroPython device. |
5668 Public slot to close all editors related to a MicroPython device. |
5616 """ |
5669 """ |
5617 for editor in self.editors[:]: |
5670 for editor in self.editors[:]: |
5618 if FileSystemUtilities.isDeviceFileName(editor.getFileName()): |
5671 if FileSystemUtilities.isDeviceFileName(editor.getFileName()): |
5619 self.closeEditor(editor, ignoreDirty=True) |
5672 self.closeEditor(editor, ignoreDirty=True) |
|
5673 |
|
5674 @pyqtSlot() |
|
5675 def closeRemoteEditors(self): |
|
5676 """ |
|
5677 Public slot to close all editors related to a connected eric-ide server. |
|
5678 """ |
|
5679 for editor in self.editors[:]: |
|
5680 if FileSystemUtilities.isRemoteFileName(editor.getFileName()): |
|
5681 self.closeEditor(editor, ignoreDirty=True) |
|
5682 |
|
5683 @pyqtSlot(bool) |
|
5684 def remoteConnectionChanged(self, connected): |
|
5685 """ |
|
5686 Public slot handling a change of the connection state to an eric-ide server. |
|
5687 |
|
5688 @param connected flag indicating the connection state |
|
5689 @type bool |
|
5690 """ |
|
5691 self.openRemoteAct.setEnabled(connected) |
5620 |
5692 |
5621 def exit(self): |
5693 def exit(self): |
5622 """ |
5694 """ |
5623 Public method to handle the debugged program terminating. |
5695 Public method to handle the debugged program terminating. |
5624 """ |
5696 """ |
8032 |
8104 |
8033 ################################################################## |
8105 ################################################################## |
8034 ## Below are protected utility methods |
8106 ## Below are protected utility methods |
8035 ################################################################## |
8107 ################################################################## |
8036 |
8108 |
8037 def _getOpenStartDir(self): |
8109 def _getOpenStartDir(self, forRemote=False): |
8038 """ |
8110 """ |
8039 Protected method to return the starting directory for a file open |
8111 Protected method to return the starting directory for a file open |
8040 dialog. |
8112 dialog. |
8041 |
8113 |
8042 The appropriate starting directory is calculated |
8114 The appropriate starting directory is calculated |
8043 using the following search order, until a match is found:<br /> |
8115 using the following search order, until a match is found:<br /> |
8044 1: Directory of currently active editor<br /> |
8116 1: Directory of currently active editor<br /> |
8045 2: Directory of currently active Project<br /> |
8117 2: Directory of currently active Project<br /> |
8046 3: CWD |
8118 3: Directory defined as the workspace (only for local access)<br /> |
8047 |
8119 4: CWD |
|
8120 |
|
8121 @param forRemote flag indicating to get the start directory for a remote |
|
8122 operation (defaults to False) |
|
8123 @type bool (optional) |
8048 @return name of directory to start |
8124 @return name of directory to start |
8049 @rtype str |
8125 @rtype str |
8050 """ |
8126 """ |
8051 # if we have an active source, return its path |
8127 # if we have an active source, return its path |
8052 if self.activeWindow() is not None and self.activeWindow().getFileName(): |
8128 if self.activeWindow() is not None: |
8053 return os.path.dirname(self.activeWindow().getFileName()) |
8129 fn = self.activeWindow().getFileName() |
|
8130 if ( |
|
8131 (forRemote and FileSystemUtilities.isRemoteFileName(fn)) |
|
8132 or (not forRemote and FileSystemUtilities.isPlainFileName(fn)) |
|
8133 ): |
|
8134 return os.path.dirname(self.activeWindow().getFileName()) |
8054 |
8135 |
8055 # check, if there is an active project and return its path |
8136 # check, if there is an active project and return its path |
8056 elif ericApp().getObject("Project").isOpen(): |
8137 if ericApp().getObject("Project").isOpen(): |
8057 return ericApp().getObject("Project").ppath |
8138 ppath = ericApp().getObject("Project").ppath |
8058 |
8139 if ( |
8059 else: |
8140 (forRemote and FileSystemUtilities.isRemoteFileName(ppath)) |
|
8141 or (not forRemote and FileSystemUtilities.isPlainFileName(ppath)) |
|
8142 ): |
|
8143 return ppath |
|
8144 |
|
8145 if not forRemote: |
8060 return Preferences.getMultiProject("Workspace") or OSUtilities.getHomeDir() |
8146 return Preferences.getMultiProject("Workspace") or OSUtilities.getHomeDir() |
|
8147 |
|
8148 # return empty string |
|
8149 return "" |
8061 |
8150 |
8062 def _getOpenFileFilter(self): |
8151 def _getOpenFileFilter(self): |
8063 """ |
8152 """ |
8064 Protected method to return the active filename filter for a file open |
8153 Protected method to return the active filename filter for a file open |
8065 dialog. |
8154 dialog. |