mirror of https://gitee.com/cxasm/notepad--.git
cmake-plugin: 添加获取 editor 的插件示例(base-plugin-editor)
This commit is contained in:
parent
893a3f69a9
commit
d7e943aca0
|
@ -12,6 +12,7 @@ if(USE_NOTEPAD_PLUGIN)
|
|||
add_subdirectory(helloworld-next)
|
||||
# 基于源代码构建的系列插件模板
|
||||
add_subdirectory(template-plugins/base-plugin)
|
||||
add_subdirectory(template-plugins/base-plugin-editor)
|
||||
add_subdirectory(template-plugins/base-widget-plugin)
|
||||
add_subdirectory(template-plugins/base-widget-ui-plugin)
|
||||
add_subdirectory(template-plugins/base-secondary-menu-plugin)
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
# base-plugin-editor/CMakeLists.txt
|
||||
# 用于在源代码中构建一个插件的模板
|
||||
|
||||
# 如果不是在源代码中构建插件,请不要使用这个部分
|
||||
# 如果想在源代码中添加更多内置模板
|
||||
# 请替换 base-plugin-editor 为你的插件名称
|
||||
# base-plugin-editor -> your plugin name
|
||||
|
||||
set(LOCAL_PLUGIN_NAME "base-plugin-editor")
|
||||
set(LOCAL_PLUGIN_VERSION "0.1")
|
||||
|
||||
configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/config.h.in plugin-config.h @ONLY)
|
||||
|
||||
# base-plugin-editor 核心构建
|
||||
# 在模块化构建中,这个部分代表着构建 base-plugin-editor 插件
|
||||
# 1. 默认构建时产出的目标为 base-plugin-editor
|
||||
# 2. 在此处可对 base-plugin-editor 目标进行详细的构建计划
|
||||
|
||||
if(TRUE)
|
||||
# 准备构建 base-plugin-editor 主程序扩展
|
||||
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 $<TARGET_FILE_DIR:${PROJECT_NAME}>/plugin
|
||||
LIBRARY_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>/plugin
|
||||
ARCHIVE_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>/plugin)
|
||||
|
||||
# 控制是否安装到 bin/plugin 而各种配方之下,每个位置或许都不一样(特别是 Linux)
|
||||
# install(TARGETS ${LOCAL_PLUGIN_NAME} DESTINATION bin/plugin)
|
||||
endif(TRUE)
|
||||
|
||||
|
||||
# ----------------- base-plugin-editor 构建宏支持相关 ----------------- #
|
||||
|
||||
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)
|
|
@ -0,0 +1,10 @@
|
|||
#include "ndd_plugin_implement.h"
|
||||
|
||||
#include <qsciscintilla.h>
|
||||
#include <QDebug>
|
||||
|
||||
NddPluginImplement::NddPluginImplement(QsciScintilla *editor)
|
||||
{
|
||||
QString text = editor->text();
|
||||
qInfo() << "text:" << text;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef NDD_PLUGIN_IMPLEMENT_H
|
||||
#define NDD_PLUGIN_IMPLEMENT_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QsciScintilla;
|
||||
class NddPluginImplement
|
||||
{
|
||||
public:
|
||||
explicit NddPluginImplement(QsciScintilla *editor);
|
||||
};
|
||||
|
||||
#endif // NDD_PLUGIN_IMPLEMENT_H
|
|
@ -0,0 +1,36 @@
|
|||
#include <qobject.h>
|
||||
#include <qstring.h>
|
||||
#include <include/pluginGl.h>
|
||||
#include <functional>
|
||||
#include <qsciscintilla.h>
|
||||
#include "ndd_plugin_implement.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
/**************************************************************
|
||||
// 当编译标志 NOTEPAD_PLUGIN_DECLARE_PLUGIN_CONFIG 被定义
|
||||
// 将会自动 #include <plugin-config.h>,并提供几个插件相关的宏
|
||||
// #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(u8"基本插件(editor)", PLUGIN_VERSION, "author", u8"获取 editor 的内容", "");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 使用可扩展宏 IMPLEMENT_ ,在 _1 中将进行二级菜单扩展的全局声明
|
||||
NOTEPAD_PLUGIN_METADATA_IMPLEMENT_1 {
|
||||
USE_IMPLEMENT_VARIABLES
|
||||
|
||||
auto placeholder = s_getCurEdit();
|
||||
NddPluginImplement imp(placeholder);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue