- 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
- enhancement: adjust the appearance of problem case's input/output/expected control
- change: swap position of problem case's output and expected input controls

View File

@ -10,7 +10,7 @@ isEmpty(APP_NAME) {
}
isEmpty(APP_VERSION) {
APP_VERSION=1.1.1
APP_VERSION=1.1.2
}
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())
return;
// if not devCodeCompletion.Enabled then
// 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;
// Position it at the top of the next line
@ -3028,6 +3028,7 @@ void Editor::showHeaderCompletion(bool autoComplete)
BufferCoord pBeginPos,pEndPos;
QString word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos,
WordPurpose::wpHeaderCompletionStart);
if (word.isEmpty())
return;
@ -3177,8 +3178,10 @@ void Editor::completionInsert(bool appendFunc)
void Editor::headerCompletionInsert()
{
QString headerName = mHeaderCompletionPopup->selectedFilename(true);
if (headerName.isEmpty())
if (headerName.isEmpty()) {
mHeaderCompletionPopup->hide();
return;
}
// delete the part of the word that's already been typed ...
BufferCoord p = caretXY();
@ -3199,7 +3202,11 @@ void Editor::headerCompletionInsert()
setSelText(headerName);
mCompletionPopup->hide();
if (headerName.endsWith("/")) {
showHeaderCompletion(false,true);
} else {
mHeaderCompletionPopup->hide();
}
}
bool Editor::onCompletionKeyPressed(QKeyEvent *event)
@ -3302,7 +3309,7 @@ bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
case Qt::Key_Enter:
case Qt::Key_Tab:
headerCompletionInsert();
mHeaderCompletionPopup->hide();
//mHeaderCompletionPopup->hide();
return true;
case Qt::Key_Shift:
return false;

View File

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

View File

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

View File

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

View File

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

View File

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