Commit 012ff2d2 authored by Yuchen Deng's avatar Yuchen Deng Committed by Eike Ziller

Editor: Add feature for set/unset UTF-8 BOM

Change-Id: Iec7e36b1d7a526d7fa8a8096110b91f9c4cc44f9
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent a2d3d7f3
......@@ -140,6 +140,13 @@ void TextDocument::setCodec(const QTextCodec *codec)
d->m_format.codec = codec;
}
void TextDocument::switchUtf8Bom()
{
if (debug)
qDebug() << Q_FUNC_INFO << this << "UTF-8 BOM: " << !d->m_format.hasUtf8Bom;
d->m_format.hasUtf8Bom = !d->m_format.hasUtf8Bom;
}
/*!
\brief Returns the format obtained from the last call to read().
*/
......
......@@ -55,6 +55,7 @@ public:
Utils::TextFileFormat format() const;
const QTextCodec *codec() const;
void setCodec(const QTextCodec *);
void switchUtf8Bom();
ReadResult read(const QString &fileName, QStringList *plainTextList, QString *errorString);
ReadResult read(const QString &fileName, QString *plainText, QString *errorString);
......
......@@ -5838,6 +5838,11 @@ void BaseTextEditorWidget::circularPaste()
QPlainTextEdit::copy();
}
void BaseTextEditorWidget::switchUtf8bom()
{
baseTextDocument()->switchUtf8Bom();
}
QMimeData *BaseTextEditorWidget::createMimeDataFromSelection() const
{
if (d->m_inBlockSelectionMode) {
......@@ -6087,6 +6092,17 @@ void BaseTextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
a = am->command(Constants::CIRCULAR_PASTE)->action();
if (a && a->isEnabled())
menu->addAction(a);
BaseTextDocument *doc = baseTextDocument();
if (doc->codec()->name() == QString(QLatin1String("UTF-8"))) {
a = am->command(Constants::SWITCH_UTF8BOM)->action();
if (a && a->isEnabled()) {
a->setText(doc->format().hasUtf8Bom ? tr("Delete UTF-8 BOM on Save")
: tr("Add UTF-8 BOM on Save"));
menu->addSeparator();
menu->addAction(a);
}
}
}
......
......@@ -260,6 +260,7 @@ public slots:
virtual void selectAll();
void circularPaste();
void switchUtf8bom();
void zoomIn(int range = 1);
void zoomOut(int range = 1);
......
......@@ -65,6 +65,7 @@ TextEditorActionHandler::TextEditorActionHandler(const char *context,
m_cutAction(0),
m_pasteAction(0),
m_circularPasteAction(0),
m_switchUtf8bomAction(0),
m_selectAllAction(0),
m_gotoAction(0),
m_printAction(0),
......@@ -379,6 +380,11 @@ void TextEditorActionHandler::createActions()
connect(m_circularPasteAction, SIGNAL(triggered()), this, SLOT(circularPasteAction()));
medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
m_switchUtf8bomAction = new QAction(this);
m_modifyingActions << m_switchUtf8bomAction;
command = am->registerAction(m_switchUtf8bomAction, Constants::SWITCH_UTF8BOM, m_contextId, true);
connect(m_switchUtf8bomAction, SIGNAL(triggered()), this, SLOT(switchUtf8bomAction()));
m_indentAction = new QAction(tr("Indent"), this);
m_modifyingActions << m_indentAction;
command = am->registerAction(m_indentAction, Constants::INDENT, m_contextId, true);
......@@ -589,6 +595,7 @@ FUNCTION2(copyAction, copy)
FUNCTION2(cutAction, cut)
FUNCTION2(pasteAction, paste)
FUNCTION2(circularPasteAction, circularPaste)
FUNCTION2(switchUtf8bomAction, switchUtf8bom)
FUNCTION2(formatAction, format)
FUNCTION2(rewrapParagraphAction, rewrapParagraph)
FUNCTION2(selectAllAction, selectAll)
......
......@@ -99,6 +99,7 @@ private slots:
void cutAction();
void pasteAction();
void circularPasteAction();
void switchUtf8bomAction();
void selectAllAction();
void gotoAction();
void printAction();
......@@ -170,6 +171,7 @@ private:
QAction *m_cutAction;
QAction *m_pasteAction;
QAction *m_circularPasteAction;
QAction *m_switchUtf8bomAction;
QAction *m_selectAllAction;
QAction *m_gotoAction;
QAction *m_printAction;
......
......@@ -102,6 +102,7 @@ const char TASK_DOWNLOAD_DEFINITIONS[] = "TextEditor.Task.Download";
const char TASK_REGISTER_DEFINITIONS[] = "TextEditor.Task.Register";
const char TASK_OPEN_FILE[] = "TextEditor.Task.OpenFile";
const char CIRCULAR_PASTE[] = "TextEditor.CircularPaste";
const char SWITCH_UTF8BOM[] = "TextEditor.SwitchUtf8bom";
const char INDENT[] = "TextEditor.Indent";
const char UNINDENT[] = "TextEditor.Unindent";
......
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