Implement Code Style schemes

Task-number: QTCREATORBUG-5092

Change-Id: I218cef02f7c242e4dfae59b1b8021ea618e60d07
Reviewed-on: http://codereview.qt-project.org/5160
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
Jarek Kobus
2011-08-16 10:45:23 +02:00
committed by Jarek Kobus
parent 3955df7855
commit 2244911826
92 changed files with 3138 additions and 2125 deletions
@@ -47,8 +47,9 @@
#include <utils/qtcassert.h>
/*!
\class ProjectExplorer::PersistentSettingsReader
\class Utils::PersistentSettingsReader
\brief Reads a QVariantMap of arbitrary, nested data structures from a XML file.
@@ -80,10 +81,10 @@
and added to the stack entry below (added to list or inserted into map). The first element
of the stack is the value of the <data> element.
\sa ProjectExplorer::PersistentSettingsWriter
\sa Utils::PersistentSettingsWriter
*/
namespace ProjectExplorer {
namespace Utils {
struct Context // Basic context containing element name string constants.
{
@@ -300,7 +301,7 @@ PersistentSettingsReader::PersistentSettingsReader()
{
}
QVariant PersistentSettingsReader::restoreValue(const QString & variable) const
QVariant PersistentSettingsReader::restoreValue(const QString &variable) const
{
if (m_valueMap.contains(variable))
return m_valueMap.value(variable);
@@ -312,7 +313,7 @@ QVariantMap PersistentSettingsReader::restoreValues() const
return m_valueMap;
}
bool PersistentSettingsReader::load(const QString & fileName)
bool PersistentSettingsReader::load(const QString &fileName)
{
m_valueMap.clear();
@@ -326,10 +327,10 @@ bool PersistentSettingsReader::load(const QString & fileName)
}
/*!
\class ProjectExplorer::PersistentSettingsWriter
\class Utils::PersistentSettingsWriter
\brief Serializes a QVariantMap of arbitrary, nested data structures to a XML file.
\sa ProjectExplorer::PersistentSettingsReader
\sa Utils::PersistentSettingsReader
*/
PersistentSettingsWriter::PersistentSettingsWriter()
@@ -373,12 +374,12 @@ static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx,
}
}
void PersistentSettingsWriter::saveValue(const QString & variable, const QVariant &value)
void PersistentSettingsWriter::saveValue(const QString &variable, const QVariant &value)
{
m_valueMap.insert(variable, value);
}
bool PersistentSettingsWriter::save(const QString & fileName, const QString &docType,
bool PersistentSettingsWriter::save(const QString &fileName, const QString &docType,
QWidget *parent) const
{
Utils::FileSaver saver(fileName, QIODevice::Text);
@@ -406,4 +407,4 @@ bool PersistentSettingsWriter::save(const QString & fileName, const QString &doc
}
return saver.finalize(parent);
}
} // namespace ProjectExplorer
} // namespace Utils
@@ -33,7 +33,7 @@
#ifndef PERSISTENTSETTINGS_H
#define PERSISTENTSETTINGS_H
#include "projectexplorer_export.h"
#include "utils_global.h"
#include <QtCore/QMap>
#include <QtCore/QVariant>
@@ -42,31 +42,31 @@ QT_BEGIN_NAMESPACE
class QWidget;
QT_END_NAMESPACE
namespace ProjectExplorer {
namespace Utils {
class PROJECTEXPLORER_EXPORT PersistentSettingsReader
class QTCREATOR_UTILS_EXPORT PersistentSettingsReader
{
public:
PersistentSettingsReader();
QVariant restoreValue(const QString & variable) const;
QVariant restoreValue(const QString &variable) const;
QVariantMap restoreValues() const;
bool load(const QString & fileName);
bool load(const QString &fileName);
private:
QMap<QString, QVariant> m_valueMap;
};
class PROJECTEXPLORER_EXPORT PersistentSettingsWriter
class QTCREATOR_UTILS_EXPORT PersistentSettingsWriter
{
public:
PersistentSettingsWriter();
void saveValue(const QString & variable, const QVariant &value);
void saveValue(const QString &variable, const QVariant &value);
bool save(const QString &fileName, const QString &docType, QWidget *parent) const;
private:
QMap<QString, QVariant> m_valueMap;
};
} // namespace ProjectExplorer
} // namespace Utils
#endif // PERSISTENTSETTINGS_H
+4 -2
View File
@@ -90,7 +90,8 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/ssh/sshkeypasswordretriever.cpp \
$$PWD/outputformatter.cpp \
$$PWD/flowlayout.cpp \
$$PWD/networkaccessmanager.cpp
$$PWD/networkaccessmanager.cpp \
$$PWD/persistentsettings.cpp
win32 {
SOURCES += \
@@ -194,7 +195,8 @@ HEADERS += \
$$PWD/outputformatter.h \
$$PWD/outputformat.h \
$$PWD/flowlayout.h \
$$PWD/networkaccessmanager.h
$$PWD/networkaccessmanager.h \
$$PWD/persistentsettings.h
FORMS += $$PWD/filewizardpage.ui \
$$PWD/projectintropage.ui \
-3
View File
@@ -53,9 +53,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/navigationwidget.h>
#include <texteditor/fontsettings.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/storagesettings.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorplugin.h>
#include <texteditor/texteditorsettings.h>
@@ -36,10 +36,8 @@ using namespace CppTools;
static const char *settingsSuffixKey = "CodeStyleSettings";
static const char *currentFallbackKey = "CurrentFallback";
CppCodeStylePreferences::CppCodeStylePreferences(const QList<TextEditor::IFallbackPreferences *> &fallbacks, QObject *parent) :
IFallbackPreferences(fallbacks, parent)
CppCodeStylePreferences::CppCodeStylePreferences(QObject *parent) :
ICodeStylePreferences(parent)
{
connect(this, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCurrentValueChanged(QVariant)));
@@ -48,7 +46,7 @@ CppCodeStylePreferences::CppCodeStylePreferences(const QList<TextEditor::IFallba
QVariant CppCodeStylePreferences::value() const
{
QVariant v;
v.setValue(settings());
v.setValue(codeStyleSettings());
return v;
}
@@ -57,15 +55,15 @@ void CppCodeStylePreferences::setValue(const QVariant &data)
if (!data.canConvert<CppCodeStyleSettings>())
return;
setSettings(data.value<CppCodeStyleSettings>());
setCodeStyleSettings(data.value<CppCodeStyleSettings>());
}
CppCodeStyleSettings CppCodeStylePreferences::settings() const
CppCodeStyleSettings CppCodeStylePreferences::codeStyleSettings() const
{
return m_data;
}
void CppCodeStylePreferences::setSettings(const CppCodeStyleSettings &data)
void CppCodeStylePreferences::setCodeStyleSettings(const CppCodeStyleSettings &data)
{
if (m_data == data)
return;
@@ -75,13 +73,13 @@ void CppCodeStylePreferences::setSettings(const CppCodeStyleSettings &data)
QVariant v;
v.setValue(data);
emit valueChanged(v);
emit settingsChanged(m_data);
if (!currentFallback()) {
emit codeStyleSettingsChanged(m_data);
if (!currentDelegate()) {
emit currentValueChanged(v);
}
}
CppCodeStyleSettings CppCodeStylePreferences::currentSettings() const
CppCodeStyleSettings CppCodeStylePreferences::currentCodeStyleSettings() const
{
QVariant v = currentValue();
if (!v.canConvert<CppCodeStyleSettings>()) {
@@ -96,7 +94,7 @@ void CppCodeStylePreferences::slotCurrentValueChanged(const QVariant &value)
if (!value.canConvert<CppCodeStyleSettings>())
return;
emit currentSettingsChanged(value.value<CppCodeStyleSettings>());
emit currentCodeStyleSettingsChanged(value.value<CppCodeStyleSettings>());
}
QString CppCodeStylePreferences::settingsSuffix() const
@@ -106,13 +104,19 @@ QString CppCodeStylePreferences::settingsSuffix() const
void CppCodeStylePreferences::toMap(const QString &prefix, QVariantMap *map) const
{
ICodeStylePreferences::toMap(prefix, map);
if (currentDelegate())
return;
m_data.toMap(prefix, map);
map->insert(prefix + QLatin1String(currentFallbackKey), currentFallbackId());
}
void CppCodeStylePreferences::fromMap(const QString &prefix, const QVariantMap &map)
{
ICodeStylePreferences::fromMap(prefix, map);
if (currentDelegate())
return;
m_data.fromMap(prefix, map);
setCurrentFallback(map.value(prefix + QLatin1String(currentFallbackKey), QLatin1String("Global")).toString());
}
@@ -35,35 +35,34 @@
#include "cpptools_global.h"
#include "cppcodestylesettings.h"
#include <texteditor/ifallbackpreferences.h>
#include <texteditor/icodestylepreferences.h>
namespace CppTools {
class CPPTOOLS_EXPORT CppCodeStylePreferences : public TextEditor::IFallbackPreferences
class CPPTOOLS_EXPORT CppCodeStylePreferences : public TextEditor::ICodeStylePreferences
{
Q_OBJECT
public:
explicit CppCodeStylePreferences(
const QList<TextEditor::IFallbackPreferences *> &fallbacks,
QObject *parent = 0);
virtual QVariant value() const;
virtual void setValue(const QVariant &);
CppCodeStyleSettings settings() const;
CppCodeStyleSettings codeStyleSettings() const;
// tracks parent hierarchy until currentParentSettings is null
CppCodeStyleSettings currentSettings() const;
CppCodeStyleSettings currentCodeStyleSettings() const;
virtual void toMap(const QString &prefix, QVariantMap *map) const;
virtual void fromMap(const QString &prefix, const QVariantMap &map);
public slots:
void setSettings(const CppTools::CppCodeStyleSettings &data);
void setCodeStyleSettings(const CppTools::CppCodeStyleSettings &data);
signals:
void settingsChanged(const CppTools::CppCodeStyleSettings &);
void currentSettingsChanged(const CppTools::CppCodeStyleSettings &);
void codeStyleSettingsChanged(const CppTools::CppCodeStyleSettings &);
void currentCodeStyleSettingsChanged(const CppTools::CppCodeStyleSettings &);
protected:
virtual QString settingsSuffix() const;
@@ -30,18 +30,66 @@
**
**************************************************************************/
#include "cppcodestylesettingsfactory.h"
#include "cppcodestylepreferencesfactory.h"
#include "cppcodestylesettings.h"
#include "cppcodestylesettingspage.h"
#include "cppcodestylepreferences.h"
#include "cpptoolsconstants.h"
#include "cppqtstyleindenter.h"
#include <texteditor/tabpreferences.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/tabsettings.h>
#include <texteditor/snippets/isnippetprovider.h>
#include <cppeditor/cppeditorconstants.h>
#include <QtGui/QLayout>
using namespace CppTools;
static const char *defaultPreviewText =
"#include <math.h>\n"
"\n"
"class Complex\n"
" {\n"
"public:\n"
" Complex(double re, double im)\n"
" : _re(re), _im(im)\n"
" {}\n"
" double modulus() const\n"
" {\n"
" return sqrt(_re * _re + _im * _im);\n"
" }\n"
"private:\n"
" double _re;\n"
" double _im;\n"
" };\n"
"\n"
"void bar(int i)\n"
" {\n"
" static int counter = 0;\n"
" counter += i;\n"
" }\n"
"\n"
"namespace Foo\n"
" {\n"
" namespace Bar\n"
" {\n"
" void foo(int a, int b)\n"
" {\n"
" for (int i = 0; i < a; i++)\n"
" {\n"
" if (i < b)\n"
" bar(i);\n"
" else\n"
" {\n"
" bar(i);\n"
" bar(b);\n"
" }\n"
" }\n"
" }\n"
" } // namespace Bar\n"
" } // namespace Foo\n"
;
CppCodeStylePreferencesFactory::CppCodeStylePreferencesFactory()
{
}
@@ -56,14 +104,12 @@ QString CppCodeStylePreferencesFactory::displayName()
return Constants::CPP_SETTINGS_NAME;
}
TextEditor::IFallbackPreferences *CppCodeStylePreferencesFactory::createPreferences(
const QList<TextEditor::IFallbackPreferences *> &fallbacks) const
TextEditor::ICodeStylePreferences *CppCodeStylePreferencesFactory::createCodeStyle() const
{
return new CppCodeStylePreferences(fallbacks);
return new CppCodeStylePreferences();
}
QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::IFallbackPreferences *preferences,
TextEditor::TabPreferences *tabPreferences,
QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
QWidget *parent) const
{
CppCodeStylePreferences *cppPreferences = qobject_cast<CppCodeStylePreferences *>(preferences);
@@ -71,7 +117,7 @@ QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::IFallbackPrefe
return 0;
Internal::CppCodeStylePreferencesWidget *widget = new Internal::CppCodeStylePreferencesWidget(parent);
widget->layout()->setMargin(0);
widget->setPreferences(cppPreferences, tabPreferences);
widget->setCodeStyle(cppPreferences);
return widget;
}
@@ -80,3 +126,18 @@ TextEditor::Indenter *CppCodeStylePreferencesFactory::createIndenter() const
return new CppQtStyleIndenter();
}
TextEditor::ISnippetProvider *CppCodeStylePreferencesFactory::snippetProvider() const
{
const QList<TextEditor::ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::instance()->getObjects<TextEditor::ISnippetProvider>();
foreach (TextEditor::ISnippetProvider *provider, providers)
if (provider->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID))
return provider;
return 0;
}
QString CppCodeStylePreferencesFactory::previewText() const
{
return QLatin1String(defaultPreviewText);
}
@@ -30,8 +30,8 @@
**
**************************************************************************/
#ifndef CPPCODESTYLESETTINGSFACTORY_H
#define CPPCODESTYLESETTINGSFACTORY_H
#ifndef CPPCODESTYLEPREFERENCESFACTORY_H
#define CPPCODESTYLEPREFERENCESFACTORY_H
#include <texteditor/icodestylepreferencesfactory.h>
@@ -44,14 +44,14 @@ public:
virtual QString languageId();
virtual QString displayName();
virtual TextEditor::IFallbackPreferences *createPreferences(const QList<TextEditor::IFallbackPreferences *> &fallbacks) const;
virtual QWidget *createEditor(TextEditor::IFallbackPreferences *settings,
TextEditor::TabPreferences *tabSettings,
QWidget *parent) const;
virtual TextEditor::ICodeStylePreferences *createCodeStyle() const;
virtual QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
QWidget *parent) const;
virtual TextEditor::Indenter *createIndenter() const;
virtual TextEditor::ISnippetProvider *snippetProvider() const;
virtual QString previewText() const;
};
} // namespace CppTools
#endif // CPPCODESTYLESETTINGSFACTORY_H
#endif // CPPCODESTYLEPREFERENCESFACTORY_H
+94 -109
View File
@@ -41,7 +41,7 @@
#include <texteditor/displaysettings.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/codestyleeditor.h>
#include <extensionsystem/pluginmanager.h>
#include <cppeditor/cppeditorconstants.h>
#include <coreplugin/icore.h>
@@ -209,8 +209,7 @@ namespace Internal {
CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
: QWidget(parent),
m_tabPreferences(0),
m_cppCodeStylePreferences(0),
m_preferences(0),
m_ui(new Ui::CppCodeStyleSettingsPage),
m_blockUpdates(false)
{
@@ -224,50 +223,51 @@ CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
m_previews[i]->setPlainText(defaultCodeStyleSnippets[i]);
}
TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
decorateEditors(settings->fontSettings());
connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
TextEditor::TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
decorateEditors(textEditorSettings->fontSettings());
connect(textEditorSettings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
this, SLOT(decorateEditors(TextEditor::FontSettings)));
setVisualizeWhitespace(true);
connect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings)));
connect(m_ui->indentBlockBraces, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentBlockBody, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentClassBraces, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentNamespaceBraces, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentEnumBraces, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentNamespaceBody, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentSwitchLabels, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentCaseStatements, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentCaseBlocks, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentCaseBreak, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentAccessSpecifiers, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentDeclarationsRelativeToAccessSpecifiers, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentFunctionBody, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->indentFunctionBraces, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->extraPaddingConditions, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
connect(m_ui->alignAssignments, SIGNAL(toggled(bool)),
this, SLOT(slotCppCodeStyleSettingsChanged()));
this, SLOT(slotCodeStyleSettingsChanged()));
m_ui->categoryTab->setCurrentIndex(0);
m_ui->tabPreferencesWidget->setFlat(true);
m_ui->fallbackWidget->setLabelText(tr("Code style settings:"));
m_ui->tabSettingsWidget->setFlat(true);
}
CppCodeStylePreferencesWidget::~CppCodeStylePreferencesWidget()
@@ -275,27 +275,21 @@ CppCodeStylePreferencesWidget::~CppCodeStylePreferencesWidget()
delete m_ui;
}
void CppCodeStylePreferencesWidget::setPreferences(CppTools::CppCodeStylePreferences *codeStylePreferences,
TextEditor::TabPreferences *tabPreferences)
void CppCodeStylePreferencesWidget::setCodeStyle(CppTools::CppCodeStylePreferences *codeStylePreferences)
{
// tab preferences
m_tabPreferences = tabPreferences;
m_ui->tabPreferencesWidget->setTabPreferences(tabPreferences);
connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
this, SLOT(updatePreview()));
// code preferences
m_cppCodeStylePreferences = codeStylePreferences;
m_ui->fallbackWidget->setFallbackPreferences(codeStylePreferences);
m_ui->fallbackContainer->setVisible(!m_ui->fallbackWidget->isHidden());
m_preferences = codeStylePreferences;
connect(m_cppCodeStylePreferences, SIGNAL(currentSettingsChanged(CppTools::CppCodeStyleSettings)),
this, SLOT(setCppCodeStyleSettings(CppTools::CppCodeStyleSettings)));
connect(m_cppCodeStylePreferences, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences*)));
connect(m_preferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(m_preferences, SIGNAL(currentCodeStyleSettingsChanged(CppTools::CppCodeStyleSettings)),
this, SLOT(setCodeStyleSettings(CppTools::CppCodeStyleSettings)));
connect(m_preferences, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences*)));
setCppCodeStyleSettings(m_cppCodeStylePreferences->settings(), false);
slotCurrentPreferencesChanged(m_cppCodeStylePreferences->currentPreferences(), false);
setTabSettings(m_preferences->tabSettings());
setCodeStyleSettings(m_preferences->codeStyleSettings(), false);
slotCurrentPreferencesChanged(m_preferences->currentPreferences(), false);
updatePreview();
}
@@ -324,7 +318,12 @@ CppCodeStyleSettings CppCodeStylePreferencesWidget::cppCodeStyleSettings() const
return set;
}
void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSettings &s, bool preview)
void CppCodeStylePreferencesWidget::setTabSettings(const TextEditor::TabSettings &settings)
{
m_ui->tabSettingsWidget->setTabSettings(settings);
}
void CppCodeStylePreferencesWidget::setCodeStyleSettings(const CppCodeStyleSettings &s, bool preview)
{
const bool wasBlocked = m_blockUpdates;
m_blockUpdates = true;
@@ -349,9 +348,10 @@ void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSe
updatePreview();
}
void CppCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *preferences, bool preview)
void CppCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences *preferences, bool preview)
{
const bool enable = !preferences->isReadOnly() && m_cppCodeStylePreferences->isFallbackEnabled(m_cppCodeStylePreferences->currentFallback());
const bool enable = !preferences->isReadOnly() && !m_preferences->currentDelegate();
m_ui->tabSettingsWidget->setEnabled(enable);
m_ui->contentGroupBox->setEnabled(enable);
m_ui->bracesGroupBox->setEnabled(enable);
m_ui->switchGroupBox->setEnabled(enable);
@@ -365,8 +365,7 @@ QString CppCodeStylePreferencesWidget::searchKeywords() const
QString rc;
QLatin1Char sep(' ');
QTextStream(&rc)
<< sep << m_ui->tabPreferencesWidget->searchKeywords()
<< sep << m_ui->fallbackWidget->searchKeywords()
<< sep << m_ui->tabSettingsWidget->searchKeywords()
<< sep << m_ui->indentBlockBraces->text()
<< sep << m_ui->indentBlockBody->text()
<< sep << m_ui->indentClassBraces->text()
@@ -394,15 +393,29 @@ QString CppCodeStylePreferencesWidget::searchKeywords() const
return rc;
}
void CppCodeStylePreferencesWidget::slotCppCodeStyleSettingsChanged()
void CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged()
{
if (m_blockUpdates)
return;
if (m_cppCodeStylePreferences) {
CppCodeStylePreferences *current = qobject_cast<CppCodeStylePreferences *>(m_cppCodeStylePreferences->currentPreferences());
if (m_preferences) {
CppCodeStylePreferences *current = qobject_cast<CppCodeStylePreferences *>(m_preferences->currentPreferences());
if (current)
current->setSettings(cppCodeStyleSettings());
current->setCodeStyleSettings(cppCodeStyleSettings());
}
updatePreview();
}
void CppCodeStylePreferencesWidget::slotTabSettingsChanged(const TextEditor::TabSettings &settings)
{
if (m_blockUpdates)
return;
if (m_preferences) {
CppCodeStylePreferences *current = qobject_cast<CppCodeStylePreferences *>(m_preferences->currentPreferences());
if (current)
current->setTabSettings(settings);
}
updatePreview();
@@ -410,30 +423,24 @@ void CppCodeStylePreferencesWidget::slotCppCodeStyleSettingsChanged()
void CppCodeStylePreferencesWidget::updatePreview()
{
CppCodeStylePreferences *cppCodeStylePreferences = m_preferences
? m_preferences
: CppToolsSettings::instance()->cppCodeStyle();
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentCodeStyleSettings();
const TextEditor::TabSettings ts = cppCodeStylePreferences->currentTabSettings();
QtStyleCodeFormatter formatter(ts, ccss);
foreach (TextEditor::SnippetEditorWidget *preview, m_previews) {
QTextDocument *doc = preview->document();
const TextEditor::TabSettings ts = m_tabPreferences
? m_tabPreferences->currentSettings()
: CppToolsSettings::instance()->tabPreferences()->settings();
CppCodeStylePreferences *cppCodeStylePreferences = m_cppCodeStylePreferences
? m_cppCodeStylePreferences
: CppToolsSettings::instance()->cppCodeStylePreferences();
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentSettings();
preview->setTabSettings(ts);
preview->setCodeStylePreferences(cppCodeStylePreferences);
QtStyleCodeFormatter formatter(ts, ccss);
preview->setCodeStyle(cppCodeStylePreferences);
QTextDocument *doc = preview->document();
formatter.invalidateCache(doc);
QTextBlock block = doc->firstBlock();
QTextCursor tc = preview->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
int indent;
int padding;
formatter.indentFor(block, &indent, &padding);
ts.indentLine(block, indent + padding, padding);
formatter.updateLineStateChange(block);
preview->indenter()->indentBlock(doc, block, QChar::Null, ts);
block = block.next();
}
@@ -475,7 +482,7 @@ void CppCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
CppCodeStyleSettingsPage::CppCodeStyleSettingsPage(
QWidget *parent) :
Core::IOptionsPage(parent),
m_pageTabPreferences(0)
m_pageCppCodeStylePreferences(0)
{
}
@@ -510,33 +517,18 @@ QIcon CppCodeStyleSettingsPage::categoryIcon() const
QWidget *CppCodeStyleSettingsPage::createPage(QWidget *parent)
{
m_widget = new CppCodeStylePreferencesWidget(parent);
TextEditor::TabPreferences *originalTabPreferences
= CppToolsSettings::instance()->tabPreferences();
QList<TextEditor::IFallbackPreferences *> originalTabFallbacks = originalTabPreferences->fallbacks();
m_pageTabPreferences = new TextEditor::TabPreferences(originalTabFallbacks, m_widget);
for (int i = 0; i < originalTabFallbacks.count(); i++) {
TextEditor::IFallbackPreferences *fallback = originalTabFallbacks.at(i);
m_pageTabPreferences->setFallbackEnabled(fallback, originalTabPreferences->isFallbackEnabled(fallback));
}
m_pageTabPreferences->setSettings(originalTabPreferences->settings());
m_pageTabPreferences->setCurrentFallback(originalTabPreferences->currentFallback());
CppCodeStylePreferences *originalCodeStylePreferences
= CppToolsSettings::instance()->cppCodeStylePreferences();
QList<TextEditor::IFallbackPreferences *> originalCodeStyleFallbacks = originalCodeStylePreferences->fallbacks();
m_pageCppCodeStylePreferences = new CppCodeStylePreferences(originalCodeStyleFallbacks, m_widget);
for (int i = 0; i < originalCodeStyleFallbacks.count(); i++) {
TextEditor::IFallbackPreferences *fallback = originalCodeStyleFallbacks.at(i);
m_pageCppCodeStylePreferences->setFallbackEnabled(fallback, originalCodeStylePreferences->isFallbackEnabled(fallback));
}
m_pageCppCodeStylePreferences->setSettings(originalCodeStylePreferences->settings());
m_pageCppCodeStylePreferences->setCurrentFallback(originalCodeStylePreferences->currentFallback());
m_widget->setPreferences(m_pageCppCodeStylePreferences, m_pageTabPreferences);
= CppToolsSettings::instance()->cppCodeStyle();
m_pageCppCodeStylePreferences = new CppCodeStylePreferences(m_widget);
m_pageCppCodeStylePreferences->setDelegatingPool(originalCodeStylePreferences->delegatingPool());
m_pageCppCodeStylePreferences->setCodeStyleSettings(originalCodeStylePreferences->codeStyleSettings());
m_pageCppCodeStylePreferences->setCurrentDelegate(originalCodeStylePreferences->currentDelegate());
// we set id so that it won't be possible to set delegate to the original prefs
m_pageCppCodeStylePreferences->setId(originalCodeStylePreferences->id());
TextEditorSettings *settings = TextEditorSettings::instance();
m_widget = new CodeStyleEditor(settings->codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID),
m_pageCppCodeStylePreferences, parent);
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
return m_widget;
}
@@ -545,26 +537,19 @@ void CppCodeStyleSettingsPage::apply()
if (m_widget) {
QSettings *s = Core::ICore::instance()->settings();
TextEditor::TabPreferences *originalTabPreferences = CppToolsSettings::instance()->tabPreferences();
if (originalTabPreferences->settings() != m_pageTabPreferences->settings()) {
originalTabPreferences->setSettings(m_pageTabPreferences->settings());
if (s)
originalTabPreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
}
if (originalTabPreferences->currentFallback() != m_pageTabPreferences->currentFallback()) {
originalTabPreferences->setCurrentFallback(m_pageTabPreferences->currentFallback());
if (s)
originalTabPreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
}
CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStylePreferences();
if (originalCppCodeStylePreferences->settings() != m_pageCppCodeStylePreferences->settings()) {
originalCppCodeStylePreferences->setSettings(m_pageCppCodeStylePreferences->settings());
CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
if (originalCppCodeStylePreferences->codeStyleSettings() != m_pageCppCodeStylePreferences->codeStyleSettings()) {
originalCppCodeStylePreferences->setCodeStyleSettings(m_pageCppCodeStylePreferences->codeStyleSettings());
if (s)
originalCppCodeStylePreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
}
if (originalCppCodeStylePreferences->currentFallback() != m_pageCppCodeStylePreferences->currentFallback()) {
originalCppCodeStylePreferences->setCurrentFallback(m_pageCppCodeStylePreferences->currentFallback());
if (originalCppCodeStylePreferences->tabSettings() != m_pageCppCodeStylePreferences->tabSettings()) {
originalCppCodeStylePreferences->setTabSettings(m_pageCppCodeStylePreferences->tabSettings());
if (s)
originalCppCodeStylePreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
}
if (originalCppCodeStylePreferences->currentDelegate() != m_pageCppCodeStylePreferences->currentDelegate()) {
originalCppCodeStylePreferences->setCurrentDelegate(m_pageCppCodeStylePreferences->currentDelegate());
if (s)
originalCppCodeStylePreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
}
+10 -11
View File
@@ -48,9 +48,9 @@
namespace TextEditor {
class FontSettings;
class TabSettings;
class TabPreferences;
class IFallbackPreferences;
class ICodeStylePreferences;
class SnippetEditorWidget;
class CodeStyleEditor;
}
namespace CppTools {
@@ -70,24 +70,24 @@ public:
explicit CppCodeStylePreferencesWidget(QWidget *parent = 0);
virtual ~CppCodeStylePreferencesWidget();
void setPreferences(CppTools::CppCodeStylePreferences *codeStylePreferences,
TextEditor::TabPreferences *tabPreferences);
void setCodeStyle(CppTools::CppCodeStylePreferences *codeStylePreferences);
QString searchKeywords() const;
private slots:
void decorateEditors(const TextEditor::FontSettings &fontSettings);
void setVisualizeWhitespace(bool on);
void slotCppCodeStyleSettingsChanged();
void slotTabSettingsChanged(const TextEditor::TabSettings &settings);
void slotCodeStyleSettingsChanged();
void updatePreview();
void setCppCodeStyleSettings(const CppTools::CppCodeStyleSettings &settings, bool preview = true);
void slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *, bool preview = true);
void setTabSettings(const TextEditor::TabSettings &settings);
void setCodeStyleSettings(const CppTools::CppCodeStyleSettings &settings, bool preview = true);
void slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences *, bool preview = true);
private:
CppCodeStyleSettings cppCodeStyleSettings() const;
TextEditor::TabPreferences *m_tabPreferences;
CppCodeStylePreferences *m_cppCodeStylePreferences;
CppCodeStylePreferences *m_preferences;
Ui::CppCodeStyleSettingsPage *m_ui;
QList<TextEditor::SnippetEditorWidget *> m_previews;
bool m_blockUpdates;
@@ -115,9 +115,8 @@ public:
private:
QString m_searchKeywords;
TextEditor::TabPreferences *m_pageTabPreferences;
CppCodeStylePreferences *m_pageCppCodeStylePreferences;
QPointer<CppCodeStylePreferencesWidget> m_widget;
QPointer<TextEditor::CodeStyleEditor> m_widget;
};
} // namespace Internal
@@ -6,63 +6,57 @@
<rect>
<x>0</x>
<y>0</y>
<width>757</width>
<height>465</height>
<width>463</width>
<height>314</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QWidget" name="fallbackContainer" native="true">
<layout class="QHBoxLayout" name="fallbackLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="TextEditor::FallbackSelectorWidget" name="fallbackWidget" native="true"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTabWidget" name="categoryTab">
<property name="currentIndex">
<number>4</number>
<number>0</number>
</property>
<widget class="QWidget" name="generalTab">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="TextEditor::TabPreferencesWidget" name="tabPreferencesWidget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="TextEditor::TabSettingsWidget" name="tabSettingsWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item>
<item row="0" column="1" rowspan="2">
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEditGeneral">
<property name="plainText">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>347</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="contentTab">
@@ -413,23 +407,17 @@ if they would align to the next line</string>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TextEditor::TabSettingsWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/tabsettingswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TextEditor::SnippetEditorWidget</class>
<extends>QPlainTextEdit</extends>
<header location="global">texteditor/snippets/snippeteditor.h</header>
</customwidget>
<customwidget>
<class>TextEditor::TabPreferencesWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/tabpreferenceswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TextEditor::FallbackSelectorWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/fallbackselectorwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
+9 -3
View File
@@ -51,7 +51,7 @@ CppQtStyleIndenter::CppQtStyleIndenter()
{
// Just for safety. setCodeStylePreferences should be called when the editor the
// indenter belongs to gets initialized.
m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStylePreferences();
m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
}
CppQtStyleIndenter::~CppQtStyleIndenter()
@@ -148,7 +148,7 @@ void CppQtStyleIndenter::indent(QTextDocument *doc,
}
}
void CppQtStyleIndenter::setCodeStylePreferences(TextEditor::IFallbackPreferences *preferences)
void CppQtStyleIndenter::setCodeStylePreferences(TextEditor::ICodeStylePreferences *preferences)
{
CppTools::CppCodeStylePreferences *cppCodeStylePreferences
= qobject_cast<CppTools::CppCodeStylePreferences *>(preferences);
@@ -156,9 +156,15 @@ void CppQtStyleIndenter::setCodeStylePreferences(TextEditor::IFallbackPreference
m_cppCodeStylePreferences = cppCodeStylePreferences;
}
void CppQtStyleIndenter::invalidateCache(QTextDocument *doc)
{
CppTools::QtStyleCodeFormatter formatter;
formatter.invalidateCache(doc);
}
CppCodeStyleSettings CppQtStyleIndenter::codeStyleSettings() const
{
if (m_cppCodeStylePreferences)
return m_cppCodeStylePreferences->currentSettings();
return m_cppCodeStylePreferences->currentCodeStyleSettings();
return CppCodeStyleSettings();
}
+3 -2
View File
@@ -39,7 +39,7 @@
namespace TextEditor
{
class IFallbackPreferences;
class ICodeStylePreferences;
}
namespace CppTools {
@@ -63,7 +63,8 @@ public:
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings);
virtual void setCodeStylePreferences(TextEditor::IFallbackPreferences *preferences);
virtual void setCodeStylePreferences(TextEditor::ICodeStylePreferences *preferences);
virtual void invalidateCache(QTextDocument *doc);
private:
CppCodeStyleSettings codeStyleSettings() const;
CppCodeStylePreferences *m_cppCodeStylePreferences;
@@ -72,7 +72,7 @@ public:
ProjectExplorer::actualTabSettings(fileName, textEditor);
// TODO: add similar method like above one
CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
codeFormatter.updateStateUntil(block);
do {
+2 -2
View File
@@ -33,7 +33,7 @@ HEADERS += completionsettingspage.h \
cppcodestylesettingspage.h \
cpptoolssettings.h \
cppcodestylesettings.h \
cppcodestylesettingsfactory.h \
cppcodestylepreferencesfactory.h \
cppcodestylepreferences.h \
cpptoolsreuse.h
@@ -60,7 +60,7 @@ SOURCES += completionsettingspage.cpp \
cppcodestylesettingspage.cpp \
cpptoolssettings.cpp \
cppcodestylesettings.cpp \
cppcodestylesettingsfactory.cpp \
cppcodestylepreferencesfactory.cpp \
cppcodestylepreferences.cpp \
cpptoolsreuse.cpp
-16
View File
@@ -43,8 +43,6 @@
#include "symbolsfindfilter.h"
#include "cppcompletionassist.h"
#include "cpptoolssettings.h"
#include "cppcodestylesettingsfactory.h"
#include "cppcodestylesettings.h"
#include <extensionsystem/pluginmanager.h>
@@ -59,9 +57,6 @@
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/filemanager.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/codestylepreferencesmanager.h>
#include <cppeditor/cppeditorconstants.h>
#include <QtCore/QtConcurrentRun>
@@ -107,8 +102,6 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
Q_UNUSED(arguments)
Q_UNUSED(error)
qRegisterMetaType<CppTools::CppCodeStyleSettings>("CppTools::CppCodeStyleSettings");
Core::ICore *core = Core::ICore::instance();
Core::ActionManager *am = core->actionManager();
@@ -134,9 +127,6 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
addAutoReleasedObject(new SymbolsFindFilter(m_modelManager));
addAutoReleasedObject(new CppCodeStyleSettingsPage);
TextEditor::CodeStylePreferencesManager::instance()->registerFactory(
new CppTools::CppCodeStylePreferencesFactory());
// Menus
Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
Core::ActionContainer *mcpptools = am->createMenu(CppTools::Constants::M_TOOLS_CPP);
@@ -154,12 +144,6 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
mcpptools->addAction(command);
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource()));
TextEditor::TextEditorSettings *ts = TextEditor::TextEditorSettings::instance();
ts->registerMimeTypeForLanguageId(QLatin1String(Constants::C_SOURCE_MIMETYPE), Constants::CPP_SETTINGS_ID);
ts->registerMimeTypeForLanguageId(QLatin1String(Constants::C_HEADER_MIMETYPE), Constants::CPP_SETTINGS_ID);
ts->registerMimeTypeForLanguageId(QLatin1String(Constants::CPP_SOURCE_MIMETYPE), Constants::CPP_SETTINGS_ID);
ts->registerMimeTypeForLanguageId(QLatin1String(Constants::CPP_HEADER_MIMETYPE), Constants::CPP_SETTINGS_ID);
return true;
}
+164 -29
View File
@@ -33,10 +33,14 @@
#include "cpptoolssettings.h"
#include "cpptoolsconstants.h"
#include "cppcodestylepreferences.h"
#include "cppcodestylepreferencesfactory.h"
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/codestylepool.h>
#include <utils/settingsutils.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
#include <QtCore/QSettings>
@@ -44,15 +48,34 @@
static const char *idKey = "CppGlobal";
using namespace CppTools;
using TextEditor::TabSettings;
namespace CppTools {
namespace Internal {
class LegacySettings
{
public:
LegacySettings()
: m_legacyTransformed(false)
{ }
void fromMap(const QString &prefix, const QVariantMap &map)
{
m_fallbackId = map.value(prefix + QLatin1String("CurrentFallback")).toString();
m_legacyTransformed = map.value(prefix + QLatin1String("LegacyTransformed"), false).toBool();
}
void toMap(const QString &prefix, QVariantMap *map) const
{
map->insert(prefix + QLatin1String("LegacyTransformed"), true);
}
QString m_fallbackId;
bool m_legacyTransformed;
};
class CppToolsSettingsPrivate
{
public:
CppCodeStylePreferences *m_cppCodeStylePreferences;
TextEditor::TabPreferences *m_tabPreferences;
CppCodeStylePreferences *m_globalCodeStyle;
};
} // namespace Internal
@@ -66,27 +89,145 @@ CppToolsSettings::CppToolsSettings(QObject *parent)
{
QTC_ASSERT(!m_instance, return);
m_instance = this;
qRegisterMetaType<CppTools::CppCodeStyleSettings>("CppTools::CppCodeStyleSettings");
if (const QSettings *s = Core::ICore::instance()->settings()) {
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
TextEditor::TabPreferences *tabPrefs = textEditorSettings->tabPreferences();
d->m_tabPreferences
= new TextEditor::TabPreferences(QList<TextEditor::IFallbackPreferences *>()
<< tabPrefs, this);
d->m_tabPreferences->setCurrentFallback(tabPrefs);
d->m_tabPreferences->setFallbackEnabled(tabPrefs, false);
d->m_tabPreferences->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
d->m_tabPreferences->setDisplayName(tr("Global C++", "Settings"));
d->m_tabPreferences->setId(idKey);
textEditorSettings->registerLanguageTabPreferences(CppTools::Constants::CPP_SETTINGS_ID, d->m_tabPreferences);
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
d->m_cppCodeStylePreferences
= new CppCodeStylePreferences(QList<TextEditor::IFallbackPreferences *>(), this);
d->m_cppCodeStylePreferences->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
d->m_cppCodeStylePreferences->setDisplayName(tr("Global C++", "Settings"));
d->m_cppCodeStylePreferences->setId(idKey);
textEditorSettings->registerLanguageCodeStylePreferences(CppTools::Constants::CPP_SETTINGS_ID, d->m_cppCodeStylePreferences);
// code style factory
TextEditor::ICodeStylePreferencesFactory *factory = new CppTools::CppCodeStylePreferencesFactory();
textEditorSettings->registerCodeStyleFactory(factory);
// code style pool
TextEditor::CodeStylePool *pool = new TextEditor::CodeStylePool(factory, this);
textEditorSettings->registerCodeStylePool(Constants::CPP_SETTINGS_ID, pool);
// global code style settings
d->m_globalCodeStyle = new CppCodeStylePreferences(this);
d->m_globalCodeStyle->setDelegatingPool(pool);
d->m_globalCodeStyle->setDisplayName(tr("Global", "Settings"));
d->m_globalCodeStyle->setId(idKey);
pool->addCodeStyle(d->m_globalCodeStyle);
textEditorSettings->registerCodeStyle(CppTools::Constants::CPP_SETTINGS_ID, d->m_globalCodeStyle);
/*
For every language we have exactly 1 pool. The pool contains:
1) All built-in code styles (Qt/GNU)
2) All custom code styles (which will be added dynamically)
3) A global code style
If the code style gets a pool (setCodeStylePool()) it means it can behave
like a proxy to one of the code styles from that pool
(ICodeStylePreferences::setCurrentDelegate()).
That's why the global code style gets a pool (it can point to any code style
from the pool), while built-in and custom code styles don't get a pool
(they can't point to any other code style).
The instance of the language pool is shared. The same instance of the pool
is used for all project code style settings and for global one.
Project code style can point to one of built-in or custom code styles
or to the global one as well. That's why the global code style is added
to the pool. The proxy chain can look like:
ProjectCodeStyle -> GlobalCodeStyle -> BuildInCodeStyle (e.g. Qt).
With the global pool there is an exception - it gets a pool
in which it exists itself. The case in which a code style point to itself
is disallowed and is handled in ICodeStylePreferences::setCurrentDelegate().
*/
// built-in settings
// Qt style
CppCodeStylePreferences *qtCodeStyle = new CppCodeStylePreferences();
qtCodeStyle->setId(QLatin1String("qt"));
qtCodeStyle->setDisplayName(tr("Qt"));
qtCodeStyle->setReadOnly(true);
TabSettings qtTabSettings;
qtTabSettings.m_tabPolicy = TabSettings::SpacesOnlyTabPolicy;
qtTabSettings.m_tabSize = 4;
qtTabSettings.m_indentSize = 4;
qtTabSettings.m_continuationAlignBehavior = TabSettings::ContinuationAlignWithIndent;
qtCodeStyle->setTabSettings(qtTabSettings);
pool->addCodeStyle(qtCodeStyle);
// GNU style
CppCodeStylePreferences *gnuCodeStyle = new CppCodeStylePreferences();
gnuCodeStyle->setId(QLatin1String("gnu"));
gnuCodeStyle->setDisplayName(tr("GNU"));
gnuCodeStyle->setReadOnly(true);
TabSettings gnuTabSettings;
gnuTabSettings.m_tabPolicy = TabSettings::MixedTabPolicy;
gnuTabSettings.m_tabSize = 8;
gnuTabSettings.m_indentSize = 2;
gnuTabSettings.m_continuationAlignBehavior = TabSettings::ContinuationAlignWithIndent;
gnuCodeStyle->setTabSettings(gnuTabSettings);
CppCodeStyleSettings gnuCodeStyleSettings;
gnuCodeStyleSettings.indentNamespaceBody = true;
gnuCodeStyleSettings.indentBlockBraces = true;
gnuCodeStyleSettings.indentSwitchLabels = true;
gnuCodeStyleSettings.indentBlocksRelativeToSwitchLabels = true;
gnuCodeStyle->setCodeStyleSettings(gnuCodeStyleSettings);
pool->addCodeStyle(gnuCodeStyle);
// default delegate for global preferences
d->m_globalCodeStyle->setCurrentDelegate(qtCodeStyle);
pool->loadCustomCodeStyles();
// load global settings (after built-in settings are added to the pool)
if (QSettings *s = Core::ICore::instance()->settings()) {
d->m_globalCodeStyle->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
// legacy handling start (Qt Creator <= 2.3)
Internal::LegacySettings legacySettings;
TabSettings legacyTabSettings;
Utils::fromSettings(QLatin1String("TabPreferences"),
QLatin1String("Cpp"), s, &legacySettings);
if (legacySettings.m_fallbackId == QLatin1String("CppGlobal")) {
Utils::fromSettings(QLatin1String("TabPreferences"),
QLatin1String("Cpp"), s, &legacyTabSettings);
} else {
legacyTabSettings = textEditorSettings->codeStyle()->currentTabSettings();
}
CppCodeStyleSettings legacyCodeStyleSettings;
Utils::fromSettings(QLatin1String("CodeStyleSettings"),
QLatin1String("Cpp"), s, &legacySettings);
if (!legacySettings.m_legacyTransformed
&& legacySettings.m_fallbackId == QLatin1String("CppGlobal")) {
Utils::fromSettings(QLatin1String("CodeStyleSettings"),
QLatin1String("Cpp"), s, &legacyCodeStyleSettings);
// create custom code style out of old settings
QVariant v;
v.setValue(legacyCodeStyleSettings);
TextEditor::ICodeStylePreferences *oldCreator = pool->createCodeStyle(
QLatin1String("legacy"), legacyTabSettings,
v, tr("Old Creator"));
// change the current delegate and save
d->m_globalCodeStyle->setCurrentDelegate(oldCreator);
d->m_globalCodeStyle->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
// mark old settings as transformed,
// we create only once "Old Creator" custom settings
Utils::toSettings(QLatin1String("CodeStyleSettings"),
QLatin1String("Cpp"), s, &legacySettings);
}
// legacy handling stop
}
// mimetypes to be handled
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::C_SOURCE_MIMETYPE),
Constants::CPP_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::C_HEADER_MIMETYPE),
Constants::CPP_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::CPP_SOURCE_MIMETYPE),
Constants::CPP_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::CPP_HEADER_MIMETYPE),
Constants::CPP_SETTINGS_ID);
}
CppToolsSettings::~CppToolsSettings()
@@ -101,14 +242,8 @@ CppToolsSettings *CppToolsSettings::instance()
return m_instance;
}
CppCodeStylePreferences *CppToolsSettings::cppCodeStylePreferences() const
CppCodeStylePreferences *CppToolsSettings::cppCodeStyle() const
{
return d->m_cppCodeStylePreferences;
return d->m_globalCodeStyle;
}
TextEditor::TabPreferences *CppToolsSettings::tabPreferences() const
{
return d->m_tabPreferences;
}
+1 -7
View File
@@ -37,11 +37,6 @@
#include <QtCore/QObject>
namespace TextEditor
{
class TabPreferences;
}
namespace CppTools
{
class CppCodeStylePreferences;
@@ -65,8 +60,7 @@ public:
static CppToolsSettings *instance();
CppCodeStylePreferences *cppCodeStylePreferences() const;
TextEditor::TabPreferences *tabPreferences() const;
CppCodeStylePreferences *cppCodeStyle() const;
private:
Internal::CppToolsSettingsPrivate *d;
+9 -6
View File
@@ -58,8 +58,9 @@
#include <texteditor/basetexteditor.h>
#include <texteditor/basetextmark.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/typingsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/icodestylepreferences.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/indenter.h>
#include <texteditor/codeassist/basicproposalitem.h>
@@ -284,14 +285,15 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent)
void FakeVimOptionPage::copyTextEditorSettings()
{
TabSettings ts = TextEditorSettings::instance()->tabPreferences()->settings();
m_ui.checkBoxExpandTab->setChecked(ts.m_spacesForTabs);
TabSettings ts = TextEditorSettings::instance()->codeStyle()->tabSettings();
TypingSettings tps = TextEditorSettings::instance()->typingSettings();
m_ui.checkBoxExpandTab->setChecked(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy);
m_ui.spinBoxTabStop->setValue(ts.m_tabSize);
m_ui.spinBoxShiftWidth->setValue(ts.m_indentSize);
m_ui.checkBoxSmartTab->setChecked(
ts.m_smartBackspaceBehavior == TabSettings::BackspaceFollowsPreviousIndents);
tps.m_smartBackspaceBehavior == TypingSettings::BackspaceFollowsPreviousIndents);
m_ui.checkBoxAutoIndent->setChecked(true);
m_ui.checkBoxSmartIndent->setChecked(ts.m_autoIndent);
m_ui.checkBoxSmartIndent->setChecked(tps.m_autoIndent);
m_ui.checkBoxIncSearch->setChecked(true);
}
@@ -1659,7 +1661,8 @@ void FakeVimPluginPrivate::indentRegion(int beginLine, int endLine,
TabSettings tabSettings;
tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt();
tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt();
tabSettings.m_spacesForTabs = theFakeVimSetting(ConfigExpandTab)->value().toBool();
tabSettings.m_tabPolicy = theFakeVimSetting(ConfigExpandTab)->value().toBool()
? TabSettings::SpacesOnlyTabPolicy : TabSettings::TabsOnlyTabPolicy;
QTextDocument *doc = bt->document();
QTextBlock startBlock = doc->findBlockByNumber(beginLine);
@@ -49,8 +49,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/taskhub.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/fontsettings.h>
#include <texteditor/storagesettings.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/textfilewizard.h>
+2 -2
View File
@@ -71,7 +71,7 @@ void GLSLIndenter::indentBlock(QTextDocument *doc,
// TODO: do something with it
CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
CppTools::CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
codeFormatter.updateStateUntil(block);
int indent;
@@ -102,7 +102,7 @@ void GLSLIndenter::indent(QTextDocument *doc,
// TODO: do something with it
CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
CppTools::CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
codeFormatter.updateStateUntil(block);
QTextCursor tc = cursor;
@@ -79,7 +79,13 @@ bool BuildSettingsPanelFactory::supports(Target *target)
PropertiesPanel *BuildSettingsPanelFactory::createPanel(Target *target)
{
PropertiesPanel *panel = new PropertiesPanel;
panel->setWidget(new BuildSettingsWidget(target));
QWidget *w = new QWidget();
QVBoxLayout *l = new QVBoxLayout(w);
QWidget *b = new BuildSettingsWidget(target);
l->addWidget(b);
l->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
l->setContentsMargins(QMargins());
panel->setWidget(w);
panel->setIcon(QIcon(":/projectexplorer/images/BuildSettings.png"));
panel->setDisplayName(QCoreApplication::translate("BuildSettingsPanel", "Build Settings"));
return panel;
@@ -33,8 +33,9 @@
#include "codestylesettingspropertiespage.h"
#include "editorconfiguration.h"
#include "project.h"
#include <texteditor/codestylepreferencesmanager.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/icodestylepreferencesfactory.h>
#include <texteditor/codestyleeditor.h>
#include <QtCore/QTextCodec>
@@ -72,18 +73,19 @@ CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project) : QWidget(),
m_ui.setupUi(this);
const EditorConfiguration *config = m_project->editorConfiguration();
CodeStylePreferencesManager *manager =
CodeStylePreferencesManager::instance();
QList<ICodeStylePreferencesFactory *> factories = manager->factories();
for (int i = 0; i < factories.count(); i++) {
ICodeStylePreferencesFactory *factory = factories.at(i);
QMap<QString, ICodeStylePreferencesFactory *> factories
= TextEditor::TextEditorSettings::instance()->codeStyleFactories();
QMapIterator<QString, ICodeStylePreferencesFactory *> it(factories);
while (it.hasNext()) {
it.next();
ICodeStylePreferencesFactory *factory = it.value();
const QString languageId = factory->languageId();
TabPreferences *tabPreferences = config->tabPreferences(languageId);
IFallbackPreferences *codeStylePreferences = config->codeStylePreferences(languageId);
ICodeStylePreferences *codeStylePreferences = config->codeStyle(languageId);
QWidget *widget = factory->createEditor(codeStylePreferences, tabPreferences, m_ui.stackedWidget);
m_ui.stackedWidget->addWidget(widget);
CodeStyleEditor *preview = new CodeStyleEditor(factory, codeStylePreferences, m_ui.stackedWidget);
preview->clearMargins();
m_ui.stackedWidget->addWidget(preview);
m_ui.languageComboBox->addItem(factory->displayName());
}
@@ -91,4 +93,3 @@ CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project) : QWidget(),
m_ui.stackedWidget, SLOT(setCurrentIndex(int)));
}
@@ -41,11 +41,12 @@
#include <texteditor/basetexteditor.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/typingsettings.h>
#include <texteditor/storagesettings.h>
#include <texteditor/behaviorsettings.h>
#include <texteditor/extraencodingsettings.h>
#include <texteditor/codestylepreferencesmanager.h>
#include <texteditor/icodestylepreferences.h>
#include <texteditor/icodestylepreferencesfactory.h>
#include <QtCore/QLatin1String>
@@ -56,8 +57,6 @@
static const QLatin1String kPrefix("EditorConfiguration.");
static const QLatin1String kUseGlobal("EditorConfiguration.UseGlobal");
static const QLatin1String kCodec("EditorConfiguration.Codec");
static const QLatin1String kTabPrefix("EditorConfiguration.Tab.");
static const QLatin1String kTabCount("EditorConfiguration.Tab.Count");
static const QLatin1String kCodeStylePrefix("EditorConfiguration.CodeStyle.");
static const QLatin1String kCodeStyleCount("EditorConfiguration.CodeStyle.Count");
static const QLatin1String kId("Project");
@@ -70,7 +69,7 @@ struct EditorConfigurationPrivate
{
EditorConfigurationPrivate()
: m_useGlobal(true)
, m_tabPreferences(0)
, m_typingSettings(TextEditorSettings::instance()->typingSettings())
, m_storageSettings(TextEditorSettings::instance()->storageSettings())
, m_behaviorSettings(TextEditorSettings::instance()->behaviorSettings())
, m_extraEncodingSettings(TextEditorSettings::instance()->extraEncodingSettings())
@@ -79,71 +78,44 @@ struct EditorConfigurationPrivate
}
bool m_useGlobal;
TabPreferences *m_tabPreferences;
ICodeStylePreferences *m_defaultCodeStyle;
TypingSettings m_typingSettings;
StorageSettings m_storageSettings;
BehaviorSettings m_behaviorSettings;
ExtraEncodingSettings m_extraEncodingSettings;
QTextCodec *m_textCodec;
QMap<QString, TabPreferences *> m_languageTabPreferences;
QMap<QString, IFallbackPreferences *> m_languageCodeStylePreferences;
QMap<QString, ICodeStylePreferences *> m_languageCodeStylePreferences;
};
EditorConfiguration::EditorConfiguration() : d(new EditorConfigurationPrivate)
{
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
QList<TabPreferences *> tabFallbacks;
tabFallbacks << textEditorSettings->tabPreferences();
d->m_tabPreferences = new TabPreferences(tabFallbacks, this);
d->m_tabPreferences->setFallbackEnabled(textEditorSettings->tabPreferences(), false);
d->m_tabPreferences->setDisplayName(tr("Project", "Settings"));
d->m_tabPreferences->setId(kId);
TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
CodeStylePreferencesManager *manager =
CodeStylePreferencesManager::instance();
TextEditorSettings *settings = TextEditorSettings::instance();
const QMap<QString, TabPreferences *> languageTabPreferences = settings->languageTabPreferences();
QMapIterator<QString, TabPreferences *> itTab(languageTabPreferences);
while (itTab.hasNext()) {
itTab.next();
const QString languageId = itTab.key();
TabPreferences *originalPreferences = itTab.value();
QList<IFallbackPreferences *> fallbacks;
fallbacks << originalPreferences->fallbacks();
fallbacks << originalPreferences;
fallbacks << tabPreferences();
TabPreferences *preferences = new TabPreferences(
fallbacks, this);
for (int i = 0; i < fallbacks.count(); i++)
preferences->setFallbackEnabled(fallbacks.at(i), false);
preferences->setId(languageId + QLatin1String("Project"));
preferences->setCurrentFallback(originalPreferences);
d->m_languageTabPreferences.insert(languageId, preferences);
}
const QMap<QString, IFallbackPreferences *> languageCodeStylePreferences = settings->languageCodeStylePreferences();
QMapIterator<QString, IFallbackPreferences *> itCodeStyle(languageCodeStylePreferences);
const QMap<QString, ICodeStylePreferences *> languageCodeStylePreferences = textEditorSettings->codeStyles();
QMapIterator<QString, ICodeStylePreferences *> itCodeStyle(languageCodeStylePreferences);
while (itCodeStyle.hasNext()) {
itCodeStyle.next();
const QString languageId = itCodeStyle.key();
IFallbackPreferences *originalPreferences = itCodeStyle.value();
ICodeStylePreferencesFactory *factory = manager->factory(languageId);
IFallbackPreferences *preferences = factory->createPreferences(
QList<IFallbackPreferences *>() << originalPreferences);
preferences->setFallbackEnabled(originalPreferences, false);
ICodeStylePreferences *originalPreferences = itCodeStyle.value();
ICodeStylePreferencesFactory *factory = textEditorSettings->codeStyleFactory(languageId);
ICodeStylePreferences *preferences = factory->createCodeStyle();
preferences->setDelegatingPool(textEditorSettings->codeStylePool(languageId));
preferences->setId(languageId + QLatin1String("Project"));
preferences->setDisplayName(tr("Project %1", "Settings, %1 is a language (C++ or QML)").arg(factory->displayName()));
preferences->setCurrentFallback(originalPreferences);
preferences->setCurrentDelegate(originalPreferences);
d->m_languageCodeStylePreferences.insert(languageId, preferences);
}
d->m_defaultCodeStyle = new SimpleCodeStylePreferences(this);
d->m_defaultCodeStyle->setDelegatingPool(textEditorSettings->codeStylePool());
d->m_defaultCodeStyle->setDisplayName(tr("Project", "Settings"));
d->m_defaultCodeStyle->setId(kId);
}
EditorConfiguration::~EditorConfiguration()
{
qDeleteAll(d->m_languageTabPreferences.values());
qDeleteAll(d->m_languageCodeStylePreferences.values());
delete d;
}
bool EditorConfiguration::useGlobalSettings() const
@@ -153,10 +125,13 @@ bool EditorConfiguration::useGlobalSettings() const
void EditorConfiguration::cloneGlobalSettings()
{
d->m_tabPreferences->setSettings(TextEditorSettings::instance()->tabPreferences()->settings());
setStorageSettings(TextEditorSettings::instance()->storageSettings());
setBehaviorSettings(TextEditorSettings::instance()->behaviorSettings());
setExtraEncodingSettings(TextEditorSettings::instance()->extraEncodingSettings());
TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
d->m_defaultCodeStyle->setTabSettings(textEditorSettings->codeStyle()->tabSettings());
setTypingSettings(textEditorSettings->typingSettings());
setStorageSettings(textEditorSettings->storageSettings());
setBehaviorSettings(textEditorSettings->behaviorSettings());
setExtraEncodingSettings(textEditorSettings->extraEncodingSettings());
d->m_textCodec = Core::EditorManager::instance()->defaultTextCodec();
}
@@ -165,9 +140,9 @@ QTextCodec *EditorConfiguration::textCodec() const
return d->m_textCodec;
}
TabPreferences *EditorConfiguration::tabPreferences() const
const TypingSettings &EditorConfiguration::typingSettings() const
{
return d->m_tabPreferences;
return d->m_typingSettings;
}
const StorageSettings &EditorConfiguration::storageSettings() const
@@ -185,25 +160,17 @@ const ExtraEncodingSettings &EditorConfiguration::extraEncodingSettings() const
return d->m_extraEncodingSettings;
}
TabPreferences *EditorConfiguration::tabPreferences(const QString &languageId) const
ICodeStylePreferences *EditorConfiguration::codeStyle() const
{
TabPreferences *prefs = d->m_languageTabPreferences.value(languageId);
if (!prefs)
prefs = d->m_tabPreferences;
return prefs;
return d->m_defaultCodeStyle;
}
QMap<QString, TabPreferences *> EditorConfiguration::languageTabPreferences() const
ICodeStylePreferences *EditorConfiguration::codeStyle(const QString &languageId) const
{
return d->m_languageTabPreferences;
return d->m_languageCodeStylePreferences.value(languageId, codeStyle());
}
IFallbackPreferences *EditorConfiguration::codeStylePreferences(const QString &languageId) const
{
return d->m_languageCodeStylePreferences.value(languageId);
}
QMap<QString, IFallbackPreferences *> EditorConfiguration::languageCodeStylePreferences() const
QMap<QString, ICodeStylePreferences *> EditorConfiguration::codeStyles() const
{
return d->m_languageCodeStylePreferences;
}
@@ -214,23 +181,9 @@ QVariantMap EditorConfiguration::toMap() const
map.insert(kUseGlobal, d->m_useGlobal);
map.insert(kCodec, d->m_textCodec->name());
map.insert(kTabCount, d->m_languageTabPreferences.count());
QMapIterator<QString, TabPreferences *> itTab(d->m_languageTabPreferences);
int i = 0;
while (itTab.hasNext()) {
itTab.next();
QVariantMap settingsIdMap;
settingsIdMap.insert(QLatin1String("language"), itTab.key());
QVariantMap value;
itTab.value()->toMap(QString(), &value);
settingsIdMap.insert(QLatin1String("value"), value);
map.insert(kTabPrefix + QString::number(i), settingsIdMap);
i++;
}
map.insert(kCodeStyleCount, d->m_languageCodeStylePreferences.count());
QMapIterator<QString, IFallbackPreferences *> itCodeStyle(d->m_languageCodeStylePreferences);
i = 0;
QMapIterator<QString, ICodeStylePreferences *> itCodeStyle(d->m_languageCodeStylePreferences);
int i = 0;
while (itCodeStyle.hasNext()) {
itCodeStyle.next();
QVariantMap settingsIdMap;
@@ -242,7 +195,8 @@ QVariantMap EditorConfiguration::toMap() const
i++;
}
d->m_tabPreferences->toMap(kPrefix, &map);
d->m_defaultCodeStyle->tabSettings().toMap(kPrefix, &map);
d->m_typingSettings.toMap(kPrefix, &map);
d->m_storageSettings.toMap(kPrefix, &map);
d->m_behaviorSettings.toMap(kPrefix, &map);
d->m_extraEncodingSettings.toMap(kPrefix, &map);
@@ -259,21 +213,6 @@ void EditorConfiguration::fromMap(const QVariantMap &map)
if (!d->m_textCodec)
d->m_textCodec = Core::EditorManager::instance()->defaultTextCodec();
const int tabCount = map.value(kTabCount, 0).toInt();
for (int i = 0; i < tabCount; ++i) {
QVariantMap settingsIdMap = map.value(kTabPrefix + QString::number(i)).toMap();
if (settingsIdMap.isEmpty()) {
qWarning() << "No data for tab settings list" << i << "found!";
continue;
}
QString languageId = settingsIdMap.value(QLatin1String("language")).toString();
QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
TabPreferences *preferences = d->m_languageTabPreferences.value(languageId);
if (preferences) {
preferences->fromMap(QString(), value);
}
}
const int codeStyleCount = map.value(kCodeStyleCount, 0).toInt();
for (int i = 0; i < codeStyleCount; ++i) {
QVariantMap settingsIdMap = map.value(kCodeStylePrefix + QString::number(i)).toMap();
@@ -283,15 +222,14 @@ void EditorConfiguration::fromMap(const QVariantMap &map)
}
QString languageId = settingsIdMap.value(QLatin1String("language")).toString();
QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
IFallbackPreferences *preferences = d->m_languageCodeStylePreferences.value(languageId);
ICodeStylePreferences *preferences = d->m_languageCodeStylePreferences.value(languageId);
if (preferences) {
preferences->fromMap(QString(), value);
}
}
d->m_tabPreferences->fromMap(kPrefix, map);
d->m_tabPreferences->setCurrentFallback(d->m_useGlobal
? TextEditorSettings::instance()->tabPreferences() : 0);
d->m_defaultCodeStyle->fromMap(kPrefix, map);
d->m_typingSettings.fromMap(kPrefix, map);
d->m_storageSettings.fromMap(kPrefix, map);
d->m_behaviorSettings.fromMap(kPrefix, map);
d->m_extraEncodingSettings.fromMap(kPrefix, map);
@@ -300,8 +238,7 @@ void EditorConfiguration::fromMap(const QVariantMap &map)
void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
{
BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(textEditor->widget());
baseTextEditor->setTabPreferences(tabPreferences(baseTextEditor->languageSettingsId()));
baseTextEditor->setCodeStylePreferences(codeStylePreferences(baseTextEditor->languageSettingsId()));
baseTextEditor->setCodeStyle(codeStyle(baseTextEditor->languageSettingsId()));
if (!d->m_useGlobal) {
textEditor->setTextCodec(d->m_textCodec, ITextEditor::TextCodecFromProjectSetting);
if (baseTextEditor)
@@ -312,8 +249,8 @@ void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
void EditorConfiguration::setUseGlobalSettings(bool use)
{
d->m_useGlobal = use;
d->m_tabPreferences->setCurrentFallback(d->m_useGlobal
? TextEditorSettings::instance()->tabPreferences() : 0);
d->m_defaultCodeStyle->setCurrentDelegate(d->m_useGlobal
? TextEditorSettings::instance()->codeStyle() : 0);
const SessionManager *session = ProjectExplorerPlugin::instance()->session();
QList<Core::IEditor *> opened = Core::EditorManager::instance()->openedEditors();
foreach (Core::IEditor *editor, opened) {
@@ -338,10 +275,13 @@ void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender,
const OldSenderT *oldSender,
BaseTextEditorWidget *baseTextEditor) const
{
baseTextEditor->setTypingSettings(newSender->typingSettings());
baseTextEditor->setStorageSettings(newSender->storageSettings());
baseTextEditor->setBehaviorSettings(newSender->behaviorSettings());
baseTextEditor->setExtraEncodingSettings(newSender->extraEncodingSettings());
disconnect(oldSender, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
baseTextEditor, SLOT(setTypingSettings(TextEditor::TypingSettings)));
disconnect(oldSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
baseTextEditor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
disconnect(oldSender, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -349,6 +289,8 @@ void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender,
disconnect(oldSender, SIGNAL(extraEncodingSettingsChanged(TextEditor::ExtraEncodingSettings)),
baseTextEditor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings)));
connect(newSender, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
baseTextEditor, SLOT(setTypingSettings(TextEditor::TypingSettings)));
connect(newSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
baseTextEditor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
connect(newSender, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -357,6 +299,12 @@ void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender,
baseTextEditor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings)));
}
void EditorConfiguration::setTypingSettings(const TextEditor::TypingSettings &settings)
{
d->m_typingSettings = settings;
emit typingSettingsChanged(d->m_typingSettings);
}
void EditorConfiguration::setStorageSettings(const TextEditor::StorageSettings &settings)
{
d->m_storageSettings = settings;
@@ -388,9 +336,9 @@ TabSettings actualTabSettings(const QString &fileName,
} else {
const SessionManager *session = ProjectExplorerPlugin::instance()->session();
if (Project *project = session->projectForFile(fileName))
return project->editorConfiguration()->tabPreferences()->settings();
return project->editorConfiguration()->codeStyle()->tabSettings();
else
return TextEditorSettings::instance()->tabPreferences()->settings();
return TextEditorSettings::instance()->codeStyle()->tabSettings();
}
}
@@ -42,8 +42,8 @@ namespace TextEditor {
class ITextEditor;
class BaseTextEditorWidget;
class TabSettings;
class TabPreferences;
class IFallbackPreferences;
class ICodeStylePreferences;
class TypingSettings;
class StorageSettings;
class BehaviorSettings;
class ExtraEncodingSettings;
@@ -68,15 +68,14 @@ public:
// The default codec is returned in the case the project doesn't override it.
QTextCodec *textCodec() const;
TextEditor::TabPreferences *tabPreferences() const;
const TextEditor::TypingSettings &typingSettings() const;
const TextEditor::StorageSettings &storageSettings() const;
const TextEditor::BehaviorSettings &behaviorSettings() const;
const TextEditor::ExtraEncodingSettings &extraEncodingSettings() const;
TextEditor::TabPreferences *tabPreferences(const QString &languageId) const;
QMap<QString, TextEditor::TabPreferences *> languageTabPreferences() const;
TextEditor::IFallbackPreferences *codeStylePreferences(const QString &languageId) const;
QMap<QString, TextEditor::IFallbackPreferences *> languageCodeStylePreferences() const;
TextEditor::ICodeStylePreferences *codeStyle() const;
TextEditor::ICodeStylePreferences *codeStyle(const QString &languageId) const;
QMap<QString, TextEditor::ICodeStylePreferences *> codeStyles() const;
void configureEditor(TextEditor::ITextEditor *textEditor) const;
@@ -84,12 +83,14 @@ public:
void fromMap(const QVariantMap &map);
signals:
void typingSettingsChanged(const TextEditor::TypingSettings &);
void storageSettingsChanged(const TextEditor::StorageSettings &);
void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
private slots:
void setTypingSettings(const TextEditor::TypingSettings &settings);
void setStorageSettings(const TextEditor::StorageSettings &settings);
void setBehaviorSettings(const TextEditor::BehaviorSettings &settings);
void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &settings);
@@ -33,7 +33,6 @@
#include "editorsettingspropertiespage.h"
#include "editorconfiguration.h"
#include "project.h"
#include <texteditor/tabpreferences.h>
#include <QtCore/QTextCodec>
@@ -77,6 +76,8 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj
connect(m_ui.globalSelector, SIGNAL(activated(int)),
this, SLOT(globalSettingsActivated(int)));
connect(m_ui.restoreButton, SIGNAL(clicked()), this, SLOT(restoreDefaultValues()));
connect(m_ui.behaviorSettingsWidget, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
config, SLOT(setTypingSettings(TextEditor::TypingSettings)));
connect(m_ui.behaviorSettingsWidget, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
config, SLOT(setStorageSettings(TextEditor::StorageSettings)));
connect(m_ui.behaviorSettingsWidget, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -85,15 +86,14 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj
config, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings)));
connect(m_ui.behaviorSettingsWidget, SIGNAL(textCodecChanged(QTextCodec*)),
config, SLOT(setTextCodec(QTextCodec*)));
m_ui.behaviorSettingsWidget->setFallbacksVisible(false);
}
void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config)
{
m_ui.behaviorSettingsWidget->setTabPreferences(config->tabPreferences());
m_ui.behaviorSettingsWidget->setCodeStyle(config->codeStyle());
m_ui.globalSelector->setCurrentIndex(config->useGlobalSettings() ? 0 : 1);
m_ui.behaviorSettingsWidget->setAssignedCodec(config->textCodec());
m_ui.behaviorSettingsWidget->setAssignedTypingSettings(config->typingSettings());
m_ui.behaviorSettingsWidget->setAssignedStorageSettings(config->storageSettings());
m_ui.behaviorSettingsWidget->setAssignedBehaviorSettings(config->behaviorSettings());
m_ui.behaviorSettingsWidget->setAssignedExtraEncodingSettings(config->extraEncodingSettings());
@@ -60,7 +60,6 @@
#include "metatypedeclarations.h"
#include "nodesvisitor.h"
#include "appoutputpane.h"
#include "persistentsettings.h"
#include "pluginfilefactory.h"
#include "processstep.h"
#include "projectexplorerconstants.h"
@@ -115,6 +114,7 @@
#include <utils/qtcassert.h>
#include <utils/parameteraction.h>
#include <utils/stringutils.h>
#include <utils/persistentsettings.h>
#include <QtCore/QtPlugin>
#include <QtCore/QDateTime>
@@ -30,7 +30,6 @@ HEADERS += projectexplorer.h \
showoutputtaskhandler.h \
vcsannotatetaskhandler.h \
taskwindow.h \
persistentsettings.h \
projectfilewizardextension.h \
session.h \
dependenciespanel.h \
@@ -127,7 +126,6 @@ SOURCES += projectexplorer.cpp \
showoutputtaskhandler.cpp \
vcsannotatetaskhandler.cpp \
taskwindow.cpp \
persistentsettings.cpp \
projectfilewizardextension.cpp \
session.cpp \
dependenciespanel.cpp \
@@ -49,10 +49,10 @@
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/indenter.h>
#include <texteditor/codestylepreferencesmanager.h>
#include <texteditor/icodestylepreferences.h>
#include <texteditor/icodestylepreferencesfactory.h>
#include <texteditor/normalindenter.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/tabsettings.h>
#include <projectexplorer/project.h>
#include <projectexplorer/editorconfiguration.h>
@@ -499,27 +499,15 @@ bool ProjectFileWizardExtension::processVersionControl(const QList<Core::Generat
return true;
}
static TextEditor::TabPreferences *tabPreferences(ProjectExplorer::Project *project, const QString &languageId)
{
if (!languageId.isEmpty()) {
if (project)
return project->editorConfiguration()->tabPreferences(languageId);
return TextEditor::TextEditorSettings::instance()->tabPreferences(languageId);
} else if (project) {
return project->editorConfiguration()->tabPreferences();
}
return TextEditor::TextEditorSettings::instance()->tabPreferences();
}
static TextEditor::IFallbackPreferences *codeStylePreferences(ProjectExplorer::Project *project, const QString &languageId)
static TextEditor::ICodeStylePreferences *codeStylePreferences(ProjectExplorer::Project *project, const QString &languageId)
{
if (languageId.isEmpty())
return 0;
if (project)
return project->editorConfiguration()->codeStylePreferences(languageId);
return project->editorConfiguration()->codeStyle(languageId);
return TextEditor::TextEditorSettings::instance()->codeStylePreferences(languageId);
return TextEditor::TextEditorSettings::instance()->codeStyle(languageId);
}
void ProjectFileWizardExtension::applyCodeStyle(Core::GeneratedFile *file) const
@@ -543,7 +531,7 @@ void ProjectFileWizardExtension::applyCodeStyle(Core::GeneratedFile *file) const
= ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForNode(project);
TextEditor::ICodeStylePreferencesFactory *factory
= TextEditor::CodeStylePreferencesManager::instance()->factory(languageId);
= TextEditor::TextEditorSettings::instance()->codeStyleFactory(languageId);
TextEditor::Indenter *indenter = 0;
if (factory)
@@ -551,14 +539,13 @@ void ProjectFileWizardExtension::applyCodeStyle(Core::GeneratedFile *file) const
if (!indenter)
indenter = new TextEditor::NormalIndenter();
TextEditor::TabPreferences *tabPrefs = tabPreferences(baseProject, languageId);
TextEditor::IFallbackPreferences *codeStylePrefs = codeStylePreferences(baseProject, languageId);
TextEditor::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, tabPrefs->currentSettings());
indenter->indent(&doc, cursor, QChar::Null, codeStylePrefs->currentTabSettings());
file->setContents(doc.toPlainText());
delete indenter;
}
@@ -167,7 +167,6 @@ void PanelsWidget::addPropertiesPanel(PropertiesPanel *panel)
QTC_ASSERT(panel, return);
const int headerRow(m_layout->rowCount() - 1);
m_layout->setRowStretch(headerRow, 0);
// icon:
if (!panel->icon().isNull()) {
@@ -209,9 +208,6 @@ void PanelsWidget::addPanelWidget(PropertiesPanel *panel, int row)
widget->setParent(m_root);
m_layout->addWidget(widget, row, 0, 1, 2);
const int stretchRow(row + 1);
m_layout->setRowStretch(stretchRow, 10);
m_panels.append(panel);
}
@@ -92,7 +92,13 @@ bool RunSettingsPanelFactory::supports(Target *target)
PropertiesPanel *RunSettingsPanelFactory::createPanel(Target *target)
{
PropertiesPanel *panel = new PropertiesPanel;
panel->setWidget(new RunSettingsWidget(target));
QWidget *w = new QWidget();
QVBoxLayout *l = new QVBoxLayout(w);
QWidget *b = new RunSettingsWidget(target);
l->addWidget(b);
l->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
l->setContentsMargins(QMargins());
panel->setWidget(w);
panel->setIcon(QIcon(":/projectexplorer/images/RunSettings.png"));
panel->setDisplayName(QCoreApplication::translate("RunSettingsPanel", "Run Settings"));
return panel;
+3 -1
View File
@@ -38,7 +38,6 @@
#include "projectexplorerconstants.h"
#include "nodesvisitor.h"
#include "editorconfiguration.h"
#include "persistentsettings.h"
#include <coreplugin/icore.h>
#include <coreplugin/imode.h>
@@ -53,6 +52,7 @@
#include <utils/listutils.h>
#include <utils/qtcassert.h>
#include <utils/persistentsettings.h>
#include <QtCore/QDebug>
#include <QtCore/QDir>
@@ -72,6 +72,8 @@ namespace {
}
using namespace Core;
using Utils::PersistentSettingsReader;
using Utils::PersistentSettingsWriter;
/* SessionFile definitions */
namespace ProjectExplorer {
@@ -35,10 +35,11 @@
#include "toolchain.h"
#include <coreplugin/icore.h>
#include <projectexplorer/persistentsettings.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/persistentsettings.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QSettings>
@@ -52,6 +53,9 @@ static const char DEFAULT_DEBUGGER_ABI_KEY[] = "DefaultDebugger.Abi.";
static const char DEFAULT_DEBUGGER_PATH_KEY[] = "DefaultDebugger.Path.";
static const char TOOLCHAIN_FILENAME[] = "/toolChains.xml";
using Utils::PersistentSettingsWriter;
using Utils::PersistentSettingsReader;
static QString settingsFileName()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
@@ -33,7 +33,6 @@
#include "userfileaccessor.h"
#include "buildconfiguration.h"
#include "persistentsettings.h"
#include "project.h"
#include "projectexplorer.h"
#include "projectexplorersettings.h"
@@ -44,6 +43,7 @@
#include <coreplugin/ifile.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/persistentsettings.h>
#include <QtCore/QFile>
#include <QtGui/QApplication>
@@ -51,6 +51,8 @@
#include <QtGui/QMessageBox>
using namespace ProjectExplorer;
using Utils::PersistentSettingsReader;
using Utils::PersistentSettingsWriter;
namespace {
@@ -64,8 +64,6 @@
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/taskhub.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/fontsettings.h>
#include <texteditor/storagesettings.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/textfilewizard.h>
@@ -30,16 +30,37 @@
**
**************************************************************************/
#include "qmljscodestylesettingsfactory.h"
#include "qmljscodestylepreferencesfactory.h"
#include "qmljscodestylesettingspage.h"
#include "qmljstoolsconstants.h"
#include "qmljsindenter.h"
#include <texteditor/tabpreferences.h>
#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/tabsettings.h>
#include <texteditor/snippets/isnippetprovider.h>
#include <extensionsystem/pluginmanager.h>
#include <qmljseditor/qmljseditorconstants.h>
#include <QtGui/QLayout>
using namespace QmlJSTools;
static const char *defaultPreviewText =
"import QtQuick 1.0\n"
"\n"
"Rectangle {\n"
" width: 360\n"
" height: 360\n"
" Text {\n"
" anchors.centerIn: parent\n"
" text: \"Hello World\"\n"
" }\n"
" MouseArea {\n"
" anchors.fill: parent\n"
" onClicked: {\n"
" Qt.quit();\n"
" }\n"
" }\n"
"}\n";
QmlJSCodeStylePreferencesFactory::QmlJSCodeStylePreferencesFactory()
{
}
@@ -54,22 +75,17 @@ QString QmlJSCodeStylePreferencesFactory::displayName()
return Constants::QML_JS_SETTINGS_NAME;
}
TextEditor::IFallbackPreferences *QmlJSCodeStylePreferencesFactory::createPreferences(
const QList<TextEditor::IFallbackPreferences *> &fallbacks) const
TextEditor::ICodeStylePreferences *QmlJSCodeStylePreferencesFactory::createCodeStyle() const
{
Q_UNUSED(fallbacks);
return 0;
return new TextEditor::SimpleCodeStylePreferences();
}
QWidget *QmlJSCodeStylePreferencesFactory::createEditor(TextEditor::IFallbackPreferences *preferences,
TextEditor::TabPreferences *tabPreferences,
QWidget *QmlJSCodeStylePreferencesFactory::createEditor(TextEditor::ICodeStylePreferences *preferences,
QWidget *parent) const
{
Q_UNUSED(preferences)
Internal::QmlJSCodeStylePreferencesWidget *widget = new Internal::QmlJSCodeStylePreferencesWidget(parent);
widget->layout()->setMargin(0);
widget->setTabPreferences(tabPreferences);
widget->setPreferences(preferences);
return widget;
}
@@ -78,3 +94,18 @@ TextEditor::Indenter *QmlJSCodeStylePreferencesFactory::createIndenter() const
return new QmlJSEditor::Internal::Indenter();
}
TextEditor::ISnippetProvider *QmlJSCodeStylePreferencesFactory::snippetProvider() const
{
const QList<TextEditor::ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::instance()->getObjects<TextEditor::ISnippetProvider>();
foreach (TextEditor::ISnippetProvider *provider, providers)
if (provider->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID))
return provider;
return 0;
}
QString QmlJSCodeStylePreferencesFactory::previewText() const
{
return QLatin1String(defaultPreviewText);
}
@@ -30,8 +30,8 @@
**
**************************************************************************/
#ifndef QMLJSCODESTYLESETTINGSFACTORY_H
#define QMLJSCODESTYLESETTINGSFACTORY_H
#ifndef QMLJSCODESTYLEPREFERENCESFACTORY_H
#define QMLJSCODESTYLEPREFERENCESFACTORY_H
#include <texteditor/icodestylepreferencesfactory.h>
@@ -44,14 +44,14 @@ public:
virtual QString languageId();
virtual QString displayName();
virtual TextEditor::IFallbackPreferences *createPreferences(const QList<TextEditor::IFallbackPreferences *> &fallbacks) const;
virtual QWidget *createEditor(TextEditor::IFallbackPreferences *settings,
TextEditor::TabPreferences *tabSettings,
virtual TextEditor::ICodeStylePreferences *createCodeStyle() const;
virtual QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
QWidget *parent) const;
virtual TextEditor::Indenter *createIndenter() const;
virtual TextEditor::ISnippetProvider *snippetProvider() const;
QString previewText() const;
};
} // namespace QmlJSTools
#endif // QMLJSCODESTYLESETTINGSFACTORY_H
#endif // QMLJSCODESTYLEPREFERENCESFACTORY_H
@@ -40,9 +40,10 @@
#include <texteditor/snippets/isnippetprovider.h>
#include <texteditor/fontsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/displaysettings.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/codestyleeditor.h>
#include <extensionsystem/pluginmanager.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <qmljseditor/qmljseditorconstants.h>
@@ -59,7 +60,7 @@ namespace Internal {
QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(QWidget *parent) :
QWidget(parent),
m_tabPreferences(0),
m_preferences(0),
m_ui(new Ui::QmlJSCodeStyleSettingsPage)
{
m_ui->setupUi(this);
@@ -72,10 +73,11 @@ QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(QWidget *parent
break;
}
}
TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
setFontSettings(settings->fontSettings());
connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
this, SLOT(setFontSettings(TextEditor::FontSettings)));
TextEditor::TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
decorateEditor(textEditorSettings->fontSettings());
connect(textEditorSettings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
this, SLOT(decorateEditor(TextEditor::FontSettings)));
setVisualizeWhitespace(true);
@@ -87,12 +89,13 @@ QmlJSCodeStylePreferencesWidget::~QmlJSCodeStylePreferencesWidget()
delete m_ui;
}
void QmlJSCodeStylePreferencesWidget::setTabPreferences(TextEditor::TabPreferences *tabPreferences)
void QmlJSCodeStylePreferencesWidget::setPreferences(TextEditor::ICodeStylePreferences *preferences)
{
m_tabPreferences = tabPreferences;
m_ui->tabPreferencesWidget->setTabPreferences(tabPreferences);
connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
this, SLOT(slotSettingsChanged()));
m_preferences = preferences;
m_ui->tabPreferencesWidget->setPreferences(preferences);
if (m_preferences)
connect(m_preferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SLOT(slotSettingsChanged()));
updatePreview();
}
@@ -108,9 +111,21 @@ QString QmlJSCodeStylePreferencesWidget::searchKeywords() const
return rc;
}
void QmlJSCodeStylePreferencesWidget::setFontSettings(const TextEditor::FontSettings &fontSettings)
void QmlJSCodeStylePreferencesWidget::decorateEditor(const TextEditor::FontSettings &fontSettings)
{
m_ui->previewTextEdit->setFont(fontSettings.font());
const ISnippetProvider *provider = 0;
const QList<ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::instance()->getObjects<ISnippetProvider>();
foreach (const ISnippetProvider *current, providers) {
if (current->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID)) {
provider = current;
break;
}
}
m_ui->previewTextEdit->setFontSettings(fontSettings);
if (provider)
provider->decorateEditor(m_ui->previewTextEdit);
}
void QmlJSCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
@@ -129,9 +144,9 @@ void QmlJSCodeStylePreferencesWidget::updatePreview()
{
QTextDocument *doc = m_ui->previewTextEdit->document();
const TextEditor::TabSettings &ts = m_tabPreferences
? m_tabPreferences->currentSettings()
: TextEditorSettings::instance()->tabPreferences()->settings();
const TextEditor::TabSettings &ts = m_preferences
? m_preferences->currentTabSettings()
: TextEditorSettings::instance()->codeStyle()->tabSettings();
m_ui->previewTextEdit->setTabSettings(ts);
QtStyleCodeFormatter formatter(ts);
formatter.invalidateCache(doc);
@@ -140,9 +155,7 @@ void QmlJSCodeStylePreferencesWidget::updatePreview()
QTextCursor tc = m_ui->previewTextEdit->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
int depth = formatter.indentFor(block);
ts.indentLine(block, depth);
formatter.updateLineStateChange(block);
m_ui->previewTextEdit->indenter()->indentBlock(doc, block, QChar::Null, ts);
block = block.next();
}
@@ -189,22 +202,17 @@ QIcon QmlJSCodeStyleSettingsPage::categoryIcon() const
QWidget *QmlJSCodeStyleSettingsPage::createPage(QWidget *parent)
{
m_widget = new QmlJSCodeStylePreferencesWidget(parent);
TextEditor::SimpleCodeStylePreferences *originalTabPreferences
= QmlJSToolsSettings::instance()->qmlJSCodeStyle();
m_pageTabPreferences = new TextEditor::SimpleCodeStylePreferences(m_widget);
m_pageTabPreferences->setDelegatingPool(originalTabPreferences->delegatingPool());
m_pageTabPreferences->setTabSettings(originalTabPreferences->tabSettings());
m_pageTabPreferences->setCurrentDelegate(originalTabPreferences->currentDelegate());
m_pageTabPreferences->setId(originalTabPreferences->id());
TextEditorSettings *settings = TextEditorSettings::instance();
m_widget = new CodeStyleEditor(settings->codeStyleFactory(QmlJSTools::Constants::QML_JS_SETTINGS_ID),
m_pageTabPreferences, parent);
TextEditor::TabPreferences *originalTabPreferences
= QmlJSToolsSettings::instance()->tabPreferences();
QList<TextEditor::IFallbackPreferences *> originalTabFallbacks = originalTabPreferences->fallbacks();
m_pageTabPreferences = new TextEditor::TabPreferences(originalTabFallbacks, m_widget);
for (int i = 0; i < originalTabFallbacks.count(); i++) {
TextEditor::IFallbackPreferences *fallback = originalTabFallbacks.at(i);
m_pageTabPreferences->setFallbackEnabled(fallback, originalTabPreferences->isFallbackEnabled(fallback));
}
m_pageTabPreferences->setSettings(originalTabPreferences->settings());
m_pageTabPreferences->setCurrentFallback(originalTabPreferences->currentFallback());
m_widget->setTabPreferences(m_pageTabPreferences);
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
return m_widget;
}
@@ -213,14 +221,14 @@ void QmlJSCodeStyleSettingsPage::apply()
if (m_widget) {
QSettings *s = Core::ICore::instance()->settings();
TextEditor::TabPreferences *originalTabPreferences = QmlJSToolsSettings::instance()->tabPreferences();
if (originalTabPreferences->settings() != m_pageTabPreferences->settings()) {
originalTabPreferences->setSettings(m_pageTabPreferences->settings());
TextEditor::SimpleCodeStylePreferences *originalTabPreferences = QmlJSToolsSettings::instance()->qmlJSCodeStyle();
if (originalTabPreferences->tabSettings() != m_pageTabPreferences->tabSettings()) {
originalTabPreferences->setTabSettings(m_pageTabPreferences->tabSettings());
if (s)
originalTabPreferences->toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
}
if (originalTabPreferences->currentFallback() != m_pageTabPreferences->currentFallback()) {
originalTabPreferences->setCurrentFallback(m_pageTabPreferences->currentFallback());
if (originalTabPreferences->currentDelegate() != m_pageTabPreferences->currentDelegate()) {
originalTabPreferences->setCurrentDelegate(m_pageTabPreferences->currentDelegate());
if (s)
originalTabPreferences->toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
}
@@ -44,7 +44,8 @@ QT_END_NAMESPACE
namespace TextEditor {
class FontSettings;
class TabSettings;
class TabPreferences;
class CodeStyleEditor;
class ICodeStylePreferences;
}
namespace QmlJSTools {
@@ -62,19 +63,19 @@ public:
explicit QmlJSCodeStylePreferencesWidget(QWidget *parent = 0);
virtual ~QmlJSCodeStylePreferencesWidget();
void setTabPreferences(TextEditor::TabPreferences *tabPreferences);
void setPreferences(TextEditor::ICodeStylePreferences *preferences);
QString searchKeywords() const;
private slots:
void setFontSettings(const TextEditor::FontSettings &fontSettings);
void decorateEditor(const TextEditor::FontSettings &fontSettings);
void setVisualizeWhitespace(bool on);
void slotSettingsChanged();
void updatePreview();
private:
TextEditor::TabPreferences *m_tabPreferences;
TextEditor::ICodeStylePreferences *m_preferences;
Ui::QmlJSCodeStyleSettingsPage *m_ui;
};
@@ -101,8 +102,8 @@ public:
private:
QString m_searchKeywords;
TextEditor::TabPreferences *m_pageTabPreferences;
QPointer<QmlJSCodeStylePreferencesWidget> m_widget;
TextEditor::ICodeStylePreferences *m_pageTabPreferences;
QPointer<TextEditor::CodeStyleEditor> m_widget;
};
} // namespace Internal
@@ -6,16 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>342</width>
<height>304</height>
<width>138</width>
<height>112</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="TextEditor::TabPreferencesWidget" name="tabPreferencesWidget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="TextEditor::SimpleCodeStylePreferencesWidget" name="tabPreferencesWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -24,7 +24,7 @@
</property>
</widget>
</item>
<item>
<item row="0" column="1" rowspan="2">
<widget class="TextEditor::SnippetEditorWidget" name="previewTextEdit">
<property name="plainText">
<string notr="true">import QtQuick 1.0
@@ -47,20 +47,33 @@ Rectangle {
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>267</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TextEditor::SimpleCodeStylePreferencesWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/simplecodestylepreferenceswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TextEditor::SnippetEditorWidget</class>
<extends>QPlainTextEdit</extends>
<header location="global">texteditor/snippets/snippeteditor.h</header>
</customwidget>
<customwidget>
<class>TextEditor::TabPreferencesWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/tabpreferenceswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
+6
View File
@@ -81,3 +81,9 @@ void Indenter::indentBlock(QTextDocument *doc,
tabSettings.indentLine(block, depth);
}
void Indenter::invalidateCache(QTextDocument *doc)
{
QmlJSTools::QtStyleCodeFormatter codeFormatter;
codeFormatter.invalidateCache(doc);
}
+1
View File
@@ -51,6 +51,7 @@ public:
const QTextBlock &block,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings);
virtual void invalidateCache(QTextDocument *doc);
};
} // Internal
+2 -2
View File
@@ -9,7 +9,7 @@ HEADERS += \
$$PWD/qmljstoolsplugin.h \
$$PWD/qmljstoolsconstants.h \
$$PWD/qmljstoolssettings.h \
$$PWD/qmljscodestylesettingsfactory.h \
$$PWD/qmljscodestylepreferencesfactory.h \
$$PWD/qmljsmodelmanager.h \
$$PWD/qmljsqtstylecodeformatter.h \
$$PWD/qmljsrefactoringchanges.h \
@@ -23,7 +23,7 @@ HEADERS += \
SOURCES += \
$$PWD/qmljstoolsplugin.cpp \
$$PWD/qmljstoolssettings.cpp \
$$PWD/qmljscodestylesettingsfactory.cpp \
$$PWD/qmljscodestylepreferencesfactory.cpp \
$$PWD/qmljsmodelmanager.cpp \
$$PWD/qmljsqtstylecodeformatter.cpp \
$$PWD/qmljsrefactoringchanges.cpp \
@@ -37,11 +37,6 @@
#include "qmljscodestylesettingspage.h"
#include "qmljstoolsconstants.h"
#include "qmljstoolssettings.h"
#include "qmljscodestylesettingsfactory.h"
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/codestylepreferencesmanager.h>
#include <extensionsystem/pluginmanager.h>
@@ -102,9 +97,6 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
addAutoReleasedObject(new FunctionFilter(locatorData));
addAutoReleasedObject(new QmlJSCodeStyleSettingsPage);
TextEditor::CodeStylePreferencesManager::instance()->registerFactory(
new QmlJSTools::QmlJSCodeStylePreferencesFactory());
// Menus
Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
Core::ActionContainer *mqmljstools = am->createMenu(Constants::M_TOOLS_QMLJS);
@@ -126,10 +118,6 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
connect(core->progressManager(), SIGNAL(allTasksFinished(QString)),
this, SLOT(onAllTasksFinished(QString)));
TextEditor::TextEditorSettings *ts = TextEditor::TextEditorSettings::instance();
ts->registerMimeTypeForLanguageId(QLatin1String(Constants::QML_MIMETYPE), Constants::QML_JS_SETTINGS_ID);
ts->registerMimeTypeForLanguageId(QLatin1String(Constants::JS_MIMETYPE), Constants::QML_JS_SETTINGS_ID);
return true;
}
+56 -15
View File
@@ -32,17 +32,22 @@
#include "qmljstoolssettings.h"
#include "qmljstoolsconstants.h"
#include "qmljscodestylepreferencesfactory.h"
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabpreferences.h>
#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/tabsettings.h>
#include <texteditor/codestylepool.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
#include <QtCore/QSettings>
static const char *idKey = "QmlJSGlobal";
using namespace QmlJSTools;
using TextEditor::TabSettings;
namespace QmlJSTools {
namespace Internal {
@@ -50,7 +55,7 @@ namespace Internal {
class QmlJSToolsSettingsPrivate
{
public:
TextEditor::TabPreferences *m_tabPreferences;
TextEditor::SimpleCodeStylePreferences *m_globalCodeStyle;
};
} // namespace Internal
@@ -65,19 +70,55 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
QTC_ASSERT(!m_instance, return);
m_instance = this;
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
// code style factory
TextEditor::ICodeStylePreferencesFactory *factory = new QmlJSTools::QmlJSCodeStylePreferencesFactory();
textEditorSettings->registerCodeStyleFactory(factory);
// code style pool
TextEditor::CodeStylePool *pool = new TextEditor::CodeStylePool(factory, this);
textEditorSettings->registerCodeStylePool(Constants::QML_JS_SETTINGS_ID, pool);
// global code style settings
d->m_globalCodeStyle = new TextEditor::SimpleCodeStylePreferences(this);
d->m_globalCodeStyle->setDelegatingPool(pool);
d->m_globalCodeStyle->setDisplayName(tr("Global", "Settings"));
d->m_globalCodeStyle->setId(idKey);
pool->addCodeStyle(d->m_globalCodeStyle);
textEditorSettings->registerCodeStyle(QmlJSTools::Constants::QML_JS_SETTINGS_ID, d->m_globalCodeStyle);
// built-in settings
// Qt style
TextEditor::SimpleCodeStylePreferences *qtCodeStyle = new TextEditor::SimpleCodeStylePreferences();
qtCodeStyle->setId(QLatin1String("qt"));
qtCodeStyle->setDisplayName(tr("Qt"));
qtCodeStyle->setReadOnly(true);
TabSettings qtTabSettings;
qtTabSettings.m_tabPolicy = TabSettings::SpacesOnlyTabPolicy;
qtTabSettings.m_tabSize = 4;
qtTabSettings.m_indentSize = 4;
qtTabSettings.m_continuationAlignBehavior = TabSettings::ContinuationAlignWithIndent;
qtCodeStyle->setTabSettings(qtTabSettings);
pool->addCodeStyle(qtCodeStyle);
// default delegate for global preferences
d->m_globalCodeStyle->setCurrentDelegate(qtCodeStyle);
pool->loadCustomCodeStyles();
// load global settings (after built-in settings are added to the pool)
if (const QSettings *s = Core::ICore::instance()->settings()) {
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
TextEditor::TabPreferences *tabPrefs = textEditorSettings->tabPreferences();
d->m_tabPreferences
= new TextEditor::TabPreferences(QList<TextEditor::IFallbackPreferences *>()
<< tabPrefs, this);
d->m_tabPreferences->setCurrentFallback(tabPrefs);
d->m_tabPreferences->setFallbackEnabled(tabPrefs, false);
d->m_tabPreferences->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
d->m_tabPreferences->setDisplayName(tr("Global Qt Quick", "Settings"));
d->m_tabPreferences->setId(idKey);
textEditorSettings->registerLanguageTabPreferences(QmlJSTools::Constants::QML_JS_SETTINGS_ID, d->m_tabPreferences);
d->m_globalCodeStyle->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
}
// mimetypes to be handled
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::QML_MIMETYPE),
Constants::QML_JS_SETTINGS_ID);
textEditorSettings->registerMimeTypeForLanguageId(
QLatin1String(Constants::JS_MIMETYPE),
Constants::QML_JS_SETTINGS_ID);
}
QmlJSToolsSettings::~QmlJSToolsSettings()
@@ -92,9 +133,9 @@ QmlJSToolsSettings *QmlJSToolsSettings::instance()
return m_instance;
}
TextEditor::TabPreferences *QmlJSToolsSettings::tabPreferences() const
TextEditor::SimpleCodeStylePreferences *QmlJSToolsSettings::qmlJSCodeStyle() const
{
return d->m_tabPreferences;
return d->m_globalCodeStyle;
}
+2 -2
View File
@@ -39,7 +39,7 @@
namespace TextEditor
{
class TabPreferences;
class SimpleCodeStylePreferences;
}
namespace QmlJSTools
@@ -63,7 +63,7 @@ public:
static QmlJSToolsSettings *instance();
TextEditor::TabPreferences *tabPreferences() const;
TextEditor::SimpleCodeStylePreferences *qmlJSCodeStyle() const;
private:
Internal::QmlJSToolsSettingsPrivate *d;
@@ -48,13 +48,13 @@
#include <coreplugin/helpmanager.h>
#include <projectexplorer/buildstep.h>
#include <projectexplorer/environmentwidget.h>
#include <projectexplorer/persistentsettings.h>
#include <projectexplorer/toolchain.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/pathchooser.h>
#include <utils/detailswidget.h>
#include <utils/stringutils.h>
#include <utils/persistentsettings.h>
#include <utils/debuggerlanguagechooser.h>
#include <qtsupport/qtoutputformatter.h>
#include <qtsupport/baseqtversion.h>
@@ -73,8 +73,8 @@
using namespace Qt4ProjectManager::Internal;
using namespace Qt4ProjectManager;
using ProjectExplorer::LocalApplicationRunConfiguration;
using ProjectExplorer::PersistentSettingsReader;
using ProjectExplorer::PersistentSettingsWriter;
using Utils::PersistentSettingsReader;
using Utils::PersistentSettingsWriter;
namespace {
const char * const QT4_RC_ID("Qt4ProjectManager.Qt4RunConfiguration");
+1 -1
View File
@@ -44,8 +44,8 @@
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/toolchainmanager.h>
#include <projectexplorer/persistentsettings.h>
#include <utils/persistentsettings.h>
#include <utils/environment.h>
#include <utils/synchronousprocess.h>
+5 -4
View File
@@ -35,17 +35,18 @@
#include "qtversionfactory.h"
#include <projectexplorer/debugginghelper.h>
#include <projectexplorer/persistentsettings.h>
// only for legay restore
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/toolchainmanager.h>
#include <projectexplorer/gcctoolchain.h>
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/persistentsettings.h>
#include <utils/qtcprocess.h>
#include <utils/qtcassert.h>
#ifdef Q_OS_WIN
@@ -152,7 +153,7 @@ bool QtVersionManager::restoreQtVersions()
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
QList<QtVersionFactory *> factories = pm->getObjects<QtVersionFactory>();
ProjectExplorer::PersistentSettingsReader reader;
Utils::PersistentSettingsReader reader;
if (!reader.load(settingsFileName()))
return false;
QVariantMap data = reader.restoreValues();
@@ -202,7 +203,7 @@ void QtVersionManager::updateFromInstaller()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
QList<QtVersionFactory *> factories = pm->getObjects<QtVersionFactory>();
ProjectExplorer::PersistentSettingsReader reader;
Utils::PersistentSettingsReader reader;
if (!reader.load(Core::ICore::instance()->resourcePath()
+ QLatin1String("/Nokia") + QLatin1String(QTVERSION_FILENAME)))
return;
@@ -343,7 +344,7 @@ void QtVersionManager::updateFromInstaller()
void QtVersionManager::saveQtVersions()
{
ProjectExplorer::PersistentSettingsWriter writer;
Utils::PersistentSettingsWriter writer;
writer.saveValue(QLatin1String(QTVERSION_FILE_VERSION_KEY), 1);
int count = 0;
@@ -34,6 +34,7 @@
#include "basetextdocumentlayout.h"
#include "basetexteditor.h"
#include "typingsettings.h"
#include "storagesettings.h"
#include "tabsettings.h"
#include "extraencodingsettings.h"
@@ -188,6 +189,7 @@ public:
QString m_defaultPath;
QString m_suggestedFileName;
QString m_mimeType;
TypingSettings m_typingSettings;
StorageSettings m_storageSettings;
TabSettings m_tabSettings;
ExtraEncodingSettings m_extraEncodingSettings;
@@ -233,11 +235,21 @@ void BaseTextDocument::setMimeType(const QString &mt)
d->m_mimeType = mt;
}
void BaseTextDocument::setTypingSettings(const TypingSettings &typingSettings)
{
d->m_typingSettings = typingSettings;
}
void BaseTextDocument::setStorageSettings(const StorageSettings &storageSettings)
{
d->m_storageSettings = storageSettings;
}
const TypingSettings &BaseTextDocument::typingSettings() const
{
return d->m_typingSettings;
}
const StorageSettings &BaseTextDocument::storageSettings() const
{
return d->m_storageSettings;
@@ -45,6 +45,7 @@ QT_END_NAMESPACE
namespace TextEditor {
class ITextMarkable;
class TypingSettings;
class StorageSettings;
class TabSettings;
class ExtraEncodingSettings;
@@ -59,10 +60,12 @@ public:
BaseTextDocument();
virtual ~BaseTextDocument();
void setTypingSettings(const TypingSettings &typingSettings);
void setStorageSettings(const StorageSettings &storageSettings);
void setTabSettings(const TabSettings &tabSettings);
void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings);
const TypingSettings &typingSettings() const;
const StorageSettings &storageSettings() const;
const TabSettings &tabSettings() const;
const ExtraEncodingSettings &extraEncodingSettings() const;
+28 -42
View File
@@ -39,7 +39,8 @@
#include "codecselector.h"
#include "completionsettings.h"
#include "tabsettings.h"
#include "tabpreferences.h"
#include "typingsettings.h"
#include "icodestylepreferences.h"
#include "texteditorconstants.h"
#include "texteditorplugin.h"
#include "syntaxhighlighter.h"
@@ -1573,13 +1574,14 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
if (d->m_inBlockSelectionMode)
cursor.clearSelection();
const TabSettings &ts = d->m_document->tabSettings();
const TypingSettings &tps = d->m_document->typingSettings();
cursor.beginEditBlock();
int extraBlocks =
d->m_autoCompleter->paragraphSeparatorAboutToBeInserted(cursor, tabSettings());
QString previousIndentationString;
if (ts.m_autoIndent) {
if (tps.m_autoIndent) {
cursor.insertBlock();
indent(document(), cursor, QChar::Null);
} else {
@@ -1599,7 +1601,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
while (extraBlocks > 0) {
--extraBlocks;
ensureVisible.movePosition(QTextCursor::NextBlock);
if (ts.m_autoIndent)
if (tps.m_autoIndent)
indent(document(), ensureVisible, QChar::Null);
else if (!previousIndentationString.isEmpty())
ensureVisible.insertText(previousIndentationString);
@@ -1636,7 +1638,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
}
} else if (!ro
&& e == QKeySequence::DeleteStartOfWord
&& d->m_document->tabSettings().m_autoIndent
&& d->m_document->typingSettings().m_autoIndent
&& !textCursor().hasSelection()){
e->accept();
QTextCursor c = textCursor();
@@ -1685,7 +1687,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
}
QTextCursor cursor = textCursor();
int newPosition;
if (d->m_document->tabSettings().tabShouldIndent(document(), cursor, &newPosition)) {
if (d->m_document->typingSettings().tabShouldIndent(document(), cursor, &newPosition)) {
if (newPosition != cursor.position() && !cursor.hasSelection()) {
cursor.setPosition(newPosition);
setTextCursor(cursor);
@@ -1808,7 +1810,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
const QString &autoText = d->m_autoCompleter->autoComplete(cursor, text);
QChar electricChar;
if (d->m_document->tabSettings().m_autoIndent) {
if (d->m_document->typingSettings().m_autoIndent) {
foreach (QChar c, text) {
if (d->m_indenter->isElectricCharacter(c)) {
electricChar = c;
@@ -1836,7 +1838,7 @@ void BaseTextEditorWidget::keyPressEvent(QKeyEvent *e)
if (!electricChar.isNull() && d->m_autoCompleter->contextAllowsElectricCharacters(cursor))
indent(document(), cursor, electricChar);
if (!autoText.isEmpty()) {
if (d->m_document->tabSettings().m_autoIndent)
if (d->m_document->typingSettings().m_autoIndent)
reindent(document(), cursor);
cursor.setPosition(autoText.length() == 1 ? cursor.position() : cursor.anchor());
}
@@ -2369,7 +2371,6 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
m_formatRange(false),
m_parenthesesMatchingTimer(0),
m_extraArea(0),
m_tabPreferences(0),
m_codeStylePreferences(0),
extraAreaSelectionAnchorBlockNumber(-1),
extraAreaToggleMarkBlockNumber(-1),
@@ -4360,28 +4361,12 @@ QString BaseTextEditorWidget::languageSettingsId() const
return d->m_tabSettingsId;
}
void BaseTextEditorWidget::setTabPreferences(TabPreferences *tabPreferences)
{
if (d->m_tabPreferences) {
disconnect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings)));
disconnect(d->m_tabPreferences, SIGNAL(destroyed()),
this, SLOT(onTabPreferencesDestroyed()));
}
d->m_tabPreferences = tabPreferences;
if (d->m_tabPreferences) {
connect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(d->m_tabPreferences, SIGNAL(destroyed()),
this, SLOT(onTabPreferencesDestroyed()));
setTabSettings(d->m_tabPreferences->currentSettings());
}
}
void BaseTextEditorWidget::setCodeStylePreferences(IFallbackPreferences *preferences)
void BaseTextEditorWidget::setCodeStyle(ICodeStylePreferences *preferences)
{
indenter()->setCodeStylePreferences(preferences);
if (d->m_codeStylePreferences) {
disconnect(d->m_codeStylePreferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings)));
disconnect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
disconnect(d->m_codeStylePreferences, SIGNAL(destroyed()),
@@ -4389,30 +4374,24 @@ void BaseTextEditorWidget::setCodeStylePreferences(IFallbackPreferences *prefere
}
d->m_codeStylePreferences = preferences;
if (d->m_codeStylePreferences) {
connect(d->m_codeStylePreferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
connect(d->m_codeStylePreferences, SIGNAL(destroyed()),
this, SLOT(onCodeStylePreferencesDestroyed()));
setTabSettings(d->m_codeStylePreferences->currentTabSettings());
slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue());
}
}
void BaseTextEditorWidget::onTabPreferencesDestroyed()
{
if (sender() != d->m_tabPreferences)
return;
// avoid failing disconnects, m_tabPreferences has already been reduced to QObject
d->m_tabPreferences = 0;
setTabPreferences(TextEditorSettings::instance()->tabPreferences(languageSettingsId()));
}
void BaseTextEditorWidget::onCodeStylePreferencesDestroyed()
{
if (sender() != d->m_codeStylePreferences)
return;
// avoid failing disconnects, m_codeStylePreferences has already been reduced to QObject
d->m_codeStylePreferences = 0;
setCodeStylePreferences(TextEditorSettings::instance()->codeStylePreferences(languageSettingsId()));
setCodeStyle(TextEditorSettings::instance()->codeStyle(languageSettingsId()));
}
void BaseTextEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
@@ -4527,17 +4506,18 @@ void BaseTextEditorWidget::handleBackspaceKey()
}
const TextEditor::TabSettings &tabSettings = d->m_document->tabSettings();
const TextEditor::TypingSettings &typingSettings = d->m_document->typingSettings();
if (tabSettings.m_autoIndent && d->m_autoCompleter->autoBackspace(cursor))
if (typingSettings.m_autoIndent && d->m_autoCompleter->autoBackspace(cursor))
return;
bool handled = false;
if (tabSettings.m_smartBackspaceBehavior == TabSettings::BackspaceNeverIndents) {
if (typingSettings.m_smartBackspaceBehavior == TypingSettings::BackspaceNeverIndents) {
if (cursorWithinSnippet)
cursor.beginEditBlock();
cursor.deletePreviousChar();
handled = true;
} else if (tabSettings.m_smartBackspaceBehavior == TabSettings::BackspaceFollowsPreviousIndents) {
} else if (typingSettings.m_smartBackspaceBehavior == TypingSettings::BackspaceFollowsPreviousIndents) {
QTextBlock currentBlock = cursor.block();
int positionInBlock = pos - currentBlock.position();
const QString blockText = currentBlock.text();
@@ -4572,7 +4552,7 @@ void BaseTextEditorWidget::handleBackspaceKey()
}
}
}
} else if (tabSettings.m_smartBackspaceBehavior == TabSettings::BackspaceUnindents) {
} else if (typingSettings.m_smartBackspaceBehavior == TypingSettings::BackspaceUnindents) {
const QChar &c = characterAt(pos - 1);
if (!(c == QLatin1Char(' ') || c == QLatin1Char('\t'))) {
if (cursorWithinSnippet)
@@ -5532,6 +5512,11 @@ void BaseTextEditorWidget::setBehaviorSettings(const TextEditor::BehaviorSetting
d->m_behaviorSettings = bs;
}
void BaseTextEditorWidget::setTypingSettings(const TypingSettings &typingSettings)
{
d->m_document->setTypingSettings(typingSettings);
}
void BaseTextEditorWidget::setStorageSettings(const StorageSettings &storageSettings)
{
d->m_document->setStorageSettings(storageSettings);
@@ -5806,8 +5791,9 @@ void BaseTextEditorWidget::insertFromMimeData(const QMimeData *source)
}
const TabSettings &ts = d->m_document->tabSettings();
const TypingSettings &tps = d->m_document->typingSettings();
QTextCursor cursor = textCursor();
if (!ts.m_autoIndent) {
if (!tps.m_autoIndent) {
cursor.beginEditBlock();
cursor.insertText(text);
cursor.endEditBlock();
+4 -5
View File
@@ -53,13 +53,12 @@ namespace Utils {
namespace TextEditor {
class TabSettings;
class TabPreferences;
class RefactorOverlay;
struct RefactorMarker;
class IAssistMonitorInterface;
class IAssistInterface;
class IAssistProvider;
class IFallbackPreferences;
class ICodeStylePreferences;
namespace Internal {
class BaseTextEditorPrivate;
@@ -76,6 +75,7 @@ class FontSettings;
class BehaviorSettings;
class CompletionSettings;
class DisplaySettings;
class TypingSettings;
class StorageSettings;
class Indenter;
class AutoCompleter;
@@ -357,7 +357,6 @@ private slots:
bool inFindScope(const QTextCursor &cursor);
bool inFindScope(int selectionStart, int selectionEnd);
void inSnippetMode(bool *active);
void onTabPreferencesDestroyed();
void onCodeStylePreferencesDestroyed();
private:
@@ -378,8 +377,7 @@ public:
void setLanguageSettingsId(const QString &settingsId);
QString languageSettingsId() const;
void setTabPreferences(TabPreferences *preferences);
void setCodeStylePreferences(IFallbackPreferences *settings);
void setCodeStyle(ICodeStylePreferences *settings);
const DisplaySettings &displaySettings() const;
@@ -435,6 +433,7 @@ public slots:
virtual void setTabSettings(const TextEditor::TabSettings &);
virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
virtual void setTypingSettings(const TextEditor::TypingSettings &);
virtual void setStorageSettings(const TextEditor::StorageSettings &);
virtual void setCompletionSettings(const TextEditor::CompletionSettings &);
virtual void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &);
+1 -2
View File
@@ -206,8 +206,7 @@ public:
QWidget *m_extraArea;
QString m_tabSettingsId;
TabPreferences *m_tabPreferences;
IFallbackPreferences *m_codeStylePreferences;
ICodeStylePreferences *m_codeStylePreferences;
DisplaySettings m_displaySettings;
FontSettings m_fontSettings;
BehaviorSettings m_behaviorSettings;
+59 -26
View File
@@ -33,12 +33,14 @@
#include "behaviorsettingspage.h"
#include "behaviorsettings.h"
#include "typingsettings.h"
#include "storagesettings.h"
#include "tabsettings.h"
#include "extraencodingsettings.h"
#include "ui_behaviorsettingspage.h"
#include "tabpreferences.h"
#include "simplecodestylepreferences.h"
#include "texteditorconstants.h"
#include "codestylepool.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
@@ -58,8 +60,10 @@ struct BehaviorSettingsPage::BehaviorSettingsPagePrivate
void init();
TabPreferences *m_tabPreferences;
TabPreferences *m_pageTabPreferences;
CodeStylePool *m_defaultCodeStylePool;
SimpleCodeStylePreferences *m_codeStyle;
SimpleCodeStylePreferences *m_pageCodeStyle;
TypingSettings m_typingSettings;
StorageSettings m_storageSettings;
BehaviorSettings m_behaviorSettings;
ExtraEncodingSettings m_extraEncodingSettings;
@@ -69,14 +73,15 @@ struct BehaviorSettingsPage::BehaviorSettingsPagePrivate
BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate
(const BehaviorSettingsPageParameters &p)
: m_parameters(p), m_page(0), m_pageTabPreferences(0)
: m_parameters(p), m_page(0), m_pageCodeStyle(0)
{
}
void BehaviorSettingsPage::BehaviorSettingsPagePrivate::init()
{
if (const QSettings *s = Core::ICore::instance()->settings()) {
m_tabPreferences->fromSettings(m_parameters.settingsPrefix, s);
m_codeStyle->fromSettings(m_parameters.settingsPrefix, s);
m_typingSettings.fromSettings(m_parameters.settingsPrefix, s);
m_storageSettings.fromSettings(m_parameters.settingsPrefix, s);
m_behaviorSettings.fromSettings(m_parameters.settingsPrefix, s);
m_extraEncodingSettings.fromSettings(m_parameters.settingsPrefix, s);
@@ -88,9 +93,14 @@ BehaviorSettingsPage::BehaviorSettingsPage(const BehaviorSettingsPageParameters
: TextEditorOptionsPage(parent),
d(new BehaviorSettingsPagePrivate(p))
{
d->m_tabPreferences = new TabPreferences(QList<IFallbackPreferences *>(), this);
d->m_tabPreferences->setDisplayName(tr("Global", "Settings"));
d->m_tabPreferences->setId(Constants::GLOBAL_SETTINGS_ID);
// global tab preferences for all other languages
d->m_codeStyle = new SimpleCodeStylePreferences(this);
d->m_codeStyle->setDisplayName(tr("Global", "Settings"));
d->m_codeStyle->setId(Constants::GLOBAL_SETTINGS_ID);
// default pool for all other languages
d->m_defaultCodeStylePool = new CodeStylePool(0, this); // Any language
d->m_defaultCodeStylePool->addCodeStyle(d->m_codeStyle);
d->init();
}
@@ -114,10 +124,11 @@ QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
QWidget *w = new QWidget(parent);
d->m_page = new Ui::BehaviorSettingsPage;
d->m_page->setupUi(w);
d->m_pageTabPreferences = new TabPreferences(d->m_tabPreferences->fallbacks(), w);
d->m_pageTabPreferences->setSettings(d->m_tabPreferences->settings());
d->m_pageTabPreferences->setCurrentFallback(d->m_tabPreferences->currentFallback());
d->m_page->behaviorWidget->setTabPreferences(d->m_pageTabPreferences);
d->m_pageCodeStyle = new SimpleCodeStylePreferences(w);
d->m_pageCodeStyle->setDelegatingPool(d->m_codeStyle->delegatingPool());
d->m_pageCodeStyle->setTabSettings(d->m_codeStyle->tabSettings());
d->m_pageCodeStyle->setCurrentDelegate(d->m_codeStyle->currentDelegate());
d->m_page->behaviorWidget->setCodeStyle(d->m_pageCodeStyle);
settingsToUI();
@@ -132,25 +143,34 @@ void BehaviorSettingsPage::apply()
if (!d->m_page) // page was never shown
return;
TypingSettings newTypingSettings;
StorageSettings newStorageSettings;
BehaviorSettings newBehaviorSettings;
ExtraEncodingSettings newExtraEncodingSettings;
settingsFromUI(&newStorageSettings, &newBehaviorSettings,
&newExtraEncodingSettings);
settingsFromUI(&newTypingSettings, &newStorageSettings,
&newBehaviorSettings, &newExtraEncodingSettings);
QSettings *s = Core::ICore::instance()->settings();
if (d->m_tabPreferences->settings() != d->m_pageTabPreferences->settings()) {
d->m_tabPreferences->setSettings(d->m_pageTabPreferences->settings());
if (d->m_codeStyle->tabSettings() != d->m_pageCodeStyle->tabSettings()) {
d->m_codeStyle->setTabSettings(d->m_pageCodeStyle->tabSettings());
if (s)
d->m_tabPreferences->toSettings(d->m_parameters.settingsPrefix, s);
d->m_codeStyle->toSettings(d->m_parameters.settingsPrefix, s);
}
if (d->m_tabPreferences->currentFallback() != d->m_pageTabPreferences->currentFallback()) {
d->m_tabPreferences->setCurrentFallback(d->m_pageTabPreferences->currentFallback());
if (d->m_codeStyle->currentDelegate() != d->m_pageCodeStyle->currentDelegate()) {
d->m_codeStyle->setCurrentDelegate(d->m_pageCodeStyle->currentDelegate());
if (s)
d->m_tabPreferences->toSettings(d->m_parameters.settingsPrefix, s);
d->m_codeStyle->toSettings(d->m_parameters.settingsPrefix, s);
}
if (newTypingSettings != d->m_typingSettings) {
d->m_typingSettings = newTypingSettings;
if (s)
d->m_typingSettings.toSettings(d->m_parameters.settingsPrefix, s);
emit typingSettingsChanged(newTypingSettings);
}
if (newStorageSettings != d->m_storageSettings) {
@@ -183,10 +203,12 @@ void BehaviorSettingsPage::apply()
}
}
void BehaviorSettingsPage::settingsFromUI(StorageSettings *storageSettings,
void BehaviorSettingsPage::settingsFromUI(TypingSettings *typingSettings,
StorageSettings *storageSettings,
BehaviorSettings *behaviorSettings,
ExtraEncodingSettings *extraEncodingSettings) const
{
d->m_page->behaviorWidget->assignedTypingSettings(typingSettings);
d->m_page->behaviorWidget->assignedStorageSettings(storageSettings);
d->m_page->behaviorWidget->assignedBehaviorSettings(behaviorSettings);
d->m_page->behaviorWidget->assignedExtraEncodingSettings(extraEncodingSettings);
@@ -194,6 +216,7 @@ void BehaviorSettingsPage::settingsFromUI(StorageSettings *storageSettings,
void BehaviorSettingsPage::settingsToUI()
{
d->m_page->behaviorWidget->setAssignedTypingSettings(d->m_typingSettings);
d->m_page->behaviorWidget->setAssignedStorageSettings(d->m_storageSettings);
d->m_page->behaviorWidget->setAssignedBehaviorSettings(d->m_behaviorSettings);
d->m_page->behaviorWidget->setAssignedExtraEncodingSettings(d->m_extraEncodingSettings);
@@ -209,6 +232,21 @@ void BehaviorSettingsPage::finish()
d->m_page = 0;
}
ICodeStylePreferences *BehaviorSettingsPage::codeStyle() const
{
return d->m_codeStyle;
}
CodeStylePool *BehaviorSettingsPage::codeStylePool() const
{
return d->m_defaultCodeStylePool;
}
const TypingSettings &BehaviorSettingsPage::typingSettings() const
{
return d->m_typingSettings;
}
const StorageSettings &BehaviorSettingsPage::storageSettings() const
{
return d->m_storageSettings;
@@ -224,11 +262,6 @@ const ExtraEncodingSettings &BehaviorSettingsPage::extraEncodingSettings() const
return d->m_extraEncodingSettings;
}
TabPreferences *BehaviorSettingsPage::tabPreferences() const
{
return d->m_tabPreferences;
}
bool BehaviorSettingsPage::matches(const QString &s) const
{
return d->m_searchKeywords.contains(s, Qt::CaseInsensitive);
@@ -40,11 +40,12 @@
namespace TextEditor {
class TabSettings;
class TypingSettings;
class StorageSettings;
class BehaviorSettings;
class ExtraEncodingSettings;
class TabPreferences;
class ICodeStylePreferences;
class CodeStylePool;
class BehaviorSettingsPageParameters
{
@@ -71,19 +72,22 @@ public:
void finish();
bool matches(const QString &s) const;
ICodeStylePreferences *codeStyle() const;
CodeStylePool *codeStylePool() const;
const TypingSettings &typingSettings() const;
const StorageSettings &storageSettings() const;
const BehaviorSettings &behaviorSettings() const;
const ExtraEncodingSettings &extraEncodingSettings() const;
TabPreferences *tabPreferences() const;
signals:
void typingSettingsChanged(const TextEditor::TypingSettings &);
void storageSettingsChanged(const TextEditor::StorageSettings &);
void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
private:
void settingsFromUI(StorageSettings *storageSettings,
void settingsFromUI(TypingSettings *typingSettings,
StorageSettings *storageSettings,
BehaviorSettings *behaviorSettings,
ExtraEncodingSettings *extraEncodingSettings) const;
void settingsToUI();
@@ -34,6 +34,7 @@
#include "ui_behaviorsettingswidget.h"
#include <texteditor/tabsettings.h>
#include <texteditor/typingsettings.h>
#include <texteditor/storagesettings.h>
#include <texteditor/behaviorsettings.h>
#include <texteditor/extraencodingsettings.h>
@@ -78,6 +79,12 @@ BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent)
d->m_codecs.append(codec);
}
connect(d->m_ui.autoIndent, SIGNAL(toggled(bool)),
this, SLOT(slotTypingSettingsChanged()));
connect(d->m_ui.smartBackspaceBehavior, SIGNAL(currentIndexChanged(int)),
this, SLOT(slotTypingSettingsChanged()));
connect(d->m_ui.tabKeyBehavior, SIGNAL(currentIndexChanged(int)),
this, SLOT(slotTypingSettingsChanged()));
connect(d->m_ui.cleanWhitespace, SIGNAL(clicked(bool)),
this, SLOT(slotStorageSettingsChanged()));
connect(d->m_ui.inEntireDocument, SIGNAL(clicked(bool)),
@@ -106,6 +113,7 @@ BehaviorSettingsWidget::~BehaviorSettingsWidget()
void BehaviorSettingsWidget::setActive(bool active)
{
d->m_ui.tabPreferencesWidget->setEnabled(active);
d->m_ui.groupBoxTyping->setEnabled(active);
d->m_ui.groupBoxEncodings->setEnabled(active);
d->m_ui.groupBoxMouse->setEnabled(active);
d->m_ui.groupBoxStorageSettings->setEnabled(active);
@@ -126,9 +134,25 @@ QTextCodec *BehaviorSettingsWidget::assignedCodec() const
return d->m_codecs.at(d->m_ui.encodingBox->currentIndex());
}
void BehaviorSettingsWidget::setTabPreferences(TabPreferences *tabPreferences)
void BehaviorSettingsWidget::setCodeStyle(ICodeStylePreferences *preferences)
{
d->m_ui.tabPreferencesWidget->setTabPreferences(tabPreferences);
d->m_ui.tabPreferencesWidget->setPreferences(preferences);
}
void BehaviorSettingsWidget::setAssignedTypingSettings(const TypingSettings &typingSettings)
{
d->m_ui.autoIndent->setChecked(typingSettings.m_autoIndent);
d->m_ui.smartBackspaceBehavior->setCurrentIndex(typingSettings.m_smartBackspaceBehavior);
d->m_ui.tabKeyBehavior->setCurrentIndex(typingSettings.m_tabKeyBehavior);
}
void BehaviorSettingsWidget::assignedTypingSettings(TypingSettings *typingSettings) const
{
typingSettings->m_autoIndent = d->m_ui.autoIndent->isChecked();
typingSettings->m_smartBackspaceBehavior =
(TypingSettings::SmartBackspaceBehavior)(d->m_ui.smartBackspaceBehavior->currentIndex());
typingSettings->m_tabKeyBehavior =
(TypingSettings::TabKeyBehavior)(d->m_ui.tabKeyBehavior->currentIndex());
}
void BehaviorSettingsWidget::setAssignedStorageSettings(const StorageSettings &storageSettings)
@@ -180,6 +204,9 @@ QString BehaviorSettingsWidget::collectUiKeywords() const
QString keywords;
QTextStream(&keywords)
<< sep << d->m_ui.tabPreferencesWidget->searchKeywords()
<< sep << d->m_ui.autoIndent->text()
<< sep << d->m_ui.smartBackspaceLabel->text()
<< sep << d->m_ui.tabKeyBehaviorLabel->text()
<< sep << d->m_ui.cleanWhitespace->text()
<< sep << d->m_ui.inEntireDocument->text()
<< sep << d->m_ui.cleanIndentation->text()
@@ -196,9 +223,11 @@ QString BehaviorSettingsWidget::collectUiKeywords() const
return keywords;
}
void BehaviorSettingsWidget::setFallbacksVisible(bool on)
void BehaviorSettingsWidget::slotTypingSettingsChanged()
{
d->m_ui.tabPreferencesWidget->setFallbacksVisible(on);
TypingSettings settings;
assignedTypingSettings(&settings);
emit typingSettingsChanged(settings);
}
void BehaviorSettingsWidget::slotStorageSettingsChanged()
@@ -43,7 +43,8 @@ QT_END_NAMESPACE
namespace TextEditor {
class TabPreferences;
class ICodeStylePreferences;
class TypingSettings;
class StorageSettings;
class BehaviorSettings;
class ExtraEncodingSettings;
@@ -63,7 +64,10 @@ public:
void setAssignedCodec(QTextCodec *codec);
QTextCodec *assignedCodec() const;
void setTabPreferences(TabPreferences *tabPreferences);
void setCodeStyle(ICodeStylePreferences *preferences);
void setAssignedTypingSettings(const TypingSettings &typingSettings);
void assignedTypingSettings(TypingSettings *typingSettings) const;
void setAssignedStorageSettings(const StorageSettings &storageSettings);
void assignedStorageSettings(StorageSettings *storageSettings) const;
@@ -76,15 +80,15 @@ public:
QString collectUiKeywords() const;
void setFallbacksVisible(bool on);
signals:
void typingSettingsChanged(const TextEditor::TypingSettings &settings);
void storageSettingsChanged(const TextEditor::StorageSettings &settings);
void behaviorSettingsChanged(const TextEditor::BehaviorSettings &settings);
void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &settings);
void textCodecChanged(QTextCodec *codec);
private slots:
void slotTypingSettingsChanged();
void slotStorageSettingsChanged();
void slotBehaviorSettingsChanged();
void slotExtraEncodingChanged();
+333 -214
View File
@@ -6,244 +6,363 @@
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<height>410</height>
<width>802</width>
<height>441</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0" rowspan="3">
<widget class="TextEditor::TabPreferencesWidget" name="tabPreferencesWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="TextEditor::SimpleCodeStylePreferencesWidget" name="tabPreferencesWidget" native="true"/>
</item>
<item>
<widget class="QGroupBox" name="groupBoxTyping">
<property name="title">
<string>Typing</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="autoIndent">
<property name="text">
<string>Enable automatic &amp;indentation</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="smartBackspaceLabel">
<property name="text">
<string>Backspace indentation:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="smartBackspaceBehavior">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
Specifies how backspace interacts with indentation.
&lt;ul&gt;
&lt;li&gt;None: No interaction at all. Regular plain backspace behavior.
&lt;/li&gt;
&lt;li&gt;Follows Previous Indents: In leading white space it will take the cursor back to the nearest indentation level used in previous lines.
&lt;/li&gt;
&lt;li&gt;Unindents: If the character behind the cursor is a space it behaves as a backtab.
&lt;/li&gt;
&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;
</string>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Follows Previous Indents</string>
</property>
</item>
<item>
<property name="text">
<string>Unindents</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="tabKeyBehaviorLabel">
<property name="text">
<string>Tab key performs auto-indent:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="tabKeyBehavior">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<item>
<property name="text">
<string>Always</string>
</property>
</item>
<item>
<property name="text">
<string>In Leading White Space</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBoxStorageSettings">
<property name="toolTip">
<string>Cleanup actions which are automatically performed right before the file is saved to disk.</string>
</property>
<property name="title">
<string>Cleanups Upon Saving</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="cleanWhitespace">
<property name="toolTip">
<string>Removes trailing whitespace upon saving.</string>
</property>
<property name="text">
<string>&amp;Clean whitespace</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="inEntireDocument">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Clean whitespace in entire document instead of only for changed parts.</string>
</property>
<property name="text">
<string>In entire &amp;document</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="cleanIndentation">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Correct leading whitespace according to tab settings.</string>
</property>
<property name="text">
<string>Clean indentation</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="addFinalNewLine">
<property name="text">
<string>&amp;Ensure newline at end of file</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBoxEncodings">
<property name="title">
<string>File Encodings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="encodingLabel">
<property name="text">
<string>Default encoding: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="encodingBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
<property name="minimumContentsLength">
<number>20</number>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>285</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="utf8BomLabel">
<property name="text">
<string>UTF-8 BOM:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="utf8BomBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBoxStorageSettings">
<property name="toolTip">
<string>Cleanup actions which are automatically performed right before the file is saved to disk.</string>
</property>
<property name="title">
<string>Cleanups Upon Saving</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="cleanWhitespace">
<property name="toolTip">
<string>Removes trailing whitespace upon saving.</string>
</property>
<property name="text">
<string>&amp;Clean whitespace</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="inEntireDocument">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Clean whitespace in entire document instead of only for changed parts.</string>
</property>
<property name="text">
<string>In entire &amp;document</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="cleanIndentation">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Correct leading whitespace according to tab settings.</string>
</property>
<property name="text">
<string>Clean indentation</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="addFinalNewLine">
<property name="text">
<string>&amp;Ensure newline at end of file</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxEncodings">
<property name="title">
<string>File Encodings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="encodingLabel">
<property name="text">
<string>Default encoding: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="encodingBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
<property name="minimumContentsLength">
<number>20</number>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>285</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="utf8BomLabel">
<property name="text">
<string>UTF-8 BOM:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="utf8BomBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
&lt;p&gt;How text editors should deal with UTF-8 Byte Order Marks. The options are:&lt;/p&gt;
&lt;ul &gt;&lt;li&gt;&lt;i&gt;Add If Encoding Is UTF-8:&lt;/i&gt; always add a BOM when saving a file in UTF-8 encoding. Note that this will not work if the encoding is &lt;i&gt;System&lt;/i&gt;, as Qt Creator does not know what it actually is.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Keep If Already Present: &lt;/i&gt;save the file with a BOM if it already had one when it was loaded.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Always Delete:&lt;/i&gt; never write an UTF-8 BOM, possibly deleting a pre-existing one.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Note that UTF-8 BOMs are uncommon and treated incorrectly by some editors, so it usually makes little sense to add any.&lt;/p&gt;
&lt;p&gt;This setting does &lt;b&gt;not&lt;/b&gt; influence the use of UTF-16 and UTF-32 BOMs.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</property>
<item>
<property name="text">
<string>Add If Encoding Is UTF-8</string>
</property>
</item>
<item>
<property name="text">
<string>Keep If Already Present</string>
</property>
</item>
<item>
<property name="text">
<string>Always Delete</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxMouse">
<property name="title">
<string>Mouse</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<property name="text">
<string>Add If Encoding Is UTF-8</string>
</property>
<widget class="QCheckBox" name="mouseNavigation">
<property name="text">
<string>Enable &amp;mouse navigation</string>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Keep If Already Present</string>
</property>
<widget class="QCheckBox" name="scrollWheelZooming">
<property name="text">
<string>Enable scroll &amp;wheel zooming</string>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Always Delete</string>
</property>
<widget class="QCheckBox" name="constrainTooltips">
<property name="text">
<string>Enable &amp;tooltips only when Shift key is down</string>
</property>
</widget>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="1">
<widget class="QGroupBox" name="groupBoxMouse">
<property name="title">
<string>Mouse</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="mouseNavigation">
<property name="text">
<string>Enable &amp;mouse navigation</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="scrollWheelZooming">
<property name="text">
<string>Enable scroll &amp;wheel zooming</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="constrainTooltips">
<property name="text">
<string>Enable &amp;tooltips only when Shift key is down</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<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>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>3</height>
</size>
</property>
</spacer>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TextEditor::TabPreferencesWidget</class>
<class>TextEditor::SimpleCodeStylePreferencesWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/tabpreferenceswidget.h</header>
<header location="global">texteditor/simplecodestylepreferenceswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
+101
View File
@@ -0,0 +1,101 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "codestyleeditor.h"
#include "icodestylepreferencesfactory.h"
#include "icodestylepreferences.h"
#include "codestyleselectorwidget.h"
#include "texteditorsettings.h"
#include "displaysettings.h"
#include "tabsettings.h"
#include "indenter.h"
#include "snippets/snippeteditor.h"
#include "snippets/isnippetprovider.h"
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextBlock>
using namespace TextEditor;
CodeStyleEditor::CodeStyleEditor(ICodeStylePreferencesFactory *factory,
ICodeStylePreferences *codeStyle, QWidget *parent)
: QWidget(parent),
m_factory(factory),
m_codeStyle(codeStyle)
{
m_layout = new QVBoxLayout(this);
CodeStyleSelectorWidget *selector = new CodeStyleSelectorWidget(factory, this);
selector->setCodeStyle(codeStyle);
m_preview = new SnippetEditorWidget(this);
TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
m_preview->setFontSettings(settings->fontSettings());
DisplaySettings displaySettings = m_preview->displaySettings();
displaySettings.m_visualizeWhitespace = true;
m_preview->setDisplaySettings(displaySettings);
ISnippetProvider *provider = factory->snippetProvider();
if (provider)
provider->decorateEditor(m_preview);
m_layout->addWidget(selector);
m_layout->addWidget(m_preview);
connect(codeStyle, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SLOT(updatePreview()));
connect(codeStyle, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(updatePreview()));
connect(codeStyle, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)),
this, SLOT(updatePreview()));
m_preview->setCodeStyle(m_codeStyle);
m_preview->setPlainText(factory->previewText());
updatePreview();
}
void CodeStyleEditor::clearMargins()
{
m_layout->setContentsMargins(QMargins());
}
void CodeStyleEditor::updatePreview()
{
QTextDocument *doc = m_preview->document();
m_preview->indenter()->invalidateCache(doc);
QTextBlock block = doc->firstBlock();
QTextCursor tc = m_preview->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
m_preview->indenter()->indentBlock(doc, block, QChar::Null, m_codeStyle->currentTabSettings());
block = block.next();
}
tc.endEditBlock();
}
@@ -30,38 +30,42 @@
**
**************************************************************************/
#ifndef CODESTYLEPREFERENCESMANAGER_H
#define CODESTYLEPREFERENCESMANAGER_H
#ifndef CODESTYLEEDITOR_H
#define CODESTYLEEDITOR_H
#include "texteditor_global.h"
#include <QtCore/QObject>
#include <QWidget>
QT_BEGIN_NAMESPACE
class QVBoxLayout;
QT_END_NAMESPACE
namespace TextEditor {
namespace Internal {
class CodeStylePreferencesManagerPrivate;
}
class ICodeStylePreferencesFactory;
class ICodeStylePreferences;
class SnippetEditorWidget;
class TEXTEDITOR_EXPORT CodeStylePreferencesManager : public QObject
class TEXTEDITOR_EXPORT CodeStyleEditor : public QWidget
{
Q_OBJECT
public:
static CodeStylePreferencesManager *instance();
CodeStyleEditor(ICodeStylePreferencesFactory *factory,
ICodeStylePreferences *codeStyle, QWidget *parent = 0);
void registerFactory(ICodeStylePreferencesFactory *settings);
QList<ICodeStylePreferencesFactory *> factories() const;
ICodeStylePreferencesFactory *factory(const QString &languageId) const;
void clearMargins();
private slots:
void updatePreview();
private:
CodeStylePreferencesManager();
~CodeStylePreferencesManager();
Internal::CodeStylePreferencesManagerPrivate *d;
static CodeStylePreferencesManager *m_instance;
QVBoxLayout *m_layout;
ICodeStylePreferencesFactory *m_factory;
ICodeStylePreferences *m_codeStyle;
SnippetEditorWidget *m_preview;
};
} // namespace TextEditor
#endif // CODESTYLEPREFERENCESMANAGER_H
#endif // CODESTYLEEDITOR_H
+289
View File
@@ -0,0 +1,289 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "codestylepool.h"
#include "icodestylepreferencesfactory.h"
#include "icodestylepreferences.h"
#include "tabsettings.h"
#include <utils/persistentsettings.h>
#include <coreplugin/icore.h>
#include <QtCore/QMap>
#include <QtCore/QDir>
#include <QtCore/QDebug>
using namespace TextEditor;
static const char *codeStyleDataKey = "CodeStyleData";
static const char *displayNameKey = "DisplayName";
static const char *codeStyleDocKey = "QtCreatorCodeStyle";
namespace TextEditor {
namespace Internal {
class CodeStylePoolPrivate
{
public:
CodeStylePoolPrivate()
: m_factory(0)
{}
QString generateUniqueId(const QString &id) const;
ICodeStylePreferencesFactory *m_factory;
QList<ICodeStylePreferences *> m_pool;
QList<ICodeStylePreferences *> m_builtInPool;
QList<ICodeStylePreferences *> m_customPool;
QMap<QString, ICodeStylePreferences *> m_idToCodeStyle;
QString m_settingsPath;
};
QString CodeStylePoolPrivate::generateUniqueId(const QString &id) const
{
if (!m_idToCodeStyle.contains(id))
return id;
int idx = id.size();
while (idx > 0) {
if (!id.at(idx - 1).isDigit())
break;
idx--;
}
const QString baseName = id.left(idx);
QString newName = baseName;
int i = 2;
while (m_idToCodeStyle.contains(newName))
newName = baseName + QString::number(i++);
return newName;
}
}
}
static QString customCodeStylesPath()
{
QString path = Core::ICore::instance()->userResourcePath();
path.append(QLatin1String("/codestyles/"));
return path;
}
CodeStylePool::CodeStylePool(ICodeStylePreferencesFactory *factory, QObject *parent)
: QObject(parent),
d(new Internal::CodeStylePoolPrivate)
{
d->m_factory = factory;
}
CodeStylePool::~CodeStylePool()
{
delete d;
}
QString CodeStylePool::settingsDir() const
{
const QString suffix = d->m_factory ? d->m_factory->languageId() : QLatin1String("default");
return customCodeStylesPath().append(suffix);
}
QString CodeStylePool::settingsPath(const QString &id) const
{
return settingsDir() + QLatin1Char('/') + id + QLatin1String(".xml");
}
QList<ICodeStylePreferences *> CodeStylePool::codeStyles() const
{
return d->m_pool;
}
QList<ICodeStylePreferences *> CodeStylePool::builtInCodeStyles() const
{
return d->m_builtInPool;
}
QList<ICodeStylePreferences *> CodeStylePool::customCodeStyles() const
{
return d->m_customPool;
}
ICodeStylePreferences *CodeStylePool::cloneCodeStyle(ICodeStylePreferences *originalCodeStyle)
{
return createCodeStyle(originalCodeStyle->id(), originalCodeStyle->tabSettings(),
originalCodeStyle->value(), originalCodeStyle->displayName());
}
ICodeStylePreferences *CodeStylePool::createCodeStyle(const QString &id, const TabSettings &tabSettings,
const QVariant &codeStyleData, const QString &displayName)
{
if (!d->m_factory)
return 0;
TextEditor::ICodeStylePreferences *codeStyle = d->m_factory->createCodeStyle();
codeStyle->setId(id);
codeStyle->setTabSettings(tabSettings);
codeStyle->setValue(codeStyleData);
codeStyle->setDisplayName(displayName);
addCodeStyle(codeStyle);
saveCodeStyle(codeStyle);
return codeStyle;
}
void CodeStylePool::addCodeStyle(ICodeStylePreferences *codeStyle)
{
const QString newId = d->generateUniqueId(codeStyle->id());
codeStyle->setId(newId);
d->m_pool.append(codeStyle);
if (codeStyle->isReadOnly())
d->m_builtInPool.append(codeStyle);
else
d->m_customPool.append(codeStyle);
d->m_idToCodeStyle.insert(newId, codeStyle);
// take ownership
codeStyle->setParent(this);
connect(codeStyle, SIGNAL(valueChanged(QVariant)), this, SLOT(slotSaveCodeStyle()));
connect(codeStyle, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), this, SLOT(slotSaveCodeStyle()));
connect(codeStyle, SIGNAL(displayNameChanged(QString)), this, SLOT(slotSaveCodeStyle()));
emit codeStyleAdded(codeStyle);
}
void CodeStylePool::removeCodeStyle(ICodeStylePreferences *codeStyle)
{
const int idx = d->m_customPool.indexOf(codeStyle);
if (idx < 0)
return;
if (codeStyle->isReadOnly())
return;
emit codeStyleRemoved(codeStyle);
d->m_customPool.removeAt(idx);
d->m_pool.removeOne(codeStyle);
d->m_idToCodeStyle.remove(codeStyle->id());
QDir dir(settingsDir());
dir.remove(QFileInfo(settingsPath(codeStyle->id())).fileName());
delete codeStyle;
}
ICodeStylePreferences *CodeStylePool::codeStyle(const QString &id) const
{
return d->m_idToCodeStyle.value(id);
}
void CodeStylePool::loadCustomCodeStyles()
{
QDir dir(settingsDir());
const QStringList codeStyleFiles = dir.entryList(QStringList() << QLatin1String("*.xml"), QDir::Files);
for (int i = 0; i < codeStyleFiles.count(); i++) {
const QString codeStyleFile = codeStyleFiles.at(i);
// filter out styles which id is the same as one of built-in styles
if (!d->m_idToCodeStyle.contains(QFileInfo(codeStyleFile).completeBaseName()))
loadCodeStyle(dir.absoluteFilePath(codeStyleFile));
}
}
ICodeStylePreferences *CodeStylePool::importCodeStyle(const QString &fileName)
{
TextEditor::ICodeStylePreferences *codeStyle = loadCodeStyle(fileName);
if (codeStyle)
saveCodeStyle(codeStyle);
return codeStyle;
}
ICodeStylePreferences *CodeStylePool::loadCodeStyle(const QString &fileName)
{
TextEditor::ICodeStylePreferences *codeStyle = 0;
Utils::PersistentSettingsReader reader;
reader.load(fileName);
QVariantMap m = reader.restoreValues();
if (m.contains(QLatin1String(codeStyleDataKey))) {
const QString id = QFileInfo(fileName).completeBaseName();
const QString displayName = reader.restoreValue(QLatin1String(displayNameKey)).toString();
const QVariantMap map = reader.restoreValue(QLatin1String(codeStyleDataKey)).toMap();
if (d->m_factory) {
codeStyle = d->m_factory->createCodeStyle();
codeStyle->setId(id);
codeStyle->setDisplayName(displayName);
codeStyle->fromMap(QString::null, map);
addCodeStyle(codeStyle);
}
}
return codeStyle;
}
void CodeStylePool::slotSaveCodeStyle()
{
ICodeStylePreferences *codeStyle = qobject_cast<ICodeStylePreferences *>(sender());
if (!codeStyle)
return;
saveCodeStyle(codeStyle);
}
void CodeStylePool::saveCodeStyle(ICodeStylePreferences *codeStyle) const
{
const QString codeStylesPath = customCodeStylesPath();
// Create the base directory when it doesn't exist
if (!QFile::exists(codeStylesPath) && !QDir().mkpath(codeStylesPath)) {
qWarning() << "Failed to create code style directory:" << codeStylesPath;
return;
}
const QString languageCodeStylesPath = settingsDir();
// Create the base directory for the language when it doesn't exist
if (!QFile::exists(languageCodeStylesPath) && !QDir().mkpath(languageCodeStylesPath)) {
qWarning() << "Failed to create language code style directory:" << languageCodeStylesPath;
return;
}
exportCodeStyle(settingsPath(codeStyle->id()), codeStyle);
}
void CodeStylePool::exportCodeStyle(const QString &fileName, ICodeStylePreferences *codeStyle) const
{
QVariantMap map;
codeStyle->toMap(QString::null, &map);
Utils::PersistentSettingsWriter writer;
writer.saveValue(QLatin1String(displayNameKey), codeStyle->displayName());
writer.saveValue(QLatin1String(codeStyleDataKey), map);
writer.save(fileName, QLatin1String(codeStyleDocKey), 0);
}
+95
View File
@@ -0,0 +1,95 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef CODESTYLEPOOL_H
#define CODESTYLEPOOL_H
#include "texteditor_global.h"
#include <QObject>
namespace TextEditor {
class ICodeStylePreferences;
class ICodeStylePreferencesFactory;
class TabSettings;
namespace Internal {
class CodeStylePoolPrivate;
}
class TEXTEDITOR_EXPORT CodeStylePool : public QObject
{
Q_OBJECT
public:
explicit CodeStylePool(ICodeStylePreferencesFactory *factory, QObject *parent = 0);
virtual ~CodeStylePool();
QList<ICodeStylePreferences *> codeStyles() const;
QList<ICodeStylePreferences *> builtInCodeStyles() const;
QList<ICodeStylePreferences *> customCodeStyles() const;
ICodeStylePreferences *cloneCodeStyle(ICodeStylePreferences *originalCodeStyle);
ICodeStylePreferences *createCodeStyle(const QString &id, const TabSettings &tabSettings,
const QVariant &codeStyleData, const QString &displayName);
// ownership is passed to the pool
void addCodeStyle(ICodeStylePreferences *codeStyle);
// is removed and deleted
void removeCodeStyle(ICodeStylePreferences *codeStyle);
ICodeStylePreferences *codeStyle(const QString &id) const;
void loadCustomCodeStyles();
ICodeStylePreferences *importCodeStyle(const QString &fileName);
void exportCodeStyle(const QString &fileName, ICodeStylePreferences *codeStyle) const;
signals:
void codeStyleAdded(ICodeStylePreferences *);
void codeStyleRemoved(ICodeStylePreferences *);
private slots:
void slotSaveCodeStyle();
private:
QString settingsDir() const;
QString settingsPath(const QString &id) const;
ICodeStylePreferences *loadCodeStyle(const QString &fileName);
void saveCodeStyle(ICodeStylePreferences *codeStyle) const;
Internal::CodeStylePoolPrivate *d;
};
} // namespace TextEditor
#endif // CODESTYLEPOOL_H
@@ -1,88 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "codestylepreferencesmanager.h"
#include "icodestylepreferencesfactory.h"
#include <QtCore/QMap>
using namespace TextEditor;
CodeStylePreferencesManager *CodeStylePreferencesManager::m_instance = 0;
namespace TextEditor {
namespace Internal {
class CodeStylePreferencesManagerPrivate
{
public:
QMap<QString, ICodeStylePreferencesFactory *> m_idToFactory;
QList<ICodeStylePreferencesFactory *> m_factories;
};
} // namespace Internal
} // namespace TextEditor
CodeStylePreferencesManager::CodeStylePreferencesManager()
: QObject(),
d(new Internal::CodeStylePreferencesManagerPrivate())
{
}
CodeStylePreferencesManager::~CodeStylePreferencesManager()
{
delete d;
}
CodeStylePreferencesManager *CodeStylePreferencesManager::instance()
{
if (!m_instance)
m_instance = new CodeStylePreferencesManager();
return m_instance;
}
void CodeStylePreferencesManager::registerFactory(ICodeStylePreferencesFactory *settings)
{
d->m_idToFactory.insert(settings->languageId(), settings);
d->m_factories = d->m_idToFactory.values();
}
QList<ICodeStylePreferencesFactory *> CodeStylePreferencesManager::factories() const
{
return d->m_factories;
}
ICodeStylePreferencesFactory *CodeStylePreferencesManager::factory(const QString &languageId) const
{
return d->m_idToFactory.value(languageId);
}
@@ -0,0 +1,408 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "codestyleselectorwidget.h"
#include "icodestylepreferences.h"
#include "icodestylepreferencesfactory.h"
#include "codestylepool.h"
#include "tabsettings.h"
#include <QtGui/QComboBox>
#include <QtGui/QBoxLayout>
#include <QtGui/QCheckBox>
#include <QtGui/QPushButton>
#include <QtGui/QMenu>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QDialog>
#include <QtGui/QInputDialog>
#include <QtGui/QLabel>
#include <QtGui/QMessageBox>
#include <QtGui/QFileDialog>
#include <QtCore/QTextStream>
#include <QtCore/QSignalMapper>
#include <QDebug>
using namespace TextEditor;
Q_DECLARE_METATYPE(TextEditor::ICodeStylePreferences *)
namespace TextEditor {
namespace Internal {
class CodeStyleDialog : public QDialog
{
Q_OBJECT
public:
CodeStyleDialog(ICodeStylePreferencesFactory *factory,
ICodeStylePreferences *codeStyle, QWidget *parent = 0);
~CodeStyleDialog();
ICodeStylePreferences *codeStyle() const;
QString displayName() const;
private:
ICodeStylePreferences *m_codeStyle;
QLineEdit *m_lineEdit;
};
CodeStyleDialog::CodeStyleDialog(ICodeStylePreferencesFactory *factory,
ICodeStylePreferences *codeStyle, QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("Edit Code Style"));
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel *label = new QLabel(tr("Code style name:"));
m_lineEdit = new QLineEdit(codeStyle->displayName(), this);
QHBoxLayout *nameLayout = new QHBoxLayout();
nameLayout->addWidget(label);
nameLayout->addWidget(m_lineEdit);
layout->addLayout(nameLayout);
m_codeStyle = factory->createCodeStyle();
m_codeStyle->setTabSettings(codeStyle->tabSettings());
m_codeStyle->setValue(codeStyle->value());
QWidget *editor = factory->createEditor(m_codeStyle, this);
QDialogButtonBox *buttons = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
if (editor)
layout->addWidget(editor);
layout->addWidget(buttons);
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
}
ICodeStylePreferences *CodeStyleDialog::codeStyle() const
{
return m_codeStyle;
}
QString CodeStyleDialog::displayName() const
{
return m_lineEdit->text();
}
CodeStyleDialog::~CodeStyleDialog()
{
delete m_codeStyle;
}
}
}
CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory, QWidget *parent) :
QWidget(parent),
m_factory(factory),
m_codeStyle(0),
m_layout(0),
m_comboBox(0),
m_comboBoxLabel(0),
m_ignoreGuiSignals(false)
{
m_layout = new QHBoxLayout(this);
m_layout->setContentsMargins(QMargins());
m_copyButton = new QPushButton(tr("Copy..."), this);
m_editButton = new QPushButton(tr("Edit..."), this);
m_removeButton = new QPushButton(tr("Remove"), this);
m_importButton = new QPushButton(tr("Import..."), this);
m_exportButton = new QPushButton(tr("Export..."), this);
m_importButton->setEnabled(false);
m_exportButton->setEnabled(false);
m_comboBoxLabel = new QLabel(tr("Current settings:"), this);
m_comboBoxLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_layout->addWidget(m_comboBoxLabel);
m_comboBox = new QComboBox(this);
m_comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_layout->addWidget(m_comboBox);
connect(m_comboBox, SIGNAL(activated(int)),
this, SLOT(slotComboBoxActivated(int)));
m_layout->addWidget(m_copyButton);
m_layout->addWidget(m_editButton);
m_layout->addWidget(m_removeButton);
m_layout->addWidget(m_importButton);
m_layout->addWidget(m_exportButton);
connect(m_copyButton, SIGNAL(clicked()),
this, SLOT(slotCopyClicked()));
connect(m_editButton, SIGNAL(clicked()),
this, SLOT(slotEditClicked()));
connect(m_removeButton, SIGNAL(clicked()),
this, SLOT(slotRemoveClicked()));
connect(m_importButton, SIGNAL(clicked()),
this, SLOT(slotImportClicked()));
connect(m_exportButton, SIGNAL(clicked()),
this, SLOT(slotExportClicked()));
}
void CodeStyleSelectorWidget::setCodeStyle(TextEditor::ICodeStylePreferences *codeStyle)
{
if (m_codeStyle == codeStyle)
return; // nothing changes
// cleanup old
if (m_codeStyle) {
CodeStylePool *codeStylePool = m_codeStyle->delegatingPool();
if (codeStylePool) {
disconnect(codeStylePool, SIGNAL(codeStyleAdded(ICodeStylePreferences*)),
this, SLOT(slotCodeStyleAdded(ICodeStylePreferences*)));
disconnect(codeStylePool, SIGNAL(codeStyleRemoved(ICodeStylePreferences*)),
this, SLOT(slotCodeStyleRemoved(ICodeStylePreferences*)));
}
disconnect(m_codeStyle, SIGNAL(currentDelegateChanged(ICodeStylePreferences*)),
this, SLOT(slotCurrentDelegateChanged(ICodeStylePreferences*)));
m_exportButton->setEnabled(false);
m_importButton->setEnabled(false);
m_comboBox->clear();
}
m_codeStyle = codeStyle;
// fillup new
if (m_codeStyle) {
QList<ICodeStylePreferences *> delegates;
CodeStylePool *codeStylePool = m_codeStyle->delegatingPool();
if (codeStylePool) {
delegates = codeStylePool->codeStyles();
connect(codeStylePool, SIGNAL(codeStyleAdded(ICodeStylePreferences*)),
this, SLOT(slotCodeStyleAdded(ICodeStylePreferences*)));
connect(codeStylePool, SIGNAL(codeStyleRemoved(ICodeStylePreferences*)),
this, SLOT(slotCodeStyleRemoved(ICodeStylePreferences*)));
m_exportButton->setEnabled(true);
m_importButton->setEnabled(true);
}
for (int i = 0; i < delegates.count(); i++)
slotCodeStyleAdded(delegates.at(i));
slotCurrentDelegateChanged(m_codeStyle->currentDelegate());
connect(m_codeStyle, SIGNAL(currentDelegateChanged(TextEditor::ICodeStylePreferences*)),
this, SLOT(slotCurrentDelegateChanged(TextEditor::ICodeStylePreferences*)));
}
}
void CodeStyleSelectorWidget::slotComboBoxActivated(int index)
{
if (m_ignoreGuiSignals)
return;
if (!m_comboBox || index < 0 || index >= m_comboBox->count())
return;
TextEditor::ICodeStylePreferences *delegate =
m_comboBox->itemData(index).value<TextEditor::ICodeStylePreferences *>();
const bool wasBlocked = blockSignals(true);
m_codeStyle->setCurrentDelegate(delegate);
blockSignals(wasBlocked);
}
void CodeStyleSelectorWidget::slotCurrentDelegateChanged(TextEditor::ICodeStylePreferences *delegate)
{
m_ignoreGuiSignals = true;
if (m_comboBox) {
m_comboBox->setCurrentIndex(m_comboBox->findData(QVariant::fromValue(delegate)));
m_comboBox->setToolTip(m_comboBox->currentText());
}
m_ignoreGuiSignals = false;
const bool enableEdit = delegate && !delegate->isReadOnly() && !delegate->currentDelegate();
m_editButton->setEnabled(enableEdit);
m_removeButton->setEnabled(enableEdit);
}
void CodeStyleSelectorWidget::slotCopyClicked()
{
if (!m_codeStyle)
return;
CodeStylePool *codeStylePool = m_codeStyle->delegatingPool();
ICodeStylePreferences *currentPreferences = m_codeStyle->currentPreferences();
bool ok = false;
const QString newName = QInputDialog::getText(this,
tr("Copy Code Style"),
tr("Code style name:"),
QLineEdit::Normal,
tr("%1 (Copy)").arg(currentPreferences->displayName()),
&ok);
if (!ok)
return;
ICodeStylePreferences *copy = codeStylePool->cloneCodeStyle(currentPreferences);
copy->setDisplayName(newName);
if (copy)
m_codeStyle->setCurrentDelegate(copy);
}
void CodeStyleSelectorWidget::slotEditClicked()
{
if (!m_codeStyle)
return;
ICodeStylePreferences *codeStyle = m_codeStyle->currentPreferences();
// check if it's read-only
Internal::CodeStyleDialog dialog(m_factory, codeStyle, this);
if (dialog.exec() == QDialog::Accepted) {
ICodeStylePreferences *dialogCodeStyle = dialog.codeStyle();
codeStyle->setTabSettings(dialogCodeStyle->tabSettings());
codeStyle->setValue(dialogCodeStyle->value());
codeStyle->setDisplayName(dialog.displayName());
}
}
void CodeStyleSelectorWidget::slotRemoveClicked()
{
if (!m_codeStyle)
return;
CodeStylePool *codeStylePool = m_codeStyle->delegatingPool();
ICodeStylePreferences *currentPreferences = m_codeStyle->currentPreferences();
QMessageBox messageBox(QMessageBox::Warning,
tr("Delete Code Style"),
tr("Are you sure you want to delete this code style permanently?"),
QMessageBox::Discard | QMessageBox::Cancel,
this);
// Change the text and role of the discard button
QPushButton *deleteButton = static_cast<QPushButton*>(messageBox.button(QMessageBox::Discard));
deleteButton->setText(tr("Delete"));
messageBox.addButton(deleteButton, QMessageBox::AcceptRole);
messageBox.setDefaultButton(deleteButton);
connect(deleteButton, SIGNAL(clicked()), &messageBox, SLOT(accept()));
if (messageBox.exec() == QDialog::Accepted)
codeStylePool->removeCodeStyle(currentPreferences);
}
void CodeStyleSelectorWidget::slotImportClicked()
{
const QString fileName = QFileDialog::getOpenFileName(this, tr("Import Code Style"), QString::null,
tr("Code styles (*.xml);;All files (*)"));
if (!fileName.isEmpty()) {
CodeStylePool *codeStylePool = m_codeStyle->delegatingPool();
ICodeStylePreferences *importedStyle = codeStylePool->importCodeStyle(fileName);
if (importedStyle)
m_codeStyle->setCurrentDelegate(importedStyle);
else
QMessageBox::warning(this, tr("Import Code Style"),
tr("Cannot import code style"));
}
}
void CodeStyleSelectorWidget::slotExportClicked()
{
ICodeStylePreferences *currentPreferences = m_codeStyle->currentPreferences();
const QString fileName = QFileDialog::getSaveFileName(this, tr("Export Code Style"),
currentPreferences->id() + QLatin1String(".xml"),
tr("Code styles (*.xml);;All files (*)"));
if (!fileName.isEmpty()) {
CodeStylePool *codeStylePool = m_codeStyle->delegatingPool();
codeStylePool->exportCodeStyle(fileName, currentPreferences);
}
}
void CodeStyleSelectorWidget::slotCodeStyleAdded(ICodeStylePreferences *codeStylePreferences)
{
if (codeStylePreferences == m_codeStyle
|| codeStylePreferences->id() == m_codeStyle->id())
return;
const QVariant data = QVariant::fromValue(codeStylePreferences);
const QString name = displayName(codeStylePreferences);
m_comboBox->addItem(name, data);
m_comboBox->setItemData(m_comboBox->count() - 1, name, Qt::ToolTipRole);
connect(codeStylePreferences, SIGNAL(displayNameChanged(QString)),
this, SLOT(slotUpdateName()));
if (codeStylePreferences->delegatingPool()) {
connect(codeStylePreferences, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)),
this, SLOT(slotUpdateName()));
}
}
void CodeStyleSelectorWidget::slotCodeStyleRemoved(ICodeStylePreferences *codeStylePreferences)
{
m_ignoreGuiSignals = true;
m_comboBox->removeItem(m_comboBox->findData(QVariant::fromValue(codeStylePreferences)));
disconnect(codeStylePreferences, SIGNAL(displayNameChanged(QString)),
this, SLOT(slotUpdateName()));
if (codeStylePreferences->delegatingPool()) {
disconnect(codeStylePreferences, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)),
this, SLOT(slotUpdateName()));
}
m_ignoreGuiSignals = false;
}
void CodeStyleSelectorWidget::slotUpdateName()
{
ICodeStylePreferences *changedCodeStyle = qobject_cast<ICodeStylePreferences *>(sender());
if (!changedCodeStyle)
return;
updateName(changedCodeStyle);
QList<ICodeStylePreferences *> codeStyles = m_codeStyle->delegatingPool()->codeStyles();
for (int i = 0; i < codeStyles.count(); i++) {
ICodeStylePreferences *codeStyle = codeStyles.at(i);
if (codeStyle->currentDelegate() == changedCodeStyle)
updateName(codeStyle);
}
m_comboBox->setToolTip(m_comboBox->currentText());
}
void CodeStyleSelectorWidget::updateName(ICodeStylePreferences *codeStyle)
{
const int idx = m_comboBox->findData(QVariant::fromValue(codeStyle));
if (idx < 0)
return;
const QString name = displayName(codeStyle);
m_comboBox->setItemText(idx, name);
m_comboBox->setItemData(idx, name, Qt::ToolTipRole);
}
QString CodeStyleSelectorWidget::displayName(ICodeStylePreferences *codeStyle) const
{
QString name = codeStyle->displayName();
if (codeStyle->currentDelegate())
name = tr("%1 [proxy: %2]").arg(name).arg(codeStyle->currentDelegate()->displayName());
if (codeStyle->isReadOnly())
name = tr("%1 [built-in]").arg(name);
return name;
}
QString CodeStyleSelectorWidget::searchKeywords() const
{
// no useful keywords here
return QString();
}
#include "codestyleselectorwidget.moc"
@@ -30,8 +30,8 @@
**
**************************************************************************/
#ifndef FALLBACKSELECTORWIDGET_H
#define FALLBACKSELECTORWIDGET_H
#ifndef CODESTYLESELECTORWIDGET_H
#define CODESTYLESELECTORWIDGET_H
#include "texteditor_global.h"
@@ -47,40 +47,52 @@ QT_END_NAMESPACE
namespace TextEditor {
class IFallbackPreferences;
class ICodeStylePreferences;
class ICodeStylePreferencesFactory;
class TEXTEDITOR_EXPORT FallbackSelectorWidget : public QWidget
class TEXTEDITOR_EXPORT CodeStyleSelectorWidget : public QWidget
{
Q_OBJECT
public:
explicit FallbackSelectorWidget(QWidget *parent = 0);
explicit CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory, QWidget *parent = 0);
void setFallbackPreferences(TextEditor::IFallbackPreferences *fallbackPreferences);
void setCodeStyle(TextEditor::ICodeStylePreferences *codeStyle);
QString searchKeywords() const;
void setFallbacksVisible(bool on);
void setLabelText(const QString &text);
signals:
private slots:
void slotComboBoxActivated(int index);
void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *);
void slotRestoreValues(QObject *);
void slotCurrentDelegateChanged(TextEditor::ICodeStylePreferences *delegate);
void slotCopyClicked();
void slotEditClicked();
void slotRemoveClicked();
void slotImportClicked();
void slotExportClicked();
void slotCodeStyleAdded(ICodeStylePreferences*);
void slotCodeStyleRemoved(ICodeStylePreferences*);
void slotUpdateName();
private:
IFallbackPreferences *m_fallbackPreferences;
void updateName(ICodeStylePreferences *codeStyle);
ICodeStylePreferencesFactory *m_factory;
ICodeStylePreferences *m_codeStyle;
QString displayName(ICodeStylePreferences *codeStyle) const;
QHBoxLayout *m_layout;
QComboBox *m_comboBox;
QLabel *m_comboBoxLabel;
QPushButton *m_restoreButton;
QPushButton *m_copyButton;
QPushButton *m_editButton;
QPushButton *m_removeButton;
QPushButton *m_importButton;
QPushButton *m_exportButton;
bool m_fallbackWidgetVisible;
QString m_labelText;
bool m_ignoreGuiSignals;
};
} // namespace TextEditor
#endif // FALLBACKSELECTORWIDGET_H
#endif // CODESTYLESELECTORWIDGET_H
@@ -1,176 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "fallbackselectorwidget.h"
#include "ifallbackpreferences.h"
#include <QtGui/QComboBox>
#include <QtGui/QBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QCheckBox>
#include <QtGui/QPushButton>
#include <QtGui/QMenu>
#include <QtCore/QTextStream>
#include <QtCore/QSignalMapper>
using namespace TextEditor;
Q_DECLARE_METATYPE(TextEditor::IFallbackPreferences *)
FallbackSelectorWidget::FallbackSelectorWidget(QWidget *parent) :
QWidget(parent),
m_fallbackPreferences(0),
m_layout(0),
m_comboBox(0),
m_comboBoxLabel(0),
m_restoreButton(0),
m_fallbackWidgetVisible(true),
m_labelText(tr("Settings:"))
{
hide();
}
void FallbackSelectorWidget::setFallbackPreferences(TextEditor::IFallbackPreferences *fallbackPreferences)
{
if (m_fallbackPreferences == fallbackPreferences)
return; // nothing changes
// cleanup old
if (m_fallbackPreferences) {
disconnect(m_fallbackPreferences, SIGNAL(currentFallbackChanged(IFallbackPreferences*)),
this, SLOT(slotCurrentFallbackChanged(IFallbackPreferences*)));
hide();
if (m_layout)
delete m_layout;
}
m_fallbackPreferences = fallbackPreferences;
// fillup new
if (m_fallbackPreferences) {
const QList<IFallbackPreferences *> fallbacks = m_fallbackPreferences->fallbacks();
setVisible(m_fallbackWidgetVisible && !fallbacks.isEmpty());
m_layout = new QHBoxLayout(this);
m_layout->setContentsMargins(QMargins());
m_restoreButton = new QPushButton(this);
QSignalMapper *mapper = new QSignalMapper(this);
m_comboBoxLabel = new QLabel(m_labelText, this);
m_comboBoxLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_layout->addWidget(m_comboBoxLabel);
m_comboBox = new QComboBox(this);
m_layout->addWidget(m_comboBox);
m_comboBox->addItem(tr("Custom"), QVariant::fromValue<TextEditor::IFallbackPreferences *>(0));
connect(m_comboBox, SIGNAL(activated(int)),
this, SLOT(slotComboBoxActivated(int)));
QMenu *menu = new QMenu(this);
if (fallbacks.count() == 1) {
IFallbackPreferences *fallback = fallbacks.first();
m_restoreButton->setText(tr("Restore %1", "%1 is settings name (e.g. Global C++)").arg(fallback->displayName()));
connect(m_restoreButton, SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(m_restoreButton, fallback);
} else {
m_restoreButton->setText(tr("Restore"));
m_restoreButton->setMenu(menu);
}
for (int i = 0; i < fallbacks.count(); i++) {
IFallbackPreferences *fallback = fallbacks.at(i);
const QString displayName = fallback->displayName();
const QVariant data = QVariant::fromValue(fallback);
m_comboBox->insertItem(i, displayName, data);
QAction *restoreAction = new QAction(displayName, this);
menu->addAction(restoreAction);
connect(restoreAction, SIGNAL(triggered()), mapper, SLOT(map()));
mapper->setMapping(restoreAction, fallback);
}
m_layout->addWidget(m_restoreButton);
slotCurrentFallbackChanged(m_fallbackPreferences->currentFallback());
connect(m_fallbackPreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
connect(mapper, SIGNAL(mapped(QObject*)), this, SLOT(slotRestoreValues(QObject*)));
}
}
void FallbackSelectorWidget::slotComboBoxActivated(int index)
{
if (!m_comboBox || index < 0 || index >= m_comboBox->count())
return;
TextEditor::IFallbackPreferences *fallback =
m_comboBox->itemData(index).value<TextEditor::IFallbackPreferences *>();
const bool wasBlocked = blockSignals(true);
m_fallbackPreferences->setCurrentFallback(fallback);
blockSignals(wasBlocked);
}
void FallbackSelectorWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback)
{
const bool wasBlocked = blockSignals(true);
if (m_comboBox)
m_comboBox->setCurrentIndex(m_comboBox->findData(QVariant::fromValue(fallback)));
if (m_restoreButton)
m_restoreButton->setEnabled(!fallback);
blockSignals(wasBlocked);
}
void FallbackSelectorWidget::slotRestoreValues(QObject *fallbackObject)
{
TextEditor::IFallbackPreferences *fallback
= qobject_cast<TextEditor::IFallbackPreferences *>(fallbackObject);
if (!fallback)
return;
m_fallbackPreferences->setValue(fallback->currentValue());
}
void FallbackSelectorWidget::setFallbacksVisible(bool on)
{
m_fallbackWidgetVisible = on;
if (m_fallbackPreferences)
setVisible(m_fallbackWidgetVisible && !m_fallbackPreferences->fallbacks().isEmpty());
}
void FallbackSelectorWidget::setLabelText(const QString &text)
{
m_labelText = text;
if (m_comboBoxLabel)
m_comboBoxLabel->setText(text);
}
QString FallbackSelectorWidget::searchKeywords() const
{
// no useful keywords here
return QString();
}
@@ -0,0 +1,287 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "icodestylepreferences.h"
#include "codestylepool.h"
#include "tabsettings.h"
#include "texteditorconstants.h"
#include <utils/settingsutils.h>
#include <QtCore/QSettings>
#include <QtCore/QStringList>
using namespace TextEditor;
static const char *currentPreferencesKey = "CurrentPreferences";
namespace TextEditor {
namespace Internal {
class ICodeStylePreferencesPrivate
{
public:
ICodeStylePreferencesPrivate()
: m_pool(0),
m_currentDelegate(0),
m_readOnly(false)
{}
CodeStylePool *m_pool;
ICodeStylePreferences *m_currentDelegate;
TabSettings m_tabSettings;
QString m_id;
QString m_displayName;
bool m_readOnly;
};
}
}
ICodeStylePreferences::ICodeStylePreferences(QObject *parent) :
QObject(parent),
d(new Internal::ICodeStylePreferencesPrivate)
{
}
ICodeStylePreferences::~ICodeStylePreferences()
{
delete d;
}
QString ICodeStylePreferences::id() const
{
return d->m_id;
}
void ICodeStylePreferences::setId(const QString &name)
{
d->m_id = name;
}
QString ICodeStylePreferences::displayName() const
{
return d->m_displayName;
}
void ICodeStylePreferences::setDisplayName(const QString &name)
{
d->m_displayName = name;
emit displayNameChanged(name);
}
bool ICodeStylePreferences::isReadOnly() const
{
return d->m_readOnly;
}
void ICodeStylePreferences::setReadOnly(bool on)
{
d->m_readOnly = on;
}
void ICodeStylePreferences::setTabSettings(const TabSettings &settings)
{
if (d->m_tabSettings == settings)
return;
d->m_tabSettings = settings;
emit tabSettingsChanged(d->m_tabSettings);
if (!currentDelegate()) {
emit currentTabSettingsChanged(d->m_tabSettings);
}
}
TabSettings ICodeStylePreferences::tabSettings() const
{
return d->m_tabSettings;
}
TabSettings ICodeStylePreferences::currentTabSettings() const
{
return currentPreferences()->tabSettings();
}
QVariant ICodeStylePreferences::currentValue() const
{
return currentPreferences()->value();
}
ICodeStylePreferences *ICodeStylePreferences::currentPreferences() const
{
ICodeStylePreferences *prefs = (ICodeStylePreferences *)this;
while (prefs->currentDelegate())
prefs = prefs->currentDelegate();
return prefs;
}
CodeStylePool *ICodeStylePreferences::delegatingPool() const
{
return d->m_pool;
}
void ICodeStylePreferences::setDelegatingPool(CodeStylePool *pool)
{
if (pool == d->m_pool)
return;
setCurrentDelegate(0);
if (d->m_pool) {
disconnect(d->m_pool, SIGNAL(codeStyleRemoved(ICodeStylePreferences*)),
this, SLOT(slotCodeStyleRemoved(ICodeStylePreferences*)));
}
d->m_pool = pool;
if (d->m_pool) {
connect(d->m_pool, SIGNAL(codeStyleRemoved(ICodeStylePreferences*)),
this, SLOT(slotCodeStyleRemoved(ICodeStylePreferences*)));
}
}
ICodeStylePreferences *ICodeStylePreferences::currentDelegate() const
{
return d->m_currentDelegate;
}
void ICodeStylePreferences::setCurrentDelegate(ICodeStylePreferences *delegate)
{
if (delegate && d->m_pool && !d->m_pool->codeStyles().contains(delegate)) {
// warning
return;
}
if (delegate == this || (delegate && delegate->id() == id())) {
// warning
return;
}
if (d->m_currentDelegate == delegate)
return; // nothing changes
if (d->m_currentDelegate) {
disconnect(d->m_currentDelegate, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)));
disconnect(d->m_currentDelegate, SIGNAL(currentValueChanged(QVariant)),
this, SIGNAL(currentValueChanged(QVariant)));
disconnect(d->m_currentDelegate, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences *)),
this, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences *)));
}
d->m_currentDelegate = delegate;
if (d->m_currentDelegate) {
connect(d->m_currentDelegate, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)));
connect(d->m_currentDelegate, SIGNAL(currentValueChanged(QVariant)),
this, SIGNAL(currentValueChanged(QVariant)));
connect(d->m_currentDelegate, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences *)),
this, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences *)));
}
emit currentDelegateChanged(d->m_currentDelegate);
emit currentPreferencesChanged(currentPreferences());
emit currentTabSettingsChanged(currentTabSettings());
emit currentValueChanged(currentValue());
}
QString ICodeStylePreferences::currentDelegateId() const
{
if (currentDelegate())
return currentDelegate()->id();
return id(); // or 0?
}
void ICodeStylePreferences::setCurrentDelegate(const QString &id)
{
if (d->m_pool)
setCurrentDelegate(d->m_pool->codeStyle(id));
}
void ICodeStylePreferences::toSettings(const QString &category, QSettings *s) const
{
Utils::toSettings(settingsSuffix(), category, s, this);
}
void ICodeStylePreferences::fromSettings(const QString &category, const QSettings *s)
{
Utils::fromSettings(settingsSuffix(), category, s, this);
}
void ICodeStylePreferences::toMap(const QString &prefix, QVariantMap *map) const
{
if (!currentDelegate())
d->m_tabSettings.toMap(prefix, map);
else
map->insert(prefix + QLatin1String(currentPreferencesKey), currentDelegateId());
}
void ICodeStylePreferences::fromMap(const QString &prefix, const QVariantMap &map)
{
d->m_tabSettings.fromMap(prefix, map);
const QString delegateId = map.value(prefix + QLatin1String(currentPreferencesKey)).toString();
if (delegatingPool()) {
ICodeStylePreferences *delegate = delegatingPool()->codeStyle(delegateId);
if (!delegateId.isEmpty() && delegate)
setCurrentDelegate(delegate);
}
}
void ICodeStylePreferences::slotCodeStyleRemoved(ICodeStylePreferences *preferences)
{
if (currentDelegate() == preferences) {
CodeStylePool *pool = delegatingPool();
QList<ICodeStylePreferences *> codeStyles = pool->codeStyles();
const int idx = codeStyles.indexOf(preferences);
ICodeStylePreferences *newCurrentPreferences = 0;
int i = idx + 1;
// go forward
while (i < codeStyles.count()) {
ICodeStylePreferences *prefs = codeStyles.at(i);
if (prefs->id() != id()) {
newCurrentPreferences = prefs;
break;
}
i++;
}
// go backward if still empty
if (!newCurrentPreferences) {
i = idx - 1;
while (i >= 0) {
ICodeStylePreferences *prefs = codeStyles.at(i);
if (prefs->id() != id()) {
newCurrentPreferences = prefs;
break;
}
i--;
}
}
setCurrentDelegate(newCurrentPreferences);
}
}
@@ -30,8 +30,8 @@
**
**************************************************************************/
#ifndef IFALLBACKPREFERENCES_H
#define IFALLBACKPREFERENCES_H
#ifndef ICODESTYLEPREFERENCES_H
#define ICODESTYLEPREFERENCES_H
#include "texteditor_global.h"
@@ -45,18 +45,20 @@ QT_END_NAMESPACE
namespace TextEditor {
namespace Internal {
class IFallbackPreferencesPrivate;
class ICodeStylePreferencesPrivate;
}
class TabSettings;
class CodeStylePool;
class TEXTEDITOR_EXPORT IFallbackPreferences : public QObject
class TEXTEDITOR_EXPORT ICodeStylePreferences : public QObject
{
Q_OBJECT
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
public:
explicit IFallbackPreferences(const QList<IFallbackPreferences *> &fallbacks, QObject *parentObject = 0);
virtual ~IFallbackPreferences();
// pool is a pool which will be used by this preferences for setting delegates
explicit ICodeStylePreferences(QObject *parentObject = 0);
virtual ~ICodeStylePreferences();
QString id() const;
void setId(const QString &name);
@@ -67,45 +69,53 @@ public:
bool isReadOnly() const;
void setReadOnly(bool on);
bool isFallbackEnabled(IFallbackPreferences *fallback) const;
void setFallbackEnabled(IFallbackPreferences *fallback, bool on);
virtual IFallbackPreferences *clone() const;
void setTabSettings(const TabSettings &settings);
TabSettings tabSettings() const;
TabSettings currentTabSettings() const;
virtual QVariant value() const = 0;
virtual void setValue(const QVariant &) = 0;
QVariant currentValue() const; // may be from grandparent
IFallbackPreferences *currentPreferences() const; // may be grandparent
ICodeStylePreferences *currentPreferences() const; // may be grandparent
QList<IFallbackPreferences *> fallbacks() const;
IFallbackPreferences *currentFallback() const; // null or one of the above list
void setCurrentFallback(IFallbackPreferences *fallback);
CodeStylePool *delegatingPool() const;
void setDelegatingPool(CodeStylePool *pool);
QString currentFallbackId() const;
void setCurrentFallback(const QString &id);
ICodeStylePreferences *currentDelegate() const; // null or one of delegates from the pool
void setCurrentDelegate(ICodeStylePreferences *delegate);
QString currentDelegateId() const;
void setCurrentDelegate(const QString &id);
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
// make below 2 protected?
virtual void toMap(const QString &prefix, QVariantMap *map) const = 0;
virtual void fromMap(const QString &prefix, const QVariantMap &map) = 0;
virtual void toMap(const QString &prefix, QVariantMap *map) const;
virtual void fromMap(const QString &prefix, const QVariantMap &map);
signals:
void tabSettingsChanged(const TextEditor::TabSettings &settings);
void currentTabSettingsChanged(const TextEditor::TabSettings &settings);
void valueChanged(const QVariant &);
void currentValueChanged(const QVariant &);
void currentFallbackChanged(TextEditor::IFallbackPreferences *currentFallback);
void currentPreferencesChanged(TextEditor::IFallbackPreferences *currentPreferences);
void currentDelegateChanged(TextEditor::ICodeStylePreferences *currentDelegate);
void currentPreferencesChanged(TextEditor::ICodeStylePreferences *currentPreferences);
void displayNameChanged(const QString &newName);
protected:
virtual QString settingsSuffix() const = 0;
protected slots:
void slotCodeStyleRemoved(ICodeStylePreferences *preferences);
private:
Internal::IFallbackPreferencesPrivate *d;
Internal::ICodeStylePreferencesPrivate *d;
};
} // namespace TextEditor
#endif // IFALLBACKPREFERENCES_H
#endif // ICODESTYLEPREFERENCES_H
@@ -39,9 +39,10 @@
namespace TextEditor {
class IFallbackPreferences;
class TabPreferences;
class ICodeStylePreferences;
class CodeStylePool;
class Indenter;
class ISnippetProvider;
class TEXTEDITOR_EXPORT ICodeStylePreferencesFactory : public QObject
{
@@ -51,9 +52,11 @@ public:
virtual QString languageId() = 0;
virtual QString displayName() = 0;
virtual IFallbackPreferences *createPreferences(const QList<IFallbackPreferences *> &fallbacks) const = 0;
virtual QWidget *createEditor(IFallbackPreferences *preferences, TabPreferences *tabSettings, QWidget *parent) const = 0;
virtual ICodeStylePreferences *createCodeStyle() const = 0;
virtual QWidget *createEditor(ICodeStylePreferences *preferences, QWidget *parent) const = 0;
virtual TextEditor::Indenter *createIndenter() const = 0;
virtual ISnippetProvider *snippetProvider() const = 0;
virtual QString previewText() const = 0;
};
} // namespace TextEditor
@@ -1,204 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "ifallbackpreferences.h"
#include <utils/settingsutils.h>
#include <QtCore/QSettings>
#include <QtCore/QStringList>
using namespace TextEditor;
namespace TextEditor {
namespace Internal {
class IFallbackPreferencesPrivate
{
public:
IFallbackPreferencesPrivate()
: m_currentFallback(0),
m_readOnly(false)
{}
QList<IFallbackPreferences *> m_fallbacks;
QMap<QString, IFallbackPreferences *> m_idToFallback;
QMap<IFallbackPreferences *, bool> m_fallbackToEnabled;
IFallbackPreferences *m_currentFallback;
QString m_id;
QString m_displayName;
bool m_readOnly;
};
}
}
IFallbackPreferences::IFallbackPreferences(
const QList<IFallbackPreferences *> &fallbacks,
QObject *parent) :
QObject(parent),
d(new Internal::IFallbackPreferencesPrivate)
{
d->m_fallbacks = fallbacks;
for (int i = 0; i < fallbacks.count(); i++) {
IFallbackPreferences *fallback = fallbacks.at(i);
d->m_idToFallback.insert(fallback->id(), fallback);
}
}
IFallbackPreferences::~IFallbackPreferences()
{
delete d;
}
QString IFallbackPreferences::id() const
{
return d->m_id;
}
void IFallbackPreferences::setId(const QString &name)
{
d->m_id = name;
}
QString IFallbackPreferences::displayName() const
{
return d->m_displayName;
}
void IFallbackPreferences::setDisplayName(const QString &name)
{
d->m_displayName = name;
}
bool IFallbackPreferences::isReadOnly() const
{
return d->m_readOnly;
}
void IFallbackPreferences::setReadOnly(bool on)
{
d->m_readOnly = on;
}
bool IFallbackPreferences::isFallbackEnabled(IFallbackPreferences *fallback) const
{
return d->m_fallbackToEnabled.value(fallback, true);
}
void IFallbackPreferences::setFallbackEnabled(IFallbackPreferences *fallback, bool on)
{
if (fallback && !d->m_fallbacks.contains(fallback)) {
// warning
return;
}
d->m_fallbackToEnabled[fallback] = on;
}
IFallbackPreferences *IFallbackPreferences::clone() const
{
return 0;
}
QVariant IFallbackPreferences::currentValue() const
{
return currentPreferences()->value();
}
IFallbackPreferences *IFallbackPreferences::currentPreferences() const
{
IFallbackPreferences *prefs = (IFallbackPreferences *)this;
while (prefs->currentFallback())
prefs = prefs->currentFallback();
return prefs;
}
QList<IFallbackPreferences *> IFallbackPreferences::fallbacks() const
{
return d->m_fallbacks;
}
IFallbackPreferences *IFallbackPreferences::currentFallback() const
{
return d->m_currentFallback;
}
void IFallbackPreferences::setCurrentFallback(IFallbackPreferences *fallback)
{
if (fallback && !d->m_fallbacks.contains(fallback)) {
// warning
return;
}
if (d->m_currentFallback == fallback)
return; // nothing changes
if (d->m_currentFallback) {
disconnect(d->m_currentFallback, SIGNAL(currentValueChanged(QVariant)),
this, SIGNAL(currentValueChanged(QVariant)));
disconnect(d->m_currentFallback, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)),
this, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)));
}
d->m_currentFallback = fallback;
if (d->m_currentFallback) {
connect(d->m_currentFallback, SIGNAL(currentValueChanged(QVariant)),
this, SIGNAL(currentValueChanged(QVariant)));
connect(d->m_currentFallback, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)),
this, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)));
}
emit currentFallbackChanged(d->m_currentFallback);
emit currentPreferencesChanged(currentPreferences());
emit currentValueChanged(currentValue());
}
QString IFallbackPreferences::currentFallbackId() const
{
if (currentFallback())
return currentFallback()->id();
return id(); // or 0?
}
void IFallbackPreferences::setCurrentFallback(const QString &id)
{
setCurrentFallback(d->m_idToFallback.value(id));
}
void IFallbackPreferences::toSettings(const QString &category, QSettings *s) const
{
Utils::toSettings(settingsSuffix(), category, s, this);
}
void IFallbackPreferences::fromSettings(const QString &category, const QSettings *s)
{
Utils::fromSettings(settingsSuffix(), category, s, this);
}
+5 -1
View File
@@ -107,7 +107,11 @@ void Indenter::reindent(QTextDocument *doc, const QTextCursor &cursor, const Tex
}
}
void Indenter::setCodeStylePreferences(IFallbackPreferences *)
void Indenter::setCodeStylePreferences(ICodeStylePreferences *)
{
}
void Indenter::invalidateCache(QTextDocument *)
{
}
+4 -2
View File
@@ -46,7 +46,7 @@ QT_END_NAMESPACE
namespace TextEditor {
class IFallbackPreferences;
class ICodeStylePreferences;
class TabSettings;
class TEXTEDITOR_EXPORT Indenter
@@ -74,7 +74,9 @@ public:
// change of the first block.
virtual void reindent(QTextDocument *doc, const QTextCursor &cursor, const TabSettings &tabSettings);
virtual void setCodeStylePreferences(IFallbackPreferences *preferences);
virtual void setCodeStylePreferences(ICodeStylePreferences *preferences);
virtual void invalidateCache(QTextDocument *doc);
};
} // namespace TextEditor
@@ -0,0 +1,62 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "simplecodestylepreferences.h"
#include "tabsettings.h"
using namespace TextEditor;
static const char *settingsSuffixKey = "TabPreferences";
SimpleCodeStylePreferences::SimpleCodeStylePreferences(QObject *parent)
: ICodeStylePreferences(parent)
{
}
QVariant SimpleCodeStylePreferences::value() const
{
return QVariant();
}
void SimpleCodeStylePreferences::setValue(const QVariant &value)
{
Q_UNUSED(value)
}
QString SimpleCodeStylePreferences::settingsSuffix() const
{
return settingsSuffixKey;
}
@@ -0,0 +1,57 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef SIMPLECODESTYLEPREFERENCES_H
#define SIMPLECODESTYLEPREFERENCES_H
#include "icodestylepreferences.h"
#include "tabsettings.h"
namespace TextEditor {
class TEXTEDITOR_EXPORT SimpleCodeStylePreferences : public ICodeStylePreferences
{
Q_OBJECT
public:
explicit SimpleCodeStylePreferences(QObject *parentObject = 0);
virtual QVariant value() const;
virtual void setValue(const QVariant &);
protected:
virtual QString settingsSuffix() const;
};
} // namespace TextEditor
#endif // SIMPLECODESTYLEPREFERENCES_H
@@ -0,0 +1,110 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "simplecodestylepreferenceswidget.h"
#include "icodestylepreferences.h"
#include "tabsettings.h"
#include "tabsettingswidget.h"
#include <QtGui/QVBoxLayout>
namespace TextEditor {
SimpleCodeStylePreferencesWidget::SimpleCodeStylePreferencesWidget(QWidget *parent) :
QWidget(parent),
m_preferences(0)
{
m_tabSettingsWidget = new TabSettingsWidget(this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(m_tabSettingsWidget);
layout->setContentsMargins(QMargins());
m_tabSettingsWidget->setEnabled(false);
}
void SimpleCodeStylePreferencesWidget::setPreferences(ICodeStylePreferences *preferences)
{
if (m_preferences == preferences)
return; // nothing changes
// cleanup old
if (m_preferences) {
disconnect(m_preferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
m_tabSettingsWidget, SLOT(setSettings(TextEditor::TabSettings)));
disconnect(m_preferences, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences*)));
disconnect(m_tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings)));
}
m_preferences = preferences;
// fillup new
if (m_preferences) {
slotCurrentPreferencesChanged(m_preferences->currentPreferences());
m_tabSettingsWidget->setTabSettings(m_preferences->currentTabSettings());
connect(m_preferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
m_tabSettingsWidget, SLOT(setTabSettings(TextEditor::TabSettings)));
connect(m_preferences, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences*)));
connect(m_tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings)));
}
m_tabSettingsWidget->setEnabled(m_preferences);
}
void SimpleCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences *preferences)
{
m_tabSettingsWidget->setEnabled(!preferences->isReadOnly() && !m_preferences->currentDelegate());
}
void SimpleCodeStylePreferencesWidget::slotTabSettingsChanged(const TextEditor::TabSettings &settings)
{
if (!m_preferences)
return;
ICodeStylePreferences *current = m_preferences->currentPreferences();
if (!current)
return;
current->setTabSettings(settings);
}
QString SimpleCodeStylePreferencesWidget::searchKeywords() const
{
return m_tabSettingsWidget->searchKeywords();
}
void SimpleCodeStylePreferencesWidget::setFlat(bool on)
{
m_tabSettingsWidget->setFlat(on);
}
} // namespace TextEditor
@@ -30,8 +30,8 @@
**
**************************************************************************/
#ifndef TABPREFERENCESWIDGET_H
#define TABPREFERENCESWIDGET_H
#ifndef SIMPLECODESTYLEPREFERENCESWIDGET_H
#define SIMPLECODESTYLEPREFERENCESWIDGET_H
#include "texteditor_global.h"
@@ -40,38 +40,33 @@
namespace TextEditor {
class TabSettings;
class TabPreferences;
class IFallbackPreferences;
class TabSettingsWidget;
class ICodeStylePreferences;
namespace Ui {
class TabPreferencesWidget;
}
class TEXTEDITOR_EXPORT TabPreferencesWidget : public QWidget
class TEXTEDITOR_EXPORT SimpleCodeStylePreferencesWidget : public QWidget
{
Q_OBJECT
public:
explicit TabPreferencesWidget(QWidget *parent = 0);
~TabPreferencesWidget();
explicit SimpleCodeStylePreferencesWidget(QWidget *parent = 0);
void setTabPreferences(TabPreferences *tabPreferences);
void setPreferences(ICodeStylePreferences *tabPreferences);
QString searchKeywords() const;
void setFallbacksVisible(bool on);
void setFlat(bool on);
protected:
void changeEvent(QEvent *e);
private slots:
void slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *preferences);
void slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences *preferences);
void slotTabSettingsChanged(const TextEditor::TabSettings &settings);
private:
Ui::TabPreferencesWidget *m_ui;
TabPreferences *m_tabPreferences;
TabSettingsWidget *m_tabSettingsWidget;
ICodeStylePreferences *m_preferences;
};
} // namespace TextEditor
#endif // TABPREFERENCESWIDGET_H
#endif // SIMPLECODESTYLEPREFERENCESWIDGET_H
-138
View File
@@ -1,138 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "tabpreferences.h"
#include "tabsettings.h"
#include "texteditorconstants.h"
using namespace TextEditor;
static const char *settingsSuffixKey = "TabPreferences";
static const char *currentFallbackKey = "CurrentFallback";
static QList<IFallbackPreferences *> toFallbackList(
const QList<TabPreferences *> &fallbacks)
{
QList<IFallbackPreferences *> fallbackList;
for (int i = 0; i < fallbacks.count(); i++)
fallbackList << fallbacks.at(i);
return fallbackList;
}
TabPreferences::TabPreferences(
const QList<IFallbackPreferences *> &fallbacks, QObject *parent)
: IFallbackPreferences(fallbacks, parent)
{
connect(this, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCurrentValueChanged(QVariant)));
}
TabPreferences::TabPreferences(
const QList<TabPreferences *> &fallbacks, QObject *parent)
: IFallbackPreferences(toFallbackList(fallbacks), parent)
{
connect(this, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCurrentValueChanged(QVariant)));
}
QVariant TabPreferences::value() const
{
QVariant v;
v.setValue(settings());
return v;
}
void TabPreferences::setValue(const QVariant &value)
{
if (!value.canConvert<TabSettings>())
return;
setSettings(value.value<TabSettings>());
}
TabSettings TabPreferences::settings() const
{
return m_data;
}
void TabPreferences::setSettings(const TextEditor::TabSettings &data)
{
if (m_data == data)
return;
m_data = data;
QVariant v;
v.setValue(data);
emit valueChanged(v);
emit settingsChanged(m_data);
if (!currentFallback()) {
emit currentValueChanged(v);
}
}
TabSettings TabPreferences::currentSettings() const
{
QVariant v = currentValue();
if (!v.canConvert<TabSettings>()) {
// warning
return TabSettings();
}
return v.value<TabSettings>();
}
void TabPreferences::slotCurrentValueChanged(const QVariant &value)
{
if (!value.canConvert<TabSettings>())
return;
emit currentSettingsChanged(value.value<TabSettings>());
}
QString TabPreferences::settingsSuffix() const
{
return settingsSuffixKey;
}
void TabPreferences::toMap(const QString &prefix, QVariantMap *map) const
{
m_data.toMap(prefix, map);
map->insert(prefix + QLatin1String(currentFallbackKey), currentFallbackId());
}
void TabPreferences::fromMap(const QString &prefix, const QVariantMap &map)
{
m_data.fromMap(prefix, map);
setCurrentFallback(map.value(prefix + QLatin1String(currentFallbackKey), Constants::GLOBAL_SETTINGS_ID).toString());
}
-83
View File
@@ -1,83 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef TABPREFERENCES_H
#define TABPREFERENCES_H
#include "ifallbackpreferences.h"
#include "tabsettings.h"
namespace TextEditor {
class TEXTEDITOR_EXPORT TabPreferences : public IFallbackPreferences
{
Q_OBJECT
public:
explicit TabPreferences(
const QList<IFallbackPreferences *> &fallbacks,
QObject *parentObject = 0);
explicit TabPreferences(
const QList<TabPreferences *> &fallbacks,
QObject *parentObject = 0);
virtual QVariant value() const;
virtual void setValue(const QVariant &);
TabSettings settings() const;
// tracks parent fallbacks until null and extracts settings from it
TabSettings currentSettings() const;
virtual void toMap(const QString &prefix, QVariantMap *map) const;
virtual void fromMap(const QString &prefix, const QVariantMap &map);
public slots:
void setSettings(const TextEditor::TabSettings &tabSettings);
signals:
void settingsChanged(const TextEditor::TabSettings &);
void currentSettingsChanged(const TextEditor::TabSettings &);
protected:
virtual QString settingsSuffix() const;
private slots:
void slotCurrentValueChanged(const QVariant &);
private:
TabSettings m_data;
};
} // namespace TextEditor
#endif // TABPREFERENCES_H
@@ -1,139 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "tabpreferenceswidget.h"
#include "ui_tabpreferenceswidget.h"
#include "tabpreferences.h"
#include <QtCore/QTextStream>
namespace TextEditor {
TabPreferencesWidget::TabPreferencesWidget(QWidget *parent) :
QWidget(parent),
m_ui(new Ui::TabPreferencesWidget),
m_tabPreferences(0)
{
m_ui->setupUi(this);
m_ui->fallbackWidget->setLabelText(tr("Tab settings:"));
m_ui->tabSettingsWidget->setEnabled(false);
}
TabPreferencesWidget::~TabPreferencesWidget()
{
delete m_ui;
}
void TabPreferencesWidget::setTabPreferences(TabPreferences *tabPreferences)
{
if (m_tabPreferences == tabPreferences)
return; // nothing changes
// cleanup old
if (m_tabPreferences) {
disconnect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
m_ui->tabSettingsWidget, SLOT(setSettings(TextEditor::TabSettings)));
disconnect(m_tabPreferences, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences*)));
disconnect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings)));
}
m_tabPreferences = tabPreferences;
m_ui->fallbackWidget->setFallbackPreferences(tabPreferences);
// fillup new
if (m_tabPreferences) {
slotCurrentPreferencesChanged(m_tabPreferences->currentPreferences());
m_ui->tabSettingsWidget->setSettings(m_tabPreferences->currentSettings());
connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
m_ui->tabSettingsWidget, SLOT(setSettings(TextEditor::TabSettings)));
connect(m_tabPreferences, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences*)));
connect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings)));
} else {
m_ui->tabSettingsWidget->setEnabled(false);
}
}
void TabPreferencesWidget::slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *preferences)
{
m_ui->tabSettingsWidget->setEnabled(!preferences->isReadOnly() && m_tabPreferences->isFallbackEnabled(m_tabPreferences->currentFallback()));
}
void TabPreferencesWidget::slotTabSettingsChanged(const TextEditor::TabSettings &settings)
{
if (!m_tabPreferences)
return;
TabPreferences *current = qobject_cast<TabPreferences *>(m_tabPreferences->currentPreferences());
if (!current)
return;
current->setSettings(settings);
}
QString TabPreferencesWidget::searchKeywords() const
{
QString rc;
QLatin1Char sep(' ');
QTextStream(&rc)
<< sep << m_ui->fallbackWidget->searchKeywords()
<< sep << m_ui->tabSettingsWidget->searchKeywords()
;
rc.remove(QLatin1Char('&'));
return rc;
}
void TabPreferencesWidget::setFallbacksVisible(bool on)
{
m_ui->fallbackWidget->setFallbacksVisible(on);
}
void TabPreferencesWidget::setFlat(bool on)
{
m_ui->tabSettingsWidget->setFlat(on);
}
void TabPreferencesWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
} // namespace TextEditor
@@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TextEditor::TabPreferencesWidget</class>
<widget class="QWidget" name="TextEditor::TabPreferencesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>122</width>
<height>97</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="TextEditor::FallbackSelectorWidget" name="fallbackWidget" native="true"/>
</item>
<item>
<widget class="TextEditor::TabSettingsWidget" name="tabSettingsWidget" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TextEditor::TabSettingsWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/tabsettingswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TextEditor::FallbackSelectorWidget</class>
<extends>QWidget</extends>
<header location="global">texteditor/fallbackselectorwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+14 -57
View File
@@ -42,27 +42,18 @@
static const char spacesForTabsKey[] = "SpacesForTabs";
static const char autoSpacesForTabsKey[] = "AutoSpacesForTabs";
static const char smartBackspaceBehaviorKey[] = "SmartBackspaceBehavior";
static const char autoIndentKey[] = "AutoIndent";
static const char tabSizeKey[] = "TabSize";
static const char indentSizeKey[] = "IndentSize";
static const char indentBracesKey[] = "IndentBraces";
static const char doubleIndentBlocksKey[] = "DoubleIndentBlocks";
static const char tabKeyBehaviorKey[] = "TabKeyBehavior";
static const char groupPostfix[] = "TabSettings";
static const char paddingModeKey[] = "PaddingMode";
namespace TextEditor {
TabSettings::TabSettings() :
m_spacesForTabs(true),
m_autoSpacesForTabs(false),
m_autoIndent(true),
m_tabPolicy(SpacesOnlyTabPolicy),
m_tabSize(8),
m_indentSize(4),
m_tabKeyBehavior(TabNeverIndents),
m_continuationAlignBehavior(ContinuationAlignWithSpaces),
m_smartBackspaceBehavior(BackspaceNeverIndents)
m_continuationAlignBehavior(ContinuationAlignWithSpaces)
{
}
@@ -79,30 +70,22 @@ void TabSettings::fromSettings(const QString &category, const QSettings *s)
void TabSettings::toMap(const QString &prefix, QVariantMap *map) const
{
map->insert(prefix + QLatin1String(spacesForTabsKey), m_spacesForTabs);
map->insert(prefix + QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs);
map->insert(prefix + QLatin1String(autoIndentKey), m_autoIndent);
map->insert(prefix + QLatin1String(smartBackspaceBehaviorKey), m_smartBackspaceBehavior);
map->insert(prefix + QLatin1String(spacesForTabsKey), m_tabPolicy != TabsOnlyTabPolicy);
map->insert(prefix + QLatin1String(autoSpacesForTabsKey), m_tabPolicy == MixedTabPolicy);
map->insert(prefix + QLatin1String(tabSizeKey), m_tabSize);
map->insert(prefix + QLatin1String(indentSizeKey), m_indentSize);
map->insert(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
map->insert(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior);
}
void TabSettings::fromMap(const QString &prefix, const QVariantMap &map)
{
m_spacesForTabs =
map.value(prefix + QLatin1String(spacesForTabsKey), m_spacesForTabs).toBool();
m_autoSpacesForTabs =
map.value(prefix + QLatin1String(autoSpacesForTabsKey), m_autoSpacesForTabs).toBool();
m_autoIndent = map.value(prefix + QLatin1String(autoIndentKey), m_autoIndent).toBool();
m_smartBackspaceBehavior = (SmartBackspaceBehavior)
map.value(prefix + QLatin1String(smartBackspaceBehaviorKey),
m_smartBackspaceBehavior).toInt();
const bool spacesForTabs =
map.value(prefix + QLatin1String(spacesForTabsKey), true).toBool();
const bool autoSpacesForTabs =
map.value(prefix + QLatin1String(autoSpacesForTabsKey), false).toBool();
m_tabPolicy = spacesForTabs ? (autoSpacesForTabs ? MixedTabPolicy : SpacesOnlyTabPolicy) : TabsOnlyTabPolicy;
m_tabSize = map.value(prefix + QLatin1String(tabSizeKey), m_tabSize).toInt();
m_indentSize = map.value(prefix + QLatin1String(indentSizeKey), m_indentSize).toInt();
m_tabKeyBehavior = (TabKeyBehavior)
map.value(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt();
m_continuationAlignBehavior = (ContinuationAlignBehavior)
map.value(prefix + QLatin1String(paddingModeKey), m_continuationAlignBehavior).toInt();
}
@@ -197,28 +180,6 @@ bool TabSettings::isIndentationClean(const QTextBlock &block) const
return true;
}
bool TabSettings::tabShouldIndent(const QTextDocument *document, QTextCursor cursor, int *suggestedPosition) const
{
if (m_tabKeyBehavior == TabNeverIndents)
return false;
QTextCursor tc = cursor;
if (suggestedPosition)
*suggestedPosition = tc.position(); // At least suggest original position
tc.movePosition(QTextCursor::StartOfLine);
if (tc.atBlockEnd()) // cursor was on a blank line
return true;
if (document->characterAt(tc.position()).isSpace()) {
tc.movePosition(QTextCursor::WordRight);
if (tc.positionInBlock() >= cursor.positionInBlock()) {
if (suggestedPosition)
*suggestedPosition = tc.position(); // Suggest position after whitespace
if (m_tabKeyBehavior == TabLeadingWhitespaceIndents)
return true;
}
}
return (m_tabKeyBehavior == TabAlwaysIndents);
}
int TabSettings::columnAt(const QString &text, int position) const
{
int column = 0;
@@ -270,7 +231,7 @@ int TabSettings::indentedColumn(int column, bool doIndent) const
bool TabSettings::guessSpacesForTabs(const QTextBlock &_block) const
{
if (m_spacesForTabs && m_autoSpacesForTabs && _block.isValid()) {
if (m_tabPolicy == MixedTabPolicy && _block.isValid()) {
const QTextDocument *doc = _block.document();
QVector<QTextBlock> currentBlocks(2, _block); // [0] looks back; [1] looks forward
int maxLookAround = 100;
@@ -296,7 +257,7 @@ bool TabSettings::guessSpacesForTabs(const QTextBlock &_block) const
break;
}
}
return m_spacesForTabs;
return m_tabPolicy != TabsOnlyTabPolicy;
}
QString TabSettings::indentationString(int startColumn, int targetColumn, const QTextBlock &block) const
@@ -339,7 +300,7 @@ void TabSettings::indentLine(QTextBlock block, int newIndent, int padding) const
QString indentString;
if (!m_spacesForTabs) {
if (m_tabPolicy == TabsOnlyTabPolicy) {
// user likes tabs for spaces and uses tabs for indentation, preserve padding
indentString = indentationString(0, newIndent - padding, block);
indentString += QString(padding, QLatin1Char(' '));
@@ -371,7 +332,7 @@ void TabSettings::reindentLine(QTextBlock block, int delta) const
return;
QString indentString;
if (!m_spacesForTabs && m_tabSize == m_indentSize) {
if (m_tabPolicy == TabsOnlyTabPolicy && m_tabSize == m_indentSize) {
// user likes tabs for spaces and uses tabs for indentation, preserve padding
int padding = qMin(maximumPadding(text), newIndent);
indentString = indentationString(0, newIndent - padding, block);
@@ -394,13 +355,9 @@ void TabSettings::reindentLine(QTextBlock block, int delta) const
bool TabSettings::equals(const TabSettings &ts) const
{
return m_spacesForTabs == ts.m_spacesForTabs
&& m_autoSpacesForTabs == ts.m_autoSpacesForTabs
&& m_autoIndent == ts.m_autoIndent
&& m_smartBackspaceBehavior == ts.m_smartBackspaceBehavior
return m_tabPolicy == ts.m_tabPolicy
&& m_tabSize == ts.m_tabSize
&& m_indentSize == ts.m_indentSize
&& m_tabKeyBehavior == ts.m_tabKeyBehavior
&& m_continuationAlignBehavior == ts.m_continuationAlignBehavior;
}
+6 -18
View File
@@ -49,11 +49,11 @@ namespace TextEditor {
class TEXTEDITOR_EXPORT TabSettings
{
public:
// This enum must match the indexes of tabKeyBehavior widget
enum TabKeyBehavior {
TabNeverIndents = 0,
TabAlwaysIndents = 1,
TabLeadingWhitespaceIndents = 2
enum TabPolicy {
SpacesOnlyTabPolicy = 0,
TabsOnlyTabPolicy = 1,
MixedTabPolicy = 2
};
// This enum must match the indexes of continuationAlignBehavior widget
@@ -63,13 +63,6 @@ public:
ContinuationAlignWithIndent = 2
};
// This enum must match the indexes of smartBackspaceBehavior widget
enum SmartBackspaceBehavior {
BackspaceNeverIndents = 0,
BackspaceFollowsPreviousIndents = 1,
BackspaceUnindents = 2
};
TabSettings();
void toSettings(const QString &category, QSettings *s) const;
@@ -97,17 +90,12 @@ public:
int trailingWhitespaces(const QString &text) const;
bool isIndentationClean(const QTextBlock &block) const;
bool tabShouldIndent(const QTextDocument *document, QTextCursor cursor, int *suggestedPosition = 0) const;
bool guessSpacesForTabs(const QTextBlock &block) const;
bool m_spacesForTabs;
bool m_autoSpacesForTabs;
bool m_autoIndent;
TabPolicy m_tabPolicy;
int m_tabSize;
int m_indentSize;
TabKeyBehavior m_tabKeyBehavior;
ContinuationAlignBehavior m_continuationAlignBehavior;
SmartBackspaceBehavior m_smartBackspaceBehavior;
bool equals(const TabSettings &ts) const;
};
+11 -44
View File
@@ -44,26 +44,14 @@ TabSettingsWidget::TabSettingsWidget(QWidget *parent) :
{
ui->setupUi(this);
connect(ui->insertSpaces, SIGNAL(toggled(bool)),
this, SLOT(slotSettingsChanged()));
connect(ui->insertSpaces, SIGNAL(toggled(bool)),
this, SLOT(updateWidget()));
connect(ui->autoInsertSpaces, SIGNAL(toggled(bool)),
this, SLOT(slotSettingsChanged()));
connect(ui->autoIndent, SIGNAL(toggled(bool)),
this, SLOT(slotSettingsChanged()));
connect(ui->smartBackspaceBehavior, SIGNAL(currentIndexChanged(int)),
connect(ui->tabPolicy, SIGNAL(currentIndexChanged(int)),
this, SLOT(slotSettingsChanged()));
connect(ui->tabSize, SIGNAL(valueChanged(int)),
this, SLOT(slotSettingsChanged()));
connect(ui->indentSize, SIGNAL(valueChanged(int)),
this, SLOT(slotSettingsChanged()));
connect(ui->tabKeyBehavior, SIGNAL(currentIndexChanged(int)),
this, SLOT(slotSettingsChanged()));
connect(ui->continuationAlignBehavior, SIGNAL(currentIndexChanged(int)),
this, SLOT(slotSettingsChanged()));
setFlat(false);
}
TabSettingsWidget::~TabSettingsWidget()
@@ -71,50 +59,38 @@ TabSettingsWidget::~TabSettingsWidget()
delete ui;
}
void TabSettingsWidget::setSettings(const TextEditor::TabSettings& s)
void TabSettingsWidget::setTabSettings(const TextEditor::TabSettings& s)
{
const bool wasBlocked = blockSignals(true);
ui->insertSpaces->setChecked(s.m_spacesForTabs);
ui->autoInsertSpaces->setChecked(s.m_autoSpacesForTabs);
ui->autoIndent->setChecked(s.m_autoIndent);
ui->smartBackspaceBehavior->setCurrentIndex(s.m_smartBackspaceBehavior);
ui->tabPolicy->setCurrentIndex(s.m_tabPolicy);
ui->tabSize->setValue(s.m_tabSize);
ui->indentSize->setValue(s.m_indentSize);
ui->tabKeyBehavior->setCurrentIndex(s.m_tabKeyBehavior);
ui->continuationAlignBehavior->setCurrentIndex(s.m_continuationAlignBehavior);
blockSignals(wasBlocked);
updateWidget();
}
TabSettings TabSettingsWidget::settings() const
TabSettings TabSettingsWidget::tabSettings() const
{
TabSettings set;
set.m_spacesForTabs = ui->insertSpaces->isChecked();
set.m_autoSpacesForTabs = ui->autoInsertSpaces->isChecked();
set.m_autoIndent = ui->autoIndent->isChecked();
set.m_smartBackspaceBehavior =
(TabSettings::SmartBackspaceBehavior)ui->smartBackspaceBehavior->currentIndex();
set.m_tabPolicy = (TabSettings::TabPolicy)(ui->tabPolicy->currentIndex());
set.m_tabSize = ui->tabSize->value();
set.m_indentSize = ui->indentSize->value();
set.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)(ui->tabKeyBehavior->currentIndex());
set.m_continuationAlignBehavior =
(TabSettings::ContinuationAlignBehavior)(ui->continuationAlignBehavior->currentIndex());
set.m_continuationAlignBehavior = (TabSettings::ContinuationAlignBehavior)(ui->continuationAlignBehavior->currentIndex());
return set;
}
void TabSettingsWidget::slotSettingsChanged()
{
emit settingsChanged(settings());
emit settingsChanged(tabSettings());
}
void TabSettingsWidget::setFlat(bool on)
{
ui->tabsAndIndentationGroupBox->setFlat(on);
const int margin = on ? 0 : -1;
ui->tabsAndIndentationGroupBox->layout()->setContentsMargins(margin, -1, margin, margin);
ui->tabsAndIndentationGroupBox->setFlat(on);
const int margin = on ? 0 : -1;
ui->tabsAndIndentationGroupBox->layout()->setContentsMargins(margin, -1, margin, margin);
}
QString TabSettingsWidget::searchKeywords() const
@@ -123,24 +99,15 @@ QString TabSettingsWidget::searchKeywords() const
QLatin1Char sep(' ');
QTextStream(&rc)
<< sep << ui->tabsAndIndentationGroupBox->title()
<< sep << ui->insertSpaces->text()
<< sep << ui->autoInsertSpaces->text()
<< sep << ui->autoIndent->text()
<< sep << ui->smartBackspaceLabel->text()
<< sep << ui->tabPolicyLabel->text()
<< sep << ui->tabSizeLabel->text()
<< sep << ui->indentSizeLabel->text()
<< sep << ui->tabKeyBehaviorLabel->text()
<< sep << ui->continuationAlignBehaviorLabel->text()
;
rc.remove(QLatin1Char('&'));
return rc;
}
void TabSettingsWidget::updateWidget()
{
ui->autoInsertSpaces->setEnabled(ui->insertSpaces->isChecked());
}
void TabSettingsWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
+2 -3
View File
@@ -53,13 +53,13 @@ public:
explicit TabSettingsWidget(QWidget *parent = 0);
~TabSettingsWidget();
TabSettings settings() const;
TabSettings tabSettings() const;
void setFlat(bool on);
QString searchKeywords() const;
public slots:
void setSettings(const TextEditor::TabSettings& s);
void setTabSettings(const TextEditor::TabSettings& s);
signals:
void settingsChanged(const TextEditor::TabSettings &);
@@ -69,7 +69,6 @@ protected:
private slots:
void slotSettingsChanged();
void updateWidget();
private:
Ui::TabSettingsWidget *ui;
+36 -129
View File
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>362</width>
<height>384</height>
<width>258</width>
<height>228</height>
</rect>
</property>
<property name="windowTitle">
@@ -22,22 +22,16 @@
<property name="title">
<string>Tabs And Indentation</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="insertSpaces">
<widget class="QLabel" name="tabPolicyLabel">
<property name="text">
<string>Insert &amp;spaces instead of tabs</string>
<string>Tab policy:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_5">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -47,22 +41,34 @@
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>24</height>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="autoInsertSpaces">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Automatically determine based on the nearest indented line (previous line preferred over next line)</string>
</property>
<property name="text">
<string>Based on the surrounding lines</string>
<item row="1" column="1">
<widget class="QComboBox" name="tabPolicy">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Spaces Only</string>
</property>
</item>
<item>
<property name="text">
<string>Tabs Only</string>
</property>
</item>
<item>
<property name="text">
<string>Mixed</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0" colspan="2">
@@ -146,35 +152,21 @@
</item>
</layout>
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>49</width>
<height>59</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="autoIndent">
<property name="text">
<string>Enable automatic &amp;indentation</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="continuationAlignBehaviorLabel">
<property name="text">
<string>Align continuation lines:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="continuationAlignBehavior">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
Influences the indentation of continuation lines.
@@ -219,100 +211,15 @@ Influences the indentation of continuation lines.
</item>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QLabel" name="tabKeyBehaviorLabel">
<property name="text">
<string>Tab key performs auto-indent:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QComboBox" name="tabKeyBehavior">
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<item>
<property name="text">
<string>Always</string>
</property>
</item>
<item>
<property name="text">
<string>In Leading White Space</string>
</property>
</item>
</widget>
</item>
<item row="10" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="smartBackspaceLabel">
<property name="text">
<string>Backspace indentation:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="smartBackspaceBehavior">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
Specifies how backspace interacts with indentation.
&lt;ul&gt;
&lt;li&gt;None: No interaction at all. Regular plain backspace behavior.
&lt;/li&gt;
&lt;li&gt;Follows Previous Indents: In leading white space it will take the cursor back to the nearest indentation level used in previous lines.
&lt;/li&gt;
&lt;li&gt;Unindents: If the character behind the cursor is a space it behaves as a backtab.
&lt;/li&gt;
&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;
</string>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Follows Previous Indents</string>
</property>
</item>
<item>
<property name="text">
<string>Unindents</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>insertSpaces</tabstop>
<tabstop>autoInsertSpaces</tabstop>
<tabstop>tabSize</tabstop>
<tabstop>indentSize</tabstop>
<tabstop>autoIndent</tabstop>
<tabstop>continuationAlignBehavior</tabstop>
<tabstop>tabKeyBehavior</tabstop>
</tabstops>
<resources/>
<connections/>
+26 -14
View File
@@ -101,13 +101,15 @@ SOURCES += texteditorplugin.cpp \
codeassist/basicproposalitemlistmodel.cpp \
codeassist/iassistproposalmodel.cpp \
tabsettingswidget.cpp \
codestylepreferencesmanager.cpp \
ifallbackpreferences.cpp \
tabpreferences.cpp \
simplecodestylepreferences.cpp \
simplecodestylepreferenceswidget.cpp \
icodestylepreferencesfactory.cpp \
tabpreferenceswidget.cpp \
fallbackselectorwidget.cpp \
semantichighlighter.cpp
semantichighlighter.cpp \
codestyleselectorwidget.cpp \
typingsettings.cpp \
icodestylepreferences.cpp \
codestylepool.cpp \
codestyleeditor.cpp
HEADERS += texteditorplugin.h \
textfilewizard.h \
@@ -213,13 +215,15 @@ HEADERS += texteditorplugin.h \
codeassist/basicproposalitemlistmodel.h \
codeassist/iassistproposalmodel.h \
tabsettingswidget.h \
codestylepreferencesmanager.h \
ifallbackpreferences.h \
tabpreferences.h \
simplecodestylepreferences.h \
simplecodestylepreferenceswidget.h \
icodestylepreferencesfactory.h \
tabpreferenceswidget.h \
fallbackselectorwidget.h \
semantichighlighter.h
semantichighlighter.h \
codestyleselectorwidget.h \
typingsettings.h \
icodestylepreferences.h \
codestylepool.h \
codestyleeditor.h
FORMS += \
displaysettingspage.ui \
@@ -230,7 +234,15 @@ FORMS += \
snippets/snippetssettingspage.ui \
behaviorsettingswidget.ui \
behaviorsettingspage.ui \
tabsettingswidget.ui \
tabpreferenceswidget.ui
tabsettingswidget.ui
RESOURCES += texteditor.qrc
OTHER_FILES += TextEditor.mimetypes.xml
@@ -41,7 +41,6 @@
#include "textfilewizard.h"
#include "plaintexteditorfactory.h"
#include "plaintexteditor.h"
#include "storagesettings.h"
#include "manager.h"
#include "outlinefactory.h"
#include "snippets/plaintextsnippetprovider.h"
+47 -23
View File
@@ -40,13 +40,15 @@
#include "displaysettings.h"
#include "displaysettingspage.h"
#include "fontsettingspage.h"
#include "typingsettings.h"
#include "storagesettings.h"
#include "tabsettings.h"
#include "tabpreferences.h"
#include "extraencodingsettings.h"
#include "texteditorplugin.h"
#include "highlightersettingspage.h"
#include "snippetssettingspage.h"
#include "icodestylepreferences.h"
#include "icodestylepreferencesfactory.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
@@ -70,9 +72,10 @@ public:
HighlighterSettingsPage *m_highlighterSettingsPage;
SnippetsSettingsPage *m_snippetsSettingsPage;
QMap<QString, TabPreferences *> m_languageTabPreferences;
QMap<QString, IFallbackPreferences *> m_languageCodeStylePreferences;
QMap<QString, ICodeStylePreferencesFactory *> m_languageToFactory;
QMap<QString, ICodeStylePreferences *> m_languageToCodeStyle;
QMap<QString, CodeStylePool *> m_languageToCodeStylePool;
QMap<QString, QString> m_mimeTypeToLanguage;
CompletionSettings m_completionSettings;
@@ -219,6 +222,8 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
connect(m_d->m_fontSettingsPage, SIGNAL(changed(TextEditor::FontSettings)),
this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)));
connect(m_d->m_behaviorSettingsPage, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
this, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)));
connect(m_d->m_behaviorSettingsPage, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)));
connect(m_d->m_behaviorSettingsPage, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -259,6 +264,8 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
// Connect to settings change signals
connect(this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
editor, SLOT(setFontSettingsIfVisible(TextEditor::FontSettings)));
connect(this, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
editor, SLOT(setTypingSettings(TextEditor::TypingSettings)));
connect(this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
editor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
connect(this, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -277,14 +284,14 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
// Apply current settings (tab settings depend on font settings)
editor->setFontSettings(fontSettings());
editor->setTabSettings(tabPreferences()->settings());
editor->setTabSettings(codeStyle()->tabSettings());
editor->setTypingSettings(typingSettings());
editor->setStorageSettings(storageSettings());
editor->setBehaviorSettings(behaviorSettings());
editor->setDisplaySettings(displaySettings());
editor->setCompletionSettings(completionSettings());
editor->setExtraEncodingSettings(extraEncodingSettings());
editor->setTabPreferences(tabPreferences(editor->languageSettingsId()));
editor->setCodeStylePreferences(codeStylePreferences(editor->languageSettingsId()));
editor->setCodeStyle(codeStyle(editor->languageSettingsId()));
}
const FontSettings &TextEditorSettings::fontSettings() const
@@ -292,6 +299,11 @@ const FontSettings &TextEditorSettings::fontSettings() const
return m_d->m_fontSettingsPage->fontSettings();
}
const TypingSettings &TextEditorSettings::typingSettings() const
{
return m_d->m_behaviorSettingsPage->typingSettings();
}
const StorageSettings &TextEditorSettings::storageSettings() const
{
return m_d->m_behaviorSettingsPage->storageSettings();
@@ -334,42 +346,54 @@ void TextEditorSettings::setCompletionSettings(const TextEditor::CompletionSetti
emit completionSettingsChanged(m_d->m_completionSettings);
}
TabPreferences *TextEditorSettings::tabPreferences() const
void TextEditorSettings::registerCodeStyleFactory(ICodeStylePreferencesFactory *factory)
{
return m_d->m_behaviorSettingsPage->tabPreferences();
m_d->m_languageToFactory.insert(factory->languageId(), factory);
}
TabPreferences *TextEditorSettings::tabPreferences(const QString &languageId) const
QMap<QString, ICodeStylePreferencesFactory *> TextEditorSettings::codeStyleFactories() const
{
TabPreferences *prefs = m_d->m_languageTabPreferences.value(languageId);
if (!prefs)
prefs = tabPreferences();
return prefs;
return m_d->m_languageToFactory;
}
QMap<QString, TabPreferences *> TextEditorSettings::languageTabPreferences() const
ICodeStylePreferencesFactory *TextEditorSettings::codeStyleFactory(const QString &languageId) const
{
return m_d->m_languageTabPreferences;
return m_d->m_languageToFactory.value(languageId);
}
void TextEditorSettings::registerLanguageTabPreferences(const QString &languageId, TabPreferences *prefs)
ICodeStylePreferences *TextEditorSettings::codeStyle() const
{
m_d->m_languageTabPreferences.insert(languageId, prefs);
return m_d->m_behaviorSettingsPage->codeStyle();
}
IFallbackPreferences *TextEditorSettings::codeStylePreferences(const QString &languageId) const
ICodeStylePreferences *TextEditorSettings::codeStyle(const QString &languageId) const
{
return m_d->m_languageCodeStylePreferences.value(languageId);
return m_d->m_languageToCodeStyle.value(languageId);
}
QMap<QString, IFallbackPreferences *> TextEditorSettings::languageCodeStylePreferences() const
QMap<QString, ICodeStylePreferences *> TextEditorSettings::codeStyles() const
{
return m_d->m_languageCodeStylePreferences;
return m_d->m_languageToCodeStyle;
}
void TextEditorSettings::registerLanguageCodeStylePreferences(const QString &languageId, IFallbackPreferences *prefs)
void TextEditorSettings::registerCodeStyle(const QString &languageId, ICodeStylePreferences *prefs)
{
m_d->m_languageCodeStylePreferences.insert(languageId, prefs);
m_d->m_languageToCodeStyle.insert(languageId, prefs);
}
CodeStylePool *TextEditorSettings::codeStylePool() const
{
return m_d->m_behaviorSettingsPage->codeStylePool();
}
CodeStylePool *TextEditorSettings::codeStylePool(const QString &languageId) const
{
return m_d->m_languageToCodeStylePool.value(languageId);
}
void TextEditorSettings::registerCodeStylePool(const QString &languageId, CodeStylePool *pool)
{
m_d->m_languageToCodeStylePool.insert(languageId, pool);
}
void TextEditorSettings::registerMimeTypeForLanguageId(const QString &mimeType, const QString &languageId)
+17 -9
View File
@@ -47,14 +47,16 @@ namespace TextEditor {
class BaseTextEditorWidget;
class FontSettings;
class TabSettings;
class TypingSettings;
class StorageSettings;
class BehaviorSettings;
class DisplaySettings;
class CompletionSettings;
class HighlighterSettings;
class ExtraEncodingSettings;
class TabPreferences;
class IFallbackPreferences;
class ICodeStylePreferences;
class ICodeStylePreferencesFactory;
class CodeStylePool;
namespace Internal {
class TextEditorSettingsPrivate;
@@ -78,6 +80,7 @@ public:
void initializeEditor(BaseTextEditorWidget *editor);
const FontSettings &fontSettings() const;
const TypingSettings &typingSettings() const;
const StorageSettings &storageSettings() const;
const BehaviorSettings &behaviorSettings() const;
const DisplaySettings &displaySettings() const;
@@ -87,20 +90,25 @@ public:
void setCompletionSettings(const TextEditor::CompletionSettings &);
TabPreferences *tabPreferences() const;
TabPreferences *tabPreferences(const QString &languageId) const;
QMap<QString, TabPreferences *> languageTabPreferences() const;
void registerLanguageTabPreferences(const QString &languageId, TabPreferences *prefs);
ICodeStylePreferencesFactory *codeStyleFactory(const QString &languageId) const;
QMap<QString, ICodeStylePreferencesFactory *> codeStyleFactories() const;
void registerCodeStyleFactory(ICodeStylePreferencesFactory *codeStyleFactory);
IFallbackPreferences *codeStylePreferences(const QString &languageId) const;
QMap<QString, IFallbackPreferences *> languageCodeStylePreferences() const;
void registerLanguageCodeStylePreferences(const QString &languageId, IFallbackPreferences *prefs);
CodeStylePool *codeStylePool() const;
CodeStylePool *codeStylePool(const QString &languageId) const;
void registerCodeStylePool(const QString &languageId, CodeStylePool *pool);
ICodeStylePreferences *codeStyle() const;
ICodeStylePreferences *codeStyle(const QString &languageId) const;
QMap<QString, ICodeStylePreferences *> codeStyles() const;
void registerCodeStyle(const QString &languageId, ICodeStylePreferences *prefs);
void registerMimeTypeForLanguageId(const QString &mimeType, const QString &languageId);
QString languageId(const QString &mimeType) const;
signals:
void fontSettingsChanged(const TextEditor::FontSettings &);
void typingSettingsChanged(const TextEditor::TypingSettings &);
void storageSettingsChanged(const TextEditor::StorageSettings &);
void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
void displaySettingsChanged(const TextEditor::DisplaySettings &);
+113
View File
@@ -0,0 +1,113 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "typingsettings.h"
#include <utils/settingsutils.h>
#include <QtGui/QTextCursor>
#include <QtGui/QTextDocument>
static const char autoIndentKey[] = "AutoIndent";
static const char tabKeyBehaviorKey[] = "TabKeyBehavior";
static const char smartBackspaceBehaviorKey[] = "SmartBackspaceBehavior";
static const char groupPostfix[] = "TypingSettings";
namespace TextEditor {
TypingSettings::TypingSettings():
m_autoIndent(true),
m_tabKeyBehavior(TabNeverIndents),
m_smartBackspaceBehavior(BackspaceNeverIndents)
{
}
void TypingSettings::toSettings(const QString &category, QSettings *s) const
{
Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
}
void TypingSettings::fromSettings(const QString &category, const QSettings *s)
{
*this = TypingSettings(); // Assign defaults
Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
void TypingSettings::toMap(const QString &prefix, QVariantMap *map) const
{
map->insert(prefix + QLatin1String(autoIndentKey), m_autoIndent);
map->insert(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
map->insert(prefix + QLatin1String(smartBackspaceBehaviorKey), m_smartBackspaceBehavior);
}
void TypingSettings::fromMap(const QString &prefix, const QVariantMap &map)
{
m_autoIndent = map.value(prefix + QLatin1String(autoIndentKey), m_autoIndent).toBool();
m_tabKeyBehavior = (TabKeyBehavior)
map.value(prefix + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt();
m_smartBackspaceBehavior = (SmartBackspaceBehavior)
map.value(prefix + QLatin1String(smartBackspaceBehaviorKey),
m_smartBackspaceBehavior).toInt();
}
bool TypingSettings::equals(const TypingSettings &ts) const
{
return m_autoIndent == ts.m_autoIndent
&& m_tabKeyBehavior == ts.m_tabKeyBehavior
&& m_smartBackspaceBehavior == ts.m_smartBackspaceBehavior;
}
bool TypingSettings::tabShouldIndent(const QTextDocument *document, QTextCursor cursor, int *suggestedPosition) const
{
if (m_tabKeyBehavior == TabNeverIndents)
return false;
QTextCursor tc = cursor;
if (suggestedPosition)
*suggestedPosition = tc.position(); // At least suggest original position
tc.movePosition(QTextCursor::StartOfLine);
if (tc.atBlockEnd()) // cursor was on a blank line
return true;
if (document->characterAt(tc.position()).isSpace()) {
tc.movePosition(QTextCursor::WordRight);
if (tc.positionInBlock() >= cursor.positionInBlock()) {
if (suggestedPosition)
*suggestedPosition = tc.position(); // Suggest position after whitespace
if (m_tabKeyBehavior == TabLeadingWhitespaceIndents)
return true;
}
}
return (m_tabKeyBehavior == TabAlwaysIndents);
}
} // namespace TextEditor
+88
View File
@@ -0,0 +1,88 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef TYPINGSETTINGS_H
#define TYPINGSETTINGS_H
#include "texteditor_global.h"
#include <QtCore/QVariant>
#include <QtGui/QTextBlock>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace TextEditor {
class TEXTEDITOR_EXPORT TypingSettings
{
public:
// This enum must match the indexes of tabKeyBehavior widget
enum TabKeyBehavior {
TabNeverIndents = 0,
TabAlwaysIndents = 1,
TabLeadingWhitespaceIndents = 2
};
// This enum must match the indexes of smartBackspaceBehavior widget
enum SmartBackspaceBehavior {
BackspaceNeverIndents = 0,
BackspaceFollowsPreviousIndents = 1,
BackspaceUnindents = 2
};
TypingSettings();
bool tabShouldIndent(const QTextDocument *document, QTextCursor cursor, int *suggestedPosition) const;
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
bool equals(const TypingSettings &ts) const;
bool m_autoIndent;
TabKeyBehavior m_tabKeyBehavior;
SmartBackspaceBehavior m_smartBackspaceBehavior;
};
inline bool operator==(const TypingSettings &t1, const TypingSettings &t2) { return t1.equals(t2); }
inline bool operator!=(const TypingSettings &t1, const TypingSettings &t2) { return !t1.equals(t2); }
} // namespace TextEditor
Q_DECLARE_METATYPE(TextEditor::TypingSettings)
#endif // TYPINGSETTINGS_H