9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import pyqtSignal, QFileInfo, QEvent, Qt |
12 from PyQt4.QtCore import pyqtSignal, QFileInfo, QEvent, Qt |
13 from PyQt4.QtGui import QStackedWidget, QSplitter, QListWidget, QListWidgetItem, \ |
13 from PyQt4.QtGui import QStackedWidget, QSplitter, QListWidget, QListWidgetItem, \ |
14 QSizePolicy, QMenu |
14 QSizePolicy, QMenu, QApplication |
15 |
15 |
16 from ViewManager.ViewManager import ViewManager |
16 from ViewManager.ViewManager import ViewManager |
17 |
17 |
18 import QScintilla.Editor |
18 import QScintilla.Editor |
19 from QScintilla.Editor import Editor |
19 from QScintilla.Editor import Editor |
205 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"), |
205 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"), |
206 self.trUtf8('Save As...'), self.__contextMenuSaveAs) |
206 self.trUtf8('Save As...'), self.__contextMenuSaveAs) |
207 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAll.png"), |
207 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAll.png"), |
208 self.trUtf8('Save All'), self.__contextMenuSaveAll) |
208 self.trUtf8('Save All'), self.__contextMenuSaveAll) |
209 self.__menu.addSeparator() |
209 self.__menu.addSeparator() |
|
210 self.openRejectionsMenuAct = \ |
|
211 self.__menu.addAction(self.trUtf8("Open 'rejection' file"), |
|
212 self.__contextMenuOpenRejections) |
|
213 self.__menu.addSeparator() |
210 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), |
214 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), |
211 self.trUtf8('Print'), self.__contextMenuPrintFile) |
215 self.trUtf8('Print'), self.__contextMenuPrintFile) |
|
216 self.__menu.addSeparator() |
|
217 self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"), |
|
218 self.__contextMenuCopyPathToClipboard) |
212 |
219 |
213 def __showMenu(self, point): |
220 def __showMenu(self, point): |
214 """ |
221 """ |
215 Private slot to handle the customContextMenuRequested signal of the viewlist. |
222 Private slot to handle the customContextMenuRequested signal of the viewlist. |
216 """ |
223 """ |
219 if itm is not None: |
226 if itm is not None: |
220 row = self.viewlist.row(itm) |
227 row = self.viewlist.row(itm) |
221 self.contextMenuEditor = self.editors[row] |
228 self.contextMenuEditor = self.editors[row] |
222 if self.contextMenuEditor: |
229 if self.contextMenuEditor: |
223 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
230 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
|
231 fileName = self.contextMenuEditor.getFileName() |
|
232 self.copyPathAct.setEnabled(bool(fileName)) |
|
233 if fileName: |
|
234 rej = "{0}.rej".format(fileName) |
|
235 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) |
|
236 else: |
|
237 self.openRejectionsMenuAct.setEnabled(False) |
224 self.__menu.popup(self.viewlist.mapToGlobal(point)) |
238 self.__menu.popup(self.viewlist.mapToGlobal(point)) |
225 |
239 |
226 def canCascade(self): |
240 def canCascade(self): |
227 """ |
241 """ |
228 Public method to signal if cascading of managed windows is available. |
242 Public method to signal if cascading of managed windows is available. |
561 index = self.editors.index(self.currentStack.currentWidget()) |
575 index = self.editors.index(self.currentStack.currentWidget()) |
562 self.viewlist.setCurrentRow(index) |
576 self.viewlist.setCurrentRow(index) |
563 |
577 |
564 def __contextMenuClose(self): |
578 def __contextMenuClose(self): |
565 """ |
579 """ |
566 Private method to close the selected tab. |
580 Private method to close the selected editor. |
567 """ |
581 """ |
568 if self.contextMenuEditor: |
582 if self.contextMenuEditor: |
569 self.closeEditorWindow(self.contextMenuEditor) |
583 self.closeEditorWindow(self.contextMenuEditor) |
570 |
584 |
571 def __contextMenuCloseAll(self): |
585 def __contextMenuCloseAll(self): |
572 """ |
586 """ |
573 Private method to close all tabs. |
587 Private method to close all editors. |
574 """ |
588 """ |
575 savedEditors = self.editors[:] |
589 savedEditors = self.editors[:] |
576 for editor in savedEditors: |
590 for editor in savedEditors: |
577 self.closeEditorWindow(editor) |
591 self.closeEditorWindow(editor) |
578 |
592 |
579 def __contextMenuSave(self): |
593 def __contextMenuSave(self): |
580 """ |
594 """ |
581 Private method to save the selected tab. |
595 Private method to save the selected editor. |
582 """ |
596 """ |
583 if self.contextMenuEditor: |
597 if self.contextMenuEditor: |
584 self.saveEditorEd(self.contextMenuEditor) |
598 self.saveEditorEd(self.contextMenuEditor) |
585 |
599 |
586 def __contextMenuSaveAs(self): |
600 def __contextMenuSaveAs(self): |
587 """ |
601 """ |
588 Private method to save the selected tab to a new file. |
602 Private method to save the selected editor to a new file. |
589 """ |
603 """ |
590 if self.contextMenuEditor: |
604 if self.contextMenuEditor: |
591 self.saveAsEditorEd(self.contextMenuEditor) |
605 self.saveAsEditorEd(self.contextMenuEditor) |
592 |
606 |
593 def __contextMenuSaveAll(self): |
607 def __contextMenuSaveAll(self): |
594 """ |
608 """ |
595 Private method to save all tabs. |
609 Private method to save all editors. |
596 """ |
610 """ |
597 self.saveEditorsList(self.editors) |
611 self.saveEditorsList(self.editors) |
598 |
612 |
|
613 def __contextMenuOpenRejections(self): |
|
614 """ |
|
615 Private slot to open a rejections file associated with the selected editor. |
|
616 """ |
|
617 if self.contextMenuEditor: |
|
618 fileName = self.contextMenuEditor.getFileName() |
|
619 if fileName: |
|
620 rej = "{0}.rej".format(fileName) |
|
621 if os.path.exists(rej): |
|
622 self.openSourceFile(rej) |
|
623 |
599 def __contextMenuPrintFile(self): |
624 def __contextMenuPrintFile(self): |
600 """ |
625 """ |
601 Private method to print the selected tab. |
626 Private method to print the selected editor. |
602 """ |
627 """ |
603 if self.contextMenuEditor: |
628 if self.contextMenuEditor: |
604 self.printEditor(self.contextMenuEditor) |
629 self.printEditor(self.contextMenuEditor) |
|
630 |
|
631 def __contextMenuCopyPathToClipboard(self): |
|
632 """ |
|
633 Private method to copy the file name of the selected editor to the clipboard. |
|
634 """ |
|
635 if self.contextMenuEditor: |
|
636 fn = self.contextMenuEditor.getFileName() |
|
637 if fn: |
|
638 cb = QApplication.clipboard() |
|
639 cb.setText(fn) |
605 |
640 |
606 def __currentChanged(self, index): |
641 def __currentChanged(self, index): |
607 """ |
642 """ |
608 Private slot to handle the currentChanged signal. |
643 Private slot to handle the currentChanged signal. |
609 |
644 |