def __init__(self, app, doc_file=''):
        self.app = app
        self.eventloop = EventLoop(self)
        self.doc_file = doc_file
        if doc_file:
            loader = get_loader(doc_file, True)
            if loader is None:
                raise IOError(_('Unknown file format'), doc_file)

            pd = ProgressDialog(_('Opening file...'), self.app.mw)
            ret = pd.run(loader, [app.appdata, doc_file, None, False])
            if ret == gtk.RESPONSE_OK:
                if pd.result is None:
                    pd.destroy()
                    raise IOError(*pd.error_info)

                self.doc_presenter = pd.result
                pd.destroy()
            else:
                pd.destroy()
                raise IOError(_('Error while opening'), doc_file)

            self.doc_file = self.doc_presenter.doc_file
            self.doc_name = os.path.basename(self.doc_file)
        else:
            #FIXME: Here should be new model creation
            self.doc_name = self.app.get_new_docname()

        self.doc_presenter.update(True)
        self.selection = ModelSelection(self)
        self.docarea = DocArea(self.app, self)
        self.app.mw.add_tab(self.docarea)
        self.selection.set_root()
    def save(self):
        try:
            if config.make_backup:
                if os.path.lexists(self.doc_file):
                    if os.path.lexists(self.doc_file + '~'):
                        os.remove(self.doc_file + '~')
                    os.rename(self.doc_file, self.doc_file + '~')
            saver = get_saver(self.doc_file, True)
            if saver is None:
                raise IOError(
                    _('Unknown file format is requested for saving!'),
                    self.doc_file)

            pd = ProgressDialog(_('Saving file...'), self.app.mw)
            ret = pd.run(saver, [self.doc_presenter, self.doc_file, False])
            if ret == gtk.RESPONSE_OK:
                if not pd.error_info is None:
                    pd.destroy()
                    raise IOError(*pd.error_info)
                pd.destroy()
            else:
                pd.destroy()
                raise IOError(_('Error while saving'), self.doc_file)

        except IOError:
            raise IOError(*sys.exc_info())
        self.reflect_saving()