Beautifier: Remove inner namespace level

And inline non-shared object id.

I regularly stumble over this speciality when doing mass refactorings
in the code base and I believe the extra benefit this namespace level
has does not outweigh it.

Change-Id: I3694a656f1095dcb5509b212b9e1d25ae5c8b5ec
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-06-17 08:33:53 +02:00
parent e064100007
commit c9a7a3a2d3
25 changed files with 44 additions and 107 deletions

View File

@@ -58,16 +58,14 @@ using namespace TextEditor;
namespace Beautifier {
namespace Internal {
namespace ArtisticStyle {
ArtisticStyle::ArtisticStyle()
{
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::ArtisticStyle::MENU_ID);
Core::ActionContainer *menu = Core::ActionManager::createMenu("ArtisticStyle.Menu");
menu->menu()->setTitle(tr("&Artistic Style"));
m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this);
menu->addAction(Core::ActionManager::registerAction(m_formatFile,
Constants::ArtisticStyle::ACTION_FORMATFILE));
menu->addAction(Core::ActionManager::registerAction(m_formatFile, "ArtisticStyle.FormatFile"));
connect(m_formatFile, &QAction::triggered, this, &ArtisticStyle::formatFile);
Core::ActionManager::actionContainer(Constants::MENU_ID)->addMenu(menu);
@@ -78,7 +76,7 @@ ArtisticStyle::ArtisticStyle()
QString ArtisticStyle::id() const
{
return QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME);
return QLatin1String(Constants::ARTISTICSTYLE_DISPLAY_NAME);
}
void ArtisticStyle::updateActions(Core::IEditor *editor)
@@ -91,7 +89,7 @@ void ArtisticStyle::formatFile()
const QString cfgFileName = configurationFile();
if (cfgFileName.isEmpty()) {
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
tr(Constants::ArtisticStyle::DISPLAY_NAME)));
tr(Constants::ARTISTICSTYLE_DISPLAY_NAME)));
} else {
formatCurrentFile(command(cfgFileName));
}
@@ -166,6 +164,5 @@ Command ArtisticStyle::command(const QString &cfgFile) const
return command;
}
} // namespace ArtisticStyle
} // namespace Internal
} // namespace Beautifier

View File

@@ -32,7 +32,6 @@
namespace Beautifier {
namespace Internal {
namespace ArtisticStyle {
class ArtisticStyle : public BeautifierAbstractTool
{
@@ -56,6 +55,5 @@ private:
ArtisticStyleOptionsPage m_page{&m_settings};
};
} // namespace ArtisticStyle
} // namespace Internal
} // namespace Beautifier

View File

@@ -29,14 +29,8 @@
namespace Beautifier {
namespace Constants {
namespace ArtisticStyle {
const char DISPLAY_NAME[] = QT_TRANSLATE_NOOP("Beautifier::Internal::ArtisticStyle::ArtisticStyle", "Artistic Style");
const char ACTION_FORMATFILE[] = "ArtisticStyle.FormatFile";
const char MENU_ID[] = "ArtisticStyle.Menu";
const char OPTION_ID[] = "ArtisticStyle";
const char SETTINGS_NAME[] = "artisticstyle";
const char ARTISTICSTYLE_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("Beautifier::Internal", "Artistic Style");
} // namespace ArtisticStyle
} // namespace Constants
} // namespace Beautifier

View File

