diff --git a/src/plugins/CutterPlugin.h b/src/plugins/CutterPlugin.h index 0c0ad61d..cea0aeab 100644 --- a/src/plugins/CutterPlugin.h +++ b/src/plugins/CutterPlugin.h @@ -10,10 +10,32 @@ class MainWindow; class CutterPlugin { public: - virtual ~CutterPlugin() {} + virtual ~CutterPlugin() = default; + + /** + * @brief Initialize the Plugin + * + * called right when the plugin is loaded initially + */ virtual void setupPlugin() = 0; + + /** + * @brief Setup any UI components for the Plugin + * @param main the MainWindow to add any UI to + * + * called after Cutter's core UI has been initialized + */ virtual void setupInterface(MainWindow *main) = 0; + /** + * @brief Shutdown the Plugin + * + * called just before the Plugin is deleted. + * This method is usually only relevant for Python Plugins where there is no + * direct equivalent of the destructor. + */ + virtual void terminate() {}; + virtual QString getName() const = 0; virtual QString getAuthor() const = 0; virtual QString getDescription() const = 0; diff --git a/src/plugins/PluginManager.cpp b/src/plugins/PluginManager.cpp index d60de83e..68834e84 100644 --- a/src/plugins/PluginManager.cpp +++ b/src/plugins/PluginManager.cpp @@ -78,6 +78,7 @@ void PluginManager::loadPlugins() void PluginManager::destroyPlugins() { for (CutterPlugin *plugin : plugins) { + plugin->terminate(); delete plugin; } } diff --git a/src/plugins/sample-python/sample_python.py b/src/plugins/sample-python/sample_python.py index 8dfb6fb0..9a864c68 100644 --- a/src/plugins/sample-python/sample_python.py +++ b/src/plugins/sample-python/sample_python.py @@ -59,6 +59,9 @@ class CutterSamplePlugin(cutter.CutterPlugin): widget = FortuneWidget(main, action) main.addPluginDockWidget(widget, action) + def terminate(self): # optional + print("CutterSamplePlugin shutting down") + # This function will be called by Cutter and should return an instance of the plugin. def create_cutter_plugin():