From ca894bbd2af7e58d619a098933806e7a7b149516 Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:03:25 +0100 Subject: [PATCH] 1.15.3 --- SandboxiePlus/MiscHelpers/Common/CodeEdit.cpp | 135 ++++++++++ SandboxiePlus/MiscHelpers/Common/CodeEdit.h | 40 +++ SandboxiePlus/MiscHelpers/MiscHelpers.pri | 2 + .../SandMan/Helpers/IniHighlighter.cpp | 246 ++++++++++++++++++ .../SandMan/Helpers/IniHighlighter.h | 46 ++++ SandboxiePlus/SandMan/SandMan.pri | 2 + .../SandMan/Windows/OptionsWindow.cpp | 20 +- SandboxiePlus/SandMan/Windows/OptionsWindow.h | 2 + .../SandMan/Windows/SettingsWindow.cpp | 22 +- .../SandMan/Windows/SettingsWindow.h | 2 + 10 files changed, 506 insertions(+), 11 deletions(-) create mode 100644 SandboxiePlus/MiscHelpers/Common/CodeEdit.cpp create mode 100644 SandboxiePlus/MiscHelpers/Common/CodeEdit.h create mode 100644 SandboxiePlus/SandMan/Helpers/IniHighlighter.cpp create mode 100644 SandboxiePlus/SandMan/Helpers/IniHighlighter.h diff --git a/SandboxiePlus/MiscHelpers/Common/CodeEdit.cpp b/SandboxiePlus/MiscHelpers/Common/CodeEdit.cpp new file mode 100644 index 00000000..2757e11e --- /dev/null +++ b/SandboxiePlus/MiscHelpers/Common/CodeEdit.cpp @@ -0,0 +1,135 @@ +#include "stdafx.h" +#include "CodeEdit.h" + + +#define TAB_SPACES " " + +CCodeEdit::CCodeEdit(QSyntaxHighlighter* pHighlighter, QWidget* pParent) + : QWidget(pParent) +{ + m_pMainLayout = new QGridLayout(this); + m_pMainLayout->setContentsMargins(0,0,0,0); + setLayout(m_pMainLayout); + + m_pSourceCode = new QTextEdit(); + QFont Font = m_pSourceCode->font(); + Font.setFamily("Courier New"); + Font.setPointSize(10); + m_pSourceCode->setFont(Font); + m_pSourceCode->setLineWrapMode(QTextEdit::NoWrap); + if(pHighlighter) + pHighlighter->setDocument(m_pSourceCode->document()); + //m_pSourceCode->setTabStopWidth (QFontMetrics(Font).width(TAB_SPACES)); + m_pMainLayout->addWidget(m_pSourceCode, 0, 0); + + connect(m_pSourceCode, SIGNAL(textChanged()), this, SIGNAL(textChanged())); + + // hot keys + m_pFind = new QAction(tr("Find"),this); + m_pFind->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_F)); + connect(m_pFind, SIGNAL(triggered()), this, SLOT(OnFind())); + m_pSourceCode->addAction(m_pFind); + + m_pFindNext = new QAction(tr("FindNext"),this); + QList Finds; + Finds << QKeySequence(Qt::Key_F3); + Finds << QKeySequence(Qt::SHIFT | Qt::Key_F3) << QKeySequence(Qt::CTRL | Qt::Key_F3) << QKeySequence(Qt::ALT | Qt::Key_F3); + Finds << QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_F3) << QKeySequence(Qt::SHIFT | Qt::ALT | Qt::Key_F3) << QKeySequence(Qt::SHIFT | Qt::CTRL | Qt::Key_F3); + Finds << QKeySequence(Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::Key_F3); + m_pFindNext->setShortcuts(Finds); + connect(m_pFindNext, SIGNAL(triggered()), this, SLOT(OnFindNext())); + m_pSourceCode->addAction(m_pFindNext); + + m_pGoTo = new QAction(tr("GoTo"),this); + m_pGoTo->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_G)); + connect(m_pGoTo, SIGNAL(triggered()), this, SLOT(OnGoTo())); + m_pSourceCode->addAction(m_pGoTo); + + + /*m_pComment = new QAction(tr("Comment"),this); + m_pComment->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); + connect(m_pComment, SIGNAL(triggered()), this, SLOT(OnComment())); + m_pSourceCode->addAction(m_pComment); + + m_pUnComment = new QAction(tr("UnComment"),this); + m_pUnComment->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_T)); + connect(m_pUnComment, SIGNAL(triggered()), this, SLOT(OnUnComment())); + m_pSourceCode->addAction(m_pUnComment);*/ +} + +#define ADD_HISTORY(list,entry) \ + list.removeAll(entry); \ + list.prepend(entry); \ + while(list.size() > 10) \ + list.removeLast(); + +void CCodeEdit::OnFind() +{ + static QStringList Finds; + bool bOK = false; + m_CurFind = QInputDialog::getItem (this, tr("Find"),tr("F3: Find Next\n+ Shift: Backward\n+ Ctrl: Case Sensitively\n+ Alt: Whole Words\n\nFind String:") + QString(160,' '), Finds, 0, true, &bOK); + if (!bOK) + return; + ADD_HISTORY(Finds, m_CurFind); + OnFindNext(); +} + +void CCodeEdit::OnFindNext() +{ + if(m_CurFind.isEmpty()) + return; + + QTextDocument::FindFlags Flags = QTextDocument::FindFlags(); + Qt::KeyboardModifiers Mods = QApplication::keyboardModifiers(); + if(Mods & Qt::ShiftModifier) + Flags |= QTextDocument::FindBackward; + if(Mods & Qt::ControlModifier) + Flags |= QTextDocument::FindCaseSensitively; + if(Mods & Qt::AltModifier) + Flags |= QTextDocument::FindWholeWords; + + m_pSourceCode->find(m_CurFind, Flags); +} + +void CCodeEdit::OnGoTo() +{ + int iLine = QInputDialog::getText(this, tr("Go to Line:"),tr(""), QLineEdit::Normal, "").toInt(); + if(!iLine) + return; + + QTextCursor Cursor = m_pSourceCode->textCursor(); + Cursor.movePosition(QTextCursor::Start); + while(iLine-- > 1) + Cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor); + //Cursor.select(QTextCursor::LineUnderCursor); + m_pSourceCode->setTextCursor(Cursor); +} + + +/*void CCodeEdit::OnComment() +{ + QTextCursor Cursor = m_pSourceCode->textCursor(); + int Start = Cursor.selectionStart(); + int End = Cursor.selectionEnd(); + QString Text = m_pSourceCode->toPlainText(); + QString Fragment = Text.mid(Start, End - Start); + + Fragment.replace(QRegExp("^"),"'"); + Fragment.replace(QRegExp("\r?\n"),"\r\n'"); + + m_pSourceCode->insertPlainText(Fragment); +} + +void CCodeEdit::OnUnComment() +{ + QTextCursor Cursor = m_pSourceCode->textCursor(); + int Start = Cursor.selectionStart(); + int End = Cursor.selectionEnd(); + QString Text = m_pSourceCode->toPlainText(); + QString Fragment = Text.mid(Start, End - Start); + + Fragment.replace(QRegExp("^[ \t]*'"),""); + Fragment.replace(QRegExp("\r?\n[ \t]*'"),"\r\n"); + + m_pSourceCode->insertPlainText(Fragment); +}*/ \ No newline at end of file diff --git a/SandboxiePlus/MiscHelpers/Common/CodeEdit.h b/SandboxiePlus/MiscHelpers/Common/CodeEdit.h new file mode 100644 index 00000000..92bba49b --- /dev/null +++ b/SandboxiePlus/MiscHelpers/Common/CodeEdit.h @@ -0,0 +1,40 @@ +#pragma once + +#include "../mischelpers_global.h" + +#include + +class MISCHELPERS_EXPORT CCodeEdit : public QWidget +{ + Q_OBJECT +public: + CCodeEdit(QSyntaxHighlighter* pHighlighter, QWidget* pParent = 0); + + void SetCode(const QString& Code) {m_pSourceCode->setPlainText(Code);} + QString GetCode() {return m_pSourceCode->toPlainText();} + +signals: + void textChanged(); + +private slots: + void OnFind(); + void OnFindNext(); + void OnGoTo(); + + /*void OnComment(); + void OnUnComment();*/ + +private: + QGridLayout* m_pMainLayout; + + QTextEdit* m_pSourceCode; + + QAction* m_pFind; + QAction* m_pFindNext; + QAction* m_pGoTo; + + /*QAction* m_pComment; + QAction* m_pUnComment;*/ + + QString m_CurFind; +}; \ No newline at end of file diff --git a/SandboxiePlus/MiscHelpers/MiscHelpers.pri b/SandboxiePlus/MiscHelpers/MiscHelpers.pri index b898fbe7..8b920bad 100644 --- a/SandboxiePlus/MiscHelpers/MiscHelpers.pri +++ b/SandboxiePlus/MiscHelpers/MiscHelpers.pri @@ -37,6 +37,7 @@ HEADERS += ./MiscHelpers.h \ ./Common/MT/ThreadLock.h \ ./Common/MultiErrorDialog.h \ ./Common/CheckableComboBox.h \ + ./Common/CodeEdit.h \ ./Archive/Archive.h \ ./Archive/ArchiveFS.h \ ./Archive/ArchiveExtractor.h \ @@ -74,6 +75,7 @@ SOURCES += ./MiscHelpers.cpp \ ./Common/MT/ThreadLock.cpp \ ./Common/MultiErrorDialog.cpp \ ./Common/CheckableComboBox.cpp \ + ./Common/CodeEdit.cpp \ ./Archive/Archive.cpp \ ./Archive/ArchiveFS.cpp \ ./Archive/ArchiveExtractor.cpp \ diff --git a/SandboxiePlus/SandMan/Helpers/IniHighlighter.cpp b/SandboxiePlus/SandMan/Helpers/IniHighlighter.cpp new file mode 100644 index 00000000..33c98446 --- /dev/null +++ b/SandboxiePlus/SandMan/Helpers/IniHighlighter.cpp @@ -0,0 +1,246 @@ +#include "stdafx.h" +#include "IniHighlighter.h" + +CIniHighlighter::CIniHighlighter(QTextDocument *parent) + : QSyntaxHighlighter(parent) +{ + HighlightRule rule; + + // Section headers: [Section] + sectionFormat.setForeground(QColor("#0000FF")); // Blue + sectionFormat.setFontWeight(QFont::Bold); + rule.pattern = QRegularExpression("^\\s*\\[.*\\]\\s*$"); + rule.format = sectionFormat; + highlightRules.append(rule); + + // Comments: ; comment or # comment + commentFormat.setForeground(QColor("#008000")); // Green + rule.pattern = QRegularExpression("^\\s*[;#].*"); + rule.format = commentFormat; + highlightRules.append(rule); + + // Keys: key= + keyFormat.setForeground(QColor("#800000")); // Dark Red + rule.pattern = QRegularExpression("^[\\w\\.]+(?=\\s*=)"); + rule.format = keyFormat; + highlightRules.append(rule); + + // Equals sign: = + equalsFormat.setForeground(QColor("#FF0000")); // Red + rule.pattern = QRegularExpression("="); + rule.format = equalsFormat; + highlightRules.append(rule); + + // Values: =value + valueFormat.setForeground(QColor("#000000")); // Black + rule.pattern = QRegularExpression("(?<=\\=).*"); + rule.format = valueFormat; + highlightRules.append(rule); + + // Initialize formats for value prefix and first comma + valuePrefixFormat.setForeground(QColor("#0000FF")); // Blue + firstCommaFormat.setForeground(QColor("#FF0000")); // Red + +#ifdef INI_WITH_JSON + // Initialize JSON formats + jsonKeyFormat.setForeground(QColor("#A52A2A")); // Brown + jsonStringFormat.setForeground(QColor("#000000")); // Black + jsonNumberFormat.setForeground(QColor("#0000FF")); // Blue + jsonBoolNullFormat.setForeground(QColor("#800080")); // Purple + jsonBracesFormat.setForeground(QColor("#808080")); // Gray + jsonColonFormat.setForeground(QColor("#FF0000")); // Red + jsonCommaFormat.setForeground(QColor("#FF0000")); // Red + + // 1. JSON Colon: Match colons not preceded by backslash + HighlightRule jsonRule; + jsonRule.pattern = QRegularExpression(R"((? 0) + braceLevel--; + } else if (currentChar == ',' && braceLevel == 0) { + firstRelevantCommaIndex = i; + break; + } + } + + if (firstRelevantCommaIndex != -1) { + // Position of the first comma relative to the entire line + int commaPos = valueStart + firstRelevantCommaIndex; + + // Highlight text before the first comma in blue + if (firstRelevantCommaIndex > 0) { + setFormat(valueStart, firstRelevantCommaIndex, valuePrefixFormat); + } + + // Highlight the first comma in red + setFormat(commaPos, 1, firstCommaFormat); + } + +#ifdef INI_WITH_JSON + bool inString = false; + int stringStart = -1; + + for (int i = firstRelevantCommaIndex != -1 ? firstRelevantCommaIndex + 1 : 0; i < valueText.length(); ++i) { + QChar currentChar = valueText[i]; + + if (currentChar == '\"') { + // Check if the quote is escaped + bool escaped = false; + int backslashCount = 0; + int j = i - 1; + while (j >= 0 && valueText[j] == '\\') { + backslashCount++; + j--; + } + if (backslashCount % 2 == 1) + escaped = true; + + if (!escaped) { + if (!inString) { + inString = true; + stringStart = valueStart + i; + } + else { + inString = false; + // Apply string formatting from stringStart to current position + int length = (valueStart + i + 1) - stringStart; + setFormat(stringStart, length, jsonStringFormat); + } + } + } + + // Apply colon and comma formatting only if not inside a string + if (!inString) { + if (currentChar == ':') { + setFormat(valueStart + i, 1, jsonColonFormat); + } + else if (currentChar == ',') { + setFormat(valueStart + i, 1, jsonCommaFormat); + } + } + } + + // If still inside a string (unclosed), format till end + if (inString && stringStart != -1) { + int length = text.length() - stringStart; + setFormat(stringStart, length, jsonStringFormat); + } + + // 4. Apply JSON Key Formatting within JSON Substrings + // Find all JSON substrings and apply key formatting + int current = 0; + while (current < valueText.length()) { + int startBrace = valueText.indexOf('{', current); + if (startBrace == -1) + break; + int braceCounter = 1; + int endBrace = startBrace + 1; + while (endBrace < valueText.length() && braceCounter > 0) { + if (valueText[endBrace] == '{') + braceCounter++; + else if (valueText[endBrace] == '}') + braceCounter--; + endBrace++; + } + if (braceCounter == 0) { + // Found a JSON substring from startBrace to endBrace-1 + QString jsonString = valueText.mid(startBrace, endBrace - startBrace); + QRegularExpression keyRegex(R"("(?:(?:\\.)|[^"\\])*"(?=\s*:))"); + QRegularExpressionMatchIterator keyMatches = keyRegex.globalMatch(jsonString); + while (keyMatches.hasNext()) { + QRegularExpressionMatch keyMatch = keyMatches.next(); + int keyStart = valueStart + startBrace + keyMatch.capturedStart(); + int keyLength = keyMatch.capturedLength(); + setFormat(keyStart, keyLength, jsonKeyFormat); + } + current = endBrace; + } + else { + break; + } + } +#endif + } +} \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Helpers/IniHighlighter.h b/SandboxiePlus/SandMan/Helpers/IniHighlighter.h new file mode 100644 index 00000000..6ffff429 --- /dev/null +++ b/SandboxiePlus/SandMan/Helpers/IniHighlighter.h @@ -0,0 +1,46 @@ +#pragma once + +#include + +#define INI_WITH_JSON + +class CIniHighlighter : public QSyntaxHighlighter +{ + Q_OBJECT + +public: + explicit CIniHighlighter(QTextDocument *parent = nullptr); + ~CIniHighlighter(); + +protected: + void highlightBlock(const QString &text) override; + +private: + struct HighlightRule { + QRegularExpression pattern; + QTextCharFormat format; + }; + QVector highlightRules; + + QTextCharFormat sectionFormat; + QTextCharFormat keyFormat; + QTextCharFormat valueFormat; + QTextCharFormat commentFormat; + QTextCharFormat equalsFormat; // New format for '=' character + QTextCharFormat valuePrefixFormat; // Format for text before first comma in value + QTextCharFormat firstCommaFormat; // Format for the first comma in value + +#ifdef INI_WITH_JSON + // JSON-specific formats + QTextCharFormat jsonKeyFormat; + QTextCharFormat jsonStringFormat; + QTextCharFormat jsonNumberFormat; + QTextCharFormat jsonBoolNullFormat; + QTextCharFormat jsonBracesFormat; + QTextCharFormat jsonColonFormat; + QTextCharFormat jsonCommaFormat; + + // JSON highlighting rules + QVector jsonHighlightRules; +#endif +}; diff --git a/SandboxiePlus/SandMan/SandMan.pri b/SandboxiePlus/SandMan/SandMan.pri index b6cede3c..c7eaec5f 100644 --- a/SandboxiePlus/SandMan/SandMan.pri +++ b/SandboxiePlus/SandMan/SandMan.pri @@ -24,6 +24,7 @@ HEADERS += ./stdafx.h \ ./Helpers/ReadDirectoryChanges.h \ ./Helpers/ReadDirectoryChangesPrivate.h \ ./Helpers/TabOrder.h \ + ./Helpers/IniHighlighter.h \ ./Windows/RecoveryWindow.h \ ./Windows/PopUpWindow.h \ ./Windows/SnapshotsWindow.h \ @@ -74,6 +75,7 @@ SOURCES += ./main.cpp \ ./Helpers/StorageInfo.cpp \ ./Helpers/ReadDirectoryChanges.cpp \ ./Helpers/ReadDirectoryChangesPrivate.cpp \ + ./Helpers/IniHighlighter.cpp \ ./Helpers/WindowFromPointEx.cpp \ ./Helpers/TabOrder.cpp \ ./Windows/OptionsWindow.cpp \ diff --git a/SandboxiePlus/SandMan/Windows/OptionsWindow.cpp b/SandboxiePlus/SandMan/Windows/OptionsWindow.cpp index cef30d49..9d0dd040 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/OptionsWindow.cpp @@ -9,6 +9,8 @@ #include "Helpers/WinAdmin.h" #include "../Wizards/TemplateWizard.h" #include "Helpers/TabOrder.h" +#include "../MiscHelpers/Common/CodeEdit.h" +#include "Helpers/IniHighlighter.h" class NoEditDelegate : public QStyledItemDelegate { @@ -575,14 +577,17 @@ COptionsWindow::COptionsWindow(const QSharedPointer& pBox, const QStri connect(ui.tabs, SIGNAL(currentChanged(int)), this, SLOT(OnTab())); // edit + m_pCodeEdit = new CCodeEdit(new CIniHighlighter); + ui.txtIniSection->parentWidget()->layout()->replaceWidget(ui.txtIniSection, m_pCodeEdit); + ui.txtIniSection->deleteLater(); + connect(m_pCodeEdit, SIGNAL(textChanged()), this, SLOT(OnIniChanged())); + ApplyIniEditFont(); connect(ui.btnEditIni, SIGNAL(clicked(bool)), this, SLOT(OnEditIni())); connect(ui.btnSaveIni, SIGNAL(clicked(bool)), this, SLOT(OnSaveIni())); connect(ui.btnCancelEdit, SIGNAL(clicked(bool)), this, SLOT(OnCancelEdit())); - connect(ui.txtIniSection, SIGNAL(textChanged()), this, SLOT(OnIniChanged())); - - // + //connect(ui.txtIniSection, SIGNAL(textChanged()), this, SLOT(OnIniChanged())); connect(ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(ok())); connect(ui.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked(bool)), this, SLOT(apply())); @@ -679,7 +684,8 @@ void COptionsWindow::ApplyIniEditFont() QFont font; // defaults to application font auto fontName = theConf->GetString("UIConfig/IniFont", "").trimmed(); if (!fontName.isEmpty()) bool dummy = font.fromString(fontName); // ignore fromString() fail - ui.txtIniSection->setFont(font); + //ui.txtIniSection->setFont(font); + m_pCodeEdit->setFont(font); } void COptionsWindow::OnSetTree() @@ -1300,7 +1306,8 @@ void COptionsWindow::LoadIniSection() Section = m_pBox->GetAPI()->SbieIniGetEx(m_pBox->GetName(), ""); m_HoldChange = true; - ui.txtIniSection->setPlainText(Section); + //ui.txtIniSection->setPlainText(Section); + m_pCodeEdit->SetCode(Section); m_HoldChange = false; } @@ -1341,7 +1348,8 @@ void COptionsWindow::SaveIniSection() m_pBox->SetRefreshOnChange(true); m_pBox->GetAPI()->CommitIniChanges();*/ - m_pBox->GetAPI()->SbieIniSet(m_pBox->GetName(), "", ui.txtIniSection->toPlainText()); + //m_pBox->GetAPI()->SbieIniSet(m_pBox->GetName(), "", ui.txtIniSection->toPlainText()); + m_pBox->GetAPI()->SbieIniSet(m_pBox->GetName(), "", m_pCodeEdit->GetCode()); LoadIniSection(); } diff --git a/SandboxiePlus/SandMan/Windows/OptionsWindow.h b/SandboxiePlus/SandMan/Windows/OptionsWindow.h index 051ff8b6..c457339f 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsWindow.h +++ b/SandboxiePlus/SandMan/Windows/OptionsWindow.h @@ -639,5 +639,7 @@ private: QMap m_DebugOptions; void InitLangID(); + + class CCodeEdit* m_pCodeEdit; }; diff --git a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp index e0171181..09963491 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp @@ -18,6 +18,8 @@ #include #include #include "Helpers/TabOrder.h" +#include "../MiscHelpers/Common/CodeEdit.h" +#include "Helpers/IniHighlighter.h" #include @@ -597,6 +599,12 @@ CSettingsWindow::CSettingsWindow(QWidget* parent) ui.btnSelectIniFont->setToolTip(tr("Select font")); ui.btnResetIniFont->setIcon(CSandMan::GetIcon("ResetFont")); ui.btnResetIniFont->setToolTip(tr("Reset font")); + + m_pCodeEdit = new CCodeEdit(new CIniHighlighter); + ui.txtIniSection->parentWidget()->layout()->replaceWidget(ui.txtIniSection, m_pCodeEdit); + ui.txtIniSection->deleteLater(); + connect(m_pCodeEdit, SIGNAL(textChanged()), this, SLOT(OnIniChanged())); + ApplyIniEditFont(); connect(ui.btnSelectIniFont, SIGNAL(clicked(bool)), this, SLOT(OnSelectIniEditFont())); @@ -604,7 +612,7 @@ CSettingsWindow::CSettingsWindow(QWidget* parent) connect(ui.btnEditIni, SIGNAL(clicked(bool)), this, SLOT(OnEditIni())); connect(ui.btnSaveIni, SIGNAL(clicked(bool)), this, SLOT(OnSaveIni())); connect(ui.btnCancelEdit, SIGNAL(clicked(bool)), this, SLOT(OnCancelEdit())); - connect(ui.txtIniSection, SIGNAL(textChanged()), this, SLOT(OnIniChanged())); + //connect(ui.txtIniSection, SIGNAL(textChanged()), this, SLOT(OnIniChanged())); // connect(ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(ok())); @@ -657,14 +665,16 @@ void CSettingsWindow::ApplyIniEditFont() QFont font; // defaults to application font auto fontName = theConf->GetString("UIConfig/IniFont", "").trimmed(); if (!fontName.isEmpty()) bool dummy = font.fromString(fontName); // ignore fromString() fail - ui.txtIniSection->setFont(font); + //ui.txtIniSection->setFont(font); + m_pCodeEdit->setFont(font); ui.lblIniEditFont->setText(tr("%0, %1 pt").arg(font.family()).arg(font.pointSizeF())); // tr: example: "Calibri, 9.5 pt" } void CSettingsWindow::OnSelectIniEditFont() { bool ok; - auto newFont = QFontDialog::getFont(&ok, ui.txtIniSection->font(), this); + //auto newFont = QFontDialog::getFont(&ok, ui.txtIniSection->font(), this); + auto newFont = QFontDialog::getFont(&ok, m_pCodeEdit->font(), this); if (!ok) return; theConf->SetValue("UIConfig/IniFont", newFont.toString()); ApplyIniEditFont(); @@ -2531,14 +2541,16 @@ void CSettingsWindow::LoadIniSection() Section = theAPI->SbieIniGetEx("GlobalSettings", ""); m_HoldChange = true; - ui.txtIniSection->setPlainText(Section); + //ui.txtIniSection->setPlainText(Section); + m_pCodeEdit->SetCode(Section); m_HoldChange = false; } void CSettingsWindow::SaveIniSection() { if(theAPI->IsConnected()) - theAPI->SbieIniSet("GlobalSettings", "", ui.txtIniSection->toPlainText()); + //theAPI->SbieIniSet("GlobalSettings", "", ui.txtIniSection->toPlainText()); + theAPI->SbieIniSet("GlobalSettings", "", m_pCodeEdit->GetCode()); LoadIniSection(); } diff --git a/SandboxiePlus/SandMan/Windows/SettingsWindow.h b/SandboxiePlus/SandMan/Windows/SettingsWindow.h index f038e41f..3728559b 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.h +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.h @@ -195,6 +195,8 @@ private: void WriteTextList(const QString& Setting, const QStringList& List); Ui::SettingsWindow ui; + + class CCodeEdit* m_pCodeEdit; }; QVariantMap GetRunEntry(const QString& sEntry);