Commit 61325aae authored by Leandro Melo's avatar Leandro Melo Committed by Leandro T. C. Melo

Editors: Make snippets and code style honor font settings

Task-number: QTCREATORBUG-5007

Change-Id: Ied78ef17ea7a25d22c37d36fd4eb7257c6c9f4c0
Reviewed-on: http://codereview.qt.nokia.com/293Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent 7ccfe19d
......@@ -191,19 +191,10 @@ CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
m_previews[i]->setPlainText(defaultCodeStyleSnippets[i]);
}
const QList<ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::instance()->getObjects<ISnippetProvider>();
foreach (ISnippetProvider *provider, providers) {
if (provider->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID)) {
foreach (TextEditor::SnippetEditorWidget *preview, m_previews)
provider->decorateEditor(preview);
break;
}
}
TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
setFontSettings(settings->fontSettings());
decorateEditors(settings->fontSettings());
connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
this, SLOT(setFontSettings(TextEditor::FontSettings)));
this, SLOT(decorateEditors(TextEditor::FontSettings)));
setVisualizeWhitespace(true);
......@@ -420,10 +411,23 @@ void CppCodeStylePreferencesWidget::updatePreview()
}
}
void CppCodeStylePreferencesWidget::setFontSettings(const TextEditor::FontSettings &fontSettings)
void CppCodeStylePreferencesWidget::decorateEditors(const TextEditor::FontSettings &fontSettings)
{
foreach (TextEditor::SnippetEditorWidget *editor, m_previews)
editor->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(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID)) {
provider = current;
break;
}
}
foreach (TextEditor::SnippetEditorWidget *editor, m_previews) {
editor->setFontSettings(fontSettings);
if (provider)
provider->decorateEditor(editor);
}
}
void CppCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
......
......@@ -44,7 +44,7 @@ public:
QString searchKeywords() const;
private slots:
void setFontSettings(const TextEditor::FontSettings &fontSettings);
void decorateEditors(const TextEditor::FontSettings &fontSettings);
void setVisualizeWhitespace(bool on);
void slotCppCodeStyleSettingsChanged();
void slotSettingsChanged();
......
......@@ -40,6 +40,8 @@
#include "ui_snippetssettingspage.h"
#include <coreplugin/icore.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h>
#include <extensionsystem/pluginmanager.h>
#include <QtCore/QModelIndex>
......@@ -290,6 +292,7 @@ private slots:
void selectMovedSnippet(const QModelIndex &, int, int, const QModelIndex &, int row);
void setSnippetContent();
void updateCurrentSnippetDependent(const QModelIndex &modelIndex = QModelIndex());
void decorateEditors(const TextEditor::FontSettings &fontSettings);
private:
SnippetEditorWidget *currentEditor() const;
......@@ -336,6 +339,7 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
foreach (ISnippetProvider *provider, providers) {
m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
SnippetEditorWidget *snippetEditor = new SnippetEditorWidget(w);
snippetEditor->setFontSettings(TextEditorSettings::instance()->fontSettings());
provider->decorateEditor(snippetEditor);
m_ui.snippetsEditorStack->insertWidget(m_ui.groupCombo->count() - 1, snippetEditor);
connect(snippetEditor, SIGNAL(snippetContentChanged()), this, SLOT(setSnippetContent()));
......@@ -380,6 +384,9 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
connect(m_ui.revertButton, SIGNAL(clicked()), this, SLOT(revertBuiltInSnippet()));
connect(m_ui.snippetsTable->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(updateCurrentSnippetDependent(QModelIndex)));
connect(TextEditorSettings::instance(), SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
this, SLOT(decorateEditors(TextEditor::FontSettings)));
}
void SnippetsSettingsPagePrivate::apply()
......@@ -536,6 +543,22 @@ void SnippetsSettingsPagePrivate::setSnippetContent()
}
}
void SnippetsSettingsPagePrivate::decorateEditors(const TextEditor::FontSettings &fontSettings)
{
const QList<ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::instance()->getObjects<ISnippetProvider>();
for (int i = 0; i < m_ui.groupCombo->count(); ++i) {
SnippetEditorWidget *snippetEditor = editorAt(i);
snippetEditor->setFontSettings(fontSettings);
const QString &id = m_ui.groupCombo->itemData(i).toString();
// This list should be quite short... Re-iterating over it is ok.
foreach (const ISnippetProvider *provider, providers) {
if (provider->groupId() == id)
provider->decorateEditor(snippetEditor);
}
}
}
// SnippetsSettingsPage
SnippetsSettingsPage::SnippetsSettingsPage(const QString &id, QObject *parent) :
TextEditorOptionsPage(parent),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment