bool initialize(const QStringList &arguments, QString *errorString)
function bool initialize(const QStringList &arguments, QString *errorString)
we are looking for special “script” plug-ins in the plug-in folder. These are JavaScript files with the * .gala extension, which can contain the following constructs:initialize()
, which is called immediately after the script is loaded.extensionsInitialized()
, which will be called in the corresponding function of the main plugin (when all the plugins are loaded).aboutToShutdown()
function that will be called before QtCreator is closed.galaPluginOrder
, which is used to reorder script plugins when loaded.galaPluginDisable
, with which you can ignore script plugins.galaPluginTrace
that allows you to log all galaPluginTrace
calls (useful for debugging). var galaPluginOrder = 1; var galaPluginTrace = true; function saveAllAction() { var docs = editorManager.documents(); for (var i = 0; i < docs.length; ++i) { var doc = docs[i]; if (doc.isModified()) { doc.save("", false); } } } function createSaveAllButton() { var bttn = galaAPI.createQObject("QPushButton", modeManager); bttn.flat = true; bttn.text = "Save All"; bttn.focusPolicy = 0; bttn.styleSheet = "QPushButton {color: white; }"; // disable button minimum width bttn.sizePolicy = galaAPI.sizePolicy(13, 0, 1); bttn.clicked.connect(saveAllAction); return bttn; } function initialize() { modeManager.addWidget(createSaveAllButton()); galaAPI.debug("Success initialize"); } function extensionsInitialized() { galaAPI.debug("Success extensionsInitialized"); } function aboutToShutdown() { galaAPI.debug("Success aboutToShutdown"); }
Core::ICore
, Core::Command
, Core::ActionManager
and others). The process of creating wrappers is almost mechanical: we create a class that inherits QObject, passes and stores in it a pointer to a class from the QtCreator API, and re-calls all public methods of the original class in a wrapper in the public slots section. class GModeManager : public GWrapper { Q_OBJECT public: GModeManager(QJSEngine* jsEngine) : GWrapper(jsEngine), m_owner(qobject_cast<Core::ModeManager*>(Core::ModeManager::instance())) { Q_ASSERT(m_owner); } ~GModeManager() {} Core::ModeManager* owner1() { return m_owner; } public slots: QJSValue owner() { return m_jsEngine->toScriptValue(m_owner); } QJSValue currentMode() { return m_jsEngine->toScriptValue(m_owner->currentMode()); } QJSValue mode(QString id) { return m_jsEngine->toScriptValue(m_owner->mode(str2id(id))); } void addAction(QAction *action, int priority) { m_owner->addAction(action, priority); } void addProjectSelector(QAction *action) { m_owner->addProjectSelector(action); } void addWidget(QWidget *widget) { m_owner->addWidget(widget); } void activateMode(QString id) { m_owner->activateMode(str2id(id)); } void setFocusToCurrentMode() { m_owner->setFocusToCurrentMode(); } bool isModeSelectorVisible() { return m_owner->isModeSelectorVisible(); } void setModeSelectorVisible(bool visible) { m_owner->setModeSelectorVisible(visible); } private: Core::ModeManager* m_owner; };
editorManager.documents()
function: QJSValue documents() { QList<Core::IDocument *> documents = m_owner->documentModel()->openedDocuments(); QJSValue array = m_jsEngine->newArray(documents.size()); for (quint32 i = 0; i < (quint32)documents.size(); ++i) { array.setProperty(i, m_jsEngine->newQObject(new GDocument(m_jsEngine, documents[i]))); } return array; }
Core::ICore::instance()
Core::MessageManager::instance()
Core::ActionManager::instance()
Core::EditorManager:instance()
Core::ModeManager::instance()
GCommand *command(QString id) { return new GCommand(m_jsEngine, m_owner->command(str2id(id))); }
// QMenu* QJSValue menu() const { return m_jsEngine->toScriptValue(static_cast<QObject*>(m_owner->menu())); }
foo
method is called from JS, a method with that name is searched for in the object's meta-system and the first one found is called. There is no comparison by the number (and, especially, types) of parameters. At the same time, if the signal has default parameters, moc generates several meta-methods. For example, for the signal void foo(int a, int b = 0, int c = 1);
three meta methods will be generated void foo(int a); void foo(int a, int b); void foo(int a, int b, int c);
Source: https://habr.com/ru/post/223143/
All Articles