forked from qt-creator/qt-creator
ProjectExplorer: Use new construction pattern for some project panels
Change-Id: I0c7cd43a2fcd9480cab06270a4fee295cf5a5fc1 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
#include "editorconfiguration.h"
|
#include "editorconfiguration.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "projectexplorertr.h"
|
#include "projectexplorertr.h"
|
||||||
|
#include "projectpanelfactory.h"
|
||||||
|
#include "projectsettingswidget.h"
|
||||||
|
|
||||||
#include <cppeditor/cppeditorconstants.h>
|
#include <cppeditor/cppeditorconstants.h>
|
||||||
|
|
||||||
@@ -17,44 +19,64 @@
|
|||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLayout>
|
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace ProjectExplorer::Internal {
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project)
|
class CodeStyleSettingsWidget final : public ProjectSettingsWidget
|
||||||
{
|
{
|
||||||
auto languageComboBox = new QComboBox(this);
|
public:
|
||||||
auto stackedWidget = new QStackedWidget(this);
|
explicit CodeStyleSettingsWidget(Project *project)
|
||||||
|
{
|
||||||
|
auto languageComboBox = new QComboBox(this);
|
||||||
|
auto stackedWidget = new QStackedWidget(this);
|
||||||
|
|
||||||
setGlobalSettingsId(CppEditor::Constants::CPP_CODE_STYLE_SETTINGS_ID);
|
setGlobalSettingsId(CppEditor::Constants::CPP_CODE_STYLE_SETTINGS_ID);
|
||||||
setUseGlobalSettingsCheckBoxVisible(false);
|
setUseGlobalSettingsCheckBoxVisible(false);
|
||||||
|
|
||||||
const EditorConfiguration *config = project->editorConfiguration();
|
const EditorConfiguration *config = project->editorConfiguration();
|
||||||
|
|
||||||
for (ICodeStylePreferencesFactory *factory : TextEditorSettings::codeStyleFactories()) {
|
for (ICodeStylePreferencesFactory *factory : TextEditorSettings::codeStyleFactories()) {
|
||||||
Utils::Id languageId = factory->languageId();
|
Utils::Id languageId = factory->languageId();
|
||||||
ICodeStylePreferences *codeStylePreferences = config->codeStyle(languageId);
|
ICodeStylePreferences *codeStylePreferences = config->codeStyle(languageId);
|
||||||
|
|
||||||
auto preview = factory->createCodeStyleEditor(codeStylePreferences, project, stackedWidget);
|
auto preview = factory->createCodeStyleEditor(codeStylePreferences, project, stackedWidget);
|
||||||
if (preview && preview->layout())
|
if (preview && preview->layout())
|
||||||
preview->layout()->setContentsMargins(QMargins());
|
preview->layout()->setContentsMargins(QMargins());
|
||||||
stackedWidget->addWidget(preview);
|
stackedWidget->addWidget(preview);
|
||||||
languageComboBox->addItem(factory->displayName());
|
languageComboBox->addItem(factory->displayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(languageComboBox, &QComboBox::currentIndexChanged,
|
||||||
|
stackedWidget, &QStackedWidget::setCurrentIndex);
|
||||||
|
|
||||||
|
using namespace Layouting;
|
||||||
|
|
||||||
|
Column {
|
||||||
|
Row { new QLabel(Tr::tr("Language:")), languageComboBox, st },
|
||||||
|
stackedWidget,
|
||||||
|
noMargin
|
||||||
|
}.attachTo(this);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
connect(languageComboBox, &QComboBox::currentIndexChanged,
|
class CodeStyleProjectPanelFactory final : public ProjectPanelFactory
|
||||||
stackedWidget, &QStackedWidget::setCurrentIndex);
|
{
|
||||||
|
public:
|
||||||
|
CodeStyleProjectPanelFactory()
|
||||||
|
{
|
||||||
|
setPriority(40);
|
||||||
|
setDisplayName(Tr::tr("Code Style"));
|
||||||
|
setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); });
|
||||||
|
ProjectPanelFactory::registerFactory(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
using namespace Layouting;
|
void setupCodeStyleProjectPanel()
|
||||||
|
{
|
||||||
Column {
|
static CodeStyleProjectPanelFactory theCodeStyleProjectPanelFactory;
|
||||||
Row { new QLabel(Tr::tr("Language:")), languageComboBox, st },
|
|
||||||
stackedWidget,
|
|
||||||
noMargin
|
|
||||||
}.attachTo(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ProjectExplorer::Internal
|
} // ProjectExplorer::Internal
|
||||||
|
|||||||
@@ -3,20 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <projectexplorer/projectsettingswidget.h>
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
void setupCodeStyleProjectPanel();
|
||||||
|
|
||||||
class Project;
|
} // ProjectExplorer::Internal
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class CodeStyleSettingsWidget : public ProjectSettingsWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit CodeStyleSettingsWidget(Project *project);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace ProjectExplorer
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "editorconfiguration.h"
|
#include "editorconfiguration.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "projectexplorertr.h"
|
#include "projectexplorertr.h"
|
||||||
|
#include "projectpanelfactory.h"
|
||||||
|
#include "projectsettingswidget.h"
|
||||||
|
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <texteditor/behaviorsettings.h>
|
#include <texteditor/behaviorsettings.h>
|
||||||
@@ -25,6 +27,28 @@
|
|||||||
|
|
||||||
namespace ProjectExplorer::Internal {
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
|
class EditorSettingsWidget : public ProjectSettingsWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit EditorSettingsWidget(Project *project);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void globalSettingsActivated(bool useGlobal);
|
||||||
|
void restoreDefaultValues();
|
||||||
|
|
||||||
|
void settingsToUi(const EditorConfiguration *config);
|
||||||
|
|
||||||
|
Project *m_project;
|
||||||
|
|
||||||
|
QPushButton *m_restoreButton;
|
||||||
|
QCheckBox *m_showWrapColumn;
|
||||||
|
QCheckBox *m_tintMarginArea;
|
||||||
|
QSpinBox *m_wrapColumn;
|
||||||
|
QCheckBox *m_useIndenter;
|
||||||
|
QGroupBox *m_displaySettings;
|
||||||
|
TextEditor::BehaviorSettingsWidget *m_behaviorSettings;
|
||||||
|
};
|
||||||
|
|
||||||
EditorSettingsWidget::EditorSettingsWidget(Project *project) : m_project(project)
|
EditorSettingsWidget::EditorSettingsWidget(Project *project) : m_project(project)
|
||||||
{
|
{
|
||||||
setGlobalSettingsId(TextEditor::Constants::TEXT_EDITOR_BEHAVIOR_SETTINGS);
|
setGlobalSettingsId(TextEditor::Constants::TEXT_EDITOR_BEHAVIOR_SETTINGS);
|
||||||
@@ -135,4 +159,21 @@ void EditorSettingsWidget::restoreDefaultValues()
|
|||||||
settingsToUi(config);
|
settingsToUi(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EditorSettingsProjectPanelFactory final : public ProjectPanelFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EditorSettingsProjectPanelFactory()
|
||||||
|
{
|
||||||
|
setPriority(30);
|
||||||
|
setDisplayName(Tr::tr("Editor"));
|
||||||
|
setCreateWidgetFunction([](Project *project) { return new EditorSettingsWidget(project); });
|
||||||
|
ProjectPanelFactory::registerFactory(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void setupEditorSettingsProjectPanel()
|
||||||
|
{
|
||||||
|
static EditorSettingsProjectPanelFactory theEditorSettingsProjectPanelFactory;
|
||||||
|
}
|
||||||
|
|
||||||
} // ProjectExplorer::Internal
|
} // ProjectExplorer::Internal
|
||||||
|
|||||||
@@ -3,46 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <projectexplorer/projectsettingswidget.h>
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
void setupEditorSettingsProjectPanel();
|
||||||
class QCheckBox;
|
|
||||||
class QGroupBox;
|
|
||||||
class QPushButton;
|
|
||||||
class QSpinBox;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace TextEditor { class BehaviorSettingsWidget; }
|
} // ProjectExplorer::Internal
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
|
||||||
|
|
||||||
class EditorConfiguration;
|
|
||||||
class Project;
|
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class EditorSettingsWidget : public ProjectSettingsWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit EditorSettingsWidget(Project *project);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void globalSettingsActivated(bool useGlobal);
|
|
||||||
void restoreDefaultValues();
|
|
||||||
|
|
||||||
void settingsToUi(const EditorConfiguration *config);
|
|
||||||
|
|
||||||
Project *m_project;
|
|
||||||
|
|
||||||
QPushButton *m_restoreButton;
|
|
||||||
QCheckBox *m_showWrapColumn;
|
|
||||||
QCheckBox *m_tintMarginArea;
|
|
||||||
QSpinBox *m_wrapColumn;
|
|
||||||
QCheckBox *m_useIndenter;
|
|
||||||
QGroupBox *m_displaySettings;
|
|
||||||
TextEditor::BehaviorSettingsWidget *m_behaviorSettings;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace ProjectExplorer
|
|
||||||
|
|||||||
@@ -882,19 +882,11 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
&dd->m_outputPane, &AppOutputPane::projectRemoved);
|
&dd->m_outputPane, &AppOutputPane::projectRemoved);
|
||||||
|
|
||||||
// ProjectPanelFactories
|
// ProjectPanelFactories
|
||||||
auto panelFactory = new ProjectPanelFactory;
|
|
||||||
panelFactory->setPriority(30);
|
|
||||||
panelFactory->setDisplayName(Tr::tr("Editor"));
|
|
||||||
panelFactory->setCreateWidgetFunction([](Project *project) { return new EditorSettingsWidget(project); });
|
|
||||||
ProjectPanelFactory::registerFactory(panelFactory);
|
|
||||||
|
|
||||||
panelFactory = new ProjectPanelFactory;
|
setupEditorSettingsProjectPanel();
|
||||||
panelFactory->setPriority(40);
|
setupCodeStyleProjectPanel();
|
||||||
panelFactory->setDisplayName(Tr::tr("Code Style"));
|
|
||||||
panelFactory->setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); });
|
|
||||||
ProjectPanelFactory::registerFactory(panelFactory);
|
|
||||||
|
|
||||||
panelFactory = new ProjectExplorer::ProjectPanelFactory;
|
auto panelFactory = new ProjectExplorer::ProjectPanelFactory;
|
||||||
panelFactory->setPriority(45);
|
panelFactory->setPriority(45);
|
||||||
panelFactory->setDisplayName(Tr::tr("Documentation Comments"));
|
panelFactory->setDisplayName(Tr::tr("Documentation Comments"));
|
||||||
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
|
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
|
||||||
|
|||||||
Reference in New Issue
Block a user