diff --git a/RedPandaIDE/HighlighterManager.h b/RedPandaIDE/HighlighterManager.h index a4b027bf..9f353130 100644 --- a/RedPandaIDE/HighlighterManager.h +++ b/RedPandaIDE/HighlighterManager.h @@ -16,7 +16,7 @@ */ #ifndef HIGHLIGHTERMANAGER_H #define HIGHLIGHTERMANAGER_H -#include "highlighter/base.h" +#include "qsynedit/highlighter/base.h" class HighlighterManager { diff --git a/RedPandaIDE/colorscheme.cpp b/RedPandaIDE/colorscheme.cpp index 39c447d5..e5f7befb 100644 --- a/RedPandaIDE/colorscheme.cpp +++ b/RedPandaIDE/colorscheme.cpp @@ -22,7 +22,7 @@ #include #include "utils.h" #include "settings.h" -#include "Constants.h" +#include "qsynedit/Constants.h" ColorManager * pColorManager; diff --git a/RedPandaIDE/colorscheme.h b/RedPandaIDE/colorscheme.h index 69d4d1a1..1d50b85e 100644 --- a/RedPandaIDE/colorscheme.h +++ b/RedPandaIDE/colorscheme.h @@ -18,7 +18,7 @@ #define COLORSCHEME_H #include -#include "highlighter/base.h" +#include "qsynedit/highlighter/base.h" #include "parser/statementmodel.h" #define EXT_COLOR_SCHEME ".scheme" diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 2cddb4e7..fe515d56 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -30,7 +30,7 @@ #include "../editorlist.h" #include "../parser/cppparser.h" #include "../autolinkmanager.h" -#include "charsetinfo.h" +#include "qt_utils/charsetinfo.h" #include "../project.h" #define COMPILE_PROCESS_END "---//END//----" diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 72906135..06772f3c 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -25,7 +25,7 @@ #include #include #include "projectcompiler.h" -#include "charsetinfo.h" +#include "qt_utils/charsetinfo.h" enum RunProgramFlag { RPF_PAUSE_CONSOLE = 0x0001, diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 079be2c2..0bc52934 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -18,7 +18,7 @@ #include "../project.h" #include "compilermanager.h" #include "../systemconsts.h" -#include "charsetinfo.h" +#include "qt_utils/charsetinfo.h" #include "../editor.h" #include diff --git a/RedPandaIDE/compiler/stdincompiler.cpp b/RedPandaIDE/compiler/stdincompiler.cpp index 23a1cc46..8238c6c5 100644 --- a/RedPandaIDE/compiler/stdincompiler.cpp +++ b/RedPandaIDE/compiler/stdincompiler.cpp @@ -19,7 +19,7 @@ #include #include #include -#include "charsetinfo.h" +#include "qt_utils/charsetinfo.h" StdinCompiler::StdinCompiler(const QString &filename,const QByteArray& encoding, const QString& content,bool silent, bool onlyCheckSyntax): Compiler(filename,silent, onlyCheckSyntax), diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 9c5e3290..6747a631 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -20,7 +20,7 @@ #include #include #include -#include "SynEdit.h" +#include "qsynedit/SynEdit.h" #include "colorscheme.h" #include "common.h" #include "parser/cppparser.h" diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index d29055ab..0a4375e3 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -17,7 +17,7 @@ #include "cppparser.h" #include "parserutils.h" #include "../utils.h" -#include "../qsynedit/highlighter/cpp.h" +#include "qsynedit/highlighter/cpp.h" #include #include diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 67b814b0..2f2e4704 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -21,7 +21,7 @@ #include "editorlist.h" #include #include "utils.h" -#include "charsetinfo.h" +#include "qt_utils/charsetinfo.h" #include "projecttemplate.h" #include "systemconsts.h" #include "iconsmanager.h" diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 94259223..0ede6e28 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -25,7 +25,7 @@ #include #include "qsynedit/SynEdit.h" #include "compiler/compilerinfo.h" -#include "qt_utils/utils.h" +#include "utils.h" /** * use the following command to get gcc's default bin/library folders: diff --git a/RedPandaIDE/settingsdialog/editormiscwidget.cpp b/RedPandaIDE/settingsdialog/editormiscwidget.cpp index a4ac663a..5f75284a 100644 --- a/RedPandaIDE/settingsdialog/editormiscwidget.cpp +++ b/RedPandaIDE/settingsdialog/editormiscwidget.cpp @@ -17,7 +17,7 @@ #include "editormiscwidget.h" #include "ui_editormiscwidget.h" #include "../settings.h" -#include "../platform.h" +#include "qt_utils/charsetinfo.h" #include "../mainwindow.h" EditorMiscWidget::EditorMiscWidget(const QString& name, const QString& group, diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp new file mode 100644 index 00000000..141987db --- /dev/null +++ b/RedPandaIDE/utils.cpp @@ -0,0 +1,357 @@ +#include "utils.h" +#include "systemconsts.h" +#include +#include +#include "editor.h" +#include "editorlist.h" +#include "settings.h" +#include "mainwindow.h" +#include "project.h" +#include "parser/cppparser.h" +#ifdef Q_OS_WIN +#include +#include +#endif + +QStringList splitProcessCommand(const QString &cmd) +{ + QStringList result; + SplitProcessCommandQuoteType quoteType = SplitProcessCommandQuoteType::None; + int i=0; + QString current; + while (ieditorList()->getEditor(); + + result.replace("", localizePath(QDir::currentPath())); + result.replace("", localizePath(pSettings->dirs().executable())); + result.replace("", REDPANDA_CPP_VERSION); + result.replace("", localizePath(pSettings->dirs().appDir())); + QDate today = QDate::currentDate(); + QDateTime now = QDateTime::currentDateTime(); + + result.replace("", today.toString("yyyy-MM-dd")); + result.replace("", now.toString("yyyy-MM-dd hh:mm:ss")); + + Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet(); + if (compilerSet) { + // Only provide the first cpp include dir + if (compilerSet->defaultCppIncludeDirs().count()>0) + result.replace("", localizePath(compilerSet->defaultCppIncludeDirs().front())); + else + result.replace("",""); + + // Only provide the first lib dir + if (compilerSet->defaultLibDirs().count()>0) + result.replace("", localizePath(compilerSet->defaultLibDirs().front())); + else + result.replace("",""); + } + + if (e!=nullptr && !e->inProject()) { // Non-project editor macros + result.replace("", extractFileName(changeFileExt(e->filename(),EXECUTABLE_EXT))); + result.replace("", localizePath(changeFileExt(e->filename(),EXECUTABLE_EXT))); + result.replace("", extractFileName(e->filename())); + result.replace("", localizePath(e->filename())); + result.replace("", extractFileName(e->filename())); + result.replace("", localizePath(extractFileDir(e->filename()))); + } else if (pMainWindow->project()) { + result.replace("", extractFileName(pMainWindow->project()->executable())); + result.replace("", localizePath(pMainWindow->project()->executable())); + result.replace("", pMainWindow->project()->name()); + result.replace("", localizePath(pMainWindow->project()->filename())); + result.replace("", extractFileName(pMainWindow->project()->filename())); + result.replace("", localizePath(pMainWindow->project()->directory())); + } else { + result.replace("", ""); + result.replace("", ""); + result.replace("", ""); + result.replace("", ""); + result.replace("", ""); + result.replace("", ""); + } + + // Editor macros + if (e!=nullptr) { + result.replace("", extractFileName(e->filename())); + result.replace("", localizePath(e->filename())); + result.replace("", localizePath(extractFileDir(e->filename()))); + result.replace("", e->wordAtCursor()); + } else { + result.replace("", ""); + result.replace("", ""); + result.replace("", ""); + result.replace("", ""); + } + return result; +} + +void resetCppParser(std::shared_ptr parser, int compilerSetIndex) +{ + if (!parser) + return; + // Configure parser + parser->reset(); + //paser->enabled = pSettings-> devCodeCompletion.Enabled; +// CppParser.ParseLocalHeaders := devCodeCompletion.ParseLocalHeaders; +// CppParser.ParseGlobalHeaders := devCodeCompletion.ParseGlobalHeaders; + parser->setEnabled(true); + parser->setParseGlobalHeaders(true); + parser->setParseLocalHeaders(true); + // Set options depending on the current compiler set + // TODO: do this every time OnCompilerSetChanged + if (compilerSetIndex<0) { + compilerSetIndex=pSettings->compilerSets().defaultIndex(); + } + Settings::PCompilerSet compilerSet = pSettings->compilerSets().getSet(compilerSetIndex); + parser->clearIncludePaths(); + if (compilerSet) { + foreach (const QString& file,compilerSet->CppIncludeDirs()) { + parser->addIncludePath(file); + } + foreach (const QString& file,compilerSet->CIncludeDirs()) { + parser->addIncludePath(file); + } + foreach (const QString& file,compilerSet->defaultCppIncludeDirs()) { + parser->addIncludePath(file); + } + foreach (const QString& file,compilerSet->defaultCIncludeDirs()) { + parser->addIncludePath(file); + } + //TODO: Add default include dirs last, just like gcc does + // Set defines + if (parser->language()==ParserLanguage::C) { + for (QString define:compilerSet->CDefines()) { + parser->addHardDefineByLine(define); // predefined constants from -dM -E + } + } else { + for (QString define:compilerSet->CppDefines()) { + parser->addHardDefineByLine(define); // predefined constants from -dM -E + } + } + // add a Red Pand C++ 's own macro + parser->addHardDefineByLine("#define EGE_FOR_AUTO_CODE_COMPLETETION_ONLY"); + // add C/C++ default macro + parser->addHardDefineByLine("#define __FILE__ 1"); + parser->addHardDefineByLine("#define __LINE__ 1"); + parser->addHardDefineByLine("#define __DATE__ 1"); + parser->addHardDefineByLine("#define __TIME__ 1"); + } + parser->parseHardDefines(); + pMainWindow->disconnect(parser.get(), + &CppParser::onStartParsing, + pMainWindow, + &MainWindow::onStartParsing); + pMainWindow->disconnect(parser.get(), + &CppParser::onProgress, + pMainWindow, + &MainWindow::onParserProgress); + pMainWindow->disconnect(parser.get(), + &CppParser::onEndParsing, + pMainWindow, + &MainWindow::onEndParsing); + pMainWindow->connect(parser.get(), + &CppParser::onStartParsing, + pMainWindow, + &MainWindow::onStartParsing); + pMainWindow->connect(parser.get(), + &CppParser::onProgress, + pMainWindow, + &MainWindow::onParserProgress); + pMainWindow->connect(parser.get(), + &CppParser::onEndParsing, + pMainWindow, + &MainWindow::onEndParsing); +} + +int getNewFileNumber() +{ + static int count = 0; + count++; + return count; +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h new file mode 100644 index 00000000..a21f158a --- /dev/null +++ b/RedPandaIDE/utils.h @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef UTILS_H +#define UTILS_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SimpleIni.h" +#include "qt_utils/utils.h" + +using SimpleIni = CSimpleIniA; +using PSimpleIni = std::shared_ptr; + +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 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 +}; + +enum class SplitProcessCommandQuoteType { + None, + Single, + Double +}; + +FileType getFileType(const QString& filename); +QStringList splitProcessCommand(const QString& cmd); + +QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes); +QString genMakePath1(const QString& fileName); +QString genMakePath2(const QString& fileName); +QString getCompiledExecutableName(const QString& filename); +bool programHasConsole(const QString& filename); + +QString parseMacros(const QString& s); + +class CppParser; +void resetCppParser(std::shared_ptr parser, int compilerSetIndex=-1); + +int getNewFileNumber(); + +#endif // UTILS_H diff --git a/RedPandaIDE/widgets/searchresultview.h b/RedPandaIDE/widgets/searchresultview.h index 4405e497..184ecf17 100644 --- a/RedPandaIDE/widgets/searchresultview.h +++ b/RedPandaIDE/widgets/searchresultview.h @@ -20,7 +20,7 @@ #include #include #include -#include "../qsynedit/SearchBase.h" +#include "qsynedit/SearchBase.h" #include "utils.h" #define MAX_SEARCH_RESULTS 20