9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 import os |
12 import os |
13 |
13 |
14 from PyQt5.QtCore import pyqtSignal, QSignalMapper, QTimer, \ |
14 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSignalMapper, QTimer, \ |
15 QFileInfo, QRegExp, Qt, QCoreApplication |
15 QFileInfo, QRegExp, Qt, QCoreApplication |
16 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap |
16 from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap |
17 from PyQt5.QtWidgets import QLineEdit, QToolBar, QWidgetAction, QDialog, \ |
17 from PyQt5.QtWidgets import QLineEdit, QToolBar, QWidgetAction, QDialog, \ |
18 QApplication, QMenu, QComboBox, QWidget |
18 QApplication, QMenu, QComboBox, QWidget |
19 from PyQt5.Qsci import QsciScintilla |
19 from PyQt5.Qsci import QsciScintilla |
381 @param win editor window to be removed |
381 @param win editor window to be removed |
382 @exception RuntimeError Not implemented |
382 @exception RuntimeError Not implemented |
383 """ |
383 """ |
384 raise RuntimeError('Not implemented') |
384 raise RuntimeError('Not implemented') |
385 |
385 |
386 def _addView(self, win, fn=None, noName="", addNext=False): |
386 def _addView(self, win, fn=None, noName="", addNext=False, indexes=None): |
387 """ |
387 """ |
388 Protected method to add a view (i.e. window). |
388 Protected method to add a view (i.e. window). |
389 |
389 |
390 @param win editor assembly to be added |
390 @param win editor assembly to be added |
|
391 @type EditorAssembly |
391 @param fn filename of this editor |
392 @param fn filename of this editor |
392 @param noName name to be used for an unnamed editor (string) |
393 @type str |
|
394 @param noName name to be used for an unnamed editor |
|
395 @type str |
393 @param addNext flag indicating to add the view next to the current |
396 @param addNext flag indicating to add the view next to the current |
394 view (bool) |
397 view |
|
398 @type bool |
|
399 @param indexes of the editor, first the split view index, second the |
|
400 index within the view |
|
401 @type tuple of two int |
395 @exception RuntimeError Not implemented |
402 @exception RuntimeError Not implemented |
396 """ |
403 """ |
397 raise RuntimeError('Not implemented') |
404 raise RuntimeError('Not implemented') |
398 |
405 |
399 def _showView(self, win, fn=None): |
406 def _showView(self, win, fn=None): |
469 """ |
476 """ |
470 Public method used to split the current view. |
477 Public method used to split the current view. |
471 """ |
478 """ |
472 pass |
479 pass |
473 |
480 |
474 def removeSplit(self): |
481 @pyqtSlot() |
475 """ |
482 def removeSplit(self, index=-1): |
476 Public method used to remove the current split view. |
483 """ |
477 |
484 Public method used to remove the current split view or a split view |
478 @return Flag indicating successful deletion |
485 by index. |
|
486 |
|
487 @param index index of the split to be removed (-1 means to |
|
488 delete the current split) |
|
489 @type int |
|
490 @return flag indicating successful deletion |
|
491 @rtype bool |
479 """ |
492 """ |
480 return False |
493 return False |
|
494 |
|
495 def splitCount(self): |
|
496 """ |
|
497 Public method to get the number of split views. |
|
498 |
|
499 @return number of split views |
|
500 @rtype int |
|
501 """ |
|
502 return 0 |
|
503 |
|
504 def setSplitCount(self, count): |
|
505 """ |
|
506 Public method to set the number of split views. |
|
507 |
|
508 @param count number of split views |
|
509 @type int |
|
510 """ |
|
511 pass |
481 |
512 |
482 def getSplitOrientation(self): |
513 def getSplitOrientation(self): |
483 """ |
514 """ |
484 Public method to get the orientation of the split view. |
515 Public method to get the orientation of the split view. |
485 |
516 |
4535 editor.refreshCoverageAnnotations() |
4566 editor.refreshCoverageAnnotations() |
4536 |
4567 |
4537 self.__setSbFile() |
4568 self.__setSbFile() |
4538 |
4569 |
4539 def openSourceFile(self, fn, lineno=-1, filetype="", |
4570 def openSourceFile(self, fn, lineno=-1, filetype="", |
4540 selStart=0, selEnd=0, pos=0, addNext=False): |
4571 selStart=0, selEnd=0, pos=0, addNext=False, |
|
4572 indexes=None): |
4541 """ |
4573 """ |
4542 Public slot to display a file in an editor. |
4574 Public slot to display a file in an editor. |
4543 |
4575 |
4544 @param fn name of file to be opened (string) |
4576 @param fn name of file to be opened |
4545 @param lineno line number to place the cursor at (integer) or |
4577 @type str |
4546 list of line numbers (list of integers) (cursor will be |
4578 @param lineno line number to place the cursor at or list of line |
4547 placed at the next line greater than the current one) |
4579 numbers (cursor will be placed at the next line greater than |
4548 @param filetype type of the source file (string) |
4580 the current one) |
4549 @param selStart start of an area to be selected (integer) |
4581 @type int or list of int |
4550 @param selEnd end of an area to be selected (integer) |
4582 @param filetype type of the source file |
4551 @param pos position within the line to place the cursor at (integer) |
4583 @type str |
|
4584 @param selStart start of an area to be selected |
|
4585 @type int |
|
4586 @param selEnd end of an area to be selected |
|
4587 @type int |
|
4588 @param pos position within the line to place the cursor at |
|
4589 @type int |
4552 @param addNext flag indicating to add the file next to the current |
4590 @param addNext flag indicating to add the file next to the current |
4553 editor (bool) |
4591 editor |
|
4592 @type bool |
|
4593 @param indexes of the editor, first the split view index, second the |
|
4594 index within the view |
|
4595 @type tuple of two int |
|
4596 @return reference to the opened editor |
|
4597 @rtype Editor |
4554 """ |
4598 """ |
4555 try: |
4599 try: |
4556 newWin, editor = self.getEditor(fn, filetype=filetype, |
4600 newWin, editor = self.getEditor(fn, filetype=filetype, |
4557 addNext=addNext) |
4601 addNext=addNext, indexes=indexes) |
4558 except (IOError, UnicodeDecodeError): |
4602 except (IOError, UnicodeDecodeError): |
4559 return |
4603 return |
4560 |
4604 |
4561 if newWin: |
4605 if newWin: |
4562 self._modificationStatusChanged(editor.isModified(), editor) |
4606 self._modificationStatusChanged(editor.isModified(), editor) |
4585 if selStart != selEnd: |
4629 if selStart != selEnd: |
4586 editor.setSelection(line - 1, selStart, line - 1, selEnd) |
4630 editor.setSelection(line - 1, selStart, line - 1, selEnd) |
4587 |
4631 |
4588 # insert filename into list of recently opened files |
4632 # insert filename into list of recently opened files |
4589 self.addToRecentList(fn) |
4633 self.addToRecentList(fn) |
|
4634 |
|
4635 return editor |
4590 |
4636 |
4591 def __connectEditor(self, editor): |
4637 def __connectEditor(self, editor): |
4592 """ |
4638 """ |
4593 Private method to establish all editor connections. |
4639 Private method to establish all editor connections. |
4594 |
4640 |
4621 |
4667 |
4622 editor.languageChanged.connect( |
4668 editor.languageChanged.connect( |
4623 lambda: self.editorLanguageChanged.emit(editor)) |
4669 lambda: self.editorLanguageChanged.emit(editor)) |
4624 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor)) |
4670 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor)) |
4625 |
4671 |
4626 def newEditorView(self, fn, caller, filetype=""): |
4672 def newEditorView(self, fn, caller, filetype="", indexes=None): |
4627 """ |
4673 """ |
4628 Public method to create a new editor displaying the given document. |
4674 Public method to create a new editor displaying the given document. |
4629 |
4675 |
4630 @param fn filename of this view |
4676 @param fn filename of this view |
|
4677 @type str |
4631 @param caller reference to the editor calling this method |
4678 @param caller reference to the editor calling this method |
4632 @param filetype type of the source file (string) |
4679 @type Editor |
|
4680 @param filetype type of the source file |
|
4681 @type str |
|
4682 @param indexes of the editor, first the split view index, second the |
|
4683 index within the view |
|
4684 @type tuple of two int |
|
4685 @return reference to the new editor object |
|
4686 @rtype Editor |
4633 """ |
4687 """ |
4634 editor, assembly = self.cloneEditor(caller, filetype, fn) |
4688 editor, assembly = self.cloneEditor(caller, filetype, fn) |
4635 |
4689 |
4636 self._addView(assembly, fn, caller.getNoName()) |
4690 self._addView(assembly, fn, caller.getNoName(), indexes=indexes) |
4637 self._modificationStatusChanged(editor.isModified(), editor) |
4691 self._modificationStatusChanged(editor.isModified(), editor) |
4638 self._checkActions(editor) |
4692 self._checkActions(editor) |
|
4693 |
|
4694 return editor |
4639 |
4695 |
4640 def cloneEditor(self, caller, filetype, fn): |
4696 def cloneEditor(self, caller, filetype, fn): |
4641 """ |
4697 """ |
4642 Public method to clone an editor displaying the given document. |
4698 Public method to clone an editor displaying the given document. |
4643 |
4699 |
4837 # only return names of existing files |
4893 # only return names of existing files |
4838 filenames.append(fn) |
4894 filenames.append(fn) |
4839 |
4895 |
4840 return filenames |
4896 return filenames |
4841 |
4897 |
4842 def getEditor(self, fn, filetype="", addNext=False): |
4898 def getEditor(self, fn, filetype="", addNext=False, indexes=None): |
4843 """ |
4899 """ |
4844 Public method to return the editor displaying the given file. |
4900 Public method to return the editor displaying the given file. |
4845 |
4901 |
4846 If there is no editor with the given file, a new editor window is |
4902 If there is no editor with the given file, a new editor window is |
4847 created. |
4903 created. |
4848 |
4904 |
4849 @param fn filename to look for |
4905 @param fn filename to look for |
4850 @param filetype type of the source file (string) |
4906 @type str |
|
4907 @param filetype type of the source file |
|
4908 @type str |
4851 @param addNext flag indicating that if a new editor needs to be |
4909 @param addNext flag indicating that if a new editor needs to be |
4852 created, it should be added next to the current editor (bool) |
4910 created, it should be added next to the current editor |
|
4911 @type bool |
|
4912 @param indexes of the editor, first the split view index, second the |
|
4913 index within the view |
|
4914 @type tuple of two int |
4853 @return tuple of two values giving a flag indicating a new window |
4915 @return tuple of two values giving a flag indicating a new window |
4854 creation and a reference to the editor displaying this file |
4916 creation and a reference to the editor displaying this file |
|
4917 @rtype tuple of (bool, Editor) |
4855 """ |
4918 """ |
4856 newWin = False |
4919 newWin = False |
4857 editor = self.activeWindow() |
4920 editor = self.activeWindow() |
4858 if editor is None or not Utilities.samepath(fn, editor.getFileName()): |
4921 if editor is None or not Utilities.samepath(fn, editor.getFileName()): |
4859 for editor in self.editors: |
4922 for editor in self.editors: |
4871 self.editorOpened.emit(fn) |
4934 self.editorOpened.emit(fn) |
4872 self.editorOpenedEd.emit(editor) |
4935 self.editorOpenedEd.emit(editor) |
4873 newWin = True |
4936 newWin = True |
4874 |
4937 |
4875 if newWin: |
4938 if newWin: |
4876 self._addView(assembly, fn, addNext=addNext) |
4939 self._addView(assembly, fn, addNext=addNext, indexes=indexes) |
4877 else: |
4940 else: |
4878 self._showView(editor.parent(), fn) |
4941 self._showView(editor.parent(), fn) |
4879 |
4942 |
4880 return (newWin, editor) |
4943 return (newWin, editor) |
4881 |
4944 |
4920 count = 0 |
4983 count = 0 |
4921 for editor in self.editors: |
4984 for editor in self.editors: |
4922 if Utilities.samepath(fn, editor.getFileName()): |
4985 if Utilities.samepath(fn, editor.getFileName()): |
4923 count += 1 |
4986 count += 1 |
4924 return count |
4987 return count |
|
4988 |
|
4989 def getOpenEditorsForSession(self): |
|
4990 """ |
|
4991 Public method to get a lists of all open editors. |
|
4992 |
|
4993 The returned list contains one list per split view. If the view manager |
|
4994 cannot split the view, only one list of editors is returned. |
|
4995 |
|
4996 Note: This method should be implemented by subclasses. |
|
4997 |
|
4998 @return list of list of editor references |
|
4999 @rtype list of list of Editor |
|
5000 """ |
|
5001 return [self.editors] |
4925 |
5002 |
4926 def getActiveName(self): |
5003 def getActiveName(self): |
4927 """ |
5004 """ |
4928 Public method to retrieve the filename of the active window. |
5005 Public method to retrieve the filename of the active window. |
4929 |
5006 |