work save
This commit is contained in:
parent
6ecfd228be
commit
23b651f0c4
|
@ -307,14 +307,14 @@ QString Compiler::getCCompileArguments(bool checkSyntax)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
|
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
|
||||||
result += " "+compilerSet()->customCompileParams();
|
result += " "+ parseMacros(compilerSet()->customCompileParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mProject) {
|
if (mProject) {
|
||||||
QString s = mProject->options().compilerCmd;
|
QString s = mProject->options().compilerCmd;
|
||||||
if (!s.isEmpty()) {
|
if (!s.isEmpty()) {
|
||||||
s.replace("_@@_", " ");
|
s.replace("_@@_", " ");
|
||||||
result += " "+s;
|
result += " "+parseMacros(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -354,13 +354,13 @@ QString Compiler::getCppCompileArguments(bool checkSyntax)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
|
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
|
||||||
result += " "+compilerSet()->customCompileParams();
|
result += " "+ parseMacros(compilerSet()->customCompileParams());
|
||||||
}
|
}
|
||||||
if (mProject) {
|
if (mProject) {
|
||||||
QString s = mProject->options().cppCompilerCmd;
|
QString s = mProject->options().cppCompilerCmd;
|
||||||
if (!s.isEmpty()) {
|
if (!s.isEmpty()) {
|
||||||
s.replace("_@@_", " ");
|
s.replace("_@@_", " ");
|
||||||
result += " "+s;
|
result += " "+parseMacros(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1737,18 +1737,17 @@ void Editor::insertCodeSnippet(const QString &code)
|
||||||
int spaceCount = GetLeftSpacing(
|
int spaceCount = GetLeftSpacing(
|
||||||
leftSpaces(lineText()),true).length();
|
leftSpaces(lineText()),true).length();
|
||||||
QStringList newSl;
|
QStringList newSl;
|
||||||
int insertPos;
|
|
||||||
for (int i=0;i<sl.count();i++) {
|
for (int i=0;i<sl.count();i++) {
|
||||||
int lastPos = 0;
|
int lastPos = 0;
|
||||||
QString s = sl[i];
|
QString s = sl[i];
|
||||||
if (i>0)
|
if (i>0)
|
||||||
lastPos = -spaceCount;
|
lastPos = -spaceCount;
|
||||||
while (true) {
|
while (true) {
|
||||||
insertPos = s.indexOf(USER_CODE_IN_INSERT_POS);
|
int insertPos = s.indexOf(USER_CODE_IN_INSERT_POS);
|
||||||
if (insertPos < 0) // no %INSERT% macro in this line now
|
if (insertPos < 0) // no %INSERT% macro in this line now
|
||||||
break;
|
break;
|
||||||
PTabStop p = std::make_shared<TabStop>();
|
PTabStop p = std::make_shared<TabStop>();
|
||||||
s.remove(insertPos,USER_CODE_IN_INSERT_POS.length());
|
s.remove(insertPos, QString(USER_CODE_IN_INSERT_POS).length());
|
||||||
insertPos--;
|
insertPos--;
|
||||||
p->x = insertPos - lastPos;
|
p->x = insertPos - lastPos;
|
||||||
p->endX = p->x;
|
p->endX = p->x;
|
||||||
|
@ -1757,45 +1756,52 @@ void Editor::insertCodeSnippet(const QString &code)
|
||||||
lastI = i;
|
lastI = i;
|
||||||
mUserCodeInTabStops.append(p);
|
mUserCodeInTabStops.append(p);
|
||||||
}
|
}
|
||||||
while True do begin
|
lastPos = 0;
|
||||||
insertPos := Pos(USER_CODE_IN_REPL_POS_BEGIN,s);
|
while (true) {
|
||||||
if insertPos = 0 then // no %INSERT% macro in this line now
|
int insertPos = s.indexOf(USER_CODE_IN_REPL_POS_BEGIN);
|
||||||
|
if (insertPos < 0) // no %INSERT% macro in this line now
|
||||||
break;
|
break;
|
||||||
System.new(p);
|
PTabStop p = std::make_shared<TabStop>();
|
||||||
Delete(s,insertPos,Length(USER_CODE_IN_REPL_POS_BEGIN));
|
s.remove(insertPos, QString(USER_CODE_IN_REPL_POS_BEGIN).length());
|
||||||
dec(insertPos);
|
insertPos--;
|
||||||
p.x:=insertPos - lastPos;
|
p->x = insertPos - lastPos;
|
||||||
|
|
||||||
insertEndPos := insertPos + Pos(USER_CODE_IN_REPL_POS_END,copy(s,insertPos+1,MaxInt));
|
|
||||||
if insertEndPos <= insertPos then begin
|
int insertEndPos = insertPos +
|
||||||
p.endX := length(s);
|
s.mid(insertPos).indexOf(USER_CODE_IN_REPL_POS_END);
|
||||||
end else begin
|
if (insertEndPos < insertPos) {
|
||||||
Delete(s,insertEndPos,Length(USER_CODE_IN_REPL_POS_END));
|
p->endX = s.length();
|
||||||
dec(insertEndPos);
|
} else {
|
||||||
p.endX := insertEndPos - lastPos;
|
s.remove(insertEndPos, QString(USER_CODE_IN_REPL_POS_END).length());
|
||||||
end;
|
insertEndPos--;
|
||||||
p.y:=i-lastI;
|
p->endX = insertEndPos - lastPos;
|
||||||
lastPos := insertEndPos;
|
}
|
||||||
lastI:=i;
|
p->y=i-lastI;
|
||||||
fUserCodeInTabStops.Add(p);
|
lastPos = insertEndPos;
|
||||||
end;
|
lastI = i;
|
||||||
newSl.Add(s);
|
mUserCodeInTabStops.append(p);
|
||||||
|
}
|
||||||
|
newSl.append(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferCoord cursorPos = caretXY();
|
||||||
|
QString s = LinesToText(newSl);
|
||||||
|
// if EndsStr(#13#10,s) then
|
||||||
|
// Delete(s,Length(s)-1,2)
|
||||||
|
// else if EndsStr(#10, s) then
|
||||||
|
// Delete(s,Length(s),1);
|
||||||
|
setSelText(s);
|
||||||
|
setCaretXY(cursorPos); //restore cursor pos before insert
|
||||||
|
// fText.SelText := s;
|
||||||
|
// Text.CaretXY := CursorPos;
|
||||||
|
if (mUserCodeInTabStops.count()>0) {
|
||||||
|
mTabStopBegin = caretX();
|
||||||
|
mTabStopEnd = caretX();
|
||||||
|
popUserCodeInTabStops();
|
||||||
|
}
|
||||||
|
if (!code.isEmpty()) {
|
||||||
|
mLastIdCharPressed = 0;
|
||||||
}
|
}
|
||||||
CursorPos := Text.CaretXY;
|
|
||||||
s:=newSl.Text;
|
|
||||||
if EndsStr(#13#10,s) then
|
|
||||||
Delete(s,Length(s)-1,2)
|
|
||||||
else if EndsStr(#10, s) then
|
|
||||||
Delete(s,Length(s),1);
|
|
||||||
fText.SelText := s;
|
|
||||||
Text.CaretXY := CursorPos; //restore cursor pos before insert
|
|
||||||
if fUserCodeInTabStops.Count > 0 then begin
|
|
||||||
fTabStopBegin :=Text.CaretX;
|
|
||||||
fTabStopEnd := Text.CaretX;
|
|
||||||
PopUserCodeInTabStops;
|
|
||||||
end;
|
|
||||||
if Code <> '' then
|
|
||||||
fLastIdCharPressed := 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::showCompletion(bool autoComplete)
|
void Editor::showCompletion(bool autoComplete)
|
||||||
|
@ -2528,6 +2534,11 @@ void Editor::updateFunctionTip()
|
||||||
pMainWindow->functionTip()->show();
|
pMainWindow->functionTip()->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::clearUserCodeInTabStops()
|
||||||
|
{
|
||||||
|
mUserCodeInTabStops.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::setInProject(bool newInProject)
|
void Editor::setInProject(bool newInProject)
|
||||||
{
|
{
|
||||||
if (mInProject == newInProject)
|
if (mInProject == newInProject)
|
||||||
|
|
|
@ -211,6 +211,7 @@ private:
|
||||||
const QString& filename, int line);
|
const QString& filename, int line);
|
||||||
|
|
||||||
void updateFunctionTip();
|
void updateFunctionTip();
|
||||||
|
void clearUserCodeInTabStops();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
#include "parser/cppparser.h"
|
#include "parser/cppparser.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "editorlist.h"
|
||||||
|
#include "editor.h"
|
||||||
|
#include "project.h"
|
||||||
|
|
||||||
const QByteArray GuessTextEncoding(const QByteArray& text){
|
const QByteArray GuessTextEncoding(const QByteArray& text){
|
||||||
bool allAscii;
|
bool allAscii;
|
||||||
|
@ -734,3 +737,74 @@ QString fromByteArray(const QByteArray &s)
|
||||||
{
|
{
|
||||||
return QString::fromLocal8Bit(s);
|
return QString::fromLocal8Bit(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString LinesToText(const QStringList &lines)
|
||||||
|
{
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString parseMacros(const QString &s)
|
||||||
|
{
|
||||||
|
QString result = s;
|
||||||
|
Editor *e = pMainWindow->editorList()->getEditor();
|
||||||
|
|
||||||
|
result.replace("<DEFAULT>", pSettings->dirs().app());
|
||||||
|
result.replace("<DEVCPP>", pSettings->dirs().app());
|
||||||
|
result.replace("<DEVCPPVERSION>", DEVCPP_VERSION);
|
||||||
|
result.replace("<EXECPATH>", pSettings->dirs().app());
|
||||||
|
QDate today = QDate::currentDate();
|
||||||
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
result.replace("<DATE>", "yyyy-MM-dd");
|
||||||
|
result.replace("<DATETIME>", "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("<INCLUDE>", compilerSet->defaultCppIncludeDirs().front());
|
||||||
|
else
|
||||||
|
result.replace("<INCLUDE>","");
|
||||||
|
|
||||||
|
// Only provide the first lib dir
|
||||||
|
if (compilerSet->defaultLibDirs().count()>0)
|
||||||
|
result.replace("<LIB>", compilerSet->defaultCppIncludeDirs().front());
|
||||||
|
else
|
||||||
|
result.replace("<LIB>","");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Project-dependent macros
|
||||||
|
if (pMainWindow->project()) {
|
||||||
|
result.replace("<EXENAME>", pMainWindow->project()->executable());
|
||||||
|
result.replace("<PROJECTNAME>", pMainWindow->project()->name());
|
||||||
|
result.replace("<PROJECTFILE>", pMainWindow->project()->filename());
|
||||||
|
result.replace("<PROJECTPATH>", pMainWindow->project()->directory());
|
||||||
|
// result.replace("<SOURCESPCLIST>', MainForm.Project.ListUnitStr(' '));
|
||||||
|
result.replace("<SOURCESPCLIST>","");
|
||||||
|
} else if (e!=nullptr) { // Non-project editor macros
|
||||||
|
result.replace("<EXENAME>", changeFileExt(e->filename(),EXECUTABLE_EXT));
|
||||||
|
result.replace("<PROJECTNAME>",e->filename());
|
||||||
|
result.replace("<PROJECTFILE>",e->filename());
|
||||||
|
result.replace("<PROJECTPATH>", extractFileDir(e->filename()));
|
||||||
|
result.replace("<SOURCESPCLIST>", ""); // clear unchanged macros
|
||||||
|
} else {
|
||||||
|
result.replace("<EXENAME>", "");
|
||||||
|
result.replace("<PROJECTNAME>", "");
|
||||||
|
result.replace("<PROJECTFILE>", "");
|
||||||
|
result.replace("<PROJECTPATH>", "");
|
||||||
|
result.replace("<SOURCESPCLIST>", ""); // clear unchanged macros
|
||||||
|
}
|
||||||
|
|
||||||
|
// Editor macros
|
||||||
|
if (e!=nullptr) {
|
||||||
|
result.replace("<SOURCENAME>", extractFileName(e->filename()));
|
||||||
|
result.replace("<SOURCEFILE>", e->filename());
|
||||||
|
result.replace("<SOURCEPATH>", extractFileDir(e->filename()));
|
||||||
|
result.replace("<WORDXY>", e->wordAtCursor());
|
||||||
|
} else {
|
||||||
|
result.replace("<SOURCENAME>", "");
|
||||||
|
result.replace("<SOURCEFILE>", "");
|
||||||
|
result.replace("<SOURCEPATH>", "");
|
||||||
|
result.replace("<WORDXY>", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -145,6 +145,9 @@ void ReadStreamToLines(QTextStream* stream, LineProcessFunc lineFunc);
|
||||||
|
|
||||||
QStringList TextToLines(const QString& text);
|
QStringList TextToLines(const QString& text);
|
||||||
void TextToLines(const QString& text, LineProcessFunc lineFunc);
|
void TextToLines(const QString& text, LineProcessFunc lineFunc);
|
||||||
|
QString LinesToText(const QStringList& lines);
|
||||||
|
|
||||||
|
QString parseMacros(const QString& s);
|
||||||
|
|
||||||
QStringList ReadFileToLines(const QString& fileName, QTextCodec* codec);
|
QStringList ReadFileToLines(const QString& fileName, QTextCodec* codec);
|
||||||
QStringList ReadFileToLines(const QString& fileName);
|
QStringList ReadFileToLines(const QString& fileName);
|
||||||
|
|
Loading…
Reference in New Issue