forked from qt-creator/qt-creator
TextEditor: Fix default context menu
Text editor implementations that did not do anything special with invoking their context menu, including our plain text editor, only had Qt's default context menu, without Qt Creator's clipboard history and BOM actions. Make the default actions in our custom context menu more similar to Qt's default actions by adding Undo, Redo and Select All, and not hiding disabled actions, and use that by default in all text editor implementations. Change-Id: Idd5fb276dcd652223d96536dacde8110f9eb576f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3001,6 +3001,11 @@ bool TextEditorWidget::event(QEvent *e)
|
|||||||
return QPlainTextEdit::event(e);
|
return QPlainTextEdit::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
||||||
|
{
|
||||||
|
showDefaultContextMenu(e, Id());
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidget::inputMethodEvent(QInputMethodEvent *e)
|
void TextEditorWidget::inputMethodEvent(QInputMethodEvent *e)
|
||||||
{
|
{
|
||||||
if (e->commitString().isEmpty() && e->preeditString().isEmpty() && e->attributes().isEmpty()) {
|
if (e->commitString().isEmpty() && e->preeditString().isEmpty() && e->attributes().isEmpty()) {
|
||||||
@@ -5662,6 +5667,7 @@ static void appendMenuActionsFromContext(QMenu *menu, Id menuContextId)
|
|||||||
void TextEditorWidget::showDefaultContextMenu(QContextMenuEvent *e, Id menuContextId)
|
void TextEditorWidget::showDefaultContextMenu(QContextMenuEvent *e, Id menuContextId)
|
||||||
{
|
{
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
|
if (menuContextId.isValid())
|
||||||
appendMenuActionsFromContext(&menu, menuContextId);
|
appendMenuActionsFromContext(&menu, menuContextId);
|
||||||
appendStandardContextMenuActions(&menu);
|
appendStandardContextMenuActions(&menu);
|
||||||
menu.exec(e->globalPos());
|
menu.exec(e->globalPos());
|
||||||
@@ -7756,24 +7762,26 @@ void TextEditorWidget::setupFallBackEditor(Id id)
|
|||||||
void TextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
|
void TextEditorWidget::appendStandardContextMenuActions(QMenu *menu)
|
||||||
{
|
{
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
const auto add = [menu](const Id &id) {
|
||||||
|
QAction *a = ActionManager::command(id)->action();
|
||||||
|
if (a)
|
||||||
|
menu->addAction(a);
|
||||||
|
};
|
||||||
|
|
||||||
QAction *a = ActionManager::command(Core::Constants::CUT)->action();
|
add(Core::Constants::UNDO);
|
||||||
if (a && a->isEnabled())
|
add(Core::Constants::REDO);
|
||||||
menu->addAction(a);
|
menu->addSeparator();
|
||||||
a = ActionManager::command(Core::Constants::COPY)->action();
|
add(Core::Constants::CUT);
|
||||||
if (a && a->isEnabled())
|
add(Core::Constants::COPY);
|
||||||
menu->addAction(a);
|
add(Core::Constants::PASTE);
|
||||||
a = ActionManager::command(Core::Constants::PASTE)->action();
|
add(Constants::CIRCULAR_PASTE);
|
||||||
if (a && a->isEnabled())
|
menu->addSeparator();
|
||||||
menu->addAction(a);
|
add(Core::Constants::SELECTALL);
|
||||||
a = ActionManager::command(Constants::CIRCULAR_PASTE)->action();
|
|
||||||
if (a && a->isEnabled())
|
|
||||||
menu->addAction(a);
|
|
||||||
|
|
||||||
TextDocument *doc = textDocument();
|
TextDocument *doc = textDocument();
|
||||||
if (doc->codec()->name() == QByteArray("UTF-8") && doc->supportsUtf8Bom()) {
|
if (doc->codec()->name() == QByteArray("UTF-8") && doc->supportsUtf8Bom()) {
|
||||||
a = ActionManager::command(Constants::SWITCH_UTF8BOM)->action();
|
QAction *a = ActionManager::command(Constants::SWITCH_UTF8BOM)->action();
|
||||||
if (a && a->isEnabled()) {
|
if (a) {
|
||||||
a->setText(doc->format().hasUtf8Bom ? tr("Delete UTF-8 BOM on Save")
|
a->setText(doc->format().hasUtf8Bom ? tr("Delete UTF-8 BOM on Save")
|
||||||
: tr("Add UTF-8 BOM on Save"));
|
: tr("Add UTF-8 BOM on Save"));
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|||||||
@@ -476,6 +476,7 @@ protected:
|
|||||||
QTextBlock blockForVisibleRow(int row) const;
|
QTextBlock blockForVisibleRow(int row) const;
|
||||||
QTextBlock blockForVerticalOffset(int offset) const;
|
QTextBlock blockForVerticalOffset(int offset) const;
|
||||||
bool event(QEvent *e) override;
|
bool event(QEvent *e) override;
|
||||||
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||||
void inputMethodEvent(QInputMethodEvent *e) override;
|
void inputMethodEvent(QInputMethodEvent *e) override;
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
void wheelEvent(QWheelEvent *e) override;
|
void wheelEvent(QWheelEvent *e) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user