Plugins/ViewManagerPlugins/Listspace/Listspace.py

changeset 3005
3953ddfb991d
parent 2964
84b65fb9e780
child 3025
67064c71df21
child 3057
10516539f238
equal deleted inserted replaced
3004:c4bf32c791d0 3005:3953ddfb991d
8 """ 8 """
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, \
14 QSizePolicy, QMenu, QApplication 14 QListWidgetItem, 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
124 """ 124 """
125 return editor in self.editors 125 return editor in self.editors
126 126
127 def firstEditor(self): 127 def firstEditor(self):
128 """ 128 """
129 Public method to retrieve the first editor in the list of managed editors. 129 Public method to retrieve the first editor in the list of managed
130 editors.
130 131
131 @return first editor in list (QScintilla.Editor.Editor) 132 @return first editor in list (QScintilla.Editor.Editor)
132 """ 133 """
133 return len(self.editors) and self.editors[0] or None 134 return len(self.editors) and self.editors[0] or None
134 135
142 @signal editorChangedEd(Editor) emitted when the current editor has changed 143 @signal editorChangedEd(Editor) emitted when the current editor has changed
143 @signal lastEditorClosed() emitted after the last editor window was closed 144 @signal lastEditorClosed() emitted after the last editor window was closed
144 @signal editorOpened(str) emitted after an editor window was opened 145 @signal editorOpened(str) emitted after an editor window was opened
145 @signal editorOpenedEd(Editor) emitted after an editor window was opened 146 @signal editorOpenedEd(Editor) emitted after an editor window was opened
146 @signal editorClosed(str) emitted just before an editor window gets closed 147 @signal editorClosed(str) emitted just before an editor window gets closed
147 @signal editorClosedEd(Editor) emitted just before an editor window gets closed 148 @signal editorClosedEd(Editor) emitted just before an editor window gets
149 closed
148 @signal editorSaved(str) emitted after an editor window was saved 150 @signal editorSaved(str) emitted after an editor window was saved
149 @signal checkActions(Editor) emitted when some actions should be checked 151 @signal checkActions(Editor) emitted when some actions should be checked
150 for their status 152 for their status
151 @signal cursorChanged(Editor) emitted after the cursor position of the active 153 @signal cursorChanged(Editor) emitted after the cursor position of the
152 window has changed 154 active window has changed
153 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled. 155 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled.
154 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled. 156 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled.
155 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled. 157 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled.
156 @signal previewStateChanged(bool) emitted to signal a change in the preview state 158 @signal previewStateChanged(bool) emitted to signal a change in the
159 preview state
157 @signal editorLanguageChanged(Editor) emitted to signal a change of an 160 @signal editorLanguageChanged(Editor) emitted to signal a change of an
158 editors language 161 editors language
159 @signal editorTextChanged(Editor) emitted to signal a change of an editor's text 162 @signal editorTextChanged(Editor) emitted to signal a change of an
160 @signal editorLineChanged(str,int) emitted to signal a change of an editor's 163 editor's text
161 current line (line is given one based) 164 @signal editorLineChanged(str,int) emitted to signal a change of an
165 editor's current line (line is given one based)
162 """ 166 """
163 changeCaption = pyqtSignal(str) 167 changeCaption = pyqtSignal(str)
164 editorChanged = pyqtSignal(str) 168 editorChanged = pyqtSignal(str)
165 editorChangedEd = pyqtSignal(Editor) 169 editorChangedEd = pyqtSignal(Editor)
166 lastEditorClosed = pyqtSignal() 170 lastEditorClosed = pyqtSignal()
222 """ 226 """
223 self.__menu = QMenu(self) 227 self.__menu = QMenu(self)
224 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), 228 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"),
225 self.trUtf8('Close'), self.__contextMenuClose) 229 self.trUtf8('Close'), self.__contextMenuClose)
226 self.closeOthersMenuAct = self.__menu.addAction( 230 self.closeOthersMenuAct = self.__menu.addAction(
227 UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"), 231 UI.PixmapCache.getIcon("tabCloseOther.png"),
232 self.trUtf8("Close Others"),
228 self.__contextMenuCloseOthers) 233 self.__contextMenuCloseOthers)
229 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) 234 self.__menu.addAction(
235 self.trUtf8('Close All'), self.__contextMenuCloseAll)
230 self.__menu.addSeparator() 236 self.__menu.addSeparator()
231 self.saveMenuAct = \ 237 self.saveMenuAct = \
232 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), 238 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"),
233 self.trUtf8('Save'), self.__contextMenuSave) 239 self.trUtf8('Save'), self.__contextMenuSave)
234 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"), 240 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"),
241 self.__contextMenuOpenRejections) 247 self.__contextMenuOpenRejections)
242 self.__menu.addSeparator() 248 self.__menu.addSeparator()
243 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), 249 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"),
244 self.trUtf8('Print'), self.__contextMenuPrintFile) 250 self.trUtf8('Print'), self.__contextMenuPrintFile)
245 self.__menu.addSeparator() 251 self.__menu.addSeparator()
246 self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"), 252 self.copyPathAct = self.__menu.addAction(
253 self.trUtf8("Copy Path to Clipboard"),
247 self.__contextMenuCopyPathToClipboard) 254 self.__contextMenuCopyPathToClipboard)
248 255
249 def __showMenu(self, point): 256 def __showMenu(self, point):
250 """ 257 """
251 Private slot to handle the customContextMenuRequested signal of 258 Private slot to handle the customContextMenuRequested signal of
258 if itm is not None: 265 if itm is not None:
259 row = self.viewlist.row(itm) 266 row = self.viewlist.row(itm)
260 self.contextMenuEditor = self.editors[row] 267 self.contextMenuEditor = self.editors[row]
261 self.contextMenuIndex = row 268 self.contextMenuIndex = row
262 if self.contextMenuEditor: 269 if self.contextMenuEditor:
263 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) 270 self.saveMenuAct.setEnabled(
271 self.contextMenuEditor.isModified())
264 fileName = self.contextMenuEditor.getFileName() 272 fileName = self.contextMenuEditor.getFileName()
265 self.copyPathAct.setEnabled(bool(fileName)) 273 self.copyPathAct.setEnabled(bool(fileName))
266 if fileName: 274 if fileName:
267 rej = "{0}.rej".format(fileName) 275 rej = "{0}.rej".format(fileName)
268 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) 276 self.openRejectionsMenuAct.setEnabled(
277 os.path.exists(rej))
269 else: 278 else:
270 self.openRejectionsMenuAct.setEnabled(False) 279 self.openRejectionsMenuAct.setEnabled(False)
271 280
272 self.closeOthersMenuAct.setEnabled(self.viewlist.count() > 1) 281 self.closeOthersMenuAct.setEnabled(
282 self.viewlist.count() > 1)
273 283
274 self.__menu.popup(self.viewlist.mapToGlobal(point)) 284 self.__menu.popup(self.viewlist.mapToGlobal(point))
275 285
276 def canCascade(self): 286 def canCascade(self):
277 """ 287 """
472 """ 482 """
473 pass 483 pass
474 484
475 def _initWindowActions(self): 485 def _initWindowActions(self):
476 """ 486 """
477 Protected method to define the user interface actions for window handling. 487 Protected method to define the user interface actions for window
488 handling.
478 """ 489 """
479 pass 490 pass
480 491
481 def setEditorName(self, editor, newName): 492 def setEditorName(self, editor, newName):
482 """ 493 """
505 @param editor editor window changed 516 @param editor editor window changed
506 """ 517 """
507 currentRow = self.viewlist.currentRow() 518 currentRow = self.viewlist.currentRow()
508 index = self.editors.index(editor) 519 index = self.editors.index(editor)
509 if m: 520 if m:
510 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("fileModified.png")) 521 self.viewlist.item(index).setIcon(
522 UI.PixmapCache.getIcon("fileModified.png"))
511 elif editor.hasSyntaxErrors(): 523 elif editor.hasSyntaxErrors():
512 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("syntaxError.png")) 524 self.viewlist.item(index).setIcon(
525 UI.PixmapCache.getIcon("syntaxError.png"))
513 elif editor.hasFlakesWarnings(): 526 elif editor.hasFlakesWarnings():
514 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("warning.png")) 527 self.viewlist.item(index).setIcon(
515 else: 528 UI.PixmapCache.getIcon("warning.png"))
516 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("empty.png")) 529 else:
530 self.viewlist.item(index).setIcon(
531 UI.PixmapCache.getIcon("empty.png"))
517 self.viewlist.setCurrentRow(currentRow) 532 self.viewlist.setCurrentRow(currentRow)
518 self._checkActions(editor) 533 self._checkActions(editor)
519 534
520 def _syntaxErrorToggled(self, editor): 535 def _syntaxErrorToggled(self, editor):
521 """ 536 """
524 @param editor editor that sent the signal 539 @param editor editor that sent the signal
525 """ 540 """
526 currentRow = self.viewlist.currentRow() 541 currentRow = self.viewlist.currentRow()
527 index = self.editors.index(editor) 542 index = self.editors.index(editor)
528 if editor.hasSyntaxErrors(): 543 if editor.hasSyntaxErrors():
529 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("syntaxError.png")) 544 self.viewlist.item(index).setIcon(
545 UI.PixmapCache.getIcon("syntaxError.png"))
530 elif editor.hasFlakesWarnings(): 546 elif editor.hasFlakesWarnings():
531 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("warning.png")) 547 self.viewlist.item(index).setIcon(
548 UI.PixmapCache.getIcon("warning.png"))
532 elif editor.isModified(): 549 elif editor.isModified():
533 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("fileModified.png")) 550 self.viewlist.item(index).setIcon(
534 else: 551 UI.PixmapCache.getIcon("fileModified.png"))
535 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("empty.png")) 552 else:
553 self.viewlist.item(index).setIcon(
554 UI.PixmapCache.getIcon("empty.png"))
536 self.viewlist.setCurrentRow(currentRow) 555 self.viewlist.setCurrentRow(currentRow)
537 556
538 ViewManager._syntaxErrorToggled(self, editor) 557 ViewManager._syntaxErrorToggled(self, editor)
539 558
540 def addSplit(self): 559 def addSplit(self):
550 stack.installEventFilter(self) 569 stack.installEventFilter(self)
551 if self.stackArea.orientation() == Qt.Horizontal: 570 if self.stackArea.orientation() == Qt.Horizontal:
552 size = self.stackArea.width() 571 size = self.stackArea.width()
553 else: 572 else:
554 size = self.stackArea.height() 573 size = self.stackArea.height()
555 self.stackArea.setSizes([int(size / len(self.stacks))] * len(self.stacks)) 574 self.stackArea.setSizes(
575 [int(size / len(self.stacks))] * len(self.stacks))
556 self.splitRemoveAct.setEnabled(True) 576 self.splitRemoveAct.setEnabled(True)
557 self.nextSplitAct.setEnabled(True) 577 self.nextSplitAct.setEnabled(True)
558 self.prevSplitAct.setEnabled(True) 578 self.prevSplitAct.setEnabled(True)
559 579
560 def removeSplit(self): 580 def removeSplit(self):
678 """ 698 """
679 self.saveEditorsList(self.editors) 699 self.saveEditorsList(self.editors)
680 700
681 def __contextMenuOpenRejections(self): 701 def __contextMenuOpenRejections(self):
682 """ 702 """
683 Private slot to open a rejections file associated with the selected editor. 703 Private slot to open a rejections file associated with the selected
704 editor.
684 """ 705 """
685 if self.contextMenuEditor: 706 if self.contextMenuEditor:
686 fileName = self.contextMenuEditor.getFileName() 707 fileName = self.contextMenuEditor.getFileName()
687 if fileName: 708 if fileName:
688 rej = "{0}.rej".format(fileName) 709 rej = "{0}.rej".format(fileName)
696 if self.contextMenuEditor: 717 if self.contextMenuEditor:
697 self.printEditor(self.contextMenuEditor) 718 self.printEditor(self.contextMenuEditor)
698 719
699 def __contextMenuCopyPathToClipboard(self): 720 def __contextMenuCopyPathToClipboard(self):
700 """ 721 """
701 Private method to copy the file name of the selected editor to the clipboard. 722 Private method to copy the file name of the selected editor to the
723 clipboard.
702 """ 724 """
703 if self.contextMenuEditor: 725 if self.contextMenuEditor:
704 fn = self.contextMenuEditor.getFileName() 726 fn = self.contextMenuEditor.getFileName()
705 if fn: 727 if fn:
706 cb = QApplication.clipboard() 728 cb = QApplication.clipboard()
724 fn = editor.getFileName() 746 fn = editor.getFileName()
725 if fn: 747 if fn:
726 self.changeCaption.emit(fn) 748 self.changeCaption.emit(fn)
727 if not self.__inRemoveView: 749 if not self.__inRemoveView:
728 self.editorChanged.emit(fn) 750 self.editorChanged.emit(fn)
729 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) 751 self.editorLineChanged.emit(
752 fn, editor.getCursorPosition()[0] + 1)
730 else: 753 else:
731 self.changeCaption.emit("") 754 self.changeCaption.emit("")
732 self.editorChangedEd.emit(editor) 755 self.editorChangedEd.emit(editor)
733 756
734 cindex = self.editors.index(editor) 757 cindex = self.editors.index(editor)
765 fn = aw.getFileName() 788 fn = aw.getFileName()
766 if fn: 789 if fn:
767 self.changeCaption.emit(fn) 790 self.changeCaption.emit(fn)
768 if switched: 791 if switched:
769 self.editorChanged.emit(fn) 792 self.editorChanged.emit(fn)
770 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) 793 self.editorLineChanged.emit(
794 fn, aw.getCursorPosition()[0] + 1)
771 else: 795 else:
772 self.changeCaption.emit("") 796 self.changeCaption.emit("")
773 self.editorChangedEd.emit(aw) 797 self.editorChangedEd.emit(aw)
774 798
775 return False 799 return False

eric ide

mercurial