forked from qt-creator/qt-creator
CppEditor: Simplify setup of global file settings
Change-Id: Icef29d5ac7417bf59a21318a1fa13750f2136221 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -180,8 +180,7 @@ public:
|
||||
|
||||
CppModelManager modelManager;
|
||||
CppToolsSettings settings;
|
||||
CppFileSettings m_fileSettings;
|
||||
CppFileSettingsPage m_cppFileSettingsPage{&m_fileSettings};
|
||||
CppFileSettingsPage m_cppFileSettingsPage;
|
||||
CppCodeModelSettingsPage m_cppCodeModelSettingsPage;
|
||||
CppCodeStyleSettingsPage m_cppCodeStyleSettingsPage;
|
||||
CppProjectUpdaterFactory m_cppProjectUpdaterFactory;
|
||||
@@ -231,16 +230,13 @@ void CppEditorPlugin::initialize()
|
||||
void CppEditorPlugin::extensionsInitialized()
|
||||
{
|
||||
setupCppQuickFixProjectPanel();
|
||||
setupCppFileSettingsProjectPanel();
|
||||
setupCppFileSettings();
|
||||
|
||||
if (CppModelManager::isClangCodeModelActive()) {
|
||||
setupClangdProjectSettingsPanel();
|
||||
setupClangdSettingsPage();
|
||||
}
|
||||
|
||||
d->m_fileSettings.fromSettings(ICore::settings());
|
||||
d->m_fileSettings.addMimeInitializer();
|
||||
|
||||
// Add the hover handler factories here instead of in initialize()
|
||||
// so that the Clang Code Model has a chance to hook in.
|
||||
d->m_cppEditorFactory.addHoverHandler(CppModelManager::createHoverHandler());
|
||||
@@ -622,17 +618,10 @@ bool CppEditorPlugin::usePragmaOnce(Project *project)
|
||||
CppFileSettings CppEditorPlugin::fileSettings(Project *project)
|
||||
{
|
||||
if (!project)
|
||||
return instance()->d->m_fileSettings;
|
||||
return globalCppFileSettings();
|
||||
return CppFileSettingsForProject(project).settings();
|
||||
}
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
void CppEditorPlugin::setGlobalFileSettings(const CppFileSettings &settings)
|
||||
{
|
||||
instance()->d->m_fileSettings = settings;
|
||||
}
|
||||
#endif
|
||||
|
||||
static FilePaths findFilesInProject(const QStringList &names, const Project *project,
|
||||
FileType fileType)
|
||||
{
|
||||
|
@@ -37,9 +37,6 @@ public:
|
||||
void switchDeclarationDefinition();
|
||||
|
||||
static CppFileSettings fileSettings(ProjectExplorer::Project *project);
|
||||
#ifdef WITH_TESTS
|
||||
static void setGlobalFileSettings(const CppFileSettings &settings);
|
||||
#endif
|
||||
|
||||
signals:
|
||||
void typeHierarchyRequested();
|
||||
|
@@ -450,14 +450,14 @@ void CppFileSettingsWidget::slotEdit()
|
||||
Core::EditorManager::openEditor(path, CppEditor::Constants::CPPEDITOR_ID);
|
||||
}
|
||||
|
||||
// --------------- CppFileSettingsPage
|
||||
// CppFileSettingsPage
|
||||
|
||||
CppFileSettingsPage::CppFileSettingsPage(CppFileSettings *settings)
|
||||
CppFileSettingsPage::CppFileSettingsPage()
|
||||
{
|
||||
setId(Constants::CPP_FILE_SETTINGS_ID);
|
||||
setDisplayName(Tr::tr("File Naming"));
|
||||
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
||||
setWidgetCreator([settings] { return new CppFileSettingsWidget(settings); });
|
||||
setWidgetCreator([] { return new CppFileSettingsWidget(&globalCppFileSettings()); });
|
||||
}
|
||||
|
||||
CppFileSettingsForProject::CppFileSettingsForProject(ProjectExplorer::Project *project)
|
||||
@@ -468,7 +468,7 @@ CppFileSettingsForProject::CppFileSettingsForProject(ProjectExplorer::Project *p
|
||||
|
||||
CppFileSettings CppFileSettingsForProject::settings() const
|
||||
{
|
||||
return m_useGlobalSettings ? CppEditorPlugin::fileSettings(nullptr) : m_customSettings;
|
||||
return m_useGlobalSettings ? globalCppFileSettings() : m_customSettings;
|
||||
}
|
||||
|
||||
void CppFileSettingsForProject::setSettings(const CppFileSettings &settings)
|
||||
@@ -600,9 +600,19 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void setupCppFileSettingsProjectPanel()
|
||||
void setupCppFileSettings()
|
||||
{
|
||||
static CppFileSettingsProjectPanelFactory theCppFileSettingsProjectPanelFactory;
|
||||
|
||||
globalCppFileSettings().fromSettings(Core::ICore::settings());
|
||||
globalCppFileSettings().addMimeInitializer();
|
||||
}
|
||||
|
||||
CppFileSettings &globalCppFileSettings()
|
||||
{
|
||||
// This is the global instance. There could be more.
|
||||
static CppFileSettings theGlobalCppFileSettings;
|
||||
return theGlobalCppFileSettings;
|
||||
}
|
||||
|
||||
} // namespace CppEditor::Internal
|
||||
|
@@ -71,7 +71,7 @@ private:
|
||||
class CppFileSettingsPage : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
explicit CppFileSettingsPage(CppFileSettings *settings);
|
||||
CppFileSettingsPage();
|
||||
};
|
||||
|
||||
class CppFileSettingsForProjectWidget : public ProjectExplorer::ProjectSettingsWidget
|
||||
@@ -85,6 +85,8 @@ private:
|
||||
Private * const d;
|
||||
};
|
||||
|
||||
void setupCppFileSettingsProjectPanel();
|
||||
CppFileSettings &globalCppFileSettings();
|
||||
|
||||
void setupCppFileSettings();
|
||||
|
||||
} // namespace CppEditor::Internal
|
||||
|
@@ -71,27 +71,25 @@ void HeaderSourceTest::test_data()
|
||||
void HeaderSourceTest::initTestCase()
|
||||
{
|
||||
QDir(baseTestDir()).mkpath(_("."));
|
||||
CppFileSettings fs = CppEditorPlugin::fileSettings(nullptr);
|
||||
CppFileSettings &fs = globalCppFileSettings();
|
||||
fs.headerSearchPaths.append(QLatin1String("include"));
|
||||
fs.headerSearchPaths.append(QLatin1String("../include"));
|
||||
fs.sourceSearchPaths.append(QLatin1String("src"));
|
||||
fs.sourceSearchPaths.append(QLatin1String("../src"));
|
||||
fs.headerPrefixes.append(QLatin1String("testh_"));
|
||||
fs.sourcePrefixes.append(QLatin1String("testc_"));
|
||||
CppEditorPlugin::setGlobalFileSettings(fs);
|
||||
}
|
||||
|
||||
void HeaderSourceTest::cleanupTestCase()
|
||||
{
|
||||
Utils::FilePath::fromString(baseTestDir()).removeRecursively();
|
||||
CppFileSettings fs = CppEditorPlugin::fileSettings(nullptr);
|
||||
CppFileSettings &fs = globalCppFileSettings();
|
||||
fs.headerSearchPaths.removeLast();
|
||||
fs.headerSearchPaths.removeLast();
|
||||
fs.sourceSearchPaths.removeLast();
|
||||
fs.sourceSearchPaths.removeLast();
|
||||
fs.headerPrefixes.removeLast();
|
||||
fs.sourcePrefixes.removeLast();
|
||||
CppEditorPlugin::setGlobalFileSettings(fs);
|
||||
}
|
||||
|
||||
} // namespace CppEditor::Internal
|
||||
|
Reference in New Issue
Block a user