work save
This commit is contained in:
parent
c59e2c6667
commit
6ecfd228be
|
@ -1727,38 +1727,36 @@ void Editor::insertCodeSnippet(const QString &code)
|
||||||
mTabStopY =0;
|
mTabStopY =0;
|
||||||
mLineBeforeTabStop = "";
|
mLineBeforeTabStop = "";
|
||||||
mLineAfterTabStop = "";
|
mLineAfterTabStop = "";
|
||||||
QStringList sl;
|
|
||||||
QString newSl;
|
|
||||||
// prevent lots of repaints
|
// prevent lots of repaints
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
auto action = finally([this]{
|
auto action = finally([this]{
|
||||||
endUpdate();
|
endUpdate();
|
||||||
});
|
});
|
||||||
fText.BeginUpdate;
|
QStringList sl = parseMacros(code);
|
||||||
try
|
int lastI=0;
|
||||||
sl.Text:=ParseMacros(Code);
|
int spaceCount = GetLeftSpacing(
|
||||||
lastI:=0;
|
leftSpaces(lineText()),true).length();
|
||||||
spaceCount := Length(Text.GetLeftSpacing(
|
QStringList newSl;
|
||||||
Text.LeftSpacesEx(fText.LineText,True), True));
|
int insertPos;
|
||||||
for i:=0 to sl.Count -1 do begin
|
for (int i=0;i<sl.count();i++) {
|
||||||
lastPos := 0;
|
int lastPos = 0;
|
||||||
s:= sl[i];
|
QString s = sl[i];
|
||||||
if i>0 then
|
if (i>0)
|
||||||
lastPos := -spaceCount;
|
lastPos = -spaceCount;
|
||||||
while True do begin
|
while (true) {
|
||||||
insertPos := Pos(USER_CODE_IN_INSERT_POS,s);
|
insertPos = s.indexOf(USER_CODE_IN_INSERT_POS);
|
||||||
if insertPos = 0 then // no %INSERT% macro in this line now
|
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_INSERT_POS));
|
s.remove(insertPos,USER_CODE_IN_INSERT_POS.length());
|
||||||
dec(insertPos);
|
insertPos--;
|
||||||
p.x:=insertPos - lastPos;
|
p->x = insertPos - lastPos;
|
||||||
p.endX := p.x;
|
p->endX = p->x;
|
||||||
p.y:=i-lastI;
|
p->y = i - lastI;
|
||||||
lastPos := insertPos;
|
lastPos = insertPos;
|
||||||
lastI:=i;
|
lastI = i;
|
||||||
fUserCodeInTabStops.Add(p);
|
mUserCodeInTabStops.append(p);
|
||||||
end;
|
}
|
||||||
while True do begin
|
while True do begin
|
||||||
insertPos := Pos(USER_CODE_IN_REPL_POS_BEGIN,s);
|
insertPos := Pos(USER_CODE_IN_REPL_POS_BEGIN,s);
|
||||||
if insertPos = 0 then // no %INSERT% macro in this line now
|
if insertPos = 0 then // no %INSERT% macro in this line now
|
||||||
|
@ -1782,7 +1780,7 @@ void Editor::insertCodeSnippet(const QString &code)
|
||||||
fUserCodeInTabStops.Add(p);
|
fUserCodeInTabStops.Add(p);
|
||||||
end;
|
end;
|
||||||
newSl.Add(s);
|
newSl.Add(s);
|
||||||
end;
|
}
|
||||||
CursorPos := Text.CaretXY;
|
CursorPos := Text.CaretXY;
|
||||||
s:=newSl.Text;
|
s:=newSl.Text;
|
||||||
if EndsStr(#13#10,s) then
|
if EndsStr(#13#10,s) then
|
||||||
|
@ -1798,10 +1796,6 @@ void Editor::insertCodeSnippet(const QString &code)
|
||||||
end;
|
end;
|
||||||
if Code <> '' then
|
if Code <> '' then
|
||||||
fLastIdCharPressed := 0;
|
fLastIdCharPressed := 0;
|
||||||
// prevent lots of repaints
|
|
||||||
finally
|
|
||||||
fText.EndUpdate;
|
|
||||||
end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::showCompletion(bool autoComplete)
|
void Editor::showCompletion(bool autoComplete)
|
||||||
|
|
|
@ -11,6 +11,18 @@
|
||||||
#include "widgets/codecompletionpopup.h"
|
#include "widgets/codecompletionpopup.h"
|
||||||
#include "widgets/headercompletionpopup.h"
|
#include "widgets/headercompletionpopup.h"
|
||||||
|
|
||||||
|
#define USER_CODE_IN_INSERT_POS "%INSERT%"
|
||||||
|
#define USER_CODE_IN_REPL_POS_BEGIN "%REPL_BEGIN%"
|
||||||
|
#define USER_CODE_IN_REPL_POS_END "%REPL_END%"
|
||||||
|
|
||||||
|
struct TabStop {
|
||||||
|
int x;
|
||||||
|
int endX;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
using PTabStop = std::shared_ptr<TabStop>;
|
||||||
|
|
||||||
class SaveException: public std::exception {
|
class SaveException: public std::exception {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -144,6 +156,7 @@ public:
|
||||||
void gotoDefinition(const BufferCoord& pos);
|
void gotoDefinition(const BufferCoord& pos);
|
||||||
void reparse();
|
void reparse();
|
||||||
void insertString(const QString& value, bool moveCursor);
|
void insertString(const QString& value, bool moveCursor);
|
||||||
|
void insertCodeSnippet(const QString& code);
|
||||||
|
|
||||||
const PCppParser &parser();
|
const PCppParser &parser();
|
||||||
|
|
||||||
|
@ -232,6 +245,14 @@ private:
|
||||||
|
|
||||||
bool mSaving;
|
bool mSaving;
|
||||||
|
|
||||||
|
int mXOffsetSince;
|
||||||
|
int mTabStopBegin;
|
||||||
|
int mTabStopEnd;
|
||||||
|
int mTabStopY;
|
||||||
|
QString mLineBeforeTabStop;
|
||||||
|
QString mLineAfterTabStop;
|
||||||
|
QList<PTabStop> mUserCodeInTabStops;
|
||||||
|
|
||||||
// QWidget interface
|
// QWidget interface
|
||||||
protected:
|
protected:
|
||||||
void wheelEvent(QWheelEvent *event) override;
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
|
|
|
@ -201,12 +201,12 @@ static bool nameComparator(PStatement statement1,PStatement statement2) {
|
||||||
|
|
||||||
static bool defaultComparator(PStatement statement1,PStatement statement2) {
|
static bool defaultComparator(PStatement statement1,PStatement statement2) {
|
||||||
// Show user template first
|
// Show user template first
|
||||||
if (statement1->kind == StatementKind::skUserCodeIn) {
|
if (statement1->kind == StatementKind::skUserCodeSnippet) {
|
||||||
if (statement2->kind != StatementKind::skUserCodeIn)
|
if (statement2->kind != StatementKind::skUserCodeSnippet)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return statement1->command < statement2->command;
|
return statement1->command < statement2->command;
|
||||||
} else if (statement2->kind == StatementKind::skUserCodeIn) {
|
} else if (statement2->kind == StatementKind::skUserCodeSnippet) {
|
||||||
return false;
|
return false;
|
||||||
// show keywords first
|
// show keywords first
|
||||||
} else if ((statement1->kind == StatementKind::skKeyword)
|
} else if ((statement1->kind == StatementKind::skKeyword)
|
||||||
|
@ -221,12 +221,12 @@ static bool defaultComparator(PStatement statement1,PStatement statement2) {
|
||||||
|
|
||||||
static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
|
static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
|
||||||
// Show user template first
|
// Show user template first
|
||||||
if (statement1->kind == StatementKind::skUserCodeIn) {
|
if (statement1->kind == StatementKind::skUserCodeSnippet) {
|
||||||
if (statement2->kind != StatementKind::skUserCodeIn)
|
if (statement2->kind != StatementKind::skUserCodeSnippet)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return statement1->command < statement2->command;
|
return statement1->command < statement2->command;
|
||||||
} else if (statement2->kind == StatementKind::skUserCodeIn) {
|
} else if (statement2->kind == StatementKind::skUserCodeSnippet) {
|
||||||
return false;
|
return false;
|
||||||
// show keywords first
|
// show keywords first
|
||||||
} else if (statement1->kind == StatementKind::skKeyword) {
|
} else if (statement1->kind == StatementKind::skKeyword) {
|
||||||
|
@ -254,12 +254,12 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
|
||||||
|
|
||||||
static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) {
|
static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) {
|
||||||
// Show user template first
|
// Show user template first
|
||||||
if (statement1->kind == StatementKind::skUserCodeIn) {
|
if (statement1->kind == StatementKind::skUserCodeSnippet) {
|
||||||
if (statement2->kind != StatementKind::skUserCodeIn)
|
if (statement2->kind != StatementKind::skUserCodeSnippet)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return statement1->command < statement2->command;
|
return statement1->command < statement2->command;
|
||||||
} else if (statement2->kind == StatementKind::skUserCodeIn) {
|
} else if (statement2->kind == StatementKind::skUserCodeSnippet) {
|
||||||
return false;
|
return false;
|
||||||
//show most freq first
|
//show most freq first
|
||||||
} else if (statement1->freqTop > statement2->freqTop) {
|
} else if (statement1->freqTop > statement2->freqTop) {
|
||||||
|
@ -279,12 +279,12 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2)
|
||||||
|
|
||||||
static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement statement2){
|
static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement statement2){
|
||||||
// Show user template first
|
// Show user template first
|
||||||
if (statement1->kind == StatementKind::skUserCodeIn) {
|
if (statement1->kind == StatementKind::skUserCodeSnippet) {
|
||||||
if (statement2->kind != StatementKind::skUserCodeIn)
|
if (statement2->kind != StatementKind::skUserCodeSnippet)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return statement1->command < statement2->command;
|
return statement1->command < statement2->command;
|
||||||
} else if (statement2->kind == StatementKind::skUserCodeIn) {
|
} else if (statement2->kind == StatementKind::skUserCodeSnippet) {
|
||||||
return false;
|
return false;
|
||||||
//show most freq first
|
//show most freq first
|
||||||
} else if (statement1->freqTop > statement2->freqTop) {
|
} else if (statement1->freqTop > statement2->freqTop) {
|
||||||
|
@ -474,7 +474,7 @@ void CodeCompletionPopup::getCompletionFor(const QString &fileName, const QStrin
|
||||||
foreach (const PCodeSnippet& codeIn,mCodeSnippets) {
|
foreach (const PCodeSnippet& codeIn,mCodeSnippets) {
|
||||||
PStatement statement = std::make_shared<Statement>();
|
PStatement statement = std::make_shared<Statement>();
|
||||||
statement->command = codeIn->prefix;
|
statement->command = codeIn->prefix;
|
||||||
statement->kind = StatementKind::skUserCodeIn;
|
statement->kind = StatementKind::skUserCodeSnippet;
|
||||||
statement->fullName = codeIn->prefix;
|
statement->fullName = codeIn->prefix;
|
||||||
statement->usageCount = 0;
|
statement->usageCount = 0;
|
||||||
statement->freqTop = 0;
|
statement->freqTop = 0;
|
||||||
|
@ -801,12 +801,12 @@ void CodeCompletionPopup::setIgnoreCase(bool newIgnoreCase)
|
||||||
mIgnoreCase = newIgnoreCase;
|
mIgnoreCase = newIgnoreCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeCompletionPopup::showCodeIns() const
|
bool CodeCompletionPopup::showCodeSnippets() const
|
||||||
{
|
{
|
||||||
return mShowCodeSnippets;
|
return mShowCodeSnippets;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeCompletionPopup::setShowCodeIns(bool newShowCodeIns)
|
void CodeCompletionPopup::setShowCodeSnippets(bool newShowCodeIns)
|
||||||
{
|
{
|
||||||
mShowCodeSnippets = newShowCodeIns;
|
mShowCodeSnippets = newShowCodeIns;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,8 @@ public:
|
||||||
bool showKeywords() const;
|
bool showKeywords() const;
|
||||||
void setShowKeywords(bool newShowKeywords);
|
void setShowKeywords(bool newShowKeywords);
|
||||||
|
|
||||||
bool showCodeIns() const;
|
bool showCodeSnippets() const;
|
||||||
void setShowCodeIns(bool newShowCodeIns);
|
void setShowCodeSnippets(bool newShowCodeIns);
|
||||||
|
|
||||||
bool ignoreCase() const;
|
bool ignoreCase() const;
|
||||||
void setIgnoreCase(bool newIgnoreCase);
|
void setIgnoreCase(bool newIgnoreCase);
|
||||||
|
@ -77,7 +77,7 @@ private:
|
||||||
private:
|
private:
|
||||||
CodeCompletionListView * mListView;
|
CodeCompletionListView * mListView;
|
||||||
CodeCompletionListModel* mModel;
|
CodeCompletionListModel* mModel;
|
||||||
QList<PCodeSnippet> mCodeInsList; //(Code template list)
|
QList<PCodeSnippet> mCodeSnippets; //(Code template list)
|
||||||
//QList<PStatement> mCodeInsStatements; //temporary (user code template) statements created when show code suggestion
|
//QList<PStatement> mCodeInsStatements; //temporary (user code template) statements created when show code suggestion
|
||||||
StatementList mFullCompletionStatementList;
|
StatementList mFullCompletionStatementList;
|
||||||
StatementList mCompletionStatementList;
|
StatementList mCompletionStatementList;
|
||||||
|
@ -94,7 +94,7 @@ private:
|
||||||
bool mOnlyGlobals;
|
bool mOnlyGlobals;
|
||||||
bool mRecordUsage;
|
bool mRecordUsage;
|
||||||
bool mShowKeywords;
|
bool mShowKeywords;
|
||||||
bool mShowCodeIns;
|
bool mShowCodeSnippets;
|
||||||
bool mIgnoreCase;
|
bool mIgnoreCase;
|
||||||
bool mSortByScope;
|
bool mSortByScope;
|
||||||
bool mUseCppKeyword;
|
bool mUseCppKeyword;
|
||||||
|
@ -108,6 +108,8 @@ protected:
|
||||||
public:
|
public:
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
const QString &phrase() const;
|
const QString &phrase() const;
|
||||||
|
const QList<PCodeSnippet> &codeSnippets() const;
|
||||||
|
void setCodeSnippets(const QList<PCodeSnippet> &newCodeSnippets);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CODECOMPLETIONPOPUP_H
|
#endif // CODECOMPLETIONPOPUP_H
|
||||||
|
|
Loading…
Reference in New Issue