- enhancement: add "minimum id length required to show code completion" to the options dialog's editor code completion page

This commit is contained in:
Roy Qu 2022-01-10 21:46:03 +08:00
parent 3d9edcad57
commit 8edace1c1d
8 changed files with 151 additions and 78 deletions

View File

@ -4,6 +4,7 @@ Red Panda C++ Version 0.13.2
- enhancement: can add non-code file in templates - enhancement: can add non-code file in templates
- enhancement: if there's no selection when copy/cut, select currect line by default - enhancement: if there's no selection when copy/cut, select currect line by default
- enhancement: support ligatures in fonts like fira code ( disabled by default, can be turned on in options dialog's editor font page) - enhancement: support ligatures in fonts like fira code ( disabled by default, can be turned on in options dialog's editor font page)
- enhancement: add "minimum id length required to show code completion" to the options dialog's editor code completion page
Red Panda C++ Version 0.13.1 Red Panda C++ Version 0.13.1
- enhancement: suppoort localization info in project templates - enhancement: suppoort localization info in project templates

View File

@ -1205,10 +1205,10 @@ Are you really want to continue?</oldsource>
<message> <message>
<location filename="editor.cpp" line="261"/> <location filename="editor.cpp" line="261"/>
<location filename="editor.cpp" line="340"/> <location filename="editor.cpp" line="340"/>
<location filename="editor.cpp" line="1198"/> <location filename="editor.cpp" line="1196"/>
<location filename="editor.cpp" line="1203"/> <location filename="editor.cpp" line="1201"/>
<location filename="editor.cpp" line="1221"/> <location filename="editor.cpp" line="1219"/>
<location filename="editor.cpp" line="1226"/> <location filename="editor.cpp" line="1224"/>
<source>Error</source> <source>Error</source>
<translation></translation> <translation></translation>
</message> </message>
@ -1222,65 +1222,65 @@ Are you really want to continue?</oldsource>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="1199"/> <location filename="editor.cpp" line="1197"/>
<source>The text to be copied exceeds count limit!</source> <source>The text to be copied exceeds count limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="1204"/> <location filename="editor.cpp" line="1202"/>
<source>The text to be copied exceeds character limit!</source> <source>The text to be copied exceeds character limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="1222"/> <location filename="editor.cpp" line="1220"/>
<source>The text to be cut exceeds count limit!</source> <source>The text to be cut exceeds count limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="1227"/> <location filename="editor.cpp" line="1225"/>
<source>The text to be cut exceeds character limit!</source> <source>The text to be cut exceeds character limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="2498"/> <location filename="editor.cpp" line="2496"/>
<source>Print Document</source> <source>Print Document</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="3074"/> <location filename="editor.cpp" line="3072"/>
<location filename="editor.cpp" line="3113"/> <location filename="editor.cpp" line="3111"/>
<location filename="editor.cpp" line="3164"/> <location filename="editor.cpp" line="3162"/>
<source>Ctrl+click for more info</source> <source>Ctrl+click for more info</source>
<translation>Ctrl+</translation> <translation>Ctrl+</translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="3551"/> <location filename="editor.cpp" line="3549"/>
<location filename="editor.cpp" line="3581"/> <location filename="editor.cpp" line="3579"/>
<source>Symbol &apos;%1&apos; not found!</source> <source>Symbol &apos;%1&apos; not found!</source>
<translation>&apos;%1&apos;!</translation> <translation>&apos;%1&apos;!</translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="3874"/> <location filename="editor.cpp" line="3872"/>
<source>astyle not found</source> <source>astyle not found</source>
<translation>astyle程序</translation> <translation>astyle程序</translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="3875"/> <location filename="editor.cpp" line="3873"/>
<source>Can&apos;t find astyle in &quot;%1&quot;.</source> <source>Can&apos;t find astyle in &quot;%1&quot;.</source>
<translation>astyle程序&quot;%1&quot;.</translation> <translation>astyle程序&quot;%1&quot;.</translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="4020"/> <location filename="editor.cpp" line="4018"/>
<source>Break point condition</source> <source>Break point condition</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="4021"/> <location filename="editor.cpp" line="4019"/>
<source>Enter the condition of the breakpoint:</source> <source>Enter the condition of the breakpoint:</source>
<translation>:</translation> <translation>:</translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="4231"/> <location filename="editor.cpp" line="4229"/>
<source>Readonly</source> <source>Readonly</source>
<translation></translation> <translation></translation>
</message> </message>
@ -1436,72 +1436,77 @@ Are you really want to continue?</oldsource>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="32"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="47"/>
<source>Minimum id length to show completion </source>
<translation></translation>
</message>
<message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="80"/>
<source>Clear all parsed symbols when editor is hidden</source> <source>Clear all parsed symbols when editor is hidden</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="39"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="87"/>
<source>Show completion suggestions while typing</source> <source>Show completion suggestions while typing</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="46"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="94"/>
<source>Engine options</source> <source>Engine options</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="52"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="100"/>
<source>Scan local header files</source> <source>Scan local header files</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="59"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="107"/>
<source>Scan system header files</source> <source>Scan system header files</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="69"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="117"/>
<source>Show keywords in suggestions</source> <source>Show keywords in suggestions</source>
<translation>C/C++</translation> <translation>C/C++</translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="76"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="124"/>
<source>Show code snippets in suggestions</source> <source>Show code snippets in suggestions</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="83"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="131"/>
<source>Append () when complete functions</source> <source>Append () when complete functions</source>
<translation>()</translation> <translation>()</translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="90"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="138"/>
<source>Ignore case when search suggestions</source> <source>Ignore case when search suggestions</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="97"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="145"/>
<source>Prefer local symbols</source> <source>Prefer local symbols</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="119"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="167"/>
<source>Prefer symbols mostly used</source> <source>Prefer symbols mostly used</source>
<translation>使</translation> <translation>使</translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="139"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="187"/>
<source>Clear usage data</source> <source>Clear usage data</source>
<translation>使</translation> <translation>使</translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="158"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="206"/>
<source>Completion suggestion window width:</source> <source>Completion suggestion window width:</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/editorcodecompletionwidget.ui" line="188"/> <location filename="settingsdialog/editorcodecompletionwidget.ui" line="236"/>
<source>Completion suggestion window height:</source> <source>Completion suggestion window height:</source>
<translation></translation> <translation></translation>
</message> </message>
@ -7289,8 +7294,8 @@ Are you really want to continue?</oldsource>
<context> <context>
<name>SynEdit</name> <name>SynEdit</name>
<message> <message>
<location filename="qsynedit/TextPainter.cpp" line="993"/>
<location filename="qsynedit/TextPainter.cpp" line="994"/> <location filename="qsynedit/TextPainter.cpp" line="994"/>
<location filename="qsynedit/TextPainter.cpp" line="995"/>
<source>The highlighter seems to be in an infinite loop</source> <source>The highlighter seems to be in an infinite loop</source>
<translation></translation> <translation></translation>
</message> </message>

