- enhancement: use different color to differenciate folder and headers in completion popup window

- enhancement: auto add "/" to folder when completing #include headers
This commit is contained in:
Roy Qu 2022-06-20 21:43:42 +08:00
parent 5c2c2bead2
commit 85c18d1f66
8 changed files with 72 additions and 24 deletions

View File

@ -1,3 +1,7 @@
Red Panda C++ Version 1.1.2
- enhancement: use different color to differenciate folder and headers in completion popup window
- enhancement: auto add "/" to folder when completing #include headers
Red Panda C++ Version 1.1.1 Red Panda C++ Version 1.1.1
- enhancement: adjust the appearance of problem case's input/output/expected control - enhancement: adjust the appearance of problem case's input/output/expected control
- change: swap position of problem case's output and expected input controls - change: swap position of problem case's output and expected input controls

View File

@ -10,7 +10,7 @@ isEmpty(APP_NAME) {
} }
isEmpty(APP_VERSION) { isEmpty(APP_VERSION) {
APP_VERSION=1.1.1 APP_VERSION=1.1.2
} }
macos: { macos: {

View File

@ -2997,14 +2997,14 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete)
} }
} }
void Editor::showHeaderCompletion(bool autoComplete) void Editor::showHeaderCompletion(bool autoComplete, bool forceShow)
{ {
if (!pSettings->codeCompletion().enabled()) if (!pSettings->codeCompletion().enabled())
return; return;
// if not devCodeCompletion.Enabled then // if not devCodeCompletion.Enabled then
// Exit; // Exit;
if (mHeaderCompletionPopup->isVisible()) // already in search, don't do it again if (!forceShow && mHeaderCompletionPopup->isVisible()) // already in search, don't do it again
return; return;
// Position it at the top of the next line // Position it at the top of the next line
@ -3028,6 +3028,7 @@ void Editor::showHeaderCompletion(bool autoComplete)
BufferCoord pBeginPos,pEndPos; BufferCoord pBeginPos,pEndPos;
QString word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, QString word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos,
WordPurpose::wpHeaderCompletionStart); WordPurpose::wpHeaderCompletionStart);
if (word.isEmpty()) if (word.isEmpty())
return; return;
@ -3177,8 +3178,10 @@ void Editor::completionInsert(bool appendFunc)
void Editor::headerCompletionInsert() void Editor::headerCompletionInsert()
{ {
QString headerName = mHeaderCompletionPopup->selectedFilename(true); QString headerName = mHeaderCompletionPopup->selectedFilename(true);
if (headerName.isEmpty()) if (headerName.isEmpty()) {
mHeaderCompletionPopup->hide();
return; return;
}
// delete the part of the word that's already been typed ... // delete the part of the word that's already been typed ...
BufferCoord p = caretXY(); BufferCoord p = caretXY();
@ -3199,7 +3202,11 @@ void Editor::headerCompletionInsert()
setSelText(headerName); setSelText(headerName);
mCompletionPopup->hide(); if (headerName.endsWith("/")) {
showHeaderCompletion(false,true);
} else {
mHeaderCompletionPopup->hide();
}
} }
bool Editor::onCompletionKeyPressed(QKeyEvent *event) bool Editor::onCompletionKeyPressed(QKeyEvent *event)
@ -3302,7 +3309,7 @@ bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
case Qt::Key_Enter: case Qt::Key_Enter:
case Qt::Key_Tab: case Qt::Key_Tab:
headerCompletionInsert(); headerCompletionInsert();
mHeaderCompletionPopup->hide(); //mHeaderCompletionPopup->hide();
return true; return true;
case Qt::Key_Shift: case Qt::Key_Shift:
return false; return false;

View File

@ -257,7 +257,7 @@ private:
QuoteStatus getQuoteStatus(); QuoteStatus getQuoteStatus();
void showCompletion(const QString& preWord, bool autoComplete); void showCompletion(const QString& preWord, bool autoComplete);
void showHeaderCompletion(bool autoComplete); void showHeaderCompletion(bool autoComplete, bool forceShow=false);
bool testInFunc(int x,int y); bool testInFunc(int x,int y);

View File

