2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2013-12-11 21:55:45 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Lorenz Haas
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-12-11 21:55:45 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
2013-12-11 21:55:45 +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.
|
2013-12-11 21:55:45 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2013-12-11 21:55:45 +01:00
|
|
|
|
2014-06-26 00:00:08 +02:00
|
|
|
#include "command.h"
|
|
|
|
|
|
2013-12-11 21:55:45 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
|
|
|
|
|
2014-06-26 00:00:08 +02:00
|
|
|
#include <QPlainTextEdit>
|
2014-07-09 14:02:26 +02:00
|
|
|
#include <QPointer>
|
2016-11-02 14:04:40 +01:00
|
|
|
#include <QSharedPointer>
|
2014-06-26 00:00:08 +02:00
|
|
|
|
2015-09-17 21:27:25 +02:00
|
|
|
namespace Core {
|
|
|
|
|
class IDocument;
|
|
|
|
|
class IEditor;
|
|
|
|
|
}
|
|
|
|
|
namespace TextEditor {class TextEditorWidget;}
|
2013-12-11 21:55:45 +01:00
|
|
|
|
|
|
|
|
namespace Beautifier {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class BeautifierAbstractTool;
|
2015-09-17 21:27:25 +02:00
|
|
|
class GeneralSettings;
|
2014-06-26 00:00:08 +02:00
|
|
|
|
|
|
|
|
struct FormatTask
|
|
|
|
|
{
|
|
|
|
|
FormatTask(QPlainTextEdit *_editor, const QString &_filePath, const QString &_sourceData,
|
2015-06-04 17:17:10 +02:00
|
|
|
const Command &_command, int _startPos = -1, int _endPos = 0) :
|
2014-06-26 00:00:08 +02:00
|
|
|
editor(_editor),
|
|
|
|
|
filePath(_filePath),
|
|
|
|
|
sourceData(_sourceData),
|
|
|
|
|
command(_command),
|
2015-06-04 17:17:10 +02:00
|
|
|
startPos(_startPos),
|
2015-09-16 19:17:01 +02:00
|
|
|
endPos(_endPos) {}
|
2014-06-26 00:00:08 +02:00
|
|
|
|
|
|
|
|
QPointer<QPlainTextEdit> editor;
|
|
|
|
|
QString filePath;
|
|
|
|
|
QString sourceData;
|
|
|
|
|
Command command;
|
2016-04-21 21:08:57 +02:00
|
|
|
int startPos = -1;
|
|
|
|
|
int endPos = 0;
|
2015-06-04 17:17:10 +02:00
|
|
|
QString formattedData;
|
2015-09-16 19:17:01 +02:00
|
|
|
QString error;
|
2014-06-26 00:00:08 +02:00
|
|
|
};
|
2013-12-11 21:55:45 +01:00
|
|
|
|
|
|
|
|
class BeautifierPlugin : public ExtensionSystem::IPlugin
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Beautifier.json")
|
|
|
|
|
|
|
|
|
|
public:
|
2015-06-03 15:33:26 +02:00
|
|
|
bool initialize(const QStringList &arguments, QString *errorString) override;
|
|
|
|
|
void extensionsInitialized() override;
|
2013-12-11 21:55:45 +01:00
|
|
|
|
2015-06-04 17:17:10 +02:00
|
|
|
void formatCurrentFile(const Command &command, int startPos = -1, int endPos = 0);
|
2013-12-11 21:55:45 +01:00
|
|
|
|
2014-03-05 14:02:01 +01:00
|
|
|
static QString msgCannotGetConfigurationFile(const QString &command);
|
|
|
|
|
static QString msgFormatCurrentFile();
|
|
|
|
|
static QString msgFormatSelectedText();
|
2017-09-05 09:59:25 +02:00
|
|
|
static QString msgFormatAtCursor();
|
2017-09-04 15:18:42 +02:00
|
|
|
static QString msgDisableFormattingSelectedText();
|
2014-03-05 14:02:01 +01:00
|
|
|
static QString msgCommandPromptDialogTitle(const QString &command);
|
2014-06-26 00:00:08 +02:00
|
|
|
static void showError(const QString &error);
|
|
|
|
|
|
2013-12-11 21:55:45 +01:00
|
|
|
private:
|
2016-04-21 21:08:57 +02:00
|
|
|
void updateActions(Core::IEditor *editor = nullptr);
|
2013-12-11 21:55:45 +01:00
|
|
|
QList<BeautifierAbstractTool *> m_tools;
|
2016-11-02 14:04:40 +01:00
|
|
|
QSharedPointer<GeneralSettings> m_generalSettings;
|
2015-09-17 21:27:25 +02:00
|
|
|
QHash<QObject*, QMetaObject::Connection> m_autoFormatConnections;
|
2015-09-16 19:17:01 +02:00
|
|
|
void formatEditor(TextEditor::TextEditorWidget *editor, const Command &command,
|
|
|
|
|
int startPos = -1, int endPos = 0);
|
|
|
|
|
void formatEditorAsync(TextEditor::TextEditorWidget *editor, const Command &command,
|
|
|
|
|
int startPos = -1, int endPos = 0);
|
|
|
|
|
void checkAndApplyTask(const FormatTask &task);
|
|
|
|
|
void updateEditorText(QPlainTextEdit *editor, const QString &text);
|
2015-09-17 21:27:25 +02:00
|
|
|
|
|
|
|
|
void autoFormatOnSave(Core::IDocument *document);
|
2013-12-11 21:55:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Beautifier
|