2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
#include "cppeditorplugin.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2014-08-27 14:18:35 +02:00
|
|
|
#include "cppautocompleter.h"
|
2014-05-23 13:55:03 -04:00
|
|
|
#include "cppcodemodelinspectordialog.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppcodemodelsettings.h"
|
|
|
|
|
#include "cppcodemodelsettingspage.h"
|
|
|
|
|
#include "cppcodestylesettingspage.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cppeditorconstants.h"
|
2014-08-27 14:18:35 +02:00
|
|
|
#include "cppeditordocument.h"
|
2020-08-20 00:33:24 +02:00
|
|
|
#include "cppeditorwidget.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppfilesettingspage.h"
|
2014-06-26 00:27:27 +02:00
|
|
|
#include "cpphighlighter.h"
|
2013-08-13 22:58:38 +02:00
|
|
|
#include "cppincludehierarchy.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppmodelmanager.h"
|
2014-05-23 13:55:03 -04:00
|
|
|
#include "cppoutline.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppprojectfile.h"
|
|
|
|
|
#include "cppprojectupdater.h"
|
2011-04-15 16:19:23 +02:00
|
|
|
#include "cppquickfixassistant.h"
|
2013-02-07 12:16:41 +01:00
|
|
|
#include "cppquickfixes.h"
|
2020-08-20 00:33:24 +02:00
|
|
|
#include "cppquickfixprojectsettingswidget.h"
|
|
|
|
|
#include "cppquickfixsettingspage.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cpptoolsreuse.h"
|
|
|
|
|
#include "cpptoolssettings.h"
|
2014-05-23 13:55:03 -04:00
|
|
|
#include "cpptypehierarchy.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "projectinfo.h"
|
2016-08-10 20:18:48 +10:00
|
|
|
#include "resourcepreviewhoverhandler.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "stringtable.h"
|
2015-02-26 13:22:35 +01:00
|
|
|
|
2015-01-15 14:58:16 +01:00
|
|
|
#ifdef WITH_TESTS
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "compileroptionsbuilder_test.h"
|
|
|
|
|
#include "cppcodegen_test.h"
|
|
|
|
|
#include "cppcompletion_test.h"
|
2021-08-25 17:34:11 +02:00
|
|
|
#include "cppdoxygen_test.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppheadersource_test.h"
|
2021-08-25 17:34:11 +02:00
|
|
|
#include "cppincludehierarchy_test.h"
|
|
|
|
|
#include "cppinsertvirtualmethods.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cpplocalsymbols_test.h"
|
|
|
|
|
#include "cpplocatorfilter_test.h"
|
|
|
|
|
#include "cppmodelmanager_test.h"
|
|
|
|
|
#include "cpppointerdeclarationformatter_test.h"
|
2021-08-25 17:34:11 +02:00
|
|
|
#include "cppquickfix_test.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppsourceprocessor_test.h"
|
2021-08-25 17:34:11 +02:00
|
|
|
#include "cppuseselections_test.h"
|
|
|
|
|
#include "fileandtokenactions_test.h"
|
|
|
|
|
#include "followsymbol_switchmethoddecldef_test.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "functionutils.h"
|
|
|
|
|
#include "includeutils.h"
|
|
|
|
|
#include "projectinfo_test.h"
|
|
|
|
|
#include "senddocumenttracker.h"
|
|
|
|
|
#include "symbolsearcher_test.h"
|
|
|
|
|
#include "typehierarchybuilder_test.h"
|
2015-01-15 14:58:16 +01:00
|
|
|
#endif
|
|
|
|
|
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <coreplugin/idocument.h>
|
2010-08-13 16:38:45 +02:00
|
|
|
#include <coreplugin/navigationwidget.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <coreplugin/vcsmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/project.h>
|
2021-09-02 08:23:46 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2020-08-20 00:33:24 +02:00
|
|
|
#include <projectexplorer/projectpanelfactory.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <projectexplorer/projecttree.h>
|
|
|
|
|
|
2015-12-27 16:00:38 +11:00
|
|
|
#include <texteditor/colorpreviewhoverhandler.h>
|
2017-04-24 15:52:04 +02:00
|
|
|
#include <texteditor/snippets/snippetprovider.h>
|
2021-09-02 08:23:46 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2020-08-20 00:33:24 +02:00
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/fileutils.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <utils/macroexpander.h>
|
2015-02-04 09:32:46 +01:00
|
|
|
#include <utils/mimetypes/mimedatabase.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <utils/qtcassert.h>
|
Implement theming for QtCreator
Adds a 'Theme' tab to the environment settings and a '-theme' command
line option.
A theme is a combination of colors, gradients, flags and style
information.
There are two themes:
- 'default': preserves the current default look
- 'dark': uses a more flat for many widgets, dark color theme
for everything
This does not use a stylesheet (too limited), but rather sets
the palette via C++ and modifies drawing behavior.
Overall, the look is more flat (removed some gradients and bevels).
Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE
Desktop (Oxygen base style).
For a screenshot, see
https://gist.github.com/thorbenk/5ab06bea726de0aa7473
Changes:
- Introduce class Theme, defining the interface how to access theme
specific settings. The class reads a .creatortheme file (INI file, via
QSettings)
- Define named colors in the [Palette] section
(see dark.creatortheme for example usage)
- Use either named colors of AARRGGBB (hex) in the [Colors]
section
- A file ending with .creatortheme may be supplied
to the '-theme' command line option
- A global Theme instance can be accessed via creatorTheme()
- Query colors, gradients, icons and flags from the theme
were possible (TODO: use this in more places...)
- There are very many color roles. It seems better to me
to describe the role clearly, and then to consolidate later
in the actual theme by assigning the same color.
For example, one can set the text color of the output pane button
individualy.
- Many elements are also drawn differently.
For the dark theme, I wanted to have a flatter look.
- Introduce Theme::WidgetStyle enum, for now {Original, Flat}.
- The theme specifies which kind of widget style it wants.
- The drawing code queries the theme's style flag and
switches between the original, gradient based look and
the new, flat look.
- Create some custom icons which look better on dark background
(wip, currently folder/file icons)
- Let ManhattanStyle draw some elements for non-panelwidgets, too
(open/close arrows in QTreeView, custom folder/file icons)
- For the welcomescreen, pass the WelcomeTheme class.
WelcomeTheme exposes theme colors as Q_PROPERTY accessible from
.qml
- Themes can be modified via the 'Themes' tab in the environment
settings.
TODO:
* Unify image handling
* Avoid style name references
* Fix gradients
Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
|
|
|
#include <utils/theme/theme.h>
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <QAction>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMenu>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStringList>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
using namespace CPlusPlus;
|
2013-08-30 09:22:42 +02:00
|
|
|
using namespace Core;
|
2021-08-30 10:58:08 +02:00
|
|
|
using namespace ProjectExplorer;
|
2014-08-27 14:18:35 +02:00
|
|
|
using namespace TextEditor;
|
Implement theming for QtCreator
Adds a 'Theme' tab to the environment settings and a '-theme' command
line option.
A theme is a combination of colors, gradients, flags and style
information.
There are two themes:
- 'default': preserves the current default look
- 'dark': uses a more flat for many widgets, dark color theme
for everything
This does not use a stylesheet (too limited), but rather sets
the palette via C++ and modifies drawing behavior.
Overall, the look is more flat (removed some gradients and bevels).
Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE
Desktop (Oxygen base style).
For a screenshot, see
https://gist.github.com/thorbenk/5ab06bea726de0aa7473
Changes:
- Introduce class Theme, defining the interface how to access theme
specific settings. The class reads a .creatortheme file (INI file, via
QSettings)
- Define named colors in the [Palette] section
(see dark.creatortheme for example usage)
- Use either named colors of AARRGGBB (hex) in the [Colors]
section
- A file ending with .creatortheme may be supplied
to the '-theme' command line option
- A global Theme instance can be accessed via creatorTheme()
- Query colors, gradients, icons and flags from the theme
were possible (TODO: use this in more places...)
- There are very many color roles. It seems better to me
to describe the role clearly, and then to consolidate later
in the actual theme by assigning the same color.
For example, one can set the text color of the output pane button
individualy.
- Many elements are also drawn differently.
For the dark theme, I wanted to have a flatter look.
- Introduce Theme::WidgetStyle enum, for now {Original, Flat}.
- The theme specifies which kind of widget style it wants.
- The drawing code queries the theme's style flag and
switches between the original, gradient based look and
the new, flat look.
- Create some custom icons which look better on dark background
(wip, currently folder/file icons)
- Let ManhattanStyle draw some elements for non-panelwidgets, too
(open/close arrows in QTreeView, custom folder/file icons)
- For the welcomescreen, pass the WelcomeTheme class.
WelcomeTheme exposes theme colors as Q_PROPERTY accessible from
.qml
- Themes can be modified via the 'Themes' tab in the environment
settings.
TODO:
* Unify image handling
* Avoid style name references
* Fix gradients
Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
|
|
|
using namespace Utils;
|
2014-08-27 10:01:27 +02:00
|
|
|
|
|
|
|
|
namespace CppEditor {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-18 15:06:26 +01:00
|
|
|
enum { QUICKFIX_INTERVAL = 20 };
|
2021-08-30 10:58:08 +02:00
|
|
|
enum { debug = 0 };
|
2009-11-18 15:06:26 +01:00
|
|
|
|
2021-05-26 17:24:18 +02:00
|
|
|
static CppEditorWidget *currentCppEditorWidget()
|
|
|
|
|
{
|
|
|
|
|
if (IEditor *currentEditor = EditorManager::currentEditor())
|
|
|
|
|
return qobject_cast<CppEditorWidget*>(currentEditor->widget());
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-17 17:43:51 +01:00
|
|
|
//////////////////////////// CppEditorFactory /////////////////////////////
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
class CppEditorFactory : public TextEditorFactory
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-08-27 14:18:35 +02:00
|
|
|
public:
|
|
|
|
|
CppEditorFactory()
|
|
|
|
|
{
|
|
|
|
|
setId(Constants::CPPEDITOR_ID);
|
2017-04-24 17:01:10 +02:00
|
|
|
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::CPPEDITOR_DISPLAY_NAME));
|
2021-08-30 10:58:08 +02:00
|
|
|
addMimeType(Constants::C_SOURCE_MIMETYPE);
|
|
|
|
|
addMimeType(Constants::C_HEADER_MIMETYPE);
|
|
|
|
|
addMimeType(Constants::CPP_SOURCE_MIMETYPE);
|
|
|
|
|
addMimeType(Constants::CPP_HEADER_MIMETYPE);
|
|
|
|
|
addMimeType(Constants::QDOC_MIMETYPE);
|
|
|
|
|
addMimeType(Constants::MOC_MIMETYPE);
|
2014-08-27 14:18:35 +02:00
|
|
|
|
|
|
|
|
setDocumentCreator([]() { return new CppEditorDocument; });
|
|
|
|
|
setEditorWidgetCreator([]() { return new CppEditorWidget; });
|
2021-09-02 08:23:46 +02:00
|
|
|
setEditorCreator([]() {
|
|
|
|
|
const auto editor = new BaseTextEditor;
|
|
|
|
|
editor->addContext(ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
|
|
|
|
return editor;
|
|
|
|
|
});
|
2014-08-27 14:18:35 +02:00
|
|
|
setAutoCompleterCreator([]() { return new CppAutoCompleter; });
|
2017-04-24 16:01:14 +02:00
|
|
|
setCommentDefinition(CommentDefinition::CppStyle);
|
2014-10-15 00:36:39 +02:00
|
|
|
setCodeFoldingSupported(true);
|
|
|
|
|
setParenthesesMatchingEnabled(true);
|
2014-08-27 14:18:35 +02:00
|
|
|
|
2014-09-02 12:25:20 +02:00
|
|
|
setEditorActionHandlers(TextEditorActionHandler::Format
|
2020-05-06 07:30:33 +02:00
|
|
|
| TextEditorActionHandler::UnCommentSelection
|
|
|
|
|
| TextEditorActionHandler::UnCollapseAll
|
|
|
|
|
| TextEditorActionHandler::FollowSymbolUnderCursor
|
|
|
|
|
| TextEditorActionHandler::RenameSymbol);
|
2012-08-23 15:53:58 +02:00
|
|
|
}
|
2014-08-27 14:18:35 +02:00
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
///////////////////////////////// CppEditorPlugin //////////////////////////////////
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
class CppEditorPluginPrivate : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-08-30 10:58:08 +02:00
|
|
|
~CppEditorPluginPrivate()
|
|
|
|
|
{
|
|
|
|
|
ExtensionSystem::PluginManager::removeObject(&m_cppProjectUpdaterFactory);
|
|
|
|
|
delete m_clangdSettingsPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initialize() { m_codeModelSettings.fromSettings(ICore::settings()); }
|
2020-06-26 13:59:38 +02:00
|
|
|
void onTaskStarted(Utils::Id type);
|
|
|
|
|
void onAllTasksFinished(Utils::Id type);
|
2018-02-07 14:51:15 +01:00
|
|
|
void inspectCppCodeModel();
|
|
|
|
|
|
|
|
|
|
QAction *m_reparseExternallyChangedFiles = nullptr;
|
2021-05-26 17:24:18 +02:00
|
|
|
QAction *m_findRefsCategorizedAction = nullptr;
|
2018-02-07 14:51:15 +01:00
|
|
|
QAction *m_openTypeHierarchyAction = nullptr;
|
|
|
|
|
QAction *m_openIncludeHierarchyAction = nullptr;
|
|
|
|
|
|
|
|
|
|
CppQuickFixAssistProvider m_quickFixProvider;
|
2020-08-20 00:33:24 +02:00
|
|
|
CppQuickFixSettingsPage m_quickFixSettingsPage;
|
2018-02-07 14:51:15 +01:00
|
|
|
|
|
|
|
|
QPointer<CppCodeModelInspectorDialog> m_cppCodeModelInspectorDialog;
|
|
|
|
|
|
|
|
|
|
QPointer<TextEditor::BaseTextEditor> m_currentEditor;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
CppOutlineWidgetFactory m_cppOutlineWidgetFactory;
|
|
|
|
|
CppTypeHierarchyFactory m_cppTypeHierarchyFactory;
|
|
|
|
|
CppIncludeHierarchyFactory m_cppIncludeHierarchyFactory;
|
|
|
|
|
CppEditorFactory m_cppEditorFactory;
|
2021-08-30 10:58:08 +02:00
|
|
|
|
|
|
|
|
StringTable stringTable;
|
|
|
|
|
CppModelManager modelManager;
|
|
|
|
|
CppCodeModelSettings m_codeModelSettings;
|
|
|
|
|
CppToolsSettings settings;
|
|
|
|
|
CppFileSettings m_fileSettings;
|
|
|
|
|
CppFileSettingsPage m_cppFileSettingsPage{&m_fileSettings};
|
|
|
|
|
CppCodeModelSettingsPage m_cppCodeModelSettingsPage{&m_codeModelSettings};
|
|
|
|
|
ClangdSettingsPage *m_clangdSettingsPage = nullptr;
|
|
|
|
|
CppCodeStyleSettingsPage m_cppCodeStyleSettingsPage;
|
|
|
|
|
CppProjectUpdaterFactory m_cppProjectUpdaterFactory;
|
2018-02-07 14:51:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static CppEditorPlugin *m_instance = nullptr;
|
2021-08-30 10:58:08 +02:00
|
|
|
static QHash<QString, QString> m_headerSourceMapping;
|
2018-02-07 14:51:15 +01:00
|
|
|
|
|
|
|
|
CppEditorPlugin::CppEditorPlugin()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
CppEditorPlugin::~CppEditorPlugin()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-01-26 16:43:01 +01:00
|
|
|
destroyCppQuickFixes();
|
2018-02-07 14:51:15 +01:00
|
|
|
delete d;
|
|
|
|
|
d = nullptr;
|
|
|
|
|
m_instance = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
CppEditorPlugin *CppEditorPlugin::instance()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
CppQuickFixAssistProvider *CppEditorPlugin::quickFixProvider() const
|
2011-04-15 16:19:23 +02:00
|
|
|
{
|
2018-02-07 14:51:15 +01:00
|
|
|
return &d->m_quickFixProvider;
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
2009-11-23 16:55:04 +01:00
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-02-04 09:32:46 +01:00
|
|
|
Q_UNUSED(errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
d = new CppEditorPluginPrivate;
|
|
|
|
|
d->initialize();
|
|
|
|
|
|
|
|
|
|
CppModelManager::instance()->registerJsExtension();
|
|
|
|
|
ExtensionSystem::PluginManager::addObject(&d->m_cppProjectUpdaterFactory);
|
|
|
|
|
|
|
|
|
|
// Menus
|
|
|
|
|
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
|
|
|
|
|
ActionContainer *mcpptools = ActionManager::createMenu(Constants::M_TOOLS_CPP);
|
|
|
|
|
QMenu *menu = mcpptools->menu();
|
|
|
|
|
menu->setTitle(tr("&C++"));
|
|
|
|
|
menu->setEnabled(true);
|
|
|
|
|
mtools->addMenu(mcpptools);
|
|
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
Context context(Constants::CPPEDITOR_ID);
|
|
|
|
|
|
|
|
|
|
QAction *switchAction = new QAction(tr("Switch Header/Source"), this);
|
|
|
|
|
Command *command = ActionManager::registerAction(switchAction, Constants::SWITCH_HEADER_SOURCE, context, true);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(Qt::Key_F4));
|
|
|
|
|
mcpptools->addAction(command);
|
|
|
|
|
connect(switchAction, &QAction::triggered, this, &CppEditorPlugin::switchHeaderSource);
|
|
|
|
|
|
|
|
|
|
QAction *openInNextSplitAction = new QAction(tr("Open Corresponding Header/Source in Next Split"), this);
|
|
|
|
|
command = ActionManager::registerAction(openInNextSplitAction, Constants::OPEN_HEADER_SOURCE_IN_NEXT_SPLIT, context, true);
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
|
|
|
|
? tr("Meta+E, F4")
|
|
|
|
|
: tr("Ctrl+E, F4")));
|
|
|
|
|
mcpptools->addAction(command);
|
|
|
|
|
connect(openInNextSplitAction, &QAction::triggered,
|
|
|
|
|
this, &CppEditorPlugin::switchHeaderSourceInNextSplit);
|
|
|
|
|
|
|
|
|
|
MacroExpander *expander = globalMacroExpander();
|
|
|
|
|
expander->registerVariable("Cpp:LicenseTemplate",
|
|
|
|
|
tr("The license template."),
|
|
|
|
|
[]() { return CppEditorPlugin::licenseTemplate(); });
|
|
|
|
|
expander->registerFileVariables("Cpp:LicenseTemplatePath",
|
|
|
|
|
tr("The configured path to the license template"),
|
|
|
|
|
[]() { return CppEditorPlugin::licenseTemplatePath(); });
|
|
|
|
|
|
|
|
|
|
expander->registerVariable(
|
|
|
|
|
"Cpp:PragmaOnce",
|
|
|
|
|
tr("Insert \"#pragma once\" instead of \"#ifndef\" include guards into header file"),
|
|
|
|
|
[] { return usePragmaOnce() ? QString("true") : QString(); });
|
|
|
|
|
|
|
|
|
|
const auto clangdPanelFactory = new ProjectPanelFactory;
|
|
|
|
|
clangdPanelFactory->setPriority(100);
|
|
|
|
|
clangdPanelFactory->setDisplayName(tr("Clangd"));
|
|
|
|
|
clangdPanelFactory->setCreateWidgetFunction([](Project *project) {
|
|
|
|
|
return new ClangdProjectSettingsWidget(project);
|
|
|
|
|
});
|
|
|
|
|
ProjectPanelFactory::registerFactory(clangdPanelFactory);
|
|
|
|
|
|
|
|
|
|
const auto quickFixSettingsPanelFactory = new ProjectPanelFactory;
|
|
|
|
|
quickFixSettingsPanelFactory->setPriority(100);
|
|
|
|
|
quickFixSettingsPanelFactory->setId(Constants::QUICK_FIX_PROJECT_PANEL_ID);
|
|
|
|
|
quickFixSettingsPanelFactory->setDisplayName(
|
|
|
|
|
QCoreApplication::translate("CppEditor", Constants::QUICK_FIX_SETTINGS_DISPLAY_NAME));
|
|
|
|
|
quickFixSettingsPanelFactory->setCreateWidgetFunction([](Project *project) {
|
2020-08-20 00:33:24 +02:00
|
|
|
return new CppQuickFixProjectSettingsWidget(project);
|
|
|
|
|
});
|
2021-08-30 10:58:08 +02:00
|
|
|
ProjectPanelFactory::registerFactory(quickFixSettingsPanelFactory);
|
2018-02-07 14:51:15 +01:00
|
|
|
|
2017-04-24 15:52:04 +02:00
|
|
|
SnippetProvider::registerGroup(Constants::CPP_SNIPPETS_GROUP_ID, tr("C++", "SnippetProvider"),
|
2021-09-02 08:23:46 +02:00
|
|
|
&decorateCppEditor);
|
2014-06-26 00:27:27 +02:00
|
|
|
|
2018-01-26 16:43:01 +01:00
|
|
|
createCppQuickFixes();
|
2010-06-22 14:14:22 +02:00
|
|
|
|
2014-08-27 10:01:27 +02:00
|
|
|
ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT);
|
2020-03-26 13:20:58 +01:00
|
|
|
contextMenu->insertGroup(Core::Constants::G_DEFAULT_ONE, Constants::G_CONTEXT_FIRST);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
Command *cmd;
|
2021-08-30 10:58:08 +02:00
|
|
|
ActionContainer *cppToolsMenu = ActionManager::actionContainer(Constants::M_TOOLS_CPP);
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
cmd = ActionManager::command(Constants::SWITCH_HEADER_SOURCE);
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
cmd->setTouchBarText(tr("Header/Source", "text on macOS touch bar"));
|
2020-03-26 13:20:58 +01:00
|
|
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
2011-08-05 13:13:17 +02:00
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR);
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
cmd->setTouchBarText(tr("Follow", "text on macOS touch bar"));
|
2020-03-26 13:20:58 +01:00
|
|
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
2009-11-11 14:32:54 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-10-23 14:13:06 +02:00
|
|
|
QAction *openPreprocessorDialog = new QAction(tr("Additional Preprocessor Directives..."), this);
|
2013-10-17 14:52:16 +02:00
|
|
|
cmd = ActionManager::registerAction(openPreprocessorDialog,
|
|
|
|
|
Constants::OPEN_PREPROCESSOR_DIALOG, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence());
|
2016-05-28 23:47:48 +03:00
|
|
|
connect(openPreprocessorDialog, &QAction::triggered, this, &CppEditorPlugin::showPreProcessorDialog);
|
2013-10-17 14:52:16 +02:00
|
|
|
cppToolsMenu->addAction(cmd);
|
|
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
QAction *switchDeclarationDefinition = new QAction(tr("Switch Between Function Declaration/Definition"), this);
|
2013-08-30 09:22:42 +02:00
|
|
|
cmd = ActionManager::registerAction(switchDeclarationDefinition,
|
2010-12-20 10:35:30 +01:00
|
|
|
Constants::SWITCH_DECLARATION_DEFINITION, context, true);
|
2012-01-11 14:26:09 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Shift+F2")));
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
cmd->setTouchBarText(tr("Decl/Def", "text on macOS touch bar"));
|
2016-05-28 23:47:48 +03:00
|
|
|
connect(switchDeclarationDefinition, &QAction::triggered,
|
|
|
|
|
this, &CppEditorPlugin::switchDeclarationDefinition);
|
2020-03-26 13:20:58 +01:00
|
|
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
2009-11-11 14:32:54 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
Add macOS touch bar support
Introduce a generic Utils::TouchBar that implements a touch bar for
macOS based on QAction. Touch bars can be nested, and one is set to be
the application's top level touch bar.
Also add an ActionContainer for the touch bar. That allows us to manage
the layout of the touch bar the same way we do with menus.
Since the touch bar is an input device with very limited space, a
command in the touch bar needs to be specifically styled for the touch
bar by setting either touchBarText or touchBarIcon (or both).
Touch bars can be nested by nesting the ActionContainers. A nested touch
bar ActionContainer needs to specify an icon and/or text to show in the
touch bar button that opens that sub-bar.
Commands are only shown in the touch bar if they are valid within the
current context.
Implementation-wise we cannot use the standard NSPopoverTouchBarItem for
nesting touch bar levels. We cannot hide items in the touch bar, because
hidden items still take up space in the touch bar. So we need to rebuild
the touch bar regularly. Since the items we show are very dynamic, every
time the items in the toplevel bar change because of a context change,
any opened sub-level touch bar closes. That is why we maintain a stack of
touch bar levels ourselves, replacing the main touch bar with the current
level, and managing opening and closing the levels manually.
This patch adds buttons for Help, Bookmarks, Header/Source, Follow
(Symbol), Decl/Def, and a sub-bar for the debugger actions.
Fixes: QTCREATORBUG-21263
Change-Id: Ib63e610f21a993f1d324fe23c83a7f2224f434ac
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
2018-10-05 13:52:57 +02:00
|
|
|
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_NAVIGATION);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
cmd = ActionManager::command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT);
|
2013-02-05 14:14:33 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
|
|
|
|
|
|
|
|
|
QAction *openDeclarationDefinitionInNextSplit =
|
2013-10-07 13:34:40 +02:00
|
|
|
new QAction(tr("Open Function Declaration/Definition in Next Split"), this);
|
2013-08-30 09:22:42 +02:00
|
|
|
cmd = ActionManager::registerAction(openDeclarationDefinitionInNextSplit,
|
2013-02-05 14:14:33 +01:00
|
|
|
Constants::OPEN_DECLARATION_DEFINITION_IN_NEXT_SPLIT, context, true);
|
2015-02-04 17:01:07 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(HostOsInfo::isMacHost()
|
2013-04-25 20:24:06 +02:00
|
|
|
? tr("Meta+E, Shift+F2")
|
|
|
|
|
: tr("Ctrl+E, Shift+F2")));
|
2016-05-28 23:47:48 +03:00
|
|
|
connect(openDeclarationDefinitionInNextSplit, &QAction::triggered,
|
|
|
|
|
this, &CppEditorPlugin::openDeclarationDefinitionInNextSplit);
|
2013-02-05 14:14:33 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
|
|
|
|
|
2018-11-28 07:26:14 +01:00
|
|
|
cmd = ActionManager::command(TextEditor::Constants::FIND_USAGES);
|
2020-03-26 13:20:58 +01:00
|
|
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
2009-11-11 14:32:54 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
2009-10-05 15:17:25 +02:00
|
|
|
|
2021-05-26 17:24:18 +02:00
|
|
|
d->m_findRefsCategorizedAction = new QAction(tr("Find References With Access Type"), this);
|
|
|
|
|
cmd = ActionManager::registerAction(d->m_findRefsCategorizedAction,
|
|
|
|
|
"CppEditor.FindRefsCategorized", context);
|
2021-08-30 10:58:08 +02:00
|
|
|
connect(d->m_findRefsCategorizedAction, &QAction::triggered, this, [this] {
|
2021-05-26 17:24:18 +02:00
|
|
|
if (const auto w = currentCppEditorWidget()) {
|
|
|
|
|
codeModelSettings()->setCategorizeFindReferences(true);
|
|
|
|
|
w->findUsages();
|
|
|
|
|
codeModelSettings()->setCategorizeFindReferences(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
|
|
|
|
cppToolsMenu->addAction(cmd);
|
|
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
d->m_openTypeHierarchyAction = new QAction(tr("Open Type Hierarchy"), this);
|
|
|
|
|
cmd = ActionManager::registerAction(d->m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context);
|
2018-02-02 13:39:18 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+T") : tr("Ctrl+Shift+T")));
|
2018-02-07 14:51:15 +01:00
|
|
|
connect(d->m_openTypeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openTypeHierarchy);
|
2020-03-26 13:20:58 +01:00
|
|
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
2010-08-13 16:38:45 +02:00
|
|
|
cppToolsMenu->addAction(cmd);
|
|
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
d->m_openIncludeHierarchyAction = new QAction(tr("Open Include Hierarchy"), this);
|
|
|
|
|
cmd = ActionManager::registerAction(d->m_openIncludeHierarchyAction, Constants::OPEN_INCLUDE_HIERARCHY, context);
|
2018-02-02 13:39:18 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+I") : tr("Ctrl+Shift+I")));
|
2018-02-07 14:51:15 +01:00
|
|
|
connect(d->m_openIncludeHierarchyAction, &QAction::triggered, this, &CppEditorPlugin::openIncludeHierarchy);
|
2020-03-26 13:20:58 +01:00
|
|
|
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
|
2013-08-13 22:58:38 +02:00
|
|
|
cppToolsMenu->addAction(cmd);
|
|
|
|
|
|
2010-09-15 14:33:44 +02:00
|
|
|
// Refactoring sub-menu
|
2015-02-19 11:35:47 +01:00
|
|
|
Command *sep = contextMenu->addSeparator();
|
2012-01-11 14:26:09 +01:00
|
|
|
sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT));
|
2015-02-19 11:35:47 +01:00
|
|
|
contextMenu->addSeparator();
|
2020-05-06 07:30:33 +02:00
|
|
|
cppToolsMenu->addAction(ActionManager::command(TextEditor::Constants::RENAME_SYMBOL));
|
2010-09-15 14:33:44 +02:00
|
|
|
|
|
|
|
|
// Update context in global context
|
2020-03-26 13:20:58 +01:00
|
|
|
cppToolsMenu->addSeparator(Core::Constants::G_DEFAULT_THREE);
|
2018-02-07 14:51:15 +01:00
|
|
|
d->m_reparseExternallyChangedFiles = new QAction(tr("Reparse Externally Changed Files"), this);
|
|
|
|
|
cmd = ActionManager::registerAction(d->m_reparseExternallyChangedFiles, Constants::UPDATE_CODEMODEL);
|
2021-08-30 10:58:08 +02:00
|
|
|
CppModelManager *cppModelManager = CppModelManager::instance();
|
|
|
|
|
connect(d->m_reparseExternallyChangedFiles, &QAction::triggered,
|
|
|
|
|
cppModelManager, &CppModelManager::updateModifiedSourceFiles);
|
2020-03-26 13:20:58 +01:00
|
|
|
cppToolsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
|
2009-08-04 13:44:54 +02:00
|
|
|
|
2022-01-24 17:06:54 +01:00
|
|
|
ActionContainer *toolsDebug = ActionManager::actionContainer(Core::Constants::M_TOOLS_DEBUG);
|
2014-03-05 09:22:02 -03:00
|
|
|
QAction *inspectCppCodeModel = new QAction(tr("Inspect C++ Code Model..."), this);
|
2015-02-19 11:35:47 +01:00
|
|
|
cmd = ActionManager::registerAction(inspectCppCodeModel, Constants::INSPECT_CPP_CODEMODEL);
|
2018-02-02 13:39:18 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+F12") : tr("Ctrl+Shift+F12")));
|
2018-02-07 14:51:15 +01:00
|
|
|
connect(inspectCppCodeModel, &QAction::triggered, d, &CppEditorPluginPrivate::inspectCppCodeModel);
|
2022-01-24 17:06:54 +01:00
|
|
|
toolsDebug->addAction(cmd);
|
2013-11-03 02:02:36 +01:00
|
|
|
|
2012-06-05 14:22:20 +02:00
|
|
|
contextMenu->addSeparator(context);
|
2009-07-22 15:32:52 +02:00
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
cmd = ActionManager::command(TextEditor::Constants::AUTO_INDENT_SELECTION);
|
2009-09-24 14:50:22 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-07-22 15:32:52 +02:00
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
2009-09-24 14:50:22 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-07-22 15:32:52 +02:00
|
|
|
|
2016-05-28 23:47:48 +03:00
|
|
|
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
|
2018-02-07 14:51:15 +01:00
|
|
|
d, &CppEditorPluginPrivate::onTaskStarted);
|
2016-05-28 23:47:48 +03:00
|
|
|
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
|
2018-02-07 14:51:15 +01:00
|
|
|
d, &CppEditorPluginPrivate::onAllTasksFinished);
|
2010-08-03 11:53:01 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
void CppEditorPlugin::extensionsInitialized()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
d->m_fileSettings.fromSettings(ICore::settings());
|
|
|
|
|
if (!d->m_fileSettings.applySuffixesToMimeDB())
|
|
|
|
|
qWarning("Unable to apply cpp suffixes to mime database (cpp mime types not found).\n");
|
|
|
|
|
if (CppModelManager::instance()->isClangCodeModelActive())
|
|
|
|
|
d->m_clangdSettingsPage = new ClangdSettingsPage;
|
|
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
// Add the hover handler factories here instead of in initialize()
|
2018-01-11 17:06:26 +01:00
|
|
|
// so that the Clang Code Model has a chance to hook in.
|
2018-02-07 14:51:15 +01:00
|
|
|
d->m_cppEditorFactory.addHoverHandler(CppModelManager::instance()->createHoverHandler());
|
|
|
|
|
d->m_cppEditorFactory.addHoverHandler(new ColorPreviewHoverHandler);
|
|
|
|
|
d->m_cppEditorFactory.addHoverHandler(new ResourcePreviewHoverHandler);
|
2018-01-11 17:06:26 +01:00
|
|
|
|
2021-11-30 14:24:50 +01:00
|
|
|
FileIconProvider::registerIconOverlayForMimeType(
|
2021-12-02 22:56:27 +01:00
|
|
|
creatorTheme()->imageFile(Theme::IconOverlayCppSource,
|
|
|
|
|
ProjectExplorer::Constants::FILEOVERLAY_CPP),
|
2021-11-30 14:24:50 +01:00
|
|
|
Constants::CPP_SOURCE_MIMETYPE);
|
|
|
|
|
FileIconProvider::registerIconOverlayForMimeType(
|
2021-12-02 22:56:27 +01:00
|
|
|
creatorTheme()->imageFile(Theme::IconOverlayCSource,
|
|
|
|
|
ProjectExplorer::Constants::FILEOVERLAY_C),
|
2021-11-30 14:24:50 +01:00
|
|
|
Constants::C_SOURCE_MIMETYPE);
|
|
|
|
|
FileIconProvider::registerIconOverlayForMimeType(
|
2021-12-02 22:56:27 +01:00
|
|
|
creatorTheme()->imageFile(Theme::IconOverlayCppHeader,
|
|
|
|
|
ProjectExplorer::Constants::FILEOVERLAY_H),
|
2021-11-30 14:24:50 +01:00
|
|
|
Constants::CPP_HEADER_MIMETYPE);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
void CppEditorPlugin::switchDeclarationDefinition()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-07-30 16:30:31 +02:00
|
|
|
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
2013-10-18 16:50:09 +02:00
|
|
|
editorWidget->switchDeclarationDefinition(/*inNextSplit*/ false);
|
2013-02-05 14:14:33 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
void CppEditorPlugin::openDeclarationDefinitionInNextSplit()
|
2013-02-05 14:14:33 +01:00
|
|
|
{
|
2014-07-30 16:30:31 +02:00
|
|
|
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
2013-10-18 16:50:09 +02:00
|
|
|
editorWidget->switchDeclarationDefinition(/*inNextSplit*/ true);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
void CppEditorPlugin::renameSymbolUnderCursor()
|
2009-08-04 13:44:54 +02:00
|
|
|
{
|
2014-07-30 16:30:31 +02:00
|
|
|
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
2013-10-18 16:50:09 +02:00
|
|
|
editorWidget->renameSymbolUnderCursor();
|
2009-08-04 13:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-17 14:52:16 +02:00
|
|
|
void CppEditorPlugin::showPreProcessorDialog()
|
|
|
|
|
{
|
2014-07-30 16:30:31 +02:00
|
|
|
if (CppEditorWidget *editorWidget = currentCppEditorWidget())
|
2013-10-18 16:50:09 +02:00
|
|
|
editorWidget->showPreProcessorWidget();
|
2013-10-17 14:52:16 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
void CppEditorPluginPrivate::onTaskStarted(Id type)
|
2009-11-04 16:07:42 +01:00
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
if (type == Constants::TASK_INDEX) {
|
2018-11-28 07:26:14 +01:00
|
|
|
ActionManager::command(TextEditor::Constants::FIND_USAGES)->action()->setEnabled(false);
|
2020-05-06 07:30:33 +02:00
|
|
|
ActionManager::command(TextEditor::Constants::RENAME_SYMBOL)->action()->setEnabled(false);
|
2013-10-04 15:54:39 +02:00
|
|
|
m_reparseExternallyChangedFiles->setEnabled(false);
|
2010-08-13 16:38:45 +02:00
|
|
|
m_openTypeHierarchyAction->setEnabled(false);
|
2013-08-13 22:58:38 +02:00
|
|
|
m_openIncludeHierarchyAction->setEnabled(false);
|
2009-11-10 18:02:42 +01:00
|
|
|
}
|
2009-11-04 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
void CppEditorPluginPrivate::onAllTasksFinished(Id type)
|
2009-11-04 16:07:42 +01:00
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
if (type == Constants::TASK_INDEX) {
|
2018-11-28 07:26:14 +01:00
|
|
|
ActionManager::command(TextEditor::Constants::FIND_USAGES)->action()->setEnabled(true);
|
2020-05-06 07:30:33 +02:00
|
|
|
ActionManager::command(TextEditor::Constants::RENAME_SYMBOL)->action()->setEnabled(true);
|
2013-10-04 15:54:39 +02:00
|
|
|
m_reparseExternallyChangedFiles->setEnabled(true);
|
2010-08-13 16:38:45 +02:00
|
|
|
m_openTypeHierarchyAction->setEnabled(true);
|
2013-08-13 22:58:38 +02:00
|
|
|
m_openIncludeHierarchyAction->setEnabled(true);
|
2009-11-10 18:02:42 +01:00
|
|
|
}
|
2009-11-04 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-07 14:51:15 +01:00
|
|
|
void CppEditorPluginPrivate::inspectCppCodeModel()
|
2013-11-03 02:02:36 +01:00
|
|
|
{
|
|
|
|
|
if (m_cppCodeModelInspectorDialog) {
|
|
|
|
|
ICore::raiseWindow(m_cppCodeModelInspectorDialog);
|
|
|
|
|
} else {
|
2020-06-02 09:10:40 +02:00
|
|
|
m_cppCodeModelInspectorDialog = new CppCodeModelInspectorDialog(ICore::dialogParent());
|
2022-02-07 09:53:19 +01:00
|
|
|
ICore::registerWindow(m_cppCodeModelInspectorDialog, Context("CppEditor.Inspector"));
|
2013-11-03 02:02:36 +01:00
|
|
|
m_cppCodeModelInspectorDialog->show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 14:12:11 +02:00
|
|
|
QVector<QObject *> CppEditorPlugin::createTestObjects() const
|
2015-01-15 14:58:16 +01:00
|
|
|
{
|
2021-08-25 17:34:11 +02:00
|
|
|
return {
|
|
|
|
|
#ifdef WITH_TESTS
|
2021-08-30 10:58:08 +02:00
|
|
|
new CodegenTest,
|
|
|
|
|
new CompilerOptionsBuilderTest,
|
|
|
|
|
new CompletionTest,
|
|
|
|
|
new FunctionUtilsTest,
|
|
|
|
|
new HeaderPathFilterTest,
|
|
|
|
|
new HeaderSourceTest,
|
|
|
|
|
new IncludeGroupsTest,
|
|
|
|
|
new LocalSymbolsTest,
|
|
|
|
|
new LocatorFilterTest,
|
|
|
|
|
new ModelManagerTest,
|
|
|
|
|
new PointerDeclarationFormatterTest,
|
|
|
|
|
new ProjectFileCategorizerTest,
|
|
|
|
|
new ProjectInfoGeneratorTest,
|
|
|
|
|
new ProjectPartChooserTest,
|
|
|
|
|
new DocumentTrackerTest,
|
|
|
|
|
new SourceProcessorTest,
|
|
|
|
|
new SymbolSearcherTest,
|
|
|
|
|
new TypeHierarchyBuilderTest,
|
2021-08-25 17:34:11 +02:00
|
|
|
new Tests::AutoCompleterTest,
|
|
|
|
|
new Tests::DoxygenTest,
|
|
|
|
|
new Tests::FileAndTokenActionsTest,
|
2021-08-27 16:00:33 +02:00
|
|
|
new Tests::FollowSymbolTest,
|
2021-08-25 17:34:11 +02:00
|
|
|
new Tests::IncludeHierarchyTest,
|
|
|
|
|
new Tests::InsertVirtualMethodsTest,
|
|
|
|
|
new Tests::QuickfixTest,
|
|
|
|
|
new Tests::SelectionsTest,
|
2015-01-15 14:58:16 +01:00
|
|
|
#endif
|
2021-08-25 17:34:11 +02:00
|
|
|
};
|
|
|
|
|
}
|
2015-01-15 14:58:16 +01:00
|
|
|
|
2013-03-19 13:44:02 +01:00
|
|
|
void CppEditorPlugin::openTypeHierarchy()
|
2010-08-13 16:38:45 +02:00
|
|
|
{
|
2013-10-18 16:50:09 +02:00
|
|
|
if (currentCppEditorWidget()) {
|
2010-08-13 16:38:45 +02:00
|
|
|
emit typeHierarchyRequested();
|
2020-11-30 17:02:33 +01:00
|
|
|
NavigationWidget::activateSubWidget(Constants::TYPE_HIERARCHY_ID, Side::Left);
|
2010-08-13 16:38:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 22:58:38 +02:00
|
|
|
void CppEditorPlugin::openIncludeHierarchy()
|
|
|
|
|
{
|
2013-10-18 16:50:09 +02:00
|
|
|
if (currentCppEditorWidget()) {
|
2013-08-13 22:58:38 +02:00
|
|
|
emit includeHierarchyRequested();
|
2020-11-30 17:02:33 +01:00
|
|
|
NavigationWidget::activateSubWidget(Constants::INCLUDE_HIERARCHY_ID, Side::Left);
|
2013-08-13 22:58:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-08-27 10:01:27 +02:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
void CppEditorPlugin::clearHeaderSourceCache()
|
|
|
|
|
{
|
|
|
|
|
m_headerSourceMapping.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FilePath CppEditorPlugin::licenseTemplatePath()
|
|
|
|
|
{
|
|
|
|
|
return FilePath::fromString(m_instance->d->m_fileSettings.licenseTemplatePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CppEditorPlugin::licenseTemplate()
|
|
|
|
|
{
|
|
|
|
|
return CppFileSettings::licenseTemplate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CppEditorPlugin::usePragmaOnce()
|
|
|
|
|
{
|
|
|
|
|
return m_instance->d->m_fileSettings.headerPragmaOnce;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList &CppEditorPlugin::headerSearchPaths()
|
|
|
|
|
{
|
|
|
|
|
return m_instance->d->m_fileSettings.headerSearchPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList &CppEditorPlugin::sourceSearchPaths()
|
|
|
|
|
{
|
|
|
|
|
return m_instance->d->m_fileSettings.sourceSearchPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList &CppEditorPlugin::headerPrefixes()
|
|
|
|
|
{
|
|
|
|
|
return m_instance->d->m_fileSettings.headerPrefixes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList &CppEditorPlugin::sourcePrefixes()
|
|
|
|
|
{
|
|
|
|
|
return m_instance->d->m_fileSettings.sourcePrefixes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppCodeModelSettings *CppEditorPlugin::codeModelSettings()
|
|
|
|
|
{
|
|
|
|
|
return &d->m_codeModelSettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppFileSettings *CppEditorPlugin::fileSettings()
|
|
|
|
|
{
|
|
|
|
|
return &instance()->d->m_fileSettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppEditorPlugin::switchHeaderSource()
|
|
|
|
|
{
|
2021-09-02 08:23:46 +02:00
|
|
|
CppEditor::switchHeaderSource();
|
2021-08-30 10:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppEditorPlugin::switchHeaderSourceInNextSplit()
|
|
|
|
|
{
|
2021-11-01 17:02:02 +01:00
|
|
|
const auto otherFile = FilePath::fromString(
|
|
|
|
|
correspondingHeaderOrSource(EditorManager::currentDocument()->filePath().toString()));
|
2021-08-30 10:58:08 +02:00
|
|
|
if (!otherFile.isEmpty())
|
|
|
|
|
EditorManager::openEditor(otherFile, Id(), EditorManager::OpenInOtherSplit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QStringList findFilesInProject(const QString &name, const Project *project)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << name << project;
|
|
|
|
|
|
|
|
|
|
if (!project)
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
|
|
|
|
QString pattern = QString(1, QLatin1Char('/'));
|
|
|
|
|
pattern += name;
|
|
|
|
|
const QStringList projectFiles
|
|
|
|
|
= transform(project->files(Project::AllFiles), &FilePath::toString);
|
|
|
|
|
const QStringList::const_iterator pcend = projectFiles.constEnd();
|
|
|
|
|
QStringList candidateList;
|
|
|
|
|
for (QStringList::const_iterator it = projectFiles.constBegin(); it != pcend; ++it) {
|
|
|
|
|
if (it->endsWith(pattern, HostOsInfo::fileNameCaseSensitivity()))
|
|
|
|
|
candidateList.append(*it);
|
|
|
|
|
}
|
|
|
|
|
return candidateList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return the suffixes that should be checked when trying to find a
|
|
|
|
|
// source belonging to a header and vice versa
|
|
|
|
|
static QStringList matchingCandidateSuffixes(ProjectFile::Kind kind)
|
|
|
|
|
{
|
|
|
|
|
switch (kind) {
|
|
|
|
|
case ProjectFile::AmbiguousHeader:
|
|
|
|
|
case ProjectFile::CHeader:
|
|
|
|
|
case ProjectFile::CXXHeader:
|
|
|
|
|
case ProjectFile::ObjCHeader:
|
|
|
|
|
case ProjectFile::ObjCXXHeader:
|
|
|
|
|
return mimeTypeForName(Constants::C_SOURCE_MIMETYPE).suffixes()
|
|
|
|
|
+ mimeTypeForName(Constants::CPP_SOURCE_MIMETYPE).suffixes()
|
|
|
|
|
+ mimeTypeForName(Constants::OBJECTIVE_C_SOURCE_MIMETYPE).suffixes()
|
|
|
|
|
+ mimeTypeForName(Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE).suffixes()
|
|
|
|
|
+ mimeTypeForName(Constants::CUDA_SOURCE_MIMETYPE).suffixes();
|
|
|
|
|
case ProjectFile::CSource:
|
|
|
|
|
case ProjectFile::ObjCSource:
|
|
|
|
|
return mimeTypeForName(Constants::C_HEADER_MIMETYPE).suffixes();
|
|
|
|
|
case ProjectFile::CXXSource:
|
|
|
|
|
case ProjectFile::ObjCXXSource:
|
|
|
|
|
case ProjectFile::CudaSource:
|
|
|
|
|
case ProjectFile::OpenCLSource:
|
|
|
|
|
return mimeTypeForName(Constants::CPP_HEADER_MIMETYPE).suffixes();
|
|
|
|
|
default:
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QStringList baseNameWithAllSuffixes(const QString &baseName, const QStringList &suffixes)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
const QChar dot = QLatin1Char('.');
|
|
|
|
|
for (const QString &suffix : suffixes) {
|
|
|
|
|
QString fileName = baseName;
|
|
|
|
|
fileName += dot;
|
|
|
|
|
fileName += suffix;
|
|
|
|
|
result += fileName;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QStringList baseNamesWithAllPrefixes(const QStringList &baseNames, bool isHeader)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
const QStringList &sourcePrefixes = m_instance->sourcePrefixes();
|
|
|
|
|
const QStringList &headerPrefixes = m_instance->headerPrefixes();
|
|
|
|
|
|
|
|
|
|
for (const QString &name : baseNames) {
|
|
|
|
|
for (const QString &prefix : isHeader ? headerPrefixes : sourcePrefixes) {
|
|
|
|
|
if (name.startsWith(prefix)) {
|
|
|
|
|
QString nameWithoutPrefix = name.mid(prefix.size());
|
|
|
|
|
result += nameWithoutPrefix;
|
|
|
|
|
for (const QString &prefix : isHeader ? sourcePrefixes : headerPrefixes)
|
|
|
|
|
result += prefix + nameWithoutPrefix;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const QString &prefix : isHeader ? sourcePrefixes : headerPrefixes)
|
|
|
|
|
result += prefix + name;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QStringList baseDirWithAllDirectories(const QDir &baseDir, const QStringList &directories)
|
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
|
|
|
|
for (const QString &dir : directories)
|
|
|
|
|
result << QDir::cleanPath(baseDir.absoluteFilePath(dir));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int commonFilePathLength(const QString &s1, const QString &s2)
|
|
|
|
|
{
|
|
|
|
|
int length = qMin(s1.length(), s2.length());
|
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
|
if (HostOsInfo::fileNameCaseSensitivity() == Qt::CaseSensitive) {
|
|
|
|
|
if (s1[i] != s2[i])
|
|
|
|
|
return i;
|
|
|
|
|
} else {
|
|
|
|
|
if (s1[i].toLower() != s2[i].toLower())
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
|
|
|
|
|
const QStringList &candidateFileNames,
|
|
|
|
|
const Project *project,
|
|
|
|
|
CacheUsage cacheUsage)
|
|
|
|
|
{
|
|
|
|
|
QString bestFileName;
|
|
|
|
|
int compareValue = 0;
|
|
|
|
|
const QString filePath = fileInfo.filePath();
|
|
|
|
|
for (const QString &candidateFileName : candidateFileNames) {
|
|
|
|
|
const QStringList projectFiles = findFilesInProject(candidateFileName, project);
|
|
|
|
|
// Find the file having the most common path with fileName
|
|
|
|
|
for (const QString &projectFile : projectFiles) {
|
|
|
|
|
int value = commonFilePathLength(filePath, projectFile);
|
|
|
|
|
if (value > compareValue) {
|
|
|
|
|
compareValue = value;
|
|
|
|
|
bestFileName = projectFile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!bestFileName.isEmpty()) {
|
|
|
|
|
const QFileInfo candidateFi(bestFileName);
|
|
|
|
|
QTC_ASSERT(candidateFi.isFile(), return QString());
|
|
|
|
|
if (cacheUsage == CacheUsage::ReadWrite) {
|
|
|
|
|
m_headerSourceMapping[fileInfo.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
|
|
|
|
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fileInfo.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
return candidateFi.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 10:01:27 +02:00
|
|
|
} // namespace Internal
|
2021-08-30 10:58:08 +02:00
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
|
|
|
|
QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader, CacheUsage cacheUsage)
|
|
|
|
|
{
|
|
|
|
|
const QFileInfo fi(fileName);
|
|
|
|
|
ProjectFile::Kind kind = ProjectFile::classify(fileName);
|
|
|
|
|
const bool isHeader = ProjectFile::isHeader(kind);
|
|
|
|
|
if (wasHeader)
|
|
|
|
|
*wasHeader = isHeader;
|
|
|
|
|
if (m_headerSourceMapping.contains(fi.absoluteFilePath()))
|
|
|
|
|
return m_headerSourceMapping.value(fi.absoluteFilePath());
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << fileName << kind;
|
|
|
|
|
|
|
|
|
|
if (kind == ProjectFile::Unsupported)
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
const QString baseName = fi.completeBaseName();
|
|
|
|
|
const QString privateHeaderSuffix = QLatin1String("_p");
|
|
|
|
|
const QStringList suffixes = matchingCandidateSuffixes(kind);
|
|
|
|
|
|
|
|
|
|
QStringList candidateFileNames = baseNameWithAllSuffixes(baseName, suffixes);
|
|
|
|
|
if (isHeader) {
|
|
|
|
|
if (baseName.endsWith(privateHeaderSuffix)) {
|
|
|
|
|
QString sourceBaseName = baseName;
|
|
|
|
|
sourceBaseName.truncate(sourceBaseName.size() - privateHeaderSuffix.size());
|
|
|
|
|
candidateFileNames += baseNameWithAllSuffixes(sourceBaseName, suffixes);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QString privateHeaderBaseName = baseName;
|
|
|
|
|
privateHeaderBaseName.append(privateHeaderSuffix);
|
|
|
|
|
candidateFileNames += baseNameWithAllSuffixes(privateHeaderBaseName, suffixes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QDir absoluteDir = fi.absoluteDir();
|
|
|
|
|
QStringList candidateDirs(absoluteDir.absolutePath());
|
|
|
|
|
// If directory is not root, try matching against its siblings
|
|
|
|
|
const QStringList searchPaths = isHeader ? m_instance->sourceSearchPaths()
|
|
|
|
|
: m_instance->headerSearchPaths();
|
|
|
|
|
candidateDirs += baseDirWithAllDirectories(absoluteDir, searchPaths);
|
|
|
|
|
|
|
|
|
|
candidateFileNames += baseNamesWithAllPrefixes(candidateFileNames, isHeader);
|
|
|
|
|
|
|
|
|
|
// Try to find a file in the same or sibling directories first
|
|
|
|
|
for (const QString &candidateDir : qAsConst(candidateDirs)) {
|
|
|
|
|
for (const QString &candidateFileName : qAsConst(candidateFileNames)) {
|
|
|
|
|
const QString candidateFilePath = candidateDir + QLatin1Char('/') + candidateFileName;
|
|
|
|
|
const QString normalized = FileUtils::normalizedPathName(candidateFilePath);
|
|
|
|
|
const QFileInfo candidateFi(normalized);
|
|
|
|
|
if (candidateFi.isFile()) {
|
|
|
|
|
if (cacheUsage == CacheUsage::ReadWrite) {
|
|
|
|
|
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
|
|
|
|
|
if (!isHeader || !baseName.endsWith(privateHeaderSuffix))
|
|
|
|
|
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
return candidateFi.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find files in the current project
|
|
|
|
|
Project *currentProject = ProjectTree::currentProject();
|
|
|
|
|
if (currentProject) {
|
|
|
|
|
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
|
|
|
|
|
currentProject, cacheUsage);
|
|
|
|
|
if (!path.isEmpty())
|
|
|
|
|
return path;
|
|
|
|
|
|
|
|
|
|
// Find files in other projects
|
|
|
|
|
} else {
|
|
|
|
|
CppModelManager *modelManager = CppModelManager::instance();
|
|
|
|
|
const QList<ProjectInfo::ConstPtr> projectInfos = modelManager->projectInfos();
|
|
|
|
|
for (const ProjectInfo::ConstPtr &projectInfo : projectInfos) {
|
|
|
|
|
const Project *project = projectForProjectInfo(*projectInfo);
|
|
|
|
|
if (project == currentProject)
|
|
|
|
|
continue; // We have already checked the current project.
|
|
|
|
|
|
|
|
|
|
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
|
|
|
|
|
project, cacheUsage);
|
|
|
|
|
if (!path.isEmpty())
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 10:01:27 +02:00
|
|
|
} // namespace CppEditor
|