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

0001 /*  This file is part of the Kate project.
0002  *
0003  *  SPDX-FileCopyrightText: 2012 Christoph Cullmann <cullmann@kde.org>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #include "kateprojectinfoview.h"
0009 #include "kateproject.h"
0010 #include "kateprojectinfoviewcodeanalysis.h"
0011 #include "kateprojectinfoviewindex.h"
0012 #include "kateprojectinfoviewnotes.h"
0013 #include "kateprojectinfoviewterminal.h"
0014 #include "kateprojectpluginview.h"
0015 
0016 #include <KLocalizedString>
0017 
0018 #include <QFileInfo>
0019 
0020 KateProjectInfoView::KateProjectInfoView(KateProjectPluginView *pluginView, KateProject *project)
0021     : m_project(project)
0022     , m_terminal(nullptr)
0023 {
0024     setDocumentMode(true);
0025 
0026     /**
0027      * skip terminal toolviews if no terminal aka KonsolePart around
0028      */
0029     if (KateProjectInfoViewTerminal::isLoadable()) {
0030         /**
0031          * terminal for the directory with the .kateproject file inside
0032          */
0033         const QString projectPath = QFileInfo(QFileInfo(m_project->fileName()).path()).absoluteFilePath();
0034         if (!projectPath.isEmpty()) {
0035             m_terminal = new KateProjectInfoViewTerminal(pluginView, projectPath);
0036             addTab(m_terminal, i18n("Terminal (.kateproject)"));
0037         }
0038 
0039         /**
0040          * terminal for the base directory, if different to directory of .kateproject
0041          */
0042         const QString basePath = QFileInfo(m_project->baseDir()).absoluteFilePath();
0043         if (!basePath.isEmpty() && projectPath != basePath) {
0044             addTab(new KateProjectInfoViewTerminal(pluginView, basePath), i18n("Terminal (Base)"));
0045         }
0046     }
0047 
0048     /**
0049      * index
0050      */
0051     addTab(new KateProjectInfoViewIndex(pluginView, project), i18n("Code Index"));
0052 
0053     /**
0054      * code analysis
0055      */
0056     addTab(new KateProjectInfoViewCodeAnalysis(pluginView, project), i18n("Code Analysis"));
0057 
0058     /**
0059      * notes
0060      */
0061     addTab(new KateProjectInfoViewNotes(project), i18n("Notes"));
0062 }
0063 
0064 KateProjectInfoView::~KateProjectInfoView()
0065 {
0066 }
0067 
0068 void KateProjectInfoView::showEvent(QShowEvent *)
0069 {
0070     setFocusProxy(currentWidget());
0071 }
0072 
0073 bool KateProjectInfoView::ignoreEsc() const
0074 {
0075     // we want to ignore stuff for some kinds of running shell processes like vim
0076     if (const auto terminal = qobject_cast<const KateProjectInfoViewTerminal *>(currentWidget())) {
0077         return terminal->ignoreEsc();
0078     }
0079 
0080     // else: always hide toolview, nothing to ignore
0081     return false;
0082 }
0083 
0084 void KateProjectInfoView::resetTerminal(const QString &directory)
0085 {
0086     if (m_terminal) {
0087         m_terminal->respawn(directory);
0088     }
0089 }
0090 
0091 void KateProjectInfoView::runCmdInTerminal(const QString &workingDir, const QString &cmd)
0092 {
0093     if (auto terminal = qobject_cast<KateProjectInfoViewTerminal *>(currentWidget())) {
0094         terminal->runCommand(workingDir, cmd);
0095     }
0096 }
0097 
0098 #include "moc_kateprojectinfoview.cpp"