@@ -35,7 +35,6 @@
namespace Beautifier {
namespace Internal {
namespace ArtisticStyle {
class ArtisticStyleOptionsPageWidget : public Core::IOptionsPageWidget
{
@@ -62,7 +61,7 @@ ArtisticStyleOptionsPageWidget::ArtisticStyleOptionsPageWidget(ArtisticStyleSett
ui.command->setExpectedKind(Utils::PathChooser::ExistingCommand);
ui.command->setCommandVersionArguments({"--version"});
ui.command->setPromptDialogTitle(BeautifierPlugin::msgCommandPromptDialogTitle(
ArtisticStyle::tr(Constants::ArtisticStyle::DISPLAY_NAME)));
ArtisticStyle::tr(Constants::ARTISTICSTYLE_DISPLAY_NAME)));
connect(ui.command, &Utils::PathChooser::validChanged, ui.options, &QWidget::setEnabled);
ui.configurations->setSettings(m_settings);
@@ -94,12 +93,11 @@ void ArtisticStyleOptionsPageWidget::apply()
ArtisticStyleOptionsPage::ArtisticStyleOptionsPage(ArtisticStyleSettings *settings)
{
setId(Constants::ArtisticStyle::OPTION_ID);
setId("ArtisticStyle");
setDisplayName(ArtisticStyleOptionsPageWidget::tr("Artistic Style"));
setCategory(Constants::OPTION_CATEGORY);
setWidgetCreator([settings] { return new ArtisticStyleOptionsPageWidget(settings); });
}
} // namespace ArtisticStyle
} // namespace Internal
} // namespace Beautifier

View File

@@ -29,7 +29,6 @@
namespace Beautifier {
namespace Internal {
namespace ArtisticStyle {
class ArtisticStyleSettings;
@@ -39,6 +38,5 @@ public:
explicit ArtisticStyleOptionsPage(ArtisticStyleSettings *settings);
};
} // namespace ArtisticStyle
} // namespace Internal
} // namespace Beautifier

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Beautifier::Internal::ArtisticStyle::ArtisticStyleOptionsPage</class>
<widget class="QWidget" name="Beautifier::Internal::ArtisticStyle::ArtisticStyleOptionsPage">
<class>Beautifier::Internal::ArtisticStyleOptionsPage</class>
<widget class="QWidget" name="Beautifier::Internal::ArtisticStyleOptionsPage">
<property name="geometry">
<rect>
<x>0</x>

View File

@@ -43,19 +43,17 @@
namespace Beautifier {
namespace Internal {
namespace ArtisticStyle {
namespace {
const char USE_OTHER_FILES[] = "useOtherFiles";
const char USE_SPECIFIC_CONFIG_FILE[] = "useSpecificConfigFile";
const char SPECIFIC_CONFIG_FILE[] = "specificConfigFile";
const char USE_HOME_FILE[] = "useHomeFile";
const char USE_CUSTOM_STYLE[] = "useCustomStyle";
const char CUSTOM_STYLE[] = "customStyle";
}
const char SETTINGS_NAME[] = "artisticstyle";
ArtisticStyleSettings::ArtisticStyleSettings() :
AbstractSettings(Constants::ArtisticStyle::SETTINGS_NAME, ".astyle")
AbstractSettings(SETTINGS_NAME, ".astyle")
{
connect(&m_versionWatcher, &QFutureWatcherBase::finished,
this, &ArtisticStyleSettings::helperSetVersion);
@@ -175,7 +173,7 @@ QString ArtisticStyleSettings::documentationFilePath() const
{
return Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME + '/'
+ Beautifier::Constants::DOCUMENTATION_DIRNAME + '/'
+ Constants::ArtisticStyle::SETTINGS_NAME + ".xml";
+ SETTINGS_NAME + ".xml";
}
void ArtisticStyleSettings::createDocumentationFile() const
@@ -250,6 +248,5 @@ void ArtisticStyleSettings::createDocumentationFile() const
}
}
} // namespace ArtisticStyle
} // namespace Internal
} // namespace Beautifier

View File

@@ -34,7 +34,6 @@
namespace Beautifier {
namespace Internal {
namespace ArtisticStyle {
class ArtisticStyleSettings : public AbstractSettings
{
@@ -77,6 +76,5 @@ private:
QFutureWatcher<int> m_versionWatcher;
};
} // namespace ArtisticStyle
} // namespace Internal
} // namespace Beautifier

View File

