forked from qt-creator/qt-creator
ClangFormat: Use the constant for the configuration filename
It is unlikely that this name changes but let's follow good coding practices. Change-Id: I12adbf155f26b1b3a02d07092fcc113e0c5157e6 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "clangformatconfigwidget.h"
|
#include "clangformatconfigwidget.h"
|
||||||
|
|
||||||
|
#include "clangformatconstants.h"
|
||||||
#include "clangformatutils.h"
|
#include "clangformatutils.h"
|
||||||
#include "ui_clangformatconfigwidget.h"
|
#include "ui_clangformatconfigwidget.h"
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ void ClangFormatConfigWidget::initialize()
|
|||||||
m_ui->clangFormatOptionsTable->show();
|
m_ui->clangFormatOptionsTable->show();
|
||||||
m_ui->applyButton->show();
|
m_ui->applyButton->show();
|
||||||
|
|
||||||
if (m_project && !m_project->projectDirectory().appendPath(".clang-format").exists()) {
|
if (m_project && !m_project->projectDirectory().appendPath(SETTINGS_FILE_NAME).exists()) {
|
||||||
m_ui->projectHasClangFormat->setText(tr("No .clang-format file for the project."));
|
m_ui->projectHasClangFormat->setText(tr("No .clang-format file for the project."));
|
||||||
m_ui->clangFormatOptionsTable->hide();
|
m_ui->clangFormatOptionsTable->hide();
|
||||||
m_ui->applyButton->hide();
|
m_ui->applyButton->hide();
|
||||||
@@ -152,7 +153,7 @@ void ClangFormatConfigWidget::initialize()
|
|||||||
} else {
|
} else {
|
||||||
const Project *currentProject = SessionManager::startupProject();
|
const Project *currentProject = SessionManager::startupProject();
|
||||||
if (!currentProject
|
if (!currentProject
|
||||||
|| !currentProject->projectDirectory().appendPath(".clang-format").exists()) {
|
|| !currentProject->projectDirectory().appendPath(SETTINGS_FILE_NAME).exists()) {
|
||||||
m_ui->projectHasClangFormat->hide();
|
m_ui->projectHasClangFormat->hide();
|
||||||
} else {
|
} else {
|
||||||
m_ui->projectHasClangFormat->setText(
|
m_ui->projectHasClangFormat->setText(
|
||||||
@@ -184,9 +185,9 @@ void ClangFormatConfigWidget::apply()
|
|||||||
const QByteArray text = tableToYAML(m_ui->clangFormatOptionsTable);
|
const QByteArray text = tableToYAML(m_ui->clangFormatOptionsTable);
|
||||||
QString filePath;
|
QString filePath;
|
||||||
if (m_project)
|
if (m_project)
|
||||||
filePath = m_project->projectDirectory().appendPath(".clang-format").toString();
|
filePath = m_project->projectDirectory().appendPath(SETTINGS_FILE_NAME).toString();
|
||||||
else
|
else
|
||||||
filePath = Core::ICore::userResourcePath() + "/.clang-format";
|
filePath = Core::ICore::userResourcePath() + "/" + SETTINGS_FILE_NAME;
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (!file.open(QFile::WriteOnly))
|
if (!file.open(QFile::WriteOnly))
|
||||||
return;
|
return;
|
||||||
|
@@ -24,3 +24,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
namespace ClangFormat {
|
||||||
|
static const char SETTINGS_FILE_NAME[] = ".clang-format";
|
||||||
|
}
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "clangformatutils.h"
|
#include "clangformatutils.h"
|
||||||
|
|
||||||
|
#include "clangformatconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <cpptools/cppcodestylesettings.h>
|
#include <cpptools/cppcodestylesettings.h>
|
||||||
#include <texteditor/tabsettings.h>
|
#include <texteditor/tabsettings.h>
|
||||||
@@ -134,7 +136,7 @@ static clang::format::FormatStyle constructStyle(bool isGlobal)
|
|||||||
|
|
||||||
void createStyleFileIfNeeded(Utils::FileName styleConfigPath, bool isGlobal)
|
void createStyleFileIfNeeded(Utils::FileName styleConfigPath, bool isGlobal)
|
||||||
{
|
{
|
||||||
const QString configFile = styleConfigPath.appendPath(".clang-format").toString();
|
const QString configFile = styleConfigPath.appendPath(SETTINGS_FILE_NAME).toString();
|
||||||
if (QFile::exists(configFile))
|
if (QFile::exists(configFile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -175,7 +177,7 @@ clang::format::FormatStyle currentGlobalStyle()
|
|||||||
static bool isCurrentStyleGlobal()
|
static bool isCurrentStyleGlobal()
|
||||||
{
|
{
|
||||||
Utils::FileName path = projectStylePath();
|
Utils::FileName path = projectStylePath();
|
||||||
if (path.appendPath(".clang-format").exists())
|
if (path.appendPath(SETTINGS_FILE_NAME).exists())
|
||||||
return false;
|
return false;
|
||||||
return !CppCodeStyleSettings::currentProjectCodeStyle().has_value();
|
return !CppCodeStyleSettings::currentProjectCodeStyle().has_value();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user