forked from qt-creator/qt-creator
JsonWizard: Support formatting of sources after creating contents
Change-Id: Ia0fbae6a1d1b2f3dd00c578a8d1ac60e0482fba9 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
committed by
Tobias Hunger
parent
989ed95c1f
commit
b1cc98f79b
@@ -31,8 +31,10 @@
|
|||||||
|
|
||||||
#include "jsonwizard.h"
|
#include "jsonwizard.h"
|
||||||
#include "../addnewmodel.h"
|
#include "../addnewmodel.h"
|
||||||
|
#include "../project.h"
|
||||||
#include "../projectexplorerconstants.h"
|
#include "../projectexplorerconstants.h"
|
||||||
#include "../projectnodes.h"
|
#include "../projectnodes.h"
|
||||||
|
#include "../session.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
|
|
||||||
@@ -79,7 +81,10 @@ static IWizardFactory::WizardKind wizardKind(JsonWizard *wiz)
|
|||||||
|
|
||||||
JsonSummaryPage::JsonSummaryPage(QWidget *parent) :
|
JsonSummaryPage::JsonSummaryPage(QWidget *parent) :
|
||||||
Internal::ProjectWizardPage(parent)
|
Internal::ProjectWizardPage(parent)
|
||||||
{ }
|
{
|
||||||
|
connect(this, &Internal::ProjectWizardPage::projectNodeChanged,
|
||||||
|
this, &JsonSummaryPage::projectNodeHasChanged);
|
||||||
|
}
|
||||||
|
|
||||||
void JsonSummaryPage::initializePage()
|
void JsonSummaryPage::initializePage()
|
||||||
{
|
{
|
||||||
@@ -174,4 +179,17 @@ void JsonSummaryPage::addToProject(const JsonWizard::GeneratorFiles &files)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonSummaryPage::projectNodeHasChanged()
|
||||||
|
{
|
||||||
|
updateProjectData(currentNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonSummaryPage::updateProjectData(FolderNode *node)
|
||||||
|
{
|
||||||
|
Project *project = SessionManager::projectForNode(node);
|
||||||
|
|
||||||
|
wizard()->setProperty("SelectedProject", QVariant::fromValue(project));
|
||||||
|
wizard()->setProperty("SelectedFolderNode", QVariant::fromValue(node));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
|
class FolderNode;
|
||||||
|
|
||||||
// Documentation inside.
|
// Documentation inside.
|
||||||
class JsonSummaryPage : public Internal::ProjectWizardPage
|
class JsonSummaryPage : public Internal::ProjectWizardPage
|
||||||
{
|
{
|
||||||
@@ -51,6 +53,10 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void triggerCommit(const JsonWizard::GeneratorFiles &files);
|
void triggerCommit(const JsonWizard::GeneratorFiles &files);
|
||||||
void addToProject(const JsonWizard::GeneratorFiles &files);
|
void addToProject(const JsonWizard::GeneratorFiles &files);
|
||||||
|
void projectNodeHasChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateProjectData(FolderNode *node);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ void JsonWizard::removeAttributeFromAllFiles(Core::GeneratedFile::Attribute a)
|
|||||||
|
|
||||||
void JsonWizard::accept()
|
void JsonWizard::accept()
|
||||||
{
|
{
|
||||||
|
|
||||||
Utils::Wizard::accept();
|
Utils::Wizard::accept();
|
||||||
|
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
#include "jsonwizardfilegenerator.h"
|
#include "jsonwizardfilegenerator.h"
|
||||||
|
|
||||||
#include "../customwizard/customwizardpreprocessor.h"
|
#include "../customwizard/customwizardpreprocessor.h"
|
||||||
#include "../project.h"
|
|
||||||
#include "../projectexplorer.h"
|
#include "../projectexplorer.h"
|
||||||
#include "jsonwizard.h"
|
#include "jsonwizard.h"
|
||||||
#include "jsonwizardfactory.h"
|
#include "jsonwizardfactory.h"
|
||||||
@@ -158,15 +157,6 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::AbstractMacroExpan
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonWizardFileGenerator::formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage)
|
|
||||||
{
|
|
||||||
Q_UNUSED(wizard);
|
|
||||||
Q_UNUSED(file);
|
|
||||||
Q_UNUSED(errorMessage);
|
|
||||||
// TODO: Implement me!
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JsonWizardFileGenerator::writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage)
|
bool JsonWizardFileGenerator::writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage)
|
||||||
{
|
{
|
||||||
Q_UNUSED(wizard);
|
Q_UNUSED(wizard);
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ public:
|
|||||||
const QString &wizardDir, const QString &projectDir,
|
const QString &wizardDir, const QString &projectDir,
|
||||||
QString *errorMessage);
|
QString *errorMessage);
|
||||||
|
|
||||||
bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
|
||||||
bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
||||||
bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
||||||
|
|
||||||
|
|||||||
@@ -32,26 +32,97 @@
|
|||||||
#include "jsonwizard.h"
|
#include "jsonwizard.h"
|
||||||
#include "jsonwizardfilegenerator.h"
|
#include "jsonwizardfilegenerator.h"
|
||||||
|
|
||||||
|
#include "../editorconfiguration.h"
|
||||||
|
#include "../project.h"
|
||||||
#include "../projectexplorerconstants.h"
|
#include "../projectexplorerconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/dialogs/promptoverwritedialog.h>
|
#include <coreplugin/dialogs/promptoverwritedialog.h>
|
||||||
|
#include <coreplugin/mimedatabase.h>
|
||||||
|
#include <texteditor/icodestylepreferences.h>
|
||||||
|
#include <texteditor/icodestylepreferencesfactory.h>
|
||||||
|
#include <texteditor/indenter.h>
|
||||||
|
#include <texteditor/normalindenter.h>
|
||||||
|
#include <texteditor/storagesettings.h>
|
||||||
|
#include <texteditor/tabsettings.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDebug>
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QTextCursor>
|
||||||
|
#include <QTextDocument>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// Helpers:
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
static ICodeStylePreferences *codeStylePreferences(Project *project, Id languageId)
|
||||||
|
{
|
||||||
|
if (!languageId.isValid())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (project)
|
||||||
|
return project->editorConfiguration()->codeStyle(languageId);
|
||||||
|
|
||||||
|
return TextEditorSettings::codeStyle(languageId);
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// JsonWizardGenerator:
|
// JsonWizardGenerator:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool JsonWizardGenerator::formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage)
|
||||||
|
{
|
||||||
|
Q_UNUSED(errorMessage);
|
||||||
|
|
||||||
|
if (file->isBinary() || file->contents().isEmpty())
|
||||||
|
return true; // nothing to do
|
||||||
|
|
||||||
|
MimeType mt = MimeDatabase::findByFile(QFileInfo(file->path()));
|
||||||
|
Id languageId = TextEditorSettings::languageId(mt.type());
|
||||||
|
|
||||||
|
if (!languageId.isValid())
|
||||||
|
return true; // don't modify files like *.ui, *.pro
|
||||||
|
|
||||||
|
Project *baseProject = qobject_cast<Project *>(wizard->property("SelectedProject").value<QObject *>());
|
||||||
|
ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(languageId);
|
||||||
|
|
||||||
|
Indenter *indenter = 0;
|
||||||
|
if (factory)
|
||||||
|
indenter = factory->createIndenter();
|
||||||
|
if (!indenter)
|
||||||
|
indenter = new NormalIndenter();
|
||||||
|
|
||||||
|
ICodeStylePreferences *codeStylePrefs = codeStylePreferences(baseProject, languageId);
|
||||||
|
indenter->setCodeStylePreferences(codeStylePrefs);
|
||||||
|
QTextDocument doc(file->contents());
|
||||||
|
QTextCursor cursor(&doc);
|
||||||
|
cursor.select(QTextCursor::Document);
|
||||||
|
indenter->indent(&doc, cursor, QChar::Null, codeStylePrefs->currentTabSettings());
|
||||||
|
delete indenter;
|
||||||
|
if (TextEditorSettings::storageSettings().m_cleanWhitespace) {
|
||||||
|
QTextBlock block = doc.firstBlock();
|
||||||
|
while (block.isValid()) {
|
||||||
|
codeStylePrefs->currentTabSettings().removeTrailingWhitespace(cursor, block);
|
||||||
|
block = block.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file->setContents(doc.toPlainText());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(JsonWizard::GeneratorFiles *files,
|
JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(JsonWizard::GeneratorFiles *files,
|
||||||
QString *errorMessage)
|
QString *errorMessage)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
virtual Core::GeneratedFiles fileList(Utils::AbstractMacroExpander *expander,
|
virtual Core::GeneratedFiles fileList(Utils::AbstractMacroExpander *expander,
|
||||||
const QString &baseDir, const QString &projectDir,
|
const QString &baseDir, const QString &projectDir,
|
||||||
QString *errorMessage) = 0;
|
QString *errorMessage) = 0;
|
||||||
virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
|
virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
|
||||||
virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
|
virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
|
||||||
virtual bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
|
virtual bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -494,6 +494,7 @@ void ProjectWizardPage::slotProjectChanged(int index)
|
|||||||
{
|
{
|
||||||
setProjectToolTip(index >= 0 && index < m_projectToolTips.size() ?
|
setProjectToolTip(index >= 0 && index < m_projectToolTips.size() ?
|
||||||
m_projectToolTips.at(index) : QString());
|
m_projectToolTips.at(index) : QString());
|
||||||
|
emit projectNodeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectWizardPage::slotManageVcs()
|
void ProjectWizardPage::slotManageVcs()
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ public:
|
|||||||
Core::IWizardFactory::WizardKind kind,
|
Core::IWizardFactory::WizardKind kind,
|
||||||
ProjectExplorer::ProjectAction action);
|
ProjectExplorer::ProjectAction action);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void projectNodeChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void initializeVersionControls();
|
void initializeVersionControls();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user