Ejemplo n.º 1
0
KTextEditor::Editor* PartController::editorPart() const
{
    if (!d->m_textEditor)
    {
        KTextEditor::Factory * editorFactory = qobject_cast<KTextEditor::Factory*>(findPartFactory(
            "text/plain",
            "KTextEditor/Document",
            "KTextEditor::Editor" ));

        if (!editorFactory) {
            KMessageBox::error(qApp->activeWindow(),
                               i18n("Could not find KTextEditor::Factory, check your installation:\n"
                                    "Make sure that Kate is installed, KDEDIRS is set properly and that you ran kbuildsycoca4." ),
                               i18n("System Configuration Error"));
            qApp->quit();
            exit(EXIT_FAILURE);
            return 0;
        }

        d->m_textEditor = editorFactory->editor();
        qRegisterMetaType<KSharedConfig::Ptr>("KSharedConfig::Ptr");
        Q_ASSERT(ICore::self()->activeSession());
        d->m_textEditor->setProperty("sessionConfig", QVariant::fromValue(ICore::self()->activeSession()->config()));

        KTextEditor::ContainerInterface * iface = qobject_cast<KTextEditor::ContainerInterface *>( d->m_textEditor );
        if (iface) {
            iface->setContainer( const_cast<PartController*>(this) );
        } else {
            // the kpart does not support ContainerInterface.
        }
    }
    return d->m_textEditor;
}
KParts::Part* IPartController::createPart ( const QString& mimetype, const QString& prefName )
{
    static const char* const services[] =
    {
        // Disable read/write parts until we can support them
        /*"KParts/ReadWritePart",*/ "KParts/ReadOnlyPart"
    };

    static const char* const classNames[] =
    {
        /*"KParts::ReadWritePart",*/ "KParts::ReadOnlyPart"
    };

    KParts::Part* part = 0;
    for ( uint i = 0; i < 2; ++i )
    {
        KParts::Factory* editorFactory = findPartFactory( mimetype, QString::fromLatin1(services[ i ]), prefName );
        if ( editorFactory )
        {
            part = editorFactory->createPart( 0, this, classNames[ i ] );
            break;
        }
    }

    return part;
}
Ejemplo n.º 3
0
KParts::Part* PartController::createPart( const QString & mimeType,
        const QString & partType,
        const QString & className,
        const QString & preferredName )
{
    KPluginFactory * editorFactory = findPartFactory(
                                          mimeType,
                                          partType,
                                          preferredName );

    if ( !className.isEmpty() && editorFactory )
    {
        return editorFactory->create<KParts::Part>(
                   0,
                   this,
                   className.toLatin1() );
    }

    return 0;
}