| 34 | //TODO: Make the widget transparent |
| 35 | |
| 36 | DocumentSwitcherPlugin::DocumentSwitcherPlugin(QObject* parent, const KPluginMetaData& metaData, |
| 37 | const QVariantList& /*args*/) |
| 38 | : KDevelop::IPlugin(QStringLiteral("kdevdocumentswitcher"), parent, metaData) |
| 39 | , view(nullptr) |
| 40 | { |
| 41 | setXMLFile(QStringLiteral("kdevdocumentswitcher.rc")); |
| 42 | qCDebug(PLUGIN_DOCUMENTSWITCHER) << "Adding active mainwindow from constructor"; |
| 43 | |
| 44 | KDevelop::IDocumentController *documentController = KDevelop::ICore::self()->documentController(); |
| 45 | for (KDevelop::IDocument *doc : documentController->openDocuments()) { |
| 46 | documentOpened(doc); |
| 47 | } |
| 48 | |
| 49 | // Signals to track last used documents. |
| 50 | connect(documentController, &KDevelop::IDocumentController::documentOpened, this, &DocumentSwitcherPlugin::documentOpened); |
| 51 | connect(documentController, &KDevelop::IDocumentController::documentActivated, this, &DocumentSwitcherPlugin::documentActivated); |
| 52 | connect(documentController, &KDevelop::IDocumentController::documentClosed, this, &DocumentSwitcherPlugin::documentClosed); |
| 53 | |
| 54 | #ifdef Q_OS_MACOS |
| 55 | // Qt/Mac swaps the Ctrl and Meta (Command) keys by default, so that shortcuts defined as Ctrl+X |
| 56 | // become the platform-standard Command+X . Ideally we would map the document switcher shortcut to |
| 57 | // Control+Tab (and thus Qt::META|Qt::Key_Tab) everywhere because Command+Tab and Command+Shift+Tab |
| 58 | // are reserved system shortcuts that bring up the application switcher. The Control+Tab shortcut is |
| 59 | // inoperable on Mac, so we resort to the Alt (Option) key, unless the AA_MacDontSwapCtrlAndMeta |
| 60 | // attribute is set. |
| 61 | const Qt::Modifier shortcutAccelerator = QCoreApplication::testAttribute(Qt::AA_MacDontSwapCtrlAndMeta) ? Qt::CTRL : Qt::ALT; |
| 62 | #else |
| 63 | const Qt::Modifier shortcutAccelerator = Qt::CTRL; |
| 64 | #endif |
| 65 | |
| 66 | forwardAction = actionCollection()->addAction ( QStringLiteral( "last_used_views_forward" ) ); |
| 67 | forwardAction->setText(i18nc("@action", "Last Used Views")); |
| 68 | forwardAction->setIcon( QIcon::fromTheme( QStringLiteral( "go-next-view-page") ) ); |
| 69 | actionCollection()->setDefaultShortcut( forwardAction, shortcutAccelerator | Qt::Key_Tab ); |
| 70 | forwardAction->setWhatsThis(i18nc("@info:whatsthis", "Opens a list to walk through the list of last used views.")); |
| 71 | forwardAction->setToolTip( i18nc("@info:tooltip", "Walk through the list of last used views")); |
| 72 | connect( forwardAction, &QAction::triggered, this, &DocumentSwitcherPlugin::walkForward ); |
| 73 | |
| 74 | backwardAction = actionCollection()->addAction ( QStringLiteral( "last_used_views_backward" ) ); |
| 75 | backwardAction->setText(i18nc("@action", "Last Used Views (Reverse)")); |
| 76 | backwardAction->setIcon( QIcon::fromTheme( QStringLiteral( "go-previous-view-page") ) ); |
| 77 | actionCollection()->setDefaultShortcut( backwardAction, shortcutAccelerator | Qt::SHIFT | Qt::Key_Tab ); |
| 78 | backwardAction->setWhatsThis(i18nc("@info:whatsthis", "Opens a list to walk through the list of last used views in reverse.")); |
| 79 | backwardAction->setToolTip(i18nc("@info:tooltip", "Walk through the list of last used views")); |
| 80 | connect( backwardAction, &QAction::triggered, this, &DocumentSwitcherPlugin::walkBackward ); |
| 81 | |
| 82 | view = new DocumentSwitcherTreeView( this ); |
| 83 | view->setSelectionBehavior( QAbstractItemView::SelectRows ); |
| 84 | view->setSelectionMode( QAbstractItemView::SingleSelection ); |
| 85 | view->setUniformRowHeights( true ); |
| 86 | view->setTextElideMode( Qt::ElideMiddle ); |
| 87 | view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
| 88 | view->addAction( forwardAction ); |
| 89 | view->addAction( backwardAction ); |
| 90 | view->setHeaderHidden( true ); |
| 91 | view->setIndentation( 10 ); |
| 92 | connect( view, &QListView::pressed, this, &DocumentSwitcherPlugin::switchToClicked ); |
| 93 | connect( view, &QListView::activated, this, &DocumentSwitcherPlugin::itemActivated ); |
nothing calls this directly
no test coverage detected