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 |