2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-08 16:11:26 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-11-08 16:11:26 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-08 16:11:26 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-11-08 16:11:26 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 17:14:20 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-08 16:11:26 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
#include "texteditor_global.h"
|
2017-07-17 12:41:37 +02:00
|
|
|
#include "tabsettings.h"
|
2010-11-08 16:11:26 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QString>
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QTextCursor;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
class TEXTEDITOR_EXPORT AutoCompleter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AutoCompleter();
|
|
|
|
|
virtual ~AutoCompleter();
|
|
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
void setAutoInsertBracketsEnabled(bool b) { m_autoInsertBrackets = b; }
|
|
|
|
|
bool isAutoInsertBracketsEnabled() const { return m_autoInsertBrackets; }
|
|
|
|
|
void setSurroundWithBracketsEnabled(bool b) { m_surroundWithBrackets = b; }
|
|
|
|
|
bool isSurroundWithBracketsEnabled() const { return m_surroundWithBrackets; }
|
2010-11-30 14:14:33 +01:00
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
void setAutoInsertQuotesEnabled(bool b) { m_autoInsertQuotes = b; }
|
|
|
|
|
bool isAutoInsertQuotesEnabled() const { return m_autoInsertQuotes; }
|
|
|
|
|
void setSurroundWithQuotesEnabled(bool b) { m_surroundWithQuotes = b; }
|
|
|
|
|
bool isSurroundWithQuotesEnabled() const { return m_surroundWithQuotes; }
|
2010-11-30 14:14:33 +01:00
|
|
|
|
2017-07-17 12:41:37 +02:00
|
|
|
void setTabSettings(const TabSettings &tabSettings) { m_tabSettings = tabSettings; }
|
|
|
|
|
const TabSettings &tabSettings() const { return m_tabSettings; }
|
|
|
|
|
|
2010-11-30 14:14:33 +01:00
|
|
|
// Returns the text to complete at the cursor position, or an empty string
|
2016-06-10 15:13:38 +02:00
|
|
|
virtual QString autoComplete(QTextCursor &cursor, const QString &text, bool skipChars) const;
|
2010-11-30 14:14:33 +01:00
|
|
|
|
|
|
|
|
// Handles backspace. When returning true, backspace processing is stopped
|
|
|
|
|
virtual bool autoBackspace(QTextCursor &cursor);
|
|
|
|
|
|
|
|
|
|
// Hook to insert special characters on enter. Returns the number of extra blocks inserted.
|
2017-07-17 12:41:37 +02:00
|
|
|
virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
|
2010-11-30 14:14:33 +01:00
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
virtual bool contextAllowsAutoBrackets(const QTextCursor &cursor,
|
2010-11-30 14:14:33 +01:00
|
|
|
const QString &textToInsert = QString()) const;
|
2016-04-14 09:00:05 +02:00
|
|
|
virtual bool contextAllowsAutoQuotes(const QTextCursor &cursor,
|
|
|
|
|
const QString &textToInsert = QString()) const;
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
// Returns true if the cursor is inside a comment.
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual bool isInComment(const QTextCursor &cursor) const;
|
|
|
|
|
|
2014-09-29 18:19:38 +02:00
|
|
|
// Returns true if the cursor is inside a string.
|
|
|
|
|
virtual bool isInString(const QTextCursor &cursor) const;
|
|
|
|
|
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual QString insertMatchingBrace(const QTextCursor &cursor, const
|
|
|
|
|
QString &text,
|
2016-06-10 15:13:38 +02:00
|
|
|
QChar lookAhead, bool skipChars,
|
2016-04-14 09:00:05 +02:00
|
|
|
int *skippedChars) const;
|
|
|
|
|
|
|
|
|
|
virtual QString insertMatchingQuote(const QTextCursor &cursor, const
|
|
|
|
|
QString &text,
|
2016-06-10 15:13:38 +02:00
|
|
|
QChar lookAhead, bool skipChars,
|
2010-11-30 14:14:33 +01:00
|
|
|
int *skippedChars) const;
|
2010-11-08 16:11:26 +01:00
|
|
|
|
|
|
|
|
// Returns the text that needs to be inserted
|
2010-11-30 14:14:33 +01:00
|
|
|
virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
|
|
|
|
|
|
2016-04-14 09:00:05 +02:00
|
|
|
static bool isQuote(const QString &text);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString replaceSelection(QTextCursor &cursor, const QString &textToInsert) const;
|
|
|
|
|
|
2010-11-08 16:11:26 +01:00
|
|
|
private:
|
2017-07-17 12:41:37 +02:00
|
|
|
TabSettings m_tabSettings;
|
2010-11-30 14:14:33 +01:00
|
|
|
mutable bool m_allowSkippingOfBlockEnd;
|
2016-04-14 09:00:05 +02:00
|
|
|
bool m_autoInsertBrackets;
|
|
|
|
|
bool m_surroundWithBrackets;
|
|
|
|
|
bool m_autoInsertQuotes;
|
|
|
|
|
bool m_surroundWithQuotes;
|
2010-11-08 16:11:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // TextEditor
|