Add Specific settings page to CMakePLugin and create checkable dialog box for user after add new file action

Change-Id: If5702764fa81f2fdda3ef59780b217e47643b030
Reviewed-by: pawelrutka <prutka13@gmail.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Pawel Rutka
2018-03-10 18:45:06 +01:00
committed by pawelrutka
parent 278a5f1e33
commit 190c5083b7
11 changed files with 443 additions and 17 deletions

View File

@@ -2,5 +2,6 @@
<qresource prefix="/cmakeproject">
<file>images/fileoverlay_cmake.png</file>
<file>images/fileoverlay_cmake@2x.png</file>
<file>images/project_type_settings_icon.png</file>
</qresource>
</RCC>

View File

@@ -30,6 +30,8 @@ HEADERS = builddirmanager.h \
cmakebuildsettingswidget.h \
cmakeindenter.h \
cmakeautocompleter.h \
cmakespecificsettings.h \
cmakespecificsettingspage.h \
configmodel.h \
configmodelitemdelegate.h \
servermode.h \
@@ -63,11 +65,16 @@ SOURCES = builddirmanager.cpp \
cmakebuildsettingswidget.cpp \
cmakeindenter.cpp \
cmakeautocompleter.cpp \
cmakespecificsettings.cpp \
cmakespecificsettingspage.cpp \
configmodel.cpp \
configmodelitemdelegate.cpp \
servermode.cpp \
servermodereader.cpp \
tealeafreader.cpp \
treescanner.cpp
treescanner.cpp \
RESOURCES += cmakeproject.qrc
FORMS += \
cmakespecificsettingspage.ui

View File

@@ -26,10 +26,12 @@
#include "cmakeprojectnodes.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectplugin.h"
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/icore.h>
#include <cpptools/cpptoolsconstants.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/optional.h>
@@ -43,6 +45,15 @@ using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
namespace {
void copySourcePathToClipboard(Utils::optional<QString> srcPath,
const ProjectExplorer::ProjectNode *node)
{
QClipboard *clip = QGuiApplication::clipboard();
QDir projDir{node->filePath().toFileInfo().absoluteFilePath()};
clip->setText(QDir::cleanPath(projDir.relativeFilePath(srcPath.value())));
}
void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::ProjectNode *node)
{
Utils::optional<QString> srcPath{};
@@ -55,17 +66,40 @@ void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::P
}
if (srcPath) {
QMessageBox::StandardButton reply =
QMessageBox::question(nullptr, QMessageBox::tr("Copy to Clipboard?"),
QMessageBox::tr("Files are not automatically added to the CMakeLists.txt file of the CMake project."
CMakeSpecificSettings *settings = CMakeProjectPlugin::projectTypeSpecificSettings();
switch (settings->afterAddFileSetting()) {
case CMakeProjectManager::Internal::ASK_USER: {
bool checkValue{false};
QDialogButtonBox::StandardButton reply =
Utils::CheckableMessageBox::question(nullptr,
QMessageBox::tr("Copy to Clipboard?"),
QMessageBox::tr("Files are not automatically added to the "
"CMakeLists.txt file of the CMake project."
"\nCopy the path to the source files to the clipboard?"),
QMessageBox::Yes | QMessageBox::No);
"Remember My Choice", &checkValue, QDialogButtonBox::Yes | QDialogButtonBox::No,
QDialogButtonBox::Yes);
if (true == checkValue) {
if (QDialogButtonBox::Yes == reply)
settings->setAfterAddFileSetting(AfterAddFileAction::COPY_FILE_PATH);
else if (QDialogButtonBox::No == reply)
settings->setAfterAddFileSetting(AfterAddFileAction::NEVER_COPY_FILE_PATH);
if (QMessageBox::Yes == reply) {
QClipboard *clip = QGuiApplication::clipboard();
settings->toSettings(Core::ICore::settings());
}
QDir projDir{node->filePath().toFileInfo().absoluteFilePath()};
clip->setText(QDir::cleanPath(projDir.relativeFilePath(srcPath.value())));
if (QDialogButtonBox::Yes == reply) {
copySourcePathToClipboard(srcPath, node);
}
break;
}
case CMakeProjectManager::Internal::COPY_FILE_PATH: {
copySourcePathToClipboard(srcPath, node);
break;
}
case CMakeProjectManager::Internal::NEVER_COPY_FILE_PATH:
break;
}
}
}

View File

@@ -42,11 +42,10 @@
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/icore.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projecttree.h>
#include <texteditor/snippets/snippetprovider.h>
#include <utils/parameteraction.h>
@@ -64,6 +63,7 @@ public:
QMetaObject::Connection m_actionConnect;
CMakeSettingsPage settingsPage;
static const std::unique_ptr<CMakeSpecificSettings> projectTypeSpecificSettings;
CMakeManager manager;
CMakeBuildStepFactory buildStepFactory;
CMakeRunConfigurationFactory runConfigFactory;
@@ -72,6 +72,14 @@ public:
CMakeLocatorFilter locatorFiler;
};
const std::unique_ptr<CMakeSpecificSettings>
CMakeProjectPluginPrivate::projectTypeSpecificSettings{std::make_unique<CMakeSpecificSettings>()};
CMakeSpecificSettings *CMakeProjectPlugin::projectTypeSpecificSettings()
{
return CMakeProjectPluginPrivate::projectTypeSpecificSettings.get();
}
CMakeProjectPlugin::~CMakeProjectPlugin()
{
delete d;
@@ -82,11 +90,15 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
Q_UNUSED(errorMessage)
d = new CMakeProjectPluginPrivate;
CMakeProjectPluginPrivate::projectTypeSpecificSettings->fromSettings(ICore::settings());
new CMakeSpecificSettingsPage(CMakeProjectPluginPrivate::projectTypeSpecificSettings.get(),
this); //do not store as this will be cleaned after program close
const Context projectContext(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
Core::FileIconProvider::registerIconOverlayForSuffix(Constants::FILEOVERLAY_CMAKE, "cmake");
Core::FileIconProvider::registerIconOverlayForFilename(Constants::FILEOVERLAY_CMAKE, "CMakeLists.txt");
Core::FileIconProvider::registerIconOverlayForFilename(Constants::FILEOVERLAY_CMAKE,
"CMakeLists.txt");
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
tr("CMake", "SnippetProvider"));
@@ -108,7 +120,8 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
d->m_buildTargetContextAction = new Utils::ParameterAction(tr("Build"), tr("Build \"%1\""),
Utils::ParameterAction::AlwaysEnabled/*handled manually*/,
this);
command = ActionManager::registerAction(d->m_buildTargetContextAction, Constants::BUILD_TARGET_CONTEXTMENU, projectContext);
command = ActionManager::registerAction(d->m_buildTargetContextAction,
Constants::BUILD_TARGET_CONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide);
command->setAttribute(Command::CA_UpdateText);
command->setDescription(d->m_buildTargetContextAction->text());
@@ -143,7 +156,9 @@ void CMakeProjectPlugin::updateContextActions()
d->m_buildTargetContextAction->setVisible(targetNode);
if (cmProject && targetNode) {
d->m_actionConnect = connect(d->m_buildTargetContextAction, &Utils::ParameterAction::triggered,
cmProject, [cmProject, targetDisplayName]() { cmProject->buildCMakeTarget(targetDisplayName); });
cmProject, [cmProject, targetDisplayName]() {
cmProject->buildCMakeTarget(targetDisplayName);
});
}
}

