work save

This commit is contained in:
Roy Qu 2022-09-25 17:43:31 +08:00
parent 6f4b24c753
commit 71a728a868
26 changed files with 417 additions and 1301 deletions

View File

@ -17,10 +17,10 @@
#include "HighlighterManager.h"
#include <QFileInfo>
#include <QObject>
#include "qsynedit/highlighter/cpp.h"
#include "qsynedit/highlighter/asm.h"
#include "qsynedit/highlighter/glsl.h"
#include "qsynedit/Constants.h"
#include "highlighter/cpp.h"
#include "highlighter/asm.h"
#include "highlighter/glsl.h"
#include "Constants.h"
#include "colorscheme.h"
HighlighterManager highlighterManager;

View File

@ -16,7 +16,7 @@
*/
#ifndef HIGHLIGHTERMANAGER_H
#define HIGHLIGHTERMANAGER_H
#include "qsynedit/highlighter/base.h"
#include "highlighter/base.h"
class HighlighterManager
{

View File

@ -52,6 +52,8 @@ msvc {
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += ../libs/qsynedit ../libs/redpanda_qt_utils
SOURCES += \
HighlighterManager.cpp \
autolinkmanager.cpp \
@ -65,7 +67,6 @@ SOURCES += \
compiler/runner.cpp \
customfileiconprovider.cpp \
gdbmiresultparser.cpp \
platform.cpp \
compiler/compiler.cpp \
compiler/compilermanager.cpp \
compiler/executablerunner.cpp \
@ -207,7 +208,6 @@ HEADERS += \
parser/cpptokenizer.h \
parser/parserutils.h \
parser/statementmodel.h \
platform.h \
problems/ojproblemset.h \
problems/problemcasevalidator.h \
project.h \

View File

@ -22,7 +22,7 @@
#include <QJsonObject>
#include "utils.h"
#include "settings.h"
#include "qsynedit/Constants.h"
#include "Constants.h"
ColorManager * pColorManager;

View File

@ -18,7 +18,7 @@
#define COLORSCHEME_H
#include <QColor>
#include "qsynedit/highlighter/base.h"
#include "highlighter/base.h"
#include "parser/statementmodel.h"
#define EXT_COLOR_SCHEME ".scheme"

View File

@ -30,7 +30,7 @@
#include "../editorlist.h"
#include "../parser/cppparser.h"
#include "../autolinkmanager.h"
#include "../platform.h"
#include "charsetinfo.h"
#include "../project.h"
#define COMPILE_PROCESS_END "---//END//----"

View File

@ -25,7 +25,7 @@
#include <QMessageBox>
#include <QUuid>
#include "projectcompiler.h"
#include "../platform.h"
#include "charsetinfo.h"
enum RunProgramFlag {
RPF_PAUSE_CONSOLE = 0x0001,

View File

@ -18,7 +18,7 @@
#include "../project.h"
#include "compilermanager.h"
#include "../systemconsts.h"
#include "../platform.h"
#include "charsetinfo.h"
#include "../editor.h"
#include <QDir>

View File

@ -19,7 +19,7 @@
#include <QFile>
#include <QFileInfo>
#include <QTextCodec>
#include "../platform.h"
#include "charsetinfo.h"
StdinCompiler::StdinCompiler(const QString &filename,const QByteArray& encoding, const QString& content,bool silent, bool onlyCheckSyntax):
Compiler(filename,silent, onlyCheckSyntax),

View File

@ -20,7 +20,7 @@
#include <QObject>
#include <utils.h>
#include <QTabWidget>
#include "qsynedit/SynEdit.h"
#include "SynEdit.h"
#include "colorscheme.h"
#include "common.h"
#include "parser/cppparser.h"

View File

@ -21,7 +21,7 @@
#include "editorlist.h"
#include <parser/cppparser.h>
#include "utils.h"
#include "platform.h"
#include "charsetinfo.h"
#include "projecttemplate.h"
#include "systemconsts.h"
#include "iconsmanager.h"

View File

@ -23,8 +23,9 @@
#include <QColor>
#include <QString>
#include <QPair>
#include "qsynedit/SynEdit.h"
#include "SynEdit.h"
#include "compiler/compilerinfo.h"
#include "utils.h"
/**
* use the following command to get gcc's default bin/library folders:

View File

@ -2,24 +2,33 @@ TEMPLATE = subdirs
SUBDIRS += \
RedPandaIDE \
tools/astyle \
tools/consolepauser
libs/qsynedit
astyle \
consolepauser \
redpanda_qt_utils \
qsynedit
astyle.subdir = tools/astyle
consolepauser.subdir = tools/consolepauser
redpanda_qt_utils.subdir = libs/redpanda_qt_utils
qsynedit.subdir = 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 libs/qsynedit
RedPandaIDE.depends = astyle consolepauser qsynedit
qsynedit.depends = redpanda_qt_utils
win32: {
SUBDIRS += \
tools/redpanda-win-git-askpass
RedPandaIDE.depends += tools/redpanda-win-git-askpass
redpanda-win-git-askpass
redpanda-win-git-askpass.subdir = tools/redpanda-win-git-askpass
RedPandaIDE.depends += redpanda-win-git-askpass
}
unix: {
SUBDIRS += \
tools/redpanda-git-askpass
RedPandaIDE.depends += tools/redpanda-git-askpass
redpanda-git-askpass
redpanda-git-askpass.subdir = tools/redpanda-git-askpass
RedPandaIDE.depends += redpanda-git-askpass
}
APP_NAME = RedPandaCPP

View File

@ -21,6 +21,7 @@
#include <QList>
#include <memory>
#include "MiscClasses.h"
#include "redpanda_utils.h"
namespace QSynedit {
//****************************************************************************

View File

@ -336,26 +336,4 @@ 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,25 +24,6 @@
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

@ -201,68 +201,4 @@ 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

@ -90,59 +90,5 @@ int findLastNonWordChar(const QString& s, int startPos);
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

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "TextBuffer.h"
#include "redpanda_utils.h"
#include <QDataStream>
#include <QFile>
#include <QTextCodec>
@ -24,6 +25,8 @@
#include "SynEdit.h"
#include <QMessageBox>
#include <cmath>
#include "charsetinfo.h"
#include <QDebug>
namespace QSynedit {

View File

@ -26,6 +26,7 @@
#include <QFile>
#include "MiscProcs.h"
#include "Types.h"
#include "redpanda_utils.h"
namespace QSynedit {
enum SynEditStringFlag {

View File

@ -24,19 +24,6 @@
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

@ -59,3 +59,6 @@ HEADERS += Search.h \
highlighter/composition.h \
highlighter/cpp.h \
highlighter/glsl.h \
INCLUDEPATH += ../redpanda_qt_utils
LIBS += -lredpand_qt_utils

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "platform.h"
#include "charsetinfo.h"
#include <QObject>
#include <memory>
#include <QMap>

View File

@ -5,6 +5,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
CONFIG += nokey
CONFIG += staticlib
win32: {
DEFINES += _WIN32_WINNT=0x0601

File diff suppressed because it is too large Load Diff

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 QT_UTILS_UTILS_H
#define QT_UTILS_UTILS_H
#ifndef REDPANDA_UTILS_H
#define REDPANDA_UTILS_H
#include <type_traits>
#include <utility>
#include <functional>
@ -25,88 +25,23 @@
#include <memory>
#include <QThread>
#include <QProcessEnvironment>
#include "SimpleIni.h"
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"
#define ENCODING_SYSTEM_DEFAULT "SYSTEM"
#define ENCODING_ASCII "ASCII"
enum class FileType{
CSource, // c source file (.c)
CppSource, // c++ source file (.cpp)
CHeader, // c header (.h)
CppHeader, // c++ header (.hpp)
WindowsResourceSource, // resource source (.res)
Project, //Red Panda C++ Project (.dev)
Text, // text file
Other // any others
};
enum class FileEndingType {
Windows,
Linux,
Mac
};// Windows: CRLF, UNIX: LF, Mac: CR
enum class SearchFileScope {
currentFile,
wholeProject,
openedFiles
};
enum AutoSaveTarget {
astCurrentFile,
astAllOpennedFiles,
astAllProjectFiles
};
enum AutoSaveStrategy {
assOverwrite,
assAppendUnixTimestamp,
assAppendFormatedTimeStamp
};
enum FormatterBraceStyle {
fbsDefault,
fbsAllman,
fbsJava,
fbsKR,
fbsStroustrup,
fbsWitesmith,
fbsVtk,
fbsRatliff,
fbsGNU,
fbsLinux,
fbsHorstmann,
fbs1TBS,
fbsGoogle,
fbsMozilla,
fbsWebkit,
fbsPico,
fbsLisp
};
enum FormatterOperatorAlign {
foaNone,
foaType,
foaMiddle,
foaName
};
enum FormatterIndentType {
fitSpace,
fitTab
};
class BaseError{
public:
explicit BaseError(const QString& reason);
@ -126,54 +61,36 @@ public:
explicit FileError(const QString& reason);
};
typedef void (*LineOutputFunc) (const QString& line);
typedef bool (*CheckAbortFunc) ();
bool isGreenEdition();
const QByteArray GuessTextEncoding(const QByteArray& text);
/* text processing utils */
const QByteArray guessTextEncoding(const QByteArray& text);
bool isTextAllAscii(const QByteArray& text);
bool isTextAllAscii(const QString& text);
QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,
const QByteArray& inputContent = QByteArray(),
bool inheritEnvironment = false,
const QProcessEnvironment& env = QProcessEnvironment() );
void executeFile(const QString& fileName,
const QString& params,
const QString& workingDir,
const QString& tempFile);
bool isNonPrintableAsciiChar(char ch);
bool fileExists(const QString& file);
bool fileExists(const QString& dir, const QString& fileName);
bool directoryExists(const QString& file);
bool removeFile(const QString& filename);
QString includeTrailingPathDelimiter(const QString& path);
QString excludeTrailingPathDelimiter(const QString& path);
FileType getFileType(const QString& filename);
QString changeFileExt(const QString& filename, QString ext);
QString extractRelativePath(const QString& base, const QString& dest);
QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes);
QString genMakePath1(const QString& fileName);
QString genMakePath2(const QString& fileName);
QString getCompiledExecutableName(const QString& filename);
void splitStringArguments(const QString& arguments, QStringList& argumentList);
bool programHasConsole(const QString& filename);
using LineProcessFunc = std::function<void(const QString&)>;
QStringList readStreamToLines(QTextStream* stream);
void readStreamToLines(QTextStream* stream, LineProcessFunc lineFunc);
QStringList textToLines(const QString& text);
void textToLines(const QString& text, LineProcessFunc lineFunc);
QString linesToText(const QStringList& lines);
QString linesToText(const QStringList& lines, const QString& lineBreak="\n");
QList<QByteArray> splitByteArrayToLines(const QByteArray& content);
QString parseMacros(const QString& s);
QString trimRight(const QString& s);
QString trimLeft(const QString& s);
int countLeadingWhitespaceChars(const QString& line);
bool stringIsBlank(const QString& s);
QByteArray toByteArray(const QString& s);
QString fromByteArray(const QByteArray& s);
/* text I/O utils */
QStringList readStreamToLines(QTextStream* stream);
void readStreamToLines(QTextStream* stream, LineProcessFunc lineFunc);
/**
* @brief readFileToLines
@ -183,61 +100,40 @@ QString parseMacros(const QString& s);
*/
QStringList readFileToLines(const QString& fileName, QTextCodec* codec);
QStringList readFileToLines(const QString& fileName);
QByteArray readFileToByteArray(const QString& fileName);
void readFileToLines(const QString& fileName, QTextCodec* codec, LineProcessFunc lineFunc);
QByteArray readFileToByteArray(const QString& fileName);
void stringsToFile(const QStringList& list, const QString& fileName);
void stringToFile(const QString& str, const QString& fileName);
int countLeadingWhitespaceChars(const QString& line);
void decodeKey(int combinedKey, int& key, Qt::KeyboardModifiers& modifiers);
void inflateRect(QRect& rect, int delta);
void inflateRect(QRect& rect, int dx, int dy);
QString trimRight(const QString& s);
QString trimLeft(const QString& s);
bool stringIsBlank(const QString& s);
int compareFileModifiedTime(const QString& filename1, const QString& filename2);
QByteArray getHTTPBody(const QByteArray& content);
bool haveGoodContrast(const QColor& c1, const QColor &c2);
qulonglong stringToHex(const QString& str, bool &isOk);
/* File I/O utils */
bool fileExists(const QString& file);
bool fileExists(const QString& dir, const QString& fileName);
bool directoryExists(const QString& file);
bool removeFile(const QString& filename);
void copyFolder(const QString &fromDir, const QString& toDir);
bool copyFile(const QString &fromFile, const QString& toFile, bool overwrite);
//void changeTheme(const QString& themeName);
bool findComplement(const QString& s,
const QChar& fromToken,
const QChar& toToken,
int& curPos,
int increment);
void logToFile(const QString& s, const QString& filename, bool append=true);
QString includeTrailingPathDelimiter(const QString& path);
QString excludeTrailingPathDelimiter(const QString& path);
QString changeFileExt(const QString& filename, QString ext);
QString localizePath(const QString& path);
QString extractRelativePath(const QString& base, const QString& dest);
QString extractFileName(const QString& fileName);
QString extractFileDir(const QString& fileName);
QString extractFilePath(const QString& filePath);
QString extractAbsoluteFilePath(const QString& filePath);
QString getSizeString(int size);
bool isReadOnly(const QString& filename);
int compareFileModifiedTime(const QString& filename1, const QString& filename2);
QByteArray toByteArray(const QString& s);
QString fromByteArray(const QByteArray& s);
int getNewFileNumber();
enum class SplitProcessCommandQuoteType {
None,
Single,
Double
};
QStringList splitProcessCommand(const QString& cmd);
#ifdef Q_OS_WIN
bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value);
#endif
class CppParser;
void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1);
/* UI utils */
void inflateRect(QRect& rect, int delta);
void inflateRect(QRect& rect, int dx, int dy);
int screenDPI();
void setScreenDPI(int dpi);
@ -245,8 +141,7 @@ float pointToPixel(float point);
float pointToPixel(float point, float dpi);
float pixelToPoint(float pixel);
void copyFolder(const QString &fromDir, const QString& toDir);
bool copyFile(const QString &fromFile, const QString& toFile, bool overwrite);
void decodeKey(int combinedKey, int& key, Qt::KeyboardModifiers& modifiers);
/**