def action_open(self): """This menu action opens the standard model open dialog.""" filters = [ { "name": _("Gaphor Models"), "pattern": "*.gaphor" }, { "name": _("All Files"), "pattern": "*" }, ] file_dialog = FileDialog(_("Open Gaphor Model"), filters=filters) filename = file_dialog.selection file_dialog.destroy() log.debug(filename) if filename: self.load(filename) self.event_manager.handle(FilenameChanged(self, filename))
def action_new_from_template(self): """This menu action opens the new model from template dialog.""" filters = [ { "name": _("Gaphor Models"), "pattern": "*.gaphor" }, { "name": _("All Files"), "pattern": "*" }, ] file_dialog = FileDialog(_("New Gaphor Model From Template"), filters=filters) filename = file_dialog.selection file_dialog.destroy() log.debug(filename) if filename: self.load(filename) self.filename = None self.event_manager.handle(FilenameChanged(self))
def load_recent(self, action, index): """Load the recent file at the specified index. This will trigger a FilenameChanged event. The recent files are stored in the recent_files property.""" filename = self.recent_files[index] self.load(filename) self.event_manager.handle(FilenameChanged(self, filename))
def action_save(self): """ Save the file. Depending on if there is a file name, either perform the save directly or present the user with a save dialog box. Returns True if the saving actually succeeded. """ filename = self.filename if filename: self.save(filename) self.event_manager.handle(FilenameChanged(self, filename)) return True else: return self.action_save_as()
def action_save_as(self): """ Save the model in the element_factory by allowing the user to select a file name. Returns True if the saving actually happened. """ file_dialog = FileDialog(_("Save Gaphor Model As"), action="save", filename=self.filename) filename = file_dialog.selection file_dialog.destroy() if filename: self.save(filename) self.event_manager.handle(FilenameChanged(self, filename)) return True return False
def action_new(self): """The new model menu action. This action will create a new UML model. This will trigger a FileManagerStateChange event.""" element_factory = self.element_factory main_window = self.main_window if element_factory.size(): dialog = QuestionDialog( _( "Opening a new model will flush the" " currently loaded model.\nAny changes" " made will not be saved. Do you want to" " continue?" ), parent=main_window.window, ) answer = dialog.answer dialog.destroy() if not answer: return element_factory.flush() with element_factory.block_events(): model = element_factory.create(UML.Package) model.name = _("New model") diagram = element_factory.create(UML.Diagram) diagram.package = model diagram.name = _("main") self.filename = None element_factory.notify_model() # main_window.select_element(diagram) # main_window.show_diagram(diagram) self.event_manager.handle(FilenameChanged(self))