@@ -98,9 +98,9 @@ public:
GeneralSettings generalSettings;
ArtisticStyle::ArtisticStyle artisticStyleBeautifier;
ClangFormat::ClangFormat clangFormatBeautifier;
Uncrustify::Uncrustify uncrustifyBeautifier;
ArtisticStyle artisticStyleBeautifier;
ClangFormat clangFormatBeautifier;
Uncrustify uncrustifyBeautifier;
BeautifierAbstractTool *m_tools[3] {
&artisticStyleBeautifier,

View File

@@ -53,35 +53,34 @@ using namespace TextEditor;
namespace Beautifier {
namespace Internal {
namespace ClangFormat {
const char MENU_ID[] = "ClangFormat.Menu";
ClangFormat::ClangFormat()
{
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::ClangFormat::MENU_ID);
Core::ActionContainer *menu = Core::ActionManager::createMenu(MENU_ID);
menu->menu()->setTitle(tr("&ClangFormat"));
m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this);
Core::Command *cmd
= Core::ActionManager::registerAction(m_formatFile,
Constants::ClangFormat::ACTION_FORMATFILE);
= Core::ActionManager::registerAction(m_formatFile, "ClangFormat.FormatFile");
menu->addAction(cmd);
connect(m_formatFile, &QAction::triggered, this, &ClangFormat::formatFile);
m_formatRange = new QAction(BeautifierPlugin::msgFormatAtCursor(), this);
cmd = Core::ActionManager::registerAction(m_formatRange,
Constants::ClangFormat::ACTION_FORMATATCURSOR);
cmd = Core::ActionManager::registerAction(m_formatRange, "ClangFormat.FormatAtCursor");
menu->addAction(cmd);
connect(m_formatRange, &QAction::triggered, this, &ClangFormat::formatAtCursor);
m_disableFormattingSelectedText
= new QAction(BeautifierPlugin::msgDisableFormattingSelectedText(), this);
cmd = Core::ActionManager::registerAction(
m_disableFormattingSelectedText, Constants::ClangFormat::ACTION_DISABLEFORMATTINGSELECTED);
m_disableFormattingSelectedText, "ClangFormat.DisableFormattingSelectedText");
menu->addAction(cmd);
connect(m_disableFormattingSelectedText, &QAction::triggered,
this, &ClangFormat::disableFormattingSelectedText);
Core::ActionManager::actionContainer(Constants::MENU_ID)->addMenu(menu);
Core::ActionManager::actionContainer(MENU_ID)->addMenu(menu);
connect(&m_settings, &ClangFormatSettings::supportedMimeTypesChanged,
[this] { updateActions(Core::EditorManager::currentEditor()); });
@@ -89,7 +88,7 @@ ClangFormat::ClangFormat()
QString ClangFormat::id() const
{
return QLatin1String(Constants::ClangFormat::DISPLAY_NAME);
return QLatin1String(Constants::CLANGFORMAT_DISPLAY_NAME);
}
void ClangFormat::updateActions(Core::IEditor *editor)
@@ -200,6 +199,5 @@ Command ClangFormat::command(int offset, int length) const
return c;
}
} // namespace ClangFormat
} // namespace Internal
} // namespace Beautifier

View File

@@ -32,7 +32,6 @@
namespace Beautifier {
namespace Internal {
namespace ClangFormat {
class ClangFormat : public BeautifierAbstractTool
{
@@ -59,6 +58,5 @@ private:
ClangFormatOptionsPage m_page{&m_settings};
};
} // namespace ClangFormat
} // namespace Internal
} // namespace Beautifier

View File

