1.15.3
This commit is contained in:
parent
0cf5d8dc90
commit
ca894bbd2a
|
@ -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<QKeySequence> 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);
|
||||
}*/
|
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include "../mischelpers_global.h"
|
||||
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
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;
|
||||
};
|
|
@ -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 \
|
||||
|
|
|
@ -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"((?<!\\):)");
|
||||
jsonRule.format = jsonColonFormat;
|
||||
jsonHighlightRules.append(jsonRule);
|
||||
|
||||
// 2. JSON Comma: Match commas not preceded by backslash
|
||||
jsonRule.pattern = QRegularExpression(R"((?<!\\),)");
|
||||
jsonRule.format = jsonCommaFormat;
|
||||
jsonHighlightRules.append(jsonRule);
|
||||
|
||||
// 3. JSON Keys: "key":
|
||||
jsonRule.pattern = QRegularExpression(R"("(?:(?:\\.)|[^"\\])*"(?=\s*:))");
|
||||
jsonRule.format = jsonKeyFormat;
|
||||
jsonHighlightRules.append(jsonRule);
|
||||
|
||||
// 4. JSON Strings: "value" (excluding keys)
|
||||
jsonRule.pattern = QRegularExpression(R"("(?:(?:\\.)|[^"\\])*"(?!\s*:))");
|
||||
jsonRule.format = jsonStringFormat;
|
||||
jsonHighlightRules.append(jsonRule);
|
||||
|
||||
// 5. JSON Numbers: 123, 45.67
|
||||
jsonRule.pattern = QRegularExpression(R"(\b-?\d+(\.\d+)?\b)");
|
||||
jsonRule.format = jsonNumberFormat;
|
||||
jsonHighlightRules.append(jsonRule);
|
||||
|
||||
// 6. JSON Booleans and Null: true, false, null
|
||||
jsonRule.pattern = QRegularExpression(R"(\b(true|false|null)\b)", QRegularExpression::CaseInsensitiveOption);
|
||||
jsonRule.format = jsonBoolNullFormat;
|
||||
jsonHighlightRules.append(jsonRule);
|
||||
|
||||
// 7. JSON Braces and Brackets: { }, [ ]
|
||||
jsonRule.pattern = QRegularExpression(R"([\{\}\[\]])");
|
||||
jsonRule.format = jsonBracesFormat;
|
||||
jsonHighlightRules.append(jsonRule);
|
||||
#endif
|
||||
}
|
||||
|
||||
CIniHighlighter::~CIniHighlighter()
|
||||
{
|
||||
}
|
||||
|
||||
void CIniHighlighter::highlightBlock(const QString &text)
|
||||
{
|
||||
// First, reset all formatting
|
||||
setFormat(0, text.length(), QTextCharFormat());
|
||||
|
||||
// 1. Check if the entire line is a comment
|
||||
QRegularExpression commentRegex(R"(^\s*[;#].*)");
|
||||
QRegularExpressionMatch commentMatch = commentRegex.match(text);
|
||||
if (commentMatch.hasMatch()) {
|
||||
setFormat(0, text.length(), commentFormat);
|
||||
return; // Skip other rules
|
||||
}
|
||||
|
||||
// 2. Apply INI highlighting rules (section, key, equals, value)
|
||||
for (const HighlightRule &rule : qAsConst(highlightRules)) {
|
||||
// Skip the comment rule as it's already handled
|
||||
if (rule.format.foreground() == commentFormat.foreground())
|
||||
continue;
|
||||
|
||||
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
|
||||
while (matchIterator.hasNext()) {
|
||||
QRegularExpressionMatch match = matchIterator.next();
|
||||
int start = match.capturedStart();
|
||||
int length = match.capturedLength();
|
||||
setFormat(start, length, rule.format);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Process the value part for value prefixes and first comma
|
||||
// Find the position of '=' to identify the start of the value
|
||||
int equalsIndex = text.indexOf('=');
|
||||
if (equalsIndex != -1) {
|
||||
// Start position of the value (after '=')
|
||||
int valueStart = equalsIndex + 1;
|
||||
QString valueText = text.mid(valueStart).trimmed();
|
||||
|
||||
// Iterate through the value to find the first comma outside of {}
|
||||
int braceLevel = 0;
|
||||
int firstRelevantCommaIndex = -1;
|
||||
for (int i = 0; i < valueText.length(); ++i) {
|
||||
QChar currentChar = valueText[i];
|
||||
if (currentChar == '{') {
|
||||
braceLevel++;
|
||||
} else if (currentChar == '}') {
|
||||
if (braceLevel > 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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
#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<HighlightRule> 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<HighlightRule> jsonHighlightRules;
|
||||
#endif
|
||||
};
|
|
@ -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 \
|
||||
|
|
|
@ -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<CSbieIni>& 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();
|
||||
}
|
||||
|
|
|
@ -639,5 +639,7 @@ private:
|
|||
QMap<QCheckBox*, SDbgOpt> m_DebugOptions;
|
||||
|
||||
void InitLangID();
|
||||
|
||||
class CCodeEdit* m_pCodeEdit;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include "Helpers/TabOrder.h"
|
||||
#include "../MiscHelpers/Common/CodeEdit.h"
|
||||
#include "Helpers/IniHighlighter.h"
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue