cmake-plugin: 添加获取 editor 的插件示例(base-plugin-editor)

This commit is contained in:
zinface 2023-04-25 15:19:41 +08:00
parent 893a3f69a9
commit d7e943aca0
5 changed files with 150 additions and 0 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}