@@ -29,16 +29,8 @@
namespace Beautifier {
namespace Constants {
namespace ClangFormat {
const char DISPLAY_NAME[] = QT_TRANSLATE_NOOP("Beautifier::Internal::ClangFormat::ClangFormat", "ClangFormat");
const char ACTION_FORMATFILE[] = "ClangFormat.FormatFile";
const char ACTION_FORMATATCURSOR[] = "ClangFormat.FormatAtCursor";
const char ACTION_DISABLEFORMATTINGSELECTED[] = "ClangFormat.DisableFormattingSelectedText";
const char MENU_ID[] = "ClangFormat.Menu";
const char OPTION_ID[] = "ClangFormat";
const char SETTINGS_NAME[] = "clangformat";
const char CLANGFORMAT_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("Beautifier::Internal::ClangFormat", "ClangFormat");
} // namespace ClangFormat
} // namespace Constants
} // namespace Beautifier

View File

@@ -34,7 +34,6 @@
namespace Beautifier {
namespace Internal {
namespace ClangFormat {
class ClangFormatOptionsPageWidget : public Core::IOptionsPageWidget
{
@@ -104,12 +103,11 @@ void ClangFormatOptionsPageWidget::apply()
ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings)
{
setId(Constants::ClangFormat::OPTION_ID);
setId("ClangFormat");
setDisplayName(ClangFormatOptionsPageWidget::tr("Clang Format"));
setCategory(Constants::OPTION_CATEGORY);
setWidgetCreator([settings] { return new ClangFormatOptionsPageWidget(settings); });
}
} // namespace ClangFormat
} // namespace Internal
} // namespace Beautifier

View File

@@ -29,7 +29,6 @@
namespace Beautifier {
namespace Internal {
namespace ClangFormat {
class ClangFormatSettings;
@@ -39,6 +38,5 @@ public:
explicit ClangFormatOptionsPage(ClangFormatSettings *settings);
};
} // namespace ClangFormat
} // namespace Internal
} // namespace Beautifier

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Beautifier::Internal::ClangFormat::ClangFormatOptionsPage</class>
<widget class="QWidget" name="Beautifier::Internal::ClangFormat::ClangFormatOptionsPage">
<class>Beautifier::Internal::ClangFormatOptionsPage</class>
<widget class="QWidget" name="Beautifier::Internal::ClangFormatOptionsPage">
<property name="geometry">
<rect>
<x>0</x>

View File

@@ -36,17 +36,15 @@
namespace Beautifier {
namespace Internal {
namespace ClangFormat {
namespace {
const char USE_PREDEFINED_STYLE[] = "usePredefinedStyle";
const char PREDEFINED_STYLE[] = "predefinedStyle";
const char FALLBACK_STYLE[] = "fallbackStyle";
const char CUSTOM_STYLE[] = "customStyle";
}
const char SETTINGS_NAME[] = "clangformat";
ClangFormatSettings::ClangFormatSettings() :
AbstractSettings(Constants::ClangFormat::SETTINGS_NAME, ".clang-format")
AbstractSettings(SETTINGS_NAME, ".clang-format")
{
setCommand("clang-format");
m_settings.insert(USE_PREDEFINED_STYLE, QVariant(true));
@@ -60,7 +58,7 @@ QString ClangFormatSettings::documentationFilePath() const
{
return Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME + '/'
+ Beautifier::Constants::DOCUMENTATION_DIRNAME + '/'
+ Constants::ClangFormat::SETTINGS_NAME + ".xml";
+ SETTINGS_NAME + ".xml";
}
void ClangFormatSettings::createDocumentationFile() const
@@ -238,6 +236,5 @@ void ClangFormatSettings::readStyles()
}
}
} // namespace ClangFormat
} // namespace Internal
} // namespace Beautifier

View File

@@ -29,7 +29,6 @@
namespace Beautifier {
namespace Internal {
namespace ClangFormat {
class ClangFormatSettings : public AbstractSettings
{
@@ -63,6 +62,5 @@ private:
void readStyles() override;
};
} // namespace ClangFormat
} // namespace Internal
} // namespace Beautifier

View File

@@ -54,23 +54,20 @@ using namespace TextEditor;
namespace Beautifier {
namespace Internal {
namespace Uncrustify {
Uncrustify::Uncrustify()
{
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::Uncrustify::MENU_ID);
Core::ActionContainer *menu = Core::ActionManager::createMenu("Uncrustify.Menu");
menu->menu()->setTitle(tr("&Uncrustify"));
m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this);
Core::Command *cmd
= Core::ActionManager::registerAction(m_formatFile,
Constants::Uncrustify::ACTION_FORMATFILE);
= Core::ActionManager::registerAction(m_formatFile, "Uncrustify.FormatFile");
menu->addAction(cmd);
connect(m_formatFile, &QAction::triggered, this, &Uncrustify::formatFile);
m_formatRange = new QAction(BeautifierPlugin::msgFormatSelectedText(), this);
cmd = Core::ActionManager::registerAction(m_formatRange,
Constants::Uncrustify::ACTION_FORMATSELECTED);
cmd = Core::ActionManager::registerAction(m_formatRange, "Uncrustify.FormatSelectedText");
menu->addAction(cmd);
connect(m_formatRange, &QAction::triggered, this, &Uncrustify::formatSelectedText);
@@ -82,7 +79,7 @@ Uncrustify::Uncrustify()
QString Uncrustify::id() const
{
return QLatin1String(Constants::Uncrustify::DISPLAY_NAME);
return QLatin1String(Constants::UNCRUSTIFY_DISPLAY_NAME);
}
void Uncrustify::updateActions(Core::IEditor *editor)
@@ -97,7 +94,7 @@ void Uncrustify::formatFile()
const QString cfgFileName = configurationFile();
if (cfgFileName.isEmpty()) {
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
tr(Constants::Uncrustify::DISPLAY_NAME)));
tr(Constants::UNCRUSTIFY_DISPLAY_NAME)));
} else {
formatCurrentFile(command(cfgFileName));
}
@@ -108,7 +105,7 @@ void Uncrustify::formatSelectedText()
const QString cfgFileName = configurationFile();
if (cfgFileName.isEmpty()) {
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
tr(Constants::Uncrustify::DISPLAY_NAME)));
tr(Constants::UNCRUSTIFY_DISPLAY_NAME)));
return;
}
@@ -199,6 +196,5 @@ Command Uncrustify::command(const QString &cfgFile, bool fragment) const
return command;
}
} // namespace Uncrustify
} // namespace Internal
} // namespace Beautifier

View File

@@ -32,7 +32,6 @@
namespace Beautifier {
namespace Internal {
namespace Uncrustify {
class Uncrustify : public BeautifierAbstractTool
{
@@ -58,6 +57,5 @@ private:
UncrustifyOptionsPage m_page{&m_settings};
};
} // namespace Uncrustify
} // namespace Internal
} // namespace Beautifier

View File

@@ -29,15 +29,8 @@
namespace Beautifier {
namespace Constants {
namespace Uncrustify {
const char DISPLAY_NAME[] = QT_TRANSLATE_NOOP("Beautifier::Internal::Uncrustify::Uncrustify", "Uncrustify");
const char ACTION_FORMATFILE[] = "Uncrustify.FormatFile";
const char ACTION_FORMATSELECTED[] = "Uncrustify.FormatSelectedText";
const char MENU_ID[] = "Uncrustify.Menu";
const char OPTION_ID[] = "Uncrustify";
const char SETTINGS_NAME[] = "uncrustify";
const char UNCRUSTIFY_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("Beautifier::Internal", "Uncrustify");
} // namespace Uncrustify
} // namespace Constants
} // namespace Beautifier

View File

