Commit 7d2a7685 authored by Lorenz Haas's avatar Lorenz Haas Committed by David Schulz

Editor: Show file encoding in editor toolbar

The file encoding is shown next to the current line in the toolbar. If
the label is clicked a dialog for encoding selection is shown.

Task-number: QTCREATORBUG-8376
Change-Id: I9adee76a31929de5f698d14fe5ca5abce3cc4633
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 63a04e0c
......@@ -541,12 +541,18 @@ void BaseTextEditorWidget::selectEncoding()
case CodecSelector::Save:
doc->setCodec(codecSelector.selectedCodec());
Core::EditorManager::instance()->saveEditor(editor());
updateTextCodecLabel();
break;
case CodecSelector::Cancel:
break;
}
}
void BaseTextEditorWidget::updateTextCodecLabel()
{
editor()->setFileEncodingLabelText(QString::fromLatin1(d->m_document->codec()->name()));
}
QString BaseTextEditorWidget::msgTextTooLarge(quint64 size)
{
return tr("The text is too large to be displayed (%1 MB).").
......@@ -584,6 +590,13 @@ bool BaseTextEditorWidget::open(QString *errorString, const QString &fileName, c
if (d->m_document->open(errorString, fileName, realFileName)) {
moveCursor(QTextCursor::Start);
updateCannotDecodeInfo();
if (editor()->m_fileEncodingLabel) {
connect(editor()->m_fileEncodingLabel, SIGNAL(clicked()), this,
SLOT(selectEncoding()), Qt::UniqueConnection);
connect(d->m_document->document(), SIGNAL(modificationChanged(bool)), this,
SLOT(updateTextCodecLabel()), Qt::UniqueConnection);
updateTextCodecLabel();
}
return true;
}
return false;
......@@ -5761,6 +5774,7 @@ void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
setHighlightCurrentLine(ds.m_highlightCurrentLine);
setRevisionsVisible(ds.m_markTextChanges);
setCenterOnScroll(ds.m_centerCursorOnScroll);
editor()->setFileEncodingLabelVisible(ds.m_displayFileEncoding);
if (d->m_displaySettings.m_visualizeWhitespace != ds.m_visualizeWhitespace) {
if (SyntaxHighlighter *highlighter = baseTextDocument()->syntaxHighlighter())
......@@ -6277,6 +6291,9 @@ BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *editor)
const int spacing = editor->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2;
m_cursorPositionLabel->setContentsMargins(spacing, 0, spacing, 0);
m_fileEncodingLabel = new Utils::LineColumnLabel;
m_fileEncodingLabel->setContentsMargins(spacing, 0, spacing, 0);
m_stretchWidget = new QWidget;
m_stretchWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
......@@ -6284,7 +6301,9 @@ BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *editor)
m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
m_toolBar->addWidget(m_stretchWidget);
m_cursorPositionLabelAction = m_toolBar->addWidget(m_cursorPositionLabel);
m_fileEncodingLabelAction = m_toolBar->addWidget(m_fileEncodingLabel);
setFileEncodingLabelVisible(editor->displaySettings().m_displayFileEncoding);
connect(editor, SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()));
connect(m_cursorPositionLabel, SIGNAL(clicked()), this, SLOT(openGotoLocator()));
}
......@@ -6432,11 +6451,21 @@ void BaseTextEditor::openGotoLocator()
}
}
void BaseTextEditor::setFileEncodingLabelVisible(bool visible)
{
m_fileEncodingLabelAction->setVisible(visible);
}
void BaseTextEditor::setFileEncodingLabelText(const QString &text)
{
m_fileEncodingLabel->setText(text, text);
}
QString BaseTextEditor::contextHelpId() const
{
if (m_contextHelpId.isEmpty())
emit const_cast<BaseTextEditor*>(this)->contextHelpIdRequested(e->editor(),
e->textCursor().position());
e->textCursor().position());
return m_contextHelpId;
}
......
......@@ -279,6 +279,7 @@ public slots:
void fold();
void unfold();
void selectEncoding();
void updateTextCodecLabel();
void gotoBlockStart();
void gotoBlockEnd();
......@@ -673,6 +674,8 @@ public:
private slots:
void updateCursorPosition();
void openGotoLocator();
void setFileEncodingLabelVisible(bool visible);
void setFileEncodingLabelText(const QString &text);
private:
BaseTextEditorWidget *e;
......@@ -680,6 +683,8 @@ private:
QWidget *m_stretchWidget;
QAction *m_cursorPositionLabelAction;
Utils::LineColumnLabel *m_cursorPositionLabel;
QAction *m_fileEncodingLabelAction;
Utils::LineColumnLabel *m_fileEncodingLabel;
};
} // namespace TextEditor
......
......@@ -46,6 +46,7 @@ static const char markTextChangesKey[] = "MarkTextChanges";
static const char autoFoldFirstCommentKey[] = "AutoFoldFirstComment";
static const char centerCursorOnScrollKey[] = "CenterCursorOnScroll";
static const char openLinksInNextSplitKey[] = "OpenLinksInNextSplitKey";
static const char displayFileEncodingKey[] = "DisplayFileEncoding";
static const char groupPostfix[] = "DisplaySettings";
namespace TextEditor {
......@@ -65,7 +66,8 @@ DisplaySettings::DisplaySettings() :
m_autoFoldFirstComment(true),
m_centerCursorOnScroll(false),
m_openLinksInNextSplit(false),
m_forceOpenLinksInNextSplit(false)
m_forceOpenLinksInNextSplit(false),
m_displayFileEncoding(false)
{
}
......@@ -89,6 +91,7 @@ void DisplaySettings::toSettings(const QString &category, QSettings *s) const
s->setValue(QLatin1String(autoFoldFirstCommentKey), m_autoFoldFirstComment);
s->setValue(QLatin1String(centerCursorOnScrollKey), m_centerCursorOnScroll);
s->setValue(QLatin1String(openLinksInNextSplitKey), m_openLinksInNextSplit);
s->setValue(QLatin1String(displayFileEncodingKey), m_displayFileEncoding);
s->endGroup();
}
......@@ -115,6 +118,7 @@ void DisplaySettings::fromSettings(const QString &category, const QSettings *s)
m_autoFoldFirstComment = s->value(group + QLatin1String(autoFoldFirstCommentKey), m_autoFoldFirstComment).toBool();
m_centerCursorOnScroll = s->value(group + QLatin1String(centerCursorOnScrollKey), m_centerCursorOnScroll).toBool();
m_openLinksInNextSplit = s->value(group + QLatin1String(openLinksInNextSplitKey), m_openLinksInNextSplit).toBool();
m_displayFileEncoding = s->value(group + QLatin1String(displayFileEncodingKey), m_displayFileEncoding).toBool();
}
bool DisplaySettings::equals(const DisplaySettings &ds) const
......@@ -134,6 +138,7 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const
&& m_centerCursorOnScroll == ds.m_centerCursorOnScroll
&& m_openLinksInNextSplit == ds.m_openLinksInNextSplit
&& m_forceOpenLinksInNextSplit == ds.m_forceOpenLinksInNextSplit
&& m_displayFileEncoding == ds.m_displayFileEncoding
;
}
......
......@@ -61,6 +61,7 @@ public:
bool m_centerCursorOnScroll;
bool m_openLinksInNextSplit;
bool m_forceOpenLinksInNextSplit;
bool m_displayFileEncoding;
bool equals(const DisplaySettings &ds) const;
};
......
......@@ -85,7 +85,8 @@ QWidget *DisplaySettingsPage::createPage(QWidget *parent)
<< ' ' << d->m_page->enableTextWrapping->text()
<< ' ' << d->m_page->autoFoldFirstComment->text()
<< ' ' << d->m_page->centerOnScroll->text()
<< ' ' << d->m_page->openLinksInNextSplit->text();
<< ' ' << d->m_page->openLinksInNextSplit->text()
<< ' ' << d->m_page->displayFileEncoding->text();
d->m_searchKeywords.remove(QLatin1Char('&'));
}
return w;
......@@ -125,6 +126,7 @@ void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings) const
displaySettings.m_autoFoldFirstComment = d->m_page->autoFoldFirstComment->isChecked();
displaySettings.m_centerCursorOnScroll = d->m_page->centerOnScroll->isChecked();
displaySettings.m_openLinksInNextSplit = d->m_page->openLinksInNextSplit->isChecked();
displaySettings.m_displayFileEncoding = d->m_page->displayFileEncoding->isChecked();
}
void DisplaySettingsPage::settingsToUI()
......@@ -144,6 +146,7 @@ void DisplaySettingsPage::settingsToUI()
d->m_page->autoFoldFirstComment->setChecked(displaySettings.m_autoFoldFirstComment);
d->m_page->centerOnScroll->setChecked(displaySettings.m_centerCursorOnScroll);
d->m_page->openLinksInNextSplit->setChecked(displaySettings.m_openLinksInNextSplit);
d->m_page->displayFileEncoding->setChecked(displaySettings.m_displayFileEncoding);
}
const DisplaySettings &DisplaySettingsPage::displaySettings() const
......
......@@ -160,6 +160,13 @@
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="displayFileEncoding">
<property name="text">
<string>Display file encoding</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......
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