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