File indexing completed on 2024-05-19 08:30:31
0001 /* 0002 SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "kdevdocumentviewplugin.h" 0008 #include "kdevdocumentview.h" 0009 #include "kdevdocumentmodel.h" 0010 #include "kdevdocumentselection.h" 0011 0012 #include <KLocalizedString> 0013 #include <KPluginFactory> 0014 0015 #include <interfaces/icore.h> 0016 #include <interfaces/iuicontroller.h> 0017 #include <interfaces/idocumentcontroller.h> 0018 0019 using namespace KDevelop; 0020 0021 K_PLUGIN_FACTORY_WITH_JSON(KDevDocumentViewFactory, "kdevdocumentview.json", registerPlugin<KDevDocumentViewPlugin>();) 0022 0023 class KDevDocumentViewPluginFactory: public KDevelop::IToolViewFactory 0024 { 0025 public: 0026 explicit KDevDocumentViewPluginFactory( KDevDocumentViewPlugin *plugin ): m_plugin( plugin ) 0027 {} 0028 QWidget* create( QWidget *parent = nullptr ) override 0029 { 0030 auto* view = new KDevDocumentView( m_plugin, parent ); 0031 KDevelop::IDocumentController* docController = m_plugin->core()->documentController(); 0032 const auto openDocuments = docController->openDocuments(); 0033 for (KDevelop::IDocument* doc : openDocuments) { 0034 view->opened( doc ); 0035 } 0036 QObject::connect( docController, &IDocumentController::documentActivated, 0037 view, &KDevDocumentView::activated ); 0038 QObject::connect( docController, &IDocumentController::documentSaved, 0039 view, &KDevDocumentView::saved ); 0040 QObject::connect( docController, &IDocumentController::documentOpened, 0041 view, &KDevDocumentView::opened ); 0042 QObject::connect( docController, &IDocumentController::documentClosed, 0043 view, &KDevDocumentView::closed ); 0044 QObject::connect( docController, 0045 &IDocumentController::documentContentChanged, 0046 view, &KDevDocumentView::contentChanged ); 0047 QObject::connect( docController, 0048 &IDocumentController::documentStateChanged, 0049 view, &KDevDocumentView::stateChanged ); 0050 QObject::connect( docController, 0051 &IDocumentController::documentUrlChanged, 0052 view, &KDevDocumentView::documentUrlChanged ); 0053 return view; 0054 } 0055 Qt::DockWidgetArea defaultPosition() const override 0056 { 0057 return Qt::LeftDockWidgetArea; 0058 } 0059 0060 QString id() const override 0061 { 0062 return QStringLiteral("org.kdevelop.DocumentsView"); 0063 } 0064 0065 private: 0066 KDevDocumentViewPlugin* m_plugin; 0067 }; 0068 0069 0070 KDevDocumentViewPlugin::KDevDocumentViewPlugin( QObject *parent, const QVariantList& args ) 0071 : KDevelop::IPlugin( QStringLiteral( "kdevdocumentview" ), parent ) 0072 { 0073 Q_UNUSED( args ); 0074 0075 factory = new KDevDocumentViewPluginFactory( this ); 0076 0077 core()->uiController()->addToolView(i18nc("@title:window", "Documents"), factory); 0078 0079 setXMLFile( QStringLiteral( "kdevdocumentview.rc" ) ); 0080 } 0081 0082 KDevDocumentViewPlugin::~KDevDocumentViewPlugin() 0083 { 0084 } 0085 0086 void KDevDocumentViewPlugin::unload() 0087 { 0088 core()->uiController()->removeToolView( factory ); 0089 } 0090 0091 #include "kdevdocumentviewplugin.moc" 0092 #include "moc_kdevdocumentviewplugin.cpp"