mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Modified some APIs for more consistence
Correct null check after create_cutter_plugin() Fix cutter.core()
This commit is contained in:
parent
18b40a8b90
commit
436842222e
@ -171,7 +171,7 @@ CutterCore::CutterCore(QObject *parent) :
|
||||
}
|
||||
|
||||
|
||||
CutterCore *CutterCore::getInstance()
|
||||
CutterCore *CutterCore::instance()
|
||||
{
|
||||
return uniqueInstance;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
#define APPNAME "Cutter"
|
||||
|
||||
#define Core() (CutterCore::getInstance())
|
||||
#define Core() (CutterCore::instance())
|
||||
|
||||
/*!
|
||||
* \brief Type to be used for all kinds of addresses/offsets in r2 address space.
|
||||
@ -416,7 +416,7 @@ class CutterCore: public QObject
|
||||
public:
|
||||
explicit CutterCore(QObject *parent = nullptr);
|
||||
~CutterCore();
|
||||
static CutterCore *getInstance();
|
||||
static CutterCore *instance();
|
||||
|
||||
AsyncTaskManager *getAsyncTaskManager() { return asyncTaskManager; }
|
||||
|
||||
|
@ -389,6 +389,11 @@ void MainWindow::addPluginDockWidget(QDockWidget *dockWidget, QAction *action)
|
||||
updateDockActionChecked(action);
|
||||
}
|
||||
|
||||
void MainWindow::addMenuFileAction(QAction *action)
|
||||
{
|
||||
ui->menuFile->addAction(action);
|
||||
}
|
||||
|
||||
void MainWindow::openNewFile(InitialOptions options, bool skipOptionsDialog)
|
||||
{
|
||||
setFilename(options.filename);
|
||||
@ -1162,3 +1167,18 @@ void MainWindow::addDockWidgetAction(QDockWidget *dockWidget, QAction *action)
|
||||
{
|
||||
this->dockWidgetActions[action] = dockWidget;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Show a warning message box.
|
||||
*
|
||||
* This API can either be used in Cutter internals, or by Python plugins.
|
||||
*/
|
||||
void MainWindow::messageBoxWarning(QString title, QString message)
|
||||
{
|
||||
QMessageBox mb(this);
|
||||
mb.setIcon(QMessageBox::Warning);
|
||||
mb.setStandardButtons(QMessageBox::Ok);
|
||||
mb.setWindowTitle(title);
|
||||
mb.setText(message);
|
||||
mb.exec();
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ public:
|
||||
void addExtraWidget(QDockWidget *extraDock);
|
||||
|
||||
void addPluginDockWidget(QDockWidget *dockWidget, QAction *action);
|
||||
void addMenuFileAction(QAction *action);
|
||||
|
||||
void updateDockActionChecked(QAction * action);
|
||||
|
||||
@ -111,6 +112,7 @@ public:
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
void messageBoxWarning(QString title, QString message);
|
||||
|
||||
public slots:
|
||||
void finalizeOpen();
|
||||
|
@ -12,7 +12,7 @@ PyObject *api_version(PyObject *self, PyObject *null)
|
||||
{
|
||||
Q_UNUSED(self)
|
||||
Q_UNUSED(null)
|
||||
return PyUnicode_FromString("Cutter version " CUTTER_VERSION_FULL);
|
||||
return PyUnicode_FromString(CUTTER_VERSION_FULL);
|
||||
}
|
||||
|
||||
PyObject *api_cmd(PyObject *self, PyObject *args)
|
||||
|
@ -126,7 +126,7 @@ CutterPlugin *PluginManager::loadPythonPlugin(const char *moduleName)
|
||||
|
||||
PyObject *createPluginFunc = PyObject_GetAttrString(pluginModule, "create_cutter_plugin");
|
||||
if (!createPluginFunc || !PyCallable_Check(createPluginFunc)) {
|
||||
qWarning() << "Plugin module does not contain create_plugin() function:" << QString(moduleName);
|
||||
qWarning() << "Plugin module does not contain create_cutter_plugin() function:" << QString(moduleName);
|
||||
if (createPluginFunc) {
|
||||
Py_DECREF(createPluginFunc);
|
||||
}
|
||||
@ -137,14 +137,23 @@ CutterPlugin *PluginManager::loadPythonPlugin(const char *moduleName)
|
||||
PyObject *pluginObject = PyObject_CallFunction(createPluginFunc, nullptr);
|
||||
Py_DECREF(createPluginFunc);
|
||||
Py_DECREF(pluginModule);
|
||||
if (!pluginObject) {
|
||||
qWarning() << "Plugin's create_cutter_plugin() function failed.";
|
||||
PyErr_Print();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PythonToCppFunc pythonToCpp = Shiboken::Conversions::isPythonToCppPointerConvertible(reinterpret_cast<SbkObjectType *>(SbkCutterBindingsTypes[SBK_CUTTERPLUGIN_IDX]), pluginObject);
|
||||
if (!pythonToCpp) {
|
||||
qWarning() << "Plugin's create_plugin() function did not return an instance of CutterPlugin:" << QString(moduleName);
|
||||
qWarning() << "Plugin's create_cutter_plugin() function did not return an instance of CutterPlugin:" << QString(moduleName);
|
||||
return nullptr;
|
||||
}
|
||||
CutterPlugin *plugin;
|
||||
pythonToCpp(pluginObject, &plugin);
|
||||
if (!plugin) {
|
||||
qWarning() << "Error during the setup of CutterPlugin:" << QString(moduleName);
|
||||
return nullptr;
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
#endif
|
@ -9,4 +9,4 @@ def cmdj(command):
|
||||
|
||||
|
||||
def core():
|
||||
return CutterCore.getInstance()
|
||||
return CutterCore.instance()
|
||||
|
Loading…
Reference in New Issue
Block a user