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()) {
|
||||
result += " "+compilerSet()->customCompileParams();
|
||||
result += " "+ parseMacros(compilerSet()->customCompileParams());
|
||||
}
|
||||
|
||||
if (mProject) {
|
||||
QString s = mProject->options().compilerCmd;
|
||||
if (!s.isEmpty()) {
|
||||
s.replace("_@@_", " ");
|
||||
result += " "+s;
|
||||
result += " "+parseMacros(s);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -354,13 +354,13 @@ QString Compiler::getCppCompileArguments(bool checkSyntax)
|
|||
}
|
||||
|
||||
if (compilerSet()->useCustomCompileParams() && !compilerSet()->customCompileParams().isEmpty()) {
|
||||
result += " "+compilerSet()->customCompileParams();
|
||||
result += " "+ parseMacros(compilerSet()->customCompileParams());
|
||||
}
|
||||
if (mProject) {
|
||||
QString s = mProject->options().cppCompilerCmd;
|
||||
if (!s.isEmpty()) {
|
||||
s.replace("_@@_", " ");
|
||||
result += " "+s;
|
||||
result += " "+parseMacros(s);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -1737,18 +1737,17 @@ void Editor::insertCodeSnippet(const QString &code)
|
|||
int spaceCount = GetLeftSpacing(
|
||||
leftSpaces(lineText()),true).length();
|
||||
QStringList newSl;
|
||||
int insertPos;
|
||||
for (int i=0;i<sl.count();i++) {
|
||||
int lastPos = 0;
|
||||
QString s = sl[i];
|
||||
if (i>0)
|
||||
lastPos = -spaceCount;
|
||||
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
|
||||
break;
|
||||
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--;
|
||||
p->x = insertPos - lastPos;
|
||||
p->endX = p->x;
|
||||
|
@ -1757,45 +1756,52 @@ void Editor::insertCodeSnippet(const QString &code)
|
|||
lastI = i;
|
||||
mUserCodeInTabStops.append(p);
|
||||
}
|
||||
while True do begin
|
||||
insertPos := Pos(USER_CODE_IN_REPL_POS_BEGIN,s);
|
||||
if insertPos = 0 then // no %INSERT% macro in this line now
|
||||
lastPos = 0;
|
||||
while (true) {
|
||||
int insertPos = s.indexOf(USER_CODE_IN_REPL_POS_BEGIN);
|
||||
if (insertPos < 0) // no %INSERT% macro in this line now
|
||||
break;
|
||||
System.new(p);
|
||||
Delete(s,insertPos,Length(USER_CODE_IN_REPL_POS_BEGIN));
|
||||
dec(insertPos);
|
||||
p.x:=insertPos - lastPos;
|
||||
PTabStop p = std::make_shared<TabStop>();
|
||||
s.remove(insertPos, QString(USER_CODE_IN_REPL_POS_BEGIN).length());
|
||||
insertPos--;
|
||||
p->x = insertPos - lastPos;
|
||||
|
||||
insertEndPos := insertPos + Pos(USER_CODE_IN_REPL_POS_END,copy(s,insertPos+1,MaxInt));
|
||||
if insertEndPos <= insertPos then begin
|
||||
p.endX := length(s);
|
||||
end else begin
|
||||
Delete(s,insertEndPos,Length(USER_CODE_IN_REPL_POS_END));
|
||||
dec(insertEndPos);
|
||||
p.endX := insertEndPos - lastPos;
|
||||
end;
|
||||
p.y:=i-lastI;
|
||||
lastPos := insertEndPos;
|
||||
lastI:=i;
|
||||
fUserCodeInTabStops.Add(p);
|
||||
end;
|
||||
newSl.Add(s);
|
||||
|
||||
int insertEndPos = insertPos +
|
||||
s.mid(insertPos).indexOf(USER_CODE_IN_REPL_POS_END);
|
||||
if (insertEndPos < insertPos) {
|
||||
p->endX = s.length();
|
||||
} else {
|
||||
s.remove(insertEndPos, QString(USER_CODE_IN_REPL_POS_END).length());
|
||||
insertEndPos--;
|
||||
p->endX = insertEndPos - lastPos;
|
||||
}
|
||||
p->y=i-lastI;
|
||||
lastPos = insertEndPos;
|
||||
lastI = i;
|
||||
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)
|
||||
|
@ -2528,6 +2534,11 @@ void Editor::updateFunctionTip()
|
|||
pMainWindow->functionTip()->show();
|
||||
}
|
||||
|
||||
void Editor::clearUserCodeInTabStops()
|
||||
{
|
||||
mUserCodeInTabStops.clear();
|
||||
}
|
||||
|
||||
void Editor::setInProject(bool newInProject)
|
||||
{
|
||||
if (mInProject == newInProject)
|
||||
|
|
|
@ -211,6 +211,7 @@ private:
|
|||
const QString& filename, int line);
|
||||
|
||||
void updateFunctionTip();
|
||||
void clearUserCodeInTabStops();
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
#include "parser/cppparser.h"
|
||||
#include "settings.h"
|
||||
#include "mainwindow.h"
|
||||
#include "editorlist.h"
|
||||
#include "editor.h"
|
||||
#include "project.h"
|
||||
|
||||
const QByteArray GuessTextEncoding(const QByteArray& text){
|
||||
bool allAscii;
|
||||
|
@ -734,3 +737,74 @@ QString fromByteArray(const QByteArray &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);
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue