Commit 7c4deb68 authored by Alexander A. Maly's avatar Alexander A. Maly

More restyling of interfaces

parent 32fb19a2
Pipeline #2370 passed with stages
in 4 minutes and 1 second
#ifndef ANALIZER_HELPERINTERFACE_H
#define ANALIZER_HELPERINTERFACE_H
#include <kumir2-libs/dataformats/lexem.h>
#include <kumir2-libs/dataformats/ast.h>
#include <kumir2/lexemtype.h>
#include <QString>
#include <QList>
#include <QtPlugin>
#include <string>
namespace Shared
{
namespace Analizer
{
namespace Shared { namespace Analizer {
typedef QPair<QString,quint32> TextAppend;
typedef QPair<QString, quint32> TextAppend;
struct Suggestion {
enum Kind { LocalVariable, GlobalVariable, Function, Module, BuiltinModule, Statement, PrimaryKeyword, SecondaryKeyword, Other };
inline Suggestion() { kind = Other; showOnlyInFullList = false; }
QString value;
QString description;
bool showOnlyInFullList;
Kind kind;
enum Kind {
LocalVariable,
GlobalVariable,
Function,
Module,
BuiltinModule,
Statement,
PrimaryKeyword,
SecondaryKeyword,
Other
};
Suggestion()
{
kind = Other;
showOnlyInFullList = false;
}
QString value;
QString description;
bool showOnlyInFullList;
Kind kind;
};
struct ApiHelpItem {
enum Kind { Empty, Keyword, Module, Function, GlobalVariable };
QString packageName;
QString itemName;
Kind kind;
inline ApiHelpItem() : kind(Empty) {}
enum Kind {
Empty,
Keyword,
Module,
Function,
GlobalVariable
};
QString packageName;
QString itemName;
Kind kind;
ApiHelpItem() : kind(Empty) {}
};
class HelperInterface {
class HelperInterface
{
public:
virtual QList<Suggestion> suggestAutoComplete(int lineNo, const QString & before, const QString & after) const = 0;
virtual TextAppend closingBracketSuggestion(int lineNo) const = 0;
virtual QStringList importModuleSuggestion(int lineNo) const = 0;
virtual ApiHelpItem itemUnderCursor(const QString & text, int lineNo, int colNo, bool includeRightBound) const = 0;
virtual QStringList imports() const = 0;
virtual QString createImportStatementLine(const QString &importName) const = 0;
virtual QString suggestFileName() const = 0;
virtual QRegExp lineCommentStartLexemPattern() const = 0;
virtual void connectSignalImportsChanged(
QObject * receiver,
const char * slot /* void (QStringList localizedNames) */
) { Q_UNUSED(receiver); Q_UNUSED(slot); }
/** Corrects lexem capitalization for case-insensetive grammatics (optional)
*/
inline virtual QString correctCapitalization(const QString & name, LexemType lxType) const
{ return name; }
inline virtual bool isKnownLexem(const QString &lexem, int lineNo, int colNo, const QString &context) const
{ return false; }
virtual QList<Suggestion> suggestAutoComplete(int lineNo, const QString &before, const QString &after) const = 0;
virtual TextAppend closingBracketSuggestion(int lineNo) const = 0;
virtual QStringList importModuleSuggestion(int lineNo) const = 0;
virtual ApiHelpItem itemUnderCursor(const QString &text, int lineNo, int colNo, bool includeRightBound) const = 0;
virtual QStringList imports() const = 0;
virtual QString createImportStatementLine(const QString &importName) const = 0;
virtual QString suggestFileName() const = 0;
virtual QRegExp lineCommentStartLexemPattern() const = 0;
virtual void connectSignalImportsChanged(
QObject *receiver,
const char *slot /* void (QStringList localizedNames) */
)
{
Q_UNUSED(receiver);
Q_UNUSED(slot);
}
/** Corrects lexem capitalization for case-insensetive grammatics (optional)
*/
virtual QString correctCapitalization(const QString &name, LexemType lxType) const
{
return name;
}
virtual bool isKnownLexem(const QString &lexem, int lineNo, int colNo, const QString &context) const
{
return false;
}
};
}}
} // namespace Analizer
} // namespace Shared
Q_DECLARE_INTERFACE(Shared::Analizer::HelperInterface,
"kumir2.Analizer.HelperInterface")
"kumir2.Analizer.HelperInterface")
#endif // ANALIZER_HELPERINTERFACE_H
#ifndef ANALIZER_COMMONINTERFACE_H
#define ANALIZER_COMMONINTERFACE_H
#include "analizer_compilerinterface.h"
#include "analizer_helperinterface.h"
#include <kumir2-libs/dataformats/ast.h>
#include <QString>
#include <QList>
#include <QtPlugin>
#include <QPoint>
#include <string>
namespace Shared {
namespace Shared
{
class AnalizerInterface;
namespace Analizer {
struct Error
namespace Analizer
{
int line; // line number from 0
int start; // position in line from 0
int len; // error markup length
QString message; // error message
QByteArray msgid; // internal message id
QByteArray origin; // message origin name (PyLint, PyFlakes etc.)
class HelperInterface;
struct Error {
int line; // line number from 0
int start; // position in line from 0
int len; // error markup length
QString message; // error message
QByteArray msgid; // internal message id
QByteArray origin; // message origin name (PyLint, PyFlakes etc.)
};
typedef QVector<LexemType> LineProp;
class InstanceInterface {
class InstanceInterface
{
public:
virtual void setSourceDirName(const QString & path) = 0;
virtual void setSourceText(const QString & plainText) = 0;
virtual std::string rawSourceData() const = 0;
virtual QList<Error> errors() const = 0;
virtual QList<LineProp> lineProperties() const = 0;
virtual QList<QPoint> lineRanks() const = 0;
virtual LineProp lineProp(int lineNo, const QString & text) const = 0;
inline virtual bool multipleStatementsInLine(int lineNo) const {
Q_UNUSED(lineNo); return false;
}
inline virtual ASTCompilerInterface * compiler() {
QObject * me = dynamic_cast<QObject*>(this);
if (!me) return 0;
return qobject_cast<ASTCompilerInterface*>(me);
}
inline virtual HelperInterface * helper() {
QObject * me = dynamic_cast<QObject*>(this);
if (!me) return 0;
return qobject_cast<HelperInterface*>(me);
}
inline virtual ExternalExecutableCompilerInterface * externalToolchain() {
QObject * me = dynamic_cast<QObject*>(this);
if (!me) return 0;
return qobject_cast<ExternalExecutableCompilerInterface*>(me);
}
inline virtual void connectUpdateRequest(QObject * receiver, const char * method) {
Q_UNUSED(receiver); Q_UNUSED(method);
}
virtual AnalizerInterface * plugin() = 0;
virtual ~InstanceInterface() {};
virtual void setSourceDirName(const QString &path) = 0;
virtual void setSourceText(const QString &plainText) = 0;
virtual std::string rawSourceData() const = 0;
virtual QList<Error> errors() const = 0;
virtual QList<LineProp> lineProperties() const = 0;
virtual QList<QPoint> lineRanks() const = 0;
virtual LineProp lineProp(int lineNo, const QString &text) const = 0;
virtual bool multipleStatementsInLine(int lineNo) const
{
Q_UNUSED(lineNo);
return false;
}
virtual ASTCompilerInterface *compiler()
{
QObject *me = dynamic_cast<QObject *>(this);
if (!me) {
return 0;
}
return qobject_cast<ASTCompilerInterface *>(me);
}
virtual HelperInterface *helper()
{
QObject *me = dynamic_cast<QObject *>(this);
if (!me) {
return 0;
}
return qobject_cast<HelperInterface *>(me);
}
virtual ExternalExecutableCompilerInterface *externalToolchain()
{
QObject *me = dynamic_cast<QObject *>(this);
if (!me) {
return 0;
}
return qobject_cast<ExternalExecutableCompilerInterface *>(me);
}
virtual void connectUpdateRequest(QObject *receiver, const char *method)
{
Q_UNUSED(receiver);
Q_UNUSED(method);
}
virtual AnalizerInterface *plugin() = 0;
virtual ~InstanceInterface() {};
};
}}
} // namespace Analizer
} // namespace Shared
Q_DECLARE_INTERFACE(Shared::Analizer::InstanceInterface,
"kumir2.Analizer.InstanceInterface")
"kumir2.Analizer.InstanceInterface")
#endif // ANALIZER_COMMONINTERFACE_H
#ifndef ANALIZER_SOURCEFILEINTERFACE_H
#define ANALIZER_SOURCEFILEINTERFACE_H
#include <QtCore>
#include <QtPlugin>
#include <QString>
#include <QSet>
#include <QUrl>
#include <QTextStream>
namespace Shared
{
......@@ -34,7 +37,7 @@ public /*methods*/:
// Generic methods to read and write from/to raw byte array. Default implementation
// assumes UTF-8 encoding with BOM mark, but it is possible to override
inline virtual QByteArray toBytes(
virtual QByteArray toBytes(
const Data &data,
const QString &forceEncoding = ""
) const {
......@@ -51,7 +54,7 @@ public /*methods*/:
return buffer;
}
inline virtual Data fromBytes(
virtual Data fromBytes(
const QByteArray &bytes,
const QString &forceEncoding = ""
) const {
......@@ -69,9 +72,9 @@ public /*methods*/:
};
}
} // namespace Analizer
}
} // namespace Shared
Q_DECLARE_INTERFACE(
Shared::Analizer::SourceFileInterface,
......
#ifndef ANALIZER_INTERFACE_H
#define ANALIZER_INTERFACE_H
#include <kumir2-libs/dataformats/ast.h>
//#include "analizer_instanceinterface.h"
//#include "analizer_sourcefileinterface.h"
#include "analizer_instanceinterface.h"
#include "analizer_sourcefileinterface.h"
#include <QtCore>
#include <QtPlugin>
class QWidget;
namespace Shared {
namespace Shared
{
namespace Analizer {
class InstanceInterface;
class SourceFileInterface;
}
class AnalizerInterface {
class AnalizerInterface
{
public:
/** How editor should handle indents */
enum IndentsBehaviour {
HardIndents, /** Hard indents, so user can't edit text there */
PythonIndents, /** Use ident values as recomendations, but user can backpace on it */
FreeIndents /** User allowed to fully contol indent values */
};
/** What editor should rehighlight on line edit */
enum SyntaxHighlightBehaviour {
IndependentLinesHighlight, /** Each line rehighlighted independently */
RestLinesHighlight, /** Rehighlight edited line and rest lines */
CompleteTextHighlight /** Rehighlight complete text on any line change */
};
virtual bool primaryAlphabetIsLatin() const = 0;
virtual bool caseInsensitiveGrammatic() const = 0;
virtual IndentsBehaviour indentsBehaviour() const = 0;
virtual SyntaxHighlightBehaviour syntaxHighlightBehaviour() const = 0;
virtual QString languageName() const = 0;
virtual QWidget * languageQuickReferenceWidget() { return 0; }
virtual QByteArray asciiLanguageIdentifier() const { return languageName().toLower().toLatin1(); }
virtual QString defaultDocumentFileNameSuffix() const = 0;
virtual Analizer::InstanceInterface * createInstance() = 0;
virtual Analizer::SourceFileInterface * sourceFileHandler() = 0;
/** How editor should handle indents */
enum IndentsBehaviour {
HardIndents, /** Hard indents, so user can't edit text there */
PythonIndents, /** Use ident values as recomendations, but user can backpace on it */
FreeIndents /** User allowed to fully contol indent values */
};
/** What editor should rehighlight on line edit */
enum SyntaxHighlightBehaviour {
IndependentLinesHighlight, /** Each line rehighlighted independently */
RestLinesHighlight, /** Rehighlight edited line and rest lines */
CompleteTextHighlight /** Rehighlight complete text on any line change */
};
virtual bool primaryAlphabetIsLatin() const = 0;
virtual bool caseInsensitiveGrammatic() const = 0;
virtual IndentsBehaviour indentsBehaviour() const = 0;
virtual SyntaxHighlightBehaviour syntaxHighlightBehaviour() const = 0;
virtual QString languageName() const = 0;
virtual QWidget *languageQuickReferenceWidget()
{
return 0;
}
virtual QByteArray asciiLanguageIdentifier() const
{
return languageName().toLower().toLatin1();
}
virtual QString defaultDocumentFileNameSuffix() const = 0;
virtual Analizer::InstanceInterface *createInstance() = 0;
virtual Analizer::SourceFileInterface *sourceFileHandler() = 0;
};
......
#ifndef EDITOR_INSTANCEINTERFACE_H
#define EDITOR_INSTANCEINTERFACE_H
#include <kumir2-libs/dataformats/kumfile.h>
#include "analizer_instanceinterface.h"
#include "analizer_sourcefileinterface.h"
#include "analizer_helperinterface.h"
#include <QWidget>
#include <QtPlugin>
#include <QMetaType>
#include <QList>
#include <QMenu>
#include <QAction>
#include <cstdint>
class QWidget;
class QMenu;
class QAction;
namespace Shared { namespace Editor {
namespace Shared
{
namespace Analizer {
class InstanceInterface;
}
namespace Editor
{
struct Breakpoint {
QString fileName;
bool enabled;
quint32 lineNo;
quint32 ignoreCount;
QString condition;
QString fileName;
bool enabled;
quint32 lineNo;
quint32 ignoreCount;
QString condition;
inline explicit Breakpoint(): enabled(true), lineNo(0u), ignoreCount(0u) {}
explicit Breakpoint(): enabled(true), lineNo(0u), ignoreCount(0u) {}
};
class InstanceInterface {
class InstanceInterface
{
public:
virtual bool isModified() const = 0;
virtual void setNotModified() = 0;
virtual void loadDocument(QIODevice * device,
const QString & fileNameSuffix,
const QString & sourceEncoding,
const QUrl & sourceUrl, QString * error
) = 0;
virtual void loadDocument(const QString & fileName, QString * error) /* throws QString */ = 0;
virtual void loadDocument(const Analizer::SourceFileInterface::Data &data, QString * error) /* throws QString */ = 0;
virtual void saveDocument(const QString & fileName, QString * error) /* throws QString */ = 0;
virtual void saveDocument(QIODevice * device, QString * error) /* throws QString */ = 0;
virtual Analizer::SourceFileInterface::Data documentContents() const = 0;
virtual Analizer::InstanceInterface * analizer() = 0;
virtual quint32 errorLinesCount() const = 0;
virtual void ensureAnalized() = 0;
virtual void highlightLineGreen(int lineNo, quint32 colStart, quint32 colEnd) = 0;
virtual void highlightLineRed(int lineNo, quint32 colStart, quint32 colEnd) = 0;
virtual void unhighlightLine() = 0;
virtual void appendMarginText(int lineNo, const QString & text) = 0;
virtual void setMarginText(int lineNo, const QString & text, const QColor & fgColor) = 0;
virtual void clearMarginText(int fromLine = 0, int toLine = -1) = 0;
virtual bool supportsContextHelp() const = 0;
inline virtual Analizer::ApiHelpItem contextHelpItem() const { return Analizer::ApiHelpItem(); }
virtual QWidget * widget() = 0;
virtual QList<QMenu*> menus() const = 0;
virtual QList<QAction*> toolBarActions() const = 0;
virtual QAction * toggleBreakpointAction() const = 0;
virtual QList<Breakpoint> breakpoints() const = 0;
virtual uint32_t currentLineNumber() const = 0;
virtual void forceCompleteCompilation() = 0;
virtual bool isModified() const = 0;
virtual void setNotModified() = 0;
virtual void loadDocument(
QIODevice *device,
const QString &fileNameSuffix,
const QString &sourceEncoding,
const QUrl &sourceUrl, QString *error
) = 0;
virtual void loadDocument(
const QString &fileName, QString *error
) /* throws QString */ = 0;
virtual void loadDocument(
const Analizer::SourceFileInterface::Data &data, QString *error
) /* throws QString */ = 0;
virtual void saveDocument(
const QString &fileName, QString *error
) /* throws QString */ = 0;
virtual void saveDocument(
QIODevice *device, QString *error
) /* throws QString */ = 0;
virtual Analizer::SourceFileInterface::Data documentContents() const = 0;
virtual Analizer::InstanceInterface *analizer() = 0;
virtual quint32 errorLinesCount() const = 0;
virtual void ensureAnalized() = 0;
virtual void highlightLineGreen(int lineNo, quint32 colStart, quint32 colEnd) = 0;
virtual void highlightLineRed(int lineNo, quint32 colStart, quint32 colEnd) = 0;
virtual void unhighlightLine() = 0;
virtual void appendMarginText(int lineNo, const QString &text) = 0;
virtual void setMarginText(int lineNo, const QString &text, const QColor &fgColor) = 0;
virtual void clearMarginText(int fromLine = 0, int toLine = -1) = 0;
virtual bool supportsContextHelp() const = 0;
virtual Analizer::ApiHelpItem contextHelpItem() const
{
return Analizer::ApiHelpItem();
}
virtual QWidget *widget() = 0;
virtual QList<QMenu *> menus() const = 0;
virtual QList<QAction *> toolBarActions() const = 0;
virtual QAction *toggleBreakpointAction() const = 0;
virtual QList<Breakpoint> breakpoints() const = 0;
virtual quint32 currentLineNumber() const = 0;
virtual void forceCompleteCompilation() = 0;
};
}}
} // namespace Editor
} // namespace Shared
Q_DECLARE_METATYPE(Shared::Editor::Breakpoint)
Q_DECLARE_INTERFACE(Shared::Editor::InstanceInterface,
"kumir2.Editor.InstanceInterface")
"kumir2.Editor.InstanceInterface")
#endif // EDITOR_INSTANCEINTERFACE_H
#ifndef PLUGININTERFACE_H
#define PLUGININTERFACE_H
#include <QtPlugin>
class QString;
namespace Shared
......@@ -55,7 +56,7 @@ public:
virtual void changeGlobalState(GlobalState old, GlobalState current) = 0;
};
}
} // namespace Shared
Q_DECLARE_INTERFACE(Shared::PluginInterface, "kumir2.Plugin")
......