Commit 014efbda authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Submit editor: Use config font settings, add simple highlighting for git

parent 10ffdd5d
......@@ -156,9 +156,6 @@ SubmitEditorWidget::SubmitEditorWidget(QWidget *parent) :
connect(m_d->m_ui.fileView, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(diffActivated(QModelIndex)));
// Text
m_d->m_ui.description->setFont(QFont(QLatin1String("Courier")));
setFocusPolicy(Qt::StrongFocus);
setFocusProxy(m_d->m_ui.description);
}
......
......@@ -30,15 +30,92 @@
#include "gitsubmiteditorwidget.h"
#include "commitdata.h"
#include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorconstants.h>
#include <QtGui/QSyntaxHighlighter>
#include <QtGui/QTextEdit>
#include <QtCore/QDebug>
#include <QtCore/QRegExp>
namespace Git {
namespace Internal {
// Retrieve the comment char format from the text editor.
static QTextCharFormat commentFormat()
{
const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings();
return settings.toTextCharFormat(QLatin1String(TextEditor::Constants::C_COMMENT));
}
// Highlighter for git submit messages. Make the first line bold, indicates
// comments as such (retrieving the format from the text editor) and marks up
// keywords (words in front of a colon as in 'Task: <bla>').
class GitSubmitHighlighter : QSyntaxHighlighter {
public:
explicit GitSubmitHighlighter(QTextEdit *parent);
virtual void highlightBlock(const QString &text);
private:
enum State { Header, Comment, Other };
const QTextCharFormat m_commentFormat;
const QRegExp m_keywordPattern;
const QChar m_hashChar;
};
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
QSyntaxHighlighter(parent),
m_commentFormat(commentFormat()),
m_keywordPattern(QLatin1String("^\\w+:")),
m_hashChar(QLatin1Char('#'))
{
Q_ASSERT(m_keywordPattern.isValid());
}
void GitSubmitHighlighter::highlightBlock(const QString &text)
{
// figure out current state
State state = Other;
const QTextBlock block = currentBlock();
if (block.position() == 0) {
state = Header;
} else {
if (text.startsWith(m_hashChar))
state = Comment;
}
// Apply format.
switch (state) {
case Header: {
QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
}
break;
case Comment:
setFormat(0, text.size(), m_commentFormat);
break;
case Other:
// Format key words ("Task:") italic
if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) {
QTextCharFormat charFormat = format(0);
charFormat.setFontItalic(true);
setFormat(0, m_keywordPattern.matchedLength(), charFormat);
}
break;
}
}
// ------------------
GitSubmitEditorWidget::GitSubmitEditorWidget(QWidget *parent) :
Core::Utils::SubmitEditorWidget(parent),
m_gitSubmitPanel(new QWidget)
{
m_gitSubmitPanelUi.setupUi(m_gitSubmitPanel);
insertTopWidget(m_gitSubmitPanel);
new GitSubmitHighlighter(descriptionEdit());
}
void GitSubmitEditorWidget::setPanelInfo(const GitSubmitEditorPanelInfo &info)
......
......@@ -41,6 +41,8 @@
#include <utils/submiteditorwidget.h>
#include <utils/submitfieldwidget.h>
#include <find/basetextfind.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
......@@ -107,6 +109,13 @@ VCSBaseSubmitEditor::VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *pa
Core::Utils::SubmitEditorWidget *editorWidget) :
m_d(new VCSBaseSubmitEditorPrivate(parameters, editorWidget, this))
{
// message font according to settings
const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::instance()->fontSettings();
QFont font = editorWidget->descriptionEdit()->font();
font.setFamily(fs.family());
font.setPointSize((fs.fontSize() * 4) / 5);
editorWidget->descriptionEdit()->setFont(font);
m_d->m_file->setModified(false);
// We are always clean to prevent the editor manager from asking to save.
connect(m_d->m_file, SIGNAL(saveMe(QString)), this, SLOT(save(QString)));
......
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