diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt index 175d834..6203de1 100644 --- a/src/plugin/CMakeLists.txt +++ b/src/plugin/CMakeLists.txt @@ -17,6 +17,8 @@ if(USE_NOTEPAD_PLUGIN) add_subdirectory(template-plugins/base-plugin-widget) add_subdirectory(template-plugins/base-plugin-window) add_subdirectory(template-plugins/base-plugin-window-ui) + add_subdirectory(template-plugins/base-plugin-interface) + # add_subdirectory(template-plugins/base-secondary-menu-plugin) # add_subdirectory(template-plugins/base-secondary-menu-plugin-v1) # add_subdirectory(template-plugins/base-secondary-menu-ui-plugin-v1) diff --git a/src/plugin/template-plugins/base-plugin-interface/CMakeLists.txt b/src/plugin/template-plugins/base-plugin-interface/CMakeLists.txt new file mode 100644 index 0000000..56a03b5 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/CMakeLists.txt @@ -0,0 +1,115 @@ +# base-plugin-interface/CMakeLists.txt + # 用于在源代码中构建一个插件的模板 + +# 如果不是在源代码中构建插件,请不要使用这个部分 + # 如果想在源代码中添加更多内置模板 + # 请替换 base-plugin-interface 为你的插件名称 + # base-plugin-interface -> your plugin name + +set(LOCAL_PLUGIN_NAME "base-plugin-interface") +set(LOCAL_PLUGIN_VERSION "0.1") + +configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/config.h.in plugin-config.h @ONLY) + +# base-plugin-interface 核心构建 +# 在模块化构建中,这个部分代表着构建 base-plugin-interface 插件 +# 1. 默认构建时产出的目标为 base-plugin-interface +# 2. 在此处可对 base-plugin-interface 目标进行详细的构建计划 + +if(TRUE) + # 准备构建 base-plugin-interface 主程序扩展 + spark_file_glob(LocalSources + ./*.h ./*.cpp ./*.ui + ) + spark_add_library(${LOCAL_PLUGIN_NAME} SHARED ${LocalSources}) + target_include_directories(${LOCAL_PLUGIN_NAME} PRIVATE + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/src/cceditor + + ${PROJECT_SOURCE_DIR}/src/qscint/src + ${PROJECT_SOURCE_DIR}/src/qscint/src/Qsci + ${PROJECT_SOURCE_DIR}/src/qscint/scintilla/src + ${PROJECT_SOURCE_DIR}/src/qscint/scintilla/include + ${PROJECT_SOURCE_DIR}/src/qscint/scintilla/lexlib + ${PROJECT_SOURCE_DIR}/src/qscint/scintilla/boostregex + ) + # target_link_libraries(${LOCAL_PLUGIN_NAME} QSci) + target_link_QSci(${LOCAL_PLUGIN_NAME}) + if(USE_QT6) + # target_link_qt6_Core5Compat(${LOCAL_PLUGIN_NAME}) # 兼容性: Qt6 可使用 Core5Compat 少量更改 Qt5 部分 + # target_link_qt6_PrintSupport(${LOCAL_PLUGIN_NAME}) + # target_link_qt6_XmlPatterns(${LOCAL_PLUGIN_NAME}) # Bug 初期配置时无此依赖要求 + else() + # target_link_qt5_PrintSupport(${LOCAL_PLUGIN_NAME}) + # target_link_qt5_XmlPatterns(${LOCAL_PLUGIN_NAME}) + endif(USE_QT6) + + # 确保生成到 Notepad-- 的相对 plugin 目录下 + set_target_properties(${LOCAL_PLUGIN_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY $/plugin + LIBRARY_OUTPUT_DIRECTORY $/plugin + ARCHIVE_OUTPUT_DIRECTORY $/plugin) + + # 控制是否安装到 bin/plugin 而各种配方之下,每个位置或许都不一样(特别是 Linux) + # install(TARGETS ${LOCAL_PLUGIN_NAME} DESTINATION bin/plugin) +endif(TRUE) + + +# ----------------- base-plugin-interface 构建宏支持相关 ----------------- # + +target_compile_definitions(${LOCAL_PLUGIN_NAME} + # 构建插件时,自动引入的插件配置 + PRIVATE + NOTEPAD_PLUGIN_DECLARE_PLUGIN_CONFIG) + +if(WIN32 AND NOTEPAD_BUILD_BY_SHARED) + # 在 Windows 中构建时,需要关注此库的构建形式,QScintilla 应该以何种方式编译 + target_compile_definitions(${LOCAL_PLUGIN_NAME} + PRIVATE + NOTEPAD_PLUGIN_MANAGER + QSCINTILLA_DLL # 目前在 Windows 中使用 QSci 库时应该采用 Q_DECL_IMPORT + # 控制 QSCINTILLA_EXPORT 符号应为 Q_DECL_IMPORT + ) +else() + # 在 Windows 中构建时,需要关注此库的构建形式,QScintilla 应该以何种方式编译 + target_compile_definitions(${LOCAL_PLUGIN_NAME} + PRIVATE + NOTEPAD_PLUGIN_MANAGER + # QSCINTILLA_DLL # 目前在 Windows 中使用 QSci 库时应该采用 Q_DECL_IMPORT + # 控制 QSCINTILLA_EXPORT 符号应为 Q_DECL_IMPORT + ) +endif(WIN32 AND NOTEPAD_BUILD_BY_SHARED) + +if(UNIX) + # 默认在 Unix/Linux 中仅需要定义一个内部插件宏管理器 + target_compile_definitions(${LOCAL_PLUGIN_NAME} + PRIVATE + NOTEPAD_PLUGIN_MANAGER + ) +endif(UNIX) + + +# ----------------- base-plugin-interface 构建接口化插件支持相关 ----------------- # + +macro(target_link_plugin_interface _target) + set(interfaces + interfaces/ndd-base + interfaces/ndd-menu + interfaces/ndd-dock) + + spark_add_library_file_glob(plugin_interface STATIC + interfaces/ndd-base/*.h interfaces/ndd-base/*.cpp + interfaces/ndd-menu/*.h interfaces/ndd-menu/*.cpp + interfaces/ndd-dock/*.h interfaces/ndd-dock/*.cpp + ) + target_include_directories(plugin_interface + PUBLIC + ${interfaces}) + target_link_qt5(plugin_interface) + + target_link_libraries(${_target} + plugin_interface) +endmacro(target_link_plugin_interface _target) + +target_link_plugin_interface(${LOCAL_PLUGIN_NAME}) diff --git a/src/plugin/template-plugins/base-plugin-interface/README.md b/src/plugin/template-plugins/base-plugin-interface/README.md new file mode 100644 index 0000000..de44d27 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/README.md @@ -0,0 +1,37 @@ +# base-plugin-interface 设计 + +- 主体结构预览 + + ``` + . + ├── CMakeLists.txt + ├── interfaces + │ ├── ndd-base + │ │ ├── ndd_plugin_base_interface.cpp + │ │ └── ndd_plugin_base_interface.h + │ ├── ndd-dock + │ │ ├── ndd_plugin_dock_interface.cpp + │ │ └── ndd_plugin_dock_interface.h + │ └── ndd-menu + │ ├── ndd_plugin_menu_interface.cpp + │ └── ndd_plugin_menu_interface.h + ├── ndd_plugin_implement.cpp + ├── ndd_plugin_implement.h + ├── ndd_plugin_interface.cpp + ├── ndd_plugin_interface.h + ├── plugin.cpp + └── README.md + + 4 directories, 13 files + ``` + + +- 接口化与继承实现说明 + + ```c + // 前提:一切基于接口化操作 + + // 如果插件实现需要拥有某种特定功能,即可继承一个类接口 + + // 如果插件继承了一个包含虚函数的接口,继承者应该去实现它 + ``` \ No newline at end of file diff --git a/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-base/ndd_plugin_base_interface.cpp b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-base/ndd_plugin_base_interface.cpp new file mode 100644 index 0000000..d311df7 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-base/ndd_plugin_base_interface.cpp @@ -0,0 +1,58 @@ +#include "ndd_plugin_base_interface.h" + + +BaseNddPluginInterface::BaseNddPluginInterface(QObject *parent) : QObject(parent) +{ + +} + +BaseNddPluginInterface::BaseNddPluginInterface(QString pluginFile, QString pluginName, QString pluginVersion, QObject *parent) : QObject(parent) + , m_pluginFile(pluginFile) + , m_pluginName(pluginName) + , m_pluginVersion(pluginVersion) +{ + m_pluginDir = QFileInfo(m_pluginFile).dir().path(); + m_pluginResourceDir = QFileInfo(m_pluginFile).dir().filePath(m_pluginName); +} + +QString BaseNddPluginInterface::pluginFile() const +{ + return m_pluginFile; +} + +void BaseNddPluginInterface::setPluginFile(const QString &newPluginFile) +{ + m_pluginFile = newPluginFile; +} + +QString BaseNddPluginInterface::pluginName() const +{ + return m_pluginName; +} + +void BaseNddPluginInterface::setPluginName(const QString &newPluginName) +{ + m_pluginName = newPluginName; +} + +QString BaseNddPluginInterface::pluginVersion() const +{ + return m_pluginVersion; +} + +void BaseNddPluginInterface::setPluginVersion(const QString &newPluginVersion) +{ + m_pluginVersion = newPluginVersion; +} + +QString BaseNddPluginInterface::pluginDir() const +{ + return QFileInfo(m_pluginFile).dir().path(); +// return m_pluginDir; +} + +QString BaseNddPluginInterface::pluginResourceDir() const +{ + return QFileInfo(m_pluginFile).dir().filePath(m_pluginName); +// return m_pluginResourceDir; +} diff --git a/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-base/ndd_plugin_base_interface.h b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-base/ndd_plugin_base_interface.h new file mode 100644 index 0000000..e0bcf09 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-base/ndd_plugin_base_interface.h @@ -0,0 +1,46 @@ +#ifndef __NDD_PLUGIN_BASE_INTERFACE__H__ +#define __NDD_PLUGIN_BASE_INTERFACE__H__ + +#include +#include + +class BaseNddPluginInterface : public QObject { + + Q_OBJECT + Q_PROPERTY(QString pluginFile READ pluginFile WRITE setPluginFile); + Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName); + Q_PROPERTY(QString pluginVersion READ pluginVersion WRITE setPluginVersion); + // Q_PROPERTY(QString pluginDir READ pluginDir); + // Q_PROPERTY(QString pluginResourceDir READ pluginResourceDir); + +public: + explicit BaseNddPluginInterface(QObject *parent = nullptr); + explicit BaseNddPluginInterface(QString pluginFile, QString pluginName, QString pluginVersion, QObject *parent = nullptr); + + QString pluginFile() const; + void setPluginFile(const QString &newPluginFile); + + QString pluginName() const; + void setPluginName(const QString &newPluginName); + + QString pluginVersion() const; + void setPluginVersion(const QString &newPluginVersion); + + QString pluginDir() const; + QString pluginResourceDir() const; + +private: + QString m_pluginFile; + QString m_pluginName; + QString m_pluginVersion; + + QString m_pluginDir; + QString m_pluginResourceDir; +}; + +#define USE_INTERFACE_IMPLEMENT(interface) \ + interface->setPluginFile(s_strFileName); \ + interface->setPluginName(PLUGIN_NAME); \ + interface->setPluginVersion(PLUGIN_VERSION); \ + +#endif //!__NDD_PLUGIN_BASE_INTERFACE__H__ \ No newline at end of file diff --git a/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-dock/ndd_plugin_dock_interface.cpp b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-dock/ndd_plugin_dock_interface.cpp new file mode 100644 index 0000000..969c1c7 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-dock/ndd_plugin_dock_interface.cpp @@ -0,0 +1,22 @@ +#include "ndd_plugin_dock_interface.h" + +DockNddPluginInterface::DockNddPluginInterface(QObject *parent) : QObject(parent) +{ + +} + + +int DockNddPluginInterface::showInDock(Qt::DockWidgetArea area) { + // m_widget 是 + auto mainwindow = dynamic_cast(m_widget); + if (!mainwindow) { + return -1; + } + if (!m_dockerContainer) { + m_dockerContainer = new QDockWidget(mainwindow); + auto m_dockTitleBarWidget = m_dockerContainer->titleBarWidget(); + } + + return 0; +} + diff --git a/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-dock/ndd_plugin_dock_interface.h b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-dock/ndd_plugin_dock_interface.h new file mode 100644 index 0000000..2acdb53 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-dock/ndd_plugin_dock_interface.h @@ -0,0 +1,25 @@ +#ifndef __NDD_PLUGIN_DOCK_INTERFACE__H__ +#define __NDD_PLUGIN_DOCK_INTERFACE__H__ + +#include +#include + +class DockNddPluginInterface : public QObject{ + +public: + explicit DockNddPluginInterface(QObject *parent = nullptr); + + /** + * @brief 显示在 DockWidget 中 + * @note + * @param area: DockWidget + * @retval + */ + int showInDock(Qt::DockWidgetArea area); + + QWidget *m_widget; + QDockWidget *m_dockerContainer; +}; + + +#endif //!__NDD_PLUGIN_DOCK_INTERFACE__H__ diff --git a/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-menu/ndd_plugin_menu_interface.cpp b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-menu/ndd_plugin_menu_interface.cpp new file mode 100644 index 0000000..0d26290 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-menu/ndd_plugin_menu_interface.cpp @@ -0,0 +1,16 @@ +#include "ndd_plugin_menu_interface.h" + +MenuNddPluginInterface::MenuNddPluginInterface(QObject *parent) : QObject(parent) { + +} + +QMenu *MenuNddPluginInterface::menu() const +{ + return m_menu; +} + +void MenuNddPluginInterface::setMenu(QMenu *newMenu) +{ + m_menu = newMenu; + setMenuAction(); +} diff --git a/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-menu/ndd_plugin_menu_interface.h b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-menu/ndd_plugin_menu_interface.h new file mode 100644 index 0000000..3ccd07e --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/interfaces/ndd-menu/ndd_plugin_menu_interface.h @@ -0,0 +1,26 @@ +#ifndef __NDD_PLUGIN_MENU_INTERFACE__H__ +#define __NDD_PLUGIN_MENU_INTERFACE__H__ + +#include + +class MenuNddPluginInterface : public QObject { + + Q_OBJECT + Q_PROPERTY(QMenu* menu READ menu WRITE setMenu); +public: + explicit MenuNddPluginInterface(QObject *parent = nullptr); + + QMenu *menu() const; + void setMenu(QMenu *newMenu); + +private: + QMenu *m_menu = nullptr; + +protected: + virtual void setMenuAction() = 0; +}; + +#define USE_MENU_IMPLEMENT(menu) \ + menu->setMenu(s_pProcData.m_rootMenu); + +#endif //!__NDD_PLUGIN_MENU_INTERFACE__H__ diff --git a/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_implement.cpp b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_implement.cpp new file mode 100644 index 0000000..8694293 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_implement.cpp @@ -0,0 +1,22 @@ +#include "ndd_plugin_implement.h" +#include "qdebug.h" + + +NddPluginImplement::NddPluginImplement(QObject *parent) : BaseNddPluginInterface(parent), MenuNddPluginInterface(parent) +{ + +} + +void NddPluginImplement::setMenuAction() +{ + menu()->addAction("First Menu", [](){ + qDebug() << ">>> First Menu"; + }); + + menu()->addAction("plugin infomations", [=](){ + qInfo() << "[pluginDir]:" << pluginDir(); + qInfo() << "[pluginFile]:" << pluginFile(); + qInfo() << "[pluginVersion]:" << pluginVersion(); + qInfo() << "[pluginResourceDir]:" << pluginResourceDir(); + }); +} diff --git a/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_implement.h b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_implement.h new file mode 100644 index 0000000..0dace87 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_implement.h @@ -0,0 +1,20 @@ +#ifndef NDD_PLUGIN_IMPLEMENT_H +#define NDD_PLUGIN_IMPLEMENT_H + +#include "ndd_plugin_base_interface.h" +#include "ndd_plugin_menu_interface.h" +#include "ndd_plugin_dock_interface.h" + +#include + +class NddPluginImplement : public BaseNddPluginInterface, public MenuNddPluginInterface +{ +public: + explicit NddPluginImplement(QObject *parent = nullptr); + + // MenuNddPluginInterface interface +protected: + void setMenuAction() override; +}; + +#endif // NDD_PLUGIN_IMPLEMENT_H diff --git a/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_interface.cpp b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_interface.cpp new file mode 100644 index 0000000..65e6bd7 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_interface.cpp @@ -0,0 +1,8 @@ +#include "ndd_plugin_interface.h" + +// Temporary interface design storage point ... + +NddPluginInterface::NddPluginInterface(QObject *parent) : BaseNddPluginInterface(parent) +{ + +} diff --git a/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_interface.h b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_interface.h new file mode 100644 index 0000000..59cb352 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/ndd_plugin_interface.h @@ -0,0 +1,29 @@ +#ifndef __NDD_PLUGIN_INTERFACE__H__ +#define __NDD_PLUGIN_INTERFACE__H__ + +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include + +#include "ndd_plugin_base_interface.h" + +class NddPluginInterface : BaseNddPluginInterface { + +public: + explicit NddPluginInterface(QObject *parent = nullptr); + +private: + +}; + + +#endif //!__NDD_PLUGIN_INTERFACE__H__ diff --git a/src/plugin/template-plugins/base-plugin-interface/plugin.cpp b/src/plugin/template-plugins/base-plugin-interface/plugin.cpp new file mode 100644 index 0000000..1ea6248 --- /dev/null +++ b/src/plugin/template-plugins/base-plugin-interface/plugin.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include "ndd_plugin_implement.h" +#include "ndd_plugin_interface.h" + +#include + +/************************************************************** +// 当编译标志 NOTEPAD_PLUGIN_DECLARE_PLUGIN_CONFIG 被定义 + // 将会自动 #include ,并提供几个插件相关的宏 + // #define NOTEPAD_VERSION "v1.23.2" + // #define PLUGIN_NAME "base-plugin" + // #define PLUGIN_VERSION "0.1" + +**************************************************************/ + +// 使用可扩展宏 IDENTIFY_ +NOTEPAD_PLUGIN_METADATA_IDENTIFY_1 { + USE_IDENTIFY_VARIABLES + + NOTEPAD_PLUGIN_METADATA("基本插件(interface)", PLUGIN_VERSION, "author", "基本 接口化与多继承实现 的插件", ""); + + return true; +} + + +// 使用可扩展宏 IMPLEMENT_ ,在 _1 中将进行二级菜单扩展的全局声明 +NOTEPAD_PLUGIN_METADATA_IMPLEMENT_1 { + USE_IMPLEMENT_VARIABLES + + + qInfo() << PLUGIN_NAME << ":" << PLUGIN_VERSION; + qInfo() << PLUGIN_NAME << ":" << QString("基于 %1 编译").arg(NOTEPAD_VERSION); + + // auto base = new BaseNddPluginInterface(); + // USE_INTERFACE_IMPLEMENT(base) + + // qInfo() << "[pluginDir]:" << base->pluginDir(); + // qInfo() << "[pluginFile]:" << base->pluginFile(); + // qInfo() << "[pluginVersion]:" << base->pluginVersion(); + // qInfo() << "[pluginResourceDir]:" << base->pluginResourceDir(); + + + auto imp = new NddPluginImplement(); + USE_INTERFACE_IMPLEMENT(imp); + USE_MENU_IMPLEMENT(imp); + + return 0; +}