@@ -35,7 +35,6 @@
namespace Beautifier {
namespace Internal {
namespace Uncrustify {
class UncrustifyOptionsPageWidget : public Core::IOptionsPageWidget
{
@@ -63,7 +62,7 @@ UncrustifyOptionsPageWidget::UncrustifyOptionsPageWidget(UncrustifySettings *set
ui.command->setExpectedKind(Utils::PathChooser::ExistingCommand);
ui.command->setCommandVersionArguments({"--version"});
ui.command->setPromptDialogTitle(BeautifierPlugin::msgCommandPromptDialogTitle(
Uncrustify::tr(Constants::Uncrustify::DISPLAY_NAME)));
Uncrustify::tr(Constants::UNCRUSTIFY_DISPLAY_NAME)));
connect(ui.command, &Utils::PathChooser::validChanged, ui.options, &QWidget::setEnabled);
ui.configurations->setSettings(m_settings);
@@ -97,12 +96,11 @@ void UncrustifyOptionsPageWidget::apply()
UncrustifyOptionsPage::UncrustifyOptionsPage(UncrustifySettings *settings)
{
setId(Constants::Uncrustify::OPTION_ID);
setId("Uncrustify");
setDisplayName(UncrustifyOptionsPageWidget::tr("Uncrustify"));
setCategory(Constants::OPTION_CATEGORY);
setWidgetCreator([settings] { return new UncrustifyOptionsPageWidget(settings); });
}
} // namespace Uncrustify
} // namespace Internal
} // namespace Beautifier

View File

@@ -29,7 +29,6 @@
namespace Beautifier {
namespace Internal {
namespace Uncrustify {
class UncrustifySettings;
@@ -39,6 +38,5 @@ public:
explicit UncrustifyOptionsPage(UncrustifySettings *settings);
};
} // namespace Uncrustify
} // namespace Internal
} // namespace Beautifier

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Beautifier::Internal::Uncrustify::UncrustifyOptionsPage</class>
<widget class="QWidget" name="Beautifier::Internal::Uncrustify::UncrustifyOptionsPage">
<class>Beautifier::Internal::UncrustifyOptionsPage</class>
<widget class="QWidget" name="Beautifier::Internal::UncrustifyOptionsPage">
<property name="geometry">
<rect>
<x>0</x>

View File

@@ -41,9 +41,7 @@
namespace Beautifier {
namespace Internal {
namespace Uncrustify {
namespace {
const char USE_OTHER_FILES[] = "useOtherFiles";
const char USE_HOME_FILE[] = "useHomeFile";
const char USE_SPECIFIC_CONFIG_FILE_PATH[] = "useSpecificConfigFile";
@@ -51,10 +49,10 @@ const char SPECIFIC_CONFIG_FILE_PATH[] = "specificConfigFile";
const char USE_CUSTOM_STYLE[] = "useCustomStyle";
const char CUSTOM_STYLE[] = "customStyle";
const char FORMAT_ENTIRE_FILE_FALLBACK[] = "formatEntireFileFallback";
}
const char SETTINGS_NAME[] = "uncrustify";
UncrustifySettings::UncrustifySettings() :
AbstractSettings(Constants::Uncrustify::SETTINGS_NAME, ".cfg")
AbstractSettings(SETTINGS_NAME, ".cfg")
{
connect(&m_versionProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &UncrustifySettings::parseVersionProcessResult);
@@ -144,7 +142,7 @@ QString UncrustifySettings::documentationFilePath() const
{
return Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME + '/'
+ Beautifier::Constants::DOCUMENTATION_DIRNAME + '/'
+ Constants::Uncrustify::SETTINGS_NAME + ".xml";
+ SETTINGS_NAME + ".xml";
}
void UncrustifySettings::createDocumentationFile() const
@@ -243,6 +241,5 @@ void UncrustifySettings::parseVersionProcessResult(int exitCode, QProcess::ExitS
parseVersion(QString::fromUtf8(m_versionProcess.readAllStandardError()), m_version);
}
} // namespace Uncrustify
} // namespace Internal
} // namespace Beautifier

View File

@@ -31,7 +31,6 @@
namespace Beautifier {
namespace Internal {
namespace Uncrustify {
class UncrustifySettings : public AbstractSettings
{
@@ -71,6 +70,5 @@ private:
void parseVersionProcessResult(int exitCode, QProcess::ExitStatus exitStatus);
};
} // namespace Uncrustify
} // namespace Internal
} // namespace Beautifier