work save

This commit is contained in:
Roy Qu 2022-09-25 16:07:52 +08:00
parent a727929e88
commit 6f4b24c753
48 changed files with 291 additions and 102 deletions

View File

@ -82,10 +82,6 @@ SOURCES += \
project.cpp \
projectoptions.cpp \
projecttemplate.cpp \
qsynedit/Search.cpp \
qsynedit/SearchBase.cpp \
qsynedit/SearchRegex.cpp \
qsynedit/Types.cpp \
settingsdialog/compilerautolinkwidget.cpp \
settingsdialog/debuggeneralwidget.cpp \
settingsdialog/editorautosavewidget.cpp \
@ -139,22 +135,6 @@ SOURCES += \
iconsmanager.cpp \
main.cpp \
mainwindow.cpp \
qsynedit/CodeFolding.cpp \
qsynedit/Constants.cpp \
qsynedit/KeyStrokes.cpp \
qsynedit/MiscClasses.cpp \
qsynedit/MiscProcs.cpp \
qsynedit/SynEdit.cpp \
qsynedit/TextBuffer.cpp \
qsynedit/TextPainter.cpp \
qsynedit/exporter/synexporter.cpp \
qsynedit/exporter/synhtmlexporter.cpp \
qsynedit/exporter/synrtfexporter.cpp \
qsynedit/highlighter/asm.cpp \
qsynedit/highlighter/base.cpp \
qsynedit/highlighter/composition.cpp \
qsynedit/highlighter/cpp.cpp \
qsynedit/highlighter/glsl.cpp \
settingsdialog/compilersetdirectorieswidget.cpp \
settingsdialog/compilersetoptionwidget.cpp \
settings.cpp \
@ -233,9 +213,6 @@ HEADERS += \
project.h \
projectoptions.h \
projecttemplate.h \
qsynedit/Search.h \
qsynedit/SearchBase.h \
qsynedit/SearchRegex.h \
settingsdialog/compilerautolinkwidget.h \
settingsdialog/debuggeneralwidget.h \
settingsdialog/editorautosavewidget.h \
@ -288,23 +265,6 @@ HEADERS += \
editorlist.h \
iconsmanager.h \
mainwindow.h \
qsynedit/CodeFolding.h \
qsynedit/Constants.h \
qsynedit/KeyStrokes.h \
qsynedit/MiscClasses.h \
qsynedit/MiscProcs.h \
qsynedit/SynEdit.h \
qsynedit/TextBuffer.h \
qsynedit/TextPainter.h \
qsynedit/Types.h \
qsynedit/exporter/synexporter.h \
qsynedit/exporter/synhtmlexporter.h \
qsynedit/exporter/synrtfexporter.h \
qsynedit/highlighter/asm.h \
qsynedit/highlighter/base.h \
qsynedit/highlighter/composition.h \
qsynedit/highlighter/cpp.h \
qsynedit/highlighter/glsl.h \
settingsdialog/compilersetdirectorieswidget.h \
settingsdialog/compilersetoptionwidget.h \
settings.h \
@ -515,9 +475,9 @@ RESOURCES += colorscheme_files
macos: {
# Add needed executables into the main app bundle
bundled_executable.files = \
$$OUT_PWD/../astyle/astyle \
$$OUT_PWD/../consolepauser/consolepauser \
$$OUT_PWD/../redpanda-git-askpass/redpanda-git-askpass.app/Contents/MacOS/redpanda-git-askpass
$$OUT_PWD/../tools/astyle/astyle \
$$OUT_PWD/../tools/consolepauser/consolepauser \
$$OUT_PWD/../tools/redpanda-git-askpass/redpanda-git-askpass.app/Contents/MacOS/redpanda-git-askpass
bundled_executable.path = Contents/MacOS
# Also bundled templates

View File

@ -2,23 +2,24 @@ TEMPLATE = subdirs
SUBDIRS += \
RedPandaIDE \
tools\astyle \
tools\consolepauser
tools/astyle \
tools/consolepauser
libs/qsynedit
# Add the dependencies so that the RedPandaIDE project can add the depended programs
# into the main app bundle
RedPandaIDE.depends = tools\astyle tools\consolepauser
RedPandaIDE.depends = tools/astyle tools/consolepauser libs/qsynedit
win32: {
SUBDIRS += \
tools\redpanda-win-git-askpass
RedPandaIDE.depends += tools\redpanda-win-git-askpass
tools/redpanda-win-git-askpass
RedPandaIDE.depends += tools/redpanda-win-git-askpass
}
unix: {
SUBDIRS += \
tools\redpanda-git-askpass
RedPandaIDE.depends += tools\redpanda-git-askpass
tools/redpanda-git-askpass
RedPandaIDE.depends += tools/redpanda-git-askpass
}
APP_NAME = RedPandaCPP

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "KeyStrokes.h"
#include "MiscProcs.h"
namespace QSynedit {
SynEditKeyStroke::SynEditKeyStroke()

View File

@ -17,10 +17,10 @@
#ifndef SYNEDITKEYSTROKE_H
#define SYNEDITKEYSTROKE_H
#include "../utils.h"
#include <QKeySequence>
#include <QList>
#include <memory>
#include "MiscClasses.h"
namespace QSynedit {
//****************************************************************************

View File

@ -16,7 +16,9 @@
*/
#include "MiscClasses.h"
#include "algorithm"
namespace QSynedit {
SynGutter::SynGutter(QObject *parent):
QObject(parent)
{
@ -334,4 +336,26 @@ void SynGutter::setBorderColor(const QColor &value)
}
}
BaseError::BaseError(const QString &reason):
mReason(reason)
{
}
QString BaseError::reason() const
{
return mReason;
}
IndexOutOfRange::IndexOutOfRange(int Index):
BaseError(QObject::tr("Index %1 out of range").arg(Index))
{
}
FileError::FileError(const QString &reason): BaseError(reason)
{
}
}

View File

@ -24,6 +24,25 @@
namespace QSynedit {
class BaseError{
public:
explicit BaseError(const QString& reason) ;
QString reason() const;
protected:
QString mReason;
};
class IndexOutOfRange:public BaseError {
public:
explicit IndexOutOfRange(int Index);
};
class FileError: public BaseError {
public:
explicit FileError(const QString& reason);
};
enum class SynGutterBorderStyle {
None,
Middle,

View File

@ -19,6 +19,8 @@
#include <QPainter>
#include <QTextStream>
#include <algorithm>
#include <QApplication>
#include <QScreen>
namespace QSynedit {
int minMax(int x, int mi, int ma)
@ -27,35 +29,6 @@ int minMax(int x, int mi, int ma)
return std::max( x, mi );
}
bool IsPowerOfTwo(int TabWidth) {
if (TabWidth<2)
return false;
int nW = 2;
do {
if (nW >= TabWidth)
break;
nW <<= 1;
} while (nW<0x10000);
return (nW == TabWidth);
}
bool GetHasTabs(const QString &line, int &CharsBefore)
{
bool result = false;
CharsBefore = 0;
if (!line.isEmpty()) {
for (const QChar& ch:line) {
if (ch == '\t') {
result = true;
break;
}
CharsBefore ++;
}
}
return result;
}
int getEOL(const QString &Line, int start)
{
if (start<0 || start>=Line.size()) {
@ -69,7 +42,7 @@ int getEOL(const QString &Line, int start)
return Line.size();
}
bool InternalEnumHighlighterAttris(PSynHighlighter Highlighter,
bool internalEnumHighlighterAttris(PSynHighlighter Highlighter,
bool SkipDuplicates,
HighlighterAttriProc highlighterAttriProc,
std::initializer_list<void *>& Params,
@ -106,7 +79,7 @@ bool enumHighlighterAttributes(PSynHighlighter Highlighter, bool SkipDuplicates,
}
SynHighlighterList HighlighterList;
return InternalEnumHighlighterAttris(Highlighter, SkipDuplicates,
return internalEnumHighlighterAttris(Highlighter, SkipDuplicates,
highlighterAttriProc, Params, HighlighterList);
}
@ -228,4 +201,68 @@ int calSpanLines(const BufferCoord &startPos, const BufferCoord &endPos)
return std::abs(endPos.line - startPos.line+1);
}
void decodeKey(const int combinedKey, int &key, Qt::KeyboardModifiers &modifiers)
{
modifiers = Qt::NoModifier;
if (combinedKey & Qt::ShiftModifier) {
modifiers|=Qt::ShiftModifier;
}
if (combinedKey & Qt::ControlModifier) {
modifiers|=Qt::ControlModifier;
}
if (combinedKey & Qt::AltModifier) {
modifiers|=Qt::AltModifier;
}
if (combinedKey & Qt::MetaModifier) {
modifiers|=Qt::MetaModifier;
}
if (combinedKey & Qt::KeypadModifier) {
modifiers|= Qt::KeypadModifier;
}
key = combinedKey & ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier);
}
float pointToPixel(float point)
{
return point * screenDPI() / 72;
}
float pixelToPoint(float pixel)
{
return pixel * 72 / screenDPI();
}
float pointToPixel(float point, float dpi)
{
return point * dpi / 72;
}
static int defaultScreenDPI = -1;
int screenDPI()
{
if (defaultScreenDPI<1) {
defaultScreenDPI = qApp->primaryScreen()->logicalDotsPerInch();
}
return defaultScreenDPI;
}
void setScreenDPI(int dpi)
{
defaultScreenDPI = dpi;
}
void inflateRect(QRect &rect, int delta)
{
inflateRect(rect,delta,delta);
}
void inflateRect(QRect &rect, int dx, int dy)
{
rect.setLeft(rect.left()-dx);
rect.setRight(rect.right()+dx);
rect.setTop(rect.top()-dy);
rect.setBottom(rect.bottom()+dy);
}
}

View File

@ -91,6 +91,58 @@ void ensureNotAfter(BufferCoord& cord1, BufferCoord& cord2);
bool isWordChar(const QChar& ch);
void decodeKey(int combinedKey, int& key, Qt::KeyboardModifiers& modifiers);
int screenDPI();
void setScreenDPI(int dpi);
float pointToPixel(float point);
float pointToPixel(float point, float dpi);
float pixelToPoint(float pixel);
void inflateRect(QRect& rect, int delta);
void inflateRect(QRect& rect, int dx, int dy);
/**
* from https://github.com/Microsoft/GSL
**/
template <class F>
class final_action
{
public:
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
!std::is_volatile<F>::value,
"Final_action should store its callable by value");
explicit final_action(F f) noexcept : f_(std::move(f)) {}
final_action(final_action&& other) noexcept
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
{}
final_action(const final_action&) = delete;
final_action& operator=(const final_action&) = delete;
final_action& operator=(final_action&&) = delete;
~final_action() noexcept
{
if (invoke_) f_();
}
private:
F f_;
bool invoke_{true};
};
template <class F> final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
finally(F&& f) noexcept
{
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
std::forward<F>(f));
}
}
#endif // MISCPROCS_H

View File

@ -22,8 +22,6 @@
#include <QMutexLocker>
#include <stdexcept>
#include "SynEdit.h"
#include "../utils.h"
#include "../platform.h"
#include <QMessageBox>
#include <cmath>

View File

@ -25,7 +25,6 @@
#include <memory>
#include <QFile>
#include "MiscProcs.h"
#include "../utils.h"
#include "Types.h"
namespace QSynedit {

View File

@ -22,7 +22,6 @@
#include <QString>
#include "Types.h"
#include "highlighter/base.h"
#include "../utils.h"
#include "MiscClasses.h"
namespace QSynedit {

View File

@ -24,6 +24,19 @@
namespace QSynedit {
#define ENCODING_AUTO_DETECT "AUTO"
#define ENCODING_UTF8 "UTF-8"
#define ENCODING_UTF8_BOM "UTF-8 BOM"
#define ENCODING_SYSTEM_DEFAULT "SYSTEM"
#define ENCODING_ASCII "ASCII"
enum class FileEndingType {
Windows,
Linux,
Mac
};// Windows: CRLF, UNIX: LF, Mac: CR
enum class SynSelectionMode {Normal, Line, Column};
struct BufferCoord {

View File

@ -21,11 +21,10 @@
#include <QGuiApplication>
#include <QMimeData>
#include <QTextCodec>
#include "../../platform.h"
namespace QSynedit {
SynExporter::SynExporter()
SynExporter::SynExporter(const QByteArray charset):mCharset(charset)
{
mClipboardFormat = "text/plain";
mFont = QGuiApplication::font();
@ -33,7 +32,6 @@ SynExporter::SynExporter()
mForegroundColor = QGuiApplication::palette().color(QPalette::Text);
mUseBackground = false;
mExportAsText = false;
mCharset = pCharsetInfoManager->getDefaultSystemEncoding();
mFileEndingType = FileEndingType::Windows;
clear();
setTitle("");

View File

@ -27,7 +27,7 @@ class SynExporter
{
public:
explicit SynExporter();
explicit SynExporter(const QByteArray charset);
/**
* @brief Clears the output buffer and any internal data that relates to the last

View File

@ -20,7 +20,8 @@
namespace QSynedit {
SynHTMLExporter::SynHTMLExporter(int tabSize)
SynHTMLExporter::SynHTMLExporter(int tabSize,const QByteArray charset):
SynExporter(charset)
{
mClipboardFormat = "text/html";
mDefaultFilter = "HTML Documents (*.htm;*.html)|*.htm;*.html";

View File

@ -23,7 +23,7 @@ namespace QSynedit {
class SynHTMLExporter : public SynExporter
{
public:
SynHTMLExporter(int tabSize);
SynHTMLExporter(int tabSize,const QByteArray charset);
bool createHTMLFragment() const;
void setCreateHTMLFragment(bool createHTMLFragment);

View File

@ -17,7 +17,7 @@
#include "synrtfexporter.h"
namespace QSynedit {
SynRTFExporter::SynRTFExporter():SynExporter()
SynRTFExporter::SynRTFExporter(const QByteArray charset):SynExporter(charset)
{
mDefaultFilter = "Rich Text Format Documents (*.rtf)|*.rtf";
mClipboardFormat = "application/x-qt-windows-mime;value=\"Rich Format Text\"";

View File

@ -24,7 +24,7 @@ namespace QSynedit {
class SynRTFExporter : public SynExporter
{
public:
explicit SynRTFExporter();
explicit SynRTFExporter(const QByteArray charset);
private:
bool mAttributesChanged;
QList<QColor> mListColors;

View File

@ -0,0 +1,61 @@
TEMPLATE = lib
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
CONFIG += nokey
win32: {
DEFINES += _WIN32_WINNT=0x0601
}
gcc {
QMAKE_CXXFLAGS_RELEASE += -Werror=return-type
QMAKE_CXXFLAGS_DEBUG += -Werror=return-type
}
msvc {
DEFINES += NOMINMAX
}
SOURCES += CodeFolding.cpp \
Constants.cpp \
KeyStrokes.cpp \
MiscClasses.cpp \
MiscProcs.cpp \
SynEdit.cpp \
TextBuffer.cpp \
TextPainter.cpp \
exporter/synexporter.cpp \
exporter/synhtmlexporter.cpp \
exporter/synrtfexporter.cpp \
highlighter/asm.cpp \
highlighter/base.cpp \
highlighter/composition.cpp \
highlighter/cpp.cpp \
highlighter/glsl.cpp \
Search.cpp \
SearchBase.cpp \
SearchRegex.cpp \
Types.cpp
HEADERS += Search.h \
SearchBase.h \
SearchRegex.h \
CodeFolding.h \
Constants.h \
KeyStrokes.h \
MiscClasses.h \
MiscProcs.h \
SynEdit.h \
TextBuffer.h \
TextPainter.h \
Types.h \
exporter/synexporter.h \
exporter/synhtmlexporter.h \
exporter/synrtfexporter.h \
highlighter/asm.h \
highlighter/base.h \
highlighter/composition.h \
highlighter/cpp.h \
highlighter/glsl.h \

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PLATFORM_H
#define PLATFORM_H
#ifndef QT_UTILS_CHARSETINFO_H
#define QT_UTILS_CHARSETINFO_H
#include <QByteArray>
#include <QString>
#include <memory>

View File

@ -0,0 +1,26 @@
TEMPLATE = lib
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
CONFIG += nokey
win32: {
DEFINES += _WIN32_WINNT=0x0601
}
gcc {
QMAKE_CXXFLAGS_RELEASE += -Werror=return-type
QMAKE_CXXFLAGS_DEBUG += -Werror=return-type
}
msvc {
DEFINES += NOMINMAX
}
SOURCES += redpanda_utils.cpp \
charsetinfo.cpp
HEADERS += redpanda_utils.h \
charsetinfo.h

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef UTILS_H
#define UTILS_H
#ifndef QT_UTILS_UTILS_H
#define QT_UTILS_UTILS_H
#include <type_traits>
#include <utility>
#include <functional>
@ -27,13 +27,13 @@
#include <QProcessEnvironment>
#include "SimpleIni.h"
using SimpleIni = CSimpleIniA;
using PSimpleIni = std::shared_ptr<SimpleIni>;
class QByteArray;
class QTextStream;
class QTextCodec;
using SimpleIni = CSimpleIniA;
using PSimpleIni = std::shared_ptr<SimpleIni>;
#define ENCODING_AUTO_DETECT "AUTO"
#define ENCODING_UTF8 "UTF-8"
#define ENCODING_UTF8_BOM "UTF-8 BOM"