7 Module implementing the view manager base class. |
7 Module implementing the view manager base class. |
8 """ |
8 """ |
9 |
9 |
10 import re |
10 import re |
11 import os |
11 import os |
|
12 import contextlib |
12 |
13 |
13 from PyQt5.QtCore import ( |
14 from PyQt5.QtCore import ( |
14 pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint, |
15 pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint, |
15 QCoreApplication |
16 QCoreApplication |
16 ) |
17 ) |
4397 Public method to check the dirty status of all editors. |
4398 Public method to check the dirty status of all editors. |
4398 |
4399 |
4399 @return flag indicating successful reset of all dirty flags |
4400 @return flag indicating successful reset of all dirty flags |
4400 @rtype bool |
4401 @rtype bool |
4401 """ |
4402 """ |
4402 for editor in self.editors: |
4403 return all(self.checkDirty(editor) for editor in self.editors) |
4403 if not self.checkDirty(editor): |
|
4404 return False |
|
4405 |
|
4406 return True |
|
4407 |
4404 |
4408 def checkFileDirty(self, fn): |
4405 def checkFileDirty(self, fn): |
4409 """ |
4406 """ |
4410 Public method to check the dirty status of an editor given its file |
4407 Public method to check the dirty status of an editor given its file |
4411 name and open a message window. |
4408 name and open a message window. |
5164 """ |
5161 """ |
5165 self.__loadRecent() |
5162 self.__loadRecent() |
5166 |
5163 |
5167 self.recentMenu.clear() |
5164 self.recentMenu.clear() |
5168 |
5165 |
5169 idx = 1 |
5166 for idx, rs in enumerate(self.recent, start=1): |
5170 for rs in self.recent: |
5167 formatStr = '&{0:d}. {1}' if idx < 10 else '{0:d}. {1}' |
5171 if idx < 10: |
|
5172 formatStr = '&{0:d}. {1}' |
|
5173 else: |
|
5174 formatStr = '{0:d}. {1}' |
|
5175 act = self.recentMenu.addAction( |
5168 act = self.recentMenu.addAction( |
5176 formatStr.format( |
5169 formatStr.format( |
5177 idx, |
5170 idx, |
5178 Utilities.compactPath(rs, self.ui.maxMenuFilePathLen))) |
5171 Utilities.compactPath(rs, self.ui.maxMenuFilePathLen))) |
5179 act.setData(rs) |
5172 act.setData(rs) |
5180 act.setEnabled(QFileInfo(rs).exists()) |
5173 act.setEnabled(QFileInfo(rs).exists()) |
5181 idx += 1 |
|
5182 |
5174 |
5183 self.recentMenu.addSeparator() |
5175 self.recentMenu.addSeparator() |
5184 self.recentMenu.addAction( |
5176 self.recentMenu.addAction( |
5185 QCoreApplication.translate('ViewManager', '&Clear'), |
5177 QCoreApplication.translate('ViewManager', '&Clear'), |
5186 self.clearRecent) |
5178 self.clearRecent) |
5723 |
5715 |
5724 def __zoom(self): |
5716 def __zoom(self): |
5725 """ |
5717 """ |
5726 Private method to handle the zoom action. |
5718 Private method to handle the zoom action. |
5727 """ |
5719 """ |
5728 if QApplication.focusWidget() == e5App().getObject("Shell"): |
5720 aw = ( |
5729 aw = e5App().getObject("Shell") |
5721 e5App().getObject("Shell") |
5730 else: |
5722 if QApplication.focusWidget() == e5App().getObject("Shell") else |
5731 aw = self.activeWindow() |
5723 self.activeWindow() |
|
5724 ) |
5732 if aw: |
5725 if aw: |
5733 from QScintilla.ZoomDialog import ZoomDialog |
5726 from QScintilla.ZoomDialog import ZoomDialog |
5734 dlg = ZoomDialog(aw.getZoom(), self.ui, None, True) |
5727 dlg = ZoomDialog(aw.getZoom(), self.ui, None, True) |
5735 if dlg.exec() == QDialog.DialogCode.Accepted: |
5728 if dlg.exec() == QDialog.DialogCode.Accepted: |
5736 value = dlg.getZoomSize() |
5729 value = dlg.getZoomSize() |
5740 """ |
5733 """ |
5741 Private slot to zoom to a given value. |
5734 Private slot to zoom to a given value. |
5742 |
5735 |
5743 @param value zoom value to be set (integer) |
5736 @param value zoom value to be set (integer) |
5744 """ |
5737 """ |
5745 if QApplication.focusWidget() == e5App().getObject("Shell"): |
5738 aw = ( |
5746 aw = e5App().getObject("Shell") |
5739 e5App().getObject("Shell") |
5747 else: |
5740 if QApplication.focusWidget() == e5App().getObject("Shell") else |
5748 aw = self.activeWindow() |
5741 self.activeWindow() |
|
5742 ) |
5749 if aw: |
5743 if aw: |
5750 aw.zoomTo(value) |
5744 aw.zoomTo(value) |
5751 self.sbZoom.setValue(aw.getZoom()) |
5745 self.sbZoom.setValue(aw.getZoom()) |
5752 |
5746 |
5753 def zoomValueChanged(self, value, zoomingWidget): |
5747 def zoomValueChanged(self, value, zoomingWidget): |
5757 @param value new zoom value |
5751 @param value new zoom value |
5758 @type int |
5752 @type int |
5759 @param zoomingWidget reference to the widget triggering the slot |
5753 @param zoomingWidget reference to the widget triggering the slot |
5760 @type Editor or Shell |
5754 @type Editor or Shell |
5761 """ |
5755 """ |
5762 if QApplication.focusWidget() == e5App().getObject("Shell"): |
5756 aw = ( |
5763 aw = e5App().getObject("Shell") |
5757 e5App().getObject("Shell") |
5764 else: |
5758 if QApplication.focusWidget() == e5App().getObject("Shell") else |
5765 aw = self.activeWindow() |
5759 self.activeWindow() |
|
5760 ) |
5766 if aw and aw == zoomingWidget: |
5761 if aw and aw == zoomingWidget: |
5767 self.sbZoom.setValue(value) |
5762 self.sbZoom.setValue(value) |
5768 |
5763 |
5769 def __clearAllFolds(self): |
5764 def __clearAllFolds(self): |
5770 """ |
5765 """ |
6292 |
6287 |
6293 If it cannot close all editor windows, it aborts the shutdown process. |
6288 If it cannot close all editor windows, it aborts the shutdown process. |
6294 |
6289 |
6295 @return flag indicating success (boolean) |
6290 @return flag indicating success (boolean) |
6296 """ |
6291 """ |
6297 try: |
6292 with contextlib.suppress(TypeError): |
6298 e5App().focusChanged.disconnect(self.appFocusChanged) |
6293 e5App().focusChanged.disconnect(self.appFocusChanged) |
6299 except TypeError: |
|
6300 pass |
|
6301 |
6294 |
6302 self.closeAllWindows() |
6295 self.closeAllWindows() |
6303 self.currentEditor = None |
6296 self.currentEditor = None |
6304 |
6297 |
6305 # save the list of recently opened projects |
6298 # save the list of recently opened projects |
6307 |
6300 |
6308 # save the list of recently opened projects |
6301 # save the list of recently opened projects |
6309 Preferences.Prefs.settings.setValue( |
6302 Preferences.Prefs.settings.setValue( |
6310 'Bookmarked/Sources', self.bookmarked) |
6303 'Bookmarked/Sources', self.bookmarked) |
6311 |
6304 |
6312 if len(self.editors): |
6305 res = len(self.editors) == 0 |
6313 res = False |
|
6314 else: |
|
6315 res = True |
|
6316 |
6306 |
6317 if not res: |
6307 if not res: |
6318 e5App().focusChanged.connect(self.appFocusChanged) |
6308 e5App().focusChanged.connect(self.appFocusChanged) |
6319 |
6309 |
6320 return res |
6310 return res |
7001 aw = e5App().getObject("Shell") |
6991 aw = e5App().getObject("Shell") |
7002 if aw.hasSelectedText(): |
6992 if aw.hasSelectedText(): |
7003 txt = aw.selectedText() |
6993 txt = aw.selectedText() |
7004 else: |
6994 else: |
7005 aw = self.activeWindow() |
6995 aw = self.activeWindow() |
7006 if aw is not None: |
6996 if aw is not None and aw.hasSelectedText(): |
7007 if aw.hasSelectedText(): |
6997 txt = aw.selectedText() |
7008 txt = aw.selectedText() |
|
7009 return txt |
6998 return txt |