View File

@ -701,14 +701,14 @@ void Editor::keyPressEvent(QKeyEvent *event)
mLastIdCharPressed++; mLastIdCharPressed++;
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& pSettings->codeCompletion().showCompletionWhileInput() ) { && pSettings->codeCompletion().showCompletionWhileInput() ) {
if (mLastIdCharPressed==1) { if (mParser && mParser->isIncludeLine(lineText())
if (mParser && mParser->isIncludeLine(lineText())) { && mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()) {
// is a #include line // is a #include line
setSelText(ch); setSelText(ch);
showHeaderCompletion(false); showHeaderCompletion(false);
handled=true; handled=true;
return; return;
} else { } else if (mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()){
QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY()); QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY());
if (!lastWord.isEmpty()) { if (!lastWord.isEmpty()) {
if (CppTypeKeywords.contains(lastWord)) { if (CppTypeKeywords.contains(lastWord)) {
@ -748,8 +748,6 @@ void Editor::keyPressEvent(QKeyEvent *event)
return; return;
} }
} }
}
} else { } else {
//preprocessor ? //preprocessor ?
if ((mLastIdCharPressed=0) && (ch=='#') && lineText().isEmpty()) { if ((mLastIdCharPressed=0) && (ch=='#') && lineText().isEmpty()) {
@ -1151,7 +1149,7 @@ void Editor::inputMethodEvent(QInputMethodEvent *event)
mLastIdCharPressed+=s.length(); mLastIdCharPressed+=s.length();
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& pSettings->codeCompletion().showCompletionWhileInput() ) { && pSettings->codeCompletion().showCompletionWhileInput() ) {
if (mLastIdCharPressed>=1) { if (mLastIdCharPressed>=pSettings->codeCompletion().minCharRequired()) {
QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY()); QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY());
if (!lastWord.isEmpty()) { if (!lastWord.isEmpty()) {
if (CppTypeKeywords.contains(lastWord)) { if (CppTypeKeywords.contains(lastWord)) {

View File

@ -400,6 +400,7 @@ void SynEditTextPainter::PaintToken(const QString &Token, int TokenCols, int Col
startPaint = false; startPaint = false;
for (int i=0;i<Token.length();i++) { for (int i=0;i<Token.length();i++) {
int charCols; int charCols;
QString textToPaint = Token[i];
if (Token[i] == SynTabChar) { if (Token[i] == SynTabChar) {
charCols = edit->mTabWidth - ((ColumnsBefore+tokenColLen) % edit->mTabWidth); charCols = edit->mTabWidth - ((ColumnsBefore+tokenColLen) % edit->mTabWidth);
} else { } else {

View File

@ -3479,6 +3479,16 @@ void Settings::CodeCompletion::setClearWhenEditorHidden(bool newClearWhenEditorH
mClearWhenEditorHidden = newClearWhenEditorHidden; mClearWhenEditorHidden = newClearWhenEditorHidden;
} }
int Settings::CodeCompletion::minCharRequired() const
{
return mMinCharRequired;
}
void Settings::CodeCompletion::setMinCharRequired(int newMinCharRequired)
{
mMinCharRequired = newMinCharRequired;
}
bool Settings::CodeCompletion::appendFunc() const bool Settings::CodeCompletion::appendFunc() const
{ {
return mAppendFunc; return mAppendFunc;
@ -3604,6 +3614,7 @@ void Settings::CodeCompletion::doSave()
saveValue("append_func",mAppendFunc); saveValue("append_func",mAppendFunc);
saveValue("show_code_ins",mShowCodeIns); saveValue("show_code_ins",mShowCodeIns);
saveValue("clear_when_editor_hidden",mClearWhenEditorHidden); saveValue("clear_when_editor_hidden",mClearWhenEditorHidden);
saveValue("min_char_required",mMinCharRequired);
} }
@ -3622,6 +3633,7 @@ void Settings::CodeCompletion::doLoad()
mIgnoreCase = boolValue("ignore_case",true); mIgnoreCase = boolValue("ignore_case",true);
mAppendFunc = boolValue("append_func",true); mAppendFunc = boolValue("append_func",true);
mShowCodeIns = boolValue("show_code_ins",true); mShowCodeIns = boolValue("show_code_ins",true);
mMinCharRequired = intValue("min_char_required",1);
bool doClear = true; bool doClear = true;

View File

@ -576,6 +576,9 @@ public:
bool clearWhenEditorHidden() const; bool clearWhenEditorHidden() const;
void setClearWhenEditorHidden(bool newClearWhenEditorHidden); void setClearWhenEditorHidden(bool newClearWhenEditorHidden);
int minCharRequired() const;
void setMinCharRequired(int newMinCharRequired);
private: private:
int mWidth; int mWidth;
int mHeight; int mHeight;
@ -590,6 +593,7 @@ public:
bool mAppendFunc; bool mAppendFunc;
bool mShowCodeIns; bool mShowCodeIns;
bool mClearWhenEditorHidden; bool mClearWhenEditorHidden;
int mMinCharRequired;
// _Base interface // _Base interface
protected: protected:

View File

@ -50,6 +50,8 @@ void EditorCodeCompletionWidget::doLoad()
ui->chkIgnoreCases->setChecked(pSettings->codeCompletion().ignoreCase()); ui->chkIgnoreCases->setChecked(pSettings->codeCompletion().ignoreCase());
ui->chkAppendFunc->setChecked(pSettings->codeCompletion().appendFunc()); ui->chkAppendFunc->setChecked(pSettings->codeCompletion().appendFunc());
ui->chkShowCodeIns->setChecked(pSettings->codeCompletion().showCodeIns()); ui->chkShowCodeIns->setChecked(pSettings->codeCompletion().showCodeIns());
ui->spinMinCharRequired->setValue(pSettings->codeCompletion().minCharRequired());
} }
void EditorCodeCompletionWidget::doSave() void EditorCodeCompletionWidget::doSave()
@ -70,6 +72,8 @@ void EditorCodeCompletionWidget::doSave()
pSettings->codeCompletion().setIgnoreCase(ui->chkIgnoreCases->isChecked()); pSettings->codeCompletion().setIgnoreCase(ui->chkIgnoreCases->isChecked());
pSettings->codeCompletion().setAppendFunc(ui->chkAppendFunc->isChecked()); pSettings->codeCompletion().setAppendFunc(ui->chkAppendFunc->isChecked());
pSettings->codeCompletion().setShowCodeIns(ui->chkShowCodeIns->isChecked()); pSettings->codeCompletion().setShowCodeIns(ui->chkShowCodeIns->isChecked());
pSettings->codeCompletion().setMinCharRequired(ui->spinMinCharRequired->value());
pSettings->codeCompletion().save(); pSettings->codeCompletion().save();
} }

View File

@ -26,6 +26,54 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Minimum id length to show completion </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinMinCharRequired">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>20</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="chkClearWhenEditorHidden"> <widget class="QCheckBox" name="chkClearWhenEditorHidden">
<property name="text"> <property name="text">