Compare commits
3 Commits
a3b465534c
...
f40d9525b0
Author | SHA1 | Date |
---|---|---|
|
f40d9525b0 | |
|
55ebbcd126 | |
|
7bbe4da34b |
|
@ -1,25 +1,29 @@
|
|||
/*==============================================================================
|
||||
** 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/>.
|
||||
**
|
||||
** The original License is LGPL from Andres6936/QHexEdit. I have modified a lot
|
||||
** so I decide to change the Open Source License. You can use the original
|
||||
** library under LGPL. Thanks for Andres6936's efforts.
|
||||
** =============================================================================
|
||||
/*
|
||||
* QHexEdit is a Hex Editor Widget for the Qt Framework
|
||||
* Copyright (C) 2010-2025 Winfried Simon
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see
|
||||
* https://www.gnu.org/licenses/
|
||||
*/
|
||||
|
||||
#include "chunks.h"
|
||||
#include <limits.h>
|
||||
|
||||
#include <QBuffer>
|
||||
|
||||
#define NORMAL 0
|
||||
#define HIGHLIGHTED 1
|
||||
|
||||
#define BUFFER_SIZE 0x10000
|
||||
#define CHUNK_SIZE 0x1000
|
||||
|
@ -29,38 +33,43 @@
|
|||
|
||||
// ***************************************** Constructors and file settings
|
||||
|
||||
Chunks::Chunks(QObject *parent) : QObject(parent) {}
|
||||
Chunks::Chunks(QObject *parent) : QObject(parent) {
|
||||
QBuffer *buf = new QBuffer(this);
|
||||
setIODevice(buf);
|
||||
}
|
||||
|
||||
Chunks::Chunks(QIODevice *ioDevice, QObject *parent) : QObject(parent) {
|
||||
setIODevice(ioDevice);
|
||||
}
|
||||
|
||||
Chunks::~Chunks() {}
|
||||
|
||||
bool Chunks::setIODevice(QIODevice *ioDevice) {
|
||||
if (ioDevice && ioDevice->isOpen()) {
|
||||
ioDevice->setParent(this);
|
||||
_size = ioDevice->size();
|
||||
_ioDevice = ioDevice;
|
||||
} else {
|
||||
return false;
|
||||
bool ok = _ioDevice->open(QIODevice::ReadOnly);
|
||||
if (ok) // Try to open IODevice
|
||||
{
|
||||
ioDevice->setParent(this);
|
||||
_size = _ioDevice->size();
|
||||
_ioDevice->close();
|
||||
} else // Fallback is an empty buffer
|
||||
{
|
||||
QBuffer *buf = new QBuffer(this);
|
||||
_ioDevice = buf;
|
||||
_size = 0;
|
||||
}
|
||||
_chunks.clear();
|
||||
_pos = 0;
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
// ***************************************** Getting data out of Chunks
|
||||
|
||||
QByteArray Chunks::data(qsizetype pos, qsizetype maxSize) {
|
||||
qsizetype ioDelta = 0;
|
||||
qsizetype chunkIdx = 0;
|
||||
QByteArray Chunks::data(qint64 pos, qint64 maxSize) const {
|
||||
qint64 ioDelta = 0;
|
||||
int chunkIdx = 0;
|
||||
|
||||
Chunk chunk;
|
||||
QByteArray buffer;
|
||||
|
||||
// Do some checks and some arrangements
|
||||
|
||||
if (pos >= _size)
|
||||
return buffer;
|
||||
|
||||
|
@ -69,8 +78,10 @@ QByteArray Chunks::data(qsizetype pos, qsizetype maxSize) {
|
|||
else if ((pos + maxSize) > _size)
|
||||
maxSize = _size - pos;
|
||||
|
||||
_ioDevice->open(QIODevice::ReadOnly);
|
||||
|
||||
while (maxSize > 0) {
|
||||
chunk.absPos = std::numeric_limits<qsizetype>::max();
|
||||
chunk.absPos = LLONG_MAX;
|
||||
bool chunksLoopOngoing = true;
|
||||
while ((chunkIdx < _chunks.count()) && chunksLoopOngoing) {
|
||||
// In this section, we track changes before our required data and
|
||||
|
@ -84,16 +95,16 @@ QByteArray Chunks::data(qsizetype pos, qsizetype maxSize) {
|
|||
else {
|
||||
chunkIdx += 1;
|
||||
qint64 count;
|
||||
qint64 chunkOfs = qint64(pos - chunk.absPos);
|
||||
if (maxSize > (chunk.data.size() - chunkOfs)) {
|
||||
count = qint64(chunk.data.size()) - chunkOfs;
|
||||
ioDelta += CHUNK_SIZE - quint64(chunk.data.size());
|
||||
qint64 chunkOfs = pos - chunk.absPos;
|
||||
if (maxSize > ((qint64)chunk.data.size() - chunkOfs)) {
|
||||
count = (qint64)chunk.data.size() - chunkOfs;
|
||||
ioDelta += CHUNK_SIZE - chunk.data.size();
|
||||
} else
|
||||
count = maxSize;
|
||||
if (count > 0) {
|
||||
buffer += chunk.data.mid(int(chunkOfs), int(count));
|
||||
buffer += chunk.data.mid(chunkOfs, (int)count);
|
||||
maxSize -= count;
|
||||
pos += quint64(count);
|
||||
pos += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +115,7 @@ QByteArray Chunks::data(qsizetype pos, qsizetype maxSize) {
|
|||
|
||||
qint64 byteCount;
|
||||
QByteArray readBuffer;
|
||||
if (chunk.absPos - pos > qsizetype(maxSize))
|
||||
if ((chunk.absPos - pos) > maxSize)
|
||||
byteCount = maxSize;
|
||||
else
|
||||
byteCount = chunk.absPos - pos;
|
||||
|
@ -113,134 +124,175 @@ QByteArray Chunks::data(qsizetype pos, qsizetype maxSize) {
|
|||
_ioDevice->seek(pos + ioDelta);
|
||||
readBuffer = _ioDevice->read(byteCount);
|
||||
buffer += readBuffer;
|
||||
pos += quint64(readBuffer.size());
|
||||
pos += readBuffer.size();
|
||||
}
|
||||
}
|
||||
|
||||
_ioDevice->close();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool Chunks::write(QIODevice *iODevice, qsizetype pos, qsizetype count) {
|
||||
bool Chunks::write(QIODevice *iODevice, qint64 pos, qint64 count) {
|
||||
if (count == -1)
|
||||
count = _size;
|
||||
|
||||
bool ok = iODevice->isOpen() && iODevice->isWritable();
|
||||
if (ok) {
|
||||
for (auto idx = pos; idx < qsizetype(count); idx += BUFFER_SIZE) {
|
||||
if (iODevice->isOpen()) {
|
||||
if (iODevice->isWritable()) {
|
||||
for (qint64 idx = pos; idx < count; idx += BUFFER_SIZE) {
|
||||
QByteArray ba = data(idx, BUFFER_SIZE);
|
||||
iODevice->write(ba);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
bool ok = iODevice->open(QIODevice::WriteOnly);
|
||||
if (ok) {
|
||||
for (qint64 idx = pos; idx < count; idx += BUFFER_SIZE) {
|
||||
QByteArray ba = data(idx, BUFFER_SIZE);
|
||||
iODevice->write(ba);
|
||||
}
|
||||
iODevice->close();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************** Search API
|
||||
|
||||
qsizetype Chunks::indexOf(const QByteArray &ba, qsizetype from) {
|
||||
qsizetype result = -1;
|
||||
qint64 Chunks::indexOf(const QByteArray &ba, qint64 from) const {
|
||||
qint64 result = -1;
|
||||
QByteArray buffer;
|
||||
|
||||
for (auto pos = from; (pos < _size) && (result < 0); pos += BUFFER_SIZE) {
|
||||
for (qint64 pos = from; (pos < _size) && (result < 0); pos += BUFFER_SIZE) {
|
||||
buffer = data(pos, BUFFER_SIZE + ba.size() - 1);
|
||||
int findPos = buffer.indexOf(ba);
|
||||
if (findPos >= 0)
|
||||
result = pos + findPos;
|
||||
result = pos + (qint64)findPos;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
qsizetype Chunks::lastIndexOf(const QByteArray &ba, qsizetype from) {
|
||||
qint64 Chunks::lastIndexOf(const QByteArray &ba, qint64 from) const {
|
||||
qint64 result = -1;
|
||||
QByteArray buffer;
|
||||
|
||||
for (auto pos = from; (pos > 0) && (result < 0); pos -= BUFFER_SIZE) {
|
||||
auto sPos = pos - BUFFER_SIZE - ba.size() + 1;
|
||||
/*if (sPos < 0)
|
||||
sPos = 0;*/
|
||||
for (qint64 pos = from; (pos > 0) && (result < 0); pos -= BUFFER_SIZE) {
|
||||
qint64 sPos = pos - BUFFER_SIZE - (qint64)ba.size() + 1;
|
||||
if (sPos < 0)
|
||||
sPos = 0;
|
||||
buffer = data(sPos, pos - sPos);
|
||||
auto findPos = buffer.lastIndexOf(ba);
|
||||
int findPos = buffer.lastIndexOf(ba);
|
||||
if (findPos >= 0)
|
||||
result = sPos + findPos;
|
||||
result = sPos + (qint64)findPos;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ***************************************** Char manipulations
|
||||
|
||||
bool Chunks::insert(qsizetype pos, char b) {
|
||||
if (pos > _size)
|
||||
bool Chunks::insert(qint64 pos, char b) {
|
||||
return insert(pos, QByteArray(1, b));
|
||||
}
|
||||
|
||||
bool Chunks::overwrite(qint64 pos, char b) {
|
||||
return overwrite(pos, QByteArray(1, b));
|
||||
}
|
||||
|
||||
bool Chunks::removeAt(qint64 pos) { return remove(pos, 1); }
|
||||
|
||||
bool Chunks::insert(qint64 pos, const QByteArray &ba) {
|
||||
if ((pos < 0) || (pos > _size))
|
||||
return false;
|
||||
qsizetype chunkIdx;
|
||||
if (pos == _size) {
|
||||
|
||||
if (ba.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto length = ba.length();
|
||||
int chunkIdx;
|
||||
if (pos == _size)
|
||||
chunkIdx = getChunkIndex(pos - 1);
|
||||
} else
|
||||
else
|
||||
chunkIdx = getChunkIndex(pos);
|
||||
auto posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].data.insert(int(posInBa), b);
|
||||
_chunks[chunkIdx].dataChanged.insert(int(posInBa), char(1));
|
||||
for (auto idx = chunkIdx + 1; idx < _chunks.size(); idx++)
|
||||
_chunks[idx].absPos += 1;
|
||||
_size += 1;
|
||||
_pos = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chunks::overwrite(qsizetype pos, char b) {
|
||||
if (pos >= _size)
|
||||
return false;
|
||||
auto chunkIdx = getChunkIndex(pos);
|
||||
auto posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].data[int(posInBa)] = b;
|
||||
_chunks[chunkIdx].dataChanged[int(posInBa)] = char(1);
|
||||
_pos = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chunks::removeAt(qsizetype pos) {
|
||||
if (pos >= _size)
|
||||
return false;
|
||||
auto chunkIdx = getChunkIndex(pos);
|
||||
auto posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].data.remove(int(posInBa), 1);
|
||||
_chunks[chunkIdx].dataChanged.remove(int(posInBa), 1);
|
||||
qint64 posInBa = pos - _chunks[chunkIdx].absPos;
|
||||
_chunks[chunkIdx].data.insert(posInBa, ba);
|
||||
for (int idx = chunkIdx + 1; idx < _chunks.size(); idx++)
|
||||
_chunks[idx].absPos -= 1;
|
||||
_size -= 1;
|
||||
_pos = pos;
|
||||
_chunks[idx].absPos += length;
|
||||
_size += length;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chunks::overwrite(qint64 pos, const QByteArray &ba) {
|
||||
if ((pos < 0) || (pos >= _size))
|
||||
return false;
|
||||
int chunkIdx = getChunkIndex(pos);
|
||||
|
||||
auto &chunk = _chunks[chunkIdx];
|
||||
qint64 posInBa = pos - chunk.absPos;
|
||||
|
||||
auto length = ba.length();
|
||||
auto clen = chunk.data.size();
|
||||
auto dist = length + posInBa - clen;
|
||||
|
||||
if (dist <= 0) {
|
||||
chunk.data.replace(posInBa, length, ba);
|
||||
} else {
|
||||
auto len = clen - posInBa;
|
||||
chunk.data.replace(posInBa, len, ba.left(len));
|
||||
if (!overwrite(pos + clen, ba.right(dist))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chunks::remove(qint64 pos, qint64 length) {
|
||||
if ((pos < 0) || (pos >= _size))
|
||||
return false;
|
||||
int chunkIdx = getChunkIndex(pos);
|
||||
|
||||
auto &chunk = _chunks[chunkIdx];
|
||||
qint64 posInBa = pos - chunk.absPos;
|
||||
|
||||
auto clen = chunk.data.size();
|
||||
auto dist = length + posInBa - clen;
|
||||
|
||||
if (dist <= 0) {
|
||||
chunk.data.remove(posInBa, length);
|
||||
for (int idx = chunkIdx + 1; idx < _chunks.size(); idx++)
|
||||
_chunks[idx].absPos += length;
|
||||
_size -= length;
|
||||
} else {
|
||||
auto len = clen - posInBa;
|
||||
chunk.data.remove(posInBa, len);
|
||||
for (int idx = chunkIdx + 1; idx < _chunks.size(); idx++)
|
||||
_chunks[idx].absPos -= len;
|
||||
_size -= len;
|
||||
|
||||
if (!remove(pos + clen, dist)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ***************************************** Utility functions
|
||||
|
||||
char Chunks::operator[](qsizetype pos) {
|
||||
auto d = data(pos, 1);
|
||||
if (d.isEmpty())
|
||||
return '0';
|
||||
return d.at(0);
|
||||
}
|
||||
char Chunks::at(qint64 pos) const { return data(pos, 1).at(0); }
|
||||
|
||||
qsizetype Chunks::pos() { return _pos; }
|
||||
char Chunks::operator[](qint64 pos) const { return this->at(pos); }
|
||||
|
||||
qsizetype Chunks::size() { return _size; }
|
||||
qint64 Chunks::size() const { return _size; }
|
||||
|
||||
qsizetype Chunks::getChunkIndex(qsizetype absPos) {
|
||||
// This routine checks, if there is already a copied chunk available. If so,
|
||||
int Chunks::getChunkIndex(qint64 absPos) {
|
||||
// This routine checks, if there is already a copied chunk available. If os,
|
||||
// it returns a reference to it. If there is no copied chunk available,
|
||||
// original data will be copied into a new chunk.
|
||||
|
||||
qsizetype foundIdx = -1;
|
||||
qsizetype insertIdx = 0;
|
||||
qsizetype ioDelta = 0;
|
||||
|
||||
// fix the bug by wingsummer
|
||||
if (absPos < 0) {
|
||||
Chunk newChunk;
|
||||
newChunk.data = QByteArray(CHUNK_SIZE, 0);
|
||||
newChunk.absPos = 0;
|
||||
newChunk.dataChanged = nullptr;
|
||||
_chunks.insert(insertIdx, newChunk);
|
||||
return insertIdx;
|
||||
}
|
||||
int foundIdx = -1;
|
||||
int insertIdx = 0;
|
||||
qint64 ioDelta = 0;
|
||||
|
||||
for (int idx = 0; idx < _chunks.size(); idx++) {
|
||||
Chunk chunk = _chunks[idx];
|
||||
|
@ -259,14 +311,17 @@ qsizetype Chunks::getChunkIndex(qsizetype absPos) {
|
|||
|
||||
if (foundIdx == -1) {
|
||||
Chunk newChunk;
|
||||
qsizetype readAbsPos = absPos - ioDelta;
|
||||
qsizetype readPos = (readAbsPos & READ_CHUNK_MASK);
|
||||
_ioDevice->seek(qint64(readPos));
|
||||
qint64 readAbsPos = absPos - ioDelta;
|
||||
qint64 readPos = (readAbsPos & READ_CHUNK_MASK);
|
||||
_ioDevice->open(QIODevice::ReadOnly);
|
||||
_ioDevice->seek(readPos);
|
||||
newChunk.data = _ioDevice->read(CHUNK_SIZE);
|
||||
_ioDevice->close();
|
||||
newChunk.absPos = absPos - (readAbsPos - readPos);
|
||||
newChunk.dataChanged = QByteArray(newChunk.data.size(), char(0));
|
||||
_chunks.insert(insertIdx, newChunk);
|
||||
foundIdx = insertIdx;
|
||||
}
|
||||
return foundIdx;
|
||||
}
|
||||
|
||||
QIODevice *Chunks::ioDevice() const { return _ioDevice; }
|
||||
|
|
|
@ -1,22 +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/>.
|
||||
**
|
||||
** The original License is LGPL from Andres6936/QHexEdit. I have modified a lot
|
||||
** so I decide to change the Open Source License. You can use the original
|
||||
** library under LGPL. Thanks for Andres6936's efforts.
|
||||
** =============================================================================
|
||||
/*
|
||||
* QHexEdit is a Hex Editor Widget for the Qt Framework
|
||||
* Copyright (C) 2010-2025 Winfried Simon
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see
|
||||
* https://www.gnu.org/licenses/
|
||||
*/
|
||||
|
||||
#ifndef CHUNKS_H
|
||||
|
@ -40,49 +38,59 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtGlobal>
|
||||
// I (wingsummer) made some modifications for supporting QByteArray
|
||||
// manipulations, great thanks for Simsys's effort!
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
|
||||
struct Chunk {
|
||||
QByteArray data;
|
||||
QByteArray dataChanged;
|
||||
qsizetype absPos;
|
||||
qint64 absPos;
|
||||
};
|
||||
|
||||
class Chunks : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and file settings
|
||||
Chunks(QObject *parent = nullptr);
|
||||
Chunks(QIODevice *ioDevice, QObject *parent);
|
||||
|
||||
~Chunks();
|
||||
explicit Chunks(QObject *parent);
|
||||
explicit Chunks(QIODevice *ioDevice, QObject *parent);
|
||||
|
||||
public:
|
||||
QIODevice *ioDevice() const;
|
||||
bool setIODevice(QIODevice *ioDevice);
|
||||
|
||||
// Getting data out of Chunks
|
||||
QByteArray data(qsizetype pos = 0, qsizetype maxSize = -1);
|
||||
bool write(QIODevice *iODevice, qsizetype pos = 0, qsizetype count = -1);
|
||||
QByteArray data(qint64 pos = 0, qint64 count = -1) const;
|
||||
bool write(QIODevice *iODevice, qint64 pos = 0, qint64 count = -1);
|
||||
|
||||
// Search API
|
||||
qsizetype indexOf(const QByteArray &ba, qsizetype from);
|
||||
qsizetype lastIndexOf(const QByteArray &ba, qsizetype from);
|
||||
qint64 indexOf(const QByteArray &ba, qint64 from) const;
|
||||
qint64 lastIndexOf(const QByteArray &ba, qint64 from) const;
|
||||
|
||||
// Char manipulations
|
||||
bool insert(qsizetype pos, char b);
|
||||
bool overwrite(qsizetype pos, char b);
|
||||
bool removeAt(qsizetype pos);
|
||||
bool insert(qint64 pos, char b);
|
||||
bool overwrite(qint64 pos, char b);
|
||||
bool removeAt(qint64 pos);
|
||||
|
||||
// QByteArray manipulations by wingsummer
|
||||
bool insert(qint64 pos, const QByteArray &ba);
|
||||
bool overwrite(qint64 pos, const QByteArray &ba);
|
||||
bool remove(qint64 pos, qint64 length);
|
||||
|
||||
// Utility functions
|
||||
char operator[](qsizetype pos);
|
||||
qsizetype pos();
|
||||
qsizetype size();
|
||||
char at(qint64 pos) const; // by wingsummer
|
||||
char operator[](qint64 pos) const;
|
||||
qint64 size() const;
|
||||
|
||||
private:
|
||||
int getChunkIndex(qint64 absPos);
|
||||
|
||||
private:
|
||||
qsizetype getChunkIndex(qsizetype absPos);
|
||||
QIODevice *_ioDevice;
|
||||
qsizetype _pos;
|
||||
qsizetype _size;
|
||||
qint64 _size;
|
||||
QList<Chunk> _chunks;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,28 +18,24 @@
|
|||
#include "QHexEdit2/chunks.h"
|
||||
|
||||
QFileBuffer::QFileBuffer(QObject *parent) : QHexBuffer(parent) {
|
||||
_chunks = new Chunks(parent);
|
||||
_chunks = new Chunks(this);
|
||||
}
|
||||
|
||||
QFileBuffer::~QFileBuffer() {}
|
||||
|
||||
uchar QFileBuffer::at(qsizetype idx) {
|
||||
auto data = _chunks->data(idx, 1);
|
||||
return uchar(data[0]);
|
||||
auto data = _chunks->at(idx);
|
||||
return uchar(data);
|
||||
}
|
||||
|
||||
qsizetype QFileBuffer::length() const { return _chunks->size(); }
|
||||
|
||||
void QFileBuffer::insert(qsizetype offset, const QByteArray &data) {
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
_chunks->insert(offset + i, data.at(i));
|
||||
}
|
||||
_chunks->insert(offset, data);
|
||||
}
|
||||
|
||||
void QFileBuffer::remove(qsizetype offset, qsizetype length) {
|
||||
for (uint i = 0; i < uint(length); i++) {
|
||||
_chunks->removeAt(offset + i);
|
||||
}
|
||||
_chunks->remove(offset, length);
|
||||
}
|
||||
|
||||
QByteArray QFileBuffer::read(qsizetype offset, qsizetype length) {
|
||||
|
@ -47,7 +43,11 @@ QByteArray QFileBuffer::read(qsizetype offset, qsizetype length) {
|
|||
}
|
||||
|
||||
bool QFileBuffer::read(QIODevice *device) {
|
||||
return _chunks->setIODevice(device);
|
||||
auto d = _chunks->ioDevice();
|
||||
auto ret = _chunks->setIODevice(device);
|
||||
d->setParent(nullptr);
|
||||
d->deleteLater();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void QFileBuffer::write(QIODevice *device) { _chunks->write(device); }
|
||||
|
|
|
@ -617,6 +617,7 @@ QHexDocument::QHexDocument(QHexBuffer *buffer, bool readonly)
|
|||
: QObject(nullptr), m_baseaddress(0), m_readonly(false), m_keepsize(false),
|
||||
m_islocked(false) {
|
||||
|
||||
buffer->setParent(this);
|
||||
m_buffer = buffer;
|
||||
m_areaindent = DEFAULT_AREA_IDENTATION;
|
||||
m_hexlinewidth = DEFAULT_HEX_LINE_LENGTH;
|
||||
|
@ -874,28 +875,13 @@ qsizetype QHexDocument::findPreviousExt(qsizetype begin,
|
|||
return findPreviousExt(begin, patterns);
|
||||
}
|
||||
|
||||
QHexDocument *QHexDocument::fromLargeFile(const QString &filename,
|
||||
bool readonly) {
|
||||
|
||||
auto f = new QFile;
|
||||
if (!filename.isEmpty()) {
|
||||
f->setFileName(filename);
|
||||
QHexBuffer *hexbuffer = new QFileBuffer();
|
||||
if (f->open(readonly ? QFile::ReadOnly : QFile::ReadWrite) &&
|
||||
hexbuffer->read(f)) {
|
||||
return new QHexDocument(hexbuffer,
|
||||
readonly); // modified by wingsummer
|
||||
} else {
|
||||
delete hexbuffer;
|
||||
}
|
||||
} else {
|
||||
delete f;
|
||||
return new QHexDocument(new QFileBuffer(), readonly);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QHexBuffer *QHexDocument::buffer() const { return m_buffer; }
|
||||
|
||||
void QHexDocument::setBuffer(QHexBuffer *buffer) {
|
||||
if (buffer) {
|
||||
m_buffer->deleteLater();
|
||||
m_buffer = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
QUndoStack *QHexDocument::undoStack() const { return m_undostack; }
|
||||
|
|
|
@ -237,10 +237,9 @@ public:
|
|||
template <typename T>
|
||||
static QHexDocument *fromMemory(const QByteArray &ba,
|
||||
bool readonly = false);
|
||||
static QHexDocument *fromLargeFile(const QString &filename,
|
||||
bool readonly = false);
|
||||
|
||||
QHexBuffer *buffer() const;
|
||||
void setBuffer(QHexBuffer *buffer);
|
||||
|
||||
QUndoStack *undoStack() const;
|
||||
|
||||
|
@ -304,7 +303,6 @@ QHexDocument *QHexDocument::fromDevice(QIODevice *iodevice, bool readonly) {
|
|||
|
||||
if (!iodevice->isOpen()) {
|
||||
needsclose = true;
|
||||
iodevice->open(QIODevice::ReadOnly);
|
||||
}
|
||||
|
||||
QHexBuffer *hexbuffer = new T();
|
||||
|
@ -314,6 +312,9 @@ QHexDocument *QHexDocument::fromDevice(QIODevice *iodevice, bool readonly) {
|
|||
|
||||
return new QHexDocument(hexbuffer, readonly);
|
||||
} else {
|
||||
if (needsclose)
|
||||
iodevice->close();
|
||||
|
||||
delete hexbuffer;
|
||||
}
|
||||
|
||||
|
@ -322,17 +323,24 @@ QHexDocument *QHexDocument::fromDevice(QIODevice *iodevice, bool readonly) {
|
|||
|
||||
template <typename T>
|
||||
QHexDocument *QHexDocument::fromFile(QString filename, bool readonly) {
|
||||
QFile f;
|
||||
QHexDocument *doc;
|
||||
if (filename.length()) {
|
||||
f.setFileName(filename);
|
||||
f.open(QFile::ReadOnly);
|
||||
doc = QHexDocument::fromDevice<T>(&f, readonly);
|
||||
f.close();
|
||||
} else {
|
||||
doc = new QHexDocument(new T(), readonly);
|
||||
auto f = new QFile;
|
||||
if (!filename.isEmpty()) {
|
||||
f->setFileName(filename);
|
||||
QHexBuffer *hexbuffer = new T();
|
||||
if (f->open(readonly ? QFile::ReadOnly : QFile::ReadWrite)) {
|
||||
f->close();
|
||||
if (hexbuffer->read(f)) {
|
||||
// modified by wingsummer
|
||||
return new QHexDocument(hexbuffer, readonly);
|
||||
}
|
||||
return doc;
|
||||
} else {
|
||||
delete hexbuffer;
|
||||
}
|
||||
} else {
|
||||
delete f;
|
||||
return new QHexDocument(new T(), readonly);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -28,6 +28,7 @@ add_definitions(-DAS_NO_THREADS)
|
|||
|
||||
if(BUILD_TEST_PLUGIN)
|
||||
add_subdirectory(TestPlugin)
|
||||
add_subdirectory(TestBadPlugin)
|
||||
add_subdirectory(TestManager)
|
||||
endif()
|
||||
|
||||
|
@ -302,7 +303,9 @@ set(CLASS_SRC
|
|||
src/class/wingangel.h
|
||||
src/class/wingangel.cpp
|
||||
src/class/winggeneric.h
|
||||
src/class/winggeneric.cpp)
|
||||
src/class/winggeneric.cpp
|
||||
src/class/changedstringlist.h
|
||||
src/class/changedstringlist.cpp)
|
||||
|
||||
set(INTERNAL_PLG_SRC
|
||||
src/class/wingangelapi.h src/class/wingangelapi.cpp
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(TestBadPlugin)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
|
||||
|
||||
# Test mode, please configure the main program directory to facilitate debugging
|
||||
|
||||
# 测试模式,启用请配置主程序目录,方便调试
|
||||
|
||||
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||
option(TEST_MODE TRUE)
|
||||
|
||||
# For Qt
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(
|
||||
Qt${QT_VERSION_MAJOR}
|
||||
COMPONENTS Widgets
|
||||
REQUIRED)
|
||||
|
||||
add_library(TestBadPlugin SHARED TestBadPlugin.json
|
||||
testbadplugin.h testbadplugin.cpp)
|
||||
|
||||
set_target_properties(TestBadPlugin PROPERTIES SUFFIX ".wingplg")
|
||||
|
||||
if(TEST_MODE)
|
||||
# If you want to be able to debug easily every time you compile, please set
|
||||
# this variable. Because this test plugin is a subproject of the main
|
||||
# project, use CMAKE_BINARY_DIR
|
||||
|
||||
# 如果你想每次编译都能够方便调试的话,请设置这个变量。因为这个测试插件是和主项目子项目,所以用 CMAKE_BINARY_DIR
|
||||
|
||||
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||
set(WINGHEX_PATH "${CMAKE_BINARY_DIR}")
|
||||
|
||||
set(WINGHEX_PLUGIN_PATH "${WINGHEX_PATH}/plugin")
|
||||
add_custom_command(
|
||||
TARGET TestBadPlugin
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${WINGHEX_PLUGIN_PATH}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
$<TARGET_FILE:TestBadPlugin> ${WINGHEX_PLUGIN_PATH})
|
||||
endif()
|
||||
|
||||
target_link_libraries(TestBadPlugin PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
|
||||
WingPlugin)
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"Id": "TestBadPlugin",
|
||||
"SDK": 18,
|
||||
"Version": "0.0.1",
|
||||
"Vendor": "WingCloudStudio",
|
||||
"Dependencies": [
|
||||
|
||||
],
|
||||
"Author": "wingsummer",
|
||||
"License": "MIT",
|
||||
"Url": "https://github.com/Wing-summer/WingHexExplorer2"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*==============================================================================
|
||||
** Copyright (C) 2024-2027 WingSummer
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and associated documentation files (the "Software"), to deal
|
||||
** in the Software without restriction, including without limitation the rights
|
||||
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
** copies of the Software, and to permit persons to whom the Software is
|
||||
** furnished to do so.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
** THE SOFTWARE.
|
||||
** =============================================================================
|
||||
*/
|
||||
|
||||
#include "testbadplugin.h"
|
||||
|
||||
TestBadPlugin::TestBadPlugin() {}
|
||||
|
||||
bool TestBadPlugin::init(const std::unique_ptr<QSettings> &set) {
|
||||
Q_UNUSED(set);
|
||||
msgCritical(
|
||||
nullptr, QStringLiteral("TestBadPlugin"),
|
||||
QStringLiteral("Hello, pals! I'm a evil MESSAGEBOX! PLEASE BAN ME!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestBadPlugin::unload(std::unique_ptr<QSettings> &set) { Q_UNUSED(set); }
|
||||
|
||||
const QString TestBadPlugin::pluginName() const {
|
||||
return QStringLiteral("TestBadPlugin");
|
||||
}
|
||||
|
||||
const QString TestBadPlugin::pluginComment() const {
|
||||
return QStringLiteral("TestBadPlugin: popup a messagebox when startup!");
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*==============================================================================
|
||||
** Copyright (C) 2024-2027 WingSummer
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and associated documentation files (the "Software"), to deal
|
||||
** in the Software without restriction, including without limitation the rights
|
||||
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
** copies of the Software, and to permit persons to whom the Software is
|
||||
** furnished to do so.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
** THE SOFTWARE.
|
||||
** =============================================================================
|
||||
*/
|
||||
|
||||
#ifndef TESTBADPLUGIN_H
|
||||
#define TESTBADPLUGIN_H
|
||||
|
||||
#include "WingPlugin/iwingplugin.h"
|
||||
|
||||
class TestBadPlugin : public WingHex::IWingPlugin {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PLUGIN_METADATA(IID "com.wingsummer.iwingplugin" FILE
|
||||
"TestBadPlugin.json")
|
||||
Q_INTERFACES(WingHex::IWingPlugin)
|
||||
public:
|
||||
TestBadPlugin();
|
||||
|
||||
// IWingPluginCoreBase interface
|
||||
public:
|
||||
virtual bool init(const std::unique_ptr<QSettings> &set) override;
|
||||
virtual void unload(std::unique_ptr<QSettings> &set) override;
|
||||
|
||||
// IWingPluginBase interface
|
||||
public:
|
||||
virtual const QString pluginName() const override;
|
||||
virtual const QString pluginComment() const override;
|
||||
};
|
||||
|
||||
#endif // TESTBADPLUGIN_H
|
|
@ -4,6 +4,6 @@
|
|||
"Version": "0.0.1",
|
||||
"Vendor": "WingCloudStudio",
|
||||
"Author": "wingsummer",
|
||||
"License": "AGPL-3.0",
|
||||
"License": "MIT",
|
||||
"Url": "https://github.com/Wing-summer/WingHexExplorer2"
|
||||
}
|
||||
|
|
|
@ -28,11 +28,14 @@ TestManager::~TestManager() {
|
|||
}
|
||||
|
||||
bool TestManager::init(const std::unique_ptr<QSettings> &set) {
|
||||
Q_UNUSED(set);
|
||||
_banTestBadPlugin = set->value("BanTestBadPlugin").toBool();
|
||||
content->initConfig(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestManager::unload(std::unique_ptr<QSettings> &set) { Q_UNUSED(set); }
|
||||
void TestManager::unload(std::unique_ptr<QSettings> &set) {
|
||||
set->setValue("BanTestBadPlugin", _banTestBadPlugin);
|
||||
}
|
||||
|
||||
const QString TestManager::comment() const {
|
||||
return QStringLiteral("Hello world!");
|
||||
|
@ -55,3 +58,12 @@ bool TestManager::enterGuard(const QMetaObject *sender, const QString &sig,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestManager::onLoadingPlugin(const QString &fileName,
|
||||
const WingHex::PluginInfo &info) {
|
||||
Q_UNUSED(fileName);
|
||||
if (info.id == QStringLiteral("TestBadPlugin")) {
|
||||
return !_banTestBadPlugin;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,10 @@ private:
|
|||
_cbblk = new QCheckBox(QStringLiteral("Disable msg*"), this);
|
||||
_cbblk->setChecked(false);
|
||||
layout->addWidget(_cbblk);
|
||||
|
||||
_banclk = new QCheckBox(QStringLiteral("BanTestBadPlugin"), this);
|
||||
|
||||
layout->addWidget(_banclk);
|
||||
layout->addStretch();
|
||||
}
|
||||
// PageBase interface
|
||||
|
@ -72,27 +76,33 @@ private:
|
|||
|
||||
// SettingInterface interface
|
||||
public:
|
||||
virtual void apply() override { _isDisabled = _cbblk->isChecked(); }
|
||||
virtual void reset() override {
|
||||
_isDisabled = false;
|
||||
_cbblk->setChecked(false);
|
||||
virtual void restore() override { _cbblk->setChecked(false); }
|
||||
|
||||
void initConfig(TestManager *man) {
|
||||
_banclk->setChecked(man->_banTestBadPlugin);
|
||||
connect(_banclk, &QCheckBox::toggled, this, [man, this](bool b) {
|
||||
man->_banTestBadPlugin = b;
|
||||
Q_EMIT optionNeedRestartChanged();
|
||||
});
|
||||
}
|
||||
virtual void cancel() override { _cbblk->setChecked(_isDisabled); }
|
||||
|
||||
public:
|
||||
bool isDisableMsg() const { return _isDisabled; }
|
||||
bool isDisableMsg() const { return _cbblk->isChecked(); }
|
||||
|
||||
private:
|
||||
QCheckBox *_cbblk;
|
||||
bool _isDisabled = false;
|
||||
QCheckBox *_cbblk, *_banclk;
|
||||
};
|
||||
|
||||
public slots:
|
||||
virtual bool enterGuard(const QMetaObject *sender, const QString &sig,
|
||||
const QVariantList ¶ms) override;
|
||||
|
||||
virtual bool onLoadingPlugin(const QString &fileName,
|
||||
const WingHex::PluginInfo &info) override;
|
||||
|
||||
private:
|
||||
TestPage *content;
|
||||
bool _banTestBadPlugin = false;
|
||||
};
|
||||
|
||||
#endif // TESTMANAGER_H
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
|
||||
],
|
||||
"Author": "wingsummer",
|
||||
"License": "AGPL-3.0",
|
||||
"License": "MIT",
|
||||
"Url": "https://github.com/Wing-summer/WingHexExplorer2"
|
||||
}
|
||||
|
|
|
@ -269,60 +269,60 @@
|
|||
<context>
|
||||
<name>TestPlugin</name>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="69"/>
|
||||
<location filename="../testplugin.cpp" line="68"/>
|
||||
<source>Test</source>
|
||||
<translation>测试</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="81"/>
|
||||
<location filename="../testplugin.cpp" line="90"/>
|
||||
<location filename="../testplugin.cpp" line="95"/>
|
||||
<location filename="../testplugin.cpp" line="164"/>
|
||||
<location filename="../testplugin.cpp" line="79"/>
|
||||
<location filename="../testplugin.cpp" line="82"/>
|
||||
<location filename="../testplugin.cpp" line="85"/>
|
||||
<location filename="../testplugin.cpp" line="144"/>
|
||||
<source>TestPlugin</source>
|
||||
<translation>测试插件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="99"/>
|
||||
<location filename="../testplugin.cpp" line="89"/>
|
||||
<source>Button - </source>
|
||||
<translation>按钮 - </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="103"/>
|
||||
<location filename="../testplugin.cpp" line="92"/>
|
||||
<source>Click</source>
|
||||
<translation>点击</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="167"/>
|
||||
<location filename="../testplugin.cpp" line="147"/>
|
||||
<source>A Test Plugin for WingHexExplorer2.</source>
|
||||
<translation>一个用来测试羽云十六进制编辑器2的插件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="196"/>
|
||||
<location filename="../testplugin.cpp" line="204"/>
|
||||
<location filename="../testplugin.cpp" line="213"/>
|
||||
<location filename="../testplugin.cpp" line="234"/>
|
||||
<location filename="../testplugin.cpp" line="250"/>
|
||||
<location filename="../testplugin.cpp" line="257"/>
|
||||
<location filename="../testplugin.cpp" line="264"/>
|
||||
<location filename="../testplugin.cpp" line="271"/>
|
||||
<location filename="../testplugin.cpp" line="278"/>
|
||||
<location filename="../testplugin.cpp" line="307"/>
|
||||
<location filename="../testplugin.cpp" line="315"/>
|
||||
<location filename="../testplugin.cpp" line="323"/>
|
||||
<location filename="../testplugin.cpp" line="331"/>
|
||||
<location filename="../testplugin.cpp" line="340"/>
|
||||
<location filename="../testplugin.cpp" line="347"/>
|
||||
<location filename="../testplugin.cpp" line="176"/>
|
||||
<location filename="../testplugin.cpp" line="184"/>
|
||||
<location filename="../testplugin.cpp" line="193"/>
|
||||
<location filename="../testplugin.cpp" line="214"/>
|
||||
<location filename="../testplugin.cpp" line="230"/>
|
||||
<location filename="../testplugin.cpp" line="237"/>
|
||||
<location filename="../testplugin.cpp" line="244"/>
|
||||
<location filename="../testplugin.cpp" line="251"/>
|
||||
<location filename="../testplugin.cpp" line="258"/>
|
||||
<location filename="../testplugin.cpp" line="287"/>
|
||||
<location filename="../testplugin.cpp" line="295"/>
|
||||
<location filename="../testplugin.cpp" line="303"/>
|
||||
<location filename="../testplugin.cpp" line="311"/>
|
||||
<location filename="../testplugin.cpp" line="320"/>
|
||||
<location filename="../testplugin.cpp" line="327"/>
|
||||
<source>InvalidParamsCount</source>
|
||||
<translation>无效参数个数</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="227"/>
|
||||
<location filename="../testplugin.cpp" line="243"/>
|
||||
<location filename="../testplugin.cpp" line="207"/>
|
||||
<location filename="../testplugin.cpp" line="223"/>
|
||||
<source>InvalidParam</source>
|
||||
<translation>非法参数</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../testplugin.cpp" line="298"/>
|
||||
<location filename="../testplugin.cpp" line="278"/>
|
||||
<source>AllocArrayFailed</source>
|
||||
<translation>分配数组失败</translation>
|
||||
</message>
|
||||
|
|
|
@ -58,7 +58,6 @@ bool TestPlugin::init(const std::unique_ptr<QSettings> &set) {
|
|||
_tform->setMaximumHeight(500);
|
||||
|
||||
using TBInfo = WingHex::WingRibbonToolBoxInfo;
|
||||
TBInfo::RibbonCatagories cats;
|
||||
auto tb = new QToolButton;
|
||||
|
||||
// 这里有一个约定,对于含有图片的,前缀应为:/images/插件的 PUID
|
||||
|
@ -74,61 +73,42 @@ bool TestPlugin::init(const std::unique_ptr<QSettings> &set) {
|
|||
}
|
||||
});
|
||||
|
||||
{
|
||||
WingHex::WingRibbonToolBoxInfo rtinfo;
|
||||
rtinfo.catagory = cats.PLUGIN;
|
||||
TBInfo::Toolbox tbtb;
|
||||
tbtb.name = tr("TestPlugin");
|
||||
tbtb.tools = {tb};
|
||||
rtinfo.toolboxs = {tbtb};
|
||||
_rtbinfo.append(rtinfo);
|
||||
}
|
||||
|
||||
{
|
||||
WingHex::WingRibbonToolBoxInfo rtinfo;
|
||||
rtinfo.catagory = QStringLiteral("TestPlugin");
|
||||
rtinfo.displayName = tr("TestPlugin");
|
||||
|
||||
QIcon btnIcon(QStringLiteral(":/images/TestPlugin/images/btn.png"));
|
||||
|
||||
_rtbinfo << createRibbonToolBox(WingHex::WingRibbonCatagories::PLUGIN,
|
||||
createToolBox(tr("TestPlugin"), tb));
|
||||
|
||||
auto rtb =
|
||||
createRibbonToolBox(QStringLiteral("TestPlugin"), tr("TestPlugin"));
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
TBInfo::Toolbox tbtb;
|
||||
tbtb.name = tr("TestPlugin") + QStringLiteral("(%1)").arg(i);
|
||||
for (int y = 0; y < 5; ++y) {
|
||||
auto tb = new QToolButton;
|
||||
tb->setIcon(btnIcon);
|
||||
tb->setText(tr("Button - ") +
|
||||
QStringLiteral("(%1, %2)").arg(i).arg(y));
|
||||
connect(tb, &QToolButton::clicked, this, [this] {
|
||||
tbtb.tools << createToolButton(
|
||||
btnIcon,
|
||||
tr("Button - ") + QStringLiteral("(%1, %2)").arg(i).arg(y),
|
||||
this, [this] {
|
||||
auto tb = qobject_cast<QToolButton *>(sender());
|
||||
msgInformation(nullptr, tr("Click"), tb->text());
|
||||
});
|
||||
tbtb.tools.append(tb);
|
||||
}
|
||||
rtinfo.toolboxs.append(tbtb);
|
||||
}
|
||||
_rtbinfo.append(rtinfo);
|
||||
rtb.toolboxs.append(tbtb);
|
||||
}
|
||||
_rtbinfo.append(rtb);
|
||||
|
||||
_setpages.append(new TestSettingPage(
|
||||
QStringLiteral("Test1"), QStringLiteral("This is a Test1"), true));
|
||||
_setpages = {new TestSettingPage(QStringLiteral("Test1"),
|
||||
QStringLiteral("This is a Test1"), true),
|
||||
new TestSettingPage(QStringLiteral("Test2"),
|
||||
QStringLiteral("This is a Test2"), false)};
|
||||
|
||||
_setpages.append(new TestSettingPage(
|
||||
QStringLiteral("Test2"), QStringLiteral("This is a Test2"), false));
|
||||
|
||||
{
|
||||
WingHex::WingDockWidgetInfo info;
|
||||
// DockWidget test
|
||||
auto lbl = new QLabel(QStringLiteral("DockTest1"));
|
||||
lbl->setAlignment(Qt::AlignCenter);
|
||||
info.widget = lbl;
|
||||
info.widgetName = QStringLiteral("DockTest1");
|
||||
info.area = Qt::LeftDockWidgetArea;
|
||||
_winfo.append(info);
|
||||
}
|
||||
_winfo << WingHex::createWingDockWidget(QStringLiteral("DockTest1"), lbl,
|
||||
Qt::LeftDockWidgetArea);
|
||||
|
||||
{
|
||||
auto ev = QSharedPointer<TestWingEditorViewWidget::Creator>::create();
|
||||
_evws.append(ev);
|
||||
}
|
||||
|
||||
_tmenu = new QMenu(QStringLiteral("TestPlugin"));
|
||||
auto micon = QIcon(QStringLiteral(":/images/TestPlugin/images/btn.png"));
|
||||
|
@ -481,9 +461,8 @@ void TestPlugin::testCrash() {
|
|||
}
|
||||
|
||||
WingHex::IWingPlugin::RegisteredEvents TestPlugin::registeredEvents() const {
|
||||
RegisteredEvents evs;
|
||||
evs.setFlag(RegisteredEvent::AppReady);
|
||||
return evs;
|
||||
return packupEvent(RegisteredEvent::AppReady,
|
||||
RegisteredEvent::HexEditorViewPaint);
|
||||
}
|
||||
|
||||
void TestPlugin::eventReady() {
|
||||
|
|
|
@ -41,8 +41,4 @@ QString TestSettingPage::id() const { return _id; }
|
|||
|
||||
bool TestSettingPage::showInRibbon() const { return _isShownInRibbton; }
|
||||
|
||||
void TestSettingPage::apply() {}
|
||||
|
||||
void TestSettingPage::reset() {}
|
||||
|
||||
void TestSettingPage::cancel() {}
|
||||
void TestSettingPage::restore() {}
|
||||
|
|
|
@ -41,9 +41,7 @@ public:
|
|||
|
||||
// SettingPage interface
|
||||
public:
|
||||
virtual void apply() override;
|
||||
virtual void reset() override;
|
||||
virtual void cancel() override;
|
||||
virtual void restore() override;
|
||||
|
||||
private:
|
||||
QLabel *_lbl = nullptr;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 3fa9d2ba9d7dd78f719c43b482a5e7f49f135f1c
|
||||
Subproject commit 3942f52c8ee7e828ba56328106eb6c03ae14a623
|
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -30,6 +30,7 @@
|
|||
<file>images/defines.png</file>
|
||||
<file>images/del.png</file>
|
||||
<file>images/devext.png</file>
|
||||
<file>images/devextdis.png</file>
|
||||
<file>images/edit.png</file>
|
||||
<file>images/encoding.png</file>
|
||||
<file>images/export.png</file>
|
||||
|
@ -70,6 +71,7 @@
|
|||
<file>images/paste.png</file>
|
||||
<file>images/pastehex.png</file>
|
||||
<file>images/plugin.png</file>
|
||||
<file>images/plugindis.png</file>
|
||||
<file>images/pro.png</file>
|
||||
<file>images/qt.png</file>
|
||||
<file>images/qtloginspect.png</file>
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include "changedstringlist.h"
|
||||
|
||||
bool ChangedStringList::containChanges() const { return !mods.isEmpty(); }
|
||||
|
||||
bool ChangedStringList::containChanges(const QString &item) const {
|
||||
return contents.contains(item);
|
||||
}
|
||||
|
||||
void ChangedStringList::clear() {
|
||||
contents.clear();
|
||||
mods.clear();
|
||||
}
|
||||
|
||||
void ChangedStringList::pushAddItem(const QString &item) {
|
||||
if (mods.contains(item)) {
|
||||
auto v = mods.value(item);
|
||||
if (v) {
|
||||
return;
|
||||
} else {
|
||||
mods.remove(item);
|
||||
}
|
||||
} else {
|
||||
mods.insert(item, true);
|
||||
}
|
||||
contents.append(item);
|
||||
}
|
||||
|
||||
void ChangedStringList::pushRemoveItem(const QString &item) {
|
||||
if (mods.contains(item)) {
|
||||
auto v = mods.value(item);
|
||||
if (v) {
|
||||
mods.remove(item);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
mods.insert(item, false);
|
||||
}
|
||||
contents.removeOne(item);
|
||||
}
|
||||
|
||||
QStringList ChangedStringList::getContents() const { return contents; }
|
||||
|
||||
void ChangedStringList::setContents(const QStringList &newContents) {
|
||||
contents = newContents;
|
||||
mods.clear();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef CHANGEDSTRINGLIST_H
|
||||
#define CHANGEDSTRINGLIST_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class ChangedStringList {
|
||||
public:
|
||||
bool containChanges() const;
|
||||
bool containChanges(const QString &item) const;
|
||||
void clear();
|
||||
|
||||
void pushAddItem(const QString &item);
|
||||
void pushRemoveItem(const QString &item);
|
||||
|
||||
QStringList getContents() const;
|
||||
void setContents(const QStringList &newContents);
|
||||
|
||||
private:
|
||||
QStringList contents;
|
||||
QHash<QString, bool> mods;
|
||||
};
|
||||
|
||||
#endif // CHANGEDSTRINGLIST_H
|
|
@ -32,7 +32,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QString, CLANG_CUSTOM_STYLE, ("clang.customStyle"))
|
|||
Q_GLOBAL_STATIC_WITH_ARGS(QString, CLANG_DEFAULT_CUSTOM,
|
||||
("BasedOnStyle: llvm, IndentWidth: 4"))
|
||||
|
||||
ClangFormatManager::ClangFormatManager() {
|
||||
ClangFormatManager::ClangFormatManager() : QObject() {
|
||||
ASSERT_SINGLETON;
|
||||
|
||||
// load config
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
#ifndef CLANGFORMATMANAGER_H
|
||||
#define CLANGFORMATMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class ClangFormatManager {
|
||||
class ClangFormatManager : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static ClangFormatManager &instance();
|
||||
|
||||
|
|
|
@ -2631,6 +2631,16 @@ bool PluginSystem::checkErrAllAllowAndReport(const QObject *sender,
|
|||
return false;
|
||||
}
|
||||
|
||||
QMap<PluginSystem::BlockReason, QList<PluginInfo>>
|
||||
PluginSystem::blockedDevPlugins() const {
|
||||
return _blkdevs;
|
||||
}
|
||||
|
||||
QMap<PluginSystem::BlockReason, QList<PluginInfo>>
|
||||
PluginSystem::blockedPlugins() const {
|
||||
return _blkplgs;
|
||||
}
|
||||
|
||||
void PluginSystem::doneRegisterScriptObj() {
|
||||
Q_ASSERT(_angelplg);
|
||||
// ok, then, we will register all script objects
|
||||
|
@ -3254,8 +3264,14 @@ std::optional<PluginInfo> PluginSystem::loadPlugin(const QFileInfo &fileinfo,
|
|||
}
|
||||
|
||||
auto m = meta.value();
|
||||
|
||||
if (_manager) {
|
||||
if (!_manager->onLoadingPlugin(fileName, m)) {
|
||||
if constexpr (std::is_same_v<T, IWingPlugin>) {
|
||||
_blkplgs[BlockReason::BlockedByManager].append(m);
|
||||
} else if constexpr (std::is_same_v<T, IWingDevice>) {
|
||||
_blkdevs[BlockReason::BlockedByManager].append(m);
|
||||
}
|
||||
Logger::critical(QStringLiteral("{ ") + m.id +
|
||||
QStringLiteral(" } ") +
|
||||
tr("PluginBlockByManager"));
|
||||
|
@ -3263,6 +3279,18 @@ std::optional<PluginInfo> PluginSystem::loadPlugin(const QFileInfo &fileinfo,
|
|||
}
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<T, IWingPlugin>) {
|
||||
if (!_enabledExtIDs.contains(m.id)) {
|
||||
_blkplgs[BlockReason::Disabled].append(m);
|
||||
return std::nullopt;
|
||||
}
|
||||
} else if constexpr (std::is_same_v<T, IWingDevice>) {
|
||||
if (!_enabledDevIDs.contains(m.id)) {
|
||||
_blkdevs[BlockReason::Disabled].append(m);
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
auto p = qobject_cast<T *>(loader.instance());
|
||||
if (Q_UNLIKELY(p == nullptr)) {
|
||||
Logger::critical(loader.errorString());
|
||||
|
@ -4270,6 +4298,9 @@ void PluginSystem::loadAllPlugin() {
|
|||
try2LoadManagerPlugin();
|
||||
|
||||
auto &set = SettingManager::instance();
|
||||
_enabledExtIDs = set.enabledExtPlugins();
|
||||
_enabledDevIDs = set.enabledDevPlugins();
|
||||
|
||||
// manager plugin can not block WingAngelAPI, only settings
|
||||
if (set.scriptEnabled()) {
|
||||
_angelplg = new WingAngelAPI;
|
||||
|
@ -4307,6 +4338,7 @@ void PluginSystem::loadAllPlugin() {
|
|||
// internal plugin has no filename
|
||||
if (_manager == nullptr ||
|
||||
(_manager && _manager->onLoadingPlugin({}, meta))) {
|
||||
if (_enabledExtIDs.contains(meta.id)) {
|
||||
auto cstructplg = new WingCStruct;
|
||||
QDir setd(Utilities::getAppDataPath());
|
||||
auto plgset = QStringLiteral("plgset");
|
||||
|
@ -4314,8 +4346,13 @@ void PluginSystem::loadAllPlugin() {
|
|||
retranslateMetadata(cstructplg, meta);
|
||||
loadPlugin(cstructplg, meta, setd);
|
||||
} else {
|
||||
_blkplgs[BlockReason::Disabled].append(meta);
|
||||
}
|
||||
} else {
|
||||
_blkplgs[BlockReason::BlockedByManager].append(meta);
|
||||
Logger::critical(QStringLiteral("{ ") + meta.id +
|
||||
QStringLiteral("} ") + tr("PluginBlockByManager"));
|
||||
QStringLiteral(" } ") +
|
||||
tr("PluginBlockByManager"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,8 @@ public:
|
|||
DupID,
|
||||
LackDependencies
|
||||
};
|
||||
Q_ENUM(PluginStatus)
|
||||
|
||||
enum class BlockReason { Disabled, BlockedByManager };
|
||||
|
||||
private:
|
||||
struct PluginFileContext {
|
||||
|
@ -260,6 +261,10 @@ public:
|
|||
|
||||
const std::optional<PluginInfo> &monitorManagerInfo() const;
|
||||
|
||||
QMap<BlockReason, QList<PluginInfo>> blockedPlugins() const;
|
||||
|
||||
QMap<BlockReason, QList<PluginInfo>> blockedDevPlugins() const;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
T readBasicTypeContent(IWingPlugin *plg, qsizetype offset) {
|
||||
|
@ -738,6 +743,11 @@ private:
|
|||
|
||||
QList<IWingDevice *> _loadeddevs;
|
||||
|
||||
QStringList _enabledExtIDs;
|
||||
QStringList _enabledDevIDs;
|
||||
QMap<BlockReason, QList<PluginInfo>> _blkplgs;
|
||||
QMap<BlockReason, QList<PluginInfo>> _blkdevs;
|
||||
|
||||
QMap<IWingPlugin::RegisteredEvent, QList<IWingPlugin *>> _evplgs;
|
||||
|
||||
QHash<IWingPlugin *, PluginFile> m_plgviewMap;
|
||||
|
|
|
@ -48,7 +48,8 @@ ScriptManager::ScriptManager() {
|
|||
m_usrScriptsPath = Utilities::getAppDataPath() + QDir::separator() +
|
||||
QStringLiteral("scripts");
|
||||
|
||||
refresh();
|
||||
refreshSysScriptsDbCats();
|
||||
refreshUsrScriptsDbCats();
|
||||
}
|
||||
|
||||
ScriptManager::~ScriptManager() {}
|
||||
|
@ -120,11 +121,6 @@ QStringList ScriptManager::getSysScriptFileNames(const QString &cat) const {
|
|||
return getScriptFileNames(scriptDir);
|
||||
}
|
||||
|
||||
void ScriptManager::refresh() {
|
||||
refreshSysScriptsDbCats();
|
||||
refreshUsrScriptsDbCats();
|
||||
}
|
||||
|
||||
void ScriptManager::refreshUsrScriptsDbCats() {
|
||||
m_usrScriptsDbCats.clear();
|
||||
|
||||
|
|
|
@ -55,16 +55,16 @@ public:
|
|||
|
||||
QStringList getSysScriptFileNames(const QString &cat) const;
|
||||
|
||||
void refresh();
|
||||
void refreshUsrScriptsDbCats();
|
||||
void refreshSysScriptsDbCats();
|
||||
|
||||
ScriptDirMeta usrDirMeta(const QString &cat) const;
|
||||
ScriptDirMeta sysDirMeta(const QString &cat) const;
|
||||
|
||||
static QList<QMenu *> buildUpScriptRunnerContext(RibbonButtonGroup *group,
|
||||
QWidget *parent);
|
||||
|
||||
private:
|
||||
void refreshUsrScriptsDbCats();
|
||||
void refreshSysScriptsDbCats();
|
||||
|
||||
private:
|
||||
static QToolButton *addPannelAction(RibbonButtonGroup *pannel,
|
||||
const QString &iconName,
|
||||
|
|
|
@ -27,30 +27,6 @@
|
|||
#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_EDITOR_RESET(config, flag, dvalue) \
|
||||
do { \
|
||||
WRITE_CONFIG(config, dvalue); \
|
||||
_setUnsavedEditor.setFlag(flag, false); \
|
||||
} while (0);
|
||||
|
||||
#define WRITE_CONFIG_CONSOLE_SET(config, flag, dvalue) \
|
||||
if (this->_setUnsavedConsole.testFlag(flag)) { \
|
||||
WRITE_CONFIG(config, dvalue); \
|
||||
_setUnsavedConsole.setFlag(flag, false); \
|
||||
}
|
||||
|
||||
#define WRITE_CONFIG_CONSOLE_RESET(config, flag, dvalue) \
|
||||
do { \
|
||||
WRITE_CONFIG(config, dvalue); \
|
||||
_setUnsavedConsole.setFlag(flag, false); \
|
||||
} while (0);
|
||||
|
||||
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_THEME, ("codeedit.theme"))
|
||||
|
@ -147,70 +123,6 @@ void ScriptSettings::load() {
|
|||
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);
|
||||
WRITE_CONFIG_EDITOR_SET(CODEEDIT_AUTO_IDEN, SETTING_ITEM::AUTO_IDEN,
|
||||
m_editorAutoIden);
|
||||
Q_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);
|
||||
Q_EMIT consoleSettingUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptSettings::reset(SETTINGS cat) {
|
||||
__reset(cat);
|
||||
load();
|
||||
|
@ -219,51 +131,31 @@ void ScriptSettings::reset(SETTINGS cat) {
|
|||
void ScriptSettings::__reset(SETTINGS cat) {
|
||||
HANDLE_CONFIG;
|
||||
if (cat.testFlag(SETTING::EDITOR)) {
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_FONT, SETTING_ITEM::FONT,
|
||||
_defaultFont.defaultFamily());
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_FONT_SIZE, SETTING_ITEM::FONT_SIZE,
|
||||
10);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_THEME, SETTING_ITEM::THEME, {});
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH,
|
||||
4);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_INDENTATION,
|
||||
SETTING_ITEM::INDENTATION, 0);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_MATCH_BRACES,
|
||||
SETTING_ITEM::MATCH_BRACES, true);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_WORD_WRAP, SETTING_ITEM::WORD_WRAP,
|
||||
false);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_LINENUMBER,
|
||||
SETTING_ITEM::SHOW_LINENUMBER, true);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_FOLDING,
|
||||
SETTING_ITEM::SHOW_FOLDING, true);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_INDENTGUIDES,
|
||||
SETTING_ITEM::SHOW_INDENTGUIDES, true);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_LONGLINEEDGE,
|
||||
SETTING_ITEM::SHOW_LONGLINEEDGE, false);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_WHITESPACE,
|
||||
SETTING_ITEM::SHOW_WHITESPACE, false);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_AUTO_CLOSE_CHAR,
|
||||
SETTING_ITEM::AUTO_CLOSE_CHAR, true);
|
||||
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_AUTO_IDEN, SETTING_ITEM::AUTO_IDEN,
|
||||
true);
|
||||
WRITE_CONFIG(CODEEDIT_FONT, _defaultFont.defaultFamily());
|
||||
WRITE_CONFIG(CODEEDIT_FONT_SIZE, 10);
|
||||
WRITE_CONFIG(CODEEDIT_THEME, {});
|
||||
WRITE_CONFIG(CODEEDIT_TABS_WIDTH, 4);
|
||||
WRITE_CONFIG(CODEEDIT_INDENTATION, 0);
|
||||
WRITE_CONFIG(CODEEDIT_MATCH_BRACES, true);
|
||||
WRITE_CONFIG(CODEEDIT_WORD_WRAP, false);
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_LINENUMBER, true);
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_FOLDING, true);
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_INDENTGUIDES, true);
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_LONGLINEEDGE, false);
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_WHITESPACE, false);
|
||||
WRITE_CONFIG(CODEEDIT_AUTO_CLOSE_CHAR, true);
|
||||
WRITE_CONFIG(CODEEDIT_AUTO_IDEN, true);
|
||||
}
|
||||
|
||||
if (cat.testFlag(SETTING::CONSOLE)) {
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_FONT, SETTING_ITEM::FONT,
|
||||
_defaultFont.defaultFamily());
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_FONT_SIZE, SETTING_ITEM::FONT_SIZE,
|
||||
10);
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_THEME, SETTING_ITEM::THEME, {});
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH,
|
||||
4);
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_INDENTATION,
|
||||
SETTING_ITEM::INDENTATION, 0);
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_MATCH_BRACES,
|
||||
SETTING_ITEM::MATCH_BRACES, true);
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_SHOW_WHITESPACE,
|
||||
SETTING_ITEM::SHOW_WHITESPACE, false);
|
||||
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_AUTO_CLOSE_CHAR,
|
||||
SETTING_ITEM::AUTO_CLOSE_CHAR, true);
|
||||
WRITE_CONFIG(CONSOLE_FONT, _defaultFont.defaultFamily());
|
||||
WRITE_CONFIG(CONSOLE_FONT_SIZE, 10);
|
||||
WRITE_CONFIG(CONSOLE_THEME, {});
|
||||
WRITE_CONFIG(CONSOLE_TABS_WIDTH, 4);
|
||||
WRITE_CONFIG(CONSOLE_INDENTATION, 0);
|
||||
WRITE_CONFIG(CONSOLE_MATCH_BRACES, true);
|
||||
WRITE_CONFIG(CONSOLE_SHOW_WHITESPACE, false);
|
||||
WRITE_CONFIG(CONSOLE_AUTO_CLOSE_CHAR, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,8 +167,12 @@ ScriptSettings::ScriptSettings() : QObject() {
|
|||
bool ScriptSettings::editorAutoIden() const { return m_editorAutoIden; }
|
||||
|
||||
void ScriptSettings::setEditorAutoIden(bool newEditorAutoIden) {
|
||||
if (m_editorAutoIden != newEditorAutoIden) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_AUTO_IDEN, newEditorAutoIden);
|
||||
m_editorAutoIden = newEditorAutoIden;
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptSettings::consoleAutoCloseChar() const {
|
||||
return m_consoleAutoCloseChar;
|
||||
|
@ -284,8 +180,9 @@ bool ScriptSettings::consoleAutoCloseChar() const {
|
|||
|
||||
void ScriptSettings::setConsoleAutoCloseChar(bool newConsoleAutoCloseChar) {
|
||||
if (m_consoleAutoCloseChar != newConsoleAutoCloseChar) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_AUTO_CLOSE_CHAR, newConsoleAutoCloseChar);
|
||||
m_consoleAutoCloseChar = newConsoleAutoCloseChar;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::AUTO_CLOSE_CHAR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,8 +192,9 @@ bool ScriptSettings::editorAutoCloseChar() const {
|
|||
|
||||
void ScriptSettings::setEditorAutoCloseChar(bool newEditorAutoCloseChar) {
|
||||
if (m_editorAutoCloseChar != newEditorAutoCloseChar) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_AUTO_CLOSE_CHAR, newEditorAutoCloseChar);
|
||||
m_editorAutoCloseChar = newEditorAutoCloseChar;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::AUTO_CLOSE_CHAR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,8 +204,9 @@ bool ScriptSettings::consoleShowWhiteSpace() const {
|
|||
|
||||
void ScriptSettings::setConsoleShowWhiteSpace(bool newConsoleShowWhiteSpace) {
|
||||
if (m_consoleShowWhiteSpace != newConsoleShowWhiteSpace) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_SHOW_WHITESPACE, newConsoleShowWhiteSpace);
|
||||
m_consoleShowWhiteSpace = newConsoleShowWhiteSpace;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::SHOW_WHITESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,8 +216,9 @@ bool ScriptSettings::editorShowWhiteSpace() const {
|
|||
|
||||
void ScriptSettings::setEditorShowWhiteSpace(bool newEditorShowWhiteSpace) {
|
||||
if (m_editorShowWhiteSpace != newEditorShowWhiteSpace) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_WHITESPACE, newEditorShowWhiteSpace);
|
||||
m_editorShowWhiteSpace = newEditorShowWhiteSpace;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_WHITESPACE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,8 +228,9 @@ bool ScriptSettings::editorShowLineEdges() const {
|
|||
|
||||
void ScriptSettings::setEditorShowLineEdges(bool newEditorShowLineEdges) {
|
||||
if (m_editorShowLineEdges != newEditorShowLineEdges) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_LONGLINEEDGE, newEditorShowLineEdges);
|
||||
m_editorShowLineEdges = newEditorShowLineEdges;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_LONGLINEEDGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,8 +240,9 @@ bool ScriptSettings::editorShowGuideLine() const {
|
|||
|
||||
void ScriptSettings::setEditorShowGuideLine(bool newEditorShowGuidLine) {
|
||||
if (m_editorShowGuideLine != newEditorShowGuidLine) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_INDENTGUIDES, newEditorShowGuidLine);
|
||||
m_editorShowGuideLine = newEditorShowGuidLine;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_INDENTGUIDES);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,8 +250,9 @@ bool ScriptSettings::editorFolding() const { return m_editorFolding; }
|
|||
|
||||
void ScriptSettings::setEditorFolding(bool newEditorFolding) {
|
||||
if (m_editorFolding != newEditorFolding) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_FOLDING, newEditorFolding);
|
||||
m_editorFolding = newEditorFolding;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_FOLDING);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,8 +262,9 @@ bool ScriptSettings::editorShowLineNumber() const {
|
|||
|
||||
void ScriptSettings::setEditorShowLineNumber(bool newEditorShowLineNumber) {
|
||||
if (m_editorShowLineNumber != newEditorShowLineNumber) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_SHOW_LINENUMBER, newEditorShowLineNumber);
|
||||
m_editorShowLineNumber = newEditorShowLineNumber;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::SHOW_LINENUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,8 +272,9 @@ bool ScriptSettings::editorWordWrap() const { return m_editorWordWrap; }
|
|||
|
||||
void ScriptSettings::setEditorWordWrap(bool newEditorWordWrap) {
|
||||
if (m_editorWordWrap != newEditorWordWrap) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_WORD_WRAP, newEditorWordWrap);
|
||||
m_editorWordWrap = newEditorWordWrap;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::WORD_WRAP);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -377,8 +282,9 @@ bool ScriptSettings::consoleMatchBraces() const { return m_consoleMatchBraces; }
|
|||
|
||||
void ScriptSettings::setConsoleMatchBraces(bool newConsoleMatchBraces) {
|
||||
if (m_consoleMatchBraces != newConsoleMatchBraces) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_MATCH_BRACES, newConsoleMatchBraces);
|
||||
m_consoleMatchBraces = newConsoleMatchBraces;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::MATCH_BRACES);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,8 +292,9 @@ bool ScriptSettings::editorMatchBraces() const { return m_editorMatchBraces; }
|
|||
|
||||
void ScriptSettings::setEditorMatchBraces(bool newEditorMatchBraces) {
|
||||
if (m_editorMatchBraces != newEditorMatchBraces) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_MATCH_BRACES, newEditorMatchBraces);
|
||||
m_editorMatchBraces = newEditorMatchBraces;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::MATCH_BRACES);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -395,8 +302,9 @@ int ScriptSettings::consoleInden() const { return m_consoleInden; }
|
|||
|
||||
void ScriptSettings::setConsoleInden(int newConsoleInden) {
|
||||
if (m_consoleInden != newConsoleInden) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_INDENTATION, newConsoleInden);
|
||||
m_consoleInden = newConsoleInden;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::INDENTATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,8 +312,9 @@ int ScriptSettings::editorInden() const { return m_editorInden; }
|
|||
|
||||
void ScriptSettings::setEditorInden(int newEditorInden) {
|
||||
if (m_editorInden != newEditorInden) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_INDENTATION, newEditorInden);
|
||||
m_editorInden = newEditorInden;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::INDENTATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,8 +322,9 @@ int ScriptSettings::consoleTabWidth() const { return m_consoleTabWidth; }
|
|||
|
||||
void ScriptSettings::setConsoleTabWidth(int newConsoleTabWidth) {
|
||||
if (m_consoleTabWidth != newConsoleTabWidth) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_TABS_WIDTH, newConsoleTabWidth);
|
||||
m_consoleTabWidth = newConsoleTabWidth;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::TAB_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,8 +332,9 @@ int ScriptSettings::editorTabWidth() const { return m_editorTabWidth; }
|
|||
|
||||
void ScriptSettings::setEditorTabWidth(int newEditorTabWidth) {
|
||||
if (m_editorTabWidth != newEditorTabWidth) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_TABS_WIDTH, newEditorTabWidth);
|
||||
m_editorTabWidth = newEditorTabWidth;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::TAB_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,8 +342,9 @@ QString ScriptSettings::consoleTheme() const { return m_consoleTheme; }
|
|||
|
||||
void ScriptSettings::setConsoleTheme(const QString &newConsoleTheme) {
|
||||
if (m_consoleTheme != newConsoleTheme) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_THEME, newConsoleTheme);
|
||||
m_consoleTheme = newConsoleTheme;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::THEME);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -440,8 +352,9 @@ QString ScriptSettings::editorTheme() const { return m_editorTheme; }
|
|||
|
||||
void ScriptSettings::setEditorTheme(const QString &newEditorTheme) {
|
||||
if (m_editorTheme != newEditorTheme) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_THEME, newEditorTheme);
|
||||
m_editorTheme = newEditorTheme;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::THEME);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,8 +362,9 @@ int ScriptSettings::consoleFontSize() const { return m_consolefontSize; }
|
|||
|
||||
void ScriptSettings::setConsoleFontSize(int newConsolefontSize) {
|
||||
if (m_consolefontSize != newConsolefontSize) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_FONT_SIZE, newConsolefontSize);
|
||||
m_consolefontSize = newConsolefontSize;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::FONT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,8 +372,9 @@ int ScriptSettings::editorFontSize() const { return m_editorfontSize; }
|
|||
|
||||
void ScriptSettings::setEditorFontSize(int newEditorfontSize) {
|
||||
if (m_editorfontSize != newEditorfontSize) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_FONT_SIZE, newEditorfontSize);
|
||||
m_editorfontSize = newEditorfontSize;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::FONT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -469,8 +384,9 @@ QString ScriptSettings::consoleFontFamily() const {
|
|||
|
||||
void ScriptSettings::setConsoleFontFamily(const QString &newConsoleFontFamily) {
|
||||
if (m_consoleFontFamily != newConsoleFontFamily) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CONSOLE_FONT, newConsoleFontFamily);
|
||||
m_consoleFontFamily = newConsoleFontFamily;
|
||||
_setUnsavedConsole.setFlag(SETTING_ITEM::FONT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -478,7 +394,8 @@ QString ScriptSettings::editorFontFamily() const { return m_editorFontFamily; }
|
|||
|
||||
void ScriptSettings::setEditorFontFamily(const QString &newEditorFontFamily) {
|
||||
if (m_editorFontFamily != newEditorFontFamily) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(CODEEDIT_FONT, newEditorFontFamily);
|
||||
m_editorFontFamily = newEditorFontFamily;
|
||||
_setUnsavedEditor.setFlag(SETTING_ITEM::FONT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,102 +28,60 @@ public:
|
|||
enum SETTING { EDITOR = 1, CONSOLE = 2, ALL = EDITOR | CONSOLE };
|
||||
Q_DECLARE_FLAGS(SETTINGS, SETTING)
|
||||
|
||||
private:
|
||||
// Flags to indicate whether the modification has been made.
|
||||
// There are a maximum of 32 flags,
|
||||
// but it is impossible to have more than this.
|
||||
enum class SETTING_ITEM : quint32 {
|
||||
FONT = 1u,
|
||||
FONT_SIZE = 1u << 1,
|
||||
THEME = 1u << 2,
|
||||
TAB_WIDTH = 1u << 3,
|
||||
INDENTATION = 1u << 4,
|
||||
WORD_WRAP = 1u << 5,
|
||||
MATCH_BRACES = 1u << 6,
|
||||
SHOW_LINENUMBER = 1u << 7,
|
||||
SHOW_FOLDING = 1u << 8,
|
||||
SHOW_INDENTGUIDES = 1u << 9,
|
||||
SHOW_LONGLINEEDGE = 1u << 10,
|
||||
SHOW_WHITESPACE = 1u << 11,
|
||||
AUTO_CLOSE_CHAR = 1u << 12,
|
||||
AUTO_IDEN = 1u << 13
|
||||
};
|
||||
Q_DECLARE_FLAGS(SETTING_ITEMS, SETTING_ITEM)
|
||||
|
||||
public:
|
||||
static ScriptSettings &instance();
|
||||
|
||||
void load();
|
||||
void save(SETTINGS cat = SETTING::ALL);
|
||||
void reset(SETTINGS cat = SETTING::ALL);
|
||||
|
||||
void __reset(SETTINGS cat);
|
||||
|
||||
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);
|
||||
|
||||
bool editorAutoIden() const;
|
||||
|
||||
public slots:
|
||||
void setEditorFontFamily(const QString &newEditorFontFamily);
|
||||
void setConsoleFontFamily(const QString &newConsoleFontFamily);
|
||||
void setEditorFontSize(int newEditorfontSize);
|
||||
void setConsoleFontSize(int newConsolefontSize);
|
||||
void setEditorTheme(const QString &newEditorTheme);
|
||||
void setConsoleTheme(const QString &newConsoleTheme);
|
||||
void setEditorTabWidth(int newEditorTabWidth);
|
||||
void setConsoleTabWidth(int newConsoleTabWidth);
|
||||
void setEditorInden(int newEditorInden);
|
||||
void setConsoleInden(int newConsoleInden);
|
||||
void setEditorMatchBraces(bool newEditorMatchBraces);
|
||||
void setConsoleMatchBraces(bool newConsoleMatchBraces);
|
||||
void setEditorWordWrap(bool newEditorWordWrap);
|
||||
void setEditorShowLineNumber(bool newEditorShowLineNumber);
|
||||
void setEditorFolding(bool newEditorFolding);
|
||||
void setEditorShowGuideLine(bool newEditorShowGuidLine);
|
||||
void setEditorShowLineEdges(bool newEditorShowLineEdges);
|
||||
void setEditorShowWhiteSpace(bool newEditorShowWhiteSpace);
|
||||
void setConsoleShowWhiteSpace(bool newConsoleShowWhiteSpace);
|
||||
void setEditorAutoCloseChar(bool newEditorAutoCloseChar);
|
||||
void setConsoleAutoCloseChar(bool newConsoleAutoCloseChar);
|
||||
void setEditorAutoIden(bool newEditorAutoIden);
|
||||
|
||||
private:
|
||||
|
@ -167,10 +125,6 @@ private:
|
|||
bool m_editorAutoCloseChar = true;
|
||||
bool m_consoleAutoCloseChar = true;
|
||||
|
||||
private:
|
||||
SETTING_ITEMS _setUnsavedEditor;
|
||||
SETTING_ITEMS _setUnsavedConsole;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY_MOVE(ScriptSettings)
|
||||
};
|
||||
|
|
|
@ -21,22 +21,12 @@
|
|||
#include "class/skinmanager.h"
|
||||
#include "settings/settings.h"
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#define WRITE_CONFIG_SET(config, dvalue) \
|
||||
if (this->_setUnsaved.testFlag(SETTING_ITEM::config)) { \
|
||||
WRITE_CONFIG(config, dvalue); \
|
||||
_setUnsaved.setFlag(SettingManager::SETTING_ITEM::config, false); \
|
||||
}
|
||||
|
||||
#define WRITE_CONFIG_RESET(config, dvalue) \
|
||||
do { \
|
||||
WRITE_CONFIG(config, dvalue); \
|
||||
_setUnsaved.setFlag(SettingManager::SETTING_ITEM::config, false); \
|
||||
} while (0);
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, DOCK_LAYOUT, ("dock.layout"))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, SCRIPT_DOCK_LAYOUT, ("script.layout"))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, APP_LASTUSED_PATH, ("app.lastusedpath"))
|
||||
|
@ -49,6 +39,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(QString, APP_LANGUAGE, ("app.lang"))
|
|||
Q_GLOBAL_STATIC_WITH_ARGS(QString, PLUGIN_ENABLE, ("plugin.enableplugin"))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, PLUGIN_ENABLE_ROOT,
|
||||
("plugin.rootenableplugin"))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, PLUGIN_ENABLEDPLUGINS_EXT, ("plugin.ext"))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, PLUGIN_ENABLEDPLUGINS_DEV, ("plugin.dev"))
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, EDITOR_FONTSIZE, ("editor.fontsize"))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, EDITOR_SHOW_ADDR, ("editor.showaddr"))
|
||||
|
@ -89,8 +81,12 @@ SettingManager::SettingManager() {
|
|||
QString SettingManager::lastUsedPath() const { return m_lastUsedPath; }
|
||||
|
||||
void SettingManager::setLastUsedPath(const QString &newLastUsedPath) {
|
||||
if (m_lastUsedPath != newLastUsedPath) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(APP_LASTUSED_PATH, newLastUsedPath);
|
||||
m_lastUsedPath = newLastUsedPath;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingManager::load() {
|
||||
auto defaultFontSize = _defaultFont.pointSize();
|
||||
|
@ -118,6 +114,21 @@ void SettingManager::load() {
|
|||
|
||||
READ_CONFIG_BOOL(m_enablePlugin, PLUGIN_ENABLE, true);
|
||||
READ_CONFIG_BOOL(m_enablePlgInRoot, PLUGIN_ENABLE_ROOT, false);
|
||||
|
||||
{
|
||||
auto data = READ_CONFIG(PLUGIN_ENABLEDPLUGINS_EXT, {});
|
||||
if (data.isValid()) {
|
||||
auto rawRules = data.toByteArray();
|
||||
m_enabledExtPlugins = readPluginRule(rawRules);
|
||||
}
|
||||
|
||||
data = READ_CONFIG(PLUGIN_ENABLEDPLUGINS_DEV, {});
|
||||
if (data.isValid()) {
|
||||
auto rawRules = data.toByteArray();
|
||||
m_enabledDevPlugins = readPluginRule(rawRules);
|
||||
}
|
||||
}
|
||||
|
||||
READ_CONFIG_INT_POSITIVE(m_editorfontSize, EDITOR_FONTSIZE,
|
||||
defaultFontSize);
|
||||
m_editorfontSize = qBound(5, m_editorfontSize, 25);
|
||||
|
@ -195,21 +206,54 @@ QVariantList SettingManager::getVarList(
|
|||
return varlist;
|
||||
}
|
||||
|
||||
QStringList SettingManager::enabledDevPlugins() const {
|
||||
return m_enabledDevPlugins;
|
||||
}
|
||||
|
||||
void SettingManager::setEnabledDevPlugins(
|
||||
const QStringList &newEnabledDevPlugins) {
|
||||
if (m_enabledDevPlugins != newEnabledDevPlugins) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(PLUGIN_ENABLEDPLUGINS_DEV,
|
||||
savePluginRule(newEnabledDevPlugins));
|
||||
m_enabledDevPlugins = newEnabledDevPlugins;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList SettingManager::enabledExtPlugins() const {
|
||||
return m_enabledExtPlugins;
|
||||
}
|
||||
|
||||
void SettingManager::setEnabledExtPlugins(
|
||||
const QStringList &newEnabledPlugins) {
|
||||
if (m_enabledExtPlugins != newEnabledPlugins) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(PLUGIN_ENABLEDPLUGINS_EXT,
|
||||
savePluginRule(newEnabledPlugins));
|
||||
m_enabledExtPlugins = newEnabledPlugins;
|
||||
}
|
||||
}
|
||||
|
||||
int SettingManager::scriptTimeout() const { return m_scriptTimeout; }
|
||||
|
||||
void SettingManager::setScriptTimeout(int newScriptTimeout) {
|
||||
newScriptTimeout = qBound(0, newScriptTimeout, 312480);
|
||||
if (m_scriptTimeout != newScriptTimeout) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SCRIPT_TIMEOUT, newScriptTimeout);
|
||||
m_scriptTimeout = newScriptTimeout;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SCRIPT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
qsizetype SettingManager::logCount() const { return m_logCount; }
|
||||
|
||||
void SettingManager::setLogCount(qsizetype newLogCount) {
|
||||
if (m_logCount != newLogCount) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(OTHER_LOG_COUNT, newLogCount);
|
||||
m_logCount = newLogCount;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingManager::checkWriteableAndWarn() {
|
||||
HANDLE_CONFIG;
|
||||
|
@ -219,18 +263,44 @@ void SettingManager::checkWriteableAndWarn() {
|
|||
}
|
||||
}
|
||||
|
||||
QStringList SettingManager::readPluginRule(const QByteArray &data) {
|
||||
if (!data.isEmpty()) {
|
||||
auto up = qUncompress(data);
|
||||
if (!up.isEmpty()) {
|
||||
auto rules = QString::fromUtf8(up);
|
||||
auto rlist = rules.split('|', Qt::SkipEmptyParts);
|
||||
rlist.removeIf([](const QString &str) {
|
||||
return !Utilities::isValidIdentifier(str);
|
||||
});
|
||||
return rlist;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray SettingManager::savePluginRule(const QStringList &rules) {
|
||||
auto plgs = rules.join('|');
|
||||
auto data = qCompress(plgs.toUtf8());
|
||||
return data;
|
||||
}
|
||||
|
||||
bool SettingManager::checkUpdate() const { return m_checkUpdate; }
|
||||
|
||||
void SettingManager::setCheckUpdate(bool newCheckUpdate) {
|
||||
if (m_checkUpdate != newCheckUpdate) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(OTHER_CHECK_UPDATE, newCheckUpdate);
|
||||
m_checkUpdate = newCheckUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
bool SettingManager::dontUseSplash() const { return m_dontUseSplash; }
|
||||
|
||||
void SettingManager::setDontUseSplash(bool newDontUseSplash) {
|
||||
if (m_dontUseSplash != newDontUseSplash) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(OTHER_DONT_USE_SPLASH, newDontUseSplash);
|
||||
m_dontUseSplash = newDontUseSplash;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::OTHER_DONT_USE_SPLASH);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,8 +308,9 @@ bool SettingManager::scriptEnabled() const { return m_scriptEnabled; }
|
|||
|
||||
void SettingManager::setScriptEnabled(bool newScriptEnabled) {
|
||||
if (m_scriptEnabled != newScriptEnabled) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SCRIPT_ENABLE, newScriptEnabled);
|
||||
m_scriptEnabled = newScriptEnabled;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SCRIPT_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,22 +320,25 @@ bool SettingManager::allowUsrScriptInRoot() const {
|
|||
|
||||
void SettingManager::setAllowUsrScriptInRoot(bool newAllowUsrScriptInRoot) {
|
||||
if (m_allowUsrScriptInRoot != newAllowUsrScriptInRoot) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SCRIPT_ALLOW_USRSCRIPT_INROOT, newAllowUsrScriptInRoot);
|
||||
m_allowUsrScriptInRoot = newAllowUsrScriptInRoot;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SCRIPT_ALLOW_USRSCRIPT_INROOT);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingManager::setUsrHideCats(const QStringList &newUsrHideCats) {
|
||||
if (m_usrHideCats != newUsrHideCats) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SCRIPT_USRHIDECATS, newUsrHideCats);
|
||||
m_usrHideCats = newUsrHideCats;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SCRIPT_USRHIDECATS);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingManager::setSysHideCats(const QStringList &newSysHideCats) {
|
||||
if (m_sysHideCats != newSysHideCats) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SCRIPT_SYSHIDECATS, newSysHideCats);
|
||||
m_sysHideCats = newSysHideCats;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SCRIPT_SYSHIDECATS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,8 +346,9 @@ int SettingManager::logLevel() const { return m_logLevel; }
|
|||
|
||||
void SettingManager::setLogLevel(int newLogLevel) {
|
||||
if (m_logLevel != newLogLevel) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(OTHER_LOG_LEVEL, newLogLevel);
|
||||
m_logLevel = newLogLevel;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::OTHER_LOG_LEVEL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,8 +356,9 @@ bool SettingManager::useNativeTitleBar() const { return m_useNativeTitleBar; }
|
|||
|
||||
void SettingManager::setUseNativeTitleBar(bool newUseNativeTitleBar) {
|
||||
if (m_useNativeTitleBar != newUseNativeTitleBar) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(OTHER_USE_NATIVE_TITLEBAR, newUseNativeTitleBar);
|
||||
m_useNativeTitleBar = newUseNativeTitleBar;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::OTHER_USE_NATIVE_TITLEBAR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,8 +368,9 @@ bool SettingManager::useNativeFileDialog() const {
|
|||
|
||||
void SettingManager::setUseNativeFileDialog(bool newUseNativeFileDialog) {
|
||||
if (m_useNativeFileDialog != newUseNativeFileDialog) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(OTHER_USESYS_FILEDIALOG, newUseNativeFileDialog);
|
||||
m_useNativeFileDialog = newUseNativeFileDialog;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::OTHER_USESYS_FILEDIALOG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,8 +381,9 @@ QByteArray SettingManager::scriptDockLayout() const {
|
|||
void SettingManager::setScriptDockLayout(
|
||||
const QByteArray &newScriptDockLayout) {
|
||||
if (m_scriptDockLayout != newScriptDockLayout) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SCRIPT_DOCK_LAYOUT, newScriptDockLayout);
|
||||
m_scriptDockLayout = newScriptDockLayout;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SCRIPT_DOCK_LAYOUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,8 +398,9 @@ QList<RecentFileManager::RecentInfo> SettingManager::recentScriptFiles() const {
|
|||
void SettingManager::setRecentScriptFiles(
|
||||
const QList<RecentFileManager::RecentInfo> &newRecentScriptFiles) {
|
||||
if (m_recentScriptFiles != newRecentScriptFiles) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SCRIPT_RECENTFILES, getVarList(newRecentScriptFiles));
|
||||
m_recentScriptFiles = newRecentScriptFiles;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SCRIPT_RECENTFILES);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,8 +408,9 @@ QString SettingManager::appFontFamily() const { return m_appFontFamily; }
|
|||
|
||||
void SettingManager::setAppFontFamily(const QString &newAppFontFamily) {
|
||||
if (m_appFontFamily != newAppFontFamily) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(APP_FONTFAMILY, newAppFontFamily);
|
||||
m_appFontFamily = newAppFontFamily;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::APP_FONTFAMILY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,8 +418,9 @@ bool SettingManager::editorShowHeader() const { return m_editorShowHeader; }
|
|||
|
||||
void SettingManager::setEditorShowHeader(bool newEditorShowAddr) {
|
||||
if (m_editorShowHeader != newEditorShowAddr) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(EDITOR_SHOW_ADDR, newEditorShowAddr);
|
||||
m_editorShowHeader = newEditorShowAddr;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::EDITOR_SHOW_ADDR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,8 +428,9 @@ bool SettingManager::enablePlugin() const { return m_enablePlugin; }
|
|||
|
||||
void SettingManager::setEnablePlugin(bool newEnablePlugin) {
|
||||
if (m_enablePlugin != newEnablePlugin) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(PLUGIN_ENABLE, newEnablePlugin);
|
||||
m_enablePlugin = newEnablePlugin;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::PLUGIN_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,8 +441,9 @@ QList<RecentFileManager::RecentInfo> SettingManager::recentHexFiles() const {
|
|||
void SettingManager::setRecentFiles(
|
||||
const QList<RecentFileManager::RecentInfo> &newRecentFiles) {
|
||||
if (m_recentHexFiles != newRecentFiles) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(EDITOR_RECENTFILES, getVarList(newRecentFiles));
|
||||
m_recentHexFiles = newRecentFiles;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::EDITOR_RECENTFILES);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,53 +462,9 @@ void SettingManager::setDefaultWinState(Qt::WindowState newDefaultWinState) {
|
|||
break;
|
||||
}
|
||||
if (m_defaultWinState != newDefaultWinState) {
|
||||
m_defaultWinState = newDefaultWinState;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::APP_WINDOWSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingManager::save(SETTINGS cat) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG_SET(DOCK_LAYOUT, m_dockLayout);
|
||||
WRITE_CONFIG_SET(SCRIPT_DOCK_LAYOUT, m_scriptDockLayout);
|
||||
WRITE_CONFIG_SET(EDITOR_RECENTFILES, getVarList(m_recentHexFiles));
|
||||
WRITE_CONFIG_SET(SCRIPT_RECENTFILES, getVarList(m_recentScriptFiles));
|
||||
WRITE_CONFIG_SET(APP_LASTUSED_PATH, m_lastUsedPath);
|
||||
if (cat.testFlag(SETTING::APP)) {
|
||||
WRITE_CONFIG_SET(SKIN_THEME, m_themeID);
|
||||
WRITE_CONFIG_SET(APP_LANGUAGE, m_defaultLang);
|
||||
WRITE_CONFIG_SET(APP_FONTFAMILY, m_appFontFamily);
|
||||
WRITE_CONFIG_SET(APP_FONTSIZE, m_appfontSize);
|
||||
WRITE_CONFIG_SET(APP_WINDOWSIZE, m_defaultWinState);
|
||||
}
|
||||
if (cat.testFlag(SETTING::PLUGIN)) {
|
||||
WRITE_CONFIG_SET(PLUGIN_ENABLE, m_enablePlugin);
|
||||
WRITE_CONFIG_SET(PLUGIN_ENABLE_ROOT, m_enablePlgInRoot);
|
||||
}
|
||||
if (cat.testFlag(SETTING::EDITOR)) {
|
||||
WRITE_CONFIG_SET(EDITOR_FONTSIZE, m_editorfontSize);
|
||||
WRITE_CONFIG_SET(EDITOR_SHOW_ADDR, m_editorShowHeader);
|
||||
WRITE_CONFIG_SET(EDITOR_SHOW_COL, m_editorShowcol);
|
||||
WRITE_CONFIG_SET(EDITOR_SHOW_TEXT, m_editorShowtext);
|
||||
WRITE_CONFIG_SET(EDITOR_COPY_LIMIT, m_copylimit);
|
||||
WRITE_CONFIG_SET(EDITOR_DECSTRLIMIT, m_decodeStrlimit);
|
||||
}
|
||||
if (cat.testFlag(SETTING::SCRIPT)) {
|
||||
WRITE_CONFIG_SET(SCRIPT_ENABLE, m_scriptEnabled);
|
||||
WRITE_CONFIG_SET(SCRIPT_TIMEOUT, m_scriptTimeout);
|
||||
WRITE_CONFIG_SET(SCRIPT_ALLOW_USRSCRIPT_INROOT, m_allowUsrScriptInRoot);
|
||||
WRITE_CONFIG_SET(SCRIPT_USRHIDECATS, m_usrHideCats);
|
||||
WRITE_CONFIG_SET(SCRIPT_SYSHIDECATS, m_sysHideCats);
|
||||
}
|
||||
if (cat.testFlag(SETTING::OTHER)) {
|
||||
WRITE_CONFIG_SET(OTHER_USESYS_FILEDIALOG, m_useNativeFileDialog);
|
||||
#ifdef WINGHEX_USE_FRAMELESS
|
||||
WRITE_CONFIG_SET(OTHER_USE_NATIVE_TITLEBAR, m_useNativeTitleBar);
|
||||
#endif
|
||||
WRITE_CONFIG_SET(OTHER_DONT_USE_SPLASH, m_dontUseSplash);
|
||||
WRITE_CONFIG_SET(OTHER_CHECK_UPDATE, m_checkUpdate);
|
||||
WRITE_CONFIG_SET(OTHER_LOG_LEVEL, m_logLevel);
|
||||
WRITE_CONFIG_SET(OTHER_LOG_COUNT, m_logCount);
|
||||
WRITE_CONFIG(APP_WINDOWSIZE, newDefaultWinState);
|
||||
m_defaultWinState = newDefaultWinState;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,41 +476,41 @@ void SettingManager::reset(SETTINGS cat) {
|
|||
void SettingManager::__reset(SETTINGS cat) {
|
||||
HANDLE_CONFIG;
|
||||
if (cat.testFlag(SETTING::APP)) {
|
||||
WRITE_CONFIG_RESET(SKIN_THEME, 0);
|
||||
WRITE_CONFIG_RESET(APP_LANGUAGE, QString());
|
||||
WRITE_CONFIG_RESET(APP_FONTFAMILY, _defaultFont.family());
|
||||
WRITE_CONFIG_RESET(APP_FONTSIZE, _defaultFont.pointSize());
|
||||
WRITE_CONFIG_RESET(APP_WINDOWSIZE, Qt::WindowMaximized);
|
||||
WRITE_CONFIG(SKIN_THEME, 0);
|
||||
WRITE_CONFIG(APP_LANGUAGE, QString());
|
||||
WRITE_CONFIG(APP_FONTFAMILY, _defaultFont.family());
|
||||
WRITE_CONFIG(APP_FONTSIZE, _defaultFont.pointSize());
|
||||
WRITE_CONFIG(APP_WINDOWSIZE, Qt::WindowMaximized);
|
||||
}
|
||||
if (cat.testFlag(SETTING::PLUGIN)) {
|
||||
WRITE_CONFIG_RESET(PLUGIN_ENABLE, true);
|
||||
WRITE_CONFIG_RESET(PLUGIN_ENABLE_ROOT, false);
|
||||
WRITE_CONFIG(PLUGIN_ENABLE, true);
|
||||
WRITE_CONFIG(PLUGIN_ENABLE_ROOT, false);
|
||||
}
|
||||
if (cat.testFlag(SETTING::EDITOR)) {
|
||||
WRITE_CONFIG_RESET(EDITOR_FONTSIZE, _defaultFont.pointSize());
|
||||
WRITE_CONFIG_RESET(EDITOR_SHOW_ADDR, true);
|
||||
WRITE_CONFIG_RESET(EDITOR_SHOW_COL, true);
|
||||
WRITE_CONFIG_RESET(EDITOR_SHOW_TEXT, true);
|
||||
WRITE_CONFIG_RESET(EDITOR_FIND_MAXCOUNT, 100);
|
||||
WRITE_CONFIG_RESET(EDITOR_COPY_LIMIT, 100);
|
||||
WRITE_CONFIG_RESET(EDITOR_DECSTRLIMIT, 10);
|
||||
WRITE_CONFIG(EDITOR_FONTSIZE, _defaultFont.pointSize());
|
||||
WRITE_CONFIG(EDITOR_SHOW_ADDR, true);
|
||||
WRITE_CONFIG(EDITOR_SHOW_COL, true);
|
||||
WRITE_CONFIG(EDITOR_SHOW_TEXT, true);
|
||||
WRITE_CONFIG(EDITOR_FIND_MAXCOUNT, 100);
|
||||
WRITE_CONFIG(EDITOR_COPY_LIMIT, 100);
|
||||
WRITE_CONFIG(EDITOR_DECSTRLIMIT, 10);
|
||||
}
|
||||
if (cat.testFlag(SETTING::SCRIPT)) {
|
||||
WRITE_CONFIG_RESET(SCRIPT_ENABLE, true);
|
||||
WRITE_CONFIG_RESET(SCRIPT_TIMEOUT, 10);
|
||||
WRITE_CONFIG_RESET(SCRIPT_ALLOW_USRSCRIPT_INROOT, false);
|
||||
WRITE_CONFIG_RESET(SCRIPT_USRHIDECATS, QStringList());
|
||||
WRITE_CONFIG_RESET(SCRIPT_SYSHIDECATS, QStringList());
|
||||
WRITE_CONFIG(SCRIPT_ENABLE, true);
|
||||
WRITE_CONFIG(SCRIPT_TIMEOUT, 10);
|
||||
WRITE_CONFIG(SCRIPT_ALLOW_USRSCRIPT_INROOT, false);
|
||||
WRITE_CONFIG(SCRIPT_USRHIDECATS, QStringList());
|
||||
WRITE_CONFIG(SCRIPT_SYSHIDECATS, QStringList());
|
||||
}
|
||||
if (cat.testFlag(SETTING::OTHER)) {
|
||||
WRITE_CONFIG_RESET(OTHER_USESYS_FILEDIALOG, true);
|
||||
WRITE_CONFIG(OTHER_USESYS_FILEDIALOG, true);
|
||||
#ifdef WINGHEX_USE_FRAMELESS
|
||||
WRITE_CONFIG_RESET(OTHER_USE_NATIVE_TITLEBAR, false);
|
||||
WRITE_CONFIG(OTHER_USE_NATIVE_TITLEBAR, false);
|
||||
#endif
|
||||
WRITE_CONFIG_RESET(OTHER_DONT_USE_SPLASH, false);
|
||||
WRITE_CONFIG_RESET(OTHER_CHECK_UPDATE, false);
|
||||
WRITE_CONFIG_RESET(OTHER_LOG_LEVEL, Logger::defaultLevel());
|
||||
WRITE_CONFIG_RESET(OTHER_LOG_COUNT, 20);
|
||||
WRITE_CONFIG(OTHER_DONT_USE_SPLASH, false);
|
||||
WRITE_CONFIG(OTHER_CHECK_UPDATE, false);
|
||||
WRITE_CONFIG(OTHER_LOG_LEVEL, Logger::defaultLevel());
|
||||
WRITE_CONFIG(OTHER_LOG_COUNT, 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,8 +520,9 @@ void SettingManager::setDecodeStrlimit(qsizetype newDecodeStrlimit) {
|
|||
newDecodeStrlimit =
|
||||
qBound(qsizetype(100), newDecodeStrlimit, qsizetype(1024));
|
||||
if (m_decodeStrlimit != newDecodeStrlimit) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(EDITOR_DECSTRLIMIT, newDecodeStrlimit);
|
||||
m_decodeStrlimit = newDecodeStrlimit;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::EDITOR_DECSTRLIMIT);
|
||||
Q_EMIT sigDecodeStrlimitChanged(m_decodeStrlimit);
|
||||
}
|
||||
}
|
||||
|
@ -492,8 +532,9 @@ qsizetype SettingManager::copylimit() const { return m_copylimit; }
|
|||
void SettingManager::setCopylimit(qsizetype newCopylimit) {
|
||||
newCopylimit = qBound(qsizetype(100), newCopylimit, qsizetype(1024));
|
||||
if (m_copylimit != newCopylimit) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(EDITOR_COPY_LIMIT, newCopylimit);
|
||||
m_copylimit = newCopylimit;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::EDITOR_COPY_LIMIT);
|
||||
Q_EMIT sigDecodeStrlimitChanged(m_copylimit);
|
||||
}
|
||||
}
|
||||
|
@ -502,8 +543,9 @@ bool SettingManager::editorShowtext() const { return m_editorShowtext; }
|
|||
|
||||
void SettingManager::setEditorShowtext(bool newEditorShowtext) {
|
||||
if (m_editorShowtext != newEditorShowtext) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(EDITOR_SHOW_TEXT, newEditorShowtext);
|
||||
m_editorShowtext = newEditorShowtext;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::EDITOR_SHOW_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -511,8 +553,9 @@ bool SettingManager::editorShowcol() const { return m_editorShowcol; }
|
|||
|
||||
void SettingManager::setEditorShowcol(bool newEditorShowcol) {
|
||||
if (m_editorShowcol != newEditorShowcol) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(EDITOR_SHOW_COL, newEditorShowcol);
|
||||
m_editorShowcol = newEditorShowcol;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::EDITOR_SHOW_COL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,8 +563,9 @@ int SettingManager::editorfontSize() const { return m_editorfontSize; }
|
|||
|
||||
void SettingManager::setEditorfontSize(int newEditorfontSize) {
|
||||
if (m_editorfontSize != newEditorfontSize) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(EDITOR_FONTSIZE, newEditorfontSize);
|
||||
m_editorfontSize = newEditorfontSize;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::EDITOR_FONTSIZE);
|
||||
Q_EMIT sigEditorfontSizeChanged(newEditorfontSize);
|
||||
}
|
||||
}
|
||||
|
@ -530,8 +574,9 @@ int SettingManager::appfontSize() const { return m_appfontSize; }
|
|||
|
||||
void SettingManager::setAppfontSize(int newAppfontSize) {
|
||||
if (m_appfontSize != newAppfontSize) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(APP_FONTSIZE, newAppfontSize);
|
||||
m_appfontSize = newAppfontSize;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::APP_FONTSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -539,8 +584,9 @@ bool SettingManager::enablePlgInRoot() const { return m_enablePlgInRoot; }
|
|||
|
||||
void SettingManager::setEnablePlgInRoot(bool newEnablePlgInRoot) {
|
||||
if (m_enablePlgInRoot != newEnablePlgInRoot) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(PLUGIN_ENABLE_ROOT, newEnablePlgInRoot);
|
||||
m_enablePlgInRoot = newEnablePlgInRoot;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::PLUGIN_ENABLE_ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -548,8 +594,9 @@ QString SettingManager::defaultLang() const { return m_defaultLang; }
|
|||
|
||||
void SettingManager::setDefaultLang(const QString &newDefaultLang) {
|
||||
if (m_defaultLang != newDefaultLang) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(APP_LANGUAGE, newDefaultLang);
|
||||
m_defaultLang = newDefaultLang;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::APP_LANGUAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -564,8 +611,9 @@ QByteArray SettingManager::dockLayout() const { return m_dockLayout; }
|
|||
|
||||
void SettingManager::setDockLayout(const QByteArray &newDockLayout) {
|
||||
if (m_dockLayout != newDockLayout) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(DOCK_LAYOUT, newDockLayout);
|
||||
m_dockLayout = newDockLayout;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::DOCK_LAYOUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -573,7 +621,8 @@ int SettingManager::themeID() const { return m_themeID; }
|
|||
|
||||
void SettingManager::setThemeID(int newThemeID) {
|
||||
if (m_themeID != newThemeID) {
|
||||
HANDLE_CONFIG;
|
||||
WRITE_CONFIG(SKIN_THEME, newThemeID);
|
||||
m_themeID = newThemeID;
|
||||
_setUnsaved.setFlag(SETTING_ITEM::SKIN_THEME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,146 +40,92 @@ public:
|
|||
ALL = APP | PLUGIN | EDITOR | SCRIPT | OTHER
|
||||
};
|
||||
Q_DECLARE_FLAGS(SETTINGS, SETTING)
|
||||
private:
|
||||
// Flags to indicate whether the modification has been made.
|
||||
// There are a maximum of 32 flags,
|
||||
// but it is impossible to have more than this.
|
||||
enum class SETTING_ITEM : quint32 {
|
||||
DOCK_LAYOUT = 1u,
|
||||
SCRIPT_DOCK_LAYOUT = 1u << 1,
|
||||
APP_LASTUSED_PATH = 1u << 2,
|
||||
SKIN_THEME = 1u << 3,
|
||||
APP_FONTFAMILY = 1u << 4,
|
||||
APP_FONTSIZE = 1u << 5,
|
||||
APP_WINDOWSIZE = 1u << 6,
|
||||
APP_LANGUAGE = 1u << 7,
|
||||
PLUGIN_ENABLE = 1u << 8,
|
||||
PLUGIN_ENABLE_ROOT = 1u << 9,
|
||||
EDITOR_FONTSIZE = 1u << 10,
|
||||
EDITOR_SHOW_ADDR = 1u << 11,
|
||||
EDITOR_SHOW_COL = 1u << 12,
|
||||
EDITOR_SHOW_TEXT = 1u << 13,
|
||||
SCRIPT_TIMEOUT = 1u << 14,
|
||||
EDITOR_FIND_MAXCOUNT = 1u << 15,
|
||||
EDITOR_COPY_LIMIT = 1u << 16,
|
||||
EDITOR_DECSTRLIMIT = 1u << 17,
|
||||
EDITOR_RECENTFILES = 1u << 18,
|
||||
SCRIPT_RECENTFILES = 1u << 19,
|
||||
SCRIPT_ENABLE = 1u << 20,
|
||||
SCRIPT_ALLOW_USRSCRIPT_INROOT = 1u << 21,
|
||||
SCRIPT_USRHIDECATS = 1u << 22,
|
||||
SCRIPT_SYSHIDECATS = 1u << 23,
|
||||
OTHER_USESYS_FILEDIALOG = 1u << 24,
|
||||
OTHER_USE_NATIVE_TITLEBAR = 1u << 25,
|
||||
OTHER_DONT_USE_SPLASH = 1u << 26,
|
||||
OTHER_LOG_LEVEL = 1u << 27,
|
||||
OTHER_CHECK_UPDATE = 1u << 28,
|
||||
OTHER_LOG_COUNT = 1u << 29,
|
||||
};
|
||||
Q_DECLARE_FLAGS(SETTING_ITEMS, SETTING_ITEM)
|
||||
|
||||
public:
|
||||
static SettingManager &instance();
|
||||
|
||||
~SettingManager();
|
||||
virtual ~SettingManager();
|
||||
|
||||
QByteArray dockLayout() const;
|
||||
void setDockLayout(const QByteArray &newDockLayout);
|
||||
|
||||
int themeID() const;
|
||||
void setThemeID(int newThemeID);
|
||||
|
||||
QString defaultLang() const;
|
||||
void setDefaultLang(const QString &newDefaultLang);
|
||||
|
||||
bool enablePlgInRoot() const;
|
||||
void setEnablePlgInRoot(bool newEnablePlgInRoot);
|
||||
|
||||
int appfontSize() const;
|
||||
void setAppfontSize(int newAppfontSize);
|
||||
|
||||
int editorfontSize() const;
|
||||
void setEditorfontSize(int newEditorfontSize);
|
||||
|
||||
bool editorShowcol() const;
|
||||
void setEditorShowcol(bool newEditorShowcol);
|
||||
|
||||
bool editorShowtext() const;
|
||||
void setEditorShowtext(bool newEditorShowtext);
|
||||
|
||||
qsizetype copylimit() const;
|
||||
void setCopylimit(qsizetype newCopylimit);
|
||||
|
||||
qsizetype decodeStrlimit() const;
|
||||
void setDecodeStrlimit(qsizetype newDecodeStrlimit);
|
||||
|
||||
Qt::WindowState defaultWinState() const;
|
||||
void setDefaultWinState(Qt::WindowState newDefaultWinState);
|
||||
|
||||
void save(SETTINGS cat = SETTING::ALL);
|
||||
void reset(SETTINGS cat);
|
||||
|
||||
void __reset(SETTINGS cat);
|
||||
|
||||
QList<RecentFileManager::RecentInfo> recentHexFiles() const;
|
||||
void
|
||||
setRecentFiles(const QList<RecentFileManager::RecentInfo> &newRecentFiles);
|
||||
|
||||
bool enablePlugin() const;
|
||||
void setEnablePlugin(bool newEnablePlugin);
|
||||
|
||||
bool editorShowHeader() const;
|
||||
void setEditorShowHeader(bool newEditorShowAddr);
|
||||
|
||||
QString appFontFamily() const;
|
||||
void setAppFontFamily(const QString &newAppFontFamily);
|
||||
|
||||
QList<RecentFileManager::RecentInfo> recentScriptFiles() const;
|
||||
void setRecentScriptFiles(
|
||||
const QList<RecentFileManager::RecentInfo> &newRecentScriptFiles);
|
||||
|
||||
QStringList usrHideCats() const;
|
||||
QStringList sysHideCats() const;
|
||||
|
||||
QString lastUsedPath() const;
|
||||
QByteArray scriptDockLayout() const;
|
||||
bool useNativeFileDialog() const;
|
||||
bool useNativeTitleBar() const;
|
||||
int logLevel() const;
|
||||
bool allowUsrScriptInRoot() const;
|
||||
bool scriptEnabled() const;
|
||||
bool dontUseSplash() const;
|
||||
bool checkUpdate() const;
|
||||
qsizetype logCount() const;
|
||||
int scriptTimeout() const;
|
||||
|
||||
QStringList enabledExtPlugins() const;
|
||||
QStringList enabledDevPlugins() const;
|
||||
|
||||
public slots:
|
||||
void setThemeID(int newThemeID);
|
||||
void setDockLayout(const QByteArray &newDockLayout);
|
||||
void setDefaultLang(const QString &newDefaultLang);
|
||||
void setEnablePlgInRoot(bool newEnablePlgInRoot);
|
||||
void setAppfontSize(int newAppfontSize);
|
||||
void setEditorfontSize(int newEditorfontSize);
|
||||
void setEditorShowcol(bool newEditorShowcol);
|
||||
void setEditorShowtext(bool newEditorShowtext);
|
||||
void setCopylimit(qsizetype newCopylimit);
|
||||
void setDecodeStrlimit(qsizetype newDecodeStrlimit);
|
||||
void setDefaultWinState(Qt::WindowState newDefaultWinState);
|
||||
void
|
||||
setRecentFiles(const QList<RecentFileManager::RecentInfo> &newRecentFiles);
|
||||
void setEnablePlugin(bool newEnablePlugin);
|
||||
void setEditorShowHeader(bool newEditorShowAddr);
|
||||
void setAppFontFamily(const QString &newAppFontFamily);
|
||||
void setRecentScriptFiles(
|
||||
const QList<RecentFileManager::RecentInfo> &newRecentScriptFiles);
|
||||
void setSysHideCats(const QStringList &newSysHideCats);
|
||||
void setUsrHideCats(const QStringList &newUsrHideCats);
|
||||
|
||||
QString lastUsedPath() const;
|
||||
void setLastUsedPath(const QString &newLastUsedPath);
|
||||
|
||||
QByteArray scriptDockLayout() const;
|
||||
void setScriptDockLayout(const QByteArray &newScriptDockLayout);
|
||||
|
||||
bool useNativeFileDialog() const;
|
||||
void setUseNativeFileDialog(bool newUseNativeFileDialog);
|
||||
|
||||
bool useNativeTitleBar() const;
|
||||
void setUseNativeTitleBar(bool newUseNativeTitleBar);
|
||||
|
||||
int logLevel() const;
|
||||
void setLogLevel(int newLogLevel);
|
||||
|
||||
bool allowUsrScriptInRoot() const;
|
||||
void setAllowUsrScriptInRoot(bool newAllowUsrScriptInRoot);
|
||||
|
||||
bool scriptEnabled() const;
|
||||
void setScriptEnabled(bool newScriptEnabled);
|
||||
|
||||
bool dontUseSplash() const;
|
||||
void setDontUseSplash(bool newDontUseSplash);
|
||||
|
||||
bool checkUpdate() const;
|
||||
void setCheckUpdate(bool newCheckUpdate);
|
||||
|
||||
qsizetype logCount() const;
|
||||
void setLogCount(qsizetype newLogCount);
|
||||
|
||||
int scriptTimeout() const;
|
||||
void setScriptTimeout(int newScriptTimeout);
|
||||
|
||||
void setEnabledExtPlugins(const QStringList &newEnabledPlugins);
|
||||
void setEnabledDevPlugins(const QStringList &newEnabledDevPlugins);
|
||||
|
||||
public:
|
||||
void checkWriteableAndWarn();
|
||||
|
||||
QStringList readPluginRule(const QByteArray &data);
|
||||
QByteArray savePluginRule(const QStringList &rules);
|
||||
|
||||
signals:
|
||||
void sigEditorfontSizeChanged(int v);
|
||||
void sigDecodeStrlimitChanged(int v);
|
||||
|
@ -225,6 +171,8 @@ private:
|
|||
QStringList m_usrHideCats;
|
||||
QStringList m_sysHideCats;
|
||||
|
||||
QStringList m_enabledExtPlugins;
|
||||
QStringList m_enabledDevPlugins;
|
||||
QString m_lastUsedPath;
|
||||
|
||||
bool m_dontUseSplash = false;
|
||||
|
@ -238,7 +186,6 @@ private:
|
|||
|
||||
private:
|
||||
QFont _defaultFont;
|
||||
SETTING_ITEMS _setUnsaved;
|
||||
};
|
||||
|
||||
#endif // SETTINGMANAGER_H
|
||||
|
|
|
@ -50,10 +50,8 @@ QString WingCStruct::retranslate(const QString &str) {
|
|||
}
|
||||
|
||||
WingCStruct::RegisteredEvents WingCStruct::registeredEvents() const {
|
||||
RegisteredEvents evs;
|
||||
evs.setFlag(RegisteredEvent::ScriptPragma);
|
||||
evs.setFlag(RegisteredEvent::ScriptPragmaInit);
|
||||
return evs;
|
||||
return packupEvent(RegisteredEvent::ScriptPragma,
|
||||
RegisteredEvent::ScriptPragmaInit);
|
||||
}
|
||||
|
||||
QList<WingHex::SettingPage *> WingCStruct::registeredSettingPages() const {
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "editorview.h"
|
||||
|
||||
#include "QHexView/document/buffer/qfilebuffer.h"
|
||||
#include "QHexView/document/buffer/qmemorybuffer.h"
|
||||
#include "Qt-Advanced-Docking-System/src/DockWidgetTab.h"
|
||||
|
||||
#include "class/logger.h"
|
||||
|
@ -36,7 +35,6 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
constexpr qsizetype FILE_MAX_BUFFER = 0x32000000; // 800MB
|
||||
constexpr auto CLONE_LIMIT = 3;
|
||||
|
||||
constexpr auto VIEW_PROPERTY = "__VIEW__";
|
||||
|
@ -302,7 +300,7 @@ ErrFile EditorView::newFile(size_t index) {
|
|||
m_docType = DocumentType::File;
|
||||
m_isWorkSpace = false;
|
||||
m_isNewFile = true;
|
||||
auto p = QHexDocument::fromMemory<QMemoryBuffer>(QByteArray(), false);
|
||||
auto p = QHexDocument::fromMemory<QFileBuffer>(QByteArray(), false);
|
||||
p->setDocSaved();
|
||||
m_hex->setDocument(QSharedPointer<QHexDocument>(p));
|
||||
m_hex->cursor()->setInsertionMode(QHexCursor::InsertMode);
|
||||
|
@ -323,11 +321,7 @@ ErrFile EditorView::openFile(const QString &filename) {
|
|||
|
||||
auto readonly = !Utilities::fileCanWrite(filename);
|
||||
|
||||
auto *p =
|
||||
info.size() > FILE_MAX_BUFFER
|
||||
? QHexDocument::fromLargeFile(filename, readonly)
|
||||
: QHexDocument::fromFile<QMemoryBuffer>(filename, readonly);
|
||||
|
||||
auto *p = QHexDocument::fromFile<QFileBuffer>(filename, readonly);
|
||||
if (Q_UNLIKELY(p == nullptr)) {
|
||||
return ErrFile::Permission;
|
||||
}
|
||||
|
@ -380,9 +374,7 @@ ErrFile EditorView::openExtFile(const QString &ext, const QString &file) {
|
|||
}
|
||||
}
|
||||
|
||||
auto *p = (d->size() > FILE_MAX_BUFFER || d->size() < 0)
|
||||
? QHexDocument::fromDevice<QFileBuffer>(d, readonly)
|
||||
: QHexDocument::fromDevice<QMemoryBuffer>(d, readonly);
|
||||
auto *p = QHexDocument::fromDevice<QFileBuffer>(d, readonly);
|
||||
|
||||
if (Q_UNLIKELY(p == nullptr)) {
|
||||
return ErrFile::Error;
|
||||
|
@ -580,9 +572,15 @@ ErrFile EditorView::save(const QString &workSpaceName, const QString &path,
|
|||
|
||||
if (doc->saveTo(&file, !isExport)) {
|
||||
file.close();
|
||||
|
||||
if (!isExport) {
|
||||
m_fileName = QFileInfo(fileName).absoluteFilePath();
|
||||
|
||||
if (isNewFile()) {
|
||||
auto buffer = new QFileBuffer;
|
||||
buffer->read(new QFile(fileName));
|
||||
doc->setBuffer(buffer);
|
||||
}
|
||||
|
||||
m_isNewFile = false;
|
||||
m_docType = DocumentType::File;
|
||||
doc->setDocSaved();
|
||||
|
|
|
@ -361,7 +361,7 @@ private slots:
|
|||
WING_API bool moveTo(QObject *caller, qsizetype offset,
|
||||
bool clearSelection);
|
||||
WING_API bool select(QObject *caller, qsizetype offset, qsizetype length,
|
||||
SelectionMode mode);
|
||||
WingHex::SelectionMode mode);
|
||||
WING_API bool setInsertionMode(QObject *caller, bool isinsert);
|
||||
|
||||
// metadata
|
||||
|
|
|
@ -76,25 +76,21 @@ public:
|
|||
|
||||
if (ctx->IntegerConstant()) {
|
||||
auto r = parseIntegerConstant(ctx->IntegerConstant()->getText());
|
||||
if (std::holds_alternative<qint64>(r)) {
|
||||
lastAddr = std::get<qint64>(r);
|
||||
} else if (std::holds_alternative<quint64>(r)) {
|
||||
lastAddr = std::get<quint64>(r);
|
||||
if (r) {
|
||||
lastAddr = r.value();
|
||||
} else {
|
||||
lastPos = GotoWidget::SEEKPOS::Invaild;
|
||||
lastAddr = 0;
|
||||
}
|
||||
} else {
|
||||
auto r = visitAssignmentExpression(ctx->assignmentExpression());
|
||||
if (r.type() == typeid(quint64)) {
|
||||
lastAddr = std::any_cast<quint64>(r);
|
||||
} else if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto addr = std::any_cast<qint64>(r);
|
||||
if (addr < 0) {
|
||||
lastPos = GotoWidget::SEEKPOS::Invaild;
|
||||
lastAddr = 0;
|
||||
}
|
||||
lastAddr = quint64(addr);
|
||||
lastAddr = addr;
|
||||
} else {
|
||||
lastPos = GotoWidget::SEEKPOS::Invaild;
|
||||
lastAddr = 0;
|
||||
|
@ -105,7 +101,7 @@ public:
|
|||
}
|
||||
|
||||
public:
|
||||
quint64 lastAddr = 0;
|
||||
qint64 lastAddr = 0;
|
||||
GotoWidget::SEEKPOS lastPos = GotoWidget::SEEKPOS::Invaild;
|
||||
|
||||
public:
|
||||
|
@ -117,10 +113,8 @@ public:
|
|||
|
||||
if (ctx->IntegerConstant()) {
|
||||
auto r = parseIntegerConstant(ctx->IntegerConstant()->getText());
|
||||
if (std::holds_alternative<qint64>(r)) {
|
||||
return std::get<qint64>(r);
|
||||
} else if (std::holds_alternative<quint64>(r)) {
|
||||
return std::get<quint64>(r);
|
||||
if (r) {
|
||||
return r.value();
|
||||
}
|
||||
} else if (ctx->unaryExpression()) {
|
||||
return visitUnaryExpression(ctx->unaryExpression());
|
||||
|
@ -137,18 +131,7 @@ public:
|
|||
|
||||
auto op = ctx->unaryOperator();
|
||||
auto r = visitCastExpression(ctx->castExpression());
|
||||
if (r.type() == typeid(quint64)) {
|
||||
auto v = std::any_cast<quint64>(r);
|
||||
if (op->Minus()) {
|
||||
return -v;
|
||||
} else if (op->Plus()) {
|
||||
return +v;
|
||||
} else if (op->Tilde()) {
|
||||
return ~v;
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
} else if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto v = std::any_cast<qint64>(r);
|
||||
if (op->Minus()) {
|
||||
return -v;
|
||||
|
@ -170,13 +153,10 @@ public:
|
|||
return defaultResult();
|
||||
}
|
||||
|
||||
qulonglong ret = 0;
|
||||
qint64 ret = 0;
|
||||
for (auto &v : ctx->exclusiveOrExpression()) {
|
||||
auto r = visitExclusiveOrExpression(v);
|
||||
if (r.type() == typeid(quint64)) {
|
||||
auto rr = std::any_cast<quint64>(r);
|
||||
ret |= rr;
|
||||
} else if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto rr = std::any_cast<qint64>(r);
|
||||
ret |= rr;
|
||||
} else {
|
||||
|
@ -195,10 +175,8 @@ public:
|
|||
|
||||
if (ctx->IntegerConstant()) {
|
||||
auto r = parseIntegerConstant(ctx->IntegerConstant()->getText());
|
||||
if (std::holds_alternative<qint64>(r)) {
|
||||
return std::get<qint64>(r);
|
||||
} else if (std::holds_alternative<quint64>(r)) {
|
||||
return std::get<quint64>(r);
|
||||
if (r) {
|
||||
return r.value();
|
||||
}
|
||||
} else if (ctx->inclusiveOrExpression()) {
|
||||
return visitInclusiveOrExpression(ctx->inclusiveOrExpression());
|
||||
|
@ -213,15 +191,12 @@ public:
|
|||
return defaultResult();
|
||||
}
|
||||
|
||||
quint64 v = 0;
|
||||
qint64 v = 0;
|
||||
for (auto &ex : ctx->andExpression()) {
|
||||
auto r = visitAndExpression(ex);
|
||||
if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto rv = std::any_cast<qint64>(r);
|
||||
v ^= rv;
|
||||
} else if (r.type() == typeid(quint64)) {
|
||||
auto rv = std::any_cast<quint64>(r);
|
||||
v ^= rv;
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
|
@ -239,17 +214,14 @@ public:
|
|||
quint64 v = std::numeric_limits<quint64>::max();
|
||||
for (auto &ex : ctx->shiftExpression()) {
|
||||
auto r = visitShiftExpression(ex);
|
||||
if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto rv = std::any_cast<qint64>(r);
|
||||
v &= rv;
|
||||
} else if (r.type() == typeid(quint64)) {
|
||||
auto rv = std::any_cast<quint64>(r);
|
||||
v &= rv;
|
||||
v &= quint64(rv);
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
}
|
||||
return v;
|
||||
return qint64(v);
|
||||
}
|
||||
|
||||
std::any
|
||||
|
@ -261,12 +233,10 @@ public:
|
|||
auto data = ctx->additiveExpression();
|
||||
auto total = data.size();
|
||||
|
||||
quint64 ret = 0;
|
||||
qint64 ret = 0;
|
||||
auto retv = visitAdditiveExpression(data.front());
|
||||
if (retv.type() == typeid(qint64)) {
|
||||
if (retv.has_value()) {
|
||||
ret = std::any_cast<qint64>(retv);
|
||||
} else if (retv.type() == typeid(quint64)) {
|
||||
ret = std::any_cast<quint64>(retv);
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
|
@ -275,22 +245,16 @@ public:
|
|||
auto op = ctx->children[2 * i - 1]->getText();
|
||||
auto r = visitAdditiveExpression(data.at(i));
|
||||
if (op == "<<") {
|
||||
if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto rv = std::any_cast<qint64>(r);
|
||||
ret <<= rv;
|
||||
} else if (r.type() == typeid(quint64)) {
|
||||
auto rv = std::any_cast<quint64>(r);
|
||||
ret <<= rv;
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
} else if (op == ">>") {
|
||||
if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto rv = std::any_cast<qint64>(r);
|
||||
ret >>= rv;
|
||||
} else if (r.type() == typeid(quint64)) {
|
||||
auto rv = std::any_cast<quint64>(r);
|
||||
ret >>= rv;
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
|
@ -311,12 +275,10 @@ public:
|
|||
auto data = ctx->multiplicativeExpression();
|
||||
auto total = data.size();
|
||||
|
||||
quint64 ret = 0;
|
||||
qint64 ret = 0;
|
||||
auto retv = visitMultiplicativeExpression(data.front());
|
||||
if (retv.type() == typeid(qint64)) {
|
||||
if (retv.has_value()) {
|
||||
ret = std::any_cast<qint64>(retv);
|
||||
} else if (retv.type() == typeid(quint64)) {
|
||||
ret = std::any_cast<quint64>(retv);
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
|
@ -324,7 +286,7 @@ public:
|
|||
for (size_t i = 1; i < total; i++) {
|
||||
auto r = visitMultiplicativeExpression(data.at(i));
|
||||
auto op = ctx->children[2 * i - 1]->getText();
|
||||
if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto rv = std::any_cast<qint64>(r);
|
||||
if (op == "+") {
|
||||
ret += rv;
|
||||
|
@ -333,15 +295,6 @@ public:
|
|||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
} else if (r.type() == typeid(quint64)) {
|
||||
auto rv = std::any_cast<quint64>(r);
|
||||
if (op == "+") {
|
||||
ret += rv;
|
||||
} else if (op == "-") {
|
||||
ret -= rv;
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
|
@ -359,12 +312,10 @@ public:
|
|||
auto data = ctx->castExpression();
|
||||
auto total = data.size();
|
||||
|
||||
quint64 ret = 0;
|
||||
qint64 ret = 0;
|
||||
auto retv = visitCastExpression(data.front());
|
||||
if (retv.type() == typeid(qint64)) {
|
||||
if (retv.has_value()) {
|
||||
ret = std::any_cast<qint64>(retv);
|
||||
} else if (retv.type() == typeid(quint64)) {
|
||||
ret = std::any_cast<quint64>(retv);
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
|
@ -372,7 +323,7 @@ public:
|
|||
for (size_t i = 1; i < total; i++) {
|
||||
auto r = visitCastExpression(data.at(i));
|
||||
auto op = ctx->children[2 * i - 1]->getText();
|
||||
if (r.type() == typeid(qint64)) {
|
||||
if (r.has_value()) {
|
||||
auto rv = std::any_cast<qint64>(r);
|
||||
if (op == "*") {
|
||||
ret *= rv;
|
||||
|
@ -383,17 +334,6 @@ public:
|
|||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
} else if (r.type() == typeid(quint64)) {
|
||||
auto rv = std::any_cast<quint64>(r);
|
||||
if (op == "*") {
|
||||
ret *= rv;
|
||||
} else if (op == "/") {
|
||||
ret /= rv;
|
||||
} else if (op == "%") {
|
||||
ret %= rv;
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
} else {
|
||||
return defaultResult();
|
||||
}
|
||||
|
@ -410,10 +350,8 @@ public:
|
|||
|
||||
if (ctx->IntegerConstant()) {
|
||||
auto r = parseIntegerConstant(ctx->IntegerConstant()->getText());
|
||||
if (std::holds_alternative<qint64>(r)) {
|
||||
return std::get<qint64>(r);
|
||||
} else if (std::holds_alternative<quint64>(r)) {
|
||||
return std::get<quint64>(r);
|
||||
if (r) {
|
||||
return r.value();
|
||||
}
|
||||
} else if (ctx->assignmentExpression()) {
|
||||
return visitAssignmentExpression(ctx->assignmentExpression());
|
||||
|
@ -423,8 +361,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
std::variant<std::monostate, qint64, quint64>
|
||||
parseIntegerConstant(const std::string &text) {
|
||||
std::optional<qint64> parseIntegerConstant(const std::string &text) {
|
||||
Q_STATIC_ASSERT_X(
|
||||
QT_VERSION >= QT_VERSION_CHECK(6, 4, 0),
|
||||
"If you want to support Qt version lower than 6.4.0, You should "
|
||||
|
@ -436,11 +373,7 @@ private:
|
|||
if (b) {
|
||||
return num;
|
||||
} else {
|
||||
auto num = ct.toULongLong(&b, 0);
|
||||
if (b) {
|
||||
return num;
|
||||
}
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -245,8 +245,8 @@ MainWindow::MainWindow(SplashDialog *splash) : FramelessMainWindow() {
|
|||
m_scriptConsole->setEnabled(false);
|
||||
|
||||
// configure error, so disable all script feature
|
||||
WingHex::WingRibbonToolBoxInfo::RibbonCatagories catagories;
|
||||
m_ribbonMaps[catagories.SCRIPT]->setEnabled(false);
|
||||
m_ribbonMaps[WingHex::WingRibbonCatagories::SCRIPT]->setEnabled(
|
||||
false);
|
||||
} else {
|
||||
ScriptMachine::RegCallBacks callbacks;
|
||||
callbacks.getInputFn = [this]() -> QString {
|
||||
|
@ -293,7 +293,6 @@ MainWindow::MainWindow(SplashDialog *splash) : FramelessMainWindow() {
|
|||
QMessageBox::critical(this, qAppName(),
|
||||
tr("ScriptEngineInitFailed"));
|
||||
set.setScriptEnabled(false);
|
||||
set.save(SettingManager::SCRIPT);
|
||||
throw CrashCode::ScriptInitFailed;
|
||||
}
|
||||
}
|
||||
|
@ -370,33 +369,35 @@ void MainWindow::buildUpRibbonBar() {
|
|||
|
||||
loadCacheIcon();
|
||||
|
||||
using RibbonCatagories = WingHex::WingRibbonToolBoxInfo::RibbonCatagories;
|
||||
RibbonCatagories catagories;
|
||||
using RibbonCatagories = WingHex::WingRibbonCatagories;
|
||||
|
||||
m_ribbonMaps[catagories.FILE] = buildFilePage(m_ribbon->addTab(tr("File")));
|
||||
m_ribbonMaps[RibbonCatagories::FILE] =
|
||||
buildFilePage(m_ribbon->addTab(tr("File")));
|
||||
qApp->processEvents();
|
||||
m_ribbonMaps[catagories.EDIT] = buildEditPage(m_ribbon->addTab(tr("Edit")));
|
||||
m_ribbonMaps[RibbonCatagories::EDIT] =
|
||||
buildEditPage(m_ribbon->addTab(tr("Edit")));
|
||||
qApp->processEvents();
|
||||
m_ribbonMaps[catagories.VIEW] = buildViewPage(m_ribbon->addTab(tr("View")));
|
||||
m_ribbonMaps[RibbonCatagories::VIEW] =
|
||||
buildViewPage(m_ribbon->addTab(tr("View")));
|
||||
qApp->processEvents();
|
||||
|
||||
auto &set = SettingManager::instance();
|
||||
if (set.scriptEnabled()) {
|
||||
m_ribbonMaps[catagories.SCRIPT] =
|
||||
m_ribbonMaps[RibbonCatagories::SCRIPT] =
|
||||
buildScriptPage(m_ribbon->addTab(tr("Script")));
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
if (set.enablePlugin()) {
|
||||
m_ribbonMaps[catagories.PLUGIN] =
|
||||
m_ribbonMaps[RibbonCatagories::PLUGIN] =
|
||||
buildPluginPage(m_ribbon->addTab(tr("Plugin")));
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
m_ribbonMaps[catagories.SETTING] =
|
||||
m_ribbonMaps[RibbonCatagories::SETTING] =
|
||||
buildSettingPage(m_ribbon->addTab(tr("Setting")));
|
||||
qApp->processEvents();
|
||||
m_ribbonMaps[catagories.ABOUT] =
|
||||
m_ribbonMaps[RibbonCatagories::ABOUT] =
|
||||
buildAboutPage(m_ribbon->addTab(tr("About")));
|
||||
qApp->processEvents();
|
||||
|
||||
|
@ -4030,7 +4031,6 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
|||
if (m_scriptDialog) {
|
||||
m_scriptDialog->saveDockLayout();
|
||||
set.setRecentFiles(m_recentmanager->saveRecent());
|
||||
set.save();
|
||||
}
|
||||
|
||||
PluginSystem::instance().destory();
|
||||
|
|
|
@ -278,7 +278,6 @@ bool ScriptingDialog::about2Close() {
|
|||
void ScriptingDialog::saveDockLayout() {
|
||||
auto &set = SettingManager::instance();
|
||||
set.setScriptDockLayout(_savedLayout);
|
||||
set.save(SettingManager::NONE);
|
||||
}
|
||||
|
||||
void ScriptingDialog::buildUpRibbonBar() {
|
||||
|
|
|
@ -23,20 +23,87 @@
|
|||
#include "utilities.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCloseEvent>
|
||||
#include <QMenu>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
|
||||
SettingDialog::SettingDialog(QWidget *parent)
|
||||
: QWidget(parent), ui(new Ui::SettingDialog) {
|
||||
ui->setupUi(this);
|
||||
|
||||
_dialog = new FramelessDialogBase(parent);
|
||||
_dialog->buildUpContent(this);
|
||||
_dialog->setWindowTitle(this->windowTitle());
|
||||
connect(_dialog, &FramelessDialogBase::rejected, this, [=] {
|
||||
for (auto &page : m_pages) {
|
||||
page->cancel();
|
||||
connect(ui->listWidget, &QListWidget::currentItemChanged, this,
|
||||
[this](QListWidgetItem *current, QListWidgetItem *previous) {
|
||||
if (previous) {
|
||||
auto page = m_pages.at(
|
||||
ui->listWidget->indexFromItem(previous).row());
|
||||
if (page->containUnsavedChanges()) {
|
||||
auto ret = WingMessageBox::question(
|
||||
this, tr("UnsavedChanges"),
|
||||
tr("SaveChangesDiscardLeave?"));
|
||||
if (ret == QMessageBox::Yes) {
|
||||
page->discard();
|
||||
} else {
|
||||
QTimer::singleShot(100, this, [this, previous]() {
|
||||
ui->listWidget->blockSignals(true);
|
||||
ui->listWidget->setCurrentItem(previous);
|
||||
ui->listWidget->blockSignals(false);
|
||||
});
|
||||
page->highlightUnsavedChange();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (current) {
|
||||
auto curpage = m_pages.at(
|
||||
ui->listWidget->indexFromItem(current).row());
|
||||
ui->stackedWidget->setCurrentWidget(curpage);
|
||||
}
|
||||
});
|
||||
connect(ui->btnRestore, &QPushButton::clicked, this, [this]() {
|
||||
auto idx = ui->listWidget->currentRow();
|
||||
auto page = m_pages.at(idx);
|
||||
page->restore();
|
||||
});
|
||||
|
||||
_dialog = new FramelessDialogBase(parent);
|
||||
_dialog->installEventFilter(this);
|
||||
_dialog->buildUpContent(this);
|
||||
_dialog->setWindowTitle(this->windowTitle());
|
||||
|
||||
ui->btnRestore->setStyleSheet(
|
||||
QStringLiteral("QToolButton::down-arrow { width:10px; height:10px; "
|
||||
"subcontrol-position:right center; "
|
||||
"subcontrol-origin:content; left: -2px;"));
|
||||
auto menu = new QMenu(ui->btnRestore);
|
||||
auto a = menu->addAction(tr("Restore current"));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
auto ret = WingMessageBox::warning(this, tr("Restore"),
|
||||
tr("RestoreCurPageSets?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (ret == QMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
auto idx = ui->listWidget->currentRow();
|
||||
if (idx > 0) {
|
||||
auto page = m_pages.at(idx);
|
||||
page->restore();
|
||||
}
|
||||
});
|
||||
|
||||
a = menu->addAction(tr("Restore all"));
|
||||
connect(a, &QAction::triggered, this, [this]() {
|
||||
auto ret =
|
||||
WingMessageBox::critical(this, tr("Restore"), tr("RestoreAllSets?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (ret == QMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
for (auto &p : m_pages) {
|
||||
p->restore();
|
||||
}
|
||||
});
|
||||
ui->btnRestore->setMenu(menu);
|
||||
|
||||
Utilities::moveToCenter(this);
|
||||
}
|
||||
|
@ -68,9 +135,11 @@ void SettingDialog::build() {
|
|||
}
|
||||
|
||||
void SettingDialog::showConfig(int index) {
|
||||
ui->listWidget->blockSignals(true);
|
||||
if (index >= 0 && index < m_pages.size()) {
|
||||
ui->listWidget->setCurrentRow(index);
|
||||
}
|
||||
ui->listWidget->blockSignals(false);
|
||||
Utilities::moveToCenter(this);
|
||||
_dialog->exec();
|
||||
}
|
||||
|
@ -90,6 +159,25 @@ void SettingDialog::showConfig(const QString &id) {
|
|||
_dialog->exec();
|
||||
}
|
||||
|
||||
bool SettingDialog::eventFilter(QObject *, QEvent *event) {
|
||||
if (event->type() == QEvent::Close) {
|
||||
auto e = static_cast<QCloseEvent *>(event);
|
||||
auto page = m_pages.at(ui->listWidget->currentRow());
|
||||
if (page->containUnsavedChanges()) {
|
||||
auto ret = WingMessageBox::question(this, tr("UnsavedChanges"),
|
||||
tr("SaveChangesDiscardLeave?"));
|
||||
if (ret == QMessageBox::Yes) {
|
||||
page->discard();
|
||||
} else {
|
||||
page->highlightUnsavedChange();
|
||||
event->ignore();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SettingDialog::toastTakeEffectReboot() {
|
||||
auto page = qobject_cast<WingHex::SettingPage *>(sender());
|
||||
if (page) {
|
||||
|
@ -100,47 +188,3 @@ void SettingDialog::toastTakeEffectReboot() {
|
|||
tr("TakeEffectRestart"));
|
||||
}
|
||||
}
|
||||
|
||||
void SettingDialog::on_buttonBox_clicked(QAbstractButton *button) {
|
||||
auto btnbox = ui->buttonBox;
|
||||
if (button == btnbox->button(QDialogButtonBox::Ok)) {
|
||||
for (auto &page : m_pages) {
|
||||
page->apply();
|
||||
}
|
||||
_dialog->done(1);
|
||||
} else if (button == btnbox->button(QDialogButtonBox::Apply)) {
|
||||
for (auto &page : m_pages) {
|
||||
page->apply();
|
||||
}
|
||||
} else if (button == btnbox->button(QDialogButtonBox::RestoreDefaults)) {
|
||||
auto index = ui->listWidget->currentRow();
|
||||
if (index >= 0) {
|
||||
m_pages.at(index)->reset();
|
||||
}
|
||||
toastTakeEffectReboot();
|
||||
} else if (button == btnbox->button(QDialogButtonBox::Reset)) {
|
||||
auto res = WingMessageBox::warning(
|
||||
this, qAppName(),
|
||||
tr("This will reset all settings. Are you sure to continue?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (res == QMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &page : m_pages) {
|
||||
page->reset();
|
||||
}
|
||||
|
||||
toastTakeEffectReboot();
|
||||
} else if (button == btnbox->button(QDialogButtonBox::Cancel)) {
|
||||
for (auto &page : m_pages) {
|
||||
page->cancel();
|
||||
}
|
||||
_dialog->done(0);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingDialog::on_listWidget_currentRowChanged(int currentRow) {
|
||||
ui->stackedWidget->setCurrentWidget(m_pages.at(currentRow));
|
||||
}
|
||||
|
|
|
@ -31,21 +31,21 @@ class SettingDialog : public QWidget {
|
|||
|
||||
public:
|
||||
explicit SettingDialog(QWidget *parent = nullptr);
|
||||
~SettingDialog();
|
||||
virtual ~SettingDialog();
|
||||
|
||||
public:
|
||||
void addPage(WingHex::SettingPage *page);
|
||||
void build(); // you can only call once
|
||||
void showConfig(int index = -1);
|
||||
void showConfig(const QString &id);
|
||||
|
||||
// QObject interface
|
||||
public:
|
||||
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
public slots:
|
||||
void toastTakeEffectReboot();
|
||||
|
||||
private slots:
|
||||
void on_buttonBox_clicked(QAbstractButton *button);
|
||||
|
||||
void on_listWidget_currentRowChanged(int currentRow);
|
||||
|
||||
private:
|
||||
Ui::SettingDialog *ui;
|
||||
QList<WingHex::SettingPage *> m_pages;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>750</width>
|
||||
<height>800</height>
|
||||
<width>700</width>
|
||||
<height>750</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
|
@ -23,18 +23,27 @@
|
|||
<iconset>
|
||||
<normaloff>:/img/general.png</normaloff>:/img/general.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="childrenCollapsible">
|
||||
<bool>false</bool>
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
|
@ -43,23 +52,38 @@
|
|||
</size>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionRectVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStackedWidget" name="stackedWidget"/>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<widget class="QToolButton" name="btnRestore">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
|
||||
<property name="text">
|
||||
<string>Restore</string>
|
||||
</property>
|
||||
<property name="popupMode">
|
||||
<enum>QToolButton::ToolButtonPopupMode::InstantPopup</enum>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonStyle::ToolButtonTextOnly</enum>
|
||||
</property>
|
||||
<property name="arrowType">
|
||||
<enum>Qt::ArrowType::DownArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStackedWidget" name="stackedWidget"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -10,20 +10,27 @@ ClangFormatSetDialog::ClangFormatSetDialog(QWidget *parent)
|
|||
: WingHex::SettingPage(parent), ui(new Ui::ClangFormatSetDialog) {
|
||||
ui->setupUi(this);
|
||||
|
||||
auto &clang = ClangFormatManager::instance();
|
||||
ui->cbStyle->addItems(clang.supportedStyles());
|
||||
auto clang = &ClangFormatManager::instance();
|
||||
ui->cbStyle->addItems(clang->supportedStyles());
|
||||
|
||||
ui->leLocation->setText(ClangFormatManager::getProgramName());
|
||||
|
||||
if (clang.exists()) {
|
||||
ui->lblClangPath->setText(clang.path());
|
||||
ui->lblClangPath->setToolTip(clang.path());
|
||||
ui->lblClangVersion->setText(clang.version());
|
||||
if (clang->exists()) {
|
||||
ui->lblClangPath->setText(clang->path());
|
||||
ui->lblClangPath->setToolTip(clang->path());
|
||||
ui->lblClangVersion->setText(clang->version());
|
||||
} else {
|
||||
ui->lblClangPath->setStyleSheet(QStringLiteral("color:red"));
|
||||
}
|
||||
|
||||
reload();
|
||||
|
||||
connect(ui->cbEnabled, &QCheckBox::toggled, clang,
|
||||
&ClangFormatManager::setEnabled);
|
||||
connect(ui->cbAutoFmt, &QCheckBox::toggled, clang,
|
||||
&ClangFormatManager::setAutoFormat);
|
||||
connect(ui->cbStyle, &QComboBox::currentTextChanged, clang,
|
||||
&ClangFormatManager::setClangStyle);
|
||||
}
|
||||
|
||||
ClangFormatSetDialog::~ClangFormatSetDialog() { delete ui; }
|
||||
|
@ -59,21 +66,12 @@ QString ClangFormatSetDialog::id() const {
|
|||
return QStringLiteral("ClangFormat");
|
||||
}
|
||||
|
||||
void ClangFormatSetDialog::apply() {
|
||||
auto &clang = ClangFormatManager::instance();
|
||||
clang.setEnabled(ui->cbEnabled->isChecked());
|
||||
clang.setAutoFormat(ui->cbAutoFmt->isChecked());
|
||||
clang.setClangStyle(ui->cbStyle->currentText());
|
||||
}
|
||||
|
||||
void ClangFormatSetDialog::reset() {
|
||||
void ClangFormatSetDialog::restore() {
|
||||
auto &clang = ClangFormatManager::instance();
|
||||
clang.reset();
|
||||
reload();
|
||||
}
|
||||
|
||||
void ClangFormatSetDialog::cancel() { reload(); }
|
||||
|
||||
void ClangFormatSetDialog::on_cbStyle_currentTextChanged(const QString &arg1) {
|
||||
ui->btnStyleCustom->setEnabled(arg1 == QStringLiteral("Custom"));
|
||||
}
|
||||
|
|
|
@ -30,9 +30,7 @@ public:
|
|||
|
||||
// SettingPage interface
|
||||
public:
|
||||
virtual void apply() override;
|
||||
virtual void reset() override;
|
||||
virtual void cancel() override;
|
||||
virtual void restore() override;
|
||||
|
||||
private slots:
|
||||
void on_cbStyle_currentTextChanged(const QString &arg1);
|
||||
|
|
|
@ -18,16 +18,16 @@
|
|||
<number>8</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cbEnabled">
|
||||
|
@ -58,7 +58,7 @@
|
|||
<string notr="true">-</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -75,7 +75,7 @@
|
|||
<string notr="true">-</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -184,7 +184,7 @@
|
|||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
|
|
@ -25,6 +25,20 @@ EditorSettingDialog::EditorSettingDialog(QWidget *parent)
|
|||
: WingHex::SettingPage(parent), ui(new Ui::EditorSettingDialog) {
|
||||
ui->setupUi(this);
|
||||
reload();
|
||||
|
||||
auto sm = &SettingManager::instance();
|
||||
connect(ui->cbShowaddr, &QCheckBox::toggled, sm,
|
||||
&SettingManager::setEditorShowHeader);
|
||||
connect(ui->cbShowcol, &QCheckBox::toggled, sm,
|
||||
&SettingManager::setEditorShowcol);
|
||||
connect(ui->cbShowtext, &QCheckBox::toggled, sm,
|
||||
&SettingManager::setEditorShowtext);
|
||||
connect(ui->sbFontSize, &QSpinBox::valueChanged, sm,
|
||||
&SettingManager::setEditorfontSize);
|
||||
connect(ui->sbDecStrLimit, &QSpinBox::valueChanged, sm,
|
||||
&SettingManager::setDecodeStrlimit);
|
||||
connect(ui->sbCopyLimit, &QSpinBox::valueChanged, sm,
|
||||
&SettingManager::setCopylimit);
|
||||
}
|
||||
|
||||
EditorSettingDialog::~EditorSettingDialog() { delete ui; }
|
||||
|
@ -45,20 +59,7 @@ QString EditorSettingDialog::name() const { return tr("Editor"); }
|
|||
|
||||
QString EditorSettingDialog::id() const { return QStringLiteral("Editor"); }
|
||||
|
||||
void EditorSettingDialog::apply() {
|
||||
auto &set = SettingManager::instance();
|
||||
set.setEditorShowHeader(ui->cbShowaddr->isChecked());
|
||||
set.setEditorShowcol(ui->cbShowcol->isChecked());
|
||||
set.setEditorShowtext(ui->cbShowtext->isChecked());
|
||||
set.setEditorfontSize(ui->sbFontSize->value());
|
||||
set.setDecodeStrlimit(ui->sbDecStrLimit->value());
|
||||
set.setCopylimit(ui->sbCopyLimit->value());
|
||||
set.save(SettingManager::SETTING::EDITOR);
|
||||
}
|
||||
|
||||
void EditorSettingDialog::reset() {
|
||||
void EditorSettingDialog::restore() {
|
||||
SettingManager::instance().reset(SettingManager::SETTING::EDITOR);
|
||||
reload();
|
||||
}
|
||||
|
||||
void EditorSettingDialog::cancel() { reload(); }
|
||||
|
|
|
@ -42,9 +42,8 @@ public:
|
|||
virtual QIcon categoryIcon() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual void apply() override;
|
||||
virtual void reset() override;
|
||||
virtual void cancel() override;
|
||||
|
||||
virtual void restore() override;
|
||||
};
|
||||
|
||||
#endif // EDITORSETTINGDIALOG_H
|
||||
|
|
|
@ -21,16 +21,16 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
|
@ -185,7 +185,7 @@
|
|||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
|
|
@ -65,6 +65,34 @@ GeneralSettingDialog::GeneralSettingDialog(QWidget *parent)
|
|||
this, &GeneralSettingDialog::optionNeedRestartChanged);
|
||||
|
||||
reload();
|
||||
|
||||
auto sm = &SettingManager::instance();
|
||||
connect(ui->cbLanguage, &QComboBox::currentIndexChanged, sm,
|
||||
[this](int index) {
|
||||
auto data = ui->cbLanguage->itemData(index).toString();
|
||||
SettingManager::instance().setDefaultLang(data);
|
||||
});
|
||||
connect(ui->sbFontSize, &QSpinBox::valueChanged, sm,
|
||||
&SettingManager::setAppfontSize);
|
||||
connect(ui->cbFont, &QFontComboBox::currentTextChanged, sm,
|
||||
&SettingManager::setAppFontFamily);
|
||||
connect(ui->cbTheme, &QComboBox::currentIndexChanged, sm,
|
||||
&SettingManager::setThemeID);
|
||||
connect(ui->cbWinState, &QComboBox::currentIndexChanged, sm, [](int index) {
|
||||
Qt::WindowState state;
|
||||
switch (index) {
|
||||
case 0:
|
||||
state = Qt::WindowState::WindowNoState;
|
||||
break;
|
||||
case 1:
|
||||
state = Qt::WindowState::WindowMaximized;
|
||||
break;
|
||||
default:
|
||||
state = Qt::WindowState::WindowFullScreen;
|
||||
break;
|
||||
}
|
||||
SettingManager::instance().setDefaultWinState(state);
|
||||
});
|
||||
}
|
||||
|
||||
GeneralSettingDialog::~GeneralSettingDialog() { delete ui; }
|
||||
|
@ -117,32 +145,7 @@ QString GeneralSettingDialog::name() const { return tr("General"); }
|
|||
|
||||
QString GeneralSettingDialog::id() const { return QStringLiteral("General"); }
|
||||
|
||||
void GeneralSettingDialog::apply() {
|
||||
auto &set = SettingManager::instance();
|
||||
set.setDefaultLang(ui->cbLanguage->currentData().toString());
|
||||
set.setAppfontSize(ui->sbFontSize->value());
|
||||
set.setAppFontFamily(ui->cbFont->currentText());
|
||||
set.setThemeID(ui->cbTheme->currentIndex());
|
||||
auto s = ui->cbWinState->currentIndex();
|
||||
Qt::WindowState state;
|
||||
switch (s) {
|
||||
case 0:
|
||||
state = Qt::WindowState::WindowNoState;
|
||||
break;
|
||||
case 1:
|
||||
state = Qt::WindowState::WindowMaximized;
|
||||
break;
|
||||
default:
|
||||
state = Qt::WindowState::WindowFullScreen;
|
||||
break;
|
||||
}
|
||||
set.setDefaultWinState(state);
|
||||
set.save(SettingManager::SETTING::APP);
|
||||
}
|
||||
|
||||
void GeneralSettingDialog::reset() {
|
||||
void GeneralSettingDialog::restore() {
|
||||
SettingManager::instance().reset(SettingManager::SETTING::APP);
|
||||
reload();
|
||||
}
|
||||
|
||||
void GeneralSettingDialog::cancel() { reload(); }
|
||||
|
|
|
@ -42,9 +42,8 @@ public:
|
|||
virtual QIcon categoryIcon() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual void apply() override;
|
||||
virtual void reset() override;
|
||||
virtual void cancel() override;
|
||||
|
||||
virtual void restore() override;
|
||||
};
|
||||
|
||||
#endif // GENERALSETTINGDIALOG_H
|
||||
|
|
|
@ -15,16 +15,16 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
|
|
|
@ -64,6 +64,20 @@ OtherSettingsDialog::OtherSettingsDialog(QWidget *parent)
|
|||
this, &OtherSettingsDialog::optionNeedRestartChanged);
|
||||
|
||||
reload();
|
||||
|
||||
auto set = &SettingManager::instance();
|
||||
connect(ui->cbDontShowSplash, &QCheckBox::toggled, set,
|
||||
&SettingManager::setDontUseSplash);
|
||||
connect(ui->cbNativeFileDialog, &QCheckBox::toggled, set,
|
||||
&SettingManager::setUseNativeFileDialog);
|
||||
#ifdef WINGHEX_USE_FRAMELESS
|
||||
connect(ui->cbNativeTitile, &QCheckBox::toggled, set,
|
||||
&SettingManager::setUseNativeTitleBar);
|
||||
#endif
|
||||
connect(ui->cbCheckWhenStartup, &QCheckBox::toggled, set,
|
||||
&SettingManager::setCheckUpdate);
|
||||
connect(ui->cbLogLevel, &QComboBox::currentIndexChanged, set,
|
||||
&SettingManager::setLogLevel);
|
||||
}
|
||||
|
||||
OtherSettingsDialog::~OtherSettingsDialog() { delete ui; }
|
||||
|
@ -86,21 +100,7 @@ QString OtherSettingsDialog::name() const { return tr("Others"); }
|
|||
|
||||
QString OtherSettingsDialog::id() const { return QStringLiteral("Others"); }
|
||||
|
||||
void OtherSettingsDialog::apply() {
|
||||
auto &set = SettingManager::instance();
|
||||
set.setDontUseSplash(ui->cbDontShowSplash->isChecked());
|
||||
set.setUseNativeFileDialog(ui->cbNativeFileDialog->isChecked());
|
||||
#ifdef WINGHEX_USE_FRAMELESS
|
||||
set.setUseNativeTitleBar(ui->cbNativeTitile->isChecked());
|
||||
#endif
|
||||
set.setCheckUpdate(ui->cbCheckWhenStartup->isChecked());
|
||||
set.setLogLevel(ui->cbLogLevel->currentIndex());
|
||||
set.save(SettingManager::OTHER);
|
||||
}
|
||||
|
||||
void OtherSettingsDialog::reset() {
|
||||
void OtherSettingsDialog::restore() {
|
||||
SettingManager::instance().reset(SettingManager::SETTING::OTHER);
|
||||
reload();
|
||||
}
|
||||
|
||||
void OtherSettingsDialog::cancel() { reload(); }
|
||||
|
|
|
@ -42,9 +42,8 @@ public:
|
|||
virtual QIcon categoryIcon() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual void apply() override;
|
||||
virtual void reset() override;
|
||||
virtual void cancel() override;
|
||||
|
||||
virtual void restore() override;
|
||||
};
|
||||
|
||||
#endif // OTHERSETTINGSDIALOG_H
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
|
@ -117,7 +129,7 @@
|
|||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
|
|
|
@ -16,11 +16,18 @@
|
|||
*/
|
||||
|
||||
#include "pluginsettingdialog.h"
|
||||
#include "class/eventfilter.h"
|
||||
#include "class/pluginsystem.h"
|
||||
#include "class/settingmanager.h"
|
||||
#include "ui_pluginsettingdialog.h"
|
||||
#include "utilities.h"
|
||||
|
||||
enum PLUGIN_INFO {
|
||||
PLUIGN_META = Qt::UserRole,
|
||||
PLUIGN_NAME,
|
||||
PLUIGN_COMMENT,
|
||||
};
|
||||
|
||||
PluginSettingDialog::PluginSettingDialog(QWidget *parent)
|
||||
: WingHex::SettingPage(parent), ui(new Ui::PluginSettingDialog) {
|
||||
ui->setupUi(this);
|
||||
|
@ -50,18 +57,98 @@ PluginSettingDialog::PluginSettingDialog(QWidget *parent)
|
|||
|
||||
for (auto &p : plgsys.plugins()) {
|
||||
auto pco = p->pluginIcon();
|
||||
ui->plglist->addItem(
|
||||
new QListWidgetItem(pco.isNull() ? pico : pco, p->pluginName()));
|
||||
auto lwi =
|
||||
new QListWidgetItem(pco.isNull() ? pico : pco, p->pluginName());
|
||||
auto info = plgsys.getPluginInfo(p);
|
||||
auto flags = lwi->flags();
|
||||
if (Q_LIKELY(p != plgsys.angelApi())) {
|
||||
flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
lwi->setFlags(flags);
|
||||
lwi->setCheckState(Qt::Checked);
|
||||
} else {
|
||||
flags.setFlag(Qt::ItemIsUserCheckable, false);
|
||||
lwi->setFlags(flags);
|
||||
}
|
||||
|
||||
lwi->setData(PLUIGN_META, QVariant::fromValue(info));
|
||||
lwi->setData(PLUIGN_NAME, p->pluginName());
|
||||
lwi->setData(PLUIGN_COMMENT, p->pluginComment());
|
||||
ui->plglist->addItem(lwi);
|
||||
}
|
||||
|
||||
pico = ICONRES("plugindis");
|
||||
auto blkplgs = plgsys.blockedPlugins();
|
||||
auto dblkplgs = blkplgs[PluginSystem::BlockReason::Disabled];
|
||||
for (auto &meta : dblkplgs) {
|
||||
auto lwi = new QListWidgetItem(pico, meta.id);
|
||||
auto flags = lwi->flags();
|
||||
flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
lwi->setFlags(flags);
|
||||
lwi->setData(PLUIGN_META, QVariant::fromValue(meta));
|
||||
lwi->setCheckState(Qt::Unchecked);
|
||||
ui->plglist->addItem(lwi);
|
||||
}
|
||||
|
||||
pico = getGrayIcon(NAMEICONRES("plugin"));
|
||||
dblkplgs = blkplgs[PluginSystem::BlockReason::BlockedByManager];
|
||||
for (auto &meta : dblkplgs) {
|
||||
auto lwi = new QListWidgetItem(pico, meta.id);
|
||||
auto flags = lwi->flags();
|
||||
flags.setFlag(Qt::ItemIsUserCheckable, false);
|
||||
lwi->setFlags(flags);
|
||||
auto font = lwi->font();
|
||||
font.setStrikeOut(true);
|
||||
lwi->setFont(font);
|
||||
lwi->setData(PLUIGN_META, QVariant::fromValue(meta));
|
||||
ui->plglist->addItem(lwi);
|
||||
}
|
||||
|
||||
ui->txtc->clear();
|
||||
|
||||
pico = ICONRES("devext");
|
||||
ui->devlist->clear();
|
||||
for (auto &d : plgsys.devices()) {
|
||||
auto pco = d->pluginIcon();
|
||||
ui->devlist->addItem(
|
||||
new QListWidgetItem(pco.isNull() ? pico : pco, d->pluginName()));
|
||||
auto lwi =
|
||||
new QListWidgetItem(pco.isNull() ? pico : pco, d->pluginName());
|
||||
auto info = plgsys.getPluginInfo(d);
|
||||
auto flags = lwi->flags();
|
||||
flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
lwi->setFlags(flags);
|
||||
lwi->setData(PLUIGN_META, QVariant::fromValue(info));
|
||||
lwi->setData(PLUIGN_NAME, d->pluginName());
|
||||
lwi->setData(PLUIGN_COMMENT, d->pluginComment());
|
||||
lwi->setCheckState(Qt::Checked);
|
||||
ui->devlist->addItem(lwi);
|
||||
}
|
||||
|
||||
pico = ICONRES("devextdis");
|
||||
auto blkdevs = plgsys.blockedDevPlugins();
|
||||
auto dblkdevs = blkdevs[PluginSystem::BlockReason::Disabled];
|
||||
for (auto &meta : dblkdevs) {
|
||||
auto lwi = new QListWidgetItem(pico, meta.id);
|
||||
auto flags = lwi->flags();
|
||||
flags.setFlag(Qt::ItemIsUserCheckable);
|
||||
lwi->setFlags(flags);
|
||||
lwi->setData(PLUIGN_META, QVariant::fromValue(meta));
|
||||
lwi->setCheckState(Qt::Unchecked);
|
||||
ui->devlist->addItem(lwi);
|
||||
}
|
||||
|
||||
pico = getGrayIcon(NAMEICONRES("devext"));
|
||||
dblkdevs = blkdevs[PluginSystem::BlockReason::BlockedByManager];
|
||||
for (auto &meta : dblkdevs) {
|
||||
auto lwi = new QListWidgetItem(pico, meta.id);
|
||||
auto flags = lwi->flags();
|
||||
flags.setFlag(Qt::ItemIsUserCheckable, false);
|
||||
lwi->setFlags(flags);
|
||||
auto font = lwi->font();
|
||||
font.setStrikeOut(true);
|
||||
lwi->setFont(font);
|
||||
lwi->setData(PLUIGN_META, QVariant::fromValue(meta));
|
||||
ui->devlist->addItem(lwi);
|
||||
}
|
||||
|
||||
ui->txtd->clear();
|
||||
|
||||
auto minfo = plgsys.monitorManagerInfo();
|
||||
|
@ -85,6 +172,160 @@ PluginSettingDialog::PluginSettingDialog(QWidget *parent)
|
|||
} else {
|
||||
ui->txtm->setText(tr("NoMonitorPlugin"));
|
||||
}
|
||||
|
||||
auto set = &SettingManager::instance();
|
||||
connect(ui->cbEnablePlugin, &QCheckBox::toggled, set,
|
||||
&SettingManager::setEnablePlugin);
|
||||
connect(ui->cbEnablePluginRoot, &QCheckBox::toggled, set,
|
||||
&SettingManager::setEnablePlgInRoot);
|
||||
|
||||
connect(ui->plglist, &QListWidget::itemChanged, this,
|
||||
[this](QListWidgetItem *item) {
|
||||
if (item == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto info = item->data(PLUIGN_META).value<PluginInfo>();
|
||||
auto id = info.id;
|
||||
switch (item->checkState()) {
|
||||
case Qt::Unchecked:
|
||||
_plgChanged.pushRemoveItem(id);
|
||||
break;
|
||||
case Qt::Checked:
|
||||
_plgChanged.pushAddItem(id);
|
||||
break;
|
||||
case Qt::PartiallyChecked:
|
||||
break;
|
||||
}
|
||||
|
||||
ui->btnplgSave->setEnabled(_plgChanged.containChanges());
|
||||
});
|
||||
connect(
|
||||
ui->plglist, &QListWidget::currentItemChanged, this,
|
||||
[this](QListWidgetItem *current, QListWidgetItem *) {
|
||||
if (current == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto info = current->data(PLUIGN_META).value<PluginInfo>();
|
||||
auto plgName = current->data(PLUIGN_NAME).toString();
|
||||
auto plgComment = current->data(PLUIGN_COMMENT).toString();
|
||||
|
||||
ui->txtc->clear();
|
||||
static auto sep = QStringLiteral(" : ");
|
||||
ui->txtc->append(getWrappedText(tr("ID") + sep + info.id));
|
||||
ui->txtc->append(getWrappedText(tr("Name") + sep + plgName));
|
||||
ui->txtc->append(
|
||||
getWrappedText(tr("License") + sep + info.license));
|
||||
ui->txtc->append(getWrappedText(tr("Author") + sep + info.author));
|
||||
ui->txtc->append(getWrappedText(tr("Vendor") + sep + info.vendor));
|
||||
ui->txtc->append(
|
||||
getWrappedText(tr("Version") + sep + info.version.toString()));
|
||||
ui->txtc->append(getWrappedText(tr("Comment") + sep + plgComment));
|
||||
if (!info.dependencies.isEmpty()) {
|
||||
ui->txtc->append(getWrappedText(tr("pluginDependencies:")));
|
||||
for (auto &d : info.dependencies) {
|
||||
ui->txtc->append(
|
||||
getWrappedText(QString(4, ' ') + tr("PUID:") + d.puid));
|
||||
ui->txtc->append(getWrappedText(QString(4, ' ') +
|
||||
tr("Version:") +
|
||||
d.version.toString()));
|
||||
}
|
||||
}
|
||||
ui->txtc->append(getWrappedText(
|
||||
tr("URL") + sep + QStringLiteral("<a href=\"") + info.url +
|
||||
QStringLiteral("\">") + info.url + QStringLiteral("</a> ")));
|
||||
});
|
||||
|
||||
connect(ui->devlist, &QListWidget::itemChanged, this,
|
||||
[this](QListWidgetItem *item) {
|
||||
if (item == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto info = item->data(PLUIGN_META).value<PluginInfo>();
|
||||
auto id = info.id;
|
||||
switch (item->checkState()) {
|
||||
case Qt::Unchecked:
|
||||
_devChanged.pushRemoveItem(id);
|
||||
break;
|
||||
case Qt::Checked:
|
||||
_devChanged.pushAddItem(id);
|
||||
break;
|
||||
case Qt::PartiallyChecked:
|
||||
break;
|
||||
}
|
||||
|
||||
ui->btndevSave->setEnabled(_devChanged.containChanges());
|
||||
});
|
||||
connect(
|
||||
ui->devlist, &QListWidget::currentItemChanged, this,
|
||||
[this](QListWidgetItem *current, QListWidgetItem *) {
|
||||
if (current == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto info = current->data(PLUIGN_META).value<PluginInfo>();
|
||||
auto plgName = current->data(PLUIGN_NAME).toString();
|
||||
auto plgComment = current->data(PLUIGN_COMMENT).toString();
|
||||
|
||||
ui->txtd->clear();
|
||||
static auto sep = QStringLiteral(" : ");
|
||||
ui->txtd->append(getWrappedText(tr("ID") + sep + info.id));
|
||||
ui->txtd->append(getWrappedText(tr("Name") + sep + plgName));
|
||||
ui->txtd->append(
|
||||
getWrappedText(tr("License") + sep + info.license));
|
||||
ui->txtd->append(getWrappedText(tr("Author") + sep + info.author));
|
||||
ui->txtd->append(getWrappedText(tr("Vendor") + sep + info.vendor));
|
||||
ui->txtd->append(
|
||||
getWrappedText(tr("Version") + sep + info.version.toString()));
|
||||
ui->txtd->append(getWrappedText(tr("Comment") + sep + plgComment));
|
||||
ui->txtd->append(getWrappedText(
|
||||
tr("URL") + sep + QStringLiteral("<a href=\"") + info.url +
|
||||
QStringLiteral("\">") + info.url + QStringLiteral("</a>")));
|
||||
});
|
||||
|
||||
connect(ui->btnplgSave, &QPushButton::clicked, set, [this]() {
|
||||
SettingManager::instance().setEnabledExtPlugins(
|
||||
_plgChanged.getContents());
|
||||
_plgChanged.clear();
|
||||
ui->btnplgSave->setEnabled(false);
|
||||
Q_EMIT optionNeedRestartChanged();
|
||||
});
|
||||
connect(ui->btndevSave, &QPushButton::clicked, set, [this]() {
|
||||
SettingManager::instance().setEnabledDevPlugins(
|
||||
_devChanged.getContents());
|
||||
_devChanged.clear();
|
||||
ui->btndevSave->setEnabled(false);
|
||||
Q_EMIT optionNeedRestartChanged();
|
||||
});
|
||||
|
||||
auto ev = new EventFilter(QEvent::EnabledChange, this);
|
||||
connect(ev, &EventFilter::eventTriggered, this,
|
||||
[this](QObject *obj, QEvent *) {
|
||||
if (obj == ui->btnplgSave) {
|
||||
auto tabName = QCoreApplication::translate(
|
||||
"PluginSettingDialog", "PluginInfo", nullptr);
|
||||
if (ui->btnplgSave->isEnabled()) {
|
||||
tabName.append(QStringLiteral(" *"));
|
||||
}
|
||||
ui->tabWidget->setTabText(
|
||||
ui->tabWidget->indexOf(ui->tabPluginInfo), tabName);
|
||||
} else if (obj == ui->btndevSave) {
|
||||
auto tabName = QCoreApplication::translate(
|
||||
"PluginSettingDialog", "DevExtInfo", nullptr);
|
||||
if (ui->btndevSave->isEnabled()) {
|
||||
tabName.append(QStringLiteral(" *"));
|
||||
}
|
||||
ui->tabWidget->setTabText(
|
||||
ui->tabWidget->indexOf(ui->tabDevInfo), tabName);
|
||||
}
|
||||
});
|
||||
ui->btnplgSave->installEventFilter(ev);
|
||||
ui->btndevSave->installEventFilter(ev);
|
||||
|
||||
resetChangedList();
|
||||
|
||||
createPluginStandardMenu(ui->plglist);
|
||||
createPluginStandardMenu(ui->devlist);
|
||||
}
|
||||
|
||||
PluginSettingDialog::~PluginSettingDialog() { delete ui; }
|
||||
|
@ -103,77 +344,117 @@ QString PluginSettingDialog::name() const { return tr("Plugin"); }
|
|||
|
||||
QString PluginSettingDialog::id() const { return QStringLiteral("Plugin"); }
|
||||
|
||||
void PluginSettingDialog::apply() {
|
||||
auto &set = SettingManager::instance();
|
||||
set.setEnablePlugin(ui->cbEnablePlugin->isChecked());
|
||||
set.setEnablePlgInRoot(ui->cbEnablePluginRoot->isChecked());
|
||||
set.save(SettingManager::SETTING::PLUGIN);
|
||||
bool PluginSettingDialog::containUnsavedChanges() const {
|
||||
return ui->btndevSave->isEnabled() || ui->btnplgSave->isEnabled();
|
||||
}
|
||||
|
||||
void PluginSettingDialog::reset() {
|
||||
void PluginSettingDialog::highlightUnsavedChange() {
|
||||
if (ui->btnplgSave->isEnabled()) {
|
||||
ui->tabWidget->setCurrentWidget(ui->tabPluginInfo);
|
||||
} else if (ui->btndevSave->isEnabled()) {
|
||||
ui->tabWidget->setCurrentWidget(ui->tabDevInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void PluginSettingDialog::discard() {
|
||||
resetChangedList();
|
||||
resetUIChagned();
|
||||
}
|
||||
|
||||
void PluginSettingDialog::restore() {
|
||||
SettingManager::instance().reset(SettingManager::SETTING::PLUGIN);
|
||||
reload();
|
||||
}
|
||||
|
||||
void PluginSettingDialog::cancel() { reload(); }
|
||||
|
||||
void PluginSettingDialog::on_devlist_currentRowChanged(int currentRow) {
|
||||
if (currentRow < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto &plgsys = PluginSystem::instance();
|
||||
auto plg = plgsys.device(currentRow);
|
||||
|
||||
auto info = plgsys.getPluginInfo(plg);
|
||||
ui->txtd->clear();
|
||||
static auto sep = QStringLiteral(" : ");
|
||||
ui->txtd->append(getWrappedText(tr("ID") + sep + info.id));
|
||||
ui->txtd->append(getWrappedText(tr("Name") + sep + plg->pluginName()));
|
||||
ui->txtd->append(getWrappedText(tr("License") + sep + info.license));
|
||||
ui->txtd->append(getWrappedText(tr("Author") + sep + info.author));
|
||||
ui->txtd->append(getWrappedText(tr("Vendor") + sep + info.vendor));
|
||||
ui->txtd->append(
|
||||
getWrappedText(tr("Version") + sep + info.version.toString()));
|
||||
ui->txtd->append(
|
||||
getWrappedText(tr("Comment") + sep + plg->pluginComment()));
|
||||
ui->txtd->append(getWrappedText(
|
||||
tr("URL") + sep + QStringLiteral("<a href=\"") + info.url +
|
||||
QStringLiteral("\">") + info.url + QStringLiteral("</a>")));
|
||||
}
|
||||
|
||||
void PluginSettingDialog::on_plglist_currentRowChanged(int currentRow) {
|
||||
if (currentRow < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto &plgsys = PluginSystem::instance();
|
||||
auto plg = plgsys.plugin(currentRow);
|
||||
|
||||
auto info = plgsys.getPluginInfo(plg);
|
||||
ui->txtc->clear();
|
||||
static auto sep = QStringLiteral(" : ");
|
||||
ui->txtc->append(getWrappedText(tr("ID") + sep + info.id));
|
||||
ui->txtc->append(getWrappedText(tr("Name") + sep + plg->pluginName()));
|
||||
ui->txtc->append(getWrappedText(tr("License") + sep + info.license));
|
||||
ui->txtc->append(getWrappedText(tr("Author") + sep + info.author));
|
||||
ui->txtc->append(getWrappedText(tr("Vendor") + sep + info.vendor));
|
||||
ui->txtc->append(
|
||||
getWrappedText(tr("Version") + sep + info.version.toString()));
|
||||
ui->txtc->append(
|
||||
getWrappedText(tr("Comment") + sep + plg->pluginComment()));
|
||||
if (!info.dependencies.isEmpty()) {
|
||||
ui->txtc->append(getWrappedText(tr("pluginDependencies:")));
|
||||
for (auto &d : info.dependencies) {
|
||||
ui->txtc->append(
|
||||
getWrappedText(QString(4, ' ') + tr("PUID:") + d.puid));
|
||||
ui->txtc->append(getWrappedText(QString(4, ' ') + tr("Version:") +
|
||||
d.version.toString()));
|
||||
void PluginSettingDialog::createPluginStandardMenu(QListWidget *widget) {
|
||||
widget->setSelectionMode(QListWidget::ExtendedSelection);
|
||||
widget->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
widget->addAction(tr("SelectEnable"), widget, [widget]() {
|
||||
for (auto &item : widget->selectedItems()) {
|
||||
auto flags = item->flags();
|
||||
if (flags.testFlag(Qt::ItemIsUserCheckable)) {
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
}
|
||||
ui->txtc->append(getWrappedText(
|
||||
tr("URL") + sep + QStringLiteral("<a href=\"") + info.url +
|
||||
QStringLiteral("\">") + info.url + QStringLiteral("</a> ")));
|
||||
});
|
||||
widget->addAction(tr("SelectDisable"), widget, [widget]() {
|
||||
for (auto &item : widget->selectedItems()) {
|
||||
auto flags = item->flags();
|
||||
if (flags.testFlag(Qt::ItemIsUserCheckable)) {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
}
|
||||
});
|
||||
auto a = new QAction(widget);
|
||||
a->setSeparator(true);
|
||||
widget->addAction(a);
|
||||
widget->addAction(tr("SelectAll"), widget, &QListWidget::selectAll);
|
||||
widget->addAction(tr("SelectClear"), widget, &QListWidget::clearSelection);
|
||||
a = new QAction(widget);
|
||||
a->setSeparator(true);
|
||||
widget->addAction(a);
|
||||
widget->addAction(tr("DiscardChanges"), this,
|
||||
&PluginSettingDialog::discard);
|
||||
}
|
||||
|
||||
QIcon PluginSettingDialog::getGrayIcon(const QString &path) {
|
||||
QImage dpico(path);
|
||||
for (int y = 0; y < dpico.height(); ++y) {
|
||||
auto row = reinterpret_cast<QRgb *>(dpico.scanLine(y));
|
||||
for (int x = 0; x < dpico.width(); ++x) {
|
||||
auto c = row[x];
|
||||
if (c) {
|
||||
auto p = qGray(c);
|
||||
row[x] = qRgba(p, p, p, qAlpha(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
return QIcon(QPixmap::fromImage(dpico));
|
||||
}
|
||||
|
||||
void PluginSettingDialog::resetChangedList() {
|
||||
auto &set = SettingManager::instance();
|
||||
_plgChanged.setContents(set.enabledExtPlugins());
|
||||
_devChanged.setContents(set.enabledDevPlugins());
|
||||
}
|
||||
|
||||
void PluginSettingDialog::resetUIChagned() {
|
||||
ui->plglist->blockSignals(true);
|
||||
ui->devlist->blockSignals(true);
|
||||
|
||||
for (int i = 0; i < ui->plglist->count(); ++i) {
|
||||
auto item = ui->plglist->item(i);
|
||||
auto flags = item->flags();
|
||||
if (flags.testFlag(Qt::ItemIsUserCheckable)) {
|
||||
auto info = item->data(PLUIGN_META).value<PluginInfo>();
|
||||
auto id = info.id;
|
||||
if (_plgChanged.containChanges(id)) {
|
||||
item->setCheckState(Qt::Checked);
|
||||
} else {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < ui->devlist->count(); ++i) {
|
||||
auto item = ui->devlist->item(i);
|
||||
auto flags = item->flags();
|
||||
if (flags.testFlag(Qt::ItemIsUserCheckable)) {
|
||||
auto info = item->data(PLUIGN_META).value<PluginInfo>();
|
||||
auto id = info.id;
|
||||
if (_devChanged.containChanges(id)) {
|
||||
item->setCheckState(Qt::Checked);
|
||||
} else {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui->plglist->blockSignals(false);
|
||||
ui->devlist->blockSignals(false);
|
||||
|
||||
ui->btnplgSave->setEnabled(false);
|
||||
ui->btndevSave->setEnabled(false);
|
||||
}
|
||||
|
||||
QString PluginSettingDialog::getWrappedText(const QString &str) {
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#define PLUGINSETTINGDIALOG_H
|
||||
|
||||
#include "WingPlugin/settingpage.h"
|
||||
#include "class/changedstringlist.h"
|
||||
|
||||
#include <QListWidget>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
|
@ -35,6 +38,10 @@ public:
|
|||
private:
|
||||
Ui::PluginSettingDialog *ui;
|
||||
|
||||
ChangedStringList _devChanged;
|
||||
ChangedStringList _plgChanged;
|
||||
|
||||
private:
|
||||
void reload();
|
||||
|
||||
// SettingPage interface
|
||||
|
@ -42,13 +49,19 @@ public:
|
|||
virtual QIcon categoryIcon() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual void apply() override;
|
||||
virtual void reset() override;
|
||||
virtual void cancel() override;
|
||||
|
||||
private slots:
|
||||
void on_devlist_currentRowChanged(int currentRow);
|
||||
void on_plglist_currentRowChanged(int currentRow);
|
||||
virtual bool containUnsavedChanges() const override;
|
||||
virtual void highlightUnsavedChange() override;
|
||||
virtual void discard() override;
|
||||
virtual void restore() override;
|
||||
|
||||
private:
|
||||
void createPluginStandardMenu(QListWidget *widget);
|
||||
|
||||
QIcon getGrayIcon(const QString &path);
|
||||
|
||||
void resetChangedList();
|
||||
void resetUIChagned();
|
||||
|
||||
private:
|
||||
QString getWrappedText(const QString &str);
|
||||
|
|
|
@ -15,16 +15,16 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
|
@ -72,7 +72,7 @@
|
|||
<property name="usesScrollButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<widget class="QWidget" name="tabPluginInfo">
|
||||
<attribute name="icon">
|
||||
<iconset resource="../../resources.qrc">
|
||||
<normaloff>:/com.wingsummer.winghex/images/plugin.png</normaloff>:/com.wingsummer.winghex/images/plugin.png</iconset>
|
||||
|
@ -116,6 +116,16 @@
|
|||
<item>
|
||||
<widget class="QListWidget" name="plglist"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnplgSave">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QTextBrowser" name="txtc">
|
||||
|
@ -127,7 +137,7 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="widget">
|
||||
<widget class="QWidget" name="tabDevInfo">
|
||||
<attribute name="icon">
|
||||
<iconset resource="../../resources.qrc">
|
||||
<normaloff>:/com.wingsummer.winghex/images/devext.png</normaloff>:/com.wingsummer.winghex/images/devext.png</iconset>
|
||||
|
@ -156,6 +166,16 @@
|
|||
<item>
|
||||
<widget class="QListWidget" name="devlist"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btndevSave">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QTextBrowser" name="txtd">
|
||||
|
@ -167,7 +187,7 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<widget class="QWidget" name="tabAPIMon">
|
||||
<attribute name="icon">
|
||||
<iconset resource="../../resources.qrc">
|
||||
<normaloff>:/com.wingsummer.winghex/images/monitor.png</normaloff>:/com.wingsummer.winghex/images/monitor.png</iconset>
|
||||
|
|
|
@ -173,70 +173,87 @@ QEditConfig::QEditConfig(bool isConsole, QWidget *w)
|
|||
}
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
QEditConfig::~QEditConfig() { delete ui; }
|
||||
|
||||
/*!
|
||||
\brief Apply changes
|
||||
*/
|
||||
void QEditConfig::apply() {
|
||||
auto &set = ScriptSettings::instance();
|
||||
auto set = &ScriptSettings::instance();
|
||||
if (m_isConsole) {
|
||||
connect(ui->cbTheme, &QComboBox::currentIndexChanged, set, [this]() {
|
||||
auto &set = ScriptSettings::instance();
|
||||
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());
|
||||
});
|
||||
connect(ui->cbFont, &QFontComboBox::currentFontChanged, set,
|
||||
[](const QFont &font) {
|
||||
ScriptSettings::instance().setConsoleFontFamily(
|
||||
font.family());
|
||||
});
|
||||
connect(ui->spnFontSize, &QSpinBox::valueChanged, set,
|
||||
&ScriptSettings::setConsoleFontSize);
|
||||
connect(ui->spnTabWidth, &QSpinBox::valueChanged, set,
|
||||
&ScriptSettings::setConsoleTabWidth);
|
||||
connect(ui->cbIndentation, &QComboBox::currentIndexChanged, set,
|
||||
[this](int index) {
|
||||
auto data = ui->cbIndentation->itemData(index);
|
||||
ScriptSettings::instance().setConsoleInden(data.toInt());
|
||||
});
|
||||
connect(ui->chkMatchBraces, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setConsoleMatchBraces);
|
||||
connect(ui->chkShowWhitespace, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setConsoleShowWhiteSpace);
|
||||
connect(ui->chkAutoCloseChar, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setConsoleAutoCloseChar);
|
||||
} else {
|
||||
connect(ui->cbTheme, &QComboBox::currentIndexChanged, set, [this]() {
|
||||
auto &set = ScriptSettings::instance();
|
||||
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.setEditorAutoIden(ui->chkAutoIden->isChecked());
|
||||
});
|
||||
connect(ui->cbFont, &QFontComboBox::currentFontChanged, set,
|
||||
[](const QFont &font) {
|
||||
ScriptSettings::instance().setEditorFontFamily(
|
||||
font.family());
|
||||
});
|
||||
connect(ui->spnFontSize, &QSpinBox::valueChanged, set,
|
||||
&ScriptSettings::setEditorFontSize);
|
||||
connect(ui->spnTabWidth, &QSpinBox::valueChanged, set,
|
||||
&ScriptSettings::setEditorTabWidth);
|
||||
connect(ui->cbIndentation, &QComboBox::currentIndexChanged, set,
|
||||
[this](int index) {
|
||||
auto data = ui->cbIndentation->itemData(index);
|
||||
ScriptSettings::instance().setEditorInden(data.toInt());
|
||||
});
|
||||
connect(ui->chkMatchBraces, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorShowLineNumber);
|
||||
connect(ui->chkShowFolding, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorFolding);
|
||||
connect(ui->chkShowIndentGuides, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorShowGuideLine);
|
||||
connect(ui->chkWordWrap, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorWordWrap);
|
||||
connect(ui->chkLongLineEdge, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorShowLineEdges);
|
||||
connect(ui->chkShowWhitespace, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorShowWhiteSpace);
|
||||
connect(ui->chkAutoCloseChar, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorAutoCloseChar);
|
||||
connect(ui->chkAutoIden, &QCheckBox::toggled, set,
|
||||
&ScriptSettings::setEditorAutoIden);
|
||||
}
|
||||
set.save(m_isConsole ? ScriptSettings::CONSOLE : ScriptSettings::EDITOR);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Reset the subcontrols to reflect the current settings
|
||||
|
||||
The name can be a bit misleading at first, it has been chosen
|
||||
because it directly maps to the effect a "cancel" button would
|
||||
have on the widget
|
||||
*/
|
||||
void QEditConfig::cancel() { reload(); }
|
||||
QEditConfig::~QEditConfig() { delete ui; }
|
||||
|
||||
/*!
|
||||
\brief Restore default values for all subcontrols
|
||||
|
||||
\note The widgets are changed but these changes are NOT applied.
|
||||
*/
|
||||
void QEditConfig::reset() {
|
||||
void QEditConfig::restore() {
|
||||
auto &set = ScriptSettings::instance();
|
||||
set.reset(m_isConsole ? ScriptSettings::CONSOLE : ScriptSettings::EDITOR);
|
||||
reload();
|
||||
|
|
|
@ -40,9 +40,8 @@ public:
|
|||
virtual QIcon categoryIcon() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual void apply() override;
|
||||
virtual void cancel() override;
|
||||
virtual void reset() override;
|
||||
|
||||
virtual void restore() override;
|
||||
|
||||
private:
|
||||
void reload();
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SizeConstraint::SetMinAndMaxSize</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
|
|
|
@ -38,6 +38,83 @@ ScriptSettingDialog::ScriptSettingDialog(QWidget *parent)
|
|||
this, &ScriptSettingDialog::optionNeedRestartChanged);
|
||||
|
||||
loadData();
|
||||
|
||||
connect(ui->listWidget, &QListWidget::itemChanged, this,
|
||||
[this](QListWidgetItem *item) {
|
||||
auto var = item->data(Qt::UserRole);
|
||||
if (var.isValid()) {
|
||||
auto meta = var.value<ScriptManager::ScriptDirMeta>();
|
||||
switch (item->checkState()) {
|
||||
case Qt::Unchecked: {
|
||||
if (meta.isSys) {
|
||||
m_sysHideCats.pushAddItem(meta.rawName);
|
||||
} else {
|
||||
m_usrHideCats.pushAddItem(meta.rawName);
|
||||
}
|
||||
} break;
|
||||
case Qt::Checked: {
|
||||
if (meta.isSys) {
|
||||
m_sysHideCats.pushRemoveItem(meta.rawName);
|
||||
} else {
|
||||
m_usrHideCats.pushRemoveItem(meta.rawName);
|
||||
}
|
||||
} break;
|
||||
case Qt::PartiallyChecked:
|
||||
break;
|
||||
}
|
||||
|
||||
ui->btnSave->setEnabled(containUnsavedChanges());
|
||||
}
|
||||
});
|
||||
|
||||
auto set = &SettingManager::instance();
|
||||
connect(ui->cbEnable, &QCheckBox::toggled, set,
|
||||
&SettingManager::setScriptEnabled);
|
||||
connect(ui->cbAllowUsrScript, &QCheckBox::toggled, set,
|
||||
&SettingManager::setAllowUsrScriptInRoot);
|
||||
connect(ui->sbTimeout, &QSpinBox::valueChanged, set,
|
||||
&SettingManager::setScriptTimeout);
|
||||
|
||||
connect(ui->btnSave, &QPushButton::clicked, this, [this]() {
|
||||
auto &set = SettingManager::instance();
|
||||
set.setUsrHideCats(m_usrHideCats.getContents());
|
||||
set.setSysHideCats(m_sysHideCats.getContents());
|
||||
m_sysHideCats.clear();
|
||||
m_usrHideCats.clear();
|
||||
ui->btnSave->setEnabled(false);
|
||||
Q_EMIT optionNeedRestartChanged();
|
||||
});
|
||||
|
||||
connect(ui->listWidget, &QListWidget::currentRowChanged, this,
|
||||
[this](int currentRow) {
|
||||
if (currentRow < 0) {
|
||||
ui->textBrowser->clear();
|
||||
return;
|
||||
}
|
||||
auto lw = ui->listWidget->item(currentRow);
|
||||
auto var = lw->data(Qt::UserRole);
|
||||
if (var.isValid()) {
|
||||
auto meta = var.value<ScriptManager::ScriptDirMeta>();
|
||||
auto info = ui->textBrowser;
|
||||
info->clear();
|
||||
info->append(tr("RawName:") + meta.rawName);
|
||||
info->append(tr("Name:") + meta.name);
|
||||
info->append(tr("Author:") + meta.author);
|
||||
info->append(tr("License:") + meta.license);
|
||||
info->append(tr("ContextMenu:") +
|
||||
(meta.isContextMenu
|
||||
? QStringLiteral("true")
|
||||
: QStringLiteral("false")));
|
||||
info->append(tr("HomePage:") + meta.homepage);
|
||||
info->append(tr("Comment:"));
|
||||
auto cur = info->textCursor();
|
||||
cur.movePosition(QTextCursor::End);
|
||||
info->setTextCursor(cur);
|
||||
info->insertHtml(meta.comment);
|
||||
}
|
||||
});
|
||||
|
||||
createPluginStandardMenu();
|
||||
}
|
||||
|
||||
ScriptSettingDialog::~ScriptSettingDialog() { delete ui; }
|
||||
|
@ -56,19 +133,26 @@ void ScriptSettingDialog::loadData() {
|
|||
auto &sm = ScriptManager::instance();
|
||||
auto usrCats = sm.usrScriptsDbCats();
|
||||
auto hidden = set.usrHideCats();
|
||||
|
||||
QStringList buffer;
|
||||
for (auto &cat : usrCats) {
|
||||
if (addCatagory(sm.usrDirMeta(cat), true, hidden.contains(cat))) {
|
||||
m_usrHideCats << cat;
|
||||
buffer.append(cat);
|
||||
}
|
||||
}
|
||||
_usrHideCats = buffer;
|
||||
m_usrHideCats.setContents(buffer);
|
||||
|
||||
buffer.clear();
|
||||
auto sysCats = sm.sysScriptsDbCats();
|
||||
hidden = set.sysHideCats();
|
||||
for (auto &cat : sysCats) {
|
||||
if (addCatagory(sm.sysDirMeta(cat), false, hidden.contains(cat))) {
|
||||
m_sysHideCats << cat;
|
||||
buffer.append(cat);
|
||||
}
|
||||
}
|
||||
_sysHideCats = buffer;
|
||||
m_sysHideCats.setContents(buffer);
|
||||
} else {
|
||||
ui->groupBox_2->setEnabled(false);
|
||||
}
|
||||
|
@ -82,7 +166,33 @@ bool ScriptSettingDialog::addCatagory(const ScriptManager::ScriptDirMeta &meta,
|
|||
meta.name, ui->listWidget);
|
||||
lw->setData(Qt::UserRole, QVariant::fromValue(meta));
|
||||
lw->setCheckState(hidden ? Qt::Unchecked : Qt::Checked);
|
||||
return !hidden;
|
||||
return hidden;
|
||||
}
|
||||
|
||||
void ScriptSettingDialog::createPluginStandardMenu() {
|
||||
auto widget = ui->listWidget;
|
||||
widget->setSelectionMode(QListWidget::ExtendedSelection);
|
||||
widget->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
widget->addAction(tr("SelectShow"), widget, [widget]() {
|
||||
for (auto &item : widget->selectedItems()) {
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
});
|
||||
widget->addAction(tr("SelectHide"), widget, [widget]() {
|
||||
for (auto &item : widget->selectedItems()) {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
});
|
||||
auto a = new QAction(widget);
|
||||
a->setSeparator(true);
|
||||
widget->addAction(a);
|
||||
widget->addAction(tr("SelectAll"), widget, &QListWidget::selectAll);
|
||||
widget->addAction(tr("SelectClear"), widget, &QListWidget::clearSelection);
|
||||
a = new QAction(widget);
|
||||
a->setSeparator(true);
|
||||
widget->addAction(a);
|
||||
widget->addAction(tr("DiscardChanges"), this,
|
||||
&ScriptSettingDialog::discard);
|
||||
}
|
||||
|
||||
QIcon ScriptSettingDialog::categoryIcon() const { return ICONRES("script"); }
|
||||
|
@ -91,75 +201,40 @@ QString ScriptSettingDialog::name() const { return tr("Script"); }
|
|||
|
||||
QString ScriptSettingDialog::id() const { return QStringLiteral("Script"); }
|
||||
|
||||
void ScriptSettingDialog::apply() {
|
||||
QStringList usrHideCats;
|
||||
QStringList sysHideCats;
|
||||
|
||||
auto total = ui->listWidget->count();
|
||||
for (int i = 0; i < total; ++i) {
|
||||
auto lw = ui->listWidget->item(i);
|
||||
auto var = lw->data(Qt::UserRole);
|
||||
if (var.isValid()) {
|
||||
auto meta = var.value<ScriptManager::ScriptDirMeta>();
|
||||
if (lw->checkState() == Qt::Unchecked) {
|
||||
if (meta.isSys) {
|
||||
sysHideCats << meta.rawName;
|
||||
} else {
|
||||
usrHideCats << meta.rawName;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool ScriptSettingDialog::containUnsavedChanges() const {
|
||||
return m_usrHideCats.containChanges() || m_sysHideCats.containChanges();
|
||||
}
|
||||
|
||||
auto &set = SettingManager::instance();
|
||||
set.setScriptEnabled(ui->cbEnable->isChecked());
|
||||
set.setAllowUsrScriptInRoot(ui->cbAllowUsrScript->isChecked());
|
||||
set.setScriptTimeout(ui->sbTimeout->value());
|
||||
set.setUsrHideCats(usrHideCats);
|
||||
set.setSysHideCats(sysHideCats);
|
||||
set.save(SettingManager::SCRIPT);
|
||||
|
||||
m_usrHideCats = usrHideCats;
|
||||
m_sysHideCats = sysHideCats;
|
||||
}
|
||||
|
||||
void ScriptSettingDialog::reset() {
|
||||
void ScriptSettingDialog::restore() {
|
||||
auto &set = SettingManager::instance();
|
||||
set.reset(SettingManager::SCRIPT);
|
||||
loadData();
|
||||
}
|
||||
|
||||
void ScriptSettingDialog::cancel() { loadData(); }
|
||||
void ScriptSettingDialog::discard() {
|
||||
m_usrHideCats.setContents(_usrHideCats);
|
||||
m_sysHideCats.setContents(_sysHideCats);
|
||||
|
||||
void ScriptSettingDialog::on_btnRefresh_clicked() {
|
||||
ui->listWidget->clear();
|
||||
ScriptManager::instance().refresh();
|
||||
loadData();
|
||||
}
|
||||
|
||||
void ScriptSettingDialog::on_listWidget_currentRowChanged(int currentRow) {
|
||||
if (currentRow < 0) {
|
||||
ui->textBrowser->clear();
|
||||
return;
|
||||
}
|
||||
auto lw = ui->listWidget->item(currentRow);
|
||||
auto var = lw->data(Qt::UserRole);
|
||||
ui->listWidget->blockSignals(true);
|
||||
for (int i = 0; i < ui->listWidget->count(); ++i) {
|
||||
auto item = ui->listWidget->item(i);
|
||||
auto var = item->data(Qt::UserRole);
|
||||
if (var.isValid()) {
|
||||
auto meta = var.value<ScriptManager::ScriptDirMeta>();
|
||||
auto info = ui->textBrowser;
|
||||
info->clear();
|
||||
info->append(tr("RawName:") + meta.rawName);
|
||||
info->append(tr("Name:") + meta.name);
|
||||
info->append(tr("Author:") + meta.author);
|
||||
info->append(tr("License:") + meta.license);
|
||||
info->append(tr("ContextMenu:") + (meta.isContextMenu
|
||||
? QStringLiteral("true")
|
||||
: QStringLiteral("false")));
|
||||
info->append(tr("HomePage:") + meta.homepage);
|
||||
info->append(tr("Comment:"));
|
||||
auto cur = info->textCursor();
|
||||
cur.movePosition(QTextCursor::End);
|
||||
info->setTextCursor(cur);
|
||||
info->insertHtml(meta.comment);
|
||||
if (meta.isSys) {
|
||||
if (_sysHideCats.contains(meta.rawName)) {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
} else {
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
} else {
|
||||
if (_usrHideCats.contains(meta.rawName)) {
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
} else {
|
||||
item->setCheckState(Qt::Checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ui->listWidget->blockSignals(false);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define SCRIPTSETTINGDIALOG_H
|
||||
|
||||
#include "WingPlugin/settingpage.h"
|
||||
#include "class/changedstringlist.h"
|
||||
#include "class/scriptmanager.h"
|
||||
#include <QWidget>
|
||||
|
||||
|
@ -36,26 +37,28 @@ public:
|
|||
private:
|
||||
Ui::ScriptSettingDialog *ui;
|
||||
|
||||
QStringList m_usrHideCats;
|
||||
QStringList m_sysHideCats;
|
||||
QStringList _usrHideCats;
|
||||
QStringList _sysHideCats;
|
||||
|
||||
ChangedStringList m_usrHideCats;
|
||||
ChangedStringList m_sysHideCats;
|
||||
|
||||
private:
|
||||
void loadData();
|
||||
bool addCatagory(const ScriptManager::ScriptDirMeta &meta, bool isUser,
|
||||
bool hidden);
|
||||
|
||||
void createPluginStandardMenu();
|
||||
|
||||
// SettingPage interface
|
||||
public:
|
||||
virtual QIcon categoryIcon() const override;
|
||||
virtual QString name() const override;
|
||||
virtual QString id() const override;
|
||||
virtual void apply() override;
|
||||
virtual void reset() override;
|
||||
virtual void cancel() override;
|
||||
|
||||
private slots:
|
||||
void on_btnRefresh_clicked();
|
||||
void on_listWidget_currentRowChanged(int currentRow);
|
||||
virtual bool containUnsavedChanges() const override;
|
||||
virtual void restore() override;
|
||||
virtual void discard() override;
|
||||
};
|
||||
|
||||
#endif // SCRIPTSETTINGDIALOG_H
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
|
@ -118,9 +130,12 @@
|
|||
<widget class="QTextBrowser" name="textBrowser"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRefresh">
|
||||
<widget class="QPushButton" name="btnSave">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Refresh</string>
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -45,8 +45,8 @@ QToolTip
|
|||
/* 0.2ex is the smallest value that's not ignored on Windows. */
|
||||
border: 0.04em solid #eff0f1;
|
||||
background-image: none;
|
||||
background-color: #31363b;
|
||||
alternate-background-color: #31363b;
|
||||
background-color: #202326;
|
||||
alternate-background-color: #202326;
|
||||
color: #eff0f1;
|
||||
padding: 0.1em;
|
||||
opacity: 200;
|
||||
|
@ -55,7 +55,7 @@ QToolTip
|
|||
QWidget
|
||||
{
|
||||
color: #eff0f1;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
selection-background-color: #3daee9;
|
||||
selection-color: #eff0f1;
|
||||
background-clip: border;
|
||||
|
@ -137,7 +137,7 @@ QWidget
|
|||
QWidget:disabled
|
||||
{
|
||||
color: #454545;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
}
|
||||
|
||||
QCheckBox
|
||||
|
@ -181,7 +181,7 @@ QGroupBox::title
|
|||
top: -1.6em;
|
||||
subcontrol-origin: content;
|
||||
subcontrol-position: top center;
|
||||
background: #31363b;
|
||||
background: #202326;
|
||||
padding-left: 0.2em;
|
||||
padding-right: 0.2em;
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ QRadioButton::indicator:unchecked:disabled
|
|||
|
||||
QMenuBar
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
color: #eff0f1;
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ QMenu::item:selected
|
|||
|
||||
QMenu::item:selected:disabled
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
}
|
||||
|
||||
QMenu::item:disabled
|
||||
|
@ -476,9 +476,9 @@ QMenu::right-arrow:disabled
|
|||
|
||||
QAbstractItemView
|
||||
{
|
||||
alternate-background-color: #31363b;
|
||||
alternate-background-color: #202326;
|
||||
color: #eff0f1;
|
||||
border: 0.09em solid #31363b;
|
||||
border: 0.09em solid #202326;
|
||||
border-radius: 0.09em;
|
||||
}
|
||||
|
||||
|
@ -513,7 +513,7 @@ QAbstractScrollArea
|
|||
*/
|
||||
QAbstractScrollArea::corner
|
||||
{
|
||||
background: #31363b;
|
||||
background: #202326;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -735,7 +735,7 @@ QFrame[frameShape="6"] /* QFrame::StyledPanel == 0x0006 */
|
|||
border-width: 0.04em;
|
||||
padding: 0.09em;
|
||||
border-style: solid;
|
||||
border-color: #31363b;
|
||||
border-color: #202326;
|
||||
background-color: #76797c;
|
||||
border-radius: 0.23em;
|
||||
}
|
||||
|
@ -842,7 +842,7 @@ QDialog QToolBar QToolButton[popupMode="2"]
|
|||
QPushButton
|
||||
{
|
||||
color: #eff0f1;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border: 0.04em solid #76797c;
|
||||
padding: 0.23em;
|
||||
border-radius: 0.09em;
|
||||
|
@ -872,7 +872,7 @@ QPushButton:closed
|
|||
|
||||
QPushButton:disabled
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border-width: 0.04em;
|
||||
border-color: #76797c;
|
||||
border-style: solid;
|
||||
|
@ -919,7 +919,7 @@ QPushButton:checked
|
|||
|
||||
QPushButton:hover
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border: 0.04em solid #3daee9;
|
||||
color: #eff0f1;
|
||||
}
|
||||
|
@ -958,12 +958,12 @@ QPlainTextEdit:hover:pressed,
|
|||
QAbstractView:hover:pressed,
|
||||
QTreeView:hover:pressed
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
}
|
||||
|
||||
QColumnView
|
||||
{
|
||||
border: 0.04em transparent #31363b;
|
||||
border: 0.04em transparent #202326;
|
||||
}
|
||||
|
||||
QColumnViewGrip
|
||||
|
@ -1365,7 +1365,7 @@ QTabBar::tab:top:only-one
|
|||
border-left: 0.04em solid #76797c;
|
||||
border-right: 0.04em solid #76797c;
|
||||
border-top: 0.09em solid #3daee9;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
padding: 0.23em;
|
||||
min-width: 50px;
|
||||
border-radius: 0.09em;
|
||||
|
@ -1376,7 +1376,7 @@ QTabBar::tab:top:only-one
|
|||
QTabBar::tab:top:!selected
|
||||
{
|
||||
color: #eff0f1;
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
border: 0.04em transparent black;
|
||||
border-right: 0.04em solid #76797c;
|
||||
border-bottom: 0.04em solid #76797c;
|
||||
|
@ -1418,7 +1418,7 @@ QTabBar::tab:bottom:only-one
|
|||
border-left: 0.04em solid #76797c;
|
||||
border-right: 0.04em solid #76797c;
|
||||
border-bottom: 0.09em solid #3daee9;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
padding: 0.23em;
|
||||
min-width: 50px;
|
||||
border-radius: 0.09em;
|
||||
|
@ -1429,7 +1429,7 @@ QTabBar::tab:bottom:only-one
|
|||
QTabBar::tab:bottom:!selected
|
||||
{
|
||||
color: #eff0f1;
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
border: 0.04em transparent black;
|
||||
border-top: 0.04em solid #76797c;
|
||||
border-right: 0.04em solid #76797c;
|
||||
|
@ -1471,7 +1471,7 @@ QTabBar::tab:left:only-one
|
|||
border-top: 0.09em solid #3daee9;
|
||||
border-bottom: 0.04em solid #76797c;
|
||||
border-left: 0.04em solid #76797c;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
padding: 0.23em;
|
||||
min-height: 50px;
|
||||
border-radius: 0.09em;
|
||||
|
@ -1482,7 +1482,7 @@ QTabBar::tab:left:only-one
|
|||
QTabBar::tab:left:!selected
|
||||
{
|
||||
color: #eff0f1;
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
border: 0.04em transparent black;
|
||||
border-top: 0.04em solid #76797c;
|
||||
border-right: 0.04em solid #76797c;
|
||||
|
@ -1524,7 +1524,7 @@ QTabBar::tab:right:only-one
|
|||
border-top: 0.09em solid #3daee9;
|
||||
border-bottom: 0.04em solid #76797c;
|
||||
border-right: 0.04em solid #76797c;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
padding: 0.23em;
|
||||
min-height: 50px;
|
||||
border-radius: 0.09em;
|
||||
|
@ -1535,7 +1535,7 @@ QTabBar::tab:right:only-one
|
|||
QTabBar::tab:right:!selected
|
||||
{
|
||||
color: #eff0f1;
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
border: 0.04em transparent black;
|
||||
border-top: 0.04em solid #76797c;
|
||||
border-left: 0.04em solid #76797c;
|
||||
|
@ -1594,7 +1594,7 @@ QTabBar[shape="7"]::tab:only-one
|
|||
{
|
||||
/* Need a dark color without alpha channel since it affects the text. */
|
||||
color: #3daee9;
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
padding: 0.23em;
|
||||
}
|
||||
|
||||
|
@ -1624,7 +1624,7 @@ QTabBar[shape="6"]::tab:!selected,
|
|||
QTabBar[shape="7"]::tab:!selected
|
||||
{
|
||||
color: #eff0f1;
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1675,7 +1675,7 @@ QTabBar[shape="7"]::close-button
|
|||
|
||||
QDockWidget
|
||||
{
|
||||
background: #31363b;
|
||||
background: #202326;
|
||||
/**
|
||||
* It doesn't seem possible to change the border of the
|
||||
* QDockWidget without changing the content margins.
|
||||
|
@ -1899,7 +1899,7 @@ QSlider::groove:horizontal,
|
|||
QSlider::groove:vertical
|
||||
{
|
||||
background: #2c3034;
|
||||
border: 0em solid #31363b;
|
||||
border: 0em solid #202326;
|
||||
border-radius: 0.19em;
|
||||
}
|
||||
|
||||
|
@ -2003,14 +2003,14 @@ QDialog QToolBar QToolButton[hasMenu="false"][popupMode="2"]
|
|||
|
||||
QToolButton[autoRaise="false"]
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border: 0.04em solid #76797c;
|
||||
border-radius: 0.09em;
|
||||
}
|
||||
|
||||
QToolButton[autoRaise="true"]
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border: 0.04em solid transparent;
|
||||
}
|
||||
|
||||
|
@ -2164,7 +2164,7 @@ QToolButton::menu-button:pressed
|
|||
QTableView
|
||||
{
|
||||
border: 0em solid black;
|
||||
gridline-color: #31363b;
|
||||
gridline-color: #202326;
|
||||
background-color: #1d2023;
|
||||
}
|
||||
|
||||
|
@ -2220,7 +2220,7 @@ QAbstractItemView::item:selected:hover
|
|||
|
||||
QHeaderView
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border: 0.04em transparent;
|
||||
border-radius: 0em;
|
||||
margin: 0em;
|
||||
|
@ -2229,7 +2229,7 @@ QHeaderView
|
|||
|
||||
QHeaderView::section
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border: 0.04em solid #76797c;
|
||||
color: #eff0f1;
|
||||
border-radius: 0em;
|
||||
|
@ -2317,7 +2317,7 @@ QHeaderView::up-arrow
|
|||
|
||||
QTableView QTableCornerButton::section
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border: 0.04em transparent #76797c;
|
||||
border-top: 0.04em solid #76797c;
|
||||
border-left: 0.04em solid #76797c;
|
||||
|
@ -2357,7 +2357,7 @@ QToolBox::tab:hover
|
|||
QSplitter::handle
|
||||
{
|
||||
border: 0.09em solid #2c3034;
|
||||
background: -0.5em solid #2c3034;
|
||||
background: -0.5em solid #202326;
|
||||
max-width: 0em;
|
||||
max-height: 0em;
|
||||
}
|
||||
|
@ -2372,7 +2372,7 @@ QProgressBar:horizontal,
|
|||
QProgressBar:vertical
|
||||
{
|
||||
background-color: #626568;
|
||||
border: 0.9em solid #31363b;
|
||||
border: 0.9em solid #202326;
|
||||
border-radius: 0.13em;
|
||||
padding: 0em;
|
||||
}
|
||||
|
@ -2462,7 +2462,7 @@ QMessageBox QPushButton
|
|||
QWidget[isTitlebar="true"],
|
||||
QWidget[isTitlebar="true"] *
|
||||
{
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2542,7 +2542,7 @@ QFrame[frameShape][isWindow="true"][windowFrame="5"]
|
|||
ads--CAutoHideDockContainer #dockAreaAutoHideButton
|
||||
{
|
||||
qproperty-icon: url(:/dark/transparent.svg);
|
||||
background: #31363b;
|
||||
background: #202326;
|
||||
width: 1.2em;
|
||||
height: 1.2em;
|
||||
padding: 0em;
|
||||
|
@ -2570,7 +2570,7 @@ ads--CAutoHideDockContainer #dockAreaAutoHideButton
|
|||
#floatingTitleCloseButton:pressed,
|
||||
#floatingTitleMaximizeButton:pressed
|
||||
{
|
||||
background: #31363b;
|
||||
background: #202326;
|
||||
}
|
||||
|
||||
#tabCloseButton,
|
||||
|
@ -2713,7 +2713,7 @@ ads--CDockWidgetTab
|
|||
{
|
||||
border: 0.04em solid #76797c;
|
||||
border-top: 0.09em solid #76797c;
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
padding: 0.1em;
|
||||
min-width: 30px;
|
||||
border-radius: 0.09em;
|
||||
|
@ -2723,7 +2723,7 @@ ads--CDockWidgetTab
|
|||
|
||||
ads--CDockWidgetTab[activeTab="true"][focused="true"]
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border-top: 0.09em solid #3de9e3;
|
||||
border-left: 0.04em solid #76797c;
|
||||
border-right: 0.04em solid #3de9e3;
|
||||
|
@ -2732,7 +2732,7 @@ ads--CDockWidgetTab[activeTab="true"][focused="true"]
|
|||
|
||||
ads--CDockWidgetTab[activeTab="true"]
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
border-top: 0.09em solid #3daee9;
|
||||
border-left: 0.04em solid #76797c;
|
||||
border-right: 0.04em solid #76797c;
|
||||
|
@ -2741,12 +2741,12 @@ ads--CDockWidgetTab[activeTab="true"]
|
|||
|
||||
ads--CDockWidgetTab QLabel
|
||||
{
|
||||
background-color: #2c3034;
|
||||
background-color: #1b1d20;
|
||||
}
|
||||
|
||||
ads--CDockWidgetTab[activeTab="true"] QLabel
|
||||
{
|
||||
background-color: #31363b;
|
||||
background-color: #202326;
|
||||
}
|
||||
|
||||
ads--CDockContainerWidget > QSplitter{
|
||||
|
@ -2942,7 +2942,7 @@ RibbonButtonGroup QFrame[frameShape="5"]:hover
|
|||
border-width: 0.04em;
|
||||
padding: 0.09em;
|
||||
border-style: solid;
|
||||
border-color: #31363b;
|
||||
border-color: #202326;
|
||||
background-color: #76797c;
|
||||
border-radius: 0.23em;
|
||||
}
|
||||
|
@ -2950,7 +2950,7 @@ RibbonButtonGroup QFrame[frameShape="5"]:hover
|
|||
QHexView
|
||||
{
|
||||
qproperty-bytesColor: #eff0f1;
|
||||
qproperty-bytesBackground: #31363b;
|
||||
qproperty-bytesBackground: #202326;
|
||||
qproperty-bytesAlterBackground: #2C3136;
|
||||
qproperty-selectionColor: #eff0f1;
|
||||
qproperty-selBackgroundColor: #3daee9;
|
||||
|
|
Loading…
Reference in New Issue