@ -574,16 +574,26 @@ void MainWindow::updateEditorColorSchemes()
pColorManager->updateStatementColors(mStatementColors,schemeName); pColorManager->updateStatementColors(mStatementColors,schemeName);
//color for code completion popup //color for code completion popup
PColorSchemeItem item; PColorSchemeItem item;
QColor localHeaderColor=palette().color(QPalette::Text);
QColor systemHeaderColor=palette().color(QPalette::Text);
QColor projectHeaderColor=palette().color(QPalette::Text);
QColor headerFolderColor=palette().color(QPalette::Text);
QColor baseColor = palette().color(QPalette::Base); QColor baseColor = palette().color(QPalette::Base);
item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor); item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
if (item) { if (item) {
mHeaderCompletionPopup->setSuggestionColor(item->foreground(), localHeaderColor = item->foreground();
item->foreground(), }
item->foreground()); item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
} else { if (item) {
mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text), systemHeaderColor = item->foreground();
palette().color(QPalette::Text), }
palette().color(QPalette::Text)); item = pColorManager->getItem(schemeName, SYNS_AttrString);
if (item) {
projectHeaderColor = item->foreground();
}
item = pColorManager->getItem(schemeName, SYNS_AttrStringEscapeSequences);
if (item) {
headerFolderColor = item->foreground();
} }
item = pColorManager->getItem(schemeName, COLOR_SCHEME_ERROR); item = pColorManager->getItem(schemeName, COLOR_SCHEME_ERROR);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item && haveGoodContrast(item->foreground(), baseColor)) {
@ -646,6 +656,10 @@ void MainWindow::updateEditorColorSchemes()
ui->txtProblemCaseOutput->setLineNumberAreaCurrentLine(pal.color(QPalette::ButtonText)); ui->txtProblemCaseOutput->setLineNumberAreaCurrentLine(pal.color(QPalette::ButtonText));
ui->txtProblemCaseExpected->setLineNumberAreaCurrentLine(pal.color(QPalette::ButtonText)); ui->txtProblemCaseExpected->setLineNumberAreaCurrentLine(pal.color(QPalette::ButtonText));
} }
mHeaderCompletionPopup->setSuggestionColor(localHeaderColor,
projectHeaderColor,
systemHeaderColor,
headerFolderColor);
} }
void MainWindow::applySettings() void MainWindow::applySettings()

View File

@ -102,11 +102,13 @@ void HeaderCompletionPopup::setKeypressedCallback(const KeyPressedCallback &newK
void HeaderCompletionPopup::setSuggestionColor(const QColor& localColor, void HeaderCompletionPopup::setSuggestionColor(const QColor& localColor,
const QColor& projectColor, const QColor& projectColor,
const QColor& systemColor) const QColor& systemColor,
const QColor& folderColor)
{ {
mModel->setLocalColor(localColor); mModel->setLocalColor(localColor);
mModel->setProjectColor(projectColor); mModel->setProjectColor(projectColor);
mModel->setSystemColor(systemColor); mModel->setSystemColor(systemColor);
mModel->setFolderColor(folderColor);
} }
QString HeaderCompletionPopup::selectedFilename(bool updateUsageCount) QString HeaderCompletionPopup::selectedFilename(bool updateUsageCount)
@ -125,6 +127,8 @@ QString HeaderCompletionPopup::selectedFilename(bool updateUsageCount)
item->usageCount++; item->usageCount++;
mHeaderUsageCounts.insert(item->fullpath,item->usageCount); mHeaderUsageCounts.insert(item->fullpath,item->usageCount);
} }
if (item->isFolder)
return item->filename+"/";
return item->filename; return item->filename;
} }
return ""; return "";
@ -204,15 +208,20 @@ void HeaderCompletionPopup::addFilesInPath(const QString &path, HeaderCompletion
foreach (const QFileInfo& fileInfo, dir.entryInfoList()) { foreach (const QFileInfo& fileInfo, dir.entryInfoList()) {
if (fileInfo.fileName().startsWith(".")) if (fileInfo.fileName().startsWith("."))
continue; continue;
if (fileInfo.isDir()) {
addFile(dir, fileInfo, type);
continue;
}
QString suffix = fileInfo.suffix().toLower(); QString suffix = fileInfo.suffix().toLower();
if (suffix == "h" || suffix == "hpp" || suffix == "") { if (suffix == "h" || suffix == "hpp" || suffix == "") {
addFile(dir, fileInfo.fileName(), type); addFile(dir, fileInfo, type);
} }
} }
} }
void HeaderCompletionPopup::addFile(const QDir& dir, const QString &fileName, HeaderCompletionListItemType type) void HeaderCompletionPopup::addFile(const QDir& dir, const QFileInfo& fileInfo, HeaderCompletionListItemType type)
{ {
QString fileName = fileInfo.fileName();
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
if (fileName.startsWith('.')) if (fileName.startsWith('.'))
@ -222,6 +231,7 @@ void HeaderCompletionPopup::addFile(const QDir& dir, const QString &fileName, He
item->itemType = type; item->itemType = type;
item->fullpath = dir.absoluteFilePath(fileName); item->fullpath = dir.absoluteFilePath(fileName);
item->usageCount = mHeaderUsageCounts.value(item->fullpath,0); item->usageCount = mHeaderUsageCounts.value(item->fullpath,0);
item->isFolder = fileInfo.isDir();
mFullCompletionList.insert(fileName,item); mFullCompletionList.insert(fileName,item);
} }
@ -310,8 +320,11 @@ QVariant HeaderCompletionListModel::data(const QModelIndex &index, int role) con
case Qt::DisplayRole: { case Qt::DisplayRole: {
return mFiles->at(index.row())->filename; return mFiles->at(index.row())->filename;
} }
case Qt::ForegroundRole: case Qt::ForegroundRole: {
switch(mFiles->at(index.row())->itemType) { PHeaderCompletionListItem item=mFiles->at(index.row());
if (item->isFolder)
return mFolderColor;
switch(item->itemType) {
case HeaderCompletionListItemType::LocalHeader: case HeaderCompletionListItemType::LocalHeader:
return mLocalColor; return mLocalColor;
case HeaderCompletionListItemType::ProjectHeader: case HeaderCompletionListItemType::ProjectHeader:
@ -319,7 +332,7 @@ QVariant HeaderCompletionListModel::data(const QModelIndex &index, int role) con
case HeaderCompletionListItemType::SystemHeader: case HeaderCompletionListItemType::SystemHeader:
return mSystemColor; return mSystemColor;
} }
}
break; break;
} }
return QVariant(); return QVariant();
@ -341,6 +354,11 @@ void HeaderCompletionListModel::setProjectColor(const QColor &newColor)
mProjectColor = newColor; mProjectColor = newColor;
} }
void HeaderCompletionListModel::setFolderColor(const QColor &newFolderColor)
{
mFolderColor = newFolderColor;
}
void HeaderCompletionListModel::setLocalColor(const QColor &newColor) void HeaderCompletionListModel::setLocalColor(const QColor &newColor)
{ {
mLocalColor = newColor; mLocalColor = newColor;

View File

@ -31,6 +31,7 @@ enum class HeaderCompletionListItemType {
struct HeaderCompletionListItem { struct HeaderCompletionListItem {
QString filename; QString filename;
QString fullpath; QString fullpath;
bool isFolder;
int usageCount; int usageCount;
HeaderCompletionListItemType itemType; HeaderCompletionListItemType itemType;
}; };
@ -48,11 +49,14 @@ public:
void setSystemColor(const QColor &newColor); void setSystemColor(const QColor &newColor);
void setProjectColor(const QColor &newColor); void setProjectColor(const QColor &newColor);
void setFolderColor(const QColor &newFolderColor);
private: private:
const QList<PHeaderCompletionListItem>* mFiles; const QList<PHeaderCompletionListItem> *mFiles;
QColor mLocalColor; QColor mLocalColor;
QColor mSystemColor; QColor mSystemColor;
QColor mProjectColor; QColor mProjectColor;
QColor mFolderColor;
}; };
class HeaderCompletionPopup : public QWidget class HeaderCompletionPopup : public QWidget
@ -66,14 +70,15 @@ public:
void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback); void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback);
void setSuggestionColor(const QColor& localColor, void setSuggestionColor(const QColor& localColor,
const QColor& projectColor, const QColor& projectColor,
const QColor& systemColor); const QColor& systemColor,
const QColor& folderColor);
QString selectedFilename(bool updateUsageCount); QString selectedFilename(bool updateUsageCount);
private: private:
void filterList(const QString& member); void filterList(const QString& member);
void getCompletionFor(const QString& phrase); void getCompletionFor(const QString& phrase);
void addFilesInPath(const QString& path, HeaderCompletionListItemType type); void addFilesInPath(const QString& path, HeaderCompletionListItemType type);
void addFile(const QDir& dir, const QString& fileName, HeaderCompletionListItemType type); void addFile(const QDir& dir, const QFileInfo &fileInfo, HeaderCompletionListItemType type);
void addFilesInSubDir(const QString& baseDirPath, const QString& subDirName, HeaderCompletionListItemType type); void addFilesInSubDir(const QString& baseDirPath, const QString& subDirName, HeaderCompletionListItemType type);
private: private:

View File

@ -23,7 +23,7 @@ SUBDIRS += \
APP_NAME = RedPandaCPP APP_NAME = RedPandaCPP
APP_VERSION = 1.1.1 APP_VERSION = 1.1.2
linux: { linux: {
isEmpty(PREFIX) { isEmpty(PREFIX) {