ViewManager/ViewManager.py

branch
maintenance
changeset 6273
0daf79d65080
parent 6166
bace7fb85a01
parent 6247
5c677a7f7d51
child 6319
df201b9fbad4
equal deleted inserted replaced
6207:0a74c1efab70 6273:0daf79d65080
4417 # Open up the new files. 4417 # Open up the new files.
4418 self.openSourceFile(prog) 4418 self.openSourceFile(prog)
4419 4419
4420 def checkDirty(self, editor, autosave=False): 4420 def checkDirty(self, editor, autosave=False):
4421 """ 4421 """
4422 Public method to check dirty status and open a message window. 4422 Public method to check the dirty status and open a message window.
4423 4423
4424 @param editor editor window to check 4424 @param editor editor window to check
4425 @type Editor
4425 @param autosave flag indicating that the file should be saved 4426 @param autosave flag indicating that the file should be saved
4426 automatically (boolean) 4427 automatically
4427 @return flag indicating successful reset of the dirty flag (boolean) 4428 @type bool
4429 @return flag indicating successful reset of the dirty flag
4430 @rtype bool
4428 """ 4431 """
4429 if editor.isModified(): 4432 if editor.isModified():
4430 fn = editor.getFileName() 4433 fn = editor.getFileName()
4431 # ignore the dirty status, if there is more than one open editor 4434 # ignore the dirty status, if there is more than one open editor
4432 # for the same file 4435 # for the same file
4455 4458
4456 def checkAllDirty(self): 4459 def checkAllDirty(self):
4457 """ 4460 """
4458 Public method to check the dirty status of all editors. 4461 Public method to check the dirty status of all editors.
4459 4462
4460 @return flag indicating successful reset of all dirty flags (boolean) 4463 @return flag indicating successful reset of all dirty flags
4464 @rtype bool
4461 """ 4465 """
4462 for editor in self.editors: 4466 for editor in self.editors:
4463 if not self.checkDirty(editor): 4467 if not self.checkDirty(editor):
4464 return False 4468 return False
4465 4469
4466 return True 4470 return True
4467 4471
4468 def closeEditor(self, editor): 4472 def checkFileDirty(self, fn):
4469 """ 4473 """
4470 Public method to close an editor window. 4474 Public method to check the dirty status of an editor given its file
4471 4475 name and open a message window.
4472 @param editor editor window to be closed 4476
4473 @return flag indicating success (boolean) 4477 @param fn file name of editor to be checked
4474 """ 4478 @type str
4475 # save file if necessary 4479 @return flag indicating successful reset of the dirty flag
4476 if not self.checkDirty(editor): 4480 @rtype bool
4477 return False
4478
4479 # get the filename of the editor for later use
4480 fn = editor.getFileName()
4481
4482 # remove the window
4483 editor.parent().shutdownTimer()
4484 self._removeView(editor)
4485 self.editors.remove(editor)
4486
4487 # send a signal, if it was the last editor for this filename
4488 if fn and self.getOpenEditor(fn) is None:
4489 self.editorClosed.emit(fn)
4490 self.editorClosedEd.emit(editor)
4491
4492 # send a signal, if it was the very last editor
4493 if not len(self.editors):
4494 self.__lastEditorClosed()
4495 self.lastEditorClosed.emit()
4496
4497 editor.deleteLater()
4498
4499 return True
4500
4501 def closeCurrentWindow(self):
4502 """
4503 Public method to close the current window.
4504
4505 @return flag indicating success (boolean)
4506 """
4507 aw = self.activeWindow()
4508 if aw is None:
4509 return False
4510
4511 res = self.closeEditor(aw)
4512 if res and aw == self.currentEditor:
4513 self.currentEditor = None
4514
4515 return res
4516
4517 def closeAllWindows(self):
4518 """
4519 Public method to close all editor windows via file menu.
4520 """
4521 savedEditors = self.editors[:]
4522 for editor in savedEditors:
4523 self.closeEditor(editor)
4524
4525 def closeWindow(self, fn):
4526 """
4527 Public method to close an arbitrary source editor.
4528
4529 @param fn filename of editor to be closed
4530 @return flag indicating success (boolean)
4531 """ 4481 """
4532 for editor in self.editors: 4482 for editor in self.editors:
4533 if Utilities.samepath(fn, editor.getFileName()): 4483 if Utilities.samepath(fn, editor.getFileName()):
4534 break 4484 break
4535 else: 4485 else:
4536 return True 4486 return True
4537 4487
4538 res = self.closeEditor(editor) 4488 res = self.checkDirty(editor)
4489 return res
4490
4491 def closeEditor(self, editor, ignoreDirty=False):
4492 """
4493 Public method to close an editor window.
4494
4495 @param editor editor window to be closed
4496 @type Editor
4497 @param ignoreDirty flag indicating to ignore the 'dirty' status
4498 @type bool
4499 @return flag indicating success
4500 @rtype bool
4501 """
4502 # save file if necessary
4503 if not ignoreDirty and not self.checkDirty(editor):
4504 return False
4505
4506 # get the filename of the editor for later use
4507 fn = editor.getFileName()
4508
4509 # remove the window
4510 editor.parent().shutdownTimer()
4511 self._removeView(editor)
4512 self.editors.remove(editor)
4513
4514 # send a signal, if it was the last editor for this filename
4515 if fn and self.getOpenEditor(fn) is None:
4516 self.editorClosed.emit(fn)
4517 self.editorClosedEd.emit(editor)
4518
4519 # send a signal, if it was the very last editor
4520 if not len(self.editors):
4521 self.__lastEditorClosed()
4522 self.lastEditorClosed.emit()
4523
4524 editor.deleteLater()
4525
4526 return True
4527
4528 def closeCurrentWindow(self):
4529 """
4530 Public method to close the current window.
4531
4532 @return flag indicating success (boolean)
4533 """
4534 aw = self.activeWindow()
4535 if aw is None:
4536 return False
4537
4538 res = self.closeEditor(aw)
4539 if res and aw == self.currentEditor:
4540 self.currentEditor = None
4541
4542 return res
4543
4544 def closeAllWindows(self):
4545 """
4546 Public method to close all editor windows via file menu.
4547 """
4548 savedEditors = self.editors[:]
4549 for editor in savedEditors:
4550 self.closeEditor(editor)
4551
4552 def closeWindow(self, fn, ignoreDirty=False):
4553 """
4554 Public method to close an arbitrary source editor.
4555
4556 @param fn file name of the editor to be closed
4557 @type str
4558 @param ignoreDirty flag indicating to ignore the 'dirty' status
4559 @type bool
4560 @return flag indicating success
4561 @rtype bool
4562 """
4563 for editor in self.editors:
4564 if Utilities.samepath(fn, editor.getFileName()):
4565 break
4566 else:
4567 return True
4568
4569 res = self.closeEditor(editor, ignoreDirty=ignoreDirty)
4539 if res and editor == self.currentEditor: 4570 if res and editor == self.currentEditor:
4540 self.currentEditor = None 4571 self.currentEditor = None
4541 4572
4542 return res 4573 return res
4543 4574
4820 if encoding is None: 4851 if encoding is None:
4821 encoding = '' 4852 encoding = ''
4822 self.sbEnc.setText(encoding) 4853 self.sbEnc.setText(encoding)
4823 4854
4824 if language is None: 4855 if language is None:
4825 language = '' 4856 pixmap = QPixmap()
4826 import QScintilla.Lexers 4857 elif language == "":
4827 pixmap = QScintilla.Lexers.getLanguageIcon(language, True) 4858 pixmap = UI.PixmapCache.getPixmap("fileText.png")
4859 else:
4860 import QScintilla.Lexers
4861 pixmap = QScintilla.Lexers.getLanguageIcon(language, True)
4828 self.sbLang.setPixmap(pixmap) 4862 self.sbLang.setPixmap(pixmap)
4829 if pixmap.isNull(): 4863 if pixmap.isNull():
4830 self.sbLang.setText(language) 4864 self.sbLang.setText(language)
4831 self.sbLang.setToolTip("") 4865 self.sbLang.setToolTip("")
4832 else: 4866 else:
5794 return 5828 return
5795 5829
5796 line, index = aw.getCursorPosition() 5830 line, index = aw.getCursorPosition()
5797 text = aw.text(line) 5831 text = aw.text(line)
5798 5832
5799 reg = QRegExp('[^\w_]') 5833 reg = QRegExp(r'[^\w_]')
5800 end = reg.indexIn(text, index) 5834 end = reg.indexIn(text, index)
5801 if end > index: 5835 if end > index:
5802 ext = text[index:end] 5836 ext = text[index:end]
5803 txt += ext 5837 txt += ext
5804 self.quickFindtextCombo.lineEdit().setText(txt) 5838 self.quickFindtextCombo.lineEdit().setText(txt)
6997 @return name of the filename filter (string) or None 7031 @return name of the filename filter (string) or None
6998 """ 7032 """
6999 if self.activeWindow() is not None and \ 7033 if self.activeWindow() is not None and \
7000 self.activeWindow().getFileName(): 7034 self.activeWindow().getFileName():
7001 ext = os.path.splitext(self.activeWindow().getFileName())[1] 7035 ext = os.path.splitext(self.activeWindow().getFileName())[1]
7002 rx = QRegExp(".*\*\.{0}[ )].*".format(ext[1:])) 7036 rx = QRegExp(r".*\*\.{0}[ )].*".format(ext[1:]))
7003 import QScintilla.Lexers 7037 import QScintilla.Lexers
7004 filters = QScintilla.Lexers.getOpenFileFiltersList() 7038 filters = QScintilla.Lexers.getOpenFileFiltersList()
7005 index = -1 7039 index = -1
7006 for i in range(len(filters)): 7040 for i in range(len(filters)):
7007 if rx.exactMatch(filters[i]): 7041 if rx.exactMatch(filters[i]):

eric ide

mercurial