diff --git a/core/generator.cpp b/core/generator.cpp index d66302767..242ef2d60 100644 --- a/core/generator.cpp +++ b/core/generator.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "document.h" #include "generator.h" @@ -458,6 +459,11 @@ bool ExportFormat::isNull() const return d->mMimeType.isNull() || d->mDescription.isNull(); } +ExportFormat ExportFormat::plainText() +{ + return ExportFormat( KIcon( "text" ), i18n( "Plain &Text..." ), KMimeType::mimeType( "text/plain" ) ); +} + kdbgstream& operator<<( kdbgstream &str, const Okular::PixmapRequest &req ) { QString s = QString( "%1 PixmapRequest (id: %2) (%3x%4), prio %5, pageNo %6" ) diff --git a/core/generator.h b/core/generator.h index 03da07dca..e0a01492d 100644 --- a/core/generator.h +++ b/core/generator.h @@ -130,6 +130,11 @@ class OKULAR_EXPORT ExportFormat */ bool isNull() const; + /** + * Builds a standard format for exporting to plain text. + */ + static ExportFormat plainText(); + private: class Private; Private* const d; diff --git a/core/textdocumentgenerator.cpp b/core/textdocumentgenerator.cpp index 08d33a633..013af2cab 100644 --- a/core/textdocumentgenerator.cpp +++ b/core/textdocumentgenerator.cpp @@ -359,8 +359,8 @@ Okular::ExportFormat::List TextDocumentGenerator::exportFormats( ) const { static Okular::ExportFormat::List formats; if ( formats.isEmpty() ) { + formats.append( Okular::ExportFormat::plainText() ); formats.append( Okular::ExportFormat( i18n( "PDF" ), KMimeType::mimeType( "application/pdf" ) ) ); - formats.append( Okular::ExportFormat( i18n( "Plain Text" ), KMimeType::mimeType( "text/plain" ) ) ); } return formats; diff --git a/part.cpp b/part.cpp index 6c7619c0c..65e65329a 100644 --- a/part.cpp +++ b/part.cpp @@ -79,6 +79,16 @@ typedef KParts::GenericFactory okularPartFactory; K_EXPORT_COMPONENT_FACTORY(libokularpart, okularPartFactory) +static QAction* actionForExportFormat( const Okular::ExportFormat& format, QObject *parent = 0 ) +{ + QAction *act = new QAction( format.description(), parent ); + if ( !format.icon().isNull() ) + { + act->setIcon( format.icon() ); + } + return act; +} + Part::Part(QWidget *parentWidget, QObject *parent, const QStringList & /*args*/ ) @@ -377,7 +387,8 @@ m_searchStarted(false), m_cliPresentation(false) QMenu *menu = new QMenu(widget()); connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(slotExportAs(QAction *))); m_exportAs->setMenu( menu ); - m_exportAsText = menu->addAction( KIcon( "text" ), i18n( "Text..." ) ); + m_exportAsText = actionForExportFormat( Okular::ExportFormat::plainText(), menu ); + menu->addAction( m_exportAsText ); m_exportAsText->setEnabled( false ); m_aboutBackend = ac->addAction("help_about_backend"); @@ -665,15 +676,7 @@ bool Part::openFile() QMenu *menu = m_exportAs->menu(); for ( ; it != itEnd; ++it ) { - const Okular::ExportFormat &format = *it; - if ( !format.icon().isNull() ) - { - menu->addAction( format.icon(), format.description() ); - } - else - { - menu->addAction( format.description() ); - } + menu->addAction( actionForExportFormat( *it ) ); } } m_exportAsText->setEnabled( ok && m_document->canExportToText() );