149 for their status |
149 for their status |
150 @signal cursorChanged(Editor) emitted after the cursor position of the active |
150 @signal cursorChanged(Editor) emitted after the cursor position of the active |
151 window has changed |
151 window has changed |
152 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled. |
152 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled. |
153 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled. |
153 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled. |
|
154 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled. |
154 """ |
155 """ |
155 changeCaption = pyqtSignal(str) |
156 changeCaption = pyqtSignal(str) |
156 editorChanged = pyqtSignal(str) |
157 editorChanged = pyqtSignal(str) |
157 |
158 |
158 lastEditorClosed = pyqtSignal() |
159 lastEditorClosed = pyqtSignal() |
184 policy = self.viewlist.sizePolicy() |
185 policy = self.viewlist.sizePolicy() |
185 policy.setHorizontalPolicy(QSizePolicy.Ignored) |
186 policy.setHorizontalPolicy(QSizePolicy.Ignored) |
186 self.viewlist.setSizePolicy(policy) |
187 self.viewlist.setSizePolicy(policy) |
187 self.addWidget(self.viewlist) |
188 self.addWidget(self.viewlist) |
188 self.viewlist.setContextMenuPolicy(Qt.CustomContextMenu) |
189 self.viewlist.setContextMenuPolicy(Qt.CustomContextMenu) |
189 self.viewlist.itemActivated.connect(self.__showSelectedView) |
190 self.viewlist.currentRowChanged.connect(self.__showSelectedView) |
190 self.viewlist.itemClicked.connect(self.__showSelectedView) |
|
191 self.viewlist.customContextMenuRequested.connect(self.__showMenu) |
191 self.viewlist.customContextMenuRequested.connect(self.__showMenu) |
192 |
192 |
193 self.stackArea = QSplitter(self) |
193 self.stackArea = QSplitter(self) |
194 self.addWidget(self.stackArea) |
194 self.addWidget(self.stackArea) |
195 self.stackArea.setOrientation(Qt.Vertical) |
195 self.stackArea.setOrientation(Qt.Vertical) |
197 self.stackArea.addWidget(stack) |
197 self.stackArea.addWidget(stack) |
198 self.stacks.append(stack) |
198 self.stacks.append(stack) |
199 self.currentStack = stack |
199 self.currentStack = stack |
200 stack.currentChanged.connect(self.__currentChanged) |
200 stack.currentChanged.connect(self.__currentChanged) |
201 stack.installEventFilter(self) |
201 stack.installEventFilter(self) |
202 self.setSizes([int(self.width() * 0.2), int(self.width() * 0.8)]) # 20% for viewlist |
202 self.setSizes([int(self.width() * 0.2), int(self.width() * 0.8)]) |
|
203 # 20% for viewlist, 80% for the editors |
203 self.__inRemoveView = False |
204 self.__inRemoveView = False |
204 |
205 |
205 self.__initMenu() |
206 self.__initMenu() |
206 self.contextMenuEditor = None |
207 self.contextMenuEditor = None |
|
208 self.contextMenuIndex = -1 |
207 |
209 |
208 def __initMenu(self): |
210 def __initMenu(self): |
209 """ |
211 """ |
210 Private method to initialize the viewlist context menu. |
212 Private method to initialize the viewlist context menu. |
211 """ |
213 """ |
212 self.__menu = QMenu(self) |
214 self.__menu = QMenu(self) |
213 self.__menu.addAction(UI.PixmapCache.getIcon("close.png"), |
215 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), |
214 self.trUtf8('Close'), self.__contextMenuClose) |
216 self.trUtf8('Close'), self.__contextMenuClose) |
|
217 self.closeOthersMenuAct = self.__menu.addAction( |
|
218 UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"), |
|
219 self.__contextMenuCloseOthers) |
215 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) |
220 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) |
216 self.__menu.addSeparator() |
221 self.__menu.addSeparator() |
217 self.saveMenuAct = \ |
222 self.saveMenuAct = \ |
218 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), |
223 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), |
219 self.trUtf8('Save'), self.__contextMenuSave) |
224 self.trUtf8('Save'), self.__contextMenuSave) |
239 if self.editors: |
244 if self.editors: |
240 itm = self.viewlist.itemAt(point) |
245 itm = self.viewlist.itemAt(point) |
241 if itm is not None: |
246 if itm is not None: |
242 row = self.viewlist.row(itm) |
247 row = self.viewlist.row(itm) |
243 self.contextMenuEditor = self.editors[row] |
248 self.contextMenuEditor = self.editors[row] |
|
249 self.contextMenuIndex = row |
244 if self.contextMenuEditor: |
250 if self.contextMenuEditor: |
245 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
251 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) |
246 fileName = self.contextMenuEditor.getFileName() |
252 fileName = self.contextMenuEditor.getFileName() |
247 self.copyPathAct.setEnabled(bool(fileName)) |
253 self.copyPathAct.setEnabled(bool(fileName)) |
248 if fileName: |
254 if fileName: |
249 rej = "{0}.rej".format(fileName) |
255 rej = "{0}.rej".format(fileName) |
250 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) |
256 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) |
251 else: |
257 else: |
252 self.openRejectionsMenuAct.setEnabled(False) |
258 self.openRejectionsMenuAct.setEnabled(False) |
|
259 |
|
260 self.closeOthersMenuAct.setEnabled(self.viewlist.count() > 1) |
|
261 |
253 self.__menu.popup(self.viewlist.mapToGlobal(point)) |
262 self.__menu.popup(self.viewlist.mapToGlobal(point)) |
254 |
263 |
255 def canCascade(self): |
264 def canCascade(self): |
256 """ |
265 """ |
257 Public method to signal if cascading of managed windows is available. |
266 Public method to signal if cascading of managed windows is available. |
323 if len(self.editors) > 1: |
332 if len(self.editors) > 1: |
324 ind = 1 |
333 ind = 1 |
325 else: |
334 else: |
326 return |
335 return |
327 stack.setCurrentWidget(stack.firstEditor()) |
336 stack.setCurrentWidget(stack.firstEditor()) |
328 self._showView(self.editors[ind]) |
337 self._showView(self.editors[ind].parent()) |
329 |
338 |
330 aw = self.activeWindow() |
339 aw = self.activeWindow() |
331 fn = aw and aw.getFileName() or None |
340 fn = aw and aw.getFileName() or None |
332 if fn: |
341 if fn: |
333 self.changeCaption.emit(fn) |
342 self.changeCaption.emit(fn) |
357 itm = QListWidgetItem(txt) |
366 itm = QListWidgetItem(txt) |
358 itm.setToolTip(fn) |
367 itm.setToolTip(fn) |
359 self.viewlist.addItem(itm) |
368 self.viewlist.addItem(itm) |
360 self.currentStack.addWidget(win) |
369 self.currentStack.addWidget(win) |
361 self.currentStack.setCurrentWidget(win) |
370 self.currentStack.setCurrentWidget(win) |
362 win.captionChanged.connect(self.__captionChange) |
371 editor.captionChanged.connect(self.__captionChange) |
363 |
372 |
364 index = self.editors.index(win) |
373 index = self.editors.index(editor) |
365 self.viewlist.setCurrentRow(index) |
374 self.viewlist.setCurrentRow(index) |
366 editor.setFocus() |
375 editor.setFocus() |
367 if fn: |
376 if fn: |
368 self.changeCaption.emit(fn) |
377 self.changeCaption.emit(fn) |
369 self.editorChanged.emit(fn) |
378 self.editorChanged.emit(fn) |
385 |
394 |
386 def _showView(self, win, fn=None): |
395 def _showView(self, win, fn=None): |
387 """ |
396 """ |
388 Protected method to show a view (i.e. window) |
397 Protected method to show a view (i.e. window) |
389 |
398 |
390 @param win editor window to be shown |
399 @param win editor assembly to be shown |
391 @param fn filename of this editor (string) |
400 @param fn filename of this editor (string) |
392 """ |
401 """ |
|
402 editor = win.getEditor() |
393 for stack in self.stacks: |
403 for stack in self.stacks: |
394 if stack.hasEditor(win): |
404 if stack.hasEditor(editor): |
395 stack.setCurrentWidget(win) |
405 stack.setCurrentWidget(win) |
396 self.currentStack = stack |
406 self.currentStack = stack |
397 break |
407 break |
398 index = self.editors.index(win) |
408 index = self.editors.index(editor) |
399 self.viewlist.setCurrentRow(index) |
409 self.viewlist.setCurrentRow(index) |
400 win.setFocus() |
410 editor.setFocus() |
401 fn = win.getFileName() |
411 fn = editor.getFileName() |
402 if fn: |
412 if fn: |
403 self.changeCaption.emit(fn) |
413 self.changeCaption.emit(fn) |
404 self.editorChanged.emit(fn) |
414 self.editorChanged.emit(fn) |
405 else: |
415 else: |
406 self.changeCaption.emit("") |
416 self.changeCaption.emit("") |
407 |
417 |
408 def __showSelectedView(self, itm): |
418 def __showSelectedView(self, row): |
409 """ |
419 """ |
410 Private slot called to show a view selected in the list by a mouse click. |
420 Private slot called to show a view selected in the list. |
411 |
421 |
412 @param itm item clicked on (QListWidgetItem) |
422 @param row row number of the item clicked on (integer) |
413 """ |
423 """ |
414 if itm: |
424 if row != -1: |
415 row = self.viewlist.row(itm) |
425 self._showView(self.editors[row].parent()) |
416 self._showView(self.editors[row]) |
|
417 self._checkActions(self.editors[row]) |
426 self._checkActions(self.editors[row]) |
418 |
427 |
419 def activeWindow(self): |
428 def activeWindow(self): |
420 """ |
429 """ |
421 Public method to return the active (i.e. current) window. |
430 Public method to return the active (i.e. current) window. |
597 """ |
606 """ |
598 Private method to close the selected editor. |
607 Private method to close the selected editor. |
599 """ |
608 """ |
600 if self.contextMenuEditor: |
609 if self.contextMenuEditor: |
601 self.closeEditorWindow(self.contextMenuEditor) |
610 self.closeEditorWindow(self.contextMenuEditor) |
|
611 |
|
612 def __contextMenuCloseOthers(self): |
|
613 """ |
|
614 Private method to close the other editors. |
|
615 """ |
|
616 index = self.contextMenuIndex |
|
617 for i in list(range(self.viewlist.count() - 1, index, -1)) + \ |
|
618 list(range(index - 1, -1, -1)): |
|
619 editor = self.editors[i] |
|
620 self.closeEditorWindow(editor) |
602 |
621 |
603 def __contextMenuCloseAll(self): |
622 def __contextMenuCloseAll(self): |
604 """ |
623 """ |
605 Private method to close all editors. |
624 Private method to close all editors. |
606 """ |
625 """ |