File indexing completed on 2024-04-28 05:49:08

0001 /*  This file is part of the Kate project.
0002  *
0003  *  SPDX-FileCopyrightText: 2010 Christoph Cullmann <cullmann@kde.org>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #pragma once
0009 
0010 #include <QKeyEvent>
0011 #include <QVBoxLayout>
0012 
0013 #include <kparts/readonlypart.h>
0014 
0015 #include <QPointer>
0016 #include <QWidget>
0017 
0018 class KateProjectPluginView;
0019 class KPluginFactory;
0020 
0021 /**
0022  * Single terminal view for project toolview
0023  */
0024 class KateProjectInfoViewTerminal : public QWidget
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     /**
0030      * construct project info view for given project
0031      * @param pluginView our plugin view
0032      * @param directory base directory for this terminal view
0033      */
0034     KateProjectInfoViewTerminal(KateProjectPluginView *pluginView, const QString &directory);
0035 
0036     /**
0037      * deconstruct info view
0038      */
0039     ~KateProjectInfoViewTerminal() override;
0040 
0041     /**
0042      * Shall the ESC key press be ignored?
0043      * If not, the toolview will be hidden.
0044      * @return ignore ESC shortcut?
0045      */
0046     bool ignoreEsc() const;
0047 
0048     /**
0049      * Check if terminal is loadable
0050      */
0051     static bool isLoadable();
0052 
0053     void respawn(const QString &dirPath);
0054 
0055     bool eventFilter(QObject *o, QEvent *e) override;
0056 
0057     void runCommand(const QString &workingDir, const QString &cmd);
0058 
0059 private Q_SLOTS:
0060     /**
0061      * Construct a new terminal for this view
0062      */
0063     void loadTerminal();
0064 
0065     /**
0066      * Handle that shortcuts are not eaten by console
0067      */
0068     void overrideShortcut(QKeyEvent *event, bool &override);
0069 
0070 protected:
0071     /**
0072      * the konsole get shown
0073      * @param ev show event
0074      */
0075     void showEvent(QShowEvent *ev) override;
0076 
0077 private:
0078     /**
0079      * global plugin factory to create terminal
0080      * exposed to allow to skip terminal toolview creation if not possible
0081      * @return plugin factory for terminal or nullptr if no terminal part there
0082      */
0083     static KPluginFactory *pluginFactory();
0084 
0085     bool hasKonsole() const
0086     {
0087         return pluginFactory() != nullptr;
0088     }
0089 
0090 private:
0091     /**
0092      * plugin factory for the terminal
0093      */
0094     static KPluginFactory *s_pluginFactory;
0095 
0096     /**
0097      * our plugin view
0098      */
0099     KateProjectPluginView *const m_pluginView;
0100 
0101     /**
0102      * our start directory for the terminal
0103      */
0104     QString m_directory;
0105 
0106     /**
0107      * our layout
0108      */
0109     QVBoxLayout *m_layout;
0110 
0111     /**
0112      * konsole part
0113      */
0114     KParts::ReadOnlyPart *m_konsolePart = nullptr;
0115 
0116     QPointer<QAction> m_showProjectInfoViewAction;
0117 };