7 Module implementing the viewmanager base class. |
7 Module implementing the viewmanager base class. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import pyqtSlot, pyqtSignal, QSignalMapper, QTimer, \ |
12 from PyQt4.QtCore import pyqtSignal, QSignalMapper, QTimer, \ |
13 QFileInfo, QRegExp, QObject, Qt |
13 QFileInfo, QRegExp, QObject, Qt |
14 from PyQt4.QtGui import QColor, QKeySequence, QLineEdit, QToolBar, \ |
14 from PyQt4.QtGui import QColor, QKeySequence, QLineEdit, QToolBar, \ |
15 QWidgetAction, QDialog, QApplication, QMenu, QPalette, QComboBox, QPixmap |
15 QWidgetAction, QDialog, QApplication, QMenu, QPalette, QComboBox, QPixmap |
16 from PyQt4.Qsci import QsciScintilla |
16 from PyQt4.Qsci import QsciScintilla |
17 |
17 |
262 self.sbWritable = sbWritable |
262 self.sbWritable = sbWritable |
263 self.sbEnc = sbEncoding |
263 self.sbEnc = sbEncoding |
264 self.sbLang = sbLanguage |
264 self.sbLang = sbLanguage |
265 self.sbEol = sbEol |
265 self.sbEol = sbEol |
266 self.sbZoom = sbZoom |
266 self.sbZoom = sbZoom |
267 self.sbZoom.valueChanged.connect(self.__zoom) |
267 self.sbZoom.valueChanged.connect(self.__zoomTo) |
268 self.__setSbFile(zoom=0) |
268 self.__setSbFile(zoom=0) |
269 |
269 |
270 self.sbLang.clicked.connect(self.__showLanguagesMenu) |
270 self.sbLang.clicked.connect(self.__showLanguagesMenu) |
271 self.sbEol.clicked.connect(self.__showEolMenu) |
271 self.sbEol.clicked.connect(self.__showEolMenu) |
272 self.sbEnc.clicked.connect(self.__showEncodingsMenu) |
272 self.sbEnc.clicked.connect(self.__showEncodingsMenu) |
591 'ViewManager', |
591 'ViewManager', |
592 """<b>Open a file</b>""" |
592 """<b>Open a file</b>""" |
593 """<p>You will be asked for the name of a file to be opened""" |
593 """<p>You will be asked for the name of a file to be opened""" |
594 """ in an editor window.</p>""" |
594 """ in an editor window.</p>""" |
595 )) |
595 )) |
596 self.openAct.triggered.connect(self.openFiles) |
596 self.openAct.triggered.connect(self.__openFiles) |
597 self.fileActions.append(self.openAct) |
597 self.fileActions.append(self.openAct) |
598 |
598 |
599 self.closeActGrp = createActionGroup(self) |
599 self.closeActGrp = createActionGroup(self) |
600 |
600 |
601 self.closeAct = E5Action( |
601 self.closeAct = E5Action( |
3366 self.unhighlightAct.setWhatsThis(QApplication.translate( |
3366 self.unhighlightAct.setWhatsThis(QApplication.translate( |
3367 'ViewManager', |
3367 'ViewManager', |
3368 """<b>Remove all highlights</b>""" |
3368 """<b>Remove all highlights</b>""" |
3369 """<p>Remove the highlights of all editors.</p>""" |
3369 """<p>Remove the highlights of all editors.</p>""" |
3370 )) |
3370 )) |
3371 self.unhighlightAct.triggered.connect(self.unhighlight) |
3371 self.unhighlightAct.triggered.connect(self.__unhighlight) |
3372 self.viewActions.append(self.unhighlightAct) |
3372 self.viewActions.append(self.unhighlightAct) |
3373 |
3373 |
3374 self.newDocumentViewAct = E5Action( |
3374 self.newDocumentViewAct = E5Action( |
3375 QApplication.translate('ViewManager', 'New Document View'), |
3375 QApplication.translate('ViewManager', 'New Document View'), |
3376 UI.PixmapCache.getIcon("documentNewView.png"), |
3376 UI.PixmapCache.getIcon("documentNewView.png"), |
4143 |
4143 |
4144 ################################################################## |
4144 ################################################################## |
4145 ## Methods and slots that deal with file and window handling |
4145 ## Methods and slots that deal with file and window handling |
4146 ################################################################## |
4146 ################################################################## |
4147 |
4147 |
4148 @pyqtSlot() |
4148 def __openFiles(self): |
4149 def openFiles(self, prog=None): |
4149 """ |
|
4150 Private slot to open some files. |
|
4151 """ |
|
4152 # set the cwd of the dialog based on the following search criteria: |
|
4153 # 1: Directory of currently active editor |
|
4154 # 2: Directory of currently active project |
|
4155 # 3: CWD |
|
4156 import QScintilla.Lexers |
|
4157 filter = self._getOpenFileFilter() |
|
4158 progs = E5FileDialog.getOpenFileNamesAndFilter( |
|
4159 self.ui, |
|
4160 QApplication.translate('ViewManager', "Open files"), |
|
4161 self._getOpenStartDir(), |
|
4162 QScintilla.Lexers.getOpenFileFiltersList(True, True), |
|
4163 filter)[0] |
|
4164 for prog in progs: |
|
4165 self.openFile(prog) |
|
4166 |
|
4167 def openFiles(self, prog): |
4150 """ |
4168 """ |
4151 Public slot to open some files. |
4169 Public slot to open some files. |
4152 |
4170 |
4153 @param prog name of file to be opened (string) |
4171 @param prog name of file to be opened (string) |
4154 """ |
4172 """ |
4155 # Get the file name if one wasn't specified. |
4173 prog = Utilities.normabspath(prog) |
4156 if prog is None: |
4174 # Open up the new files. |
4157 # set the cwd of the dialog based on the following search criteria: |
4175 self.openSourceFile(prog) |
4158 # 1: Directory of currently active editor |
|
4159 # 2: Directory of currently active project |
|
4160 # 3: CWD |
|
4161 import QScintilla.Lexers |
|
4162 filter = self._getOpenFileFilter() |
|
4163 progs = E5FileDialog.getOpenFileNamesAndFilter( |
|
4164 self.ui, |
|
4165 QApplication.translate('ViewManager', "Open files"), |
|
4166 self._getOpenStartDir(), |
|
4167 QScintilla.Lexers.getOpenFileFiltersList(True, True), |
|
4168 filter)[0] |
|
4169 else: |
|
4170 progs = [prog] |
|
4171 |
|
4172 for prog in progs: |
|
4173 prog = Utilities.normabspath(prog) |
|
4174 # Open up the new files. |
|
4175 self.openSourceFile(prog) |
|
4176 |
4176 |
4177 def checkDirty(self, editor, autosave=False): |
4177 def checkDirty(self, editor, autosave=False): |
4178 """ |
4178 """ |
4179 Public method to check dirty status and open a message window. |
4179 Public method to check dirty status and open a message window. |
4180 |
4180 |
4563 pixmap = UI.PixmapCache.getPixmap("eolWindows.png") |
4563 pixmap = UI.PixmapCache.getPixmap("eolWindows.png") |
4564 else: |
4564 else: |
4565 pixmap = QPixmap() |
4565 pixmap = QPixmap() |
4566 return pixmap |
4566 return pixmap |
4567 |
4567 |
4568 @pyqtSlot() |
4568 def __unhighlight(self): |
|
4569 """ |
|
4570 Privat slot to switch of all highlights. |
|
4571 """ |
|
4572 self.unhighlight() |
|
4573 |
4569 def unhighlight(self, current=False): |
4574 def unhighlight(self, current=False): |
4570 """ |
4575 """ |
4571 Public method to switch off all highlights. |
4576 Public method to switch off all highlights or the highlight of |
|
4577 the current editor. |
4572 |
4578 |
4573 @param current flag indicating only the current editor should be |
4579 @param current flag indicating only the current editor should be |
4574 unhighlighted (boolean) |
4580 unhighlighted (boolean) |
4575 """ |
4581 """ |
4576 if current: |
4582 if current: |
5582 aw = self.activeWindow() |
5588 aw = self.activeWindow() |
5583 if aw: |
5589 if aw: |
5584 aw.zoomTo(0) |
5590 aw.zoomTo(0) |
5585 self.sbZoom.setValue(aw.getZoom()) |
5591 self.sbZoom.setValue(aw.getZoom()) |
5586 |
5592 |
5587 @pyqtSlot() |
5593 def __zoom(self): |
5588 @pyqtSlot(int) |
|
5589 def __zoom(self, value=None): |
|
5590 """ |
5594 """ |
5591 Private method to handle the zoom action. |
5595 Private method to handle the zoom action. |
5592 |
|
5593 @keyparam value zoom value to be set (integer) |
|
5594 """ |
5596 """ |
5595 if QApplication.focusWidget() == e5App().getObject("Shell"): |
5597 if QApplication.focusWidget() == e5App().getObject("Shell"): |
5596 aw = e5App().getObject("Shell") |
5598 aw = e5App().getObject("Shell") |
5597 else: |
5599 else: |
5598 aw = self.activeWindow() |
5600 aw = self.activeWindow() |
5599 if aw: |
5601 if aw: |
5600 if value is None: |
5602 from QScintilla.ZoomDialog import ZoomDialog |
5601 from QScintilla.ZoomDialog import ZoomDialog |
5603 dlg = ZoomDialog(aw.getZoom(), self.ui, None, True) |
5602 dlg = ZoomDialog(aw.getZoom(), self.ui, None, True) |
5604 if dlg.exec_() == QDialog.Accepted: |
5603 if dlg.exec_() == QDialog.Accepted: |
5605 value = dlg.getZoomSize() |
5604 value = dlg.getZoomSize() |
|
5605 if value is not None: |
5606 if value is not None: |
5606 aw.zoomTo(value) |
5607 self.__zoomTo(value) |
5607 self.sbZoom.setValue(aw.getZoom()) |
5608 |
|
5609 def __zoomTo(self, value): |
|
5610 """ |
|
5611 Private slot to zoom to a given value. |
|
5612 |
|
5613 @param value zoom value to be set (integer) |
|
5614 """ |
|
5615 if QApplication.focusWidget() == e5App().getObject("Shell"): |
|
5616 aw = e5App().getObject("Shell") |
|
5617 else: |
|
5618 aw = self.activeWindow() |
|
5619 if aw: |
|
5620 aw.zoomTo(value) |
|
5621 self.sbZoom.setValue(aw.getZoom()) |
5608 |
5622 |
5609 def zoomValueChanged(self, value): |
5623 def zoomValueChanged(self, value): |
5610 """ |
5624 """ |
5611 Public slot to handle changes of the zoom value. |
5625 Public slot to handle changes of the zoom value. |
5612 |
5626 |