View File

@@ -25,8 +25,9 @@
#pragma once
#include "cmakespecificsettingspage.h"
#include <extensionsystem/iplugin.h>
#include <memory>
namespace CMakeProjectManager {
namespace Internal {
@@ -36,6 +37,7 @@ class CMakeProjectPlugin : public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
public:
static CMakeSpecificSettings *projectTypeSpecificSettings();
~CMakeProjectPlugin() override;
#ifdef WITH_TESTS

View File

@@ -0,0 +1,51 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "cmakespecificsettings.h"
namespace CMakeProjectManager {
namespace Internal {
namespace {
static const char SETTINGS_KEY[] = "CMakeSpecificSettings";
static const char AFTER_ADD_FILE_ACTION_KEY[] = "ProjectPopupSetting";
}
void CMakeSpecificSettings::fromSettings(QSettings *settings)
{
const QString rootKey = QString(SETTINGS_KEY) + '/';
afterAddFileToProjectSetting = static_cast<AfterAddFileAction>(
settings->value(rootKey + AFTER_ADD_FILE_ACTION_KEY,
static_cast<int>(AfterAddFileAction::ASK_USER)).toInt());
}
void CMakeSpecificSettings::toSettings(QSettings *settings) const
{
settings->beginGroup(QString(SETTINGS_KEY));
settings->setValue(QString(AFTER_ADD_FILE_ACTION_KEY), static_cast<int>(afterAddFileToProjectSetting));
settings->endGroup();
}
}
}

View File

@@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <QSettings>
namespace CMakeProjectManager {
namespace Internal {
enum AfterAddFileAction : int {
ASK_USER,
COPY_FILE_PATH,
NEVER_COPY_FILE_PATH
};
class CMakeSpecificSettings
{
public:
CMakeSpecificSettings() = default;
void fromSettings(QSettings *settings);
void toSettings(QSettings *settings) const;
void setAfterAddFileSetting(AfterAddFileAction settings) { afterAddFileToProjectSetting = settings; }
AfterAddFileAction afterAddFileSetting() const { return afterAddFileToProjectSetting; }
private:
AfterAddFileAction afterAddFileToProjectSetting;
};
}
}

View File

@@ -0,0 +1,110 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "cmakespecificsettingspage.h"
#include <coreplugin/icore.h>
namespace CMakeProjectManager {
namespace Internal {
namespace {
const char PROJECT_TYPE_ICON[] = ":/cmakeproject/images/project_type_settings_icon.png";
}
CMakeSpecificSettingWidget::CMakeSpecificSettingWidget(QWidget *parent):
QWidget(parent)
{
m_ui.setupUi(this);
m_ui.newFileAddedCopyToCpliSettingGroup->setId(m_ui.alwaysAskRadio,
AfterAddFileAction::ASK_USER);
m_ui.newFileAddedCopyToCpliSettingGroup->setId(m_ui.neverCopyRadio,
AfterAddFileAction::NEVER_COPY_FILE_PATH);
m_ui.newFileAddedCopyToCpliSettingGroup->setId(m_ui.alwaysCopyRadio,
AfterAddFileAction::COPY_FILE_PATH);
}
void CMakeSpecificSettingWidget::setSettings(const CMakeSpecificSettings &settings)
{
setProjectPopupSetting(settings.afterAddFileSetting());
}
CMakeSpecificSettings CMakeSpecificSettingWidget::settings() const
{
CMakeSpecificSettings set;
int popupSetting = m_ui.newFileAddedCopyToCpliSettingGroup->checkedId();
set.setAfterAddFileSetting( (popupSetting == -1) ? AfterAddFileAction::ASK_USER :
static_cast<AfterAddFileAction>(popupSetting));
return set;
}
void CMakeSpecificSettingWidget::setProjectPopupSetting(AfterAddFileAction mode)
{
switch (mode) {
case CMakeProjectManager::Internal::ASK_USER:
m_ui.alwaysAskRadio->setChecked(true);
break;
case CMakeProjectManager::Internal::COPY_FILE_PATH:
m_ui.alwaysCopyRadio->setChecked(true);
break;
case CMakeProjectManager::Internal::NEVER_COPY_FILE_PATH:
m_ui.neverCopyRadio->setChecked(true);
break;
}
}
CMakeSpecificSettingsPage::CMakeSpecificSettingsPage(CMakeSpecificSettings *settings,
QObject *parent):
Core::IOptionsPage{parent}, m_settings{settings}
{
setCategory("ProjectTypeSettingsPage");
setDisplayName("Project-Type Settings");
setCategoryIcon(Utils::Icon((PROJECT_TYPE_ICON)));
setId("CMakeSpecificSettings");
setDisplayName(tr("CMake"));
}
QWidget *CMakeSpecificSettingsPage::widget()
{
if (!m_widget) {
m_widget = new CMakeSpecificSettingWidget();
m_widget->setSettings(*m_settings);
}
return m_widget;
}
void CMakeSpecificSettingsPage::apply()
{
if (!m_widget) // page was never shown
return;
const CMakeSpecificSettings newSettings = m_widget->settings();
*m_settings = newSettings;
m_settings->toSettings(Core::ICore::settings());
}
}
}

View File

@@ -0,0 +1,70 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
#include "cmakespecificsettings.h"
#include <memory>
#include "ui_cmakespecificsettingspage.h"
namespace CMakeProjectManager {
namespace Internal {
class CMakeSpecificSettingWidget : public QWidget
{
Q_OBJECT
public:
explicit CMakeSpecificSettingWidget(QWidget *parent = 0);
void setSettings(const CMakeSpecificSettings &settings);
CMakeSpecificSettings settings() const;
private:
Ui::CMakeSpecificSettingForm m_ui;
void setProjectPopupSetting(AfterAddFileAction mode);
};
class CMakeSpecificSettingsPage : public Core::IOptionsPage
{
public:
CMakeSpecificSettingsPage(CMakeSpecificSettings *settings, QObject *parent);
QWidget *widget() override;
void apply() override;
void finish() override { }
private:
CMakeSpecificSettings * const m_settings;
QPointer<CMakeSpecificSettingWidget> m_widget;
};
}
}

View File

@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CMakeProjectManager::Internal::CMakeSpecificSettingForm</class>
<widget class="QWidget" name="CMakeProjectManager::Internal::CMakeSpecificSettingForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>852</width>
<height>567</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="toolTip">
<string>Determines whether file paths are copied to the clipboard for pasting to the CMakeLists.txt file when you add new files to CMake projects.</string>
</property>
<property name="title">
<string>Adding Files</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="alwaysAskRadio">
<property name="text">
<string>Ask about copying file paths</string>
</property>
<attribute name="buttonGroup">
<string notr="true">newFileAddedCopyToCpliSettingGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="neverCopyRadio">
<property name="text">
<string>Do not copy file paths</string>
</property>
<attribute name="buttonGroup">
<string notr="true">newFileAddedCopyToCpliSettingGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="alwaysCopyRadio">
<property name="text">
<string>Copy file paths</string>
</property>
<attribute name="buttonGroup">
<string notr="true">newFileAddedCopyToCpliSettingGroup</string>
</attribute>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="newFileAddedCopyToCpliSettingGroup"/>
</buttongroups>
</ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B