forked from qt-creator/qt-creator
QmlDesigner: Enable searching in the text editor
Also hide the bottom status bar when it is empty. Task-number: QDS-6187 Change-Id: I053771243c268ea20df8e127831b789b854021aa Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -81,7 +81,7 @@ TextEditorView::TextEditorView(QObject *parent)
|
||||
Core::Command *command = Core::ActionManager::registerAction(completionAction, TextEditor::Constants::COMPLETE_THIS, context);
|
||||
command->setDefaultKeySequence(QKeySequence(Core::useMacShortcuts ? tr("Meta+Space") : tr("Ctrl+Space")));
|
||||
|
||||
connect(completionAction, &QAction::triggered, [this]() {
|
||||
connect(completionAction, &QAction::triggered, this, [this] {
|
||||
if (m_widget->textEditor())
|
||||
m_widget->textEditor()->editorWidget()->invokeAssist(TextEditor::Completion);
|
||||
});
|
||||
@@ -102,13 +102,9 @@ void TextEditorView::modelAttached(Model *model)
|
||||
auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(
|
||||
QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate());
|
||||
|
||||
// Set the context of the text editor, but we add another special context to override shortcuts.
|
||||
Core::Context context = textEditor->context();
|
||||
context.prepend(TEXTEDITOR_CONTEXT_ID);
|
||||
|
||||
/*
|
||||
* Set the context of the text editor, but we add another special context to override shortcuts.
|
||||
*/
|
||||
|
||||
m_textEditorContext->setContext(context);
|
||||
|
||||
m_widget->setTextEditor(textEditor);
|
||||
@@ -272,9 +268,8 @@ void TextEditorView::reformatFile()
|
||||
auto document =
|
||||
qobject_cast<QmlJSEditor::QmlJSEditorDocument *>(Core::EditorManager::currentDocument());
|
||||
|
||||
/* Reformat document if we have a .ui.qml file */
|
||||
if (document
|
||||
&& document->filePath().toString().endsWith(".ui.qml")
|
||||
// Reformat document if we have a .ui.qml file
|
||||
if (document && document->filePath().toString().endsWith(".ui.qml")
|
||||
&& DesignerSettings::getValue(DesignerSettingsKey::REFORMAT_UI_QML_FILES).toBool()) {
|
||||
|
||||
QmlJS::Document::Ptr currentDocument(document->semanticInfo().document);
|
||||
@@ -315,4 +310,3 @@ void TextEditorView::instancePropertyChanged(const QList<QPair<ModelNode, Proper
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
|
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <texteditorstatusbar.h>
|
||||
#include <texteditorview.h>
|
||||
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
#include <rewriterview.h>
|
||||
|
||||
#include <qmldesignerplugin.h>
|
||||
@@ -52,13 +52,17 @@ TextEditorWidget::TextEditorWidget(TextEditorView *textEditorView)
|
||||
: QWidget()
|
||||
, m_textEditorView(textEditorView)
|
||||
, m_statusBar(new TextEditorStatusBar(this))
|
||||
, m_findToolBar(new Core::FindToolBarPlaceHolder(this))
|
||||
, m_layout(new QVBoxLayout(this))
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
QBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
layout->addWidget(m_statusBar);
|
||||
m_statusBar->hide();
|
||||
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_layout->setSpacing(0);
|
||||
m_layout->addWidget(m_statusBar);
|
||||
m_layout->addWidget(m_findToolBar);
|
||||
|
||||
m_updateSelectionTimer.setSingleShot(true);
|
||||
m_updateSelectionTimer.setInterval(200);
|
||||
@@ -72,24 +76,22 @@ void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor)
|
||||
m_textEditor.reset(textEditor);
|
||||
|
||||
if (textEditor) {
|
||||
layout()->removeWidget(m_statusBar);
|
||||
layout()->addWidget(textEditor->editorWidget());
|
||||
layout()->addWidget(m_statusBar);
|
||||
m_layout->insertWidget(0, textEditor->editorWidget());
|
||||
|
||||
setFocusProxy(textEditor->editorWidget());
|
||||
|
||||
QmlDesignerPlugin::instance()->emitCurrentTextEditorChanged(textEditor);
|
||||
|
||||
connect(textEditor->editorWidget(), &QPlainTextEdit::cursorPositionChanged,
|
||||
this, [this]() {
|
||||
/* Cursor position is changed by rewriter */
|
||||
connect(textEditor->editorWidget(), &QPlainTextEdit::cursorPositionChanged, this, [this] {
|
||||
// Cursor position is changed by rewriter
|
||||
if (!m_blockCursorSelectionSynchronisation)
|
||||
m_updateSelectionTimer.start();
|
||||
});
|
||||
|
||||
textEditor->editorWidget()->installEventFilter(this);
|
||||
|
||||
static QString styleSheet = Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(
|
||||
":/qmldesigner/scrollbar.css")));
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
|
||||
textEditor->editorWidget()->verticalScrollBar()->setStyleSheet(styleSheet);
|
||||
textEditor->editorWidget()->horizontalScrollBar()->setStyleSheet(styleSheet);
|
||||
}
|
||||
@@ -105,7 +107,6 @@ void TextEditorWidget::contextHelp(const Core::IContext::HelpCallback &callback)
|
||||
|
||||
void TextEditorWidget::updateSelectionByCursorPosition()
|
||||
{
|
||||
/* Because of the timer we have to be careful. */
|
||||
if (!m_textEditorView->model())
|
||||
return;
|
||||
|
||||
@@ -162,11 +163,13 @@ void TextEditorWidget::gotoCursorPosition(int line, int column)
|
||||
void TextEditorWidget::setStatusText(const QString &text)
|
||||
{
|
||||
m_statusBar->setText(text);
|
||||
m_statusBar->setVisible(!text.isEmpty());
|
||||
}
|
||||
|
||||
void TextEditorWidget::clearStatusBar()
|
||||
{
|
||||
m_statusBar->clearText();
|
||||
m_statusBar->hide();
|
||||
}
|
||||
|
||||
int TextEditorWidget::currentLine() const
|
||||
@@ -199,6 +202,9 @@ bool TextEditorWidget::eventFilter(QObject *, QEvent *event)
|
||||
auto keyEvent = static_cast<QKeyEvent *>(event);
|
||||
|
||||
if (std::find(overrideKeys.begin(), overrideKeys.end(), keyEvent->key()) != overrideKeys.end()) {
|
||||
if (keyEvent->key() == Qt::Key_Escape)
|
||||
m_findToolBar->hide();
|
||||
|
||||
keyEvent->accept();
|
||||
return true;
|
||||
}
|
||||
@@ -208,13 +214,14 @@ bool TextEditorWidget::eventFilter(QObject *, QEvent *event)
|
||||
| Qt::AltModifier
|
||||
| Qt::MetaModifier;
|
||||
|
||||
QKeySequence keySqeuence(keyEvent->key() | (keyEvent->modifiers() & relevantModifiers));
|
||||
for (const QKeySequence &overrideSequence : overrideSequences)
|
||||
const QKeySequence keySqeuence(keyEvent->key() | (keyEvent->modifiers() & relevantModifiers));
|
||||
for (const QKeySequence &overrideSequence : overrideSequences) {
|
||||
if (keySqeuence.matches(overrideSequence)) {
|
||||
keyEvent->accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -26,11 +26,15 @@
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Core {
|
||||
class FindToolBarPlaceHolder;
|
||||
}
|
||||
namespace QmlDesigner {
|
||||
|
||||
class TextEditorView;
|
||||
@@ -72,7 +76,9 @@ private:
|
||||
std::unique_ptr<TextEditor::BaseTextEditor> m_textEditor;
|
||||
QPointer<TextEditorView> m_textEditorView;
|
||||
QTimer m_updateSelectionTimer;
|
||||
TextEditorStatusBar *m_statusBar;
|
||||
TextEditorStatusBar *m_statusBar = nullptr;
|
||||
Core::FindToolBarPlaceHolder *m_findToolBar = nullptr;
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
bool m_blockCursorSelectionSynchronisation = false;
|
||||
bool m_blockRoundTrip = false;
|
||||
};
|
||||
|
Reference in New Issue
Block a user