diff --git a/.github/workflows/qt-build-test.yml b/.github/workflows/qt-build-test.yml index b46b507..1245336 100644 --- a/.github/workflows/qt-build-test.yml +++ b/.github/workflows/qt-build-test.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - qt_version: [5.15.2, 6.6.2] + qt_version: [6.6.2] arch: [win64_msvc2019_64, gcc_64] exclude: - os: windows-latest diff --git a/3rdparty/QConsoleWidget/QConsoleWidget.cpp b/3rdparty/QConsoleWidget/QConsoleWidget.cpp index 32223ca..8616eee 100644 --- a/3rdparty/QConsoleWidget/QConsoleWidget.cpp +++ b/3rdparty/QConsoleWidget/QConsoleWidget.cpp @@ -1,5 +1,6 @@ #include "QConsoleWidget.h" #include "QConsoleIODevice.h" +#include "wingsyntaxhighlighter.h" #include #include @@ -27,9 +28,6 @@ QConsoleWidget::QConsoleWidget(QWidget *parent) for (int i = 0; i < nConsoleChannels; i++) chanFormat_[i] = fmt; - chanFormat_[StandardOutput].setForeground(Qt::white); - chanFormat_[StandardError].setForeground(Qt::red); - setTextInteractionFlags(Qt::TextEditorInteraction); setUndoRedoEnabled(false); @@ -37,6 +35,16 @@ QConsoleWidget::QConsoleWidget(QWidget *parent) setMatchBraces(true); setDefaultTheme(); + auto theme = highlighter()->theme(); + auto color = theme.textColor(KSyntaxHighlighting::Theme::Normal); + chanFormat_[StandardOutput].setForeground(QColor(color)); + chanFormat_[StandardError].setForeground(Qt::red); + + connect(this, &QConsoleWidget::themeChanged, this, [this]() { + auto theme = highlighter()->theme(); + auto color = theme.textColor(KSyntaxHighlighting::Theme::Normal); + chanFormat_[StandardOutput].setForeground(QColor(color)); + }); } QConsoleWidget::~QConsoleWidget() {} @@ -72,8 +80,6 @@ void QConsoleWidget::setChannelCharFormat(ConsoleChannel ch, chanFormat_[ch] = fmt; } -QSize QConsoleWidget::sizeHint() const { return QSize(600, 400); } - QString QConsoleWidget::getCommandLine() { if (mode_ == Output) return QString(); diff --git a/3rdparty/QConsoleWidget/QConsoleWidget.h b/3rdparty/QConsoleWidget/QConsoleWidget.h index 01c9bf1..28ea7ef 100644 --- a/3rdparty/QConsoleWidget/QConsoleWidget.h +++ b/3rdparty/QConsoleWidget/QConsoleWidget.h @@ -53,7 +53,6 @@ public: QIODevice *device() const; QTextCharFormat channelCharFormat(ConsoleChannel ch) const; void setChannelCharFormat(ConsoleChannel ch, const QTextCharFormat &fmt); - virtual QSize sizeHint() const override; // write a formatted message to the console void write(const QString &message, const QTextCharFormat &fmt); static History &history(); diff --git a/3rdparty/WingCodeEdit b/3rdparty/WingCodeEdit index 910a385..608ab83 160000 --- a/3rdparty/WingCodeEdit +++ b/3rdparty/WingCodeEdit @@ -1 +1 @@ -Subproject commit 910a38521cb963cc40581bb8d98bf966eb706f17 +Subproject commit 608ab834bd9934e1aa7b4a0417e22e9f4f14da1a diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f6f445..70a8910 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(PROJECT_VERSION "2.2.0") +set(PROJECT_VERSION "2.2.1") find_package( QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network Concurrent @@ -186,6 +186,8 @@ set(CONTROL_SRC src/control/toast.cpp src/control/scriptingconsole.cpp src/control/scriptingconsole.h + src/control/scriptingconsolebase.h + src/control/scriptingconsolebase.cpp src/control/gotowidget.h src/control/gotowidget.cpp src/control/gotowidget.ui diff --git a/README.md b/README.md index e6e9b46..1a14875 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,13 @@ ## 软件编译运行情况 -> 对于 Qt 5 版本,仅支持 5.15.2 或更高版本,Qt 6 的话 6.6.2 或更高的版本,其他低版本由于关键库的 API 缺失和自身的一些 Bug,所以不提供支持。 +> 对于 Qt 5 版本,建议 5.15.2 或更高版本,Qt 6 的话 6.6.2 或更高的版本,其他低版本由于关键库的 API 缺失和自身的一些 Bug,所以请不要使用。 另外: -> QT5 版本主动编译支持将会在 2025/05/26 停止,届时相关 GitAction 自动化测试将会撤销。如果因特殊需要 QT5 版本,请咨询我商业合作和付费技术支持。 +> QT5 版本主动编译支持已停止,我不会再支持和修复相关问题,但接受 PR 。如果因特殊需要 QT5 版本,请咨询我商业合作和付费技术支持。 -  该仓库代码使用 Qt 5.15.2 和 6.6.2 在最新版 Windows 和 Ubuntu 编译情况: ![Status](https://github.com/Wing-summer/WingHexExplorer2/actions/workflows/qt-build-test.yml/badge.svg) +  该仓库代码使用 Qt 6.6.2 在最新版 Windows 和 Ubuntu 编译情况: ![Status](https://github.com/Wing-summer/WingHexExplorer2/actions/workflows/qt-build-test.yml/badge.svg) ## WingHexExplorer2 diff --git a/README_en.md b/README_en.md index f99c61f..1cb09be 100644 --- a/README_en.md +++ b/README_en.md @@ -91,11 +91,11 @@ Make sure that you follow [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) while contrib ## Status -> For Qt 5, only version 5.15.2 or higher is supported, and for Qt 6, only version 6.6.2 or higher is supported. Other lower versions are not supported due to missing APIs of key libraries and some bugs of their own. +> For Qt 5, only version 5.15.2 or higher is suggested, and for Qt 6, only version 6.6.2 or higher is recommended. Other lower versions are wired due to missing APIs of key libraries and some bugs of their own. And also: -> Active compilation support for QT5 will be discontinued on 2025/05/26, and the related GitAction automated tests will be revoked at that time. If you need QT5 version for special purposes, please consult me ​​for commercial cooperation and paid technical support. +> Support for QT5 had been stopped, and I will no longer fix related issues, but PR will be welcomed. If you need QT5 version for special purposes, please consult me ​​for commercial cooperation and paid technical support. The repository code compiles with Qt 5.15.2 and 6.6.2 on the latest versions of Windows and Ubuntu: ![Status](https://github.com/Wing-summer/WingHexExplorer2/actions/workflows/qt-build-test.yml/badge.svg) diff --git a/images/console.png b/images/console.png new file mode 100644 index 0000000..2b87db6 Binary files /dev/null and b/images/console.png differ diff --git a/images/scheme.png b/images/scheme.png deleted file mode 100644 index 9745a2e..0000000 Binary files a/images/scheme.png and /dev/null differ diff --git a/lang/zh_CN/winghex_zh_CN.ts b/lang/zh_CN/winghex_zh_CN.ts index ceb6ddf..88366fa 100644 --- a/lang/zh_CN/winghex_zh_CN.ts +++ b/lang/zh_CN/winghex_zh_CN.ts @@ -766,18 +766,18 @@ MainWindow - + File 文件 - - + + View 视图 - + About 关于 @@ -798,347 +798,347 @@ 选长: - + Edit 编辑 - + Script 脚本 - - - + + + Plugin 插件 - + Setting 设置 - - + + Log 日志 - + ExportFindResult 导出搜索结果 - + ClearFindResult 清空记录 - - + + FindResult 搜索结果 - - - - - - - + + + + + + + Copy 复制 - - - - - - - - + + + + + + + + CopyToClipBoard 数据已拷贝到粘贴板 - + LittleEndian 小端 - + BigEndian 大端 - + Number 数值 - - + + CheckSum 校验和 - - + + DeleteBookMark 删除书签 - - + + ClearBookMark 清空书签 - - - - + + + + BookMark 书签 - - + + DecodeText 解码字符串 - + ScriptConsole 脚本控制台 - - + + DVList 可视化列表 - - + + DVTree 可视化树数据 - - + + DVTable 可视化表格 - - + + DVText 可视化文本 - - + + Basic 基础 - + New 新建 - + OpenF 打开文件 - + OpenWorkSpace 打开工作区 - + RecentFiles 最近打开 - + Reload 重新加载 - - + + Save 保存 - + SaveAs 另存为 - + ConvertWS 转为工作区 - + Export 导出 - + SaveSel 保存选区字节 - - - - + + + + General 基本 - + Undo 撤销 - + Redo 恢复 - + Cut 剪切 - + Paste 粘贴 - + Delete 删除 - + Clone 克隆 - + Lookup 查询 - + Find 查找 - + Goto 跳转 - - + + Encoding 编码 - + FileInfo 文件信息 - - + + Hex 十六进制 - + CutHex 剪切(十六进制) - + CopyHex 复制(十六进制) - + PasteHex 粘贴(十六进制) - - + + Fill 填充 - + FillZero 填充零 - - - - - + + + + + MetaData 标注 - + DeleteMetadata 删除标注 - + ClearMetadata 清空标注 - + MetaDataEdit 编辑标注 - + DeleteMetaData 删除标注 - + ClearMetaData 清空标注 - + Display 显示 - + ViewText 文本预览 - + Scale 缩放 @@ -1188,771 +1188,771 @@ 启动脚本服务 - + SetupScriptEditor 构建脚本编辑器 - + SetupSetDialog 构建设置窗体 - + SetupPlgWidgets 启动插件组件 - + SetupDockingLayout 恢复 Dock 布局 - + SetupWaiting 启动即将完成 - + SetupFinished 启动完毕 - + NoExtension 无扩展 - - - - - - + + + + + + ExportResult 导出结果 - - - + + + NothingToSave 没有保存的数据 - - - - + + + + ClearResult 清空结果 - + OpenExt 打开 - 拓展 - + ResetScale 重置缩放 - + ShowMetafg 标注前景色 - + ShowMetabg 标注背景色 - + ShowMetaComment 批注 - + MetaShowAll 显示所有标注 - + MetaHideAll 隐藏所有标注 - + FileStatus 文件状态 - + InfoSave 是否保存 - + ReadOnly 可读写 - + SetLocked 启用/禁用锁定编辑 - + ErrUnLock 锁定编辑失败 - + SetOver 启用/禁用改变大小 - + ErrUnOver 锁定文件大小失败 - + Window 窗体 - + Editor 编辑器 - + Tools 工具 - + HexEditorLayout 编辑器布局 - + SetBaseAddr 设置基址 - + addressBase 基址 - + inputAddressBase 请输入基址 - + WarnBigBaseAddress 基址过大,你得到的地址将会不正确! - + ErrBaseAddress 非法基址输入 - + SetColInfo 显示/隐藏地址栏 - + SetHeaderInfo 显示/隐藏表头 - + SetAsciiString 显示/隐藏解码字符串 - + Layout 布局 - + Fullscreen 全屏 - + Default 默认 - - - + + + LayoutRestoring... 恢复布局中... - + RestoreLayout 恢复布局 - - + + SaveLayout 保存布局 - + ExportLog 导出日志 - + ClearLog 清空日志 - + InsepctQt 监视 Qt - + ScriptEditor 脚本编辑器 - + Scripts 脚本仓库 - + PluginFunctions 插件功能 - + ScriptSetting 脚本设置 - + PluginSettings 插件设置 - + Info 信息 - + Software 软件 - + Sponsor 赞助 - + CheckUpdate 检查更新 - + Wiki 网页 Wiki - + AboutQT 关于 QT - + SetPageIDEmptyTryUseName 设置页 ID 为空,尝试使用名称作为 ID - + SetPageDupNameIgnored 设置页重复的 ID 名称,已忽略加载 - + Plugin %1 contains a duplicate ID (%2) that is already registered by plugin %3 插件 %1 包含重复 ID (%2),该 ID 已被插件 %3 注册 - - + + ChooseFile 选择文件 - - - - - - - - - - - - - - - - - - - - - - - - Error - 错误 - - - - - FileNotExist - 文件不存在! - - - - - - + + + + + + + + + + + + + + + + + + + + Error + 错误 + + + + + FileNotExist + 文件不存在! + + + + + + + + + + FilePermission 因文件权限无法继续! - + ProjectFile (*.wingpro) 项目文件 (*.wingpro) - + ReloadSuccessfully 文件重新加载成功! - + ReloadUnSuccessfully 文件重新加载失败! - - - - - - - + + + + + + + ChooseSaveFile 请选择保存文件路径: - + NoMoreClone 克隆已到上限,无法继续操作! - + FindFininishBusy 查找任务繁忙,请勿重复查找! - + MayTooMuchFindResult 搜索数量已到达上限,结果可能不全,建议请按区段搜索。 - + SaveLayoutSuccess 保存布局成功 - + SaveLayoutError 保存布局失败 - + HasClonedView 该编辑页已被克隆编辑,如果关闭,相关联的页也会被关闭,你确认继续吗? - + SaveWorkSpace 保存工作区 - + WingHexWorkSpace (*.wingpro) 羽云十六进制工作区 (*.wingpro) - + ConfirmSave 正在关闭未保存的文件或工作区,你确定保存吗? - + Column %1 列 %1 - + ConfirmAPPSave 你尝试关闭程序,但仍存在未保存的文件或工作区,你确定保存这些更改吗? - - - - - - + + + + + + SaveSuccessfully 保存成功! - - + + SaveWSError 保存工作区错误! - + Warn 警告 - + ScriptObjShow 脚本对象 - + Opening... 打开文件中... - + WorkSpaceOpening... 打开工作区中... - + Reloading... 重载文件中... - + Saving... 保存中... - + SaveNewFirst 请首先保存新建的文件 - + AlreadyWorkSpace 已经是工作区,无需转化 - + ConvWorkSpaceFailed 转化为工作区失败 - + ConvWorkSpaceSuccess 转化为工作区成功 - + SavingAs... 另存为中... - + SaveUnSuccessfully 保存失败! - + Exporting... 导出中... - + ChooseExportFile 请选择导出文件路径: - + ExportSuccessfully 导出成功! - + ExportUnSuccessfully 导出失败! - + SavingSel... 保存选中字节中... - + SaveSelSuccess 保存选区字节成功! - + SaveSelError 保存选区字节失败,因文件不具有可写权限! - - + + CutToClipBoard 数据已剪切到粘贴板! - - + + UnCutToClipBoard 由于保持大小限制,数据剪切到粘贴板失败! - - + + UnCopyToClipBoard 由于保持大小限制,数据剪切到复制板失败! - - + + Finding... 查找中... - + DeleteSuccess 删除成功 - + DeleteFailed 删除失败 - + FindFininish 查找结果完毕! - + PleaseInputFill 请输入填充字节值 - + FillInputTruncWarn 填充输入数值过大,将会被截断填充 - + FillInputError 填充字节输入错误 - - + + InputComment 请输入批注: - - + + BookmarkDelSuccess 删除书签成功 - + BookmarkDelNoItem 无书签可删除 - + BookmarkClearSuccess 书签清空完毕 - - - + + + NoSelection 没有选区,无法继续的操作! - + NoMetaData 无可编辑标记 - + PleaseClearSel 请清空选择 - + MetaDelSuccess 元数据删除成功 - + MetaDelNoItem 无元数据可删除 - + MetaClearSuccess 元数据清空完毕 - + FindResultExporting... 查找结果导出中... - - + + EmptyFindResult 没有可导出的搜索结果! - + SaveFindResult 导出搜索结果成功! - + SaveFindResultError 导出结果失败! - + TooManyBytesDecode 超出解码字节限制…… - + LayoutSaving... 布局保存中... - + PleaseInput 请输入 - + LogExporting... 日志导出中... - + ExportLogError 导出日志失败! - + ExportLogSuccess 导出日志成功,路径: - + ClearLogSuccess 清空日志成功! - + BadNetwork 无法与远程服务器的更新检查建立连接,请检查网络。 - + NewestVersion 当前软件为最新版本 - - + + OlderVersion 你使用的软件为老版本,建议到 Github 和 Gitee 的仓库发行版下载更新。 - + CheckingUpdate 检查更新中…… - + Too much opened files 打开的文件过多,无法继续操作! - + FilePermissionSure2Quit 因文件权限无法保存,你确认要退出吗? - + UnknownErrorSure2Quit 因未知错误无法保存,你确认要退出吗? - + WorkSpaceUnSavedSure2Quit 工作区文件无法保存,你确认要退出吗? - + CopyLimit 拷贝字节超出限制 - + ErrOpenFileBelow 打开文件出现错误(由于权限不足),如下为打开错误的文件: @@ -2402,102 +2402,107 @@ QEditConfig - + Preference 设置 - + Theme 主题 - + FontSize 字体大小 - + Font 字体 - + Indentation 缩进 - + Options 选项 - + LineNumber 行号 - + WordWrap 换行 - + Whitespace 空格可见 - + AutoCloseChar 匹配填充 - + MatchBraces 高亮括号 - + Folding 代码折叠 - + LongLineEdge 长线边缘 - + IndentGuides 缩进线 - + Tab width 制表符宽度 - + Default 默认 - + IndentMixed 混合缩进 - + IndentSpaces 空格缩进 - + + Console + 控制台 + + + IndentTabs 制表符缩进 - + Edit 编辑 @@ -4381,36 +4386,39 @@ ScriptingConsole - - Scripting console for WingHexExplorer - 羽云十六进制编辑器脚本控制台 - - - - >>>> Powered by AngelScript <<<< - >>>> 由 AngelScript 引擎提供支持 <<<< - - - + [Info] 【信息】 - + [Warn] 【警告】 - + [Error] 【错误】 - + [Console] 【控制台】 + + ScriptingConsoleBase + + + Scripting console for WingHexExplorer + 羽云十六进制编辑器脚本控制台 + + + + >>>> Powered by AngelScript <<<< + >>>> 由 AngelScript 引擎提供支持 <<<< + + ScriptingDialog @@ -4546,7 +4554,6 @@ - Format 代码样式 @@ -4607,128 +4614,133 @@ 设置 - + ClangFormat Clang Format - + + Console + 控制台 + + + Local 本地 - + Global 全局 - + Variables 变量 - + ConsoleOutput 输出 - + StackTrace 栈跟踪 - + Symbol 符号 - - - - - - + + + + + + Error 错误 - + Too much opened files 打开的文件过多,无法继续操作! - + ConfirmSave 正在关闭未保存的脚本文件,你确定保存吗? - + ScriptSaveFailedClose 脚本保存失败,你仍确认关闭吗? - + Debuging... 调试中... - + Running... 运行中... - - + + ChooseFile 选择文件 - - - + + + FilePermission 因文件权限无法继续! - + ReloadSuccessfully 文件重新加载成功! - + ReloadUnSuccessfully 文件重新加载失败! - + ChooseSaveFile 请选择保存文件路径: - - + + SaveSuccessfully 保存成功! - + SaveUnSuccessfully 保存失败! - + FormatCodeFailed 代码格式化失败 - - + + CannotSave2RunScript 无法保存,故无法继续运行脚本。 - - + + ScriptStillRunning 脚本仍在运行,你确定要退出吗? @@ -4798,27 +4810,27 @@ 删除断点 - + Info 信息 - + Software 软件 - + Sponsor 赞助 - + Wiki 网页 Wiki - + AboutQT 关于 QT @@ -4865,12 +4877,12 @@ ShowTextDialog - + General 基本 - + Copy 复制 @@ -4880,42 +4892,42 @@ 文本浏览 - + TooHugeFile 文件内容过大 - + Edit 编辑 - + View 视图 - + Find 查找 - + Goto 跳转 - + Encoding 编码 - + Display 显示 - + CopyToClipBoard 数据已拷贝到粘贴板 diff --git a/lang/zh_TW/winghex_zh_TW.ts b/lang/zh_TW/winghex_zh_TW.ts index 90be90c..7a97141 100644 --- a/lang/zh_TW/winghex_zh_TW.ts +++ b/lang/zh_TW/winghex_zh_TW.ts @@ -766,18 +766,18 @@ MainWindow - + File - - + + View 視圖 - + About 關於 @@ -798,347 +798,347 @@ 選長: - + Edit 編輯 - + Script 腳本 - - - + + + Plugin 插件 - + Setting 設置 - - + + Log 日誌 - + ExportFindResult 導出搜索結果 - + ClearFindResult 清空記錄 - - + + FindResult 搜索結果 - - - - - - - + + + + + + + Copy 複製 - - - - - - - - + + + + + + + + CopyToClipBoard 數據已拷貝到粘貼板 - + LittleEndian 小端 - + BigEndian 大端 - + Number 數值 - - + + CheckSum 校驗和 - - + + DeleteBookMark 刪除書簽 - - + + ClearBookMark 清空書簽 - - - - + + + + BookMark 書簽 - - + + DecodeText 解碼字串 - + ScriptConsole 腳本控制臺 - - + + DVList 可視化列表 - - + + DVTree 可視化樹數據 - - + + DVTable 可視化表格 - - + + DVText 可視化文本 - - + + Basic 基礎 - + New 新建 - + OpenF 打開檔 - + OpenWorkSpace 打開工作區 - + RecentFiles 最近打開 - + Reload 重新加載 - - + + Save 保存 - + SaveAs 另存為 - + ConvertWS 轉為工作區 - + Export 導出 - + SaveSel 保存選區位元組 - - - - + + + + General 基本 - + Undo 撤銷 - + Redo 恢復 - + Cut 剪切 - + Paste 粘貼 - + Delete 刪除 - + Clone 克隆 - + Lookup 查詢 - + Find 查找 - + Goto 跳轉 - - + + Encoding 編碼 - + FileInfo 檔資訊 - - + + Hex 十六進制 - + CutHex 剪切(十六進制) - + CopyHex 複製(十六進制) - + PasteHex 粘貼(十六進制) - - + + Fill 填充 - + FillZero 填充零 - - - - - + + + + + MetaData 標注 - + DeleteMetadata 刪除標注 - + ClearMetadata 清空標注 - + MetaDataEdit 編輯標注 - + DeleteMetaData 刪除標注 - + ClearMetaData 清空標注 - + Display 顯示 - + ViewText 文本預覽 - + Scale 縮放 @@ -1188,771 +1188,771 @@ 啟動腳本服務 - + SetupScriptEditor 構建腳本編輯器 - + SetupSetDialog 構建設置窗體 - + SetupPlgWidgets 啟動插件組件 - + SetupDockingLayout 恢復 Dock 佈局 - + SetupWaiting 啟動即將完成 - + SetupFinished 啟動完畢 - + NoExtension 無擴展 - - - - - - + + + + + + ExportResult 導出結果 - - - + + + NothingToSave 沒有保存的數據 - - - - + + + + ClearResult 清空結果 - + OpenExt 打開 - 拓展 - + ResetScale 重置縮放 - + ShowMetafg 標注前景色 - + ShowMetabg 標注背景色 - + ShowMetaComment 批註 - + MetaShowAll 顯示所有標注 - + MetaHideAll 隱藏所有標注 - + FileStatus 檔狀態 - + InfoSave 是否保存 - + ReadOnly 可讀寫 - + SetLocked 啟用/禁用鎖定編輯 - + ErrUnLock 鎖定編輯失敗 - + SetOver 啟用/禁用改變大小 - + ErrUnOver 鎖定檔大小失敗 - + Window 窗體 - + Editor 編輯器 - + Tools 工具 - + HexEditorLayout 編輯器佈局 - + SetBaseAddr 設置基址 - + addressBase 基址 - + inputAddressBase 請輸入基址 - + WarnBigBaseAddress 基址過大,你得到的地址將會不正確! - + ErrBaseAddress 非法基址輸入 - + SetColInfo 顯示/隱藏地址欄 - + SetHeaderInfo 顯示/隱藏表頭 - + SetAsciiString 顯示/隱藏解碼字串 - + Layout 佈局 - + Fullscreen 全屏 - + Default 默認 - - - + + + LayoutRestoring... 恢復佈局中... - + RestoreLayout 恢復佈局 - - + + SaveLayout 保存佈局 - + ExportLog 導出日誌 - + ClearLog 清空日誌 - + InsepctQt 監視 Qt - + ScriptEditor 腳本編輯器 - + Scripts 腳本倉庫 - + PluginFunctions 插件功能 - + ScriptSetting 腳本設置 - + PluginSettings 插件設置 - + Info 資訊 - + Software 軟體 - + Sponsor 贊助 - + CheckUpdate 檢查更新 - + Wiki 網頁 Wiki - + AboutQT 關於 QT - + SetPageIDEmptyTryUseName 設置頁 ID 為空,嘗試使用名稱作為 ID - + SetPageDupNameIgnored 設置頁重複的 ID 名稱,已忽略加載 - + Plugin %1 contains a duplicate ID (%2) that is already registered by plugin %3 插件 %1 包含重複 ID (%2),該 ID 已被插件 %3 註冊 - - + + ChooseFile 選擇檔 - - - - - - - - - - - - - - - - - - - - - - - - Error - 錯誤 - - - - - FileNotExist - 檔不存在! - - - - - - + + + + + + + + + + + + + + + + + + + + Error + 錯誤 + + + + + FileNotExist + 檔不存在! + + + + + + + + + + FilePermission 因檔許可權無法繼續! - + ProjectFile (*.wingpro) 專案檔 (*.wingpro) - + ReloadSuccessfully 檔重新加載成功! - + ReloadUnSuccessfully 檔重新加載失敗! - - - - - - - + + + + + + + ChooseSaveFile 請選擇保存檔路徑: - + NoMoreClone 克隆已到上限,無法繼續操作! - + FindFininishBusy 查找任務繁忙,請勿重複查找! - + MayTooMuchFindResult 搜索數量已到達上限,結果可能不全,建議請按區段搜索。 - + SaveLayoutSuccess 保存佈局成功 - + SaveLayoutError 保存佈局失敗 - + HasClonedView 該編輯頁已被克隆編輯,如果關閉,相關聯的頁也會被關閉,你確認繼續嗎? - + SaveWorkSpace 保存工作區 - + WingHexWorkSpace (*.wingpro) 羽雲十六進制工作區 (*.wingpro) - + ConfirmSave 正在關閉未保存的檔或工作區,你確定保存嗎? - + Column %1 列 %1 - + ConfirmAPPSave 你嘗試關閉程式,但仍存在未保存的檔或工作區,你確定保存這些更改嗎? - - - - - - + + + + + + SaveSuccessfully 保存成功! - - + + SaveWSError 保存工作區錯誤! - + Warn 警告 - + ScriptObjShow 腳本對象 - + Opening... 打開檔中... - + WorkSpaceOpening... 打開工作區中... - + Reloading... 重載檔中... - + Saving... 保存中... - + SaveNewFirst 請首先保存新建的檔 - + AlreadyWorkSpace 已經是工作區,無需轉化 - + ConvWorkSpaceFailed 轉化為工作區失敗 - + ConvWorkSpaceSuccess 轉化為工作區成功 - + SavingAs... 另存為中... - + SaveUnSuccessfully 保存失敗! - + Exporting... 導出中... - + ChooseExportFile 請選擇導出檔路徑: - + ExportSuccessfully 導出成功! - + ExportUnSuccessfully 導出失敗! - + SavingSel... 保存選中位元組中... - + SaveSelSuccess 保存選區位元組成功! - + SaveSelError 保存選區位元組失敗,因檔不具有可寫許可權! - - + + CutToClipBoard 數據已剪切到粘貼板! - - + + UnCutToClipBoard 由於保持大小限制,數據剪切到粘貼板失敗! - - + + UnCopyToClipBoard 由於保持大小限制,數據剪切到複製板失敗! - - + + Finding... 查找中... - + DeleteSuccess 刪除成功 - + DeleteFailed 刪除失敗 - + FindFininish 查找結果完畢! - + PleaseInputFill 請輸入填充位元組值 - + FillInputTruncWarn 填充輸入數值過大,將會被截斷填充 - + FillInputError 填充位元組輸入錯誤 - - + + InputComment 請輸入批註: - - + + BookmarkDelSuccess 刪除書簽成功 - + BookmarkDelNoItem 無書簽可刪除 - + BookmarkClearSuccess 書簽清空完畢 - - - + + + NoSelection 沒有選區,無法繼續的操作! - + NoMetaData 無可編輯標記 - + PleaseClearSel 請清空選擇 - + MetaDelSuccess 元數據刪除成功 - + MetaDelNoItem 無元數據可刪除 - + MetaClearSuccess 元數據清空完畢 - + FindResultExporting... 查找結果導出中... - - + + EmptyFindResult 沒有可導出的搜索結果! - + SaveFindResult 導出搜索結果成功! - + SaveFindResultError 導出結果失敗! - + TooManyBytesDecode 超出解碼位元組限制…… - + LayoutSaving... 佈局保存中... - + PleaseInput 請輸入 - + LogExporting... 日誌導出中... - + ExportLogError 導出日誌失敗! - + ExportLogSuccess 導出日誌成功,路徑: - + ClearLogSuccess 清空日誌成功! - + BadNetwork 無法與遠程伺服器的更新檢查建立連接,請檢查網路。 - + NewestVersion 當前軟體為最新版本 - - + + OlderVersion 你使用的軟體為老版本,建議到 Github 和 Gitee 的倉庫發行版下載更新。 - + CheckingUpdate 檢查更新中…… - + Too much opened files 打開的檔過多,無法繼續操作! - + FilePermissionSure2Quit 因檔許可權無法保存,你確認要退出嗎? - + UnknownErrorSure2Quit 因未知錯誤無法保存,你確認要退出嗎? - + WorkSpaceUnSavedSure2Quit 工作區檔無法保存,你確認要退出嗎? - + CopyLimit 拷貝位元組超出限制 - + ErrOpenFileBelow 打開檔出現錯誤(由於許可權不足),如下為打開錯誤的檔: @@ -2402,102 +2402,107 @@ QEditConfig - + Preference 設置 - + Theme 主題 - + FontSize 字體大小 - + Font 字體 - + Indentation 縮進 - + Options 選項 - + LineNumber 行號 - + WordWrap 換行 - + Whitespace 空格可見 - + AutoCloseChar 匹配填充 - + MatchBraces 括號匹配 - + Folding 代碼折疊 - + LongLineEdge 長線邊緣 - + IndentGuides 縮進線 - + Tab width 跳位字元寬度 - + Default 默認 - + IndentMixed 混合縮進 - + IndentSpaces 空格縮進 - + + Console + 控制台 + + + IndentTabs 定位字元縮進 - + Edit 編輯 @@ -4381,36 +4386,39 @@ ScriptingConsole - - Scripting console for WingHexExplorer - 羽雲十六進制編輯器腳本控制臺 - - - - >>>> Powered by AngelScript <<<< - >>>> 由 AngelScript 引擎提供支持 <<<< - - - + [Info] 【資訊】 - + [Warn] 【警告】 - + [Error] 【錯誤】 - + [Console] 【控制臺】 + + ScriptingConsoleBase + + + Scripting console for WingHexExplorer + 羽雲十六進制編輯器腳本控制臺 + + + + >>>> Powered by AngelScript <<<< + >>>> 由 AngelScript 引擎提供支持 <<<< + + ScriptingDialog @@ -4546,7 +4554,6 @@ - Format 代碼樣式 @@ -4607,128 +4614,133 @@ 設置 - + ClangFormat Clang Format - + + Console + 控制台 + + + Local 本地 - + Global 全局 - + Variables 變數 - + ConsoleOutput 輸出 - + StackTrace 棧跟蹤 - + Symbol 符號 - - - - - - + + + + + + Error 錯誤 - + Too much opened files 打開的檔過多,無法繼續操作! - + ConfirmSave 正在關閉未保存的腳本檔,你確定保存嗎? - + ScriptSaveFailedClose 腳本保存失敗,你仍確認關閉嗎? - + Debuging... 調試中... - + Running... 運行中... - - + + ChooseFile 選擇檔 - - - + + + FilePermission 因檔許可權無法繼續! - + ReloadSuccessfully 檔重新加載成功! - + ReloadUnSuccessfully 檔重新加載失敗! - + ChooseSaveFile 請選擇保存檔路徑: - - + + SaveSuccessfully 保存成功! - + SaveUnSuccessfully 保存失敗! - + FormatCodeFailed 代碼格式化失敗 - - + + CannotSave2RunScript 無法保存,故無法繼續運行腳本。 - - + + ScriptStillRunning 腳本仍在運行,你確定要退出嗎? @@ -4798,27 +4810,27 @@ 刪除中斷點 - + Info 資訊 - + Software 軟體 - + Sponsor 贊助 - + Wiki 網頁 Wiki - + AboutQT 關於 QT @@ -4865,12 +4877,12 @@ ShowTextDialog - + General 基本 - + Copy 複製 @@ -4880,42 +4892,42 @@ 文本流覽 - + TooHugeFile 檔內容過大 - + Edit 編輯 - + View 視圖 - + Find 查找 - + Goto 跳轉 - + Encoding 編碼 - + Display 顯示 - + CopyToClipBoard 數據已拷貝到粘貼板 diff --git a/resources.qrc b/resources.qrc index 6d9d6d8..b75d821 100644 --- a/resources.qrc +++ b/resources.qrc @@ -11,6 +11,7 @@ images/closefile.png images/codefmt.png images/codeformat.png + images/console.png images/convpro.png images/copy.png images/copyhex.png @@ -82,7 +83,6 @@ images/savesel.png images/scale.png images/scalereset.png - images/scheme.png images/script.png images/scriptdbg/bp.png images/scriptdbg/delbp.png diff --git a/src/class/scriptsettings.cpp b/src/class/scriptsettings.cpp index 1f71f05..5e3c6f1 100644 --- a/src/class/scriptsettings.cpp +++ b/src/class/scriptsettings.cpp @@ -1,31 +1,457 @@ +/*============================================================================== +** Copyright (C) 2024-2027 WingSummer +** +** This program is free software: you can redistribute it and/or modify it under +** the terms of the GNU Affero General Public License as published by the Free +** Software Foundation, version 3. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +** details. +** +** You should have received a copy of the GNU Affero General Public License +** along with this program. If not, see . +** ============================================================================= +*/ + #include "scriptsettings.h" +#include +#include + +#include "settings/settings.h" +#include "wingcodeedit.h" + +#include +#include +#include + +#define WRITE_CONFIG_EDITOR_SET(config, flag, dvalue) \ + if (this->_setUnsavedEditor.testFlag(flag)) { \ + WRITE_CONFIG(config, dvalue); \ + _setUnsavedEditor.setFlag(flag, false); \ + } + +#define WRITE_CONFIG_CONSOLE_SET(config, flag, dvalue) \ + if (this->_setUnsavedConsole.testFlag(flag)) { \ + WRITE_CONFIG(config, dvalue); \ + _setUnsavedConsole.setFlag(flag, false); \ + } + Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_FONT, ("codeedit.font")) Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_FONT_SIZE, ("codeedit.fontsize")) -Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_LEADING_WHITESPACE, - ("codeedit.leading_whitespace")) -Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_TRAILING_WHITESPACE, - ("codeedit.trailing_whitespace")) -Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_TABS, ("codeedit.show_tabs")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_THEME, ("codeedit.theme")) Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_TABS_WIDTH, ("codeedit.tab_width")) -Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_REPLACE_TABS, - ("codeedit.replace_tabs")) -Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_REMOVE_TRAILING, - ("codeedit.remove_trailing")) -Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_PRESERVE_TRAILING_INDENT, - ("codeedit.preserve_trailing_indent")) -Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_LINE_ENDINGS, - ("codeedit.line_endings")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_INDENTATION, + ("codeedit.indentation")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_WORD_WRAP, ("codeedit.word_wrap")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_MATCH_BRACES, + ("codeedit.match_braces")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_LINENUMBER, + ("codeedit.linenumber")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_FOLDING, ("codeedit.folding")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_INDENTGUIDES, + ("codeedit.indentguides")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_LONGLINEEDGE, + ("codeedit.longlineedge")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_SHOW_WHITESPACE, + ("codeedit.whitespace")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_AUTO_CLOSE_CHAR, + ("codeedit.auto_close_char")) + +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_FONT, ("console.font")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_FONT_SIZE, ("console.fontsize")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_THEME, ("console.theme")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_TABS_WIDTH, ("console.tab_width")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_INDENTATION, ("console.indentation")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_MATCH_BRACES, + ("console.match_braces")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_SHOW_WHITESPACE, + ("console.whitespace")) +Q_GLOBAL_STATIC_WITH_ARGS(QString, CONSOLE_AUTO_CLOSE_CHAR, + ("console.auto_close_char")) ScriptSettings &ScriptSettings::instance() { static ScriptSettings ins; return ins; } -void ScriptSettings::load() {} +void ScriptSettings::load() { + auto defaultFontSize = _defaultFont.pointSize(); + Q_ASSERT(defaultFontSize > 0); + HANDLE_CONFIG; -void ScriptSettings::save(SETTINGS cat) {} + READ_CONFIG_STRING(m_editorFontFamily, CODEEDIT_FONT, + _defaultFont.family()); + if (!QFontInfo(QFont(m_editorFontFamily)).exactMatch()) { + m_editorFontFamily = _defaultFont.family(); + } + READ_CONFIG_STRING(m_consoleFontFamily, CONSOLE_FONT, + _defaultFont.family()); + if (!QFontInfo(QFont(m_consoleFontFamily)).exactMatch()) { + m_consoleFontFamily = _defaultFont.family(); + } -void ScriptSettings::reset(SETTINGS cat) {} + READ_CONFIG_INT_POSITIVE(m_editorfontSize, CODEEDIT_FONT_SIZE, 10); + m_editorfontSize = qBound(6, m_editorfontSize, 50); + READ_CONFIG_INT_POSITIVE(m_consolefontSize, CONSOLE_FONT_SIZE, 10); + m_consolefontSize = qBound(6, m_consolefontSize, 50); -ScriptSettings::ScriptSettings() : QObject() {} + READ_CONFIG_STRING(m_editorTheme, CODEEDIT_THEME, {}); + if (!WingCodeEdit::syntaxRepo().theme(m_editorTheme).isValid()) { + m_editorTheme.clear(); + } + READ_CONFIG_STRING(m_consoleTheme, CONSOLE_THEME, {}); + if (!WingCodeEdit::syntaxRepo().theme(m_consoleTheme).isValid()) { + m_consoleTheme.clear(); + } + + READ_CONFIG_INT_POSITIVE(m_editorTabWidth, CODEEDIT_TABS_WIDTH, 4); + m_editorTabWidth = qBound(2, m_editorTabWidth, 32); + READ_CONFIG_INT_POSITIVE(m_consoleTabWidth, CONSOLE_TABS_WIDTH, 4); + m_consoleTabWidth = qBound(2, m_consoleTabWidth, 32); + + READ_CONFIG_INT(m_editorInden, CODEEDIT_INDENTATION, 0); + m_editorInden = qBound(0, m_editorInden, 2); + READ_CONFIG_INT(m_consoleInden, CONSOLE_INDENTATION, 0); + m_consoleInden = qBound(0, m_consoleInden, 2); + + READ_CONFIG_BOOL(m_editorMatchBraces, CODEEDIT_MATCH_BRACES, true); + READ_CONFIG_BOOL(m_consoleMatchBraces, CONSOLE_MATCH_BRACES, true); + + READ_CONFIG_BOOL(m_editorWordWrap, CODEEDIT_WORD_WRAP, false); + READ_CONFIG_BOOL(m_editorShowLineNumber, CODEEDIT_SHOW_LINENUMBER, true); + READ_CONFIG_BOOL(m_editorFolding, CODEEDIT_SHOW_FOLDING, true); + READ_CONFIG_BOOL(m_editorShowGuideLine, CODEEDIT_SHOW_INDENTGUIDES, true); + READ_CONFIG_BOOL(m_editorShowLineEdges, CODEEDIT_SHOW_LONGLINEEDGE, false); + + READ_CONFIG_BOOL(m_editorShowWhiteSpace, CODEEDIT_SHOW_WHITESPACE, false); + READ_CONFIG_BOOL(m_consoleShowWhiteSpace, CONSOLE_SHOW_WHITESPACE, false); + + READ_CONFIG_BOOL(m_editorAutoCloseChar, CODEEDIT_AUTO_CLOSE_CHAR, true); + READ_CONFIG_BOOL(m_consoleAutoCloseChar, CONSOLE_AUTO_CLOSE_CHAR, true); +} + +void ScriptSettings::save(SETTINGS cat) { + HANDLE_CONFIG; + if (cat.testFlag(SETTING::EDITOR)) { + WRITE_CONFIG_EDITOR_SET(CODEEDIT_FONT, SETTING_ITEM::FONT, + m_editorFontFamily); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_FONT_SIZE, SETTING_ITEM::FONT_SIZE, + m_editorfontSize); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_THEME, SETTING_ITEM::THEME, + m_editorTheme); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH, + m_editorTabWidth); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_INDENTATION, SETTING_ITEM::INDENTATION, + m_editorInden); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_MATCH_BRACES, + SETTING_ITEM::MATCH_BRACES, + m_editorMatchBraces); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_WORD_WRAP, SETTING_ITEM::WORD_WRAP, + m_editorWordWrap); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_LINENUMBER, + SETTING_ITEM::SHOW_LINENUMBER, + m_editorShowLineNumber); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_FOLDING, + SETTING_ITEM::SHOW_FOLDING, m_editorFolding); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_INDENTGUIDES, + SETTING_ITEM::SHOW_INDENTGUIDES, + m_editorShowGuideLine); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_LONGLINEEDGE, + SETTING_ITEM::SHOW_LONGLINEEDGE, + m_editorShowLineEdges); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_WHITESPACE, + SETTING_ITEM::SHOW_WHITESPACE, + m_editorShowWhiteSpace); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_AUTO_CLOSE_CHAR, + SETTING_ITEM::AUTO_CLOSE_CHAR, + m_editorAutoCloseChar); + emit editorSettingsUpdate(); + } + + if (cat.testFlag(SETTING::CONSOLE)) { + WRITE_CONFIG_CONSOLE_SET(CONSOLE_FONT, SETTING_ITEM::FONT, + m_consoleFontFamily); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_FONT_SIZE, SETTING_ITEM::FONT_SIZE, + m_consolefontSize); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_THEME, SETTING_ITEM::THEME, + m_consoleTheme); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH, + m_consoleTabWidth); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_INDENTATION, SETTING_ITEM::INDENTATION, + m_consoleInden); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_MATCH_BRACES, + SETTING_ITEM::MATCH_BRACES, + m_consoleMatchBraces); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_SHOW_WHITESPACE, + SETTING_ITEM::SHOW_WHITESPACE, + m_consoleShowWhiteSpace); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_AUTO_CLOSE_CHAR, + SETTING_ITEM::AUTO_CLOSE_CHAR, + m_consoleAutoCloseChar); + emit consoleSettingUpdate(); + } +} + +void ScriptSettings::reset(SETTINGS cat) { + HANDLE_CONFIG; + if (cat.testFlag(SETTING::EDITOR)) { + WRITE_CONFIG_EDITOR_SET(CODEEDIT_FONT, SETTING_ITEM::FONT, + _defaultFont.defaultFamily()); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_FONT_SIZE, SETTING_ITEM::FONT_SIZE, + 10); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_THEME, SETTING_ITEM::THEME, {}); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH, + 4); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_INDENTATION, SETTING_ITEM::INDENTATION, + 0); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_MATCH_BRACES, + SETTING_ITEM::MATCH_BRACES, true); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_WORD_WRAP, SETTING_ITEM::WORD_WRAP, + false); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_LINENUMBER, + SETTING_ITEM::SHOW_LINENUMBER, true); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_FOLDING, + SETTING_ITEM::SHOW_FOLDING, true); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_INDENTGUIDES, + SETTING_ITEM::SHOW_INDENTGUIDES, true); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_LONGLINEEDGE, + SETTING_ITEM::SHOW_LONGLINEEDGE, false); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_WHITESPACE, + SETTING_ITEM::SHOW_WHITESPACE, false); + WRITE_CONFIG_EDITOR_SET(CODEEDIT_AUTO_CLOSE_CHAR, + SETTING_ITEM::AUTO_CLOSE_CHAR, true); + } + + if (cat.testFlag(SETTING::CONSOLE)) { + WRITE_CONFIG_CONSOLE_SET(CONSOLE_FONT, SETTING_ITEM::FONT, + _defaultFont.defaultFamily()); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_FONT_SIZE, SETTING_ITEM::FONT_SIZE, + 10); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_THEME, SETTING_ITEM::THEME, {}); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH, + 4); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_INDENTATION, SETTING_ITEM::INDENTATION, + 0); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_MATCH_BRACES, + SETTING_ITEM::MATCH_BRACES, true); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_SHOW_WHITESPACE, + SETTING_ITEM::SHOW_WHITESPACE, false); + WRITE_CONFIG_CONSOLE_SET(CONSOLE_AUTO_CLOSE_CHAR, + SETTING_ITEM::AUTO_CLOSE_CHAR, true); + } + + load(); +} + +ScriptSettings::ScriptSettings() : QObject() { + _defaultFont = qApp->font(); + load(); +} + +bool ScriptSettings::consoleAutoCloseChar() const { + return m_consoleAutoCloseChar; +} + +void ScriptSettings::setConsoleAutoCloseChar(bool newConsoleAutoCloseChar) { + if (m_consoleAutoCloseChar != newConsoleAutoCloseChar) { + m_consoleAutoCloseChar = newConsoleAutoCloseChar; + _setUnsavedConsole.setFlag(SETTING_ITEM::AUTO_CLOSE_CHAR); + } +} + +bool ScriptSettings::editorAutoCloseChar() const { + return m_editorAutoCloseChar; +} + +void ScriptSettings::setEditorAutoCloseChar(bool newEditorAutoCloseChar) { + if (m_editorAutoCloseChar != newEditorAutoCloseChar) { + m_editorAutoCloseChar = newEditorAutoCloseChar; + _setUnsavedEditor.setFlag(SETTING_ITEM::AUTO_CLOSE_CHAR); + } +} + +bool ScriptSettings::consoleShowWhiteSpace() const { + return m_consoleShowWhiteSpace; +} + +void ScriptSettings::setConsoleShowWhiteSpace(bool newConsoleShowWhiteSpace) { + if (m_consoleShowWhiteSpace != newConsoleShowWhiteSpace) { + m_consoleShowWhiteSpace = newConsoleShowWhiteSpace; + _setUnsavedConsole.setFlag(SETTING_ITEM::SHOW_WHITESPACE); + } +} + +bool ScriptSettings::editorShowWhiteSpace() const { + return m_editorShowWhiteSpace; +} + +void ScriptSettings::setEditorShowWhiteSpace(bool newEditorShowWhiteSpace) { + if (m_editorShowWhiteSpace != newEditorShowWhiteSpace) { + m_editorShowWhiteSpace = newEditorShowWhiteSpace; + _setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_WHITESPACE); + } +} + +bool ScriptSettings::editorShowLineEdges() const { + return m_editorShowLineEdges; +} + +void ScriptSettings::setEditorShowLineEdges(bool newEditorShowLineEdges) { + if (m_editorShowLineEdges != newEditorShowLineEdges) { + m_editorShowLineEdges = newEditorShowLineEdges; + _setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_LONGLINEEDGE); + } +} + +bool ScriptSettings::editorShowGuideLine() const { + return m_editorShowGuideLine; +} + +void ScriptSettings::setEditorShowGuideLine(bool newEditorShowGuidLine) { + if (m_editorShowGuideLine != newEditorShowGuidLine) { + m_editorShowGuideLine = newEditorShowGuidLine; + _setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_INDENTGUIDES); + } +} + +bool ScriptSettings::editorFolding() const { return m_editorFolding; } + +void ScriptSettings::setEditorFolding(bool newEditorFolding) { + if (m_editorFolding != newEditorFolding) { + m_editorFolding = newEditorFolding; + _setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_FOLDING); + } +} + +bool ScriptSettings::editorShowLineNumber() const { + return m_editorShowLineNumber; +} + +void ScriptSettings::setEditorShowLineNumber(bool newEditorShowLineNumber) { + if (m_editorShowLineNumber != newEditorShowLineNumber) { + m_editorShowLineNumber = newEditorShowLineNumber; + _setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_LINENUMBER); + } +} + +bool ScriptSettings::editorWordWrap() const { return m_editorWordWrap; } + +void ScriptSettings::setEditorWordWrap(bool newEditorWordWrap) { + if (m_editorWordWrap != newEditorWordWrap) { + m_editorWordWrap = newEditorWordWrap; + _setUnsavedEditor.setFlag(SETTING_ITEM::WORD_WRAP); + } +} + +bool ScriptSettings::consoleMatchBraces() const { return m_consoleMatchBraces; } + +void ScriptSettings::setConsoleMatchBraces(bool newConsoleMatchBraces) { + if (m_consoleMatchBraces != newConsoleMatchBraces) { + m_consoleMatchBraces = newConsoleMatchBraces; + _setUnsavedConsole.setFlag(SETTING_ITEM::MATCH_BRACES); + } +} + +bool ScriptSettings::editorMatchBraces() const { return m_editorMatchBraces; } + +void ScriptSettings::setEditorMatchBraces(bool newEditorMatchBraces) { + if (m_editorMatchBraces != newEditorMatchBraces) { + m_editorMatchBraces = newEditorMatchBraces; + _setUnsavedEditor.setFlag(SETTING_ITEM::MATCH_BRACES); + } +} + +int ScriptSettings::consoleInden() const { return m_consoleInden; } + +void ScriptSettings::setConsoleInden(int newConsoleInden) { + if (m_consoleInden != newConsoleInden) { + m_consoleInden = newConsoleInden; + _setUnsavedConsole.setFlag(SETTING_ITEM::INDENTATION); + } +} + +int ScriptSettings::editorInden() const { return m_editorInden; } + +void ScriptSettings::setEditorInden(int newEditorInden) { + if (m_editorInden != newEditorInden) { + m_editorInden = newEditorInden; + _setUnsavedEditor.setFlag(SETTING_ITEM::INDENTATION); + } +} + +int ScriptSettings::consoleTabWidth() const { return m_consoleTabWidth; } + +void ScriptSettings::setConsoleTabWidth(int newConsoleTabWidth) { + if (m_consoleTabWidth != newConsoleTabWidth) { + m_consoleTabWidth = newConsoleTabWidth; + _setUnsavedConsole.setFlag(SETTING_ITEM::TAB_WIDTH); + } +} + +int ScriptSettings::editorTabWidth() const { return m_editorTabWidth; } + +void ScriptSettings::setEditorTabWidth(int newEditorTabWidth) { + if (m_editorTabWidth != newEditorTabWidth) { + m_editorTabWidth = newEditorTabWidth; + _setUnsavedEditor.setFlag(SETTING_ITEM::TAB_WIDTH); + } +} + +QString ScriptSettings::consoleTheme() const { return m_consoleTheme; } + +void ScriptSettings::setConsoleTheme(const QString &newConsoleTheme) { + if (m_consoleTheme != newConsoleTheme) { + m_consoleTheme = newConsoleTheme; + _setUnsavedConsole.setFlag(SETTING_ITEM::THEME); + } +} + +QString ScriptSettings::editorTheme() const { return m_editorTheme; } + +void ScriptSettings::setEditorTheme(const QString &newEditorTheme) { + if (m_editorTheme != newEditorTheme) { + m_editorTheme = newEditorTheme; + _setUnsavedEditor.setFlag(SETTING_ITEM::THEME); + } +} + +int ScriptSettings::consoleFontSize() const { return m_consolefontSize; } + +void ScriptSettings::setConsoleFontSize(int newConsolefontSize) { + if (m_consolefontSize != newConsolefontSize) { + m_consolefontSize = newConsolefontSize; + _setUnsavedConsole.setFlag(SETTING_ITEM::FONT_SIZE); + } +} + +int ScriptSettings::editorFontSize() const { return m_editorfontSize; } + +void ScriptSettings::setEditorFontSize(int newEditorfontSize) { + if (m_editorfontSize != newEditorfontSize) { + m_editorfontSize = newEditorfontSize; + _setUnsavedEditor.setFlag(SETTING_ITEM::FONT_SIZE); + } +} + +QString ScriptSettings::consoleFontFamily() const { + return m_consoleFontFamily; +} + +void ScriptSettings::setConsoleFontFamily(const QString &newConsoleFontFamily) { + if (m_consoleFontFamily != newConsoleFontFamily) { + m_consoleFontFamily = newConsoleFontFamily; + _setUnsavedConsole.setFlag(SETTING_ITEM::FONT); + } +} + +QString ScriptSettings::editorFontFamily() const { return m_editorFontFamily; } + +void ScriptSettings::setEditorFontFamily(const QString &newEditorFontFamily) { + if (m_editorFontFamily != newEditorFontFamily) { + m_editorFontFamily = newEditorFontFamily; + _setUnsavedEditor.setFlag(SETTING_ITEM::FONT); + } +} diff --git a/src/class/scriptsettings.h b/src/class/scriptsettings.h index 48069f6..8364c68 100644 --- a/src/class/scriptsettings.h +++ b/src/class/scriptsettings.h @@ -1,6 +1,24 @@ +/*============================================================================== +** Copyright (C) 2024-2027 WingSummer +** +** This program is free software: you can redistribute it and/or modify it under +** the terms of the GNU Affero General Public License as published by the Free +** Software Foundation, version 3. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +** details. +** +** You should have received a copy of the GNU Affero General Public License +** along with this program. If not, see . +** ============================================================================= +*/ + #ifndef SCRIPTSETTINGS_H #define SCRIPTSETTINGS_H +#include #include class ScriptSettings : public QObject { @@ -38,6 +56,70 @@ public: void save(SETTINGS cat = SETTING::ALL); void reset(SETTINGS cat = SETTING::ALL); +public: + QString editorFontFamily() const; + void setEditorFontFamily(const QString &newEditorFontFamily); + + QString consoleFontFamily() const; + void setConsoleFontFamily(const QString &newConsoleFontFamily); + + int editorFontSize() const; + void setEditorFontSize(int newEditorfontSize); + + int consoleFontSize() const; + void setConsoleFontSize(int newConsolefontSize); + + QString editorTheme() const; + void setEditorTheme(const QString &newEditorTheme); + + QString consoleTheme() const; + void setConsoleTheme(const QString &newConsoleTheme); + + int editorTabWidth() const; + void setEditorTabWidth(int newEditorTabWidth); + + int consoleTabWidth() const; + void setConsoleTabWidth(int newConsoleTabWidth); + + int editorInden() const; + void setEditorInden(int newEditorInden); + + int consoleInden() const; + void setConsoleInden(int newConsoleInden); + + bool editorMatchBraces() const; + void setEditorMatchBraces(bool newEditorMatchBraces); + + bool consoleMatchBraces() const; + void setConsoleMatchBraces(bool newConsoleMatchBraces); + + bool editorWordWrap() const; + void setEditorWordWrap(bool newEditorWordWrap); + + bool editorShowLineNumber() const; + void setEditorShowLineNumber(bool newEditorShowLineNumber); + + bool editorFolding() const; + void setEditorFolding(bool newEditorFolding); + + bool editorShowGuideLine() const; + void setEditorShowGuideLine(bool newEditorShowGuidLine); + + bool editorShowLineEdges() const; + void setEditorShowLineEdges(bool newEditorShowLineEdges); + + bool editorShowWhiteSpace() const; + void setEditorShowWhiteSpace(bool newEditorShowWhiteSpace); + + bool consoleShowWhiteSpace() const; + void setConsoleShowWhiteSpace(bool newConsoleShowWhiteSpace); + + bool editorAutoCloseChar() const; + void setEditorAutoCloseChar(bool newEditorAutoCloseChar); + + bool consoleAutoCloseChar() const; + void setConsoleAutoCloseChar(bool newConsoleAutoCloseChar); + private: explicit ScriptSettings(); @@ -45,6 +127,43 @@ signals: void editorSettingsUpdate(); void consoleSettingUpdate(); +private: + QFont _defaultFont; + + QString m_editorFontFamily; + QString m_consoleFontFamily; + + int m_editorfontSize = 10; + int m_consolefontSize = 10; + + QString m_editorTheme; + QString m_consoleTheme; + + int m_editorTabWidth = 4; + int m_consoleTabWidth = 4; + + int m_editorInden = 0; + int m_consoleInden = 0; + + bool m_editorMatchBraces = true; + bool m_consoleMatchBraces = true; + + bool m_editorWordWrap = false; + bool m_editorShowLineNumber = true; + bool m_editorFolding = true; + bool m_editorShowGuideLine = true; + bool m_editorShowLineEdges = false; + + bool m_editorShowWhiteSpace = false; + bool m_consoleShowWhiteSpace = false; + + bool m_editorAutoCloseChar = true; + bool m_consoleAutoCloseChar = true; + +private: + SETTING_ITEMS _setUnsavedEditor; + SETTING_ITEMS _setUnsavedConsole; + private: Q_DISABLE_COPY_MOVE(ScriptSettings) }; diff --git a/src/control/codeedit.cpp b/src/control/codeedit.cpp index f2f7fda..efa3936 100644 --- a/src/control/codeedit.cpp +++ b/src/control/codeedit.cpp @@ -16,24 +16,20 @@ */ #include "codeedit.h" +#include "class/scriptsettings.h" #include "model/codecompletionmodel.h" #include #include CodeEdit::CodeEdit(QWidget *parent) : WingCodeEdit(parent) { - setAutoIndent(true); - setAutoCloseChar(true); - setMatchBraces(true); - setShowIndentGuides(true); - setShowLineNumbers(true); - setShowFolding(true); - setShowSymbolMark(true); - connect(this->document(), &QTextDocument::modificationChanged, this, &CodeEdit::contentModified); - addMoveLineShortCut(); + + connect(&ScriptSettings::instance(), &ScriptSettings::editorSettingsUpdate, + this, &CodeEdit::applyEditorSetStyle); + applyEditorSetStyle(); } void CodeEdit::onCompletion(const QModelIndex &index) { @@ -64,3 +60,20 @@ void CodeEdit::addMoveLineShortCut() { connect(downLines, &QShortcut::activated, this, [this]() { moveLines(QTextCursor::NextBlock); }); } + +void CodeEdit::applyEditorSetStyle() { + auto &set = ScriptSettings::instance(); + auto dfont = QFont(set.editorFontFamily()); + dfont.setPointSize(set.editorFontSize()); + this->setFont(dfont); + this->setTabWidth(set.editorTabWidth()); + this->setIndentationMode(WingCodeEdit::IndentationMode(set.editorInden())); + this->setShowLineNumbers(set.editorShowLineNumber()); + this->setShowFolding(set.editorFolding()); + this->setShowIndentGuides(set.editorShowGuideLine()); + this->setWordWrap(set.editorWordWrap()); + this->setShowLongLineEdge(set.editorShowLineEdges()); + this->setMatchBraces(set.editorMatchBraces()); + this->setShowWhitespace(set.editorShowWhiteSpace()); + this->setAutoCloseChar(set.editorAutoCloseChar()); +} diff --git a/src/control/codeedit.h b/src/control/codeedit.h index 3e12143..7bf83a7 100644 --- a/src/control/codeedit.h +++ b/src/control/codeedit.h @@ -34,6 +34,9 @@ protected slots: private: void addMoveLineShortCut(); + +private slots: + void applyEditorSetStyle(); }; #endif // CODEEDIT_H diff --git a/src/control/scripteditor.cpp b/src/control/scripteditor.cpp index 5e5a1f1..7460d41 100644 --- a/src/control/scripteditor.cpp +++ b/src/control/scripteditor.cpp @@ -34,7 +34,6 @@ #include "class/ascompletion.h" #include "class/clangformatmanager.h" -#include "class/skinmanager.h" ScriptEditor::ScriptEditor(asIScriptEngine *engine, QWidget *parent) : ads::CDockWidget(nullptr, QString(), parent) { @@ -46,18 +45,6 @@ ScriptEditor::ScriptEditor(asIScriptEngine *engine, QWidget *parent) this->setObjectName(QStringLiteral("ScriptEditor")); m_editor = new CodeEdit(this); - - switch (SkinManager::instance().currentTheme()) { - case SkinManager::Theme::Dark: - m_editor->setTheme(m_editor->syntaxRepo().defaultTheme( - KSyntaxHighlighting::Repository::DarkTheme)); - break; - case SkinManager::Theme::Light: - m_editor->setTheme(m_editor->syntaxRepo().defaultTheme( - KSyntaxHighlighting::Repository::LightTheme)); - break; - } - m_editor->setSyntax( m_editor->syntaxRepo().definitionForName("AngelScript")); diff --git a/src/control/scriptingconsole.cpp b/src/control/scriptingconsole.cpp index 217016e..588a003 100644 --- a/src/control/scriptingconsole.cpp +++ b/src/control/scriptingconsole.cpp @@ -19,7 +19,7 @@ #include "QConsoleWidget/QConsoleIODevice.h" #include "class/logger.h" #include "class/scriptconsolemachine.h" -#include "class/wingconsolehighligher.h" +#include "class/scriptsettings.h" #include "model/codecompletionmodel.h" #include @@ -28,44 +28,15 @@ #include #include -#include -#include -#include - -ScriptingConsole::ScriptingConsole(QWidget *parent) : QConsoleWidget(parent) { - _warnCharFmt.setForeground(QColorConstants::Svg::gold); - setHighlighter(new WingConsoleHighligher); - setSyntax(syntaxRepo().definitionForName("AngelScript")); +ScriptingConsole::ScriptingConsole(QWidget *parent) + : ScriptingConsoleBase(parent) { + connect(&ScriptSettings::instance(), &ScriptSettings::consoleSettingUpdate, + this, &ScriptingConsole::applyScriptSettings); + applyScriptSettings(); } ScriptingConsole::~ScriptingConsole() {} -void ScriptingConsole::stdOut(const QString &str) { - writeStdOut(str); - dontHighlightLastLine(); -} - -void ScriptingConsole::stdErr(const QString &str) { - writeStdErr(str); - dontHighlightLastLine(); -} - -void ScriptingConsole::stdWarn(const QString &str) { - write(str, _warnCharFmt); - dontHighlightLastLine(); -} - -void ScriptingConsole::newLine() { _s << Qt::endl; } - -void ScriptingConsole::dontHighlightLastLine() { dontHighlightLastOffset(-1); } - -void ScriptingConsole::dontHighlightLastOffset(int offset) { - auto blk = document()->lastBlock(); - auto hl = highlighter(); - hl->setProperty(blk, "cmdoff", offset); - hl->rehighlightBlock(blk); -} - void ScriptingConsole::handleReturnKey() { QString code = getCommandLine(); @@ -91,8 +62,6 @@ void ScriptingConsole::handleReturnKey() { } void ScriptingConsole::init() { - _s.setDevice(this->device()); - _getInputFn = std::bind(&ScriptingConsole::getInput, this); _sp = new ScriptConsoleMachine(_getInputFn, this); @@ -110,26 +79,26 @@ void ScriptingConsole::init() { switch (type) { case ScriptMachine::MessageType::Info: if (isNotBlockStart) { - _s << Qt::endl; + newLine(); } stdOut(tr("[Info]") + message.message); - _s << Qt::flush; + flush(); newLine(); break; case ScriptMachine::MessageType::Warn: if (isNotBlockStart) { - _s << Qt::endl; + newLine(); } stdWarn(tr("[Warn]") + message.message); - _s << Qt::flush; + flush(); newLine(); break; case ScriptMachine::MessageType::Error: if (isNotBlockStart) { - _s << Qt::endl; + newLine(); } stdErr(tr("[Error]") + message.message); - _s << Qt::flush; + flush(); newLine(); break; case ScriptMachine::MessageType::Print: @@ -153,24 +122,27 @@ void ScriptingConsole::init() { &ScriptingConsole::onFunctionTip); } -void ScriptingConsole::initOutput() { - stdWarn(tr("Scripting console for WingHexExplorer")); - _s << Qt::endl; - stdWarn(tr(">>>> Powered by AngelScript <<<<")); - _s << Qt::endl << Qt::endl; - appendCommandPrompt(); - setMode(Input); -} - void ScriptingConsole::clearConsole() { setMode(Output); clear(); - appendCommandPrompt(_lastCommandPrompt); + appendCommandPrompt(lastCommandPrompt()); setMode(Input); } void ScriptingConsole::processKeyEvent(QKeyEvent *e) { keyPressEvent(e); } +void ScriptingConsole::applyScriptSettings() { + auto &set = ScriptSettings::instance(); + auto dfont = QFont(set.consoleFontFamily()); + dfont.setPointSize(set.consoleFontSize()); + this->setFont(dfont); + this->setTabWidth(set.consoleTabWidth()); + this->setIndentationMode(WingCodeEdit::IndentationMode(set.consoleInden())); + this->setMatchBraces(set.consoleMatchBraces()); + this->setShowWhitespace(set.consoleShowWhiteSpace()); + this->setAutoCloseChar(set.consoleAutoCloseChar()); +} + void ScriptingConsole::runConsoleCommand(const QString &code) { auto exec = code.trimmed(); if (exec.endsWith('\\')) { @@ -193,9 +165,9 @@ void ScriptingConsole::runConsoleCommand(const QString &code) { QString ScriptingConsole::getInput() { appendCommandPrompt(true); setMode(Input); - _s.device()->waitForReadyRead(-1); + consoleStream().device()->waitForReadyRead(-1); QString instr; - _s >> instr; + consoleStream() >> instr; setMode(Output); return instr; } @@ -231,29 +203,6 @@ QString ScriptingConsole::currentCodes() const { return _codes + currentCommandLine(); } -void ScriptingConsole::appendCommandPrompt(bool storeOnly) { - QString commandPrompt; - - if (storeOnly) { - commandPrompt += QStringLiteral("... > "); - } else { - auto cursor = this->textCursor(); - if (!cursor.atBlockStart()) { - newLine(); - } - if (_sp && _sp->isDebugMode()) { - commandPrompt += QStringLiteral("[dbg] > "); - } else { - commandPrompt += QStringLiteral("as > "); - } - } - - _lastCommandPrompt = storeOnly; - - writeStdOut(commandPrompt); - dontHighlightLastOffset(commandPrompt.length()); -} - ScriptMachine *ScriptingConsole::machine() const { return _sp; } ScriptConsoleMachine *ScriptingConsole::consoleMachine() const { return _sp; } diff --git a/src/control/scriptingconsole.h b/src/control/scriptingconsole.h index 0bdd595..6a26672 100644 --- a/src/control/scriptingconsole.h +++ b/src/control/scriptingconsole.h @@ -18,13 +18,14 @@ #ifndef ScriptingConsole_H #define ScriptingConsole_H -#include "QConsoleWidget/QConsoleWidget.h" +#include "scriptingconsolebase.h" + #include "class/asconsolecompletion.h" #include "class/scriptconsolemachine.h" #include -class ScriptingConsole : public QConsoleWidget { +class ScriptingConsole : public ScriptingConsoleBase { Q_OBJECT public: @@ -35,28 +36,21 @@ public: ScriptMachine *machine() const; ScriptConsoleMachine *consoleMachine() const; - //! Appends a newline and command prompt at the end of the document. - void appendCommandPrompt(bool storeOnly = false); - QString currentCodes() const; signals: void onFunctionTip(const QString &tip); public slots: - void stdOut(const QString &str); - void stdErr(const QString &str); - void stdWarn(const QString &str); - void newLine(); - void init(); - void initOutput(); - void clearConsole(); void processKeyEvent(QKeyEvent *e); +private slots: + void applyScriptSettings(); + private: void runConsoleCommand(const QString &code); @@ -64,10 +58,6 @@ private: QString packUpLoggingStr(const QString &message); - void dontHighlightLastLine(); - - void dontHighlightLastOffset(int offset); - protected: void handleReturnKey() override; void keyPressEvent(QKeyEvent *e) override; @@ -77,12 +67,9 @@ protected slots: private: ScriptConsoleMachine *_sp = nullptr; - QTextStream _s; - bool _lastCommandPrompt = false; QString _codes; - QTextCharFormat _warnCharFmt; std::function _getInputFn; }; diff --git a/src/control/scriptingconsolebase.cpp b/src/control/scriptingconsolebase.cpp new file mode 100644 index 0000000..9594c72 --- /dev/null +++ b/src/control/scriptingconsolebase.cpp @@ -0,0 +1,83 @@ +#include "scriptingconsolebase.h" +#include "class/wingconsolehighligher.h" +#include "wingsyntaxhighlighter.h" + +#include +#include + +#include +#include +#include + +ScriptingConsoleBase::ScriptingConsoleBase(QWidget *parent) + : QConsoleWidget(parent) { + _warnCharFmt.setForeground(QColorConstants::Svg::gold); + setHighlighter(new WingConsoleHighligher); + setSyntax(syntaxRepo().definitionForName("AngelScript")); + + _s.setDevice(this->device()); +} + +void ScriptingConsoleBase::stdOut(const QString &str) { + writeStdOut(str); + dontHighlightLastLine(); +} + +void ScriptingConsoleBase::stdErr(const QString &str) { + writeStdErr(str); + dontHighlightLastLine(); +} + +void ScriptingConsoleBase::stdWarn(const QString &str) { + write(str, _warnCharFmt); + dontHighlightLastLine(); +} + +void ScriptingConsoleBase::newLine() { _s << Qt::endl; } + +void ScriptingConsoleBase::flush() { _s << Qt::flush; } + +void ScriptingConsoleBase::initOutput() { + stdWarn(tr("Scripting console for WingHexExplorer")); + _s << Qt::endl; + stdWarn(tr(">>>> Powered by AngelScript <<<<")); + _s << Qt::endl << Qt::endl; + appendCommandPrompt(); +} + +void ScriptingConsoleBase::appendCommandPrompt(bool storeOnly) { + QString commandPrompt; + + auto cursor = this->textCursor(); + if (!cursor.atBlockStart()) { + newLine(); + } + + if (storeOnly) { + commandPrompt += QStringLiteral("... > "); + } else { + commandPrompt += QStringLiteral("as > "); + } + + _lastCommandPrompt = storeOnly; + + writeStdOut(commandPrompt); + dontHighlightLastOffset(commandPrompt.length()); +} + +void ScriptingConsoleBase::dontHighlightLastLine() { + dontHighlightLastOffset(-1); +} + +void ScriptingConsoleBase::dontHighlightLastOffset(int offset) { + auto blk = document()->lastBlock(); + auto hl = highlighter(); + hl->setProperty(blk, "cmdoff", offset); + hl->rehighlightBlock(blk); +} + +bool ScriptingConsoleBase::lastCommandPrompt() const { + return _lastCommandPrompt; +} + +QTextStream &ScriptingConsoleBase::consoleStream() { return _s; } diff --git a/src/control/scriptingconsolebase.h b/src/control/scriptingconsolebase.h new file mode 100644 index 0000000..f02a5b4 --- /dev/null +++ b/src/control/scriptingconsolebase.h @@ -0,0 +1,40 @@ +#ifndef SCRIPTINGCONSOLEBASE_H +#define SCRIPTINGCONSOLEBASE_H + +#include "QConsoleWidget/QConsoleWidget.h" + +class ScriptingConsoleBase : public QConsoleWidget { + Q_OBJECT +public: + explicit ScriptingConsoleBase(QWidget *parent = nullptr); + +public: + QTextStream &consoleStream(); + + bool lastCommandPrompt() const; + +public slots: + void stdOut(const QString &str); + void stdErr(const QString &str); + void stdWarn(const QString &str); + void newLine(); + void flush(); + + void initOutput(); + + //! Appends a newline and command prompt at the end of the document. + void appendCommandPrompt(bool storeOnly = false); + +protected: + void dontHighlightLastLine(); + + void dontHighlightLastOffset(int offset); + +private: + QTextStream _s; + QTextCharFormat _warnCharFmt; + + bool _lastCommandPrompt = false; +}; + +#endif // SCRIPTINGCONSOLEBASE_H diff --git a/src/dialog/mainwindow.cpp b/src/dialog/mainwindow.cpp index 165a377..9cea2a3 100644 --- a/src/dialog/mainwindow.cpp +++ b/src/dialog/mainwindow.cpp @@ -245,6 +245,7 @@ MainWindow::MainWindow(SplashDialog *splash) : FramelessMainWindow() { splash->setInfoText(tr("SetupScriptService")); m_scriptConsole->initOutput(); + m_scriptConsole->setMode(QConsoleWidget::Input); m_scriptConsole->machine()->setInsteadFoundDisabled(true); if (splash) diff --git a/src/dialog/scriptingdialog.cpp b/src/dialog/scriptingdialog.cpp index 2e389e9..bd287c5 100644 --- a/src/dialog/scriptingdialog.cpp +++ b/src/dialog/scriptingdialog.cpp @@ -515,11 +515,13 @@ RibbonTabContent *ScriptingDialog::buildSettingPage(RibbonTabContent *tab) { addPannelAction(pannel, QStringLiteral("file"), tr("Editor"), [=] { m_setdialog->showConfig(QStringLiteral("Edit")); }); + addPannelAction(pannel, QStringLiteral("console"), tr("Console"), [=] { + m_setdialog->showConfig(QStringLiteral("Console")); + }); addPannelAction( pannel, QStringLiteral("codeformat"), tr("ClangFormat"), [=] { m_setdialog->showConfig(QStringLiteral("ClangFormat")); }); - addPannelAction(pannel, QStringLiteral("scheme"), tr("Format"), - [=] { m_setdialog->showConfig(QStringLiteral("Scheme")); }); + return tab; } @@ -950,7 +952,10 @@ void ScriptingDialog::runDbgCommand(asDebugger::DebugAction action) { void ScriptingDialog::buildUpSettingDialog() { m_setdialog = new SettingDialog(this); - auto edit = new QEditConfig(m_setdialog); + auto edit = new QEditConfig(false, m_setdialog); + m_setdialog->addPage(edit); + + edit = new QEditConfig(true, m_setdialog); m_setdialog->addPage(edit); auto clang = new ClangFormatSetDialog(m_setdialog); diff --git a/src/dialog/scriptingdialog.h b/src/dialog/scriptingdialog.h index 88ab783..7f09581 100644 --- a/src/dialog/scriptingdialog.h +++ b/src/dialog/scriptingdialog.h @@ -139,7 +139,7 @@ private: auto a = new QToolButton(pannel); #if QT_VERSION <= QT_VERSION_CHECK(6, 6, 0) if (menu) { - a->setText(title + QStringLiteral(" ▼")); + a->setText(title + QStringLiteral(" 闂佸厖绱幏锟�")); } else #endif { diff --git a/src/dialog/showtextdialog.cpp b/src/dialog/showtextdialog.cpp index 9b50837..9314831 100644 --- a/src/dialog/showtextdialog.cpp +++ b/src/dialog/showtextdialog.cpp @@ -93,8 +93,7 @@ void ShowTextDialog::setSyntax(const KSyntaxHighlighting::Definition &syntax) { m_edit->setSyntax(syntax); } -void ShowTextDialog::load(QHexBuffer *buffer, const QString encoding, - qsizetype offset, qsizetype size) { +void ShowTextDialog::load(QHexBuffer *buffer, const QString encoding) { // auto editor = m_edit->editor(); // editor->blockSignals(true); // editor->setCodec(encoding); @@ -102,19 +101,9 @@ void ShowTextDialog::load(QHexBuffer *buffer, const QString encoding, // editor->blockSignals(false); } -void ShowTextDialog::load(QHexBuffer *buffer, qsizetype offset, - qsizetype size) { - if (buffer == nullptr || offset < 0) { - return; - } - - m_canceled = false; - - if (size < 0) { - size = buffer->length(); - } - - if (size >= std::numeric_limits::max()) { +void ShowTextDialog::load(QHexBuffer *buffer) { + constexpr auto MAXLEN = 1024 * 1024 * 1024; + if (buffer->length() > MAXLEN) { WingMessageBox::critical(this, this->windowTitle(), tr("TooHugeFile")); return; } diff --git a/src/dialog/showtextdialog.h b/src/dialog/showtextdialog.h index f9df3db..c2057c8 100644 --- a/src/dialog/showtextdialog.h +++ b/src/dialog/showtextdialog.h @@ -43,9 +43,8 @@ public: void setSyntax(const KSyntaxHighlighting::Definition &syntax); public: - void load(QHexBuffer *buffer, const QString encoding, qsizetype offset = 0, - qsizetype size = -1); - void load(QHexBuffer *buffer, qsizetype offset = 0, qsizetype size = -1); + void load(QHexBuffer *buffer, const QString encoding); + void load(QHexBuffer *buffer); private: void buildUpRibbonBar(); diff --git a/src/settings/qeditconfig.cpp b/src/settings/qeditconfig.cpp index 64cf010..90d82ed 100644 --- a/src/settings/qeditconfig.cpp +++ b/src/settings/qeditconfig.cpp @@ -22,13 +22,15 @@ \see QEditConfig */ +#include "class/scriptsettings.h" #include "control/codeedit.h" +#include "control/scriptingconsolebase.h" #include "ui_qeditconfig.h" #include "utilities.h" #include "class/skinmanager.h" -#include +#include #include #include @@ -44,25 +46,46 @@ */ QEditConfig::QEditConfig(bool isConsole, QWidget *w) - : WingHex::SettingPage(w), ui(new Ui::QEditConfig()) { + : WingHex::SettingPage(w), ui(new Ui::QEditConfig()), + m_isConsole(isConsole) { ui->setupUi(this); loadThemes(); loadIndentations(); - QFile code(QStringLiteral(":/com.wingsummer.winghex/src/TESTCODE.as")); - auto ret = code.open(QFile::ReadOnly); - Q_ASSERT(ret); - Q_UNUSED(ret); - - auto cbuffer = code.readAll(); - _edit = new CodeEdit(this); - _edit->setPlainText(QString::fromUtf8(cbuffer)); + if (isConsole) { + auto console = new ScriptingConsoleBase(this); + console->initOutput(); + auto outfmt = + console->channelCharFormat(QConsoleWidget::StandardOutput); + console->write( + QStringLiteral(R"(print("WingHexExplorer2 by wingsummer!");)"), + outfmt); + console->appendCommandPrompt(); + console->write(QStringLiteral(R"(for(auto i = 0; i < 5; i++) { \)"), + outfmt); + console->appendCommandPrompt(true); + console->write(QStringLiteral(R"(print(i); \)"), outfmt); + console->appendCommandPrompt(true); + console->write(QStringLiteral("}"), outfmt); + console->newLine(); + console->stdOut(QStringLiteral("01234")); + _edit = console; + } else { + _edit = new WingCodeEdit(this); + QFile code(QStringLiteral(":/com.wingsummer.winghex/src/TESTCODE.as")); + auto ret = code.open(QFile::ReadOnly); + Q_ASSERT(ret); + Q_UNUSED(ret); + auto cbuffer = code.readAll(); + _edit->setPlainText(QString::fromUtf8(cbuffer)); + } _edit->setReadOnly(true); _edit->setUndoRedoEnabled(false); _edit->setSyntax(WingCodeEdit::syntaxRepo().definitionForName( QStringLiteral("AngelScript"))); + ui->layoutEdit->addWidget(_edit); connect(ui->cbTheme, QOverload::of(&QComboBox::currentIndexChanged), @@ -128,6 +151,22 @@ QEditConfig::QEditConfig(bool isConsole, QWidget *w) connect(ui->chkAutoCloseChar, &QCheckBox::toggled, _edit, &CodeEdit::setAutoCloseChar); + if (isConsole) { + ui->chkShowLineNumber->setEnabled(false); + ui->chkShowFolding->setEnabled(false); + ui->chkShowIndentGuides->setEnabled(false); + ui->chkWordWrap->setEnabled(false); + ui->chkLongLineEdge->setEnabled(false); + + _name = tr("Console"); + _id = QStringLiteral("Console"); + _icon = ICONRES("console"); + } else { + _name = tr("Edit"); + _id = QStringLiteral("Edit"); + _icon = ICONRES("file"); + } + reload(); } @@ -137,8 +176,44 @@ QEditConfig::~QEditConfig() { delete ui; } \brief Apply changes */ void QEditConfig::apply() { - QFont font = ui->cbFont->currentFont(); - font.setPointSize(ui->spnFontSize->value()); + auto &set = ScriptSettings::instance(); + if (m_isConsole) { + if (ui->cbTheme->currentIndex() == 0) { + set.setConsoleTheme({}); + } else { + set.setConsoleTheme(ui->cbTheme->currentText()); + } + + set.setConsoleFontFamily(ui->cbFont->currentFont().family()); + set.setConsoleFontSize(ui->spnFontSize->value()); + set.setConsoleTabWidth(ui->spnTabWidth->value()); + set.setConsoleInden(ui->cbIndentation->currentData().toInt()); + + set.setConsoleMatchBraces(ui->chkMatchBraces->isChecked()); + set.setConsoleShowWhiteSpace(ui->chkShowWhitespace->isChecked()); + set.setConsoleAutoCloseChar(ui->chkAutoCloseChar->isChecked()); + } else { + if (ui->cbTheme->currentIndex() == 0) { + set.setEditorTheme({}); + } else { + set.setEditorTheme(ui->cbTheme->currentText()); + } + + set.setEditorFontFamily(ui->cbFont->currentFont().family()); + set.setEditorFontSize(ui->spnFontSize->value()); + set.setEditorTabWidth(ui->spnTabWidth->value()); + set.setEditorInden(ui->cbIndentation->currentData().toInt()); + + set.setEditorShowLineNumber(ui->chkShowLineNumber->isChecked()); + set.setEditorFolding(ui->chkShowFolding->isChecked()); + set.setEditorShowGuideLine(ui->chkShowIndentGuides->isChecked()); + set.setEditorWordWrap(ui->chkWordWrap->isChecked()); + set.setEditorShowLineEdges(ui->chkLongLineEdge->isChecked()); + set.setEditorMatchBraces(ui->chkMatchBraces->isChecked()); + set.setEditorShowWhiteSpace(ui->chkShowWhitespace->isChecked()); + set.setEditorAutoCloseChar(ui->chkAutoCloseChar->isChecked()); + } + set.save(m_isConsole ? ScriptSettings::CONSOLE : ScriptSettings::EDITOR); } /*! @@ -156,52 +231,57 @@ void QEditConfig::cancel() { reload(); } \note The widgets are changed but these changes are NOT applied. */ void QEditConfig::reset() { - // restore default configuration - auto font = qApp->font(); - ui->cbFont->setFont(font); - ui->spnFontSize->setValue(font.pointSize()); - - ui->spnTabWidth->setValue(4); - - ui->chkShowWhitespace->setChecked(true); - ui->chkShowIndentGuides->setChecked(true); - ui->chkShowLineNumber->setChecked(true); - - // ui->chkDetectLE->setChecked(true); - // ui->cbLineEndings->setCurrentIndex(0); - - // ui->chkReplaceTabs->setChecked(true); - // ui->chkAutoRemoveTrailingWhitespace->setChecked(true); - // ui->chkPreserveTrailingIndent->setChecked(false); - - apply(); + auto &set = ScriptSettings::instance(); + set.reset(m_isConsole ? ScriptSettings::CONSOLE : ScriptSettings::EDITOR); + reload(); } void QEditConfig::reload() { + auto &set = ScriptSettings::instance(); + + auto e = QMetaEnum::fromType(); + // reload the current config - // auto dfont = QEditor::defaultFont(); - // ui->cbFont->setFont(dfont); - // ui->spnFontSize->setValue(dfont.pointSize()); + if (m_isConsole) { + auto theme = set.consoleTheme(); + if (theme.isEmpty()) { + ui->cbTheme->setCurrentIndex(0); + } else { + ui->cbTheme->setCurrentText(set.consoleTheme()); + } - // ui->spnTabWidth->setValue(QEditor::defaultTabStop()); + auto dfont = QFont(set.consoleFontFamily()); + ui->cbFont->setCurrentFont(dfont); + ui->spnFontSize->setValue(set.consoleFontSize()); + ui->spnTabWidth->setValue(set.consoleTabWidth()); - // auto ss = QEditor::defaultShowSpaces(); - // ui->chkShowTabsInText->setChecked(ss.testFlag(QDocument::ShowTabs)); - // ui->chkShowLeadingWhitespace->setChecked( - // ss.testFlag(QDocument::ShowLeading)); - // ui->chkShowTrailingWhitespace->setChecked( - // ss.testFlag(QDocument::ShowTrailing)); + ui->cbIndentation->setCurrentText(e.valueToKey(set.consoleInden())); + ui->chkMatchBraces->setChecked(set.consoleMatchBraces()); + ui->chkShowWhitespace->setChecked(set.consoleShowWhiteSpace()); + ui->chkAutoCloseChar->setChecked(set.consoleAutoCloseChar()); + } else { + auto theme = set.editorTheme(); + if (theme.isEmpty()) { + ui->cbTheme->setCurrentIndex(0); + } else { + ui->cbTheme->setCurrentText(set.consoleTheme()); + } - // auto le = QEditor::defaultLineEnding(); - // ui->chkDetectLE->setChecked(le == QDocument::Conservative); - // ui->cbLineEndings->setCurrentIndex(le ? le - 1 : 0); + auto dfont = QFont(set.editorFontFamily()); + ui->cbFont->setCurrentFont(dfont); + ui->spnFontSize->setValue(set.editorFontSize()); + ui->spnTabWidth->setValue(set.editorTabWidth()); - // int flag = QEditor::defaultFlags(); - // ui->chkReplaceTabs->setChecked(flag & QEditor::ReplaceTabs); - // ui->chkAutoRemoveTrailingWhitespace->setChecked(flag & - // QEditor::RemoveTrailing); - // ui->chkPreserveTrailingIndent->setChecked(flag & - // QEditor::PreserveTrailingIndent); + ui->cbIndentation->setCurrentText(e.valueToKey(set.editorInden())); + ui->chkShowLineNumber->setChecked(set.editorShowLineNumber()); + ui->chkShowFolding->setChecked(set.editorFolding()); + ui->chkShowIndentGuides->setChecked(set.editorShowGuideLine()); + ui->chkWordWrap->setChecked(set.editorWordWrap()); + ui->chkLongLineEdge->setChecked(set.editorShowLineEdges()); + ui->chkMatchBraces->setChecked(set.editorMatchBraces()); + ui->chkShowWhitespace->setChecked(set.editorShowWhiteSpace()); + ui->chkAutoCloseChar->setChecked(set.editorAutoCloseChar()); + } } void QEditConfig::loadThemes() { @@ -214,16 +294,17 @@ void QEditConfig::loadThemes() { } void QEditConfig::loadIndentations() { - ui->cbIndentation->addItem(tr("IndentMixed"), - int(WingCodeEdit::IndentationMode::IndentMixed)); ui->cbIndentation->addItem( tr("IndentSpaces"), int(WingCodeEdit::IndentationMode::IndentSpaces)); ui->cbIndentation->addItem(tr("IndentTabs"), int(WingCodeEdit::IndentationMode::IndentTabs)); + ui->cbIndentation->addItem(tr("IndentMixed"), + int(WingCodeEdit::IndentationMode::IndentMixed)); + ui->cbIndentation->setCurrentIndex(0); } -QIcon QEditConfig::categoryIcon() const { return ICONRES("file"); } +QIcon QEditConfig::categoryIcon() const { return _icon; } -QString QEditConfig::name() const { return tr("Edit"); } +QString QEditConfig::name() const { return _name; } -QString QEditConfig::id() const { return QStringLiteral("Edit"); } +QString QEditConfig::id() const { return _id; } diff --git a/src/settings/qeditconfig.h b/src/settings/qeditconfig.h index a433c16..cef711c 100644 --- a/src/settings/qeditconfig.h +++ b/src/settings/qeditconfig.h @@ -2,7 +2,10 @@ #define QEDITCONFIG_H #include "WingPlugin/settingpage.h" -#include "control/codeedit.h" +#include "wingcodeedit.h" + +#include +#include #include namespace Ui { @@ -32,7 +35,12 @@ private: private: Ui::QEditConfig *ui; - CodeEdit *_edit; + WingCodeEdit *_edit; + bool m_isConsole; + + QString _name; + QString _id; + QIcon _icon; }; #endif // QEDITCONFIG_H diff --git a/src/settings/qeditconfig.ui b/src/settings/qeditconfig.ui index aecc245..e121783 100644 --- a/src/settings/qeditconfig.ui +++ b/src/settings/qeditconfig.ui @@ -11,8 +11,17 @@ + + QLayout::SizeConstraint::SetMinAndMaxSize + + + + 0 + 0 + + Preference @@ -95,6 +104,12 @@ 0 + + 2 + + + 32 + 4 @@ -125,7 +140,7 @@ - + 0 0 @@ -140,7 +155,7 @@ LineNumber - true + false @@ -170,7 +185,7 @@ AutoCloseChar - true + false @@ -180,7 +195,7 @@ MatchBraces - true + false @@ -190,7 +205,7 @@ Folding - true + false @@ -210,7 +225,7 @@ IndentGuides - true + false diff --git a/src/settings/settings.h b/src/settings/settings.h index 3059f38..1f75d10 100644 --- a/src/settings/settings.h +++ b/src/settings/settings.h @@ -1,3 +1,20 @@ +/*============================================================================== +** Copyright (C) 2024-2027 WingSummer +** +** This program is free software: you can redistribute it and/or modify it under +** the terms of the GNU Affero General Public License as published by the Free +** Software Foundation, version 3. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +** details. +** +** You should have received a copy of the GNU Affero General Public License +** along with this program. If not, see . +** ============================================================================= +*/ + #ifndef SETTINGS_H #define SETTINGS_H