diff --git a/cmake/modules/config.h.in b/cmake/modules/config.h.in index f357ef4..b6e3d68 100644 --- a/cmake/modules/config.h.in +++ b/cmake/modules/config.h.in @@ -1 +1,5 @@ -#define NOTEPAD_VERSION "v@PROJECT_VERSION@" \ No newline at end of file +#define NOTEPAD_VERSION "v@PROJECT_VERSION@" + + +#define PLUGIN_NAME "@LOCAL_PLUGIN_NAME@" +#define PLUGIN_VERSION "@LOCAL_PLUGIN_VERSION@" \ No newline at end of file diff --git a/src/plugin/template-plugins/base-plugin/CMakeLists.txt b/src/plugin/template-plugins/base-plugin/CMakeLists.txt index 7cdb930..a586261 100644 --- a/src/plugin/template-plugins/base-plugin/CMakeLists.txt +++ b/src/plugin/template-plugins/base-plugin/CMakeLists.txt @@ -6,7 +6,10 @@ # 请替换 base-plugin 为你的插件名称 # base-plugin -> your plugin name -set(LOCAL_PLUGIN_NAME "base-plugin") +set(LOCAL_PLUGIN_NAME "base-plugin") +set(LOCAL_PLUGIN_VERSION "0.1") + +configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/config.h.in plugin-config.h @ONLY) # base-plugin 核心构建 # 在模块化构建中,这个部分代表着构建 base-plugin 插件 @@ -55,6 +58,11 @@ endif(TRUE) # ----------------- base-plugin 构建宏支持相关 ----------------- # +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} diff --git a/src/plugin/template-plugins/base-plugin/plugin.cpp b/src/plugin/template-plugins/base-plugin/plugin.cpp index e69cee5..bca9865 100644 --- a/src/plugin/template-plugins/base-plugin/plugin.cpp +++ b/src/plugin/template-plugins/base-plugin/plugin.cpp @@ -1,29 +1,116 @@ -#include +#include #include #include #include #include #include "ndd_plugin_implement.h" +#include + +// 当编译标志 NOTEPAD_PLUGIN_DECLARE_PLUGIN_CONFIG 被定义 + // 将会自动 #include ,并提供几个插件相关的宏 + // #define NOTEPAD_VERSION "v1.23.2" + // #define PLUGIN_NAME "opencc-demo-plugin" + // #define PLUGIN_VERSION "0.1" + +// 使用可扩展宏 IDENTIFY_ +NOTEPAD_PLUGIN_METADATA_IDENTIFY_ { + USE_IDENTIFY_VARIABLES + + NOTEPAD_PLUGIN_METADATA("base-plugin", PLUGIN_VERSION, "author", u8"基本插件", ""); + + qInfo() << "[Plugin]" << "strPlugName:" << pProcData->m_strPlugName; + qInfo() << "[Plugin]" << "Version: " << pProcData->m_version; + qInfo() << "[Plugin]" << "strComment: " << pProcData->m_strComment; + qInfo() << "[Plugin]" << "Author: " << pProcData->m_auther; + qInfo() << "[Plugin]" << "strFilePath:" << pProcData->m_strFilePath; + + qInfo() << "[Plugin]" << "PLUGIN_VERSION: " << PLUGIN_VERSION; + qInfo() << "[Plugin]" << "NOTEPAD_VERSION:" << QString(u8"基于 %1 编译").arg(NOTEPAD_VERSION); + + // [Plugin] strPlugName: "base-plugin" + // [Plugin] Version: "0.1" + // [Plugin] strComment: "基本插件" + // [Plugin] Author: "author" + // [Plugin] strFilePath: "" + // [Plugin] PLUGIN_VERSION: 0.1 + // [Plugin] NOTEPAD_VERSION: "基于 v1.23.2 编译" -bool NDD_PROC_IDENTIFY(NDD_PROC_DATA* pProcData) { - // NOTEPAD_PLUGIN_METADATA - // (name, version, author, comment, filepath) - // 使用插件宏模板来完成简单的插件处理 - NOTEPAD_PLUGIN_METADATA("base-plugin", "0.1", "author", "基本插件", ""); return true; } - -int NDD_PROC_MAIN(QWidget* pNotepad, const QString& strFileName, std::functiongetCurEdit) { - // NOTEPAD_PLUGIN_IMPLEMENT - // (NddPluginImplement); - // 使用插件宏模板来完成基本的插件内容处理 - NddPluginImplement *imp = new NddPluginImplement(); +// 使用可扩展宏 IMPLEMENT_ ,在 _1 中将进行二级菜单扩展的全局声明 +NOTEPAD_PLUGIN_METADATA_IMPLEMENT_1 { + USE_IMPLEMENT_VARIABLES - // 这个插件是一个窗口需要显示 - // imp->show(); + // 输出:从插件中能获取的所有继承的对象名称 + QObject *parent = nullptr; + QString indent = ""; + + // 以 s_pNotepad 对象开始的父级探索 + { + parent = s_pNotepad; + // if 判断 + if (parent) { + qInfo() << PLUGIN_NAME << ":" << parent->objectName(); + } + // base-plugin:CCNotePad + + // while 简写 + qInfo() << "[Parent layer]"; + while (parent) { + qInfo() << QString("%1%2").arg(indent).arg(parent->objectName()); + parent = parent->parent(); + indent = indent.append(" "); + } + // [Parent layer] + // "CCNotePad" + } + + // 从 [s_]getCurEdit 开始的父级探索 + { + // if 判断形式,比较复杂 + // if (getCurEdit) // 从 getCurEdit 开始 + // { + // if (getCurEdit()) { + // // "" + // qInfo() << PLUGIN_NAME << ":" << getCurEdit()->objectName(); + // if (getCurEdit()->parent()) + // { // qt_tabwidget_stackedwidget + // qInfo() << PLUGIN_NAME << ":" << getCurEdit()->parent()->objectName(); + // if (getCurEdit()->parent()->parent()) + // { // editTabWidget + // qInfo() << PLUGIN_NAME << ":" << getCurEdit()->parent()->parent()->objectName(); + // if (getCurEdit()->parent()->parent()->parent()) + // { // centralWidget + // qInfo() << PLUGIN_NAME << ":" << getCurEdit()->parent()->parent()->parent()->objectName(); + // if (getCurEdit()->parent()->parent()->parent()->parent()) + // { // CCNotePad + // qInfo() << PLUGIN_NAME << ":" << getCurEdit()->parent()->parent()->parent()->parent()->objectName(); + // } + // } + // } + // } + // } + // } + + // while 判断形式,比较简单 + parent = getCurEdit(); + indent = ""; + qInfo() << "[Parent layer]"; + // while 简写 + while (parent) { + qInfo() << QString("%1%2").arg(indent).arg(parent->objectName()); + parent = parent->parent(); + indent = indent.append(" "); + } + // [Parent layer] + // "" + // " qt_tabwidget_stackedwidget" + // " editTabWidget" + // " centralWidget" + // " CCNotePad" + } - // 插件已成功实现 return 0; }