ViewManager/ViewManager.py

changeset 6052
8b49d3e0b4c8
parent 6048
82ad8ec9548c
child 6053
c2d1566692d3
equal deleted inserted replaced
6051:6e09a9a73cb7 6052:8b49d3e0b4c8
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 def removeSplit(self, index=-1):
475 """ 482 """
476 Public method used to remove the current split view. 483 Public method used to remove the current split view or a split view
477 484 by index.
478 @return Flag indicating successful deletion 485
486 @param index index of the split to be removed (-1 means to
487 delete the current split)
488 @type int
489 @return flag indicating successful deletion
490 @rtype bool
479 """ 491 """
480 return False 492 return False
493
494 def splitCount(self):
495 """
496 Public method to get the number of split views.
497
498 @return number of split views
499 @rtype int
500 """
501 return 0
502
503 def setSplitCount(self, count):
504 """
505 Public method to set the number of split views.
506
507 @param count number of split views
508 @type int
509 """
510 pass
481 511
482 def getSplitOrientation(self): 512 def getSplitOrientation(self):
483 """ 513 """
484 Public method to get the orientation of the split view. 514 Public method to get the orientation of the split view.
485 515
4533 editor.refreshCoverageAnnotations() 4563 editor.refreshCoverageAnnotations()
4534 4564
4535 self.__setSbFile() 4565 self.__setSbFile()
4536 4566
4537 def openSourceFile(self, fn, lineno=-1, filetype="", 4567 def openSourceFile(self, fn, lineno=-1, filetype="",
4538 selStart=0, selEnd=0, pos=0, addNext=False): 4568 selStart=0, selEnd=0, pos=0, addNext=False,
4569 indexes=None):
4539 """ 4570 """
4540 Public slot to display a file in an editor. 4571 Public slot to display a file in an editor.
4541 4572
4542 @param fn name of file to be opened (string) 4573 @param fn name of file to be opened
4543 @param lineno line number to place the cursor at (integer) or 4574 @type str
4544 list of line numbers (list of integers) (cursor will be 4575 @param lineno line number to place the cursor at or list of line
4545 placed at the next line greater than the current one) 4576 numbers (cursor will be placed at the next line greater than
4546 @param filetype type of the source file (string) 4577 the current one)
4547 @param selStart start of an area to be selected (integer) 4578 @type int or list of int
4548 @param selEnd end of an area to be selected (integer) 4579 @param filetype type of the source file
4549 @param pos position within the line to place the cursor at (integer) 4580 @type str
4581 @param selStart start of an area to be selected
4582 @type int
4583 @param selEnd end of an area to be selected
4584 @type int
4585 @param pos position within the line to place the cursor at
4586 @type int
4550 @param addNext flag indicating to add the file next to the current 4587 @param addNext flag indicating to add the file next to the current
4551 editor (bool) 4588 editor
4589 @type bool
4590 @param indexes of the editor, first the split view index, second the
4591 index within the view
4592 @type tuple of two int
4593 @return reference to the opened editor
4594 @rtype Editor
4552 """ 4595 """
4553 try: 4596 try:
4554 newWin, editor = self.getEditor(fn, filetype=filetype, 4597 newWin, editor = self.getEditor(fn, filetype=filetype,
4555 addNext=addNext) 4598 addNext=addNext, indexes=indexes)
4556 except (IOError, UnicodeDecodeError): 4599 except (IOError, UnicodeDecodeError):
4557 return 4600 return
4558 4601
4559 if newWin: 4602 if newWin:
4560 self._modificationStatusChanged(editor.isModified(), editor) 4603 self._modificationStatusChanged(editor.isModified(), editor)
4583 if selStart != selEnd: 4626 if selStart != selEnd:
4584 editor.setSelection(line - 1, selStart, line - 1, selEnd) 4627 editor.setSelection(line - 1, selStart, line - 1, selEnd)
4585 4628
4586 # insert filename into list of recently opened files 4629 # insert filename into list of recently opened files
4587 self.addToRecentList(fn) 4630 self.addToRecentList(fn)
4631
4632 return editor
4588 4633
4589 def __connectEditor(self, editor): 4634 def __connectEditor(self, editor):
4590 """ 4635 """
4591 Private method to establish all editor connections. 4636 Private method to establish all editor connections.
4592 4637
4619 4664
4620 editor.languageChanged.connect( 4665 editor.languageChanged.connect(
4621 lambda: self.editorLanguageChanged.emit(editor)) 4666 lambda: self.editorLanguageChanged.emit(editor))
4622 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor)) 4667 editor.textChanged.connect(lambda: self.editorTextChanged.emit(editor))
4623 4668
4624 def newEditorView(self, fn, caller, filetype=""): 4669 def newEditorView(self, fn, caller, filetype="", indexes=None):
4625 """ 4670 """
4626 Public method to create a new editor displaying the given document. 4671 Public method to create a new editor displaying the given document.
4627 4672
4628 @param fn filename of this view 4673 @param fn filename of this view
4674 @type str
4629 @param caller reference to the editor calling this method 4675 @param caller reference to the editor calling this method
4630 @param filetype type of the source file (string) 4676 @type Editor
4677 @param filetype type of the source file
4678 @type str
4679 @param indexes of the editor, first the split view index, second the
4680 index within the view
4681 @type tuple of two int
4682 @return reference to the new editor object
4683 @rtype Editor
4631 """ 4684 """
4632 editor, assembly = self.cloneEditor(caller, filetype, fn) 4685 editor, assembly = self.cloneEditor(caller, filetype, fn)
4633 4686
4634 self._addView(assembly, fn, caller.getNoName()) 4687 self._addView(assembly, fn, caller.getNoName(), indexes=indexes)
4635 self._modificationStatusChanged(editor.isModified(), editor) 4688 self._modificationStatusChanged(editor.isModified(), editor)
4636 self._checkActions(editor) 4689 self._checkActions(editor)
4690
4691 return editor
4637 4692
4638 def cloneEditor(self, caller, filetype, fn): 4693 def cloneEditor(self, caller, filetype, fn):
4639 """ 4694 """
4640 Public method to clone an editor displaying the given document. 4695 Public method to clone an editor displaying the given document.
4641 4696
4835 # only return names of existing files 4890 # only return names of existing files
4836 filenames.append(fn) 4891 filenames.append(fn)
4837 4892
4838 return filenames 4893 return filenames
4839 4894
4840 def getEditor(self, fn, filetype="", addNext=False): 4895 def getEditor(self, fn, filetype="", addNext=False, indexes=None):
4841 """ 4896 """
4842 Public method to return the editor displaying the given file. 4897 Public method to return the editor displaying the given file.
4843 4898
4844 If there is no editor with the given file, a new editor window is 4899 If there is no editor with the given file, a new editor window is
4845 created. 4900 created.
4846 4901
4847 @param fn filename to look for 4902 @param fn filename to look for
4848 @param filetype type of the source file (string) 4903 @type str
4904 @param filetype type of the source file
4905 @type str
4849 @param addNext flag indicating that if a new editor needs to be 4906 @param addNext flag indicating that if a new editor needs to be
4850 created, it should be added next to the current editor (bool) 4907 created, it should be added next to the current editor
4908 @type bool
4909 @param indexes of the editor, first the split view index, second the
4910 index within the view
4911 @type tuple of two int
4851 @return tuple of two values giving a flag indicating a new window 4912 @return tuple of two values giving a flag indicating a new window
4852 creation and a reference to the editor displaying this file 4913 creation and a reference to the editor displaying this file
4914 @rtype tuple of (bool, Editor)
4853 """ 4915 """
4854 newWin = False 4916 newWin = False
4855 editor = self.activeWindow() 4917 editor = self.activeWindow()
4856 if editor is None or not Utilities.samepath(fn, editor.getFileName()): 4918 if editor is None or not Utilities.samepath(fn, editor.getFileName()):
4857 for editor in self.editors: 4919 for editor in self.editors:
4869 self.editorOpened.emit(fn) 4931 self.editorOpened.emit(fn)
4870 self.editorOpenedEd.emit(editor) 4932 self.editorOpenedEd.emit(editor)
4871 newWin = True 4933 newWin = True
4872 4934
4873 if newWin: 4935 if newWin:
4874 self._addView(assembly, fn, addNext=addNext) 4936 self._addView(assembly, fn, addNext=addNext, indexes=indexes)
4875 else: 4937 else:
4876 self._showView(editor.parent(), fn) 4938 self._showView(editor.parent(), fn)
4877 4939
4878 return (newWin, editor) 4940 return (newWin, editor)
4879 4941
4918 count = 0 4980 count = 0
4919 for editor in self.editors: 4981 for editor in self.editors:
4920 if Utilities.samepath(fn, editor.getFileName()): 4982 if Utilities.samepath(fn, editor.getFileName()):
4921 count += 1 4983 count += 1
4922 return count 4984 return count
4985
4986 def getOpenEditorsForSession(self):
4987 """
4988 Public method to get a lists of all open editors.
4989
4990 The returned list contains one list per split view. If the view manager
4991 cannot split the view, only one list of editors is returned.
4992
4993 Note: This method should be implemented by subclasses.
4994
4995 @return list of list of editor references
4996 @rtype list of list of Editor
4997 """
4998 return [self.editors]
4923 4999
4924 def getActiveName(self): 5000 def getActiveName(self):
4925 """ 5001 """
4926 Public method to retrieve the filename of the active window. 5002 Public method to retrieve the filename of the active window.
4927 5003

eric ide

mercurial