- enhancement: correctly handle auto indents for statement span many lines;
- enhancment: only use colors have good contrasts with the background in the class browser and code completion suggestion window
This commit is contained in:
parent
2db0d95593
commit
4eec185ac4
2
NEWS.md
2
NEWS.md
|
@ -4,6 +4,8 @@ Version 0.7.6
|
|||
- enhancement: the line containing 'public:' / 'private:' / 'protected:' / 'case *:' will use of indents of the surrounding '{' line, instead of just unindent one level
|
||||
- enhancement: correctly handle auto indents for multi-level embedding complex statements like 'for(...) if (...) printf();
|
||||
- change: Don't use 'pause' in the console pauser, in case of privilege problems.
|
||||
- enhancement: correctly handle auto indents for statement span many lines;
|
||||
- enhancment: only use colors have good contrasts with the background in the class browser and code completion suggestion window
|
||||
|
||||
Version 0.7.5
|
||||
- enhancement: more accurate auto indent calculation
|
||||
|
|
|
@ -425,56 +425,67 @@ void MainWindow::updateCompileActions()
|
|||
|| mEditorList->pageCount()>0);
|
||||
|
||||
}
|
||||
static bool haveGoodContrast(const QColor& c1, const QColor &c2) {
|
||||
int lightness1 = c1.lightness();
|
||||
int lightness2 = c2.lightness();
|
||||
return std::abs(lightness1 - lightness2)>=150;
|
||||
}
|
||||
|
||||
void MainWindow::updateEditorColorSchemes()
|
||||
{
|
||||
if (!mStatementColors)
|
||||
return;
|
||||
mStatementColors->clear();
|
||||
|
||||
mEditorList->applyColorSchemes(pSettings->editor().colorScheme());
|
||||
QString schemeName = pSettings->editor().colorScheme();
|
||||
//color for code completion popup
|
||||
PColorSchemeItem item;
|
||||
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrFunction);
|
||||
if (item) {
|
||||
QColor baseColor = palette().color(QPalette::Base);
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skFunction,item);
|
||||
mStatementColors->insert(StatementKind::skConstructor,item);
|
||||
mStatementColors->insert(StatementKind::skDestructor,item);
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrClass);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skClass,item);
|
||||
mStatementColors->insert(StatementKind::skTypedef,item);
|
||||
mStatementColors->insert(StatementKind::skAlias,item);
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skEnumType,item);
|
||||
mStatementColors->insert(StatementKind::skEnumClassType,item);
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrVariable);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skVariable,item);
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skLocalVariable,item);
|
||||
mStatementColors->insert(StatementKind::skParameter,item);
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skGlobalVariable,item);
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skPreprocessor,item);
|
||||
mStatementColors->insert(StatementKind::skEnum,item);
|
||||
mHeaderCompletionPopup->setSuggestionColor(item->foreground());
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skKeyword,item);
|
||||
mStatementColors->insert(StatementKind::skUserCodeSnippet,item);
|
||||
}
|
||||
item = pColorManager->getItem(schemeName, SYNS_AttrString);
|
||||
if (item) {
|
||||
if (item && haveGoodContrast(item->foreground(), baseColor)) {
|
||||
mStatementColors->insert(StatementKind::skNamespace,item);
|
||||
mStatementColors->insert(StatementKind::skNamespaceAlias,item);
|
||||
}
|
||||
|
@ -490,6 +501,7 @@ void MainWindow::applySettings()
|
|||
else
|
||||
QApplication::setStyle("fusion");
|
||||
qApp->setPalette(appTheme->palette());
|
||||
updateEditorColorSchemes();
|
||||
|
||||
QFont font(pSettings->environment().interfaceFont(),
|
||||
pSettings->environment().interfaceFontSize());
|
||||
|
|
|
@ -1455,13 +1455,6 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
|||
int len = matchingIndents.length();
|
||||
while (i<len && !newIndents.isEmpty()) {
|
||||
int indent = matchingIndents[i];
|
||||
if (indent >= sitStatemntBrace) {
|
||||
int counts = indent - sitStatemntBrace;
|
||||
for (int j=0;j<counts;j++) {
|
||||
matchingIndents.insert(i+1,sitStatement);
|
||||
}
|
||||
len = matchingIndents.length();
|
||||
}
|
||||
int idx = newIndents.lastIndexOf(indent);
|
||||
if (idx >=0) {
|
||||
newIndents.remove(idx,newIndents.length()-idx);
|
||||
|
@ -1471,10 +1464,20 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
|||
i++;
|
||||
}
|
||||
if (i>=len) {
|
||||
indentSpaces = leftSpaces(mLines->getString(l-1));
|
||||
// if (newIndents.length()>0)
|
||||
// indentSpaces+=mTabWidth;
|
||||
break;
|
||||
// we found the where the indent started
|
||||
if (len>0 && !range.matchingIndents.isEmpty()
|
||||
&&
|
||||
( matchingIndents.back()== sitBrace
|
||||
|| matchingIndents.back() == sitStatement
|
||||
) ) {
|
||||
// but it's not a complete statement
|
||||
matchingIndents = range.matchingIndents;
|
||||
} else {
|
||||
indentSpaces = leftSpaces(mLines->getString(l-1));
|
||||
if (newIndents.length()>0)
|
||||
indentSpaces+=mTabWidth;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
matchingIndents = range.matchingIndents + matchingIndents.mid(i);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ enum SynIndentType {
|
|||
sitParenthesis = 1,
|
||||
sitBracket = 2,
|
||||
sitStatement = 3,
|
||||
sitStatemntBrace = 100
|
||||
};
|
||||
|
||||
struct SynRangeState {
|
||||
|
|
|
@ -393,8 +393,9 @@ void SynEditCppHighlighter::braceOpenProc()
|
|||
if (mRange.getLastIndent() == sitStatement) {
|
||||
// if last indent is started by 'if' 'for' etc
|
||||
// just replace it
|
||||
int counts = popStatementIndents();
|
||||
pushIndents(sitStatemntBrace+counts);
|
||||
while (mRange.getLastIndent() == sitStatement)
|
||||
popIndents(sitStatement);
|
||||
pushIndents(sitBrace);
|
||||
// int idx = mRange.indents.length()-1;
|
||||
// if (idx < mRange.firstIndentThisLine) {
|
||||
// mRange.firstIndentThisLine = idx;
|
||||
|
@ -1358,8 +1359,6 @@ void SynEditCppHighlighter::processChar()
|
|||
void SynEditCppHighlighter::popIndents(int indentType)
|
||||
{
|
||||
while (!mRange.indents.isEmpty() && mRange.indents.back()!=indentType) {
|
||||
if (indentType == sitBrace && mRange.indents.back() >= sitStatemntBrace)
|
||||
break;
|
||||
mRange.indents.pop_back();
|
||||
}
|
||||
if (!mRange.indents.isEmpty()) {
|
||||
|
@ -1371,20 +1370,6 @@ void SynEditCppHighlighter::popIndents(int indentType)
|
|||
}
|
||||
}
|
||||
|
||||
int SynEditCppHighlighter::popStatementIndents()
|
||||
{
|
||||
int counts = 0;
|
||||
while (!mRange.indents.isEmpty() && mRange.indents.back() == sitStatement) {
|
||||
int idx = mRange.indents.length()-1;
|
||||
if (idx < mRange.firstIndentThisLine) {
|
||||
// mRange.matchingIndents.append(mRange.indents[idx]);
|
||||
counts++;
|
||||
}
|
||||
mRange.indents.pop_back();
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
void SynEditCppHighlighter::pushIndents(int indentType)
|
||||
{
|
||||
int idx = mRange.indents.length();
|
||||
|
|
|
@ -126,7 +126,6 @@ private:
|
|||
void xorSymbolProc();
|
||||
void processChar();
|
||||
void popIndents(int indentType);
|
||||
int popStatementIndents();
|
||||
void pushIndents(int indentType);
|
||||
|
||||
private:
|
||||
|
|
|
@ -127,7 +127,7 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
|
|||
return node->statement->command + node->statement->args;
|
||||
}
|
||||
} else if (role == Qt::ForegroundRole) {
|
||||
if (node->statement) {
|
||||
if (mColors && node->statement) {
|
||||
PStatement statement = (node->statement);
|
||||
StatementKind kind;
|
||||
if (mParser) {
|
||||
|
@ -143,8 +143,8 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
|
|||
if (item) {
|
||||
return item->foreground();
|
||||
}
|
||||
return pMainWindow->palette().color(QPalette::Text);
|
||||
}
|
||||
return pMainWindow->palette().color(QPalette::Text);
|
||||
} else if (role == Qt::DecorationRole) {
|
||||
if (node->statement) {
|
||||
PStatement statement = (node->statement);
|
||||
|
|
Loading…
Reference in New Issue