Commit df99d544 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Initial work on "Quick Fix".

parent 22551cff
......@@ -561,6 +561,11 @@ void BaseTextEditor::triggerCompletions()
emit requestAutoCompletion(editableInterface(), true);
}
void BaseTextEditor::triggerQuickFix()
{
emit requestQuickFix(editableInterface());
}
bool BaseTextEditor::createNew(const QString &contents)
{
setPlainText(contents);
......
......@@ -310,6 +310,7 @@ public:
ITextMarkable *markableInterface() const;
virtual void triggerCompletions();
virtual void triggerQuickFix();
QChar characterAt(int pos) const;
......@@ -512,6 +513,7 @@ protected slots:
signals:
void requestBlockUpdate(const QTextBlock &);
void requestAutoCompletion(ITextEditable *editor, bool forced);
void requestQuickFix(ITextEditable *editor);
private:
void indentOrUnindent(bool doIndent);
......@@ -586,6 +588,8 @@ public:
inline QChar characterAt(int pos) const { return e->characterAt(pos); }
inline void triggerCompletions() { e->triggerCompletions(); } // slot?
inline void triggerQuickFix() { e->triggerQuickFix(); } // slot?
inline ITextMarkable *markableInterface() { return e->markableInterface(); }
void setContextHelpId(const QString &id) { m_contextHelpId = id; }
......
......@@ -90,11 +90,28 @@ void CompletionSupport::cleanupCompletions()
}
void CompletionSupport::autoComplete(ITextEditable *editor, bool forced)
{
autoComplete_helper(editor, forced, /*quickFix = */ false);
}
void CompletionSupport::quickFix(ITextEditable *editor)
{
qDebug() << Q_FUNC_INFO;
autoComplete_helper(editor,
/*forced = */ true,
/*quickFix = */ true);
}
void CompletionSupport::autoComplete_helper(ITextEditable *editor, bool forced,
bool quickFix)
{
m_completionCollector = 0;
foreach (ICompletionCollector *collector, m_completionCollectors) {
if (collector->supportsEditor(editor)) {
if (quickFix)
collector = qobject_cast<IQuickFixCollector *>(collector);
if (collector && collector->supportsEditor(editor)) {
m_completionCollector = collector;
break;
}
......@@ -121,6 +138,7 @@ void CompletionSupport::autoComplete(ITextEditable *editor, bool forced)
}
m_completionList = new CompletionWidget(this, editor);
m_completionList->setQuickFix(quickFix);
connect(m_completionList, SIGNAL(itemSelected(TextEditor::CompletionItem)),
this, SLOT(performCompletion(TextEditor::CompletionItem)));
......
......@@ -57,6 +57,7 @@ public:
static CompletionSupport *instance();
public slots:
void autoComplete(ITextEditable *editor, bool forced);
void quickFix(ITextEditable *editor);
private slots:
void performCompletion(const TextEditor::CompletionItem &item);
......@@ -64,6 +65,7 @@ private slots:
private:
QList<CompletionItem> getCompletions() const;
void autoComplete_helper(ITextEditable *editor, bool forced, bool quickFix);
CompletionWidget *m_completionList;
int m_startPosition;
......
......@@ -100,6 +100,7 @@ QVariant AutoCompletionModel::data(const QModelIndex &index, int role) const
CompletionWidget::CompletionWidget(CompletionSupport *support, ITextEditable *editor)
: QListView(),
m_blockFocusOut(false),
m_quickFix(false),
m_editor(editor),
m_editorWidget(editor->widget()),
m_model(0),
......@@ -165,7 +166,7 @@ bool CompletionWidget::event(QEvent *e)
break;
}
if (forwardKeys) {
if (forwardKeys && ! m_quickFix) {
m_blockFocusOut = true;
QApplication::sendEvent(m_editorWidget, e);
m_blockFocusOut = false;
......@@ -201,6 +202,11 @@ void CompletionWidget::closeList(const QModelIndex &index)
m_blockFocusOut = false;
}
void CompletionWidget::setQuickFix(bool quickFix)
{
m_quickFix = quickFix;
}
void CompletionWidget::setCompletionItems(const QList<TextEditor::CompletionItem> &completionItems)
{
if (!m_model) {
......
......@@ -54,6 +54,7 @@ class CompletionWidget : public QListView
public:
CompletionWidget(CompletionSupport *support, ITextEditable *editor);
void setQuickFix(bool quickFix);
void setCompletionItems(const QList<TextEditor::CompletionItem> &completionitems);
void showCompletions(int startPos);
void keyboardSearch(const QString &search);
......@@ -74,6 +75,7 @@ private:
QPointer<QFrame> m_popupFrame;
bool m_blockFocusOut;
bool m_quickFix;
ITextEditable *m_editor;
QWidget *m_editorWidget;
AutoCompletionModel *m_model;
......
......@@ -113,6 +113,19 @@ public:
virtual void cleanup() = 0;
};
class TEXTEDITOR_EXPORT IQuickFixCollector : public ICompletionCollector
{
Q_OBJECT
public:
IQuickFixCollector(QObject *parent = 0) : ICompletionCollector(parent) {}
virtual ~IQuickFixCollector() {}
virtual bool partiallyComplete(const QList<TextEditor::CompletionItem> &)
{ return false; }
};
} // namespace TextEditor
#endif // COMPLETIONCOLLECTORINTERFACE_H
......@@ -109,6 +109,7 @@ public:
virtual QChar characterAt(int pos) const = 0;
virtual void triggerCompletions() = 0;
virtual void triggerQuickFix() = 0;
virtual ITextMarkable *markableInterface() = 0;
......
......@@ -35,6 +35,7 @@ namespace Constants {
const char * const C_TEXTEDITOR = "Text Editor";
const char * const COMPLETE_THIS = "TextEditor.CompleteThis";
const char * const QUICKFIX_THIS = "TextEditor.QuickFix";
const char * const VISUALIZE_WHITESPACE = "TextEditor.VisualizeWhitespace";
const char * const CLEAN_WHITESPACE = "TextEditor.CleanWhitespace";
const char * const TEXT_WRAPPING = "TextEditor.TextWrapping";
......
......@@ -131,6 +131,13 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
#endif
connect(completionShortcut, SIGNAL(activated()), this, SLOT(invokeCompletion()));
// Add shortcut for invoking automatic completion
QShortcut *quickFixShortcut = new QShortcut(core->mainWindow());
quickFixShortcut->setWhatsThis(tr("Triggers a quick fix in this scope"));
// Make sure the shortcut still works when the quick fix widget is active
quickFixShortcut->setContext(Qt::ApplicationShortcut);
Core::Command *quickFixCommand = am->registerShortcut(quickFixShortcut, Constants::QUICKFIX_THIS, context);
connect(quickFixShortcut, SIGNAL(activated()), this, SLOT(invokeQuickFix()));
return true;
}
......@@ -168,6 +175,14 @@ void TextEditorPlugin::invokeCompletion()
editor->triggerCompletions();
}
void TextEditorPlugin::invokeQuickFix()
{
Core::IEditor *iface = Core::EditorManager::instance()->currentEditor();
ITextEditor *editor = qobject_cast<ITextEditor *>(iface);
if (editor)
editor->triggerQuickFix();
}
void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings)
{
if (m_searchResultWindow)
......
......@@ -69,6 +69,7 @@ public:
private slots:
void invokeCompletion();
void invokeQuickFix();
void updateSearchResultsFont(const TextEditor::FontSettings &);
private:
......
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