feat: 恢复设置功能;移除 QT5 主动支持;

This commit is contained in:
寂静的羽夏 2025-03-21 21:52:56 +08:00
parent b4fba2fc05
commit b0560c37f7
30 changed files with 1787 additions and 1034 deletions

View File

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

View File

@ -1,5 +1,6 @@
#include "QConsoleWidget.h"
#include "QConsoleIODevice.h"
#include "wingsyntaxhighlighter.h"
#include <QAbstractItemView>
#include <QApplication>
@ -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();

View File

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

@ -1 +1 @@
Subproject commit 910a38521cb963cc40581bb8d98bf966eb706f17
Subproject commit 608ab834bd9934e1aa7b4a0417e22e9f4f14da1a

View File

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

View File

@ -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 版本,请咨询我商业合作和付费技术支持。
&emsp;&emsp;该仓库代码使用 Qt 5.15.2 和 6.6.2 在最新版 Windows 和 Ubuntu 编译情况: ![Status](https://github.com/Wing-summer/WingHexExplorer2/actions/workflows/qt-build-test.yml/badge.svg)
&emsp;&emsp;该仓库代码使用 Qt 6.6.2 在最新版 Windows 和 Ubuntu 编译情况: ![Status](https://github.com/Wing-summer/WingHexExplorer2/actions/workflows/qt-build-test.yml/badge.svg)
## WingHexExplorer2

View File

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

BIN
images/console.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@
<file>images/closefile.png</file>
<file>images/codefmt.png</file>
<file>images/codeformat.png</file>
<file>images/console.png</file>
<file>images/convpro.png</file>
<file>images/copy.png</file>
<file>images/copyhex.png</file>
@ -82,7 +83,6 @@
<file>images/savesel.png</file>
<file>images/scale.png</file>
<file>images/scalereset.png</file>
<file>images/scheme.png</file>
<file>images/script.png</file>
<file>images/scriptdbg/bp.png</file>
<file>images/scriptdbg/delbp.png</file>

View File

@ -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 <https://www.gnu.org/licenses/>.
** =============================================================================
*/
#include "scriptsettings.h"
#include <QApplication>
#include <QFontInfo>
#include "settings/settings.h"
#include "wingcodeedit.h"
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Repository>
#include <KSyntaxHighlighting/Theme>
#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);
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
** =============================================================================
*/
#ifndef SCRIPTSETTINGS_H
#define SCRIPTSETTINGS_H
#include <QFont>
#include <QObject>
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)
};

View File

@ -16,24 +16,20 @@
*/
#include "codeedit.h"
#include "class/scriptsettings.h"
#include "model/codecompletionmodel.h"
#include <QModelIndex>
#include <QShortcut>
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());
}

View File

@ -34,6 +34,9 @@ protected slots:
private:
void addMoveLineShortCut();
private slots:
void applyEditorSetStyle();
};
#endif // CODEEDIT_H

View File

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

View File

@ -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 <QApplication>
@ -28,44 +28,15 @@
#include <QRegularExpression>
#include <QTextBlock>
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Repository>
#include <KSyntaxHighlighting/Theme>
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; }

View File

@ -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 <QMutex>
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<QString(void)> _getInputFn;
};

View File

@ -0,0 +1,83 @@
#include "scriptingconsolebase.h"
#include "class/wingconsolehighligher.h"
#include "wingsyntaxhighlighter.h"
#include <QTextBlock>
#include <QTextStream>
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Repository>
#include <KSyntaxHighlighting/Theme>
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; }

View File

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

View File

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

View File

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

View File

@ -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(" 闂佸厖绱幏锟<EFBFBD>"));
} else
#endif
{

View File

@ -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<decltype(size)>::max()) {
void ShowTextDialog::load(QHexBuffer *buffer) {
constexpr auto MAXLEN = 1024 * 1024 * 1024;
if (buffer->length() > MAXLEN) {
WingMessageBox::critical(this, this->windowTitle(), tr("TooHugeFile"));
return;
}

View File

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

View File

@ -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 <QDebug>
#include <QVBoxLayout>
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Repository>
@ -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<int>::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<WingCodeEdit::IndentationMode>();
// 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; }

View File

@ -2,7 +2,10 @@
#define QEDITCONFIG_H
#include "WingPlugin/settingpage.h"
#include "control/codeedit.h"
#include "wingcodeedit.h"
#include <QIcon>
#include <QString>
#include <QWidget>
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

View File

@ -11,8 +11,17 @@
</rect>
</property>
<layout class="QVBoxLayout" name="layoutEdit">
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetMinAndMaxSize</enum>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Preference</string>
</property>
@ -95,6 +104,12 @@
<height>0</height>
</size>
</property>
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>32</number>
</property>
<property name="value">
<number>4</number>
</property>
@ -125,7 +140,7 @@
<item>
<widget class="QGroupBox" name="gbTabs">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -140,7 +155,7 @@
<string>LineNumber</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -170,7 +185,7 @@
<string>AutoCloseChar</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -180,7 +195,7 @@
<string>MatchBraces</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -190,7 +205,7 @@
<string>Folding</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -210,7 +225,7 @@
<string>IndentGuides</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>

View File

@ -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 <https://www.gnu.org/licenses/>.
** =============================================================================
*/
#ifndef SETTINGS_H
#define SETTINGS_H