diff --git a/EditorConfig.json.in b/EditorConfig.json.in
index 80cd22b..8360597 100644
--- a/EditorConfig.json.in
+++ b/EditorConfig.json.in
@@ -1,9 +1,9 @@
{
\"Name\" : \"EditorConfig\",
- \"Version\" : \"0.2.0\",
- \"CompatVersion\" : \"0.2.0\",
+ \"Version\" : \"0.3.0\",
+ \"CompatVersion\" : \"0.3.0\",
\"Vendor\" : \"Herbert Graeber\",
- \"Copyright\" : \"(C) 2016 Herbert Graeber\",
+ \"Copyright\" : \"(C) 2016,2017 Herbert Graeber\",
\"License\" : [ \"Commercial Usage\",
\"\",
\"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt 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.\",
diff --git a/README.md b/README.md
index b13fe1f..77e3b4c 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ installed in the users plugin folder for direct use with the next run of
QtCreator. QtCreator option `-noload EditorConfig` can be used to suppress
the load of the plugin, for the case that something goes wrong.
-## Supported properties
+## Supported Properties
The EditorConfig QtCreator plugin supports the following EditorConfig properties:
@@ -79,3 +79,8 @@ The EditorConfig QtCreator plugin supports the following EditorConfig properties
- tab_width
- trim_trailing_whitespace
- insert_final_newline
+
+## Additonal Features
+
+Initial EditorConfig files may be created using the new file wizard. The initial
+values for this file are taken from the current projects C++ and Qml settings.
diff --git a/editorconfig.pro b/editorconfig.pro
index 5ec43e8..2d532a8 100644
--- a/editorconfig.pro
+++ b/editorconfig.pro
@@ -8,12 +8,19 @@ DEFINES += EDITORCONFIG_LIBRARY
SOURCES += editorconfigplugin.cpp \
editorconfigdata.cpp \
- editorconfiglogging.cpp
+ editorconfiglogging.cpp \
+ editorconfigwizard.cpp \
+ editorconfigwizardpage.cpp \
+ editorconfigwizarddialog.cpp
HEADERS += editorconfigplugin.h \
editorconfig_global.h \
editorconfigdata.h \
- editorconfiglogging.h
+ editorconfiglogging.h \
+ editorconfigwizard.h \
+ editorconfigconstants.h \
+ editorconfigwizardpage.h \
+ editorconfigwizarddialog.h
# Qt Creator linking
@@ -32,6 +39,7 @@ QTC_LIB_DEPENDS += \
QTC_PLUGIN_DEPENDS += \
coreplugin \
+ projectexplorer \
texteditor
QTC_PLUGIN_RECOMMENDS += \
@@ -44,3 +52,9 @@ include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)
DISTFILES += \
README.md \
.editorconfig
+
+FORMS += \
+ editorconfigpage.ui
+
+TRANSLATIONS += \
+ editorconfig_de.ts
diff --git a/editorconfigconstants.h b/editorconfigconstants.h
new file mode 100644
index 0000000..92e7411
--- /dev/null
+++ b/editorconfigconstants.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2016 herbert
+ */
+#ifndef EDITORCONFIGCONSTANTS_H
+#define EDITORCONFIGCONSTANTS_H
+
+namespace EditorConfig {
+
+namespace Constants {
+
+const char WIZARD_CATEGORY[] = "U.General";
+const char WIZARD_CATEGORY_DISPLAY[] = QT_TRANSLATE_NOOP("EditorConfig", "General");
+const char EDITORCONFIGFILE_ID[] = "Z.EditorConfig";
+
+}
+
+}
+
+#endif // EDITORCONFIGCONSTANTS_H
diff --git a/editorconfigdata.cpp b/editorconfigdata.cpp
index 64c9c1a..17507df 100644
--- a/editorconfigdata.cpp
+++ b/editorconfigdata.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Herbert Graeber
+ * Copyright 2016,2017 Herbert Graeber
*/
#include "editorconfigdata.h"
@@ -56,7 +56,7 @@ bool EditorConfigData::overrideTabSettings(TextEditor::TabSettings &tabSettings)
if (ok && tabSize > 0 && tabSettings.m_tabSize != tabSize) {
message(tr("override tab width with %1").arg(tabSize));
tabSettings.m_tabSize = tabSize;
- ++changed;
+ changed = true;
}
value = m_data["indent_size"];
@@ -64,7 +64,7 @@ bool EditorConfigData::overrideTabSettings(TextEditor::TabSettings &tabSettings)
if (ok && indentSize > 0 && tabSettings.m_indentSize != indentSize) {
message(tr("override indent size with %1").arg(indentSize));
tabSettings.m_indentSize = indentSize;
- ++changed;
+ changed = true;
}
value = m_data["indent_style"];
@@ -72,14 +72,14 @@ bool EditorConfigData::overrideTabSettings(TextEditor::TabSettings &tabSettings)
if (tabSettings.m_tabPolicy != TextEditor::TabSettings::TabsOnlyTabPolicy) {
message(tr("override indent style with 'tab'"));
tabSettings.m_tabPolicy = TextEditor::TabSettings::TabsOnlyTabPolicy;
- ++changed;
+ changed = true;
}
}
else if (value == "space") {
if (tabSettings.m_tabPolicy != TextEditor::TabSettings::SpacesOnlyTabPolicy) {
message(tr("override indent style with 'space'"));
tabSettings.m_tabPolicy = TextEditor::TabSettings::SpacesOnlyTabPolicy;
- ++changed;
+ changed = true;
}
}
@@ -95,24 +95,24 @@ bool EditorConfigData::overrideStorageSettings(TextEditor::StorageSettings &stor
if (value == "true" && !storageSettings.m_addFinalNewLine) {
message(tr("override add final newline with 'true'"));
storageSettings.m_addFinalNewLine = true;
- ++changed;
+ changed = true;
}
else if (value == "false" && storageSettings.m_addFinalNewLine) {
message(tr("override add final newline with 'false'"));
storageSettings.m_addFinalNewLine = false;
- ++changed;
+ changed = true;
}
value = m_data["trim_trailing_whitespace"];
if (value == "true" && !storageSettings.m_cleanWhitespace) {
message(tr("override trim trailing whitespace with 'true'"));
storageSettings.m_cleanWhitespace = true;
- ++changed;
+ changed = true;
}
else if (value == "false" && storageSettings.m_cleanWhitespace) {
message(tr("override trim trailing whitespace with 'false'"));
storageSettings.m_cleanWhitespace = false;
- ++changed;
+ changed = true;
}
return changed;
@@ -126,7 +126,7 @@ bool EditorConfigData::overrideCodec(const QTextCodec *&codec) const {
if (newCodec && codec != newCodec) {
message(tr("override charset with '%2'").arg(QString::fromLatin1(newCodec->name())));
codec = newCodec;
- ++changed;
+ changed = true;
}
return changed;
diff --git a/editorconfiglogging.h b/editorconfiglogging.h
index 05dfcdd..ce439cc 100644
--- a/editorconfiglogging.h
+++ b/editorconfiglogging.h
@@ -9,7 +9,9 @@
namespace EditorConfig {
namespace Internal {
+
Q_DECLARE_LOGGING_CATEGORY(editorConfigLog)
+
}
}
diff --git a/editorconfigpage.ui b/editorconfigpage.ui
new file mode 100644
index 0000000..d7a8d0d
--- /dev/null
+++ b/editorconfigpage.ui
@@ -0,0 +1,44 @@
+
+
+ EditorConfigPage
+
+
+
+ 0
+ 0
+ 400
+ 300
+
+
+
+ Form
+
+
+ Path
+
+
+ 0
+
+
+ -
+
+
+ <html><head/><body><p>Path:</p></body></html>
+
+
+
+ -
+
+
+ true
+
+
+ true
+
+
+
+
+
+
+
+
diff --git a/editorconfigplugin.cpp b/editorconfigplugin.cpp
index a6ffbc5..3b9374c 100644
--- a/editorconfigplugin.cpp
+++ b/editorconfigplugin.cpp
@@ -1,19 +1,23 @@
/*
- * Copyright 2016 Herbert Graeber
+ * Copyright 2016,2017 Herbert Graeber
*/
#include "editorconfigplugin.h"
#include "editorconfigdata.h"
#include "editorconfiglogging.h"
+#include "editorconfigwizard.h"
#include
#include
#include
+#include
#include
+#include
#include
#include
+#include
using namespace EditorConfig::Internal;
@@ -30,6 +34,15 @@ bool EditorConfigPlugin::initialize(const QStringList &arguments, QString *error
Q_UNUSED(arguments)
Q_UNUSED(errorString)
+ if (translator.load(QLatin1String("editorconfig")))
+ QApplication::instance()->installTranslator(&translator);
+
+ Core::IWizardFactory::registerFactoryCreator([] {
+ return QList {
+ new EditorConfigWizard
+ };
+ });
+
if (Core::EditorManager *editorManager = Core::EditorManager::instance()) {
connect(editorManager, SIGNAL(editorCreated(Core::IEditor*,QString)), SLOT(editorCreated(Core::IEditor*,QString)));
connect(editorManager, SIGNAL(editorAboutToClose(Core::IEditor*)), SLOT(editorAboutToClose(Core::IEditor*)));
diff --git a/editorconfigplugin.h b/editorconfigplugin.h
index 68b0581..c6f2d19 100644
--- a/editorconfigplugin.h
+++ b/editorconfigplugin.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Herbert Graeber
+ * Copyright 2016,2017 Herbert Graeber
*/
#ifndef EDITORCONFIG_H
@@ -15,6 +15,7 @@
#include
#include
#include
+#include
namespace EditorConfig {
namespace Internal {
@@ -39,6 +40,8 @@ private slots:
void editorAboutToClose(Core::IEditor *editor);
private:
+ QTranslator translator;
+
QMap documents;
QSet changingDocuments;
};
diff --git a/editorconfigwizard.cpp b/editorconfigwizard.cpp
new file mode 100644
index 0000000..c36fd6a
--- /dev/null
+++ b/editorconfigwizard.cpp
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2016,2017 Herbert Graeber
+ */
+#include "editorconfigwizard.h"
+
+#include "editorconfigwizarddialog.h"
+
+#include "editorconfigconstants.h"
+#include "editorconfiglogging.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+using namespace EditorConfig;
+using namespace Internal;
+
+EditorConfigWizard::EditorConfigWizard() {
+ qCDebug(editorConfigLog) << "EditorConfigWizard::EditorConfigWizard";
+
+ setId("Z.EditorConfig");
+ setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
+ setDisplayCategory(QLatin1String(Constants::WIZARD_CATEGORY_DISPLAY));
+ setDisplayName(tr("Editorconfig File"));
+ setDescription(tr("Creates an initial editorconfig file derived from the current "
+ "C++, Qml and generic files settings."));
+ setFlags(Core::IWizardFactory::PlatformIndependent);
+}
+
+Core::BaseFileWizard *EditorConfigWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const {
+ EditorConfigDialog *wizardDialog = new EditorConfigDialog(this, parent);
+ wizardDialog->setPath(parameters.defaultPath());
+ return wizardDialog;
+}
+
+Core::GeneratedFiles EditorConfigWizard::generateFiles(const QWizard *w, QString *errorMessage) const {
+ Q_UNUSED(errorMessage);
+
+ const EditorConfigDialog *wizardDialog = qobject_cast(w);
+
+ const QString editorConfigFileName = buildFileName(wizardDialog->path(), QString(), QString::fromUtf8("editorconfig"));
+
+ // UI
+ Core::GeneratedFile editorConfigFile(editorConfigFileName);
+
+ if (ProjectExplorer::ProjectTree *projectTree = ProjectExplorer::ProjectTree::instance()) {
+ if (ProjectExplorer::Project *project = projectTree->currentProject()) {
+ QString contents;
+ QTextStream stream(&contents, QIODevice::WriteOnly);
+ createEditorConfigFile(stream, project);
+ stream.flush();
+
+ editorConfigFile.setContents(contents);
+ editorConfigFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
+ }
+ }
+
+ return { editorConfigFile };
+}
+
+void EditorConfigWizard::createEditorConfigFileSection(QTextStream &stream,
+ TextEditor::ICodeStylePreferences *stylePreferences) const
+{
+ if (stylePreferences) {
+ TextEditor::TabSettings tabSettings = stylePreferences->tabSettings();
+
+ stream << "indent_size = " << tabSettings.m_indentSize << "\n";
+ stream << "tab_width = " << tabSettings.m_tabSize << "\n";
+ if (tabSettings.m_tabPolicy == TextEditor::TabSettings::TabsOnlyTabPolicy)
+ stream << "indent_style = tab\n";
+ else if (tabSettings.m_tabPolicy == TextEditor::TabSettings::SpacesOnlyTabPolicy)
+ stream << "indent_style = spaces\n";
+ }
+}
+
+void EditorConfigWizard::createEditorConfigFile(QTextStream &stream,
+ ProjectExplorer::Project *project) const
+{
+ ProjectExplorer::EditorConfiguration *editorConfiguration = project->editorConfiguration();
+
+ stream << "root = true\n";
+ stream << "\n";
+
+ stream << "[*.{h,hpp,hxx,c,cpp,cxx}{,.in}]\n";
+ createEditorConfigFileSection(stream,
+ editorConfiguration->codeStyle(CppTools::Constants::CPP_SETTINGS_ID));
+ stream << "\n";
+
+ stream << "[*{.js,.qml}{,.in}]\n";
+ createEditorConfigFileSection(stream,
+ editorConfiguration->codeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID));
+ stream << "\n";
+
+ stream << "[*]\n";
+ createEditorConfigFileSection(stream, editorConfiguration->codeStyle());
+ TextEditor::StorageSettings storageSettings = editorConfiguration->storageSettings();
+ stream << "insert_final_newline = " << storageSettings.m_addFinalNewLine << "\n";
+ stream << "trim_trailing_whitespace = " << storageSettings.m_cleanWhitespace << "\n";
+ if (QTextCodec *codec = editorConfiguration->textCodec()) {
+ stream << "charset = " << codec->name() << "\n";
+ }
+}
diff --git a/editorconfigwizard.h b/editorconfigwizard.h
new file mode 100644
index 0000000..f7f7a8a
--- /dev/null
+++ b/editorconfigwizard.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016,2017 Herbert Graeber
+ */
+#ifndef EDITORCONFIGWIZARD_H
+#define EDITORCONFIGWIZARD_H
+
+#include
+
+namespace ProjectExplorer {
+ class Project;
+}
+
+namespace TextEditor {
+ class ICodeStylePreferences;
+}
+
+class QTextStream;
+
+namespace EditorConfig {
+
+class EditorConfigWizard : public Core::BaseFileWizardFactory {
+ Q_OBJECT
+public:
+ EditorConfigWizard();
+
+ virtual Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const;
+ virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
+
+private:
+ void createEditorConfigFileSection(QTextStream &stream, TextEditor::ICodeStylePreferences *stylePreferences) const;
+ void createEditorConfigFile(QTextStream &stream, ProjectExplorer::Project *project) const;
+};
+
+}
+
+#endif // EDITORCONFIGWIZARD_H
diff --git a/editorconfigwizarddialog.cpp b/editorconfigwizarddialog.cpp
new file mode 100644
index 0000000..2eae58d
--- /dev/null
+++ b/editorconfigwizarddialog.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 Herbert Graeber
+ */
+
+#include "editorconfigwizarddialog.h"
+
+#include "editorconfigwizard.h"
+#include "editorconfigwizardpage.h"
+
+#include "editorconfiglogging.h"
+
+
+using namespace EditorConfig;
+using namespace Internal;
+
+EditorConfigDialog::EditorConfigDialog(const EditorConfigWizard *factory, QWidget *parent) :
+ Core::BaseFileWizard(factory, QVariantMap(), parent)
+{
+ qCDebug(editorConfigLog) << "EditorConfigDialog::EditorConfigDialog";
+
+ setWindowTitle(tr("Editorconfig File"));
+
+ m_editorConfigPage = new EditorConfigPage(this);
+ setPage(0, m_editorConfigPage);
+
+ foreach (QWizardPage *p, extensionPages())
+ addPage(p);
+}
+
+QString EditorConfigDialog::path() const {
+ return m_editorConfigPage->path();
+}
+
+void EditorConfigDialog::setPath(const QString &path) {
+ m_editorConfigPage->setPath(path);
+}
+
+bool EditorConfigDialog::validateCurrentPage()
+{
+ return QWizard::validateCurrentPage();
+}
+
+
diff --git a/editorconfigwizarddialog.h b/editorconfigwizarddialog.h
new file mode 100644
index 0000000..7a7083a
--- /dev/null
+++ b/editorconfigwizarddialog.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017 Herbert Graeber
+ */
+#ifndef EDITORCONFIGWIZARDDIALOG_H
+#define EDITORCONFIGWIZARDDIALOG_H
+
+#include
+
+namespace EditorConfig {
+
+class EditorConfigWizard;
+class EditorConfigPage;
+
+class EditorConfigDialog : public Core::BaseFileWizard {
+ Q_OBJECT
+public:
+ EditorConfigDialog(const EditorConfigWizard *factory, QWidget *parent);
+
+ QString path() const;
+ void setPath(const QString &);
+
+ bool validateCurrentPage();
+
+private:
+ EditorConfigPage *m_editorConfigPage;
+};
+
+}
+
+#endif // EDITORCONFIGWIZARDDIALOG_H
diff --git a/editorconfigwizardpage.cpp b/editorconfigwizardpage.cpp
new file mode 100644
index 0000000..a766d50
--- /dev/null
+++ b/editorconfigwizardpage.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017 Herbert Graeber
+ */
+
+#include "editorconfigwizardpage.h"
+
+#include "ui_editorconfigpage.h"
+
+#include "editorconfiglogging.h"
+
+#include
+#include
+
+#include
+
+
+using namespace EditorConfig;
+using namespace Internal;
+using namespace ProjectExplorer;
+
+EditorConfigPage::EditorConfigPage(QWidget *parent) :
+ Utils::WizardPage(parent), ui(new Ui_EditorConfigPage)
+{
+ qCDebug(editorConfigLog) << "EditorConfigPage::EditorConfigPage";
+
+ ui->setupUi(this);
+
+ setProperty(Utils::SHORT_TITLE_PROPERTY, tr("Editorconfig Details"));
+}
+
+QString EditorConfigPage::path() const {
+ return m_path;
+}
+
+void EditorConfigPage::setPath(const QString &path) {
+ m_path = path;
+ ui->path->setText(path);
+}
+
diff --git a/editorconfigwizardpage.h b/editorconfigwizardpage.h
new file mode 100644
index 0000000..c19e0e6
--- /dev/null
+++ b/editorconfigwizardpage.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017 Herbert Graeber
+ */
+#ifndef EDITORCONFIGWIZARDPAGE_H
+#define EDITORCONFIGWIZARDPAGE_H
+
+#include
+
+class Ui_EditorConfigPage;
+
+namespace EditorConfig {
+
+class EditorConfigPage : public Utils::WizardPage {
+ Q_OBJECT
+public:
+ explicit EditorConfigPage(QWidget *parent = nullptr);
+
+ QString path() const;
+ void setPath(const QString &);
+
+private:
+ QString m_path;
+
+ Ui_EditorConfigPage *ui;
+};
+
+}
+
+#endif // EDITORCONFIGWIZARDPAGE_H