Skip to content

Commit

Permalink
Add a wizard for the creation of an initial .editorconfg file
Browse files Browse the repository at this point in the history
- Create a new .editorconfig file in the current projects root with the
  "root = yes" property.
- Take the initial settings from the C++ and Qml settings of the current
  project
  • Loading branch information
hgraeber committed Jul 29, 2017
1 parent 1798276 commit 704d82b
Show file tree
Hide file tree
Showing 15 changed files with 407 additions and 18 deletions.
6 changes: 3 additions & 3 deletions EditorConfig.json.in
Original file line number Diff line number Diff line change
@@ -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.\",
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
18 changes: 16 additions & 2 deletions editorconfig.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,6 +39,7 @@ QTC_LIB_DEPENDS += \

QTC_PLUGIN_DEPENDS += \
coreplugin \
projectexplorer \
texteditor

QTC_PLUGIN_RECOMMENDS += \
Expand All @@ -44,3 +52,9 @@ include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)
DISTFILES += \
README.md \
.editorconfig

FORMS += \
editorconfigpage.ui

TRANSLATIONS += \
editorconfig_de.ts
19 changes: 19 additions & 0 deletions editorconfigconstants.h
Original file line number Diff line number Diff line change
@@ -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
20 changes: 10 additions & 10 deletions editorconfigdata.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Herbert Graeber
* Copyright 2016,2017 Herbert Graeber
*/

#include "editorconfigdata.h"
Expand Down Expand Up @@ -56,30 +56,30 @@ 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"];
int indentSize = value.toInt(&ok);
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"];
if (value == "tab") {
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;
}
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions editorconfiglogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace EditorConfig {
namespace Internal {

Q_DECLARE_LOGGING_CATEGORY(editorConfigLog)

}
}

Expand Down
44 changes: 44 additions & 0 deletions editorconfigpage.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditorConfigPage</class>
<widget class="QWizardPage" name="EditorConfigPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="title">
<string>Path</string>
</property>
<attribute name="pageId">
<string notr="true">0</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Path:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="path">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
15 changes: 14 additions & 1 deletion editorconfigplugin.cpp
Original file line number Diff line number Diff line change
@@ -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 <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/idocument.h>
#include <coreplugin/iwizardfactory.h>
#include <texteditor/textdocument.h>
#include <extensionsystem/pluginmanager.h>

#include <QtPlugin>
#include <QtDebug>
#include <QApplication>

using namespace EditorConfig::Internal;

Expand All @@ -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<Core::IWizardFactory *> {
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*)));
Expand Down
5 changes: 4 additions & 1 deletion editorconfigplugin.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Herbert Graeber
* Copyright 2016,2017 Herbert Graeber
*/

#ifndef EDITORCONFIG_H
Expand All @@ -15,6 +15,7 @@
#include <QtCore/QMultiMap>
#include <QtCore/QSet>
#include <QtCore/QMetaObject>
#include <QTranslator>

namespace EditorConfig {
namespace Internal {
Expand All @@ -39,6 +40,8 @@ private slots:
void editorAboutToClose(Core::IEditor *editor);

private:
QTranslator translator;

QMap<TextEditor::TextDocument *, QMetaObject::Connection> documents;
QSet<TextEditor::TextDocument *> changingDocuments;
};
Expand Down
Loading

0 comments on commit 704d82b

Please sign in to comment.