Skip to content

Commit

Permalink
1.15.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Nov 20, 2024
1 parent 0cf5d8d commit ca894bb
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 11 deletions.
135 changes: 135 additions & 0 deletions SandboxiePlus/MiscHelpers/Common/CodeEdit.cpp
Original file line number Diff line number Diff line change
@@ -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);
}*/
40 changes: 40 additions & 0 deletions SandboxiePlus/MiscHelpers/Common/CodeEdit.h
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 2 additions & 0 deletions SandboxiePlus/MiscHelpers/MiscHelpers.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
Loading

0 comments on commit ca894bb

Please sign in to comment.