Пример #1
0
    def offer_single_export(self, rec, prefs, mult=1, parent=None):
        """Offer to export a single file.

        Return the filename if we have in fact exported said file.
        """
        default_extension = prefs.get('save_recipe_as', 'html')
        # strip the period if one ended up on our default extension
        if default_extension and default_extension[0] == '.':
            default_extension = default_extension[1:]
        exp_directory = prefs.get(
            'rec_exp_directory',
            get_user_special_dir(USER_DIRECTORY_DOCUMENTS))
        filename, exp_type = de.saveas_file(
            _('Save recipe as...'),
            filename='%s%s%s%s%s' % (exp_directory, os.path.sep, rec.title,
                                     os.path.extsep, default_extension),
            filters=self.get_single_filters(),
            parent=parent)
        if not filename: return
        if not exp_type or not self.can_export_type(exp_type):
            de.show_message(
                label=_('Gourmet cannot export file of type "%s"') %
                os.path.splitext(filename)[1])
            return
        return self.do_single_export(rec, filename, exp_type, mult)
Пример #2
0
    def offer_multiple_export(self,
                              recs,
                              prefs,
                              parent=None,
                              prog=None,
                              export_all=False):
        """Offer user a chance to export multiple recipes at once.

        Return the exporter class capable of doing this and a
        dictionary of arguments for the progress dialog.
        """
        if (not export_all) or (len(recs) < 950):
            # inelegantly avoid bug that happens when this code runs
            # on large numbers of recipes. The good news is that this
            # that that will almost only ever happen when we're
            # exporting all recipes, which makes this code irrelevant
            # anyway.
            self.app.rd.include_linked_recipes(recs)
        ext = prefs.get('save_recipes_as', '%sxml' % os.path.extsep)
        exp_directory = prefs.get(
            'rec_exp_directory',
            get_user_special_dir(USER_DIRECTORY_DOCUMENTS))
        fn, exp_type = de.saveas_file(
            _("Export recipes"),
            filename="%s%s%s%s" %
            (exp_directory, os.path.sep, _('recipes'), ext),
            parent=parent,
            filters=self.get_multiple_filters())
        if fn:
            prefs['rec_exp_directory'] = os.path.split(fn)[0]
            prefs['save_recipes_as'] = os.path.splitext(fn)[1]
            instance = self.do_multiple_export(recs, fn, exp_type)
            if not instance:
                de.show_message(
                    okay=Gtk.STOCK_CLOSE,
                    cancel=False,
                    label=_('Unable to export: unknown filetype "%s"' % fn),
                    sublabel=
                    _('Please make sure to select a filetype from the dropdown menu when saving.'
                      ),
                    message_type=Gtk.MessageType.ERROR,
                )
                return
            return instance
Пример #3
0
    def get_new_file_name(self):
        lang = self.text_buffer.get_language()
        dialog = FileSaveDialog(self.__win)
        dialog.add_filter_rst(lang.get_id() == "rst")
        dialog.add_filter_md(lang.get_id() == "markdown")
        dialog.add_filter_html(lang.get_id() == "html")
        dialog.add_filter_json(lang.get_id() == "json")
        dialog.add_filter_plain(lang.get_id() == "text")
        dialog.set_do_overwrite_confirmation(True)

        if not self.__file_name:
            dialog.set_current_folder(
                get_user_special_dir(UserDirectory.DIRECTORY_DOCUMENTS))
            dialog.set_current_name("Untitled document")
        else:
            dialog.set_current_folder(dirname(self.file_path))
            dialog.set_current_name(self.file_name)

        file_name = ''
        if dialog.run() == Gtk.ResponseType.ACCEPT:
            file_name = dialog.get_filename_with_ext()
        dialog.destroy